Physlib.Mathematics.List.InsertIdx
14 declarations
Mapping a function over a list commutes with element insertion:
#insertIdx_mapLet and be types and be a function. For any index , any list of elements in , and any element , the list obtained by inserting into at index and then applying to each element of the resulting list is equal to the list obtained by applying to each element of and then inserting at index . That is,
Erasing an element preserves the pairwise property of a list
#eraseIdx_sortedLet be a type and be a binary relation on . For any list of elements in and any index , if satisfies the pairwise relation (meaning holds for all pairs of elements in the list in their original order), then the list obtained by erasing the element at index also satisfies the pairwise relation .
for lists with no duplicates
#mem_eraseIdx_nodupLet be a list of elements of type and be a natural number representing an index such that . If contains no duplicate elements (), then for any element , is a member of the list obtained by erasing the element at index (denoted ) if and only if is a member of the original list and is not equal to the element of at index (denoted ).
Let be a list of elements of type and be an element of type . For any index such that , the list obtained by inserting into at position is equal to the concatenation of the first elements of , the element , and the remaining elements of starting from index . Mathematically, this is expressed as: where is the prefix of of length , and is the suffix of starting after the first elements.
Let be a list of elements of type and be an element. For any index in the range , the length of the list obtained by inserting into at position is equal to .
Let be a list of elements of type , be an element, be an insertion index, and be an index. Let be the list obtained by inserting into at index (i.e., `List.insertIdx r k i`). Then the element at position in the original list is equal to the element at the shifted index in , where . The mapping is defined such that if and if .
Inserting at index after erasing it restores
#insertIdx_eraseIdx_finFor any list and any valid index such that , inserting the original element at index into the list formed by erasing the element at index from results in the original list .
For any type , an element , and two lists of elements of , the result of inserting into the concatenated list at the index equal to the length of is equal to .
Let be a list of elements of type and be an element. For any insertion index , the function that retrieves the -th element of (for ) is equal to the composition of the index mapping and the retrieval function of the list obtained by inserting into at index . In other words, for any : where the mapping is defined as if and if .
For any list of elements of type , an element , and a natural number , the first elements of the list obtained by inserting into at index is equal to the first elements of the original list :
For any list of elements of type and any natural number , taking the first elements of the list obtained by erasing the element at index from is equal to taking the first elements of the original list . In symbols, .
For any list of elements of type and any natural number such that , it holds that: where denotes the -th element of the list, is the list with the element at index removed, is the sublist of starting from index , and denotes the operation of prepending an element to a list.
Taking elements is invariant under insertion at index
#take_insert_gtFor any type , an element , natural numbers and such that , and a list of elements from , the first elements of the list obtained by inserting into at index are the same as the first elements of the original list .
Taking elements after insertion at index is a permutation of prepended to taking elements
#take_insert_letLet be a type, an element of , and a list of elements of . For any natural numbers and such that and is less than or equal to the length of , the first elements of the list obtained by inserting into at index is a permutation of the list formed by prepending to the first elements of .
