Documentation

BasicLeanDatastructures.List.EraseDupsKeepRight

eraseDupsKeepRight #

In this file, we define the eraseDupsKeepRight convenience function that removes duplicates from a given list while keeping the rightmost occurrence. This function assumes DecidableEq on the list elements. As one would expect, the resulting list is free of duplicates and still contains the same members as the original list, which is shown in theorems below.

def List.eraseDupsKeepRight {α : Type u_1} [DecidableEq α] :
List αList α

Remove duplicates from a list, keeping the rightmost occurrense.

Equations
Instances For
    @[simp]
    theorem List.mem_eraseDupsKeepRight {α : Type u_1} [DecidableEq α] (l : List α) (e : α) :

    The deduplicated list contains the same elements as the original list.

    eraseDupsKeepRight can only make the list shorter.

    The deduplicated list indeed has no duplicates.

    @[simp]
    theorem List.eraseDupsKeepRight_eq_self_of_nodup {α : Type u_1} [DecidableEq α] (l : List α) (nodup : l.Nodup) :

    Erasing dups from a list without duplicates does not change anything.

    If the length after erasing duplicates remains the same, then the list contains no duplicates.

    @[simp]

    Calling eraseDupsKeepRight a second time does not change anything anymore.

    theorem List.length_eraseDupsKeepRight_eq_of_same_elements {α : Type u_1} [DecidableEq α] (l1 l2 : List α) :
    (∀ (e : α), e l1 e l2)l1.eraseDupsKeepRight.length = l2.eraseDupsKeepRight.length

    If two lists contain the same elements, then calling eraseDupsKeepRight on both ends up with lists of equal length. Again the lists might not be equal as they could differ in their order of elements.