Physlib.Mathematics.List
58 declarations · 2 submodules
Submodules
Declarations
of equals of
#takeWile_eraseIdxLet be a type and be a decidable predicate on . Let be a list of elements of type . Suppose that the predicate is downward-closed with respect to the indices of ; that is, for any indices , if the element at index satisfies , then the element at index must also satisfy . Then, for any index , it holds that where denotes the list with the element at index removed, and is the longest prefix of consisting only of elements that satisfy .
of a list with an erased element for prefix-closed predicates
#dropWile_eraseIdxLet be a type and be a decidable predicate on . Let be a list of elements of type and be a natural number representing an index. Suppose that for any indices and of the list , if and the element at index satisfies , then the element at index also satisfies . Then, the result of removing the prefix of elements satisfying from the list after erasing the element at index is given by: where is the prefix of consisting of elements satisfying , is the remainder of the list, and is the list with the element at index removed.
For any type equipped with a decidable binary relation , and for any list of elements in , the length of the list after applying the insertion sort algorithm using is equal to the length of the original list . That is, .
Position of in `List.orderedInsert`
#orderedInsertPosGiven a type with a decidable binary relation (denoted as `le1`), a list , and an element , this function returns the index at which is placed when inserted into via the `List.orderedInsert` operation. The index is defined as the length of the prefix of consisting of elements such that the condition is false. The returned value is an index of type , where is the length of the list after insertion.
Given a type with a decidable binary relation (denoted as `le1`), for any list in and any element , the index at which is inserted into is strictly less than the length of the list formed by prepending to , denoted by .
Let be a type with a decidable binary relation (denoted as `le1`). For any list of elements in and any element in , the element at index in the list resulting from the ordered insertion is . That is, , where is the position at which is placed during the insertion.
Removing the element at the `orderedInsert` position results in the original list
#orderedInsert_eraseIdx_orderedInsertPosLet be a type with a decidable binary relation . For any list of elements in and any element , let be the index where is placed when inserted into via the ordered insertion function `List.orderedInsert` (this index is given by `orderedInsertPos`). If the element at index is removed from the resulting list using `eraseIdx`, the remaining list is equal to the original list .
Recursive formula for the insertion position of into
#orderedInsertPos_consLet be a type with a decidable binary relation . For a list and elements , let denote the index at which is placed when inserted into via an ordered insertion. Then the index is given by:
The insertion position of into a list of sigma types is determined by the insertion position of into the list of projected indices.
#orderedInsertPos_sigmaLet be a type with a decidable binary relation . Let be a type family. Consider a list of dependent pairs (where and ), and let denote the projection map that sends to . For any and , the index at which the pair is inserted into (using the relation defined by on the first components) is equal to the index at which is inserted into the list using the relation .
Elements at Indices are Unchanged by `List.orderedInsert`
#orderedInsert_get_ltLet be a type equipped with a decidable binary relation . For a list of elements in and an element , let be the index where is inserted into using the ordered insertion operation `List.orderedInsert`. For any index , the element at index in the list resulting from the insertion is equal to the element at index in the original list .
The prefix of `orderedInsert` before the insertion point equals the `takeWhile` prefix of the original list.
#orderedInsertPos_take_orderedInsertLet be a type with a decidable binary relation . For any list of elements in and an element , let be the index at which is inserted into via the ordered insertion operation (denoted by ). Then, the prefix of the resulting list consisting of the first elements is equal to the prefix of the original list obtained by taking elements such that the condition is false.
where is the insertion position
#orderedInsertPos_take_eq_orderedInsertLet be a type equipped with a decidable binary relation . For a list of elements in and an element , let be the index where is inserted into via the ordered insertion operation. Then the first elements of the original list are identical to the first elements of the list resulting from the insertion. That is: \[ \text{List.take}(p, r) = \text{List.take}(p, \text{List.orderedInsert}(\le, r_0, r)) \]
where is the insertion position of
#orderedInsertPos_drop_eq_orderedInsertFor a type equipped with a decidable binary relation , a list , and an element , let be the position where is inserted into (formally defined as ). Then the suffix of the original list starting at index is equal to the suffix of the list resulting from the ordered insertion starting at index . That is: \[ \text{List.drop}(i, r) = \text{List.drop}(i + 1, \text{List.orderedInsert}(\le, r_0, r)) \]
where is the insertion position of
#orderedInsertPos_takeFor a type equipped with a decidable binary relation , a list , and an element , let be the index at which would be placed when inserted into via an ordered insertion operation (defined as ). The theorem states that the prefix of the original list of length is equal to the prefix of obtained by taking elements as long as the condition is false. That is: \[ \text{List.take}(i, r) = \text{List.takeWhile}(\lambda b.\ \neg(r_0 \le b), r) \]
where is the insertion position of
#orderedInsertPos_dropFor a type equipped with a decidable binary relation , a list , and an element , let be the index at which is placed when inserted into via the ordered insertion operation (defined as ). The theorem states that dropping the first elements of the original list is equivalent to dropping elements from the start of as long as the condition is false. That is: \[ \text{List.drop}(i, r) = \text{List.dropWhile}(\lambda b.\ \neg(r_0 \le b), r) \]
The prefix of `orderedInsert` up to 's position is the `takeWhile` of followed by
#orderedInsertPos_succ_take_orderedInsertLet be a type equipped with a decidable binary relation . For a list of elements in and an element , let be the index at which is placed when inserted into via the ordered insertion operation (`orderedInsert`). Then, the prefix of the resulting list (after insertion) of length is equal to the prefix of the original list consisting of elements for which the condition is false, followed by the element .
for indices
#lt_orderedInsertPos_relLet be a type equipped with a decidable binary relation . For a list of elements in and an element , let be the index at which is placed when inserted into via the ordered insertion operation (defined as ). For any index of the list , if , then the element at that index satisfies .
for indices in the list after insertion
#lt_orderedInsertPos_rel_finLet be a type equipped with a decidable binary relation . Let be a list of elements in and be an element. Let be the index at which is inserted into via the ordered insertion operation. For any index in the list resulting from this insertion, if , then the element at that index satisfies .
for indices
#gt_orderedInsertPos_relLet be a type equipped with a decidable, total, and transitive binary relation . Let be a list of elements in that is sorted with respect to (i.e., `List.Pairwise le1 r`). Let be an element, and let be the position where is placed when inserted into via the ordered insertion operation (the index of the first element in such that is true). For any index in the list , if , then .
and commute for indices
#orderedInsert_eraseIdx_lt_orderedInsertPosLet be a type with a decidable binary relation . Let be a list of elements in , be an element in , and be the position at which is inserted into via the `orderedInsert` operation (denoted by `orderedInsertPos le1 r r0`). Suppose that the condition is prefix-closed in ; that is, for any indices , if , then . Then, for any index , the result of erasing the element at index from the list after has been inserted is the same as inserting into the list after the element at index has been erased from : where denotes the removal of the element at index from list .
of at index equals into at index for
#orderedInsert_eraseIdx_orderedInsertPos_leLet be a type equipped with a decidable binary relation . Let be a list of elements of type and be an element of . Let be the index where is placed when inserted into via the `orderedInsert` operation (specifically, the length of the prefix of where the condition is false). Suppose that for any indices and of the list , if and the condition is false, then is also false. Then for any natural number such that , it holds that: where is the list with inserted at index , and is the list with the element at index removed.
Equivalence of indices between and
#orderedInsertEquivLet be a type with a decidable binary relation . Given a list and an element , let be the list obtained by inserting into at the position . This definition provides an equivalence (bijection) between the set of indices of the prepended list , denoted by , and the set of indices of the list , denoted by . Under this mapping, the index is sent to , and the indices are mapped to the remaining positions in such that the relative order of the original elements in is preserved.
Let be a type with a decidable binary relation . For any list of elements in and any element , let be the equivalence (bijection) that maps the indices of the prepended list to the indices of the list resulting from inserting into via the `orderedInsert` operation. Let be the index at which is placed in the resulting list. Then the equivalence maps the first index to , i.e., .
Value of for successor indices via
#orderedInsertEquiv_succLet be a type with a decidable binary relation . For any list of elements in and any element , let be the position at which is inserted into by the operation. Let be the index equivalence which maps indices of the prepended list to indices of the list resulting from the ordered insertion. Then for any natural number such that is a valid index of , the equivalence satisfies: where is defined as if and if . This formula describes how the original indices of (shifted by 1 in ) are mapped to their new positions in the list after is inserted at position .
Let be a type with a decidable binary relation . For any list of elements in and any element , let be the position at which is inserted into via the ordered insertion operation. Let denote the index equivalence which maps the set of indices of the prepended list to the set of indices of the list resulting from the insertion. For any index , let be its successor in . Then it holds that: where is the function that maps to if and to if .
Let be a type with a decidable binary relation . For any list of elements in and any element , let denote the index equivalence which maps the set of indices of the prepended list to the set of indices of the list resulting from the ordered insertion of into . For any two indices , if , then it holds that .
implies congruence of
#orderedInsertEquiv_congrLet be a type with a decidable binary relation . For any element and any two lists of elements in , if , then the equivalence of indices (which maps indices of to indices of ) is equal to the composition: where and are the canonical isomorphisms between the respective index sets and induced by the equality of the lists.
Let be a type with a decidable binary relation . For any list of elements in and any element , let be the list resulting from the ordered insertion of into . Let be the index equivalence , which maps the indices of the prepended list to the corresponding indices in . Then, the element at index in the list is equal to the element at index in . That is, the element retrieval functions satisfy:
Let be a type with a decidable binary relation . For any list of elements in and any element , let be the list resulting from the ordered insertion of into . Let be the index equivalence , which maps the indices of the prepended list to the corresponding indices in , and let be its inverse. Then, the element retrieval functions (the `get` operations) satisfy the identity:
Let be a type with a decidable binary relation . For any list of elements in and any element , let be the list resulting from the ordered insertion of into . Let be the index equivalence , which maps indices of the prepended list to the corresponding indices in . Then, removing the element at the index from using the `eraseIdx` function results in the original list :
Let be a type with a decidable binary relation . Let be a list of elements in and be an element in . Let be the index equivalence , which maps the indices of the prepended list to the indices of the list resulting from inserting into (denoted by ). Suppose that for any indices of the list , the condition is prefix-closed, meaning . Then, for any natural number such that is a valid index of , it holds that: where denotes the removal of the element at index from list .
Let be a type with a decidable binary relation . Let be a list of elements in and be an element in . Let be the index equivalence , which maps the indices of the prepended list to the indices of the list resulting from inserting into (denoted by ). Suppose that for any indices of the list , the condition is prefix-closed, meaning . Then, for any index , it holds that: where is the successor index in and denotes the removal of the element at index from list .
`orderedInsertEquiv` for a list of sigma types is equivalent to the `orderedInsertEquiv` of its projection
#orderedInsertEquiv_sigmaLet be a type with a decidable binary relation , and be a type family. Let be a list of dependent pairs where and , and let denote the projection map . For any and , let be the relation on the sigma type defined by the first components, i.e., if and only if . The index equivalence , which maps indices of the prepended list to the indices of the list resulting from the ordered insertion of into , is equal to the index equivalence of the projected list. This equality holds identifying the respective index sets through their canonical isomorphisms.
equals at the position
#orderedInsert_eq_insertIdx_orderedInsertPosLet be a type with a decidable binary relation . For any list of elements in and any element , the list resulting from the ordered insertion of into is identical to the list obtained by inserting at the specific index using the standard index-based insertion operation. Mathematically, this is expressed as: where is the index where is placed according to the ordering rule.
Equivalence of indices between and
#insertionSortEquivLet be a type equipped with a decidable binary relation . For any list of elements in , the function constructs a bijection (equivalence) between the set of indices of the original list , denoted by , and the set of indices of the sorted list . The mapping is defined recursively: 1. For the empty list , the bijection is the identity map. 2. For a list , the bijection is formed by first applying the recursive equivalence for , extended to include the new head element , and then composing it with the bijection `orderedInsertEquiv`, which maps the indices of the prepended list to the indices of the list after has been inserted into its correct sorted position.
Let be a type equipped with a decidable binary relation . For any list of elements in , let be the list resulting from the insertion sort of according to . Let be the index equivalence , which maps the indices of the original list to the corresponding indices in the sorted list, and let be its inverse. Then, the element retrieval functions (the `get` operations) satisfy the identity:
Congruence of for
#insertionSortEquiv_congrLet be a type and be a decidable binary relation on . For any two lists such that , the bijection between the indices of and the indices of its sorted version is equal to the composition of the following equivalences: 1. The natural cast between the indices of and , 2. The bijection , 3. The natural cast between the indices of and .
Let be a type and be a decidable binary relation on . For any two lists such that , and for any index , applying the index equivalence to yields the same result as applying to the index (cast as an index of ), with the result cast back to the index set of the sorted list .
Let be a type equipped with a decidable binary relation . For any list of elements in , let be the list resulting from the insertion sort of according to . Let be the index equivalence , which maps each index of the original list to its corresponding position in the sorted list. Then, the composition of the element retrieval function (the `get` operation) of the sorted list with the index mapping is equal to the retrieval function of the original list:
Let be a type equipped with a decidable binary relation . For any list of elements in , let be the index equivalence that maps indices from the original list to their positions in the sorted list. Then, the sorted list is equal to the list constructed by applying the original list's retrieval function to the indices mapped by the inverse equivalence . That is, where creates a list from a function defined on the indices.
for insertion sort index equivalence
#insertionSortEquiv_orderLet be a type and be a decidable binary relation on . For any list of elements in , let be the index equivalence , which maps each index of the original list to its corresponding index in the sorted list . For any two indices in the original list such that , if the element originally at is placed before the element originally at in the sorted list (i.e., ), then the relation does not hold for the pair , denoted .
Optional erasure of a list element by index
#optionEraseGiven a list of elements of type and an optional index , this function returns the original list if is `none`. If is `some } klk$ removed.
Length of list after erasing an index equals
#eraseIdx_length'For any list of elements of type and any valid index (where ), the length of the list obtained by erasing the element at index is equal to the length of minus .
Let be a list of elements of type and be a valid index for (i.e., ). Then the length of the list obtained by removing the element at index , denoted by , satisfies the property that .
For any list of elements of type and any valid index (where ), the successor of the length of the list obtained by removing the element at index is equal to the original length of .
The length of after erasing an element equals the length of
#eraseIdx_cons_lengthLet be a type, be an element, and be a list of elements of . For any valid index in the list , the length of the list obtained by erasing the element at index from is equal to the length of .
Indexing of equals
#eraseIdx_getLet be a list of elements of type and be a valid index in . Let be the list formed by removing the element of at index . The retrieval function for the resulting list, , is equal to the composition of the original retrieval function and the function . That is, for any valid index in the shortened list, the element is retrieved from index of if , and from index of if .
Let be a type equipped with a decidable binary relation that is both total and transitive. For any list of elements in and any natural number such that , let denote the index equivalence , which maps the indices of the original list to the indices of the list sorted by insertion sort, . Then, erasing the element at index from the sorted list is equivalent to sorting the list obtained by erasing the element at index from the original list:
Let be a type equipped with a decidable binary relation that is both total and transitive. For any list of elements in and any valid index , let denote the index equivalence `insertionSortEquiv` which maps the indices of the original list to the indices of the list sorted by insertion sort. Then, erasing the element at index from the sorted list is equivalent to sorting the list obtained by erasing the element at index from the original list:
Left-most minimal index of with respect to
#insertionSortMinPosGiven a type with a decidable binary relation , an element , and a list of elements in , this function returns the index in the list that corresponds to the first element (the head) of the list after it has been sorted using insertion sort. Specifically, it uses the inverse of the index equivalence to map the index of the sorted list back to its original position in . This index represents the leftmost minimal position in with respect to , such that for every element appearing before index , the relation is false.
Minimum element of via insertion sort with respect to
#insertionSortMinGiven a type with a decidable binary relation , an element , and a list of elements in , this function returns the element of the list located at the index defined by . This element is the one that would appear at the head (the first position) of the list after it has been sorted using the insertion sort algorithm with respect to the relation .
Let be a type with a decidable binary relation . For any element and list of elements in , the value is equal to the first element (the head) of the list obtained by sorting using the insertion sort algorithm with respect to .
List with the leftmost minimal element removed
#insertionSortDropMinPosLet be a decidable binary relation on a type . Given an element and a list of elements in , this function returns the list obtained by removing the element at the position from the list . Here, is the index of the leftmost minimal element of with respect to the relation .
Let be a type equipped with a decidable binary relation that is both total and transitive. For any element and list of elements in , sorting the list using insertion sort with respect to is equivalent to prepending the minimum element of to the sorted version of the list obtained by removing that same minimum element from : where is the element that appears at the head of the sorted list, and is the list with that specific element removed.
Insert or erase the -th element of a list
#optionEraseZLet be a list of elements of type , be an element of type , and be an optional index into (represented as an element of the type ). The function returns a new list of type according to the following cases: - If , the result is the list , which is with prepended to the front. - If for some index , the result is the list with the element at index removed.
Let be a list of elements of type and be an element of type . For any index of the list (represented as an element of type ), the length of the list resulting from —which is the list with the element at index removed—is equal to .
Extensionality of `optionEraseZ`
#optionEraseZ_extLet and be lists of elements of type , and let and be elements of type . Let and be optional indices into and respectively (where an index is either `none` or a specific position within the list). If the lists are equal (), the elements are equal (), and the indices are equal (), then the result of the `optionEraseZ` operation is the same for both: where the `optionEraseZ` operation returns if the index is `none`, and returns with the element at the specified index removed if the index is a specific position.
For any natural numbers and , and for any element (represented by the type `Fin n`), is a member of the list containing the first elements of the finite range if and only if the value of is strictly less than ().
