effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let max_length_info (a:S.hash_algorithm) =
max_size_t - S.size_label_version - S.size_suite_id_hpke - S.size_label_info_hash - Spec.Hash.Definitions.block_length a | let max_length_info (a: S.hash_algorithm) = | false | null | false | max_size_t - S.size_label_version - S.size_suite_id_hpke - S.size_label_info_hash -
Spec.Hash.Definitions.block_length a | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.hash_algorithm",
"Prims.op_Subtraction",
"Lib.IntTypes.max_size_t",
"Spec.Agile.HPKE.size_label_version",
"Spec.Agile.HPKE.size_suite_id_hpke",
"Spec.Agile.HPKE.size_label_info_hash",
"Spec.Hash.Definitions.block_length",
"Prims.int"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs))
inline_for_extraction noextract
let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs))
inline_for_extraction noextract
let key_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_key cs))
inline_for_extraction noextract
let nonce_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_nonce cs))
(* Redefining this to work around Low*'s limitation on buffer size *)
inline_for_extraction noextract | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val max_length_info : a: Spec.Agile.HPKE.hash_algorithm -> Prims.int | [] | Hacl.Impl.HPKE.max_length_info | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.HPKE.hash_algorithm -> Prims.int | {
"end_col": 122,
"end_line": 29,
"start_col": 2,
"start_line": 29
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs)) | let serialized_point_dh (cs: S.ciphersuite) = | false | null | false | lbuffer uint8 (size (S.size_dh_serialized cs)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size",
"Spec.Agile.HPKE.size_dh_serialized"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs)) | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialized_point_dh : cs: Spec.Agile.HPKE.ciphersuite -> Type0 | [] | Hacl.Impl.HPKE.serialized_point_dh | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> Type0 | {
"end_col": 91,
"end_line": 20,
"start_col": 45,
"start_line": 20
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let key_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_key cs)) | let key_aead (cs: S.ciphersuite) = | false | null | false | lbuffer uint8 (size (S.size_aead_key cs)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size",
"Spec.Agile.HPKE.size_aead_key"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs))
inline_for_extraction noextract
let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs)) | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val key_aead : cs: Spec.Agile.HPKE.ciphersuite -> Type0 | [] | Hacl.Impl.HPKE.key_aead | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> Type0 | {
"end_col": 75,
"end_line": 22,
"start_col": 34,
"start_line": 22
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs)) | let key_dh_secret (cs: S.ciphersuite) = | false | null | false | lbuffer uint8 (size (S.size_dh_key cs)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size",
"Spec.Agile.HPKE.size_dh_key"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs)) | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val key_dh_secret : cs: Spec.Agile.HPKE.ciphersuite -> Type0 | [] | Hacl.Impl.HPKE.key_dh_secret | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> Type0 | {
"end_col": 78,
"end_line": 18,
"start_col": 39,
"start_line": 18
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let nonce_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_nonce cs)) | let nonce_aead (cs: S.ciphersuite) = | false | null | false | lbuffer uint8 (size (S.size_aead_nonce cs)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size",
"Spec.Agile.HPKE.size_aead_nonce"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs))
inline_for_extraction noextract
let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs))
inline_for_extraction noextract
let key_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_key cs)) | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val nonce_aead : cs: Spec.Agile.HPKE.ciphersuite -> Type0 | [] | Hacl.Impl.HPKE.nonce_aead | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> Type0 | {
"end_col": 79,
"end_line": 24,
"start_col": 36,
"start_line": 24
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "HKDF"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "SDH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "SHa"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let setupBaseR_st (cs:S.ciphersuite) (p:Type0) =
o_ctx : context_s cs
-> pkE: key_dh_public cs
-> skR: key_dh_secret cs
-> infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires fun h0 ->
p /\
ctx_invariant h0 o_ctx /\
live h0 pkE /\ live h0 skR /\ live h0 info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info)
)
(ensures fun h0 result h1 -> modifies (ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseR cs (as_seq h0 pkE) (as_seq h0 skR) (as_seq h0 info) in
match result with
| 0ul -> Some? output /\ (let ctx = Some?.v output in
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False
)
) | let setupBaseR_st (cs: S.ciphersuite) (p: Type0) = | false | null | false |
o_ctx: context_s cs ->
pkE: key_dh_public cs ->
skR: key_dh_secret cs ->
infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)} ->
info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires
fun h0 ->
p /\ ctx_invariant h0 o_ctx /\ live h0 pkE /\ live h0 skR /\ live h0 info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info))
(ensures
fun h0 result h1 ->
modifies (ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseR cs (as_seq h0 pkE) (as_seq h0 skR) (as_seq h0 info) in
match result with
| 0ul ->
Some? output /\
(let ctx = Some?.v output in
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Hacl.Impl.HPKE.context_s",
"Hacl.Impl.HPKE.key_dh_public",
"Hacl.Impl.HPKE.key_dh_secret",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.HPKE.max_length_info",
"Spec.Agile.HPKE.hash_of_cs",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Hacl.Impl.HPKE.ctx_invariant",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Impl.HPKE.ctx_loc",
"Lib.Buffer.loc",
"Lib.Buffer.modifies",
"FStar.Pervasives.Native.uu___is_Some",
"Spec.Agile.HPKE.encryption_context",
"Prims.eq2",
"Hacl.Impl.HPKE.as_ctx",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.uu___is_None",
"Prims.l_False",
"Prims.logical",
"FStar.Pervasives.Native.option",
"Spec.Agile.HPKE.setupBaseR",
"Lib.Buffer.as_seq",
"Lib.IntTypes.size",
"Spec.Agile.HPKE.size_dh_public",
"Spec.Agile.HPKE.size_dh_key"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs))
inline_for_extraction noextract
let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs))
inline_for_extraction noextract
let key_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_key cs))
inline_for_extraction noextract
let nonce_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_nonce cs))
(* Redefining this to work around Low*'s limitation on buffer size *)
inline_for_extraction noextract
let max_length_info (a:S.hash_algorithm) =
max_size_t - S.size_label_version - S.size_suite_id_hpke - S.size_label_info_hash - Spec.Hash.Definitions.block_length a
val context_s (cs:S.ciphersuite) : Type0
val ctx_loc (#cs:S.ciphersuite) (ctx:context_s cs) : GTot B.loc
val ctx_invariant (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot prop
val as_ctx (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot (S.encryption_context cs)
val frame_ctx (#cs:S.ciphersuite) (ctx:context_s cs) (l:B.loc) (h0 h1:mem)
: Lemma (requires ctx_invariant h0 ctx /\ B.loc_disjoint (ctx_loc ctx) l /\ modifies l h0 h1)
(ensures ctx_invariant h1 ctx /\ as_ctx h0 ctx == as_ctx h1 ctx)
[SMTPat (modifies l h0 h1); SMTPat (ctx_invariant h0 ctx)]
inline_for_extraction noextract
let setupBaseS_st (cs:S.ciphersuite) (p:Type0) =
o_pkE: key_dh_public cs
-> o_ctx: context_s cs
-> skE: key_dh_secret cs
-> pkR: serialized_point_dh cs
-> infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o_pkE /\
ctx_invariant h0 o_ctx /\
live h0 skE /\ live h0 pkR /\ live h0 info /\
disjoint o_pkE skE /\ disjoint o_pkE pkR /\ disjoint o_pkE info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info) /\
B.loc_disjoint (loc o_pkE) (ctx_loc o_ctx))
(ensures fun h0 result h1 -> modifies (loc o_pkE |+| ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseS cs (as_seq h0 skE) (as_seq h0 pkR) (as_seq h0 info) in
match result with
| 0ul -> Some? output /\ (let pkE, ctx = Some?.v output in
as_seq h1 o_pkE == pkE /\
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False
)
)
inline_for_extraction noextract | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val setupBaseR_st : cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | [] | Hacl.Impl.HPKE.setupBaseR_st | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | {
"end_col": 6,
"end_line": 91,
"start_col": 5,
"start_line": 71
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "HKDF"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "SDH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "SHa"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let setupBaseS_st (cs:S.ciphersuite) (p:Type0) =
o_pkE: key_dh_public cs
-> o_ctx: context_s cs
-> skE: key_dh_secret cs
-> pkR: serialized_point_dh cs
-> infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o_pkE /\
ctx_invariant h0 o_ctx /\
live h0 skE /\ live h0 pkR /\ live h0 info /\
disjoint o_pkE skE /\ disjoint o_pkE pkR /\ disjoint o_pkE info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info) /\
B.loc_disjoint (loc o_pkE) (ctx_loc o_ctx))
(ensures fun h0 result h1 -> modifies (loc o_pkE |+| ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseS cs (as_seq h0 skE) (as_seq h0 pkR) (as_seq h0 info) in
match result with
| 0ul -> Some? output /\ (let pkE, ctx = Some?.v output in
as_seq h1 o_pkE == pkE /\
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False
)
) | let setupBaseS_st (cs: S.ciphersuite) (p: Type0) = | false | null | false |
o_pkE: key_dh_public cs ->
o_ctx: context_s cs ->
skE: key_dh_secret cs ->
pkR: serialized_point_dh cs ->
infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)} ->
info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires
fun h0 ->
p /\ live h0 o_pkE /\ ctx_invariant h0 o_ctx /\ live h0 skE /\ live h0 pkR /\ live h0 info /\
disjoint o_pkE skE /\ disjoint o_pkE pkR /\ disjoint o_pkE info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info) /\ B.loc_disjoint (loc o_pkE) (ctx_loc o_ctx))
(ensures
fun h0 result h1 ->
modifies (loc o_pkE |+| ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseS cs (as_seq h0 skE) (as_seq h0 pkR) (as_seq h0 info) in
match result with
| 0ul ->
Some? output /\
(let pkE, ctx = Some?.v output in
as_seq h1 o_pkE == pkE /\ as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Hacl.Impl.HPKE.key_dh_public",
"Hacl.Impl.HPKE.context_s",
"Hacl.Impl.HPKE.key_dh_secret",
"Hacl.Impl.HPKE.serialized_point_dh",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.HPKE.max_length_info",
"Spec.Agile.HPKE.hash_of_cs",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.HPKE.ctx_invariant",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Impl.HPKE.ctx_loc",
"Lib.Buffer.loc",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"Spec.Agile.HPKE.key_dh_public_s",
"Spec.Agile.HPKE.encryption_context",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.size",
"Spec.Agile.HPKE.size_dh_public",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.as_seq",
"Hacl.Impl.HPKE.as_ctx",
"Prims.logical",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.uu___is_None",
"Prims.l_False",
"FStar.Pervasives.Native.option",
"Spec.Agile.HPKE.setupBaseS",
"Spec.Agile.HPKE.size_dh_key",
"Spec.Agile.HPKE.size_dh_serialized"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs))
inline_for_extraction noextract
let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs))
inline_for_extraction noextract
let key_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_key cs))
inline_for_extraction noextract
let nonce_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_nonce cs))
(* Redefining this to work around Low*'s limitation on buffer size *)
inline_for_extraction noextract
let max_length_info (a:S.hash_algorithm) =
max_size_t - S.size_label_version - S.size_suite_id_hpke - S.size_label_info_hash - Spec.Hash.Definitions.block_length a
val context_s (cs:S.ciphersuite) : Type0
val ctx_loc (#cs:S.ciphersuite) (ctx:context_s cs) : GTot B.loc
val ctx_invariant (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot prop
val as_ctx (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot (S.encryption_context cs)
val frame_ctx (#cs:S.ciphersuite) (ctx:context_s cs) (l:B.loc) (h0 h1:mem)
: Lemma (requires ctx_invariant h0 ctx /\ B.loc_disjoint (ctx_loc ctx) l /\ modifies l h0 h1)
(ensures ctx_invariant h1 ctx /\ as_ctx h0 ctx == as_ctx h1 ctx)
[SMTPat (modifies l h0 h1); SMTPat (ctx_invariant h0 ctx)]
inline_for_extraction noextract | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val setupBaseS_st : cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | [] | Hacl.Impl.HPKE.setupBaseS_st | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | {
"end_col": 6,
"end_line": 67,
"start_col": 5,
"start_line": 43
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "HKDF"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "SDH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "SHa"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let openBase_st (cs:S.ciphersuite) (p:Type0) =
pkE: key_dh_public cs { S.is_valid_not_export_only_ciphersuite cs }
-> skR: key_dh_secret cs
-> infolen: size_t {v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> aadlen: size_t {v aadlen <= SAEAD.max_length (S.aead_alg_of cs)}
-> aad: lbuffer uint8 aadlen
-> ctlen: size_t{16 < v ctlen /\ v ctlen <= SAEAD.max_length (S.aead_alg_of cs) }
-> ct:lbuffer uint8 ctlen
-> o_pt: lbuffer uint8 (size (v ctlen - 16))
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o_pt /\
live h0 skR /\ live h0 pkE /\ live h0 info /\
live h0 aad /\ live h0 ct /\
disjoint o_pt skR /\ disjoint o_pt pkE /\ disjoint o_pt info /\
disjoint o_pt aad /\ disjoint o_pt ct
)
(ensures fun h0 result h1 -> modifies (loc o_pt) h0 h1 /\
(let sealed = S.openBase cs (as_seq h0 pkE) (as_seq h0 skR) (as_seq h0 info) (as_seq h0 aad) (as_seq h0 ct) in
match result with
| 0ul -> Some? sealed /\
(let pt = Some?.v sealed in
as_seq h1 o_pt `Seq.equal` pt)
| 1ul -> True
| _ -> False)
) | let openBase_st (cs: S.ciphersuite) (p: Type0) = | false | null | false |
pkE: key_dh_public cs {S.is_valid_not_export_only_ciphersuite cs} ->
skR: key_dh_secret cs ->
infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)} ->
info: lbuffer uint8 infolen ->
aadlen: size_t{v aadlen <= SAEAD.max_length (S.aead_alg_of cs)} ->
aad: lbuffer uint8 aadlen ->
ctlen: size_t{16 < v ctlen /\ v ctlen <= SAEAD.max_length (S.aead_alg_of cs)} ->
ct: lbuffer uint8 ctlen ->
o_pt: lbuffer uint8 (size (v ctlen - 16))
-> Stack UInt32.t
(requires
fun h0 ->
p /\ live h0 o_pt /\ live h0 skR /\ live h0 pkE /\ live h0 info /\ live h0 aad /\
live h0 ct /\ disjoint o_pt skR /\ disjoint o_pt pkE /\ disjoint o_pt info /\
disjoint o_pt aad /\ disjoint o_pt ct)
(ensures
fun h0 result h1 ->
modifies (loc o_pt) h0 h1 /\
(let sealed =
S.openBase cs
(as_seq h0 pkE)
(as_seq h0 skR)
(as_seq h0 info)
(as_seq h0 aad)
(as_seq h0 ct)
in
match result with
| 0ul ->
Some? sealed /\
(let pt = Some?.v sealed in
(as_seq h1 o_pt) `Seq.equal` pt)
| 1ul -> True
| _ -> False)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Hacl.Impl.HPKE.key_dh_public",
"Prims.b2t",
"Spec.Agile.HPKE.is_valid_not_export_only_ciphersuite",
"Hacl.Impl.HPKE.key_dh_secret",
"Lib.IntTypes.size_t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.HPKE.max_length_info",
"Spec.Agile.HPKE.hash_of_cs",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Spec.Agile.AEAD.max_length",
"Spec.Agile.HPKE.aead_alg_of",
"Prims.l_and",
"Prims.op_LessThan",
"Lib.IntTypes.size",
"Prims.op_Subtraction",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"FStar.Pervasives.Native.uu___is_Some",
"Spec.Agile.AEAD.decrypted",
"Lib.Buffer.as_seq",
"FStar.Seq.Base.equal",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.l_True",
"Prims.l_False",
"Prims.logical",
"FStar.Pervasives.Native.option",
"Spec.Agile.HPKE.openBase",
"Spec.Agile.HPKE.size_dh_public",
"Spec.Agile.HPKE.size_dh_key"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs))
inline_for_extraction noextract
let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs))
inline_for_extraction noextract
let key_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_key cs))
inline_for_extraction noextract
let nonce_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_nonce cs))
(* Redefining this to work around Low*'s limitation on buffer size *)
inline_for_extraction noextract
let max_length_info (a:S.hash_algorithm) =
max_size_t - S.size_label_version - S.size_suite_id_hpke - S.size_label_info_hash - Spec.Hash.Definitions.block_length a
val context_s (cs:S.ciphersuite) : Type0
val ctx_loc (#cs:S.ciphersuite) (ctx:context_s cs) : GTot B.loc
val ctx_invariant (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot prop
val as_ctx (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot (S.encryption_context cs)
val frame_ctx (#cs:S.ciphersuite) (ctx:context_s cs) (l:B.loc) (h0 h1:mem)
: Lemma (requires ctx_invariant h0 ctx /\ B.loc_disjoint (ctx_loc ctx) l /\ modifies l h0 h1)
(ensures ctx_invariant h1 ctx /\ as_ctx h0 ctx == as_ctx h1 ctx)
[SMTPat (modifies l h0 h1); SMTPat (ctx_invariant h0 ctx)]
inline_for_extraction noextract
let setupBaseS_st (cs:S.ciphersuite) (p:Type0) =
o_pkE: key_dh_public cs
-> o_ctx: context_s cs
-> skE: key_dh_secret cs
-> pkR: serialized_point_dh cs
-> infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o_pkE /\
ctx_invariant h0 o_ctx /\
live h0 skE /\ live h0 pkR /\ live h0 info /\
disjoint o_pkE skE /\ disjoint o_pkE pkR /\ disjoint o_pkE info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info) /\
B.loc_disjoint (loc o_pkE) (ctx_loc o_ctx))
(ensures fun h0 result h1 -> modifies (loc o_pkE |+| ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseS cs (as_seq h0 skE) (as_seq h0 pkR) (as_seq h0 info) in
match result with
| 0ul -> Some? output /\ (let pkE, ctx = Some?.v output in
as_seq h1 o_pkE == pkE /\
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False
)
)
inline_for_extraction noextract
let setupBaseR_st (cs:S.ciphersuite) (p:Type0) =
o_ctx : context_s cs
-> pkE: key_dh_public cs
-> skR: key_dh_secret cs
-> infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires fun h0 ->
p /\
ctx_invariant h0 o_ctx /\
live h0 pkE /\ live h0 skR /\ live h0 info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info)
)
(ensures fun h0 result h1 -> modifies (ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseR cs (as_seq h0 pkE) (as_seq h0 skR) (as_seq h0 info) in
match result with
| 0ul -> Some? output /\ (let ctx = Some?.v output in
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False
)
)
(* The error code here is not exact w.r.t. the spec.
The reason is that, in the spec, the overflow of an internal counter is defined
when it runs above 2**96.
In the code, this counter is represented as a uint64, so the overflow occurs earlier.
Apart from this case, the behaviour of the impl and the spec should be identical *)
inline_for_extraction noextract
let sealBase_st (cs:S.ciphersuite) (p:Type0) =
skE: key_dh_secret cs { S.is_valid_not_export_only_ciphersuite cs }
-> pkR: serialized_point_dh cs
-> infolen: size_t {v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> aadlen: size_t {v aadlen <= SAEAD.max_length (S.aead_alg_of cs)}
-> aad: lbuffer uint8 aadlen
-> plainlen: size_t {v plainlen <= SAEAD.max_length (S.aead_alg_of cs) /\ v plainlen + 16 <= max_size_t}
-> plain: lbuffer uint8 plainlen
-> o_enc: key_dh_public cs
-> o_ct: lbuffer uint8 (size (v plainlen + 16))
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o_enc /\ live h0 o_ct /\
live h0 skE /\ live h0 pkR /\ live h0 info /\
live h0 aad /\ live h0 plain /\
disjoint o_enc skE /\ disjoint o_enc pkR /\ disjoint o_enc info /\
disjoint o_enc aad /\ disjoint o_enc plain /\
disjoint o_ct skE /\ disjoint o_ct pkR /\ disjoint o_ct info /\
disjoint o_ct aad /\ disjoint o_ct plain /\ disjoint o_ct o_enc
)
(ensures fun h0 result h1 -> modifies (loc o_enc |+| loc o_ct) h0 h1 /\
(let sealed = S.sealBase cs (as_seq h0 skE) (as_seq h0 pkR) (as_seq h0 info) (as_seq h0 aad) (as_seq h0 plain) in
match result with
| 0ul -> Some? sealed /\
(let enc, ct = Some?.v sealed in
as_seq h1 o_enc `Seq.equal` enc /\ as_seq h1 o_ct `Seq.equal` ct)
| 1ul -> True
| _ -> False)
)
(* Same issue as above for the exactness of the error code *)
inline_for_extraction noextract | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val openBase_st : cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | [] | Hacl.Impl.HPKE.openBase_st | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | {
"end_col": 8,
"end_line": 160,
"start_col": 5,
"start_line": 134
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "HKDF"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "SDH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "SHa"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "SAEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sealBase_st (cs:S.ciphersuite) (p:Type0) =
skE: key_dh_secret cs { S.is_valid_not_export_only_ciphersuite cs }
-> pkR: serialized_point_dh cs
-> infolen: size_t {v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> aadlen: size_t {v aadlen <= SAEAD.max_length (S.aead_alg_of cs)}
-> aad: lbuffer uint8 aadlen
-> plainlen: size_t {v plainlen <= SAEAD.max_length (S.aead_alg_of cs) /\ v plainlen + 16 <= max_size_t}
-> plain: lbuffer uint8 plainlen
-> o_enc: key_dh_public cs
-> o_ct: lbuffer uint8 (size (v plainlen + 16))
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o_enc /\ live h0 o_ct /\
live h0 skE /\ live h0 pkR /\ live h0 info /\
live h0 aad /\ live h0 plain /\
disjoint o_enc skE /\ disjoint o_enc pkR /\ disjoint o_enc info /\
disjoint o_enc aad /\ disjoint o_enc plain /\
disjoint o_ct skE /\ disjoint o_ct pkR /\ disjoint o_ct info /\
disjoint o_ct aad /\ disjoint o_ct plain /\ disjoint o_ct o_enc
)
(ensures fun h0 result h1 -> modifies (loc o_enc |+| loc o_ct) h0 h1 /\
(let sealed = S.sealBase cs (as_seq h0 skE) (as_seq h0 pkR) (as_seq h0 info) (as_seq h0 aad) (as_seq h0 plain) in
match result with
| 0ul -> Some? sealed /\
(let enc, ct = Some?.v sealed in
as_seq h1 o_enc `Seq.equal` enc /\ as_seq h1 o_ct `Seq.equal` ct)
| 1ul -> True
| _ -> False)
) | let sealBase_st (cs: S.ciphersuite) (p: Type0) = | false | null | false |
skE: key_dh_secret cs {S.is_valid_not_export_only_ciphersuite cs} ->
pkR: serialized_point_dh cs ->
infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)} ->
info: lbuffer uint8 infolen ->
aadlen: size_t{v aadlen <= SAEAD.max_length (S.aead_alg_of cs)} ->
aad: lbuffer uint8 aadlen ->
plainlen:
size_t{v plainlen <= SAEAD.max_length (S.aead_alg_of cs) /\ v plainlen + 16 <= max_size_t} ->
plain: lbuffer uint8 plainlen ->
o_enc: key_dh_public cs ->
o_ct: lbuffer uint8 (size (v plainlen + 16))
-> Stack UInt32.t
(requires
fun h0 ->
p /\ live h0 o_enc /\ live h0 o_ct /\ live h0 skE /\ live h0 pkR /\ live h0 info /\
live h0 aad /\ live h0 plain /\ disjoint o_enc skE /\ disjoint o_enc pkR /\
disjoint o_enc info /\ disjoint o_enc aad /\ disjoint o_enc plain /\ disjoint o_ct skE /\
disjoint o_ct pkR /\ disjoint o_ct info /\ disjoint o_ct aad /\ disjoint o_ct plain /\
disjoint o_ct o_enc)
(ensures
fun h0 result h1 ->
modifies (loc o_enc |+| loc o_ct) h0 h1 /\
(let sealed =
S.sealBase cs
(as_seq h0 skE)
(as_seq h0 pkR)
(as_seq h0 info)
(as_seq h0 aad)
(as_seq h0 plain)
in
match result with
| 0ul ->
Some? sealed /\
(let enc, ct = Some?.v sealed in
(as_seq h1 o_enc) `Seq.equal` enc /\ (as_seq h1 o_ct) `Seq.equal` ct)
| 1ul -> True
| _ -> False)) | {
"checked_file": "Hacl.Impl.HPKE.fsti.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HPKE.fsti"
} | [
"total"
] | [
"Spec.Agile.HPKE.ciphersuite",
"Hacl.Impl.HPKE.key_dh_secret",
"Prims.b2t",
"Spec.Agile.HPKE.is_valid_not_export_only_ciphersuite",
"Hacl.Impl.HPKE.serialized_point_dh",
"Lib.IntTypes.size_t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.HPKE.max_length_info",
"Spec.Agile.HPKE.hash_of_cs",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Spec.Agile.AEAD.max_length",
"Spec.Agile.HPKE.aead_alg_of",
"Prims.l_and",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Impl.HPKE.key_dh_public",
"Lib.IntTypes.size",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"Spec.Agile.HPKE.key_dh_public_s",
"Spec.Agile.AEAD.encrypted",
"Lib.Buffer.as_seq",
"FStar.Seq.Base.equal",
"Spec.Agile.HPKE.size_dh_public",
"Prims.logical",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.l_True",
"Prims.l_False",
"FStar.Pervasives.Native.option",
"Spec.Agile.HPKE.sealBase",
"Spec.Agile.HPKE.size_dh_key",
"Spec.Agile.HPKE.size_dh_serialized"
] | [] | module Hacl.Impl.HPKE
open FStar.HyperStack
open FStar.HyperStack.All
module B = LowStar.Buffer
open Lib.Buffer
open Lib.IntTypes
module S = Spec.Agile.HPKE
module SAEAD = Spec.Agile.AEAD
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
let key_dh_public (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_public cs))
inline_for_extraction noextract
let key_dh_secret (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_key cs))
inline_for_extraction noextract
let serialized_point_dh (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_dh_serialized cs))
inline_for_extraction noextract
let key_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_key cs))
inline_for_extraction noextract
let nonce_aead (cs:S.ciphersuite) = lbuffer uint8 (size (S.size_aead_nonce cs))
(* Redefining this to work around Low*'s limitation on buffer size *)
inline_for_extraction noextract
let max_length_info (a:S.hash_algorithm) =
max_size_t - S.size_label_version - S.size_suite_id_hpke - S.size_label_info_hash - Spec.Hash.Definitions.block_length a
val context_s (cs:S.ciphersuite) : Type0
val ctx_loc (#cs:S.ciphersuite) (ctx:context_s cs) : GTot B.loc
val ctx_invariant (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot prop
val as_ctx (#cs:S.ciphersuite) (h:mem) (ctx:context_s cs) : GTot (S.encryption_context cs)
val frame_ctx (#cs:S.ciphersuite) (ctx:context_s cs) (l:B.loc) (h0 h1:mem)
: Lemma (requires ctx_invariant h0 ctx /\ B.loc_disjoint (ctx_loc ctx) l /\ modifies l h0 h1)
(ensures ctx_invariant h1 ctx /\ as_ctx h0 ctx == as_ctx h1 ctx)
[SMTPat (modifies l h0 h1); SMTPat (ctx_invariant h0 ctx)]
inline_for_extraction noextract
let setupBaseS_st (cs:S.ciphersuite) (p:Type0) =
o_pkE: key_dh_public cs
-> o_ctx: context_s cs
-> skE: key_dh_secret cs
-> pkR: serialized_point_dh cs
-> infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o_pkE /\
ctx_invariant h0 o_ctx /\
live h0 skE /\ live h0 pkR /\ live h0 info /\
disjoint o_pkE skE /\ disjoint o_pkE pkR /\ disjoint o_pkE info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info) /\
B.loc_disjoint (loc o_pkE) (ctx_loc o_ctx))
(ensures fun h0 result h1 -> modifies (loc o_pkE |+| ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseS cs (as_seq h0 skE) (as_seq h0 pkR) (as_seq h0 info) in
match result with
| 0ul -> Some? output /\ (let pkE, ctx = Some?.v output in
as_seq h1 o_pkE == pkE /\
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False
)
)
inline_for_extraction noextract
let setupBaseR_st (cs:S.ciphersuite) (p:Type0) =
o_ctx : context_s cs
-> pkE: key_dh_public cs
-> skR: key_dh_secret cs
-> infolen: size_t{v infolen <= max_length_info (S.hash_of_cs cs)}
-> info: lbuffer uint8 infolen
-> Stack UInt32.t
(requires fun h0 ->
p /\
ctx_invariant h0 o_ctx /\
live h0 pkE /\ live h0 skR /\ live h0 info /\
B.loc_disjoint (ctx_loc o_ctx) (loc info)
)
(ensures fun h0 result h1 -> modifies (ctx_loc o_ctx) h0 h1 /\
(let output = S.setupBaseR cs (as_seq h0 pkE) (as_seq h0 skR) (as_seq h0 info) in
match result with
| 0ul -> Some? output /\ (let ctx = Some?.v output in
as_ctx h1 o_ctx == ctx)
| 1ul -> None? output
| _ -> False
)
)
(* The error code here is not exact w.r.t. the spec.
The reason is that, in the spec, the overflow of an internal counter is defined
when it runs above 2**96.
In the code, this counter is represented as a uint64, so the overflow occurs earlier.
Apart from this case, the behaviour of the impl and the spec should be identical *)
inline_for_extraction noextract | false | true | Hacl.Impl.HPKE.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sealBase_st : cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | [] | Hacl.Impl.HPKE.sealBase_st | {
"file_name": "code/hpke/Hacl.Impl.HPKE.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | cs: Spec.Agile.HPKE.ciphersuite -> p: Type0 -> Type0 | {
"end_col": 8,
"end_line": 129,
"start_col": 5,
"start_line": 100
} |
|
Prims.Tot | val hash_sha256:Hash.hash_st Spec.Agile.Hash.SHA2_256 | [
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hash_sha256 : Hash.hash_st Spec.Agile.Hash.SHA2_256 =
Hacl.Streaming.SHA2.hash_256 | val hash_sha256:Hash.hash_st Spec.Agile.Hash.SHA2_256
let hash_sha256:Hash.hash_st Spec.Agile.Hash.SHA2_256 = | false | null | false | Hacl.Streaming.SHA2.hash_256 | {
"checked_file": "Hacl.HPKE.Interface.Hash.fst.checked",
"dependencies": [
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.Hash.fst"
} | [
"total"
] | [
"Hacl.Streaming.SHA2.hash_256"
] | [] | module Hacl.HPKE.Interface.Hash
module S = Spec.Agile.HPKE
module Hash = Hacl.Hash.Definitions
[@ Meta.Attribute.specialize ]
noextract
assume val hash: #cs:S.ciphersuite -> Hash.hash_st (S.hash_of_cs cs)
(** Instantiations of hash **)
inline_for_extraction noextract | false | true | Hacl.HPKE.Interface.Hash.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hash_sha256:Hash.hash_st Spec.Agile.Hash.SHA2_256 | [] | Hacl.HPKE.Interface.Hash.hash_sha256 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.Hash.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Hash.Definitions.hash_st Spec.Hash.Definitions.SHA2_256 | {
"end_col": 30,
"end_line": 14,
"start_col": 2,
"start_line": 14
} |
Prims.Tot | val hash_sha512:Hash.hash_st Spec.Agile.Hash.SHA2_512 | [
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hash_sha512 : Hash.hash_st Spec.Agile.Hash.SHA2_512 =
Hacl.Streaming.SHA2.hash_512 | val hash_sha512:Hash.hash_st Spec.Agile.Hash.SHA2_512
let hash_sha512:Hash.hash_st Spec.Agile.Hash.SHA2_512 = | false | null | false | Hacl.Streaming.SHA2.hash_512 | {
"checked_file": "Hacl.HPKE.Interface.Hash.fst.checked",
"dependencies": [
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.Hash.fst"
} | [
"total"
] | [
"Hacl.Streaming.SHA2.hash_512"
] | [] | module Hacl.HPKE.Interface.Hash
module S = Spec.Agile.HPKE
module Hash = Hacl.Hash.Definitions
[@ Meta.Attribute.specialize ]
noextract
assume val hash: #cs:S.ciphersuite -> Hash.hash_st (S.hash_of_cs cs)
(** Instantiations of hash **)
inline_for_extraction noextract
let hash_sha256 : Hash.hash_st Spec.Agile.Hash.SHA2_256 =
Hacl.Streaming.SHA2.hash_256
inline_for_extraction noextract | false | true | Hacl.HPKE.Interface.Hash.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hash_sha512:Hash.hash_st Spec.Agile.Hash.SHA2_512 | [] | Hacl.HPKE.Interface.Hash.hash_sha512 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.Hash.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Hash.Definitions.hash_st Spec.Hash.Definitions.SHA2_512 | {
"end_col": 30,
"end_line": 17,
"start_col": 2,
"start_line": 17
} |
FStar.Pervasives.Lemma | val mem_index (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let mem_index = mem_index' | val mem_index (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
let mem_index = | false | null | true | mem_index' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.mem_index'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mem_index (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x)) | [] | FStar.Seq.Properties.mem_index | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma (requires FStar.Seq.Properties.mem x s)
(ensures exists (i: Prims.nat{i < FStar.Seq.Base.length s}). FStar.Seq.Base.index s i == x) | {
"end_col": 26,
"end_line": 60,
"start_col": 16,
"start_line": 60
} |
FStar.Pervasives.Lemma | val lemma_mem_count: #a:eqtype -> s:seq a -> f:(a -> Tot bool) -> Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_mem_count = lemma_mem_count' | val lemma_mem_count: #a:eqtype -> s:seq a -> f:(a -> Tot bool) -> Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
let lemma_mem_count = | false | null | true | lemma_mem_count' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lemma_mem_count'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mem_count: #a:eqtype -> s:seq a -> f:(a -> Tot bool) -> Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x)) | [] | FStar.Seq.Properties.lemma_mem_count | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma
(requires forall (i: Prims.nat{i < FStar.Seq.Base.length s}). f (FStar.Seq.Base.index s i))
(ensures forall (x: a). FStar.Seq.Properties.mem x s ==> f x) | {
"end_col": 38,
"end_line": 125,
"start_col": 22,
"start_line": 125
} |
FStar.Pervasives.Lemma | val sorted_concat_lemma: #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi)))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let sorted_concat_lemma = sorted_concat_lemma' | val sorted_concat_lemma: #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
let sorted_concat_lemma = | false | null | true | sorted_concat_lemma' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.sorted_concat_lemma'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sorted_concat_lemma: #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi)))) | [] | FStar.Seq.Properties.sorted_concat_lemma | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: a -> _: a -> Prims.bool){FStar.Seq.Properties.total_order a f} ->
lo: FStar.Seq.Base.seq a {FStar.Seq.Properties.sorted f lo} ->
pivot: a ->
hi: FStar.Seq.Base.seq a {FStar.Seq.Properties.sorted f hi}
-> FStar.Pervasives.Lemma
(requires
forall (y: a).
(FStar.Seq.Properties.mem y lo ==> f y pivot) /\
(FStar.Seq.Properties.mem y hi ==> f pivot y))
(ensures
FStar.Seq.Properties.sorted f
(FStar.Seq.Base.append lo (FStar.Seq.Properties.cons pivot hi))) | {
"end_col": 46,
"end_line": 148,
"start_col": 26,
"start_line": 148
} |
FStar.Pervasives.Lemma | val lemma_list_seq_bij: #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_list_seq_bij = lemma_list_seq_bij' | val lemma_list_seq_bij: #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
let lemma_list_seq_bij = | false | null | true | lemma_list_seq_bij' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lemma_list_seq_bij'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_list_seq_bij: #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l)) | [] | FStar.Seq.Properties.lemma_list_seq_bij | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Properties.seq_to_list (FStar.Seq.Properties.seq_of_list l) == l) | {
"end_col": 44,
"end_line": 423,
"start_col": 25,
"start_line": 423
} |
FStar.Pervasives.Lemma | val lemma_split : #a:Type -> s:seq a -> i:nat{(0 <= i /\ i <= length s)} -> Lemma
(ensures (append (fst (split s i)) (snd (split s i)) == s)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s) | val lemma_split : #a:Type -> s:seq a -> i:nat{(0 <= i /\ i <= length s)} -> Lemma
(ensures (append (fst (split s i)) (snd (split s i)) == s))
let lemma_split #_ s i = | false | null | true | cut (equal (append (fst (split s i)) (snd (split s i))) s) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"FStar.Pervasives.Native.fst",
"FStar.Seq.Properties.split",
"FStar.Pervasives.Native.snd",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_split : #a:Type -> s:seq a -> i:nat{(0 <= i /\ i <= length s)} -> Lemma
(ensures (append (fst (split s i)) (snd (split s i)) == s)) | [] | FStar.Seq.Properties.lemma_split | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat{0 <= i /\ i <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.append (FStar.Pervasives.Native.fst (FStar.Seq.Properties.split s i))
(FStar.Pervasives.Native.snd (FStar.Seq.Properties.split s i)) ==
s) | {
"end_col": 61,
"end_line": 50,
"start_col": 2,
"start_line": 50
} |
FStar.Pervasives.Lemma | val lemma_cons_inj: #a:Type -> v1:a -> v2:a -> s1:seq a -> s2:seq a
-> Lemma (requires (equal (cons v1 s1) (cons v2 s2)))
(ensures (v1 == v2 /\ equal s1 s2)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0) | val lemma_cons_inj: #a:Type -> v1:a -> v2:a -> s1:seq a -> s2:seq a
-> Lemma (requires (equal (cons v1 s1) (cons v2 s2)))
(ensures (v1 == v2 /\ equal s1 s2))
let lemma_cons_inj #_ v1 v2 s1 s2 = | false | null | true | let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert (index t1 0 == index t2 0) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.unit",
"FStar.Seq.Properties.lemma_append_inj",
"FStar.Seq.Base.create"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_cons_inj: #a:Type -> v1:a -> v2:a -> s1:seq a -> s2:seq a
-> Lemma (requires (equal (cons v1 s1) (cons v2 s2)))
(ensures (v1 == v2 /\ equal s1 s2)) | [] | FStar.Seq.Properties.lemma_cons_inj | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v1: a -> v2: a -> s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.equal (FStar.Seq.Properties.cons v1 s1) (FStar.Seq.Properties.cons v2 s2))
(ensures v1 == v2 /\ FStar.Seq.Base.equal s1 s2) | {
"end_col": 34,
"end_line": 47,
"start_col": 35,
"start_line": 43
} |
FStar.Pervasives.Lemma | val upd_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s}
-> k:nat{k < j - i} -> v:a -> Lemma
(requires i + k < j)
(ensures upd (slice s i j) k v == slice (upd s (i + k) v) i j)
[SMTPat (upd (slice s i j) k v)] | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j) | val upd_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s}
-> k:nat{k < j - i} -> v:a -> Lemma
(requires i + k < j)
(ensures upd (slice s i j) k v == slice (upd s (i + k) v) i j)
[SMTPat (upd (slice s i j) k v)]
let upd_slice #_ s i j k v = | false | null | true | lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"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",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Seq.Base.upd",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val upd_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s}
-> k:nat{k < j - i} -> v:a -> Lemma
(requires i + k < j)
(ensures upd (slice s i j) k v == slice (upd s (i + k) v) i j)
[SMTPat (upd (slice s i j) k v)] | [] | FStar.Seq.Properties.upd_slice | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
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} ->
v: a
-> FStar.Pervasives.Lemma (requires i + k < j)
(ensures
FStar.Seq.Base.upd (FStar.Seq.Base.slice s i j) k v ==
FStar.Seq.Base.slice (FStar.Seq.Base.upd s (i + k) v) i j)
[SMTPat (FStar.Seq.Base.upd (FStar.Seq.Base.slice s i j) k v)] | {
"end_col": 70,
"end_line": 78,
"start_col": 2,
"start_line": 78
} |
FStar.Pervasives.Lemma | val slice_upd: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s}
-> k:nat{k < length s} -> v:a -> Lemma
(requires k < i \/ j <= k)
(ensures slice (upd s k v) i j == slice s i j)
[SMTPat (slice (upd s k v) i j)] | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j) | val slice_upd: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s}
-> k:nat{k < length s} -> v:a -> Lemma
(requires k < i \/ j <= k)
(ensures slice (upd s k v) i j == slice s i j)
[SMTPat (slice (upd s k v) i j)]
let slice_upd #_ s i j k v = | false | null | true | lemma_eq_intro (slice (upd s k v) i j) (slice s i j) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_LessThan",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.upd",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val slice_upd: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s}
-> k:nat{k < length s} -> v:a -> Lemma
(requires k < i \/ j <= k)
(ensures slice (upd s k v) i j == slice s i j)
[SMTPat (slice (upd s k v) i j)] | [] | FStar.Seq.Properties.slice_upd | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j <= FStar.Seq.Base.length s} ->
k: Prims.nat{k < FStar.Seq.Base.length s} ->
v: a
-> FStar.Pervasives.Lemma (requires k < i \/ j <= k)
(ensures FStar.Seq.Base.slice (FStar.Seq.Base.upd s k v) i j == FStar.Seq.Base.slice s i j)
[SMTPat (FStar.Seq.Base.slice (FStar.Seq.Base.upd s k v) i j)] | {
"end_col": 54,
"end_line": 75,
"start_col": 2,
"start_line": 75
} |
FStar.Pervasives.Lemma | val lemma_mem_snoc : #a:eqtype -> s:Seq.seq a -> x:a ->
Lemma (ensures (forall y. mem y (snoc s x) <==> mem y s \/ x=y)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x) | val lemma_mem_snoc : #a:eqtype -> s:Seq.seq a -> x:a ->
Lemma (ensures (forall y. mem y (snoc s x) <==> mem y s \/ x=y))
let lemma_mem_snoc #_ s x = | false | null | true | lemma_append_count s (Seq.create 1 x) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.lemma_append_count",
"FStar.Seq.Base.create",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mem_snoc : #a:eqtype -> s:Seq.seq a -> x:a ->
Lemma (ensures (forall y. mem y (snoc s x) <==> mem y s \/ x=y)) | [] | FStar.Seq.Properties.lemma_mem_snoc | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> x: a
-> FStar.Pervasives.Lemma
(ensures
forall (y: a).
FStar.Seq.Properties.mem y (FStar.Seq.Properties.snoc s x) <==>
FStar.Seq.Properties.mem y s \/ x = y) | {
"end_col": 65,
"end_line": 321,
"start_col": 28,
"start_line": 321
} |
FStar.Pervasives.Lemma | val find_append_some: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let find_append_some = find_append_some' | val find_append_some: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
let find_append_some = | false | null | true | find_append_some' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.find_append_some'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_append_some: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1)) | [] | FStar.Seq.Properties.find_append_some | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (requires Some? (FStar.Seq.Properties.find_l f s1))
(ensures
FStar.Seq.Properties.find_l f (FStar.Seq.Base.append s1 s2) ==
FStar.Seq.Properties.find_l f s1) | {
"end_col": 40,
"end_line": 333,
"start_col": 23,
"start_line": 333
} |
FStar.Pervasives.Lemma | val swap_frame_lo : #a:Type -> s:seq a -> lo:nat -> i:nat{lo <= i} -> j:nat{i <= j && j < length s}
-> Lemma (ensures (slice s lo i == slice (swap s i j) lo i)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i)) | val swap_frame_lo : #a:Type -> s:seq a -> lo:nat -> i:nat{lo <= i} -> j:nat{i <= j && j < length s}
-> Lemma (ensures (slice s lo i == slice (swap s i j) lo i))
let swap_frame_lo #_ s lo i j = | false | null | true | cut (equal (slice s lo i) (slice (swap s i j) lo i)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Properties.swap",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val swap_frame_lo : #a:Type -> s:seq a -> lo:nat -> i:nat{lo <= i} -> j:nat{i <= j && j < length s}
-> Lemma (ensures (slice s lo i == slice (swap s i j) lo i)) | [] | FStar.Seq.Properties.swap_frame_lo | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
lo: Prims.nat ->
i: Prims.nat{lo <= i} ->
j: Prims.nat{i <= j && j < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice s lo i == FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) lo i) | {
"end_col": 84,
"end_line": 260,
"start_col": 32,
"start_line": 260
} |
FStar.Pervasives.Lemma | val lemma_mem_append : #a:eqtype -> s1:seq a -> s2:seq a
-> Lemma (ensures (forall x. mem x (append s1 s2) <==> (mem x s1 || mem x s2))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2 | val lemma_mem_append : #a:eqtype -> s1:seq a -> s2:seq a
-> Lemma (ensures (forall x. mem x (append s1 s2) <==> (mem x s1 || mem x s2)))
let lemma_mem_append #_ s1 s2 = | false | null | true | lemma_append_count s1 s2 | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.lemma_append_count",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mem_append : #a:eqtype -> s1:seq a -> s2:seq a
-> Lemma (ensures (forall x. mem x (append s1 s2) <==> (mem x s1 || mem x s2))) | [] | FStar.Seq.Properties.lemma_mem_append | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.mem x (FStar.Seq.Base.append s1 s2) <==>
FStar.Seq.Properties.mem x s1 || FStar.Seq.Properties.mem x s2) | {
"end_col": 56,
"end_line": 242,
"start_col": 32,
"start_line": 242
} |
FStar.Pervasives.Lemma | val lemma_slice_snoc: #a:eqtype -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma (ensures (forall x. mem x (slice s i j) <==> (x = index s (j - 1) || mem x (slice s i (j - 1))))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1))) | val lemma_slice_snoc: #a:eqtype -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma (ensures (forall x. mem x (slice s i j) <==> (x = index s (j - 1) || mem x (slice s i (j - 1)))))
let lemma_slice_snoc #_ s i j = | false | null | true | cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_mem_append",
"FStar.Seq.Base.slice",
"Prims.op_Subtraction",
"FStar.Seq.Base.create",
"FStar.Seq.Base.index",
"Prims.unit",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_slice_snoc: #a:eqtype -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma (ensures (forall x. mem x (slice s i j) <==> (x = index s (j - 1) || mem x (slice s i (j - 1))))) | [] | FStar.Seq.Properties.lemma_slice_snoc | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i < j && j <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.mem x (FStar.Seq.Base.slice s i j) <==>
x = FStar.Seq.Base.index s (j - 1) ||
FStar.Seq.Properties.mem x (FStar.Seq.Base.slice s i (j - 1))) | {
"end_col": 67,
"end_line": 250,
"start_col": 2,
"start_line": 249
} |
FStar.Pervasives.Lemma | val find_append_none: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let find_append_none = find_append_none' | val find_append_none: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
let find_append_none = | false | null | true | find_append_none' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.find_append_none'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_append_none: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2)) | [] | FStar.Seq.Properties.find_append_none | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (requires None? (FStar.Seq.Properties.find_l f s1))
(ensures
FStar.Seq.Properties.find_l f (FStar.Seq.Base.append s1 s2) ==
FStar.Seq.Properties.find_l f s2) | {
"end_col": 40,
"end_line": 345,
"start_col": 23,
"start_line": 345
} |
FStar.Pervasives.Lemma | val lemma_index_is_nth: #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_index_is_nth = lemma_index_is_nth' | val lemma_index_is_nth: #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
let lemma_index_is_nth = | false | null | true | lemma_index_is_nth' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lemma_index_is_nth'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_index_is_nth: #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i)) | [] | FStar.Seq.Properties.lemma_index_is_nth | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat{i < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.index (FStar.Seq.Properties.seq_to_list s) i == FStar.Seq.Base.index s i) | {
"end_col": 44,
"end_line": 435,
"start_col": 25,
"start_line": 435
} |
FStar.Pervasives.Lemma | val seq_mem_k' (#a: eqtype) (s: seq a) (n: nat{n < Seq.length s})
: Lemma (requires True) (ensures (mem (Seq.index s n) s)) (decreases n) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1) | val seq_mem_k' (#a: eqtype) (s: seq a) (n: nat{n < Seq.length s})
: Lemma (requires True) (ensures (mem (Seq.index s n) s)) (decreases n)
let rec seq_mem_k': #a: eqtype -> s: seq a -> n: nat{n < Seq.length s}
-> Lemma (requires True) (ensures (mem (Seq.index s n) s)) (decreases n) = | false | null | true | fun #_ s n ->
if n = 0
then ()
else
let tl = tail s in
seq_mem_k' tl (n - 1) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Properties.seq_mem_k'",
"Prims.op_Subtraction",
"FStar.Seq.Properties.tail",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val seq_mem_k' (#a: eqtype) (s: seq a) (n: nat{n < Seq.length s})
: Lemma (requires True) (ensures (mem (Seq.index s n) s)) (decreases n) | [
"recursion"
] | FStar.Seq.Properties.seq_mem_k' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> n: Prims.nat{n < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Properties.mem (FStar.Seq.Base.index s n) s)
(decreases n) | {
"end_col": 28,
"end_line": 381,
"start_col": 2,
"start_line": 378
} |
FStar.Pervasives.Lemma | val lemma_find_l_contains (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l))) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_find_l_contains = lemma_find_l_contains' | val lemma_find_l_contains (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
let lemma_find_l_contains = | false | null | true | lemma_find_l_contains' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lemma_find_l_contains'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_find_l_contains (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l))) | [] | FStar.Seq.Properties.lemma_find_l_contains | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> Prims.bool) -> l: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
Some? (FStar.Seq.Properties.find_l f l) ==>
FStar.Seq.Properties.contains l (Some?.v (FStar.Seq.Properties.find_l f l))) | {
"end_col": 50,
"end_line": 472,
"start_col": 28,
"start_line": 472
} |
FStar.Pervasives.Lemma | val lemma_swap_slice_commute : #a:Type -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma (ensures (slice (swap s i j) start len == (swap (slice s start len) (i - start) (j - start)))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start))) | val lemma_swap_slice_commute : #a:Type -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma (ensures (slice (swap s i j) start len == (swap (slice s start len) (i - start) (j - start))))
let lemma_swap_slice_commute #_ s start i j len = | false | null | true | cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Properties.swap",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_swap_slice_commute : #a:Type -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma (ensures (slice (swap s i j) start len == (swap (slice s start len) (i - start) (j - start)))) | [] | FStar.Seq.Properties.lemma_swap_slice_commute | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
start: Prims.nat ->
i: Prims.nat{start <= i} ->
j: Prims.nat{i <= j} ->
len: Prims.nat{j < len && len <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) start len ==
FStar.Seq.Properties.swap (FStar.Seq.Base.slice s start len) (i - start) (j - start)) | {
"end_col": 95,
"end_line": 267,
"start_col": 2,
"start_line": 267
} |
FStar.Pervasives.Lemma | val contains_snoc : #a:Type -> s:Seq.seq a -> x:a ->
Lemma (ensures (forall y. (snoc s x) `contains` y <==> s `contains` y \/ x==y)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x)) | val contains_snoc : #a:Type -> s:Seq.seq a -> x:a ->
Lemma (ensures (forall y. (snoc s x) `contains` y <==> s `contains` y \/ x==y))
let contains_snoc #_ s x = | false | null | true | FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"FStar.Classical.forall_intro",
"Prims.l_iff",
"FStar.Seq.Properties.contains",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Prims.l_or",
"FStar.Seq.Properties.append_contains_equiv",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val contains_snoc : #a:Type -> s:Seq.seq a -> x:a ->
Lemma (ensures (forall y. (snoc s x) `contains` y <==> s `contains` y \/ x==y)) | [] | FStar.Seq.Properties.contains_snoc | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> x: a
-> FStar.Pervasives.Lemma
(ensures
forall (y: a).
FStar.Seq.Properties.contains (FStar.Seq.Properties.snoc s x) y <==>
FStar.Seq.Properties.contains s y \/ x == y) | {
"end_col": 73,
"end_line": 463,
"start_col": 2,
"start_line": 463
} |
FStar.Pervasives.Lemma | val lemma_mem_count' (#a: eqtype) (s: seq a) (f: (a -> Tot bool))
: Lemma (requires (forall (i: nat{i < length s}). f (index s i)))
(ensures (forall (x: a). mem x s ==> f x))
(decreases (length s)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f) | val lemma_mem_count' (#a: eqtype) (s: seq a) (f: (a -> Tot bool))
: Lemma (requires (forall (i: nat{i < length s}). f (index s i)))
(ensures (forall (x: a). mem x s ==> f x))
(decreases (length s))
let rec lemma_mem_count' (#a: eqtype) (s: seq a) (f: (a -> Tot bool))
: Lemma (requires (forall (i: nat{i < length s}). f (index s i)))
(ensures (forall (x: a). mem x s ==> f x))
(decreases (length s)) = | false | null | true | if length s = 0
then ()
else
(let t = i: nat{i < length (tail s)} in
cut (forall (i: t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_mem_count'",
"FStar.Seq.Properties.tail",
"Prims.unit",
"Prims.cut",
"Prims.l_Forall",
"Prims.b2t",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.nat",
"Prims.op_LessThan",
"Prims.squash",
"Prims.l_imp",
"FStar.Seq.Properties.mem",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mem_count' (#a: eqtype) (s: seq a) (f: (a -> Tot bool))
: Lemma (requires (forall (i: nat{i < length s}). f (index s i)))
(ensures (forall (x: a). mem x s ==> f x))
(decreases (length s)) | [
"recursion"
] | FStar.Seq.Properties.lemma_mem_count' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma
(requires forall (i: Prims.nat{i < FStar.Seq.Base.length s}). f (FStar.Seq.Base.index s i))
(ensures forall (x: a). FStar.Seq.Properties.mem x s ==> f x)
(decreases FStar.Seq.Base.length s) | {
"end_col": 36,
"end_line": 123,
"start_col": 2,
"start_line": 119
} |
FStar.Pervasives.Lemma | val lemma_seq_to_list_permutation' (#a: eqtype) (s: seq a)
: Lemma (requires True)
(ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s)))
(decreases (length s)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_seq_to_list_permutation' (#a:eqtype) (s:seq a)
:Lemma (requires True) (ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s))) (decreases (length s))
= if length s > 0 then lemma_seq_to_list_permutation' (slice s 1 (length s)) | val lemma_seq_to_list_permutation' (#a: eqtype) (s: seq a)
: Lemma (requires True)
(ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s)))
(decreases (length s))
let rec lemma_seq_to_list_permutation' (#a: eqtype) (s: seq a)
: Lemma (requires True)
(ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s)))
(decreases (length s)) = | false | null | true | if length s > 0 then lemma_seq_to_list_permutation' (slice s 1 (length s)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_seq_to_list_permutation'",
"FStar.Seq.Base.slice",
"Prims.bool",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Properties.count",
"FStar.List.Tot.Base.count",
"FStar.Seq.Properties.seq_to_list",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s
let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1))
let cons_index_slice #_ s i j _ = lemma_eq_elim (cons (index s i) (slice s (i + 1) j)) (slice s i j)
let slice_is_empty #_ s i = lemma_eq_elim (slice s i i) Seq.empty
let slice_length #_ s = lemma_eq_elim (slice s 0 (length s)) s
let slice_slice #_ s i1 j1 i2 j2 = lemma_eq_elim (slice (slice s i1 j1) i2 j2) (slice s (i1 + i2) (i1 + j2))
let rec lemma_seq_of_list_index #_ l i
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd::tl -> if i = 0 then () else lemma_seq_of_list_index tl (i - 1)
let seq_of_list_tl #_ l = lemma_seq_of_list_induction l
let rec mem_seq_of_list #_ x l
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| y :: q ->
let _ : squash (head (seq_of_list l) == y) = () in
let _ : squash (tail (seq_of_list l) == seq_of_list q) = seq_of_list_tl l in
let _ : squash (mem x (seq_of_list l) == (x = y || mem x (seq_of_list q))) =
lemma_mem_inversion (seq_of_list l)
in
mem_seq_of_list x q
let rec intro_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
explode_and i s l))
(ensures (
equal (seq_of_list l) (slice s i (length s))))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl -> intro_of_list'' (i + 1) s tl
let intro_of_list' = intro_of_list''
let intro_of_list #_ s l = intro_of_list' 0 s l
let rec elim_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
slice s i (length s) == seq_of_list l))
(ensures (
explode_and i s l))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
match l with
| [] -> ()
| hd :: tl ->
lemma_seq_of_list_induction l;
elim_of_list'' (i + 1) s tl
let elim_of_list' = elim_of_list''
let elim_of_list #_ l = elim_of_list' 0 (seq_of_list l) l
let rec lemma_seq_to_list_permutation' (#a:eqtype) (s:seq a) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_to_list_permutation' (#a: eqtype) (s: seq a)
: Lemma (requires True)
(ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s)))
(decreases (length s)) | [
"recursion"
] | FStar.Seq.Properties.lemma_seq_to_list_permutation' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.count x s ==
FStar.List.Tot.Base.count x (FStar.Seq.Properties.seq_to_list s))
(decreases FStar.Seq.Base.length s) | {
"end_col": 78,
"end_line": 596,
"start_col": 4,
"start_line": 596
} |
FStar.Pervasives.Lemma | val un_snoc_snoc (#a:Type) (s:seq a) (x:a) : Lemma (un_snoc (snoc s x) == (s, x)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s') | val un_snoc_snoc (#a:Type) (s:seq a) (x:a) : Lemma (un_snoc (snoc s x) == (s, x))
let un_snoc_snoc #_ s x = | false | null | true | let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s') | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims._assert",
"FStar.Seq.Base.equal",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"FStar.Seq.Properties.snoc",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"FStar.Seq.Properties.un_snoc"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val un_snoc_snoc (#a:Type) (s:seq a) (x:a) : Lemma (un_snoc (snoc s x) == (s, x)) | [] | FStar.Seq.Properties.un_snoc_snoc | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> x: a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.un_snoc (FStar.Seq.Properties.snoc s x) ==
FStar.Pervasives.Native.Mktuple2 s x) | {
"end_col": 25,
"end_line": 367,
"start_col": 25,
"start_line": 365
} |
FStar.Pervasives.Lemma | val lemma_append_inj_l: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a{length s1 = length t1 /\ equal (append s1 s2) (append t1 t2)} -> i:nat{i < length s1}
-> Lemma (index s1 i == index t1 i) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i)) | val lemma_append_inj_l: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a{length s1 = length t1 /\ equal (append s1 s2) (append t1 t2)} -> i:nat{i < length s1}
-> Lemma (index s1 i == index t1 i)
let lemma_append_inj_l #_ s1 s2 t1 t2 i = | false | null | true | assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"Prims.op_LessThan",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_inj_l: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a{length s1 = length t1 /\ equal (append s1 s2) (append t1 t2)} -> i:nat{i < length s1}
-> Lemma (index s1 i == index t1 i) | [] | FStar.Seq.Properties.lemma_append_inj_l | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
t1: FStar.Seq.Base.seq a ->
t2:
FStar.Seq.Base.seq a
{ FStar.Seq.Base.length s1 = FStar.Seq.Base.length t1 /\
FStar.Seq.Base.equal (FStar.Seq.Base.append s1 s2) (FStar.Seq.Base.append t1 t2) } ->
i: Prims.nat{i < FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index s1 i == FStar.Seq.Base.index t1 i) | {
"end_col": 49,
"end_line": 24,
"start_col": 2,
"start_line": 23
} |
FStar.Pervasives.Lemma | val intro_append_contains_from_disjunction (#a: Type) (s1 s2: seq a) (x: a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x) (ensures (append s1 s2) `contains` x) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x))) | val intro_append_contains_from_disjunction (#a: Type) (s1 s2: seq a) (x: a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x) (ensures (append s1 s2) `contains` x)
let intro_append_contains_from_disjunction (#a: Type) (s1 s2: seq a) (x: a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x) (ensures (append s1 s2) `contains` x) = | false | null | true | let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x)
#(s2 `contains` x)
#(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ ->
let s = append s1 s2 in
exists_elim (s `contains` x)
(get_proof (s2 `contains` x))
(fun k -> assert (Seq.index s (Seq.length s1 + k) == x))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"FStar.Classical.or_elim",
"FStar.Seq.Properties.contains",
"Prims.squash",
"Prims.l_or",
"FStar.Seq.Base.append",
"Prims.unit",
"FStar.Classical.exists_elim",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Squash.get_proof",
"Prims._assert",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_append_contains_from_disjunction (#a: Type) (s1 s2: seq a) (x: a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x) (ensures (append s1 s2) `contains` x) | [] | FStar.Seq.Properties.intro_append_contains_from_disjunction | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> x: a
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Properties.contains s1 x \/ FStar.Seq.Properties.contains s2 x)
(ensures FStar.Seq.Properties.contains (FStar.Seq.Base.append s1 s2) x) | {
"end_col": 62,
"end_line": 457,
"start_col": 6,
"start_line": 451
} |
FStar.Pervasives.Lemma | val find_mem (#a:eqtype) (s:seq a) (f:a -> Tot bool) (x:a{f x})
: Lemma (requires (mem x s))
(ensures (Some? (seq_find f s) /\ f (Some?.v (seq_find f s)))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> () | val find_mem (#a:eqtype) (s:seq a) (f:a -> Tot bool) (x:a{f x})
: Lemma (requires (mem x s))
(ensures (Some? (seq_find f s) /\ f (Some?.v (seq_find f s))))
let find_mem #_ s f x = | false | null | true | match seq_find f s with
| None -> mem_index x s
| Some _ -> () | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.bool",
"Prims.b2t",
"FStar.Seq.Properties.seq_find",
"FStar.Seq.Properties.mem_index",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s') | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_mem (#a:eqtype) (s:seq a) (f:a -> Tot bool) (x:a{f x})
: Lemma (requires (mem x s))
(ensures (Some? (seq_find f s) /\ f (Some?.v (seq_find f s)))) | [] | FStar.Seq.Properties.find_mem | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool) -> x: a{f x}
-> FStar.Pervasives.Lemma (requires FStar.Seq.Properties.mem x s)
(ensures
Some? (FStar.Seq.Properties.seq_find f s) /\ f (Some?.v (FStar.Seq.Properties.seq_find f s))
) | {
"end_col": 19,
"end_line": 372,
"start_col": 5,
"start_line": 370
} |
FStar.Pervasives.Lemma | val swap_frame_hi : #a:Type -> s:seq a -> i:nat -> j:nat{i <= j} -> k:nat{j < k} -> hi:nat{k <= hi /\ hi <= length s}
-> Lemma (ensures (slice s k hi == slice (swap s i j) k hi)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi)) | val swap_frame_hi : #a:Type -> s:seq a -> i:nat -> j:nat{i <= j} -> k:nat{j < k} -> hi:nat{k <= hi /\ hi <= length s}
-> Lemma (ensures (slice s k hi == slice (swap s i j) k hi))
let swap_frame_hi #_ s i j k hi = | false | null | true | cut (equal (slice s k hi) (slice (swap s i j) k hi)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.l_and",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Properties.swap",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i')) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val swap_frame_hi : #a:Type -> s:seq a -> i:nat -> j:nat{i <= j} -> k:nat{j < k} -> hi:nat{k <= hi /\ hi <= length s}
-> Lemma (ensures (slice s k hi == slice (swap s i j) k hi)) | [] | FStar.Seq.Properties.swap_frame_hi | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
i: Prims.nat ->
j: Prims.nat{i <= j} ->
k: Prims.nat{j < k} ->
hi: Prims.nat{k <= hi /\ hi <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice s k hi == FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) k hi) | {
"end_col": 86,
"end_line": 264,
"start_col": 34,
"start_line": 264
} |
FStar.Pervasives.Lemma | val lemma_seq_frame_hi: #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat{i <= j} -> m:nat{j <= m} -> n:nat{m < n && n <= length s1}
-> Lemma
(requires (s1 == (splice s2 i s1 j)))
(ensures ((slice s1 m n == slice s2 m n) /\ (index s1 m == index s2 m))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n)) | val lemma_seq_frame_hi: #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat{i <= j} -> m:nat{j <= m} -> n:nat{m < n && n <= length s1}
-> Lemma
(requires (s1 == (splice s2 i s1 j)))
(ensures ((slice s1 m n == slice s2 m n) /\ (index s1 m == index s2 m)))
let lemma_seq_frame_hi #_ s1 s2 i j m n = | false | null | true | cut (equal (slice s1 m n) (slice s2 m n)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_frame_hi: #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat{i <= j} -> m:nat{j <= m} -> n:nat{m < n && n <= length s1}
-> Lemma
(requires (s1 == (splice s2 i s1 j)))
(ensures ((slice s1 m n == slice s2 m n) /\ (index s1 m == index s2 m))) | [] | FStar.Seq.Properties.lemma_seq_frame_hi | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
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 ->
j: Prims.nat{i <= j} ->
m: Prims.nat{j <= m} ->
n: Prims.nat{m < n && n <= FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma (requires s1 == FStar.Seq.Properties.splice s2 i s1 j)
(ensures
FStar.Seq.Base.slice s1 m n == FStar.Seq.Base.slice s2 m n /\
FStar.Seq.Base.index s1 m == FStar.Seq.Base.index s2 m) | {
"end_col": 43,
"end_line": 278,
"start_col": 2,
"start_line": 278
} |
FStar.Pervasives.Lemma | val mem_cons
(#a:eqtype)
(x:a)
(s:seq a)
: Lemma
(ensures (forall y. mem y (cons x s) <==> mem y s \/ x=y)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let mem_cons #_ x s = lemma_append_count (create 1 x) s | val mem_cons
(#a:eqtype)
(x:a)
(s:seq a)
: Lemma
(ensures (forall y. mem y (cons x s) <==> mem y s \/ x=y))
let mem_cons #_ x s = | false | null | true | lemma_append_count (create 1 x) s | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.lemma_append_count",
"FStar.Seq.Base.create",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = () | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mem_cons
(#a:eqtype)
(x:a)
(s:seq a)
: Lemma
(ensures (forall y. mem y (cons x s) <==> mem y s \/ x=y)) | [] | FStar.Seq.Properties.mem_cons | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
forall (y: a).
FStar.Seq.Properties.mem y (FStar.Seq.Properties.cons x s) <==>
FStar.Seq.Properties.mem y s \/ x = y) | {
"end_col": 55,
"end_line": 515,
"start_col": 22,
"start_line": 515
} |
FStar.Pervasives.Lemma | val seq_of_list_tl
(#a: Type)
(l: list a { List.Tot.length l > 0 } )
: Lemma
(requires True)
(ensures (seq_of_list (List.Tot.tl l) == tail (seq_of_list l))) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let seq_of_list_tl #_ l = lemma_seq_of_list_induction l | val seq_of_list_tl
(#a: Type)
(l: list a { List.Tot.length l > 0 } )
: Lemma
(requires True)
(ensures (seq_of_list (List.Tot.tl l) == tail (seq_of_list l)))
let seq_of_list_tl #_ l = | false | null | true | lemma_seq_of_list_induction l | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"FStar.Seq.Properties.lemma_seq_of_list_induction",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s
let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1))
let cons_index_slice #_ s i j _ = lemma_eq_elim (cons (index s i) (slice s (i + 1) j)) (slice s i j)
let slice_is_empty #_ s i = lemma_eq_elim (slice s i i) Seq.empty
let slice_length #_ s = lemma_eq_elim (slice s 0 (length s)) s
let slice_slice #_ s i1 j1 i2 j2 = lemma_eq_elim (slice (slice s i1 j1) i2 j2) (slice s (i1 + i2) (i1 + j2))
let rec lemma_seq_of_list_index #_ l i
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd::tl -> if i = 0 then () else lemma_seq_of_list_index tl (i - 1) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val seq_of_list_tl
(#a: Type)
(l: list a { List.Tot.length l > 0 } )
: Lemma
(requires True)
(ensures (seq_of_list (List.Tot.tl l) == tail (seq_of_list l))) | [] | FStar.Seq.Properties.seq_of_list_tl | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a {FStar.List.Tot.Base.length l > 0}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.seq_of_list (FStar.List.Tot.Base.tl l) ==
FStar.Seq.Properties.tail (FStar.Seq.Properties.seq_of_list l)) | {
"end_col": 55,
"end_line": 533,
"start_col": 26,
"start_line": 533
} |
FStar.Pervasives.Lemma | val suffix_of_tail
(#a: Type)
(s: seq a {length s > 0})
: Lemma
(requires True)
(ensures ((tail s) `suffix_of` s))
[SMTPat ((tail s) `suffix_of` s)] | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let suffix_of_tail #_ s = cons_head_tail s | val suffix_of_tail
(#a: Type)
(s: seq a {length s > 0})
: Lemma
(requires True)
(ensures ((tail s) `suffix_of` s))
[SMTPat ((tail s) `suffix_of` s)]
let suffix_of_tail #_ s = | false | null | true | cons_head_tail s | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.cons_head_tail",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = () | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val suffix_of_tail
(#a: Type)
(s: seq a {length s > 0})
: Lemma
(requires True)
(ensures ((tail s) `suffix_of` s))
[SMTPat ((tail s) `suffix_of` s)] | [] | FStar.Seq.Properties.suffix_of_tail | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s > 0}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Properties.suffix_of (FStar.Seq.Properties.tail s) s)
[SMTPat (FStar.Seq.Properties.suffix_of (FStar.Seq.Properties.tail s) s)] | {
"end_col": 42,
"end_line": 505,
"start_col": 26,
"start_line": 505
} |
FStar.Pervasives.Lemma | val lemma_slice_cons: #a:eqtype -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma (ensures (forall x. mem x (slice s i j) <==> (x = index s i || mem x (slice s (i + 1) j)))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j) | val lemma_slice_cons: #a:eqtype -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma (ensures (forall x. mem x (slice s i j) <==> (x = index s i || mem x (slice s (i + 1) j))))
let lemma_slice_cons #_ s i j = | false | null | true | cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_mem_append",
"FStar.Seq.Base.create",
"FStar.Seq.Base.index",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.unit",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2 | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_slice_cons: #a:eqtype -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma (ensures (forall x. mem x (slice s i j) <==> (x = index s i || mem x (slice s (i + 1) j)))) | [] | FStar.Seq.Properties.lemma_slice_cons | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i < j && j <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.mem x (FStar.Seq.Base.slice s i j) <==>
x = FStar.Seq.Base.index s i ||
FStar.Seq.Properties.mem x (FStar.Seq.Base.slice s (i + 1) j)) | {
"end_col": 61,
"end_line": 246,
"start_col": 2,
"start_line": 245
} |
FStar.Pervasives.Lemma | val lemma_weaken_frame_left : #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j && j <= k && k <= length s1}
-> Lemma
(requires (s1 == splice s2 j s1 k))
(ensures (s1 == splice s2 i s1 k)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k)) | val lemma_weaken_frame_left : #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j && j <= k && k <= length s1}
-> Lemma
(requires (s1 == splice s2 j s1 k))
(ensures (s1 == splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = | false | null | true | cut (equal s1 (splice s2 i s1 k)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.splice",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_weaken_frame_left : #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j && j <= k && k <= length s1}
-> Lemma
(requires (s1 == splice s2 j s1 k))
(ensures (s1 == splice s2 i s1 k)) | [] | FStar.Seq.Properties.lemma_weaken_frame_left | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
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 ->
j: Prims.nat ->
k: Prims.nat{i <= j && j <= k && k <= FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma (requires s1 == FStar.Seq.Properties.splice s2 j s1 k)
(ensures s1 == FStar.Seq.Properties.splice s2 i s1 k) | {
"end_col": 78,
"end_line": 288,
"start_col": 45,
"start_line": 288
} |
FStar.Pervasives.Lemma | val snoc_slice_index
(#a: Type)
(s: seq a)
(i: nat)
(j: nat {i <= j /\ j < length s} )
: Lemma
(requires True)
(ensures (snoc (slice s i j) (index s j) == slice s i (j + 1)))
[SMTPat (snoc (slice s i j) (index s j))] | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1)) | val snoc_slice_index
(#a: Type)
(s: seq a)
(i: nat)
(j: nat {i <= j /\ j < length s} )
: Lemma
(requires True)
(ensures (snoc (slice s i j) (index s j) == slice s i (j + 1)))
[SMTPat (snoc (slice s i j) (index s j))]
let snoc_slice_index #_ s i j = | false | null | true | lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Seq.Base.lemma_eq_elim",
"FStar.Seq.Properties.snoc",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val snoc_slice_index
(#a: Type)
(s: seq a)
(i: nat)
(j: nat {i <= j /\ j < length s} )
: Lemma
(requires True)
(ensures (snoc (slice s i j) (index s j) == slice s i (j + 1)))
[SMTPat (snoc (slice s i j) (index s j))] | [] | FStar.Seq.Properties.snoc_slice_index | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | 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.Properties.snoc (FStar.Seq.Base.slice s i j) (FStar.Seq.Base.index s j) ==
FStar.Seq.Base.slice s i (j + 1))
[SMTPat (FStar.Seq.Properties.snoc (FStar.Seq.Base.slice s i j) (FStar.Seq.Base.index s j))] | {
"end_col": 98,
"end_line": 517,
"start_col": 32,
"start_line": 517
} |
FStar.Pervasives.Lemma | val elim_of_list (#a: Type) (l: list a):
Lemma
(ensures (
let s = seq_of_list l in
pointwise_and s l)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let elim_of_list #_ l = elim_of_list' 0 (seq_of_list l) l | val elim_of_list (#a: Type) (l: list a):
Lemma
(ensures (
let s = seq_of_list l in
pointwise_and s l))
let elim_of_list #_ l = | false | null | true | elim_of_list' 0 (seq_of_list l) l | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.Seq.Properties.elim_of_list'",
"FStar.Seq.Properties.seq_of_list",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s
let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1))
let cons_index_slice #_ s i j _ = lemma_eq_elim (cons (index s i) (slice s (i + 1) j)) (slice s i j)
let slice_is_empty #_ s i = lemma_eq_elim (slice s i i) Seq.empty
let slice_length #_ s = lemma_eq_elim (slice s 0 (length s)) s
let slice_slice #_ s i1 j1 i2 j2 = lemma_eq_elim (slice (slice s i1 j1) i2 j2) (slice s (i1 + i2) (i1 + j2))
let rec lemma_seq_of_list_index #_ l i
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd::tl -> if i = 0 then () else lemma_seq_of_list_index tl (i - 1)
let seq_of_list_tl #_ l = lemma_seq_of_list_induction l
let rec mem_seq_of_list #_ x l
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| y :: q ->
let _ : squash (head (seq_of_list l) == y) = () in
let _ : squash (tail (seq_of_list l) == seq_of_list q) = seq_of_list_tl l in
let _ : squash (mem x (seq_of_list l) == (x = y || mem x (seq_of_list q))) =
lemma_mem_inversion (seq_of_list l)
in
mem_seq_of_list x q
let rec intro_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
explode_and i s l))
(ensures (
equal (seq_of_list l) (slice s i (length s))))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl -> intro_of_list'' (i + 1) s tl
let intro_of_list' = intro_of_list''
let intro_of_list #_ s l = intro_of_list' 0 s l
let rec elim_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
slice s i (length s) == seq_of_list l))
(ensures (
explode_and i s l))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
match l with
| [] -> ()
| hd :: tl ->
lemma_seq_of_list_induction l;
elim_of_list'' (i + 1) s tl
let elim_of_list' = elim_of_list'' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_of_list (#a: Type) (l: list a):
Lemma
(ensures (
let s = seq_of_list l in
pointwise_and s l)) | [] | FStar.Seq.Properties.elim_of_list | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
(let s = FStar.Seq.Properties.seq_of_list l in
FStar.Seq.Properties.pointwise_and s l)) | {
"end_col": 57,
"end_line": 592,
"start_col": 24,
"start_line": 592
} |
FStar.Pervasives.Lemma | val lemma_append_count' (#a: eqtype) (lo hi: seq a)
: Lemma (requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h)) | val lemma_append_count' (#a: eqtype) (lo hi: seq a)
: Lemma (requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
let rec lemma_append_count' (#a: eqtype) (lo hi: seq a)
: Lemma (requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo)) = | false | null | true | if length lo = 0
then cut (equal (append lo hi) hi)
else
(cut (equal (cons (head lo) (append (tail lo) hi)) (append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"Prims.bool",
"FStar.Seq.Properties.tail",
"FStar.Seq.Properties.cons",
"FStar.Seq.Properties.head",
"Prims.unit",
"FStar.Seq.Properties.lemma_append_count'",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.b2t",
"FStar.Seq.Properties.count",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_count' (#a: eqtype) (lo hi: seq a)
: Lemma (requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo)) | [
"recursion"
] | FStar.Seq.Properties.lemma_append_count' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | lo: FStar.Seq.Base.seq a -> hi: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.count x (FStar.Seq.Base.append lo hi) =
FStar.Seq.Properties.count x lo + FStar.Seq.Properties.count x hi)
(decreases FStar.Seq.Base.length lo) | {
"end_col": 37,
"end_line": 106,
"start_col": 2,
"start_line": 99
} |
FStar.Pervasives.Lemma | val lemma_seq_list_bij' (#a: Type) (s: seq a)
: Lemma (requires (True)) (ensures (seq_of_list (seq_to_list s) == s)) (decreases (length s)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
) | val lemma_seq_list_bij' (#a: Type) (s: seq a)
: Lemma (requires (True)) (ensures (seq_of_list (seq_to_list s) == s)) (decreases (length s))
let rec lemma_seq_list_bij': #a: Type -> s: seq a
-> Lemma (requires (True)) (ensures (seq_of_list (seq_to_list s) == s)) (decreases (length s)) = | false | null | true | fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0
then (assert (equal s (seq_of_list l)))
else
(lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.seq_of_list",
"Prims.bool",
"FStar.Seq.Properties.seq_to_list",
"Prims.unit",
"FStar.Seq.Properties.lemma_seq_list_bij'",
"FStar.Seq.Base.slice",
"FStar.Seq.Properties.lemma_seq_of_list_induction",
"Prims.list",
"Prims.b2t",
"Prims.nat",
"FStar.List.Tot.Base.length"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_list_bij' (#a: Type) (s: seq a)
: Lemma (requires (True)) (ensures (seq_of_list (seq_to_list s) == s)) (decreases (length s)) | [
"recursion"
] | FStar.Seq.Properties.lemma_seq_list_bij' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Properties.seq_of_list (FStar.Seq.Properties.seq_to_list s) == s)
(decreases FStar.Seq.Base.length s) | {
"end_col": 3,
"end_line": 407,
"start_col": 2,
"start_line": 398
} |
FStar.Pervasives.Lemma | val lemma_seq_of_list_permutation (#a:eqtype) (l:list a)
:Lemma (forall x. List.Tot.Base.count x l == count x (seq_of_list l)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_seq_of_list_permutation #a l
=
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| _::tl -> lemma_seq_of_list_permutation tl | val lemma_seq_of_list_permutation (#a:eqtype) (l:list a)
:Lemma (forall x. List.Tot.Base.count x l == count x (seq_of_list l))
let rec lemma_seq_of_list_permutation #a l = | false | null | true | lemma_seq_of_list_induction l;
match l with
| [] -> ()
| _ :: tl -> lemma_seq_of_list_permutation tl | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"Prims.list",
"FStar.Seq.Properties.lemma_seq_of_list_permutation",
"Prims.unit",
"FStar.Seq.Properties.lemma_seq_of_list_induction"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s
let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1))
let cons_index_slice #_ s i j _ = lemma_eq_elim (cons (index s i) (slice s (i + 1) j)) (slice s i j)
let slice_is_empty #_ s i = lemma_eq_elim (slice s i i) Seq.empty
let slice_length #_ s = lemma_eq_elim (slice s 0 (length s)) s
let slice_slice #_ s i1 j1 i2 j2 = lemma_eq_elim (slice (slice s i1 j1) i2 j2) (slice s (i1 + i2) (i1 + j2))
let rec lemma_seq_of_list_index #_ l i
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd::tl -> if i = 0 then () else lemma_seq_of_list_index tl (i - 1)
let seq_of_list_tl #_ l = lemma_seq_of_list_induction l
let rec mem_seq_of_list #_ x l
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| y :: q ->
let _ : squash (head (seq_of_list l) == y) = () in
let _ : squash (tail (seq_of_list l) == seq_of_list q) = seq_of_list_tl l in
let _ : squash (mem x (seq_of_list l) == (x = y || mem x (seq_of_list q))) =
lemma_mem_inversion (seq_of_list l)
in
mem_seq_of_list x q
let rec intro_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
explode_and i s l))
(ensures (
equal (seq_of_list l) (slice s i (length s))))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl -> intro_of_list'' (i + 1) s tl
let intro_of_list' = intro_of_list''
let intro_of_list #_ s l = intro_of_list' 0 s l
let rec elim_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
slice s i (length s) == seq_of_list l))
(ensures (
explode_and i s l))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
match l with
| [] -> ()
| hd :: tl ->
lemma_seq_of_list_induction l;
elim_of_list'' (i + 1) s tl
let elim_of_list' = elim_of_list''
let elim_of_list #_ l = elim_of_list' 0 (seq_of_list l) l
let rec lemma_seq_to_list_permutation' (#a:eqtype) (s:seq a)
:Lemma (requires True) (ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s))) (decreases (length s))
= if length s > 0 then lemma_seq_to_list_permutation' (slice s 1 (length s))
let lemma_seq_to_list_permutation = lemma_seq_to_list_permutation'
let rec lemma_seq_of_list_permutation #a l | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_of_list_permutation (#a:eqtype) (l:list a)
:Lemma (forall x. List.Tot.Base.count x l == count x (seq_of_list l)) | [
"recursion"
] | FStar.Seq.Properties.lemma_seq_of_list_permutation | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.List.Tot.Base.count x l ==
FStar.Seq.Properties.count x (FStar.Seq.Properties.seq_of_list l)) | {
"end_col": 47,
"end_line": 605,
"start_col": 4,
"start_line": 602
} |
FStar.Pervasives.Lemma | val find_append_none' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f | val find_append_none' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
let rec find_append_none': #a: Type -> s1: seq a -> s2: seq a -> f: (a -> Tot bool)
-> Lemma (requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1)) = | false | null | true | fun #_ s1 s2 f ->
if Seq.length s1 = 0
then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Base.seq",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.find_append_none'",
"FStar.Seq.Properties.tail",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_append_none' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1)) | [
"recursion"
] | FStar.Seq.Properties.find_append_none' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (requires None? (FStar.Seq.Properties.find_l f s1))
(ensures
FStar.Seq.Properties.find_l f (FStar.Seq.Base.append s1 s2) ==
FStar.Seq.Properties.find_l f s2)
(decreases FStar.Seq.Base.length s1) | {
"end_col": 36,
"end_line": 343,
"start_col": 2,
"start_line": 339
} |
FStar.Pervasives.Lemma | val lemma_index_is_nth' (#a: Type) (s: seq a) (i: nat{i < length s})
: Lemma (requires True) (ensures (L.index (seq_to_list s) i == index s i)) (decreases i) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
) | val lemma_index_is_nth' (#a: Type) (s: seq a) (i: nat{i < length s})
: Lemma (requires True) (ensures (L.index (seq_to_list s) i == index s i)) (decreases i)
let rec lemma_index_is_nth': #a: Type -> s: seq a -> i: nat{i < length s}
-> Lemma (requires True) (ensures (L.index (seq_to_list s) i == index s i)) (decreases i) = | false | null | true | fun #_ s i -> if i = 0 then () else (lemma_index_is_nth' (slice s 1 (length s)) (i - 1)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Properties.lemma_index_is_nth'",
"FStar.Seq.Base.slice",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_index_is_nth' (#a: Type) (s: seq a) (i: nat{i < length s})
: Lemma (requires True) (ensures (L.index (seq_to_list s) i == index s i)) (decreases i) | [
"recursion"
] | FStar.Seq.Properties.lemma_index_is_nth' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat{i < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.index (FStar.Seq.Properties.seq_to_list s) i == FStar.Seq.Base.index s i
) (decreases i) | {
"end_col": 3,
"end_line": 433,
"start_col": 2,
"start_line": 429
} |
FStar.Pervasives.Lemma | val cons_head_tail
(#a: Type)
(s: seq a {length s > 0})
: Lemma
(requires True)
(ensures (s == cons (head s) (tail s)))
[SMTPat (cons (head s) (tail s))] | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1 | val cons_head_tail
(#a: Type)
(s: seq a {length s > 0})
: Lemma
(requires True)
(ensures (s == cons (head s) (tail s)))
[SMTPat (cons (head s) (tail s))]
let cons_head_tail #_ s = | false | null | true | let _:squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1 | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_split",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.create",
"FStar.Seq.Base.index",
"FStar.Seq.Base.lemma_eq_elim",
"Prims.unit",
"FStar.Seq.Base.lemma_index_create",
"FStar.Seq.Base.lemma_index_slice"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cons_head_tail
(#a: Type)
(s: seq a {length s > 0})
: Lemma
(requires True)
(ensures (s == cons (head s) (tail s)))
[SMTPat (cons (head s) (tail s))] | [] | FStar.Seq.Properties.cons_head_tail | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s > 0}
-> FStar.Pervasives.Lemma
(ensures
s == FStar.Seq.Properties.cons (FStar.Seq.Properties.head s) (FStar.Seq.Properties.tail s))
[
SMTPat (FStar.Seq.Properties.cons (FStar.Seq.Properties.head s)
(FStar.Seq.Properties.tail s))
] | {
"end_col": 17,
"end_line": 501,
"start_col": 25,
"start_line": 495
} |
FStar.Pervasives.Lemma | val lemma_seq_of_list_sorted (#a:Type) (f:a -> a -> Tot bool) (l:list a)
:Lemma (requires (List.Tot.Properties.sorted f l)) (ensures (sorted f (seq_of_list l))) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_seq_of_list_sorted #a f l
=
lemma_seq_of_list_induction l;
if List.Tot.length l > 1 then begin
lemma_seq_of_list_induction (List.Tot.Base.tl l);
lemma_seq_of_list_sorted f (List.Tot.Base.tl l)
end | val lemma_seq_of_list_sorted (#a:Type) (f:a -> a -> Tot bool) (l:list a)
:Lemma (requires (List.Tot.Properties.sorted f l)) (ensures (sorted f (seq_of_list l)))
let rec lemma_seq_of_list_sorted #a f l = | false | null | true | lemma_seq_of_list_induction l;
if List.Tot.length l > 1
then
(lemma_seq_of_list_induction (List.Tot.Base.tl l);
lemma_seq_of_list_sorted f (List.Tot.Base.tl l)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.bool",
"Prims.list",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"FStar.Seq.Properties.lemma_seq_of_list_sorted",
"FStar.List.Tot.Base.tl",
"Prims.unit",
"FStar.Seq.Properties.lemma_seq_of_list_induction"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s
let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1))
let cons_index_slice #_ s i j _ = lemma_eq_elim (cons (index s i) (slice s (i + 1) j)) (slice s i j)
let slice_is_empty #_ s i = lemma_eq_elim (slice s i i) Seq.empty
let slice_length #_ s = lemma_eq_elim (slice s 0 (length s)) s
let slice_slice #_ s i1 j1 i2 j2 = lemma_eq_elim (slice (slice s i1 j1) i2 j2) (slice s (i1 + i2) (i1 + j2))
let rec lemma_seq_of_list_index #_ l i
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd::tl -> if i = 0 then () else lemma_seq_of_list_index tl (i - 1)
let seq_of_list_tl #_ l = lemma_seq_of_list_induction l
let rec mem_seq_of_list #_ x l
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| y :: q ->
let _ : squash (head (seq_of_list l) == y) = () in
let _ : squash (tail (seq_of_list l) == seq_of_list q) = seq_of_list_tl l in
let _ : squash (mem x (seq_of_list l) == (x = y || mem x (seq_of_list q))) =
lemma_mem_inversion (seq_of_list l)
in
mem_seq_of_list x q
let rec intro_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
explode_and i s l))
(ensures (
equal (seq_of_list l) (slice s i (length s))))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl -> intro_of_list'' (i + 1) s tl
let intro_of_list' = intro_of_list''
let intro_of_list #_ s l = intro_of_list' 0 s l
let rec elim_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
slice s i (length s) == seq_of_list l))
(ensures (
explode_and i s l))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
match l with
| [] -> ()
| hd :: tl ->
lemma_seq_of_list_induction l;
elim_of_list'' (i + 1) s tl
let elim_of_list' = elim_of_list''
let elim_of_list #_ l = elim_of_list' 0 (seq_of_list l) l
let rec lemma_seq_to_list_permutation' (#a:eqtype) (s:seq a)
:Lemma (requires True) (ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s))) (decreases (length s))
= if length s > 0 then lemma_seq_to_list_permutation' (slice s 1 (length s))
let lemma_seq_to_list_permutation = lemma_seq_to_list_permutation'
let rec lemma_seq_of_list_permutation #a l
=
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| _::tl -> lemma_seq_of_list_permutation tl
let rec lemma_seq_of_list_sorted #a f l | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_of_list_sorted (#a:Type) (f:a -> a -> Tot bool) (l:list a)
:Lemma (requires (List.Tot.Properties.sorted f l)) (ensures (sorted f (seq_of_list l))) | [
"recursion"
] | FStar.Seq.Properties.lemma_seq_of_list_sorted | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> _: a -> Prims.bool) -> l: Prims.list a
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Properties.sorted f l)
(ensures FStar.Seq.Properties.sorted f (FStar.Seq.Properties.seq_of_list l)) | {
"end_col": 7,
"end_line": 613,
"start_col": 4,
"start_line": 609
} |
FStar.Pervasives.Lemma | val intro_of_list'' (#a: Type) (i: nat) (s: seq a) (l: list a)
: Lemma (requires (List.Tot.length l + i = length s /\ i <= length s /\ explode_and i s l))
(ensures (equal (seq_of_list l) (slice s i (length s))))
(decreases (List.Tot.length l)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec intro_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
explode_and i s l))
(ensures (
equal (seq_of_list l) (slice s i (length s))))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl -> intro_of_list'' (i + 1) s tl | val intro_of_list'' (#a: Type) (i: nat) (s: seq a) (l: list a)
: Lemma (requires (List.Tot.length l + i = length s /\ i <= length s /\ explode_and i s l))
(ensures (equal (seq_of_list l) (slice s i (length s))))
(decreases (List.Tot.length l))
let rec intro_of_list'': #a: Type -> i: nat -> s: seq a -> l: list a
-> Lemma (requires (List.Tot.length l + i = length s /\ i <= length s /\ explode_and i s l))
(ensures (equal (seq_of_list l) (slice s i (length s))))
(decreases (List.Tot.length l)) = | false | null | true | fun #_ i s l ->
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl -> intro_of_list'' (i + 1) s tl | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Prims.list",
"FStar.Seq.Properties.intro_of_list''",
"Prims.op_Addition",
"Prims.unit",
"FStar.Seq.Properties.lemma_seq_of_list_induction"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s
let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1))
let cons_index_slice #_ s i j _ = lemma_eq_elim (cons (index s i) (slice s (i + 1) j)) (slice s i j)
let slice_is_empty #_ s i = lemma_eq_elim (slice s i i) Seq.empty
let slice_length #_ s = lemma_eq_elim (slice s 0 (length s)) s
let slice_slice #_ s i1 j1 i2 j2 = lemma_eq_elim (slice (slice s i1 j1) i2 j2) (slice s (i1 + i2) (i1 + j2))
let rec lemma_seq_of_list_index #_ l i
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd::tl -> if i = 0 then () else lemma_seq_of_list_index tl (i - 1)
let seq_of_list_tl #_ l = lemma_seq_of_list_induction l
let rec mem_seq_of_list #_ x l
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| y :: q ->
let _ : squash (head (seq_of_list l) == y) = () in
let _ : squash (tail (seq_of_list l) == seq_of_list q) = seq_of_list_tl l in
let _ : squash (mem x (seq_of_list l) == (x = y || mem x (seq_of_list q))) =
lemma_mem_inversion (seq_of_list l)
in
mem_seq_of_list x q
let rec intro_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
explode_and i s l))
(ensures (
equal (seq_of_list l) (slice s i (length s))))
(decreases ( | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_of_list'' (#a: Type) (i: nat) (s: seq a) (l: list a)
: Lemma (requires (List.Tot.length l + i = length s /\ i <= length s /\ explode_and i s l))
(ensures (equal (seq_of_list l) (slice s i (length s))))
(decreases (List.Tot.length l)) | [
"recursion"
] | FStar.Seq.Properties.intro_of_list'' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: Prims.nat -> s: FStar.Seq.Base.seq a -> l: Prims.list a
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.length l + i = FStar.Seq.Base.length s /\ i <= FStar.Seq.Base.length s /\
FStar.Seq.Properties.explode_and i s l)
(ensures
FStar.Seq.Base.equal (FStar.Seq.Properties.seq_of_list l)
(FStar.Seq.Base.slice s i (FStar.Seq.Base.length s)))
(decreases FStar.List.Tot.Base.length l) | {
"end_col": 44,
"end_line": 564,
"start_col": 2,
"start_line": 560
} |
FStar.Pervasives.Lemma | val lemma_weaken_perm_right: #a:eqtype -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j /\ j <= k /\ k <= length s1}
-> Lemma
(requires (s1 == splice s2 i s1 j /\ permutation a (slice s2 i j) (slice s1 i j)))
(ensures (permutation a (slice s2 i k) (slice s1 i k))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k) | val lemma_weaken_perm_right: #a:eqtype -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j /\ j <= k /\ k <= length s1}
-> Lemma
(requires (s1 == splice s2 i s1 j /\ permutation a (slice s2 i j) (slice s1 i j)))
(ensures (permutation a (slice s2 i k) (slice s1 i k)))
let lemma_weaken_perm_right #_ s1 s2 i j k = | false | null | true | cut (equal (slice s2 i k) (append (slice s2 i j) (slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j) (slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Properties.lemma_append_count",
"FStar.Seq.Base.slice",
"Prims.unit",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_weaken_perm_right: #a:eqtype -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j /\ j <= k /\ k <= length s1}
-> Lemma
(requires (s1 == splice s2 i s1 j /\ permutation a (slice s2 i j) (slice s1 i j)))
(ensures (permutation a (slice s2 i k) (slice s1 i k))) | [] | FStar.Seq.Properties.lemma_weaken_perm_right | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
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 ->
j: Prims.nat ->
k: Prims.nat{i <= j /\ j <= k /\ k <= FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma
(requires
s1 == FStar.Seq.Properties.splice s2 i s1 j /\
FStar.Seq.Properties.permutation a
(FStar.Seq.Base.slice s2 i j)
(FStar.Seq.Base.slice s1 i j))
(ensures
FStar.Seq.Properties.permutation a
(FStar.Seq.Base.slice s2 i k)
(FStar.Seq.Base.slice s1 i k)) | {
"end_col": 50,
"end_line": 306,
"start_col": 2,
"start_line": 301
} |
FStar.Pervasives.Lemma | val sorted_feq (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let sorted_feq = sorted_feq' | val sorted_feq (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
let sorted_feq = | false | null | true | sorted_feq' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.sorted_feq'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sorted_feq (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s)) | [] | FStar.Seq.Properties.sorted_feq | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: a -> _: a -> Prims.bool) ->
g: (_: a -> _: a -> Prims.bool) ->
s: FStar.Seq.Base.seq a {forall (x: a) (y: a). f x y == g x y}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Properties.sorted f s <==> FStar.Seq.Properties.sorted g s) | {
"end_col": 28,
"end_line": 92,
"start_col": 17,
"start_line": 92
} |
FStar.Pervasives.Lemma | val lemma_append_inj_r: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a{length s1 = length t1 /\ length s2 = length t2 /\ equal (append s1 s2) (append t1 t2)} -> i:nat{i < length s2}
-> Lemma (ensures (index s2 i == index t2 i)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1))) | val lemma_append_inj_r: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a{length s1 = length t1 /\ length s2 = length t2 /\ equal (append s1 s2) (append t1 t2)} -> i:nat{i < length s2}
-> Lemma (ensures (index s2 i == index t2 i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i = | false | null | true | assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"Prims.op_LessThan",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_inj_r: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a{length s1 = length t1 /\ length s2 = length t2 /\ equal (append s1 s2) (append t1 t2)} -> i:nat{i < length s2}
-> Lemma (ensures (index s2 i == index t2 i)) | [] | FStar.Seq.Properties.lemma_append_inj_r | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
t1: FStar.Seq.Base.seq a ->
t2:
FStar.Seq.Base.seq a
{ FStar.Seq.Base.length s1 = FStar.Seq.Base.length t1 /\
FStar.Seq.Base.length s2 = FStar.Seq.Base.length t2 /\
FStar.Seq.Base.equal (FStar.Seq.Base.append s1 s2) (FStar.Seq.Base.append t1 t2) } ->
i: Prims.nat{i < FStar.Seq.Base.length s2}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index s2 i == FStar.Seq.Base.index t2 i) | {
"end_col": 63,
"end_line": 28,
"start_col": 2,
"start_line": 27
} |
FStar.Pervasives.Lemma | val lemma_append_count: #a:eqtype -> lo:seq a -> hi:seq a -> Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_append_count = lemma_append_count' | val lemma_append_count: #a:eqtype -> lo:seq a -> hi:seq a -> Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
let lemma_append_count = | false | null | true | lemma_append_count' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lemma_append_count'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_count: #a:eqtype -> lo:seq a -> hi:seq a -> Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi))) | [] | FStar.Seq.Properties.lemma_append_count | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | lo: FStar.Seq.Base.seq a -> hi: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.count x (FStar.Seq.Base.append lo hi) =
FStar.Seq.Properties.count x lo + FStar.Seq.Properties.count x hi) | {
"end_col": 44,
"end_line": 108,
"start_col": 25,
"start_line": 108
} |
FStar.Pervasives.Lemma | val lemma_append_len_disj: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a {(length s1 = length t1 \/ length s2 = length t2) /\ (equal (append s1 s2) (append t1 t2))}
-> Lemma (ensures (length s1 = length t1 /\ length s2 = length t2)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2) | val lemma_append_len_disj: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a {(length s1 = length t1 \/ length s2 = length t2) /\ (equal (append s1 s2) (append t1 t2))}
-> Lemma (ensures (length s1 = length t1 /\ length s2 = length t2))
let lemma_append_len_disj #_ s1 s2 t1 t2 = | false | null | true | cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.l_and",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"Prims.cut",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_len_disj: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a {(length s1 = length t1 \/ length s2 = length t2) /\ (equal (append s1 s2) (append t1 t2))}
-> Lemma (ensures (length s1 = length t1 /\ length s2 = length t2)) | [] | FStar.Seq.Properties.lemma_append_len_disj | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
t1: FStar.Seq.Base.seq a ->
t2:
FStar.Seq.Base.seq a
{ (FStar.Seq.Base.length s1 = FStar.Seq.Base.length t1 \/
FStar.Seq.Base.length s2 = FStar.Seq.Base.length t2) /\
FStar.Seq.Base.equal (FStar.Seq.Base.append s1 s2) (FStar.Seq.Base.append t1 t2) }
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.length s1 = FStar.Seq.Base.length t1 /\
FStar.Seq.Base.length s2 = FStar.Seq.Base.length t2) | {
"end_col": 54,
"end_line": 32,
"start_col": 2,
"start_line": 31
} |
FStar.Pervasives.Lemma | val lemma_append_inj: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a {length s1 = length t1 \/ length s2 = length t2}
-> Lemma (requires (equal (append s1 s2) (append t1 t2)))
(ensures (equal s1 t1 /\ equal s2 t2)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2) | val lemma_append_inj: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a {length s1 = length t1 \/ length s2 = length t2}
-> Lemma (requires (equal (append s1 s2) (append t1 t2)))
(ensures (equal s1 t1 /\ equal s2 t2))
let lemma_append_inj #_ s1 s2 t1 t2 = | false | null | true | lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i: nat{i < length s1})
#(fun i -> index s1 i == index t1 i)
(lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i: nat{i < length s2})
#(fun i -> index s2 i == index t2 i)
(lemma_append_inj_r s1 s2 t1 t2) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Classical.forall_intro",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Properties.lemma_append_inj_r",
"Prims.unit",
"FStar.Seq.Properties.lemma_append_inj_l",
"FStar.Seq.Properties.lemma_append_len_disj"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_inj: #a:Type -> s1:seq a -> s2:seq a -> t1:seq a -> t2:seq a {length s1 = length t1 \/ length s2 = length t2}
-> Lemma (requires (equal (append s1 s2) (append t1 t2)))
(ensures (equal s1 t1 /\ equal s2 t2)) | [] | FStar.Seq.Properties.lemma_append_inj | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
t1: FStar.Seq.Base.seq a ->
t2:
FStar.Seq.Base.seq a
{ FStar.Seq.Base.length s1 = FStar.Seq.Base.length t1 \/
FStar.Seq.Base.length s2 = FStar.Seq.Base.length t2 }
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.equal (FStar.Seq.Base.append s1 s2) (FStar.Seq.Base.append t1 t2))
(ensures FStar.Seq.Base.equal s1 t1 /\ FStar.Seq.Base.equal s2 t2) | {
"end_col": 124,
"end_line": 37,
"start_col": 2,
"start_line": 35
} |
FStar.Pervasives.Lemma | val perm_len (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let perm_len = perm_len' | val perm_len (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
let perm_len = | false | null | true | perm_len' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.perm_len'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val perm_len (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2)) | [] | FStar.Seq.Properties.perm_len | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma (requires FStar.Seq.Properties.permutation a s1 s2)
(ensures FStar.Seq.Base.length s1 == FStar.Seq.Base.length s2) | {
"end_col": 24,
"end_line": 238,
"start_col": 15,
"start_line": 238
} |
FStar.Pervasives.Lemma | val seq_mem_k: #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
[SMTPat (mem (Seq.index s n) s)] | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let seq_mem_k = seq_mem_k' | val seq_mem_k: #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
[SMTPat (mem (Seq.index s n) s)]
let seq_mem_k = | false | null | true | seq_mem_k' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.seq_mem_k'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val seq_mem_k: #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
[SMTPat (mem (Seq.index s n) s)] | [] | FStar.Seq.Properties.seq_mem_k | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> n: Prims.nat{n < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Properties.mem (FStar.Seq.Base.index s n) s)
[SMTPat (FStar.Seq.Properties.mem (FStar.Seq.Base.index s n) s)] | {
"end_col": 26,
"end_line": 383,
"start_col": 16,
"start_line": 383
} |
FStar.Pervasives.Lemma | val lemma_seq_list_bij: #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_seq_list_bij = lemma_seq_list_bij' | val lemma_seq_list_bij: #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
let lemma_seq_list_bij = | false | null | true | lemma_seq_list_bij' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lemma_seq_list_bij'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_list_bij: #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s)) | [] | FStar.Seq.Properties.lemma_seq_list_bij | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Properties.seq_of_list (FStar.Seq.Properties.seq_to_list s) == s) | {
"end_col": 44,
"end_line": 409,
"start_col": 25,
"start_line": 409
} |
Prims.Tot | val contains (#a:Type) (s:seq a) (x:a) : Tot Type0 | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x | val contains (#a:Type) (s:seq a) (x:a) : Tot Type0
let contains #a s x = | false | null | false | exists (k: nat). k < Seq.length s /\ Seq.index s k == x | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"total"
] | [
"FStar.Seq.Base.seq",
"Prims.l_Exists",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.eq2",
"FStar.Seq.Base.index"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val contains (#a:Type) (s:seq a) (x:a) : Tot Type0 | [] | FStar.Seq.Properties.contains | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> x: a -> Type0 | {
"end_col": 56,
"end_line": 438,
"start_col": 2,
"start_line": 438
} |
FStar.Pervasives.Lemma | val lemma_tail_append: #a:Type -> s1:seq a{length s1 > 0} -> s2:seq a -> Lemma
(tail (append s1 s2) == append (tail s1) s2) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) | val lemma_tail_append: #a:Type -> s1:seq a{length s1 > 0} -> s2:seq a -> Lemma
(tail (append s1 s2) == append (tail s1) s2)
let lemma_tail_append #_ s1 s2 = | false | null | true | cut (equal (tail (append s1 s2)) (append (tail s1) s2)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.tail",
"FStar.Seq.Base.append",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = () | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_tail_append: #a:Type -> s1:seq a{length s1 > 0} -> s2:seq a -> Lemma
(tail (append s1 s2) == append (tail s1) s2) | [] | FStar.Seq.Properties.lemma_tail_append | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a {FStar.Seq.Base.length s1 > 0} -> s2: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.tail (FStar.Seq.Base.append s1 s2) ==
FStar.Seq.Base.append (FStar.Seq.Properties.tail s1) s2) | {
"end_col": 88,
"end_line": 41,
"start_col": 33,
"start_line": 41
} |
FStar.Pervasives.Lemma | val mem_index' (#a: eqtype) (x: a) (s: seq a)
: Lemma (requires (mem x s)) (ensures (exists i. index s i == x)) (decreases (length s)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s) | val mem_index' (#a: eqtype) (x: a) (s: seq a)
: Lemma (requires (mem x s)) (ensures (exists i. index s i == x)) (decreases (length s))
let rec mem_index' (#a: eqtype) (x: a) (s: seq a)
: Lemma (requires (mem x s)) (ensures (exists i. index s i == x)) (decreases (length s)) = | false | null | true | if length s = 0 then () else if head s = x then () else mem_index' x (tail s) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.bool",
"FStar.Seq.Properties.head",
"FStar.Seq.Properties.mem_index'",
"FStar.Seq.Properties.tail",
"Prims.unit",
"Prims.b2t",
"FStar.Seq.Properties.mem",
"Prims.squash",
"Prims.l_Exists",
"Prims.nat",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mem_index' (#a: eqtype) (x: a) (s: seq a)
: Lemma (requires (mem x s)) (ensures (exists i. index s i == x)) (decreases (length s)) | [
"recursion"
] | FStar.Seq.Properties.mem_index' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma (requires FStar.Seq.Properties.mem x s)
(ensures exists (i: Prims.nat{i < FStar.Seq.Base.length s}). FStar.Seq.Base.index s i == x)
(decreases FStar.Seq.Base.length s) | {
"end_col": 32,
"end_line": 58,
"start_col": 6,
"start_line": 56
} |
FStar.Pervasives.Lemma | val find_l_none_no_index (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let find_l_none_no_index = find_l_none_no_index' | val find_l_none_no_index (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
let find_l_none_no_index = | false | null | true | find_l_none_no_index' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Properties.find_l_none_no_index'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_l_none_no_index (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s)) | [] | FStar.Seq.Properties.find_l_none_no_index | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (requires None? (FStar.Seq.Properties.find_l f s))
(ensures
forall (i: Prims.nat{i < FStar.Seq.Base.length s}).
Prims.op_Negation (f (FStar.Seq.Base.index s i)))
(decreases FStar.Seq.Base.length s) | {
"end_col": 48,
"end_line": 493,
"start_col": 27,
"start_line": 493
} |
FStar.Pervasives.Lemma | val lemma_slice_first_in_append: #a:Type -> s1:seq a -> s2:seq a -> i:nat{i <= length s1} -> Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_slice_first_in_append = lemma_slice_first_in_append' | val lemma_slice_first_in_append: #a:Type -> s1:seq a -> s2:seq a -> i:nat{i <= length s1} -> Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
let lemma_slice_first_in_append = | false | null | true | lemma_slice_first_in_append' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lemma_slice_first_in_append'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_slice_first_in_append: #a:Type -> s1:seq a -> s2:seq a -> i:nat{i <= length s1} -> Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2))) | [] | FStar.Seq.Properties.lemma_slice_first_in_append | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | 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.equal (FStar.Seq.Base.slice (FStar.Seq.Base.append s1 s2)
i
(FStar.Seq.Base.length (FStar.Seq.Base.append s1 s2)))
(FStar.Seq.Base.append (FStar.Seq.Base.slice s1 i (FStar.Seq.Base.length s1)) s2)) | {
"end_col": 62,
"end_line": 72,
"start_col": 34,
"start_line": 72
} |
FStar.Pervasives.Lemma | val sorted_feq' (#a: Type) (f g: (a -> a -> Tot bool)) (s: seq a {forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s)) (decreases (length s)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s) | val sorted_feq' (#a: Type) (f g: (a -> a -> Tot bool)) (s: seq a {forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s)) (decreases (length s))
let rec sorted_feq' (#a: Type) (f g: (a -> a -> Tot bool)) (s: seq a {forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s)) (decreases (length s)) = | false | null | true | if length s <= 1 then () else sorted_feq' f g (tail s) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.bool",
"FStar.Seq.Base.seq",
"Prims.l_Forall",
"Prims.eq2",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.sorted_feq'",
"FStar.Seq.Properties.tail",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Prims.b2t",
"FStar.Seq.Properties.sorted",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sorted_feq' (#a: Type) (f g: (a -> a -> Tot bool)) (s: seq a {forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s)) (decreases (length s)) | [
"recursion"
] | FStar.Seq.Properties.sorted_feq' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: a -> _: a -> Prims.bool) ->
g: (_: a -> _: a -> Prims.bool) ->
s: FStar.Seq.Base.seq a {forall (x: a) (y: a). f x y == g x y}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Properties.sorted f s <==> FStar.Seq.Properties.sorted g s)
(decreases FStar.Seq.Base.length s) | {
"end_col": 34,
"end_line": 90,
"start_col": 5,
"start_line": 89
} |
FStar.Pervasives.Lemma | val lemma_append_count_aux: #a:eqtype -> x:a -> lo:seq a -> hi:seq a -> Lemma
(requires True)
(ensures (count x (append lo hi) = (count x lo + count x hi))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi | val lemma_append_count_aux: #a:eqtype -> x:a -> lo:seq a -> hi:seq a -> Lemma
(requires True)
(ensures (count x (append lo hi) = (count x lo + count x hi)))
let lemma_append_count_aux #_ _ lo hi = | false | null | true | lemma_append_count lo hi | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.lemma_append_count",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_append_count_aux: #a:eqtype -> x:a -> lo:seq a -> hi:seq a -> Lemma
(requires True)
(ensures (count x (append lo hi) = (count x lo + count x hi))) | [] | FStar.Seq.Properties.lemma_append_count_aux | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> lo: FStar.Seq.Base.seq a -> hi: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.count x (FStar.Seq.Base.append lo hi) =
FStar.Seq.Properties.count x lo + FStar.Seq.Properties.count x hi) | {
"end_col": 64,
"end_line": 110,
"start_col": 40,
"start_line": 110
} |
FStar.Pervasives.Lemma | val lemma_slice_first_in_append' (#a: Type) (s1 s2: seq a) (i: nat{i <= length s1})
: Lemma
(ensures
(equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)
)) (decreases (length s1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1) | val lemma_slice_first_in_append' (#a: Type) (s1 s2: seq a) (i: nat{i <= length s1})
: Lemma
(ensures
(equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)
)) (decreases (length s1))
let rec lemma_slice_first_in_append' (#a: Type) (s1 s2: seq a) (i: nat{i <= length s1})
: Lemma
(ensures
(equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)
)) (decreases (length s1)) = | false | null | true | if i = 0 then () else lemma_slice_first_in_append' (tail s1) s2 (i - 1) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Properties.lemma_slice_first_in_append'",
"FStar.Seq.Properties.tail",
"Prims.op_Subtraction",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_slice_first_in_append' (#a: Type) (s1 s2: seq a) (i: nat{i <= length s1})
: Lemma
(ensures
(equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)
)) (decreases (length s1)) | [
"recursion"
] | FStar.Seq.Properties.lemma_slice_first_in_append' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | 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.equal (FStar.Seq.Base.slice (FStar.Seq.Base.append s1 s2)
i
(FStar.Seq.Base.length (FStar.Seq.Base.append s1 s2)))
(FStar.Seq.Base.append (FStar.Seq.Base.slice s1 i (FStar.Seq.Base.length s1)) s2))
(decreases FStar.Seq.Base.length s1) | {
"end_col": 56,
"end_line": 70,
"start_col": 2,
"start_line": 69
} |
FStar.Pervasives.Lemma | val lemma_count_slice: #a:eqtype -> s:seq a -> i:nat{i<=length s} -> Lemma
(requires True)
(ensures (forall x. count x s = count x (slice s 0 i) + count x (slice s i (length s)))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s)) | val lemma_count_slice: #a:eqtype -> s:seq a -> i:nat{i<=length s} -> Lemma
(requires True)
(ensures (forall x. count x s = count x (slice s 0 i) + count x (slice s i (length s))))
let lemma_count_slice #_ s i = | false | null | true | cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_append_count",
"FStar.Seq.Base.slice",
"Prims.unit",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_count_slice: #a:eqtype -> s:seq a -> i:nat{i<=length s} -> Lemma
(requires True)
(ensures (forall x. count x s = count x (slice s 0 i) + count x (slice s i (length s)))) | [] | FStar.Seq.Properties.lemma_count_slice | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat{i <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.count x s =
FStar.Seq.Properties.count x (FStar.Seq.Base.slice s 0 i) +
FStar.Seq.Properties.count x (FStar.Seq.Base.slice s i (FStar.Seq.Base.length s))) | {
"end_col": 57,
"end_line": 129,
"start_col": 2,
"start_line": 128
} |
FStar.Pervasives.Lemma | val cons_perm: #a:eqtype -> tl:seq a -> s:seq a{length s > 0} ->
Lemma (requires (permutation a tl (tail s)))
(ensures (permutation a (cons (head s) tl) s)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let cons_perm #_ tl s = lemma_tl (head s) tl | val cons_perm: #a:eqtype -> tl:seq a -> s:seq a{length s > 0} ->
Lemma (requires (permutation a tl (tail s)))
(ensures (permutation a (cons (head s) tl) s))
let cons_perm #_ tl s = | false | null | true | lemma_tl (head s) tl | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_tl",
"FStar.Seq.Properties.head",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cons_perm: #a:eqtype -> tl:seq a -> s:seq a{length s > 0} ->
Lemma (requires (permutation a tl (tail s)))
(ensures (permutation a (cons (head s) tl) s)) | [] | FStar.Seq.Properties.cons_perm | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | tl: FStar.Seq.Base.seq a -> s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s > 0}
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Properties.permutation a tl (FStar.Seq.Properties.tail s))
(ensures
FStar.Seq.Properties.permutation a
(FStar.Seq.Properties.cons (FStar.Seq.Properties.head s) tl)
s) | {
"end_col": 44,
"end_line": 240,
"start_col": 24,
"start_line": 240
} |
FStar.Pervasives.Lemma | val lemma_swap_permutes (#a:eqtype) (s:seq a) (i:nat{i<length s}) (j:nat{i <= j && j<length s})
: Lemma (permutation a s (swap s i j)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j) | val lemma_swap_permutes (#a:eqtype) (s:seq a) (i:nat{i<length s}) (j:nat{i <= j && j<length s})
: Lemma (permutation a s (swap s i j))
let lemma_swap_permutes #a s i j = | false | null | true | FStar.Classical.forall_intro #a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"FStar.Classical.forall_intro",
"Prims.op_Equality",
"FStar.Seq.Properties.count",
"FStar.Seq.Properties.swap",
"FStar.Seq.Properties.lemma_swap_permutes_aux",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_swap_permutes (#a:eqtype) (s:seq a) (i:nat{i<length s}) (j:nat{i <= j && j<length s})
: Lemma (permutation a s (swap s i j)) | [] | FStar.Seq.Properties.lemma_swap_permutes | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
i: Prims.nat{i < FStar.Seq.Base.length s} ->
j: Prims.nat{i <= j && j < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Properties.permutation a s (FStar.Seq.Properties.swap s i j)) | {
"end_col": 51,
"end_line": 202,
"start_col": 4,
"start_line": 199
} |
FStar.Pervasives.Lemma | val swap_frame_lo' : #a:Type -> s:seq a -> lo:nat -> i':nat {lo <= i'} -> i:nat{i' <= i} -> j:nat{i <= j && j < length s}
-> Lemma (ensures (slice s lo i' == slice (swap s i j) lo i')) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i')) | val swap_frame_lo' : #a:Type -> s:seq a -> lo:nat -> i':nat {lo <= i'} -> i:nat{i' <= i} -> j:nat{i <= j && j < length s}
-> Lemma (ensures (slice s lo i' == slice (swap s i j) lo i'))
let swap_frame_lo' #_ s lo i' i j = | false | null | true | cut (equal (slice s lo i') (slice (swap s i j) lo i')) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Properties.swap",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val swap_frame_lo' : #a:Type -> s:seq a -> lo:nat -> i':nat {lo <= i'} -> i:nat{i' <= i} -> j:nat{i <= j && j < length s}
-> Lemma (ensures (slice s lo i' == slice (swap s i j) lo i')) | [] | FStar.Seq.Properties.swap_frame_lo' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
lo: Prims.nat ->
i': Prims.nat{lo <= i'} ->
i: Prims.nat{i' <= i} ->
j: Prims.nat{i <= j && j < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice s lo i' == FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) lo i') | {
"end_col": 90,
"end_line": 262,
"start_col": 36,
"start_line": 262
} |
FStar.Pervasives.Lemma | val splice_refl : #a:Type -> s:seq a -> i:nat -> j:nat{i <= j && j <= length s}
-> Lemma
(ensures (s == splice s i s j)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let splice_refl #_ s i j = cut (equal s (splice s i s j)) | val splice_refl : #a:Type -> s:seq a -> i:nat -> j:nat{i <= j && j <= length s}
-> Lemma
(ensures (s == splice s i s j))
let splice_refl #_ s i j = | false | null | true | cut (equal s (splice s i s j)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.splice",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val splice_refl : #a:Type -> s:seq a -> i:nat -> j:nat{i <= j && j <= length s}
-> Lemma
(ensures (s == splice s i s j)) | [] | FStar.Seq.Properties.splice_refl | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i <= j && j <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma (ensures s == FStar.Seq.Properties.splice s i s j) | {
"end_col": 57,
"end_line": 273,
"start_col": 27,
"start_line": 273
} |
FStar.Pervasives.Lemma | val lemma_swap_permutes_slice : #a:eqtype -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma (ensures (permutation a (slice s start len) (slice (swap s i j) start len))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start) | val lemma_swap_permutes_slice : #a:eqtype -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma (ensures (permutation a (slice s start len) (slice (swap s i j) start len)))
let lemma_swap_permutes_slice #_ s start i j len = | false | null | true | lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_swap_permutes",
"FStar.Seq.Base.slice",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Seq.Properties.lemma_swap_slice_commute"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_swap_permutes_slice : #a:eqtype -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma (ensures (permutation a (slice s start len) (slice (swap s i j) start len))) | [] | FStar.Seq.Properties.lemma_swap_permutes_slice | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
start: Prims.nat ->
i: Prims.nat{start <= i} ->
j: Prims.nat{i <= j} ->
len: Prims.nat{j < len && len <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.permutation a
(FStar.Seq.Base.slice s start len)
(FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) start len)) | {
"end_col": 65,
"end_line": 271,
"start_col": 2,
"start_line": 270
} |
FStar.Pervasives.Lemma | val append_permutations: #a:eqtype -> s1:seq a -> s2:seq a -> s1':seq a -> s2':seq a -> Lemma
(requires permutation a s1 s1' /\ permutation a s2 s2')
(ensures permutation a (append s1 s2) (append s1' s2')) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
) | val append_permutations: #a:eqtype -> s1:seq a -> s2:seq a -> s1':seq a -> s2':seq a -> Lemma
(requires permutation a s1 s1' /\ permutation a s2 s2')
(ensures permutation a (append s1 s2) (append s1' s2'))
let append_permutations #a s1 s2 s1' s2' = | false | null | true | (lemma_append_count s1 s2;
lemma_append_count s1' s2') | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.lemma_append_count",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val append_permutations: #a:eqtype -> s1:seq a -> s2:seq a -> s1':seq a -> s2':seq a -> Lemma
(requires permutation a s1 s1' /\ permutation a s2 s2')
(ensures permutation a (append s1 s2) (append s1' s2')) | [] | FStar.Seq.Properties.append_permutations | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
s1': FStar.Seq.Base.seq a ->
s2': FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Properties.permutation a s1 s1' /\ FStar.Seq.Properties.permutation a s2 s2')
(ensures
FStar.Seq.Properties.permutation a
(FStar.Seq.Base.append s1 s2)
(FStar.Seq.Base.append s1' s2')) | {
"end_col": 3,
"end_line": 196,
"start_col": 2,
"start_line": 193
} |
FStar.Pervasives.Lemma | val lemma_tail_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma
(requires True)
(ensures (tail (slice s i j) == slice s (i + 1) j))
[SMTPat (tail (slice s i j))] | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j)) | val lemma_tail_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma
(requires True)
(ensures (tail (slice s i j) == slice s (i + 1) j))
[SMTPat (tail (slice s i j))]
let lemma_tail_slice #_ s i j = | false | null | true | cut (equal (tail (slice s i j)) (slice s (i + 1) j)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.tail",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_tail_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i < j && j <= length s}
-> Lemma
(requires True)
(ensures (tail (slice s i j) == slice s (i + 1) j))
[SMTPat (tail (slice s i j))] | [] | FStar.Seq.Properties.lemma_tail_slice | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | 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.Properties.tail (FStar.Seq.Base.slice s i j) == FStar.Seq.Base.slice s (i + 1) j)
[SMTPat (FStar.Seq.Properties.tail (FStar.Seq.Base.slice s i j))] | {
"end_col": 54,
"end_line": 284,
"start_col": 2,
"start_line": 284
} |
FStar.Pervasives.Lemma | val find_append_none_s2: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let find_append_none_s2 = find_append_none_s2' | val find_append_none_s2: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
let find_append_none_s2 = | false | null | true | find_append_none_s2' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.find_append_none_s2'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_append_none_s2: #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1)) | [] | FStar.Seq.Properties.find_append_none_s2 | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (requires None? (FStar.Seq.Properties.find_l f s2))
(ensures
FStar.Seq.Properties.find_l f (FStar.Seq.Base.append s1 s2) ==
FStar.Seq.Properties.find_l f s1) | {
"end_col": 46,
"end_line": 359,
"start_col": 26,
"start_line": 359
} |
FStar.Pervasives.Lemma | val lemma_ordering_lo_snoc: #a:eqtype -> f:tot_ord a -> s:seq a -> i:nat -> j:nat{i <= j && j < length s} -> pv:a
-> Lemma (requires ((forall y. mem y (slice s i j) ==> f y pv) /\ f (index s j) pv))
(ensures ((forall y. mem y (slice s i (j + 1)) ==> f y pv))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j)) | val lemma_ordering_lo_snoc: #a:eqtype -> f:tot_ord a -> s:seq a -> i:nat -> j:nat{i <= j && j < length s} -> pv:a
-> Lemma (requires ((forall y. mem y (slice s i j) ==> f y pv) /\ f (index s j) pv))
(ensures ((forall y. mem y (slice s i (j + 1)) ==> f y pv)))
let lemma_ordering_lo_snoc #_ f s i j pv = | false | null | true | cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Properties.tot_ord",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_mem_append",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.create",
"FStar.Seq.Base.index",
"Prims.unit",
"Prims.cut",
"FStar.Seq.Base.equal",
"Prims.op_Addition",
"FStar.Seq.Base.append"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_ordering_lo_snoc: #a:eqtype -> f:tot_ord a -> s:seq a -> i:nat -> j:nat{i <= j && j < length s} -> pv:a
-> Lemma (requires ((forall y. mem y (slice s i j) ==> f y pv) /\ f (index s j) pv))
(ensures ((forall y. mem y (slice s i (j + 1)) ==> f y pv))) | [] | FStar.Seq.Properties.lemma_ordering_lo_snoc | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: FStar.Seq.Properties.tot_ord a ->
s: FStar.Seq.Base.seq a ->
i: Prims.nat ->
j: Prims.nat{i <= j && j < FStar.Seq.Base.length s} ->
pv: a
-> FStar.Pervasives.Lemma
(requires
(forall (y: a). FStar.Seq.Properties.mem y (FStar.Seq.Base.slice s i j) ==> f y pv) /\
f (FStar.Seq.Base.index s j) pv)
(ensures
forall (y: a). FStar.Seq.Properties.mem y (FStar.Seq.Base.slice s i (j + 1)) ==> f y pv) | {
"end_col": 55,
"end_line": 254,
"start_col": 2,
"start_line": 253
} |
FStar.Pervasives.Lemma | val lemma_snoc_inj: #a:Type -> s1:seq a -> s2:seq a -> v1:a -> v2:a
-> Lemma (requires (equal (snoc s1 v1) (snoc s2 v2)))
(ensures (v1 == v2 /\ equal s1 s2)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2) | val lemma_snoc_inj: #a:Type -> s1:seq a -> s2:seq a -> v1:a -> v2:a
-> Lemma (requires (equal (snoc s1 v1) (snoc s2 v2)))
(ensures (v1 == v2 /\ equal s1 s2))
let lemma_snoc_inj #_ s1 s2 v1 v2 = | false | null | true | let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert (head t1 == head t2) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Properties.head",
"Prims.unit",
"FStar.Seq.Properties.lemma_append_inj",
"FStar.Seq.Base.create"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1 | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_snoc_inj: #a:Type -> s1:seq a -> s2:seq a -> v1:a -> v2:a
-> Lemma (requires (equal (snoc s1 v1) (snoc s2 v2)))
(ensures (v1 == v2 /\ equal s1 s2)) | [] | FStar.Seq.Properties.lemma_snoc_inj | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> v1: a -> v2: a
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.equal (FStar.Seq.Properties.snoc s1 v1) (FStar.Seq.Properties.snoc s2 v2))
(ensures v1 == v2 /\ FStar.Seq.Base.equal s1 s2) | {
"end_col": 29,
"end_line": 319,
"start_col": 35,
"start_line": 315
} |
FStar.Pervasives.Lemma | val lemma_list_seq_bij' (#a: Type) (l: list a)
: Lemma (requires (True)) (ensures (seq_to_list (seq_of_list l) == l)) (decreases (L.length l)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
) | val lemma_list_seq_bij' (#a: Type) (l: list a)
: Lemma (requires (True)) (ensures (seq_to_list (seq_of_list l) == l)) (decreases (L.length l))
let rec lemma_list_seq_bij': #a: Type -> l: list a
-> Lemma (requires (True)) (ensures (seq_to_list (seq_of_list l) == l)) (decreases (L.length l)) = | false | null | true | fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0
then ()
else
(lemma_list_seq_bij' (L.tl l);
assert (equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.list",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.bool",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.seq_of_list",
"FStar.List.Tot.Base.tl",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"Prims.unit",
"FStar.Seq.Properties.lemma_list_seq_bij'",
"FStar.Seq.Properties.lemma_seq_of_list_induction"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_list_seq_bij' (#a: Type) (l: list a)
: Lemma (requires (True)) (ensures (seq_to_list (seq_of_list l) == l)) (decreases (L.length l)) | [
"recursion"
] | FStar.Seq.Properties.lemma_list_seq_bij' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Properties.seq_to_list (FStar.Seq.Properties.seq_of_list l) == l)
(decreases FStar.List.Tot.Base.length l) | {
"end_col": 3,
"end_line": 421,
"start_col": 2,
"start_line": 415
} |
FStar.Pervasives.Lemma | val lemma_weaken_frame_right : #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j && j <= k && k <= length s1}
-> Lemma
(requires (s1 == splice s2 i s1 j))
(ensures (s1 == splice s2 i s1 k)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k)) | val lemma_weaken_frame_right : #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j && j <= k && k <= length s1}
-> Lemma
(requires (s1 == splice s2 i s1 j))
(ensures (s1 == splice s2 i s1 k))
let lemma_weaken_frame_right #_ s1 s2 i j k = | false | null | true | cut (equal s1 (splice s2 i s1 k)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.splice",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_weaken_frame_right : #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat -> k:nat{i <= j && j <= k && k <= length s1}
-> Lemma
(requires (s1 == splice s2 i s1 j))
(ensures (s1 == splice s2 i s1 k)) | [] | FStar.Seq.Properties.lemma_weaken_frame_right | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
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 ->
j: Prims.nat ->
k: Prims.nat{i <= j && j <= k && k <= FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma (requires s1 == FStar.Seq.Properties.splice s2 i s1 j)
(ensures s1 == FStar.Seq.Properties.splice s2 i s1 k) | {
"end_col": 79,
"end_line": 286,
"start_col": 46,
"start_line": 286
} |
FStar.Pervasives.Lemma | val lemma_tail_snoc: #a:Type -> s:Seq.seq a{Seq.length s > 0} -> x:a
-> Lemma (ensures (tail (snoc s x) == snoc (tail s) x)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1 | val lemma_tail_snoc: #a:Type -> s:Seq.seq a{Seq.length s > 0} -> x:a
-> Lemma (ensures (tail (snoc s x) == snoc (tail s) x))
let lemma_tail_snoc #_ s x = | false | null | true | lemma_slice_first_in_append s (Seq.create 1 x) 1 | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_slice_first_in_append",
"FStar.Seq.Base.create",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = () | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_tail_snoc: #a:Type -> s:Seq.seq a{Seq.length s > 0} -> x:a
-> Lemma (ensures (tail (snoc s x) == snoc (tail s) x)) | [] | FStar.Seq.Properties.lemma_tail_snoc | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s > 0} -> x: a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.tail (FStar.Seq.Properties.snoc s x) ==
FStar.Seq.Properties.snoc (FStar.Seq.Properties.tail s) x) | {
"end_col": 77,
"end_line": 313,
"start_col": 29,
"start_line": 313
} |
FStar.Pervasives.Lemma | val find_snoc: #a:Type -> s:Seq.seq a -> x:a -> f:(a -> Tot bool)
-> Lemma (ensures (let res = find_l f (snoc s x) in
match res with
| None -> find_l f s == None /\ not (f x)
| Some y -> res == find_l f s \/ (f x /\ x==y))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f | val find_snoc: #a:Type -> s:Seq.seq a -> x:a -> f:(a -> Tot bool)
-> Lemma (ensures (let res = find_l f (snoc s x) in
match res with
| None -> find_l f s == None /\ not (f x)
| Some y -> res == find_l f s \/ (f x /\ x==y)))
let find_snoc #_ s x f = | false | null | true | if Some? (find_l f s)
then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.bool",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Properties.find_l",
"FStar.Seq.Properties.find_append_some",
"FStar.Seq.Base.create",
"FStar.Seq.Properties.find_append_none",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_snoc: #a:Type -> s:Seq.seq a -> x:a -> f:(a -> Tot bool)
-> Lemma (ensures (let res = find_l f (snoc s x) in
match res with
| None -> find_l f s == None /\ not (f x)
| Some y -> res == find_l f s \/ (f x /\ x==y))) | [] | FStar.Seq.Properties.find_snoc | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> x: a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma
(ensures
(let res = FStar.Seq.Properties.find_l f (FStar.Seq.Properties.snoc s x) in
(match res with
| FStar.Pervasives.Native.None #_ ->
FStar.Seq.Properties.find_l f s == FStar.Pervasives.Native.None /\
Prims.op_Negation (f x)
| FStar.Pervasives.Native.Some #_ y ->
res == FStar.Seq.Properties.find_l f s \/ f x /\ x == y)
<:
Type0)) | {
"end_col": 44,
"end_line": 363,
"start_col": 2,
"start_line": 362
} |
FStar.Pervasives.Lemma | val lemma_seq_of_list_induction (#a:Type) (l:list a)
:Lemma (requires True)
(ensures (let s = seq_of_list l in
match l with
| [] -> Seq.equal s empty
| hd::tl -> s == cons hd (seq_of_list tl) /\
head s == hd /\ tail s == (seq_of_list tl))) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl) | val lemma_seq_of_list_induction (#a:Type) (l:list a)
:Lemma (requires True)
(ensures (let s = seq_of_list l in
match l with
| [] -> Seq.equal s empty
| hd::tl -> s == cons hd (seq_of_list tl) /\
head s == hd /\ tail s == (seq_of_list tl)))
let lemma_seq_of_list_induction #_ l = | false | null | true | match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd :: tl ->
assert_norm (seq_of_list (hd :: tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.list",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.length",
"Prims.int",
"FStar.Seq.Properties.seq_of_list",
"FStar.Seq.Base.empty",
"FStar.Seq.Properties.lemma_tl",
"Prims.unit",
"Prims.Cons",
"FStar.Seq.Base.op_At_Bar",
"FStar.Seq.Base.create"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_of_list_induction (#a:Type) (l:list a)
:Lemma (requires True)
(ensures (let s = seq_of_list l in
match l with
| [] -> Seq.equal s empty
| hd::tl -> s == cons hd (seq_of_list tl) /\
head s == hd /\ tail s == (seq_of_list tl))) | [] | FStar.Seq.Properties.lemma_seq_of_list_induction | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
(let s = FStar.Seq.Properties.seq_of_list l in
(match l with
| Prims.Nil #_ -> FStar.Seq.Base.equal s FStar.Seq.Base.empty
| Prims.Cons #_ hd tl ->
s == FStar.Seq.Properties.cons hd (FStar.Seq.Properties.seq_of_list tl) /\
FStar.Seq.Properties.head s == hd /\
FStar.Seq.Properties.tail s == FStar.Seq.Properties.seq_of_list tl)
<:
Type0)) | {
"end_col": 34,
"end_line": 392,
"start_col": 4,
"start_line": 388
} |
FStar.Pervasives.Lemma | val lemma_swap_splice : #a:Type -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma
(ensures (swap s i j == splice s start (swap s i j) len)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len)) | val lemma_swap_splice : #a:Type -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma
(ensures (swap s i j == splice s start (swap s i j) len))
let lemma_swap_splice #_ s start i j len = | false | null | true | cut (equal (swap s i j) (splice s start (swap s i j) len)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.swap",
"FStar.Seq.Properties.splice",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_swap_splice : #a:Type -> s:seq a -> start:nat -> i:nat{start <= i} -> j:nat{i <= j} -> len:nat{j < len && len <= length s}
-> Lemma
(ensures (swap s i j == splice s start (swap s i j) len)) | [] | FStar.Seq.Properties.lemma_swap_splice | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
start: Prims.nat ->
i: Prims.nat{start <= i} ->
j: Prims.nat{i <= j} ->
len: Prims.nat{j < len && len <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.swap s i j ==
FStar.Seq.Properties.splice s start (FStar.Seq.Properties.swap s i j) len) | {
"end_col": 101,
"end_line": 275,
"start_col": 43,
"start_line": 275
} |
FStar.Pervasives.Lemma | val append_contains_equiv (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma ((append s1 s2) `contains` x
<==>
(s1 `contains` x \/ s2 `contains` x)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x | val append_contains_equiv (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma ((append s1 s2) `contains` x
<==>
(s1 `contains` x \/ s2 `contains` x))
let append_contains_equiv #_ s1 s2 x = | false | null | true | FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"FStar.Classical.move_requires",
"Prims.l_or",
"FStar.Seq.Properties.contains",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.intro_append_contains_from_disjunction",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val append_contains_equiv (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma ((append s1 s2) `contains` x
<==>
(s1 `contains` x \/ s2 `contains` x)) | [] | FStar.Seq.Properties.append_contains_equiv | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> x: a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.contains (FStar.Seq.Base.append s1 s2) x <==>
FStar.Seq.Properties.contains s1 x \/ FStar.Seq.Properties.contains s2 x) | {
"end_col": 82,
"end_line": 460,
"start_col": 4,
"start_line": 460
} |
FStar.Pervasives.Lemma | val lemma_seq_frame_lo: #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat{i <= j} -> m:nat{j < m} -> n:nat{m <= n && n <= length s1}
-> Lemma
(requires (s1 == (splice s2 m s1 n)))
(ensures ((slice s1 i j == slice s2 i j) /\ (index s1 j == index s2 j))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j)) | val lemma_seq_frame_lo: #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat{i <= j} -> m:nat{j < m} -> n:nat{m <= n && n <= length s1}
-> Lemma
(requires (s1 == (splice s2 m s1 n)))
(ensures ((slice s1 i j == slice s2 i j) /\ (index s1 j == index s2 j)))
let lemma_seq_frame_lo #_ s1 s2 i j m n = | false | null | true | cut (equal (slice s1 i j) (slice s2 i j)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_AmpAmp",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_frame_lo: #a:Type -> s1:seq a -> s2:seq a{length s1 = length s2} -> i:nat -> j:nat{i <= j} -> m:nat{j < m} -> n:nat{m <= n && n <= length s1}
-> Lemma
(requires (s1 == (splice s2 m s1 n)))
(ensures ((slice s1 i j == slice s2 i j) /\ (index s1 j == index s2 j))) | [] | FStar.Seq.Properties.lemma_seq_frame_lo | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
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 ->
j: Prims.nat{i <= j} ->
m: Prims.nat{j < m} ->
n: Prims.nat{m <= n && n <= FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma (requires s1 == FStar.Seq.Properties.splice s2 m s1 n)
(ensures
FStar.Seq.Base.slice s1 i j == FStar.Seq.Base.slice s2 i j /\
FStar.Seq.Base.index s1 j == FStar.Seq.Base.index s2 j) | {
"end_col": 43,
"end_line": 281,
"start_col": 2,
"start_line": 281
} |
FStar.Pervasives.Lemma | val find_append_some' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f | val find_append_some' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
let rec find_append_some': #a: Type -> s1: seq a -> s2: seq a -> f: (a -> Tot bool)
-> Lemma (requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1)) = | false | null | true | fun #_ s1 s2 f ->
if f (head s1)
then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Base.seq",
"Prims.bool",
"FStar.Seq.Properties.head",
"FStar.Seq.Properties.find_append_some'",
"FStar.Seq.Properties.tail",
"Prims.unit",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_append_some' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1)) | [
"recursion"
] | FStar.Seq.Properties.find_append_some' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (requires Some? (FStar.Seq.Properties.find_l f s1))
(ensures
FStar.Seq.Properties.find_l f (FStar.Seq.Base.append s1 s2) ==
FStar.Seq.Properties.find_l f s1)
(decreases FStar.Seq.Base.length s1) | {
"end_col": 36,
"end_line": 331,
"start_col": 2,
"start_line": 327
} |
FStar.Pervasives.Lemma | val lemma_ordering_hi_cons: #a:eqtype -> f:tot_ord a -> s:seq a -> back:nat -> len:nat{back < len && len <= length s} -> pv:a
-> Lemma (requires ((forall y. mem y (slice s (back + 1) len) ==> f pv y) /\ f pv (index s back)))
(ensures ((forall y. mem y (slice s back len) ==> f pv y))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len) | val lemma_ordering_hi_cons: #a:eqtype -> f:tot_ord a -> s:seq a -> back:nat -> len:nat{back < len && len <= length s} -> pv:a
-> Lemma (requires ((forall y. mem y (slice s (back + 1) len) ==> f pv y) /\ f pv (index s back)))
(ensures ((forall y. mem y (slice s back len) ==> f pv y)))
let lemma_ordering_hi_cons #_ f s back len pv = | false | null | true | cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Seq.Properties.tot_ord",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.lemma_mem_append",
"FStar.Seq.Base.create",
"FStar.Seq.Base.index",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.unit",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_ordering_hi_cons: #a:eqtype -> f:tot_ord a -> s:seq a -> back:nat -> len:nat{back < len && len <= length s} -> pv:a
-> Lemma (requires ((forall y. mem y (slice s (back + 1) len) ==> f pv y) /\ f pv (index s back)))
(ensures ((forall y. mem y (slice s back len) ==> f pv y))) | [] | FStar.Seq.Properties.lemma_ordering_hi_cons | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: FStar.Seq.Properties.tot_ord a ->
s: FStar.Seq.Base.seq a ->
back: Prims.nat ->
len: Prims.nat{back < len && len <= FStar.Seq.Base.length s} ->
pv: a
-> FStar.Pervasives.Lemma
(requires
(forall (y: a).
FStar.Seq.Properties.mem y (FStar.Seq.Base.slice s (back + 1) len) ==> f pv y) /\
f pv (FStar.Seq.Base.index s back))
(ensures
forall (y: a). FStar.Seq.Properties.mem y (FStar.Seq.Base.slice s back len) ==> f pv y) | {
"end_col": 69,
"end_line": 258,
"start_col": 2,
"start_line": 257
} |
FStar.Pervasives.Lemma | val sorted_concat_lemma'
(#a: eqtype)
(f: (a -> a -> Tot bool){total_order a f})
(lo: seq a {sorted f lo})
(pivot: a)
(hi: seq a {sorted f hi})
: Lemma (requires (forall y. (mem y lo ==> f y pivot) /\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi))) | val sorted_concat_lemma'
(#a: eqtype)
(f: (a -> a -> Tot bool){total_order a f})
(lo: seq a {sorted f lo})
(pivot: a)
(hi: seq a {sorted f hi})
: Lemma (requires (forall y. (mem y lo ==> f y pivot) /\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
let rec sorted_concat_lemma':
#a: eqtype ->
f: (a -> a -> Tot bool){total_order a f} ->
lo: seq a {sorted f lo} ->
pivot: a ->
hi: seq a {sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot) /\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo)) = | false | null | true | fun #_ f lo pivot hi ->
if length lo = 0
then
(cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else
(sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"Prims.bool",
"FStar.Seq.Properties.total_order",
"FStar.Seq.Base.seq",
"Prims.b2t",
"FStar.Seq.Properties.sorted",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.tail",
"FStar.Seq.Properties.cons",
"Prims.unit",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.lemma_tl",
"FStar.Seq.Properties.head",
"FStar.Seq.Properties.lemma_append_cons",
"FStar.Seq.Properties.sorted_concat_lemma'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi)))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sorted_concat_lemma'
(#a: eqtype)
(f: (a -> a -> Tot bool){total_order a f})
(lo: seq a {sorted f lo})
(pivot: a)
(hi: seq a {sorted f hi})
: Lemma (requires (forall y. (mem y lo ==> f y pivot) /\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo)) | [
"recursion"
] | FStar.Seq.Properties.sorted_concat_lemma' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: a -> _: a -> Prims.bool){FStar.Seq.Properties.total_order a f} ->
lo: FStar.Seq.Base.seq a {FStar.Seq.Properties.sorted f lo} ->
pivot: a ->
hi: FStar.Seq.Base.seq a {FStar.Seq.Properties.sorted f hi}
-> FStar.Pervasives.Lemma
(requires
forall (y: a).
(FStar.Seq.Properties.mem y lo ==> f y pivot) /\
(FStar.Seq.Properties.mem y hi ==> f pivot y))
(ensures
FStar.Seq.Properties.sorted f
(FStar.Seq.Base.append lo (FStar.Seq.Properties.cons pivot hi)))
(decreases FStar.Seq.Base.length lo) | {
"end_col": 62,
"end_line": 146,
"start_col": 2,
"start_line": 140
} |
FStar.Pervasives.Lemma | val lemma_swap_permutes_aux_frag_eq: #a:Type -> s:seq a -> i:nat{i<length s} -> j:nat{i <= j && j<length s}
-> i':nat -> j':nat{i' <= j' /\ j'<=length s /\
(j < i' //high slice
\/ j' <= i //low slice
\/ (i < i' /\ j' <= j)) //mid slice
}
-> Lemma (ensures (slice s i' j' == slice (swap s i j) i' j'
/\ slice s i (i + 1) == slice (swap s i j) j (j + 1)
/\ slice s j (j + 1) == slice (swap s i j) i (i + 1))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1))) | val lemma_swap_permutes_aux_frag_eq: #a:Type -> s:seq a -> i:nat{i<length s} -> j:nat{i <= j && j<length s}
-> i':nat -> j':nat{i' <= j' /\ j'<=length s /\
(j < i' //high slice
\/ j' <= i //low slice
\/ (i < i' /\ j' <= j)) //mid slice
}
-> Lemma (ensures (slice s i' j' == slice (swap s i j) i' j'
/\ slice s i (i + 1) == slice (swap s i j) j (j + 1)
/\ slice s j (j + 1) == slice (swap s i j) i (i + 1)))
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' = | false | null | true | cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.l_and",
"Prims.l_or",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.Seq.Properties.swap",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_swap_permutes_aux_frag_eq: #a:Type -> s:seq a -> i:nat{i<length s} -> j:nat{i <= j && j<length s}
-> i':nat -> j':nat{i' <= j' /\ j'<=length s /\
(j < i' //high slice
\/ j' <= i //low slice
\/ (i < i' /\ j' <= j)) //mid slice
}
-> Lemma (ensures (slice s i' j' == slice (swap s i j) i' j'
/\ slice s i (i + 1) == slice (swap s i j) j (j + 1)
/\ slice s j (j + 1) == slice (swap s i j) i (i + 1))) | [] | FStar.Seq.Properties.lemma_swap_permutes_aux_frag_eq | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Seq.Base.seq a ->
i: Prims.nat{i < FStar.Seq.Base.length s} ->
j: Prims.nat{i <= j && j < FStar.Seq.Base.length s} ->
i': Prims.nat ->
j':
Prims.nat
{i' <= j' /\ j' <= FStar.Seq.Base.length s /\ (j < i' \/ j' <= i \/ i < i' /\ j' <= j)}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice s i' j' == FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) i' j' /\
FStar.Seq.Base.slice s i (i + 1) ==
FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) j (j + 1) /\
FStar.Seq.Base.slice s j (j + 1) ==
FStar.Seq.Base.slice (FStar.Seq.Properties.swap s i j) i (i + 1)) | {
"end_col": 65,
"end_line": 161,
"start_col": 2,
"start_line": 159
} |
FStar.Pervasives.Lemma | val lemma_trans_frame : #a:Type -> s1:seq a -> s2:seq a -> s3:seq a{length s1 = length s2 /\ length s2 = length s3} -> i:nat -> j:nat{i <= j && j <= length s1}
-> Lemma
(requires ((s1 == splice s2 i s1 j) /\ s2 == splice s3 i s2 j))
(ensures (s1 == splice s3 i s1 j)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j)) | val lemma_trans_frame : #a:Type -> s1:seq a -> s2:seq a -> s3:seq a{length s1 = length s2 /\ length s2 = length s3} -> i:nat -> j:nat{i <= j && j <= length s1}
-> Lemma
(requires ((s1 == splice s2 i s1 j) /\ s2 == splice s3 i s2 j))
(ensures (s1 == splice s3 i s1 j))
let lemma_trans_frame #_ s1 s2 s3 i j = | false | null | true | cut (equal s1 (splice s3 i s1 j)) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.splice",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_trans_frame : #a:Type -> s1:seq a -> s2:seq a -> s3:seq a{length s1 = length s2 /\ length s2 = length s3} -> i:nat -> j:nat{i <= j && j <= length s1}
-> Lemma
(requires ((s1 == splice s2 i s1 j) /\ s2 == splice s3 i s2 j))
(ensures (s1 == splice s3 i s1 j)) | [] | FStar.Seq.Properties.lemma_trans_frame | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
s3:
FStar.Seq.Base.seq a
{ FStar.Seq.Base.length s1 = FStar.Seq.Base.length s2 /\
FStar.Seq.Base.length s2 = FStar.Seq.Base.length s3 } ->
i: Prims.nat ->
j: Prims.nat{i <= j && j <= FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma
(requires
s1 == FStar.Seq.Properties.splice s2 i s1 j /\ s2 == FStar.Seq.Properties.splice s3 i s2 j)
(ensures s1 == FStar.Seq.Properties.splice s3 i s1 j) | {
"end_col": 73,
"end_line": 290,
"start_col": 40,
"start_line": 290
} |
Prims.Pure | val split_5 : #a:Type -> s:seq a -> i:nat -> j:nat{i < j && j < length s} -> Pure (seq (seq a))
(requires True)
(ensures (fun x ->
(length x = 5
/\ equal s (append (index x 0) (append (index x 1) (append (index x 2) (append (index x 3) (index x 4)))))
/\ equal (index x 0) (slice s 0 i)
/\ equal (index x 1) (slice s i (i+1))
/\ equal (index x 2) (slice s (i+1) j)
/\ equal (index x 3) (slice s j (j + 1))
/\ equal (index x 4) (slice s (j + 1) (length s))))) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi | val split_5 : #a:Type -> s:seq a -> i:nat -> j:nat{i < j && j < length s} -> Pure (seq (seq a))
(requires True)
(ensures (fun x ->
(length x = 5
/\ equal s (append (index x 0) (append (index x 1) (append (index x 2) (append (index x 3) (index x 4)))))
/\ equal (index x 0) (slice s 0 i)
/\ equal (index x 1) (slice s i (i+1))
/\ equal (index x 2) (slice s (i+1) j)
/\ equal (index x 3) (slice s j (j + 1))
/\ equal (index x 4) (slice s (j + 1) (length s)))))
let split_5 #a s i j = | false | null | false | let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Seq.Base.upd",
"FStar.Seq.Base.create",
"FStar.Seq.Base.slice",
"Prims.op_Addition"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val split_5 : #a:Type -> s:seq a -> i:nat -> j:nat{i < j && j < length s} -> Pure (seq (seq a))
(requires True)
(ensures (fun x ->
(length x = 5
/\ equal s (append (index x 0) (append (index x 1) (append (index x 2) (append (index x 3) (index x 4)))))
/\ equal (index x 0) (slice s 0 i)
/\ equal (index x 1) (slice s i (i+1))
/\ equal (index x 2) (slice s (i+1) j)
/\ equal (index x 3) (slice s j (j + 1))
/\ equal (index x 4) (slice s (j + 1) (length s))))) | [] | FStar.Seq.Properties.split_5 | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i < j && j < FStar.Seq.Base.length s}
-> Prims.Pure (FStar.Seq.Base.seq (FStar.Seq.Base.seq a)) | {
"end_col": 81,
"end_line": 156,
"start_col": 22,
"start_line": 150
} |
FStar.Pervasives.Lemma | val lemma_find_l_contains' (#a: Type) (f: (a -> Tot bool)) (l: seq a)
: Lemma (requires True)
(ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l) | val lemma_find_l_contains' (#a: Type) (f: (a -> Tot bool)) (l: seq a)
: Lemma (requires True)
(ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
let rec lemma_find_l_contains' (#a: Type) (f: (a -> Tot bool)) (l: seq a)
: Lemma (requires True)
(ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l)) = | false | null | true | if length l = 0 then () else if f (head l) then () else lemma_find_l_contains' f (tail l) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.bool",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.head",
"FStar.Seq.Properties.lemma_find_l_contains'",
"FStar.Seq.Properties.tail",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Properties.find_l",
"FStar.Seq.Properties.contains",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l))) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_find_l_contains' (#a: Type) (f: (a -> Tot bool)) (l: seq a)
: Lemma (requires True)
(ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l)) | [
"recursion"
] | FStar.Seq.Properties.lemma_find_l_contains' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: a -> Prims.bool) -> l: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
Some? (FStar.Seq.Properties.find_l f l) ==>
FStar.Seq.Properties.contains l (Some?.v (FStar.Seq.Properties.find_l f l)))
(decreases FStar.Seq.Base.length l) | {
"end_col": 42,
"end_line": 470,
"start_col": 4,
"start_line": 468
} |
FStar.Pervasives.Lemma | val perm_len' (#a: eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2' | val perm_len' (#a: eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
let rec perm_len' (#a: eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1)) = | false | null | true | if length s1 = 0
then if length s2 = 0 then () else assert (count (index s2 0) s2 > 0)
else
let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then
(assert (permutation a s1_tl s2_tl);
perm_len' s1_tl s2_tl)
else
let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.bool",
"Prims._assert",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Properties.count",
"FStar.Seq.Base.index",
"Prims.unit",
"FStar.Seq.Properties.perm_len'",
"FStar.Seq.Properties.permutation",
"FStar.Seq.Properties.lemma_append_count",
"FStar.Seq.Properties.tail",
"FStar.Seq.Base.create",
"FStar.Seq.Base.append",
"FStar.Seq.Base.equal",
"FStar.Pervasives.Native.tuple2",
"FStar.Seq.Properties.split_eq",
"Prims.nat",
"FStar.Seq.Properties.index_mem",
"FStar.Seq.Properties.head",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val perm_len' (#a: eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1)) | [
"recursion"
] | FStar.Seq.Properties.perm_len' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma (requires FStar.Seq.Properties.permutation a s1 s2)
(ensures FStar.Seq.Base.length s1 == FStar.Seq.Base.length s2)
(decreases FStar.Seq.Base.length s1) | {
"end_col": 33,
"end_line": 235,
"start_col": 4,
"start_line": 214
} |
FStar.Pervasives.Lemma | val contains_cons (#a:Type) (hd:a) (tl:Seq.seq a) (x:a)
: Lemma ((cons hd tl) `contains` x
<==>
(x==hd \/ tl `contains` x)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x | val contains_cons (#a:Type) (hd:a) (tl:Seq.seq a) (x:a)
: Lemma ((cons hd tl) `contains` x
<==>
(x==hd \/ tl `contains` x))
let contains_cons #_ hd tl x = | false | null | true | append_contains_equiv (Seq.create 1 hd) tl x | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma"
] | [
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.append_contains_equiv",
"FStar.Seq.Base.create",
"Prims.unit"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains' | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val contains_cons (#a:Type) (hd:a) (tl:Seq.seq a) (x:a)
: Lemma ((cons hd tl) `contains` x
<==>
(x==hd \/ tl `contains` x)) | [] | FStar.Seq.Properties.contains_cons | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | hd: a -> tl: FStar.Seq.Base.seq a -> x: a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Properties.contains (FStar.Seq.Properties.cons hd tl) x <==>
x == hd \/ FStar.Seq.Properties.contains tl x) | {
"end_col": 48,
"end_line": 475,
"start_col": 4,
"start_line": 475
} |
FStar.Pervasives.Lemma | val lemma_seq_to_list_permutation (#a:eqtype) (s:seq a)
:Lemma (requires True) (ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s))) (decreases (length s)) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let lemma_seq_to_list_permutation = lemma_seq_to_list_permutation' | val lemma_seq_to_list_permutation (#a:eqtype) (s:seq a)
:Lemma (requires True) (ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s))) (decreases (length s))
let lemma_seq_to_list_permutation = | false | null | true | lemma_seq_to_list_permutation' | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Properties.lemma_seq_to_list_permutation'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end
let find_append_none_s2 = find_append_none_s2'
let find_snoc #_ s x f =
if Some? (find_l f s) then find_append_some s (Seq.create 1 x) f
else find_append_none s (Seq.create 1 x) f
let un_snoc_snoc #_ s x =
let s', x = un_snoc (snoc s x) in
assert (Seq.equal s s')
let find_mem #_ s f x
= match seq_find f s with
| None -> mem_index x s
| Some _ -> ()
let rec seq_mem_k': #a:eqtype -> s:seq a -> n:nat{n < Seq.length s} ->
Lemma (requires True)
(ensures (mem (Seq.index s n) s))
(decreases n)
= fun #_ s n ->
if n = 0 then ()
else let tl = tail s in
seq_mem_k' tl (n - 1)
let seq_mem_k = seq_mem_k'
module L = FStar.List.Tot
let lemma_seq_of_list_induction #_ l
= match l with
| [] -> assert_norm (seq_of_list l == Seq.empty)
| hd::tl ->
assert_norm (seq_of_list (hd::tl) == create 1 hd @| seq_of_list tl);
lemma_tl hd (seq_of_list tl)
let rec lemma_seq_list_bij': #a:Type -> s:seq a -> Lemma
(requires (True))
(ensures (seq_of_list (seq_to_list s) == s))
(decreases (length s))
= fun #_ s ->
let l = seq_to_list s in
lemma_seq_of_list_induction l;
if length s = 0 then (
assert (equal s (seq_of_list l))
)
else (
lemma_seq_list_bij' (slice s 1 (length s));
assert (equal s (seq_of_list (seq_to_list s)))
)
let lemma_seq_list_bij = lemma_seq_list_bij'
let rec lemma_list_seq_bij': #a:Type -> l:list a -> Lemma
(requires (True))
(ensures (seq_to_list (seq_of_list l) == l))
(decreases (L.length l))
= fun #_ l ->
lemma_seq_of_list_induction l;
if L.length l = 0 then ()
else (
lemma_list_seq_bij' (L.tl l);
assert(equal (seq_of_list (L.tl l)) (slice (seq_of_list l) 1 (length (seq_of_list l))))
)
let lemma_list_seq_bij = lemma_list_seq_bij'
let rec lemma_index_is_nth': #a:Type -> s:seq a -> i:nat{i < length s} -> Lemma
(requires True)
(ensures (L.index (seq_to_list s) i == index s i))
(decreases i)
= fun #_ s i ->
if i = 0 then ()
else (
lemma_index_is_nth' (slice s 1 (length s)) (i-1)
)
let lemma_index_is_nth = lemma_index_is_nth'
let contains #a s x =
exists (k:nat). k < Seq.length s /\ Seq.index s k == x
let contains_intro #_ _ _ _ = ()
let contains_elim #_ _ _ = ()
let lemma_contains_empty #_ = ()
let lemma_contains_singleton #_ _ = ()
private let intro_append_contains_from_disjunction (#a:Type) (s1:seq a) (s2:seq a) (x:a)
: Lemma (requires s1 `contains` x \/ s2 `contains` x)
(ensures (append s1 s2) `contains` x)
= let open FStar.Classical in
let open FStar.Squash in
or_elim #(s1 `contains` x) #(s2 `contains` x) #(fun _ -> (append s1 s2) `contains` x)
(fun _ -> ())
(fun _ -> let s = append s1 s2 in
exists_elim (s `contains` x) (get_proof (s2 `contains` x)) (fun k ->
assert (Seq.index s (Seq.length s1 + k) == x)))
let append_contains_equiv #_ s1 s2 x
= FStar.Classical.move_requires (intro_append_contains_from_disjunction s1 s2) x
let contains_snoc #_ s x =
FStar.Classical.forall_intro (append_contains_equiv s (Seq.create 1 x))
let rec lemma_find_l_contains' (#a:Type) (f:a -> Tot bool) (l:seq a)
: Lemma (requires True) (ensures Some? (find_l f l) ==> l `contains` (Some?.v (find_l f l)))
(decreases (Seq.length l))
= if length l = 0 then ()
else if f (head l) then ()
else lemma_find_l_contains' f (tail l)
let lemma_find_l_contains = lemma_find_l_contains'
let contains_cons #_ hd tl x
= append_contains_equiv (Seq.create 1 hd) tl x
let append_cons_snoc #_ _ _ _ = ()
let append_slices #_ _ _ = ()
let rec find_l_none_no_index' (#a:Type) (s:Seq.seq a) (f:(a -> Tot bool)) :
Lemma (requires (None? (find_l f s)))
(ensures (forall (i:nat{i < Seq.length s}). not (f (Seq.index s i))))
(decreases (Seq.length s))
= if Seq.length s = 0
then ()
else (assert (not (f (head s)));
assert (None? (find_l f (tail s)));
find_l_none_no_index' (tail s) f;
assert (Seq.equal s (cons (head s) (tail s)));
find_append_none (create 1 (head s)) (tail s) f)
let find_l_none_no_index = find_l_none_no_index'
let cons_head_tail #_ s =
let _ : squash (slice s 0 1 == create 1 (index s 0)) =
lemma_index_slice s 0 1 0;
lemma_index_create 1 (index s 0) 0;
lemma_eq_elim (slice s 0 1) (create 1 (index s 0))
in
lemma_split s 1
let head_cons #_ _ _ = ()
let suffix_of_tail #_ s = cons_head_tail s
let index_cons_l #_ _ _ = ()
let index_cons_r #_ _ _ _ = ()
let append_cons #_ c s1 s2 = lemma_eq_elim (append (cons c s1) s2) (cons c (append s1 s2))
let index_tail #_ _ _ = ()
let mem_cons #_ x s = lemma_append_count (create 1 x) s
let snoc_slice_index #_ s i j = lemma_eq_elim (snoc (slice s i j) (index s j)) (slice s i (j + 1))
let cons_index_slice #_ s i j _ = lemma_eq_elim (cons (index s i) (slice s (i + 1) j)) (slice s i j)
let slice_is_empty #_ s i = lemma_eq_elim (slice s i i) Seq.empty
let slice_length #_ s = lemma_eq_elim (slice s 0 (length s)) s
let slice_slice #_ s i1 j1 i2 j2 = lemma_eq_elim (slice (slice s i1 j1) i2 j2) (slice s (i1 + i2) (i1 + j2))
let rec lemma_seq_of_list_index #_ l i
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd::tl -> if i = 0 then () else lemma_seq_of_list_index tl (i - 1)
let seq_of_list_tl #_ l = lemma_seq_of_list_induction l
let rec mem_seq_of_list #_ x l
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| y :: q ->
let _ : squash (head (seq_of_list l) == y) = () in
let _ : squash (tail (seq_of_list l) == seq_of_list q) = seq_of_list_tl l in
let _ : squash (mem x (seq_of_list l) == (x = y || mem x (seq_of_list q))) =
lemma_mem_inversion (seq_of_list l)
in
mem_seq_of_list x q
let rec intro_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
explode_and i s l))
(ensures (
equal (seq_of_list l) (slice s i (length s))))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl -> intro_of_list'' (i + 1) s tl
let intro_of_list' = intro_of_list''
let intro_of_list #_ s l = intro_of_list' 0 s l
let rec elim_of_list'': #a:Type ->
i:nat ->
s:seq a ->
l:list a ->
Lemma
(requires (
List.Tot.length l + i = length s /\
i <= length s /\
slice s i (length s) == seq_of_list l))
(ensures (
explode_and i s l))
(decreases (
List.Tot.length l))
= fun #_ i s l ->
match l with
| [] -> ()
| hd :: tl ->
lemma_seq_of_list_induction l;
elim_of_list'' (i + 1) s tl
let elim_of_list' = elim_of_list''
let elim_of_list #_ l = elim_of_list' 0 (seq_of_list l) l
let rec lemma_seq_to_list_permutation' (#a:eqtype) (s:seq a)
:Lemma (requires True) (ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s))) (decreases (length s))
= if length s > 0 then lemma_seq_to_list_permutation' (slice s 1 (length s)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_seq_to_list_permutation (#a:eqtype) (s:seq a)
:Lemma (requires True) (ensures (forall x. count x s == List.Tot.Base.count x (seq_to_list s))) (decreases (length s)) | [] | FStar.Seq.Properties.lemma_seq_to_list_permutation | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.Seq.Properties.count x s ==
FStar.List.Tot.Base.count x (FStar.Seq.Properties.seq_to_list s))
(decreases FStar.Seq.Base.length s) | {
"end_col": 66,
"end_line": 598,
"start_col": 36,
"start_line": 598
} |
FStar.Pervasives.Lemma | val find_append_none_s2' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1)) | [
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq.Base",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"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
}
] | false | let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else if f (head s1) then ()
else begin
find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))
end | val find_append_none_s2' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
let rec find_append_none_s2': #a: Type -> s1: seq a -> s2: seq a -> f: (a -> Tot bool)
-> Lemma (requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1)) = | false | null | true | fun #_ s1 s2 f ->
if Seq.length s1 = 0
then cut (equal (append s1 s2) s2)
else
if f (head s1)
then ()
else
(find_append_none_s2' (tail s1) s2 f;
cut (equal (tail (append s1 s2)) (append (tail s1) s2))) | {
"checked_file": "FStar.Seq.Properties.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Properties.fst"
} | [
"lemma",
""
] | [
"FStar.Seq.Base.seq",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.cut",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.head",
"FStar.Seq.Properties.tail",
"Prims.unit",
"FStar.Seq.Properties.find_append_none_s2'"
] | [] | (*
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.
*)
module FStar.Seq.Properties
open FStar.Seq.Base
module Seq = FStar.Seq.Base
let lemma_append_inj_l #_ s1 s2 t1 t2 i =
assert (index s1 i == (index (append s1 s2) i));
assert (index t1 i == (index (append t1 t2) i))
let lemma_append_inj_r #_ s1 s2 t1 t2 i =
assert (index s2 i == (index (append s1 s2) (i + length s1)));
assert (index t2 i == (index (append t1 t2) (i + length t1)))
let lemma_append_len_disj #_ s1 s2 t1 t2 =
cut (length (append s1 s2) == length s1 + length s2);
cut (length (append t1 t2) == length t1 + length t2)
let lemma_append_inj #_ s1 s2 t1 t2 =
lemma_append_len_disj s1 s2 t1 t2;
FStar.Classical.forall_intro #(i:nat{i < length s1}) #(fun i -> index s1 i == index t1 i) (lemma_append_inj_l s1 s2 t1 t2);
FStar.Classical.forall_intro #(i:nat{i < length s2}) #(fun i -> index s2 i == index t2 i) (lemma_append_inj_r s1 s2 t1 t2)
let lemma_head_append #_ _ _ = ()
let lemma_tail_append #_ s1 s2 = cut (equal (tail (append s1 s2)) (append (tail s1) s2))
let lemma_cons_inj #_ v1 v2 s1 s2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj t1 s1 t2 s2;
assert(index t1 0 == index t2 0)
let lemma_split #_ s i =
cut (equal (append (fst (split s i)) (snd (split s i))) s)
let rec mem_index' (#a:eqtype) (x:a) (s:seq a)
: Lemma (requires (mem x s))
(ensures (exists i. index s i == x))
(decreases (length s))
= if length s = 0 then ()
else if head s = x then ()
else mem_index' x (tail s)
let mem_index = mem_index'
let lemma_slice_append #_ _ _ = ()
let rec lemma_slice_first_in_append' (#a:Type) (s1:seq a) (s2:seq a)
(i:nat{i <= length s1})
: Lemma
(ensures (equal (slice (append s1 s2) i (length (append s1 s2))) (append (slice s1 i (length s1)) s2)))
(decreases (length s1))
= if i = 0 then ()
else lemma_slice_first_in_append' (tail s1) s2 (i - 1)
let lemma_slice_first_in_append = lemma_slice_first_in_append'
let slice_upd #_ s i j k v =
lemma_eq_intro (slice (upd s k v) i j) (slice s i j)
let upd_slice #_ s i j k v =
lemma_eq_intro (upd (slice s i j) k v) (slice (upd s (i + k) v) i j)
let lemma_append_cons #_ _ _ = ()
let lemma_tl #_ _ _ = ()
let rec sorted_feq' (#a:Type)
(f g : (a -> a -> Tot bool))
(s:seq a{forall x y. f x y == g x y})
: Lemma (ensures (sorted f s <==> sorted g s))
(decreases (length s))
= if length s <= 1 then ()
else sorted_feq' f g (tail s)
let sorted_feq = sorted_feq'
let rec lemma_append_count' (#a:eqtype) (lo:seq a) (hi:seq a)
: Lemma
(requires True)
(ensures (forall x. count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= if length lo = 0
then cut (equal (append lo hi) hi)
else (cut (equal (cons (head lo) (append (tail lo) hi))
(append lo hi));
lemma_append_count' (tail lo) hi;
let tl_l_h = append (tail lo) hi in
let lh = cons (head lo) tl_l_h in
cut (equal (tail lh) tl_l_h))
let lemma_append_count = lemma_append_count'
let lemma_append_count_aux #_ _ lo hi = lemma_append_count lo hi
let lemma_mem_inversion #_ _ = ()
let rec lemma_mem_count' (#a:eqtype) (s:seq a) (f:a -> Tot bool)
: Lemma
(requires (forall (i:nat{i<length s}). f (index s i)))
(ensures (forall (x:a). mem x s ==> f x))
(decreases (length s))
= if length s = 0
then ()
else (let t = i:nat{i<length (tail s)} in
cut (forall (i:t). index (tail s) i = index s (i + 1));
lemma_mem_count' (tail s) f)
let lemma_mem_count = lemma_mem_count'
let lemma_count_slice #_ s i =
cut (equal s (append (slice s 0 i) (slice s i (length s))));
lemma_append_count (slice s 0 i) (slice s i (length s))
let rec sorted_concat_lemma': #a:eqtype
-> f:(a -> a -> Tot bool){total_order a f}
-> lo:seq a{sorted f lo}
-> pivot:a
-> hi:seq a{sorted f hi}
-> Lemma (requires (forall y. (mem y lo ==> f y pivot)
/\ (mem y hi ==> f pivot y)))
(ensures (sorted f (append lo (cons pivot hi))))
(decreases (length lo))
= fun #_ f lo pivot hi ->
if length lo = 0
then (cut (equal (append lo (cons pivot hi)) (cons pivot hi));
cut (equal (tail (cons pivot hi)) hi))
else (sorted_concat_lemma' f (tail lo) pivot hi;
lemma_append_cons lo (cons pivot hi);
lemma_tl (head lo) (append (tail lo) (cons pivot hi)))
let sorted_concat_lemma = sorted_concat_lemma'
let split_5 #a s i j =
let frag_lo = slice s 0 i in
let frag_i = slice s i (i + 1) in
let frag_mid = slice s (i + 1) j in
let frag_j = slice s j (j + 1) in
let frag_hi = slice s (j + 1) (length s) in
upd (upd (upd (upd (create 5 frag_lo) 1 frag_i) 2 frag_mid) 3 frag_j) 4 frag_hi
let lemma_swap_permutes_aux_frag_eq #a s i j i' j' =
cut (equal (slice s i' j') (slice (swap s i j) i' j'));
cut (equal (slice s i (i + 1)) (slice (swap s i j) j (j + 1)));
cut (equal (slice s j (j + 1)) (slice (swap s i j) i (i + 1)))
#push-options "--z3rlimit 20"
let lemma_swap_permutes_aux #_ s i j x =
if j=i
then cut (equal (swap s i j) s)
else begin
let s5 = split_5 s i j in
let frag_lo, frag_i, frag_mid, frag_j, frag_hi =
index s5 0, index s5 1, index s5 2, index s5 3, index s5 4 in
lemma_append_count_aux x frag_lo (append frag_i (append frag_mid (append frag_j frag_hi)));
lemma_append_count_aux x frag_i (append frag_mid (append frag_j frag_hi));
lemma_append_count_aux x frag_mid (append frag_j frag_hi);
lemma_append_count_aux x frag_j frag_hi;
let s' = swap s i j in
let s5' = split_5 s' i j in
let frag_lo', frag_j', frag_mid', frag_i', frag_hi' =
index s5' 0, index s5' 1, index s5' 2, index s5' 3, index s5' 4 in
lemma_swap_permutes_aux_frag_eq s i j 0 i;
lemma_swap_permutes_aux_frag_eq s i j (i + 1) j;
lemma_swap_permutes_aux_frag_eq s i j (j + 1) (length s);
lemma_append_count_aux x frag_lo (append frag_j (append frag_mid (append frag_i frag_hi)));
lemma_append_count_aux x frag_j (append frag_mid (append frag_i frag_hi));
lemma_append_count_aux x frag_mid (append frag_i frag_hi);
lemma_append_count_aux x frag_i frag_hi
end
#pop-options
let append_permutations #a s1 s2 s1' s2' =
(
lemma_append_count s1 s2;
lemma_append_count s1' s2'
)
let lemma_swap_permutes #a s i j
= FStar.Classical.forall_intro
#a
#(fun x -> count x s = count x (swap s i j))
(lemma_swap_permutes_aux s i j)
(* perm_len:
A lemma that shows that two sequences that are permutations
of each other also have the same length
*)
//a proof optimization: Z3 only needs to unfold the recursive definition of `count` once
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let rec perm_len' (#a:eqtype) (s1 s2: seq a)
: Lemma (requires (permutation a s1 s2))
(ensures (length s1 == length s2))
(decreases (length s1))
= if length s1 = 0 then begin
if length s2 = 0 then ()
else assert (count (index s2 0) s2 > 0)
end
else let s1_hd = head s1 in
let s1_tl = tail s1 in
assert (count s1_hd s1 > 0);
assert (count s1_hd s2 > 0);
assert (length s2 > 0);
let s2_hd = head s2 in
let s2_tl = tail s2 in
if s1_hd = s2_hd
then (assert (permutation a s1_tl s2_tl); perm_len' s1_tl s2_tl)
else let i = index_mem s1_hd s2 in
let s_pfx, s_sfx = split_eq s2 i in
assert (equal s_sfx (append (create 1 s1_hd) (tail s_sfx)));
let s2' = append s_pfx (tail s_sfx) in
lemma_append_count s_pfx s_sfx;
lemma_append_count (create 1 s1_hd) (tail s_sfx);
lemma_append_count s_pfx (tail s_sfx);
assert (permutation a s1_tl s2');
perm_len' s1_tl s2'
#pop-options
let perm_len = perm_len'
let cons_perm #_ tl s = lemma_tl (head s) tl
let lemma_mem_append #_ s1 s2 = lemma_append_count s1 s2
let lemma_slice_cons #_ s i j =
cut (equal (slice s i j) (append (create 1 (index s i)) (slice s (i + 1) j)));
lemma_mem_append (create 1 (index s i)) (slice s (i + 1) j)
let lemma_slice_snoc #_ s i j =
cut (equal (slice s i j) (append (slice s i (j - 1)) (create 1 (index s (j - 1)))));
lemma_mem_append (slice s i (j - 1)) (create 1 (index s (j - 1)))
let lemma_ordering_lo_snoc #_ f s i j pv =
cut (equal (slice s i (j + 1)) (append (slice s i j) (create 1 (index s j))));
lemma_mem_append (slice s i j) (create 1 (index s j))
let lemma_ordering_hi_cons #_ f s back len pv =
cut (equal (slice s back len) (append (create 1 (index s back)) (slice s (back + 1) len)));
lemma_mem_append (create 1 (index s back)) (slice s (back + 1) len)
let swap_frame_lo #_ s lo i j = cut (equal (slice s lo i) (slice (swap s i j) lo i))
let swap_frame_lo' #_ s lo i' i j = cut (equal (slice s lo i') (slice (swap s i j) lo i'))
let swap_frame_hi #_ s i j k hi = cut (equal (slice s k hi) (slice (swap s i j) k hi))
let lemma_swap_slice_commute #_ s start i j len =
cut (equal (slice (swap s i j) start len) (swap (slice s start len) (i - start) (j - start)))
let lemma_swap_permutes_slice #_ s start i j len =
lemma_swap_slice_commute s start i j len;
lemma_swap_permutes (slice s start len) (i - start) (j - start)
let splice_refl #_ s i j = cut (equal s (splice s i s j))
let lemma_swap_splice #_ s start i j len = cut (equal (swap s i j) (splice s start (swap s i j) len))
let lemma_seq_frame_hi #_ s1 s2 i j m n =
cut (equal (slice s1 m n) (slice s2 m n))
let lemma_seq_frame_lo #_ s1 s2 i j m n =
cut (equal (slice s1 i j) (slice s2 i j))
let lemma_tail_slice #_ s i j =
cut (equal (tail (slice s i j)) (slice s (i + 1) j))
let lemma_weaken_frame_right #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_weaken_frame_left #_ s1 s2 i j k = cut (equal s1 (splice s2 i s1 k))
let lemma_trans_frame #_ s1 s2 s3 i j = cut (equal s1 (splice s3 i s1 j))
let lemma_weaken_perm_left #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s2 i j)
(slice s1 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s2 i j) (slice s1 j k)
let lemma_weaken_perm_right #_ s1 s2 i j k =
cut (equal (slice s2 i k) (append (slice s2 i j)
(slice s2 j k)));
cut (equal (slice s1 i k) (append (slice s1 i j)
(slice s2 j k)));
lemma_append_count (slice s2 i j) (slice s2 j k);
lemma_append_count (slice s1 i j) (slice s2 j k)
let lemma_trans_perm #_ _ _ _ _ _ = ()
let lemma_cons_snoc #_ _ _ _ = ()
let lemma_tail_snoc #_ s x = lemma_slice_first_in_append s (Seq.create 1 x) 1
let lemma_snoc_inj #_ s1 s2 v1 v2 =
let t1 = create 1 v1 in
let t2 = create 1 v2 in
lemma_append_inj s1 t1 s2 t2;
assert(head t1 == head t2)
let lemma_mem_snoc #_ s x = lemma_append_count s (Seq.create 1 x)
let rec find_append_some': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (Some? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1))
= fun #_ s1 s2 f ->
if f (head s1) then ()
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_some' (tail s1) s2 f
let find_append_some = find_append_some'
let rec find_append_none': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s1)))
(ensures (find_l f (append s1 s2) == find_l f s2))
(decreases (length s1))
= fun #_ s1 s2 f ->
if Seq.length s1 = 0 then cut (equal (append s1 s2) s2)
else
let _ = cut (equal (tail (append s1 s2)) (append (tail s1) s2)) in
find_append_none' (tail s1) s2 f
let find_append_none = find_append_none'
let rec find_append_none_s2': #a:Type -> s1:seq a -> s2:seq a -> f:(a -> Tot bool) -> Lemma
(requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1)) | false | false | FStar.Seq.Properties.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_append_none_s2' (#a: Type) (s1 s2: seq a) (f: (a -> Tot bool))
: Lemma (requires (None? (find_l f s2)))
(ensures (find_l f (append s1 s2) == find_l f s1))
(decreases (length s1)) | [
"recursion"
] | FStar.Seq.Properties.find_append_none_s2' | {
"file_name": "ulib/FStar.Seq.Properties.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (requires None? (FStar.Seq.Properties.find_l f s2))
(ensures
FStar.Seq.Properties.find_l f (FStar.Seq.Base.append s1 s2) ==
FStar.Seq.Properties.find_l f s1)
(decreases FStar.Seq.Base.length s1) | {
"end_col": 5,
"end_line": 357,
"start_col": 2,
"start_line": 351
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.