The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V33. Data structures and computation

Mathlib.Data.List.Cycle

152 declarations. Mathlib docs · Source

Cycles of a list

Lists have an equivalence relation of whether they are rotational permutations of one another. This relation is defined as IsRotated.

Based on this, we define the quotient of lists by the rotation relation, called Cycle.

We also define a representation of concrete cycles, available when viewing them in a goal state or via #eval, when over representable types. For example, the cycle (2 1 4 3) will be shown as c[2, 1, 4, 3]. Two equal cycles may be printed differently if their internal representation is different.

theorem List.prev.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} (motive : (x : List α) → (x_1 : α) → x_1 ∈ x → Sort u_2) (x : List α) (x_1 : α) (x_2 : x_1 ∈ x)
  (h_1 : (x : α) → (h : x ∈ []) → motive [] x h) (h_2 : (y x : α) → (x_3 : x ∈ [y]) → motive [y] x x_3)
  (h_3 : (y z : α) → (xs : List α) → (x : α) → (h : x ∈ y :: z :: xs) → motive (y :: z :: xs) x h) (y x_3 : α)
  (x_4 : x_3 ∈ [y]),
  x = [y] →
    x_1 = x_3 →
      x_2 ≍ x_4 →
        (match x, x_1, x_2 with
          | [], x, h => h_1 x h
          | [y], x, x_5 => h_2 y x x_5
          | y :: z :: xs, x, h => h_3 y z xs x h) ≍
          h_2 y x_3 x_4

theorem List.next.congr_simp E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l l_1 : List α) (e_l : l = l_1) (x x_1 : α) (e_x : x = x_1) (h : x ∈ l),
  l.next x h = l_1.next x_1 ⋯

theorem decidable_of_iff'.congr_simp E1 #

∀ {a : Prop} (b b_1 : Prop) (e_b : b = b_1) (h : a ↔ b) {inst : Decidable b} [inst_1 : Decidable b_1],
  decidable_of_iff' b h = decidable_of_iff' b_1 ⋯

theorem List.nextOr.match_1.congr_eq_3 E1 #

∀ {α : Type u_1} (motive : List α → α → α → Sort u_2) (x : List α) (x_1 x_2 : α)
  (h_1 : (x default : α) → motive [] x default) (h_2 : (head x default : α) → motive [head] x default)
  (h_3 : (y z : α) → (xs : List α) → (x default : α) → motive (y :: z :: xs) x default) (y z : α) (xs : List α)
  (x_3 default : α),
  x = y :: z :: xs →
    x_1 = x_3 →
      x_2 = default →
        (match x, x_1, x_2 with
          | [], x, default => h_1 x default
          | [head], x, default => h_2 head x default
          | y :: z :: xs, x, default => h_3 y z xs x default) ≍
          h_3 y z xs x_3 default

theorem Cycle.next.congr_simp E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (s s_1 : Cycle α) (e_s : s = s_1) (_hs : s.Nodup) (x x_1 : α) (e_x : x = x_1)
  (_hx : x ∈ s), s.next _hs x _hx = s_1.next ⋯ x_1 ⋯

theorem List.prev.match_1.congr_eq_3 E1 #

∀ {α : Type u_1} (motive : (x : List α) → (x_1 : α) → x_1 ∈ x → Sort u_2) (x : List α) (x_1 : α) (x_2 : x_1 ∈ x)
  (h_1 : (x : α) → (h : x ∈ []) → motive [] x h) (h_2 : (y x : α) → (x_3 : x ∈ [y]) → motive [y] x x_3)
  (h_3 : (y z : α) → (xs : List α) → (x : α) → (h : x ∈ y :: z :: xs) → motive (y :: z :: xs) x h) (y z : α)
  (xs : List α) (x_3 : α) (h : x_3 ∈ y :: z :: xs),
  x = y :: z :: xs →
    x_1 = x_3 →
      x_2 ≍ h →
        (match x, x_1, x_2 with
          | [], x, h => h_1 x h
          | [y], x, x_4 => h_2 y x x_4
          | y :: z :: xs, x, h => h_3 y z xs x h) ≍
          h_3 y z xs x_3 h

theorem List.next.hcongr_5 E1 #

∀ (α α' : Type u_1),
  α = α' →
    ∀ (inst : DecidableEq α) (inst' : DecidableEq α'),
      inst ≍ inst' →
        ∀ (l : List α) (l' : List α'),
          l ≍ l' → ∀ (x : α) (x' : α'), x ≍ x' → ∀ (h : x ∈ l) (h' : x' ∈ l'), h ≍ h' → l.next x h ≍ l'.next x' h'

theorem List.nextOr.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : List α → α → α → Sort u_2) (x : List α) (x_1 x_2 : α)
  (h_1 : (x default : α) → motive [] x default) (h_2 : (head x default : α) → motive [head] x default)
  (h_3 : (y z : α) → (xs : List α) → (x default : α) → motive (y :: z :: xs) x default) (x_3 default : α),
  x = [] →
    x_1 = x_3 →
      x_2 = default →
        (match x, x_1, x_2 with
          | [], x, default => h_1 x default
          | [head], x, default => h_2 head x default
          | y :: z :: xs, x, default => h_3 y z xs x default) ≍
          h_1 x_3 default

theorem List.nextOr.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} (motive : List α → α → α → Sort u_2) (x : List α) (x_1 x_2 : α)
  (h_1 : (x default : α) → motive [] x default) (h_2 : (head x default : α) → motive [head] x default)
  (h_3 : (y z : α) → (xs : List α) → (x default : α) → motive (y :: z :: xs) x default) (head x_3 default : α),
  x = [head] →
    x_1 = x_3 →
      x_2 = default →
        (match x, x_1, x_2 with
          | [], x, default => h_1 x default
          | [head], x, default => h_2 head x default
          | y :: z :: xs, x, default => h_3 y z xs x default) ≍
          h_2 head x_3 default

theorem List.prev.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : (x : List α) → (x_1 : α) → x_1 ∈ x → Sort u_2) (x : List α) (x_1 : α) (x_2 : x_1 ∈ x)
  (h_1 : (x : α) → (h : x ∈ []) → motive [] x h) (h_2 : (y x : α) → (x_3 : x ∈ [y]) → motive [y] x x_3)
  (h_3 : (y z : α) → (xs : List α) → (x : α) → (h : x ∈ y :: z :: xs) → motive (y :: z :: xs) x h) (x_3 : α)
  (h : x_3 ∈ []),
  x = [] →
    x_1 = x_3 →
      x_2 ≍ h →
        (match x, x_1, x_2 with
          | [], x, h => h_1 x h
          | [y], x, x_4 => h_2 y x x_4
          | y :: z :: xs, x, h => h_3 y z xs x h) ≍
          h_1 x_3 h

theorem List.prev.congr_simp E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l l_1 : List α) (e_l : l = l_1) (x x_1 : α) (e_x : x = x_1) (a : x ∈ l),
  l.prev x a = l_1.prev x_1 ⋯

theorem Cycle.prev.congr_simp E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (s s_1 : Cycle α) (e_s : s = s_1) (_hs : s.Nodup) (x x_1 : α) (e_x : x = x_1)
  (_hx : x ∈ s), s.prev _hs x _hx = s_1.prev ⋯ x_1 ⋯

def List.nextOr E1 #

{α : Type u_1} → [DecidableEq α] → List α → α → α → α

Return the z such that x :: z :: _ appears in xs, or default if there is no such z.

theorem List.nextOr_nil E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (x d : α), [].nextOr x d = d

theorem List.nextOr_singleton E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (x y d : α), [y].nextOr x d = d

theorem List.nextOr_self_cons_cons E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (xs : List α) (x y d : α), (x :: y :: xs).nextOr x d = y

theorem List.nextOr_cons_of_ne E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (xs : List α) (y x d : α), x ≠ y → (y :: xs).nextOr x d = xs.nextOr x d

theorem List.nextOr_eq_nextOr_of_mem_dropLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (xs : List α) (x d d' : α), x ∈ xs.dropLast → xs.nextOr x d = xs.nextOr x d'

nextOr does not depend on the default value, if the next value appears.

theorem List.mem_of_nextOr_ne E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {xs : List α} {x d : α}, xs.nextOr x d ≠ d → x ∈ xs

theorem List.nextOr_concat E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {xs : List α} {x : α} (d : α), x ∉ xs → (xs ++ [x]).nextOr x d = d

theorem List.nextOr_mem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {xs : List α} {x d : α}, d ∈ xs → xs.nextOr x d ∈ xs

def List.next E1 #

{α : Type u_1} → [DecidableEq α] → (l : List α) → (x : α) → x ∈ l → α

Given an element x : α of l : List α such that x ∈ l, get the next element of l. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates.

For example:

  • next [1, 2, 3] 2 _ = 3
  • next [1, 2, 3] 3 _ = 1
  • next [1, 2, 3, 2, 4] 2 _ = 3
  • next [1, 2, 3, 2] 2 _ = 3
  • next [1, 1, 2, 3, 2] 1 _ = 1

def List.prev E1 #

{α : Type u_1} → [DecidableEq α] → (l : List α) → (x : α) → x ∈ l → α

Given an element x : α of l : List α such that x ∈ l, get the previous element of l. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates.

  • prev [1, 2, 3] 2 _ = 1
  • prev [1, 2, 3] 1 _ = 3
  • prev [1, 2, 3, 2, 4] 2 _ = 1
  • prev [1, 2, 3, 4, 2] 2 _ = 1
  • prev [1, 1, 2] 1 _ = 2

theorem List.next_singleton E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (x y : α) (h : x ∈ [y]), [y].next x h = y

theorem List.prev_singleton E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (x y : α) (h : x ∈ [y]), [y].prev x h = y

theorem List.next_cons_cons_eq' E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y z : α) (h : x ∈ y :: z :: l),
  x = y → (y :: z :: l).next x h = z

theorem List.next_cons_cons_eq E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x z : α) (h : x ∈ x :: z :: l), (x :: z :: l).next x h = z

theorem List.next_cons_eq_next_of_mem_dropLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x : α) (h : x ∈ l.dropLast) (y : α),
  x ≠ y → (y :: l).next x ⋯ = l.next x ⋯

theorem List.next_cons_concat E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y : α),
  x ≠ y → x ∉ l → ∀ (h : optParam (x ∈ y :: l ++ [x]) ⋯), (y :: l ++ [x]).next x h = y

theorem List.next_getLast_cons E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y : α) (h : x ∈ y :: l),
  x ≠ y → x = (y :: l).getLast ⋯ → l.Nodup → (y :: l).next x h = y

theorem List.prev_getLast_cons' E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y : α) (hxy : x ∈ y :: l),
  x = y → (y :: l).prev x hxy = (y :: l).getLast ⋯

theorem List.prev_getLast_cons E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x : α) (h : x ∈ x :: l), (x :: l).prev x h = (x :: l).getLast ⋯

theorem List.prev_head_eq_getLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (hl : l ≠ []), l.prev (l.head hl) ⋯ = l.getLast hl

theorem List.prev_cons_cons_eq' E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y z : α) (h : x ∈ y :: z :: l),
  x = y → (y :: z :: l).prev x h = (z :: l).getLast ⋯

theorem List.prev_cons_cons_eq E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x z : α) (h : x ∈ x :: z :: l),
  (x :: z :: l).prev x h = (z :: l).getLast ⋯

theorem List.prev_cons_cons_of_ne' E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y z : α) (h : x ∈ y :: z :: l),
  x ≠ y → x = z → (y :: z :: l).prev x h = y

theorem List.prev_cons_cons_of_ne E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y : α) (h : x ∈ y :: x :: l), x ≠ y → (y :: x :: l).prev x h = y

theorem List.prev_ne_cons_cons E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y),
  x ≠ z → (y :: z :: l).prev x h = (z :: l).prev x ⋯

theorem List.next_mem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x : α) (h : x ∈ l), l.next x h ∈ l

theorem List.prev_mem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (x : α) (h : x ∈ l), l.prev x h ∈ l

theorem List.nextOr_eq_getElem?_idxOf_succ_of_mem_dropLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α},
  a ∈ l.dropLast → ∀ (d : α), some (l.nextOr a d) = l[List.idxOf a l + 1]?

theorem List.nextOr_eq_getElem_idxOf_succ_of_mem_dropLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α} (ha : a ∈ l.dropLast) (d : α),
  l.nextOr a d = l[List.idxOf a l + 1]

theorem List.nextOr_infix_of_mem_dropLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α}, a ∈ l.dropLast → ∀ (d : α), [a, l.nextOr a d] <:+: l

theorem List.nextOr_getLast_of_notMem_dropLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} (hl : l ≠ []),
  l.getLast hl ∉ l.dropLast → ∀ (d : α), l.nextOr (l.getLast hl) d = d

theorem List.next_getLast_eq_head_of_notMem_dropLast E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} (hl : l ≠ []),
  l.getLast hl ∉ l.dropLast → l.next (l.getLast hl) ⋯ = l.head hl

theorem List.next_eq_getElem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α} (ha : a ∈ l),
  l.next a ha = l[(List.idxOf a l + 1) % l.length]

theorem List.next_getElem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α),
  l.Nodup → ∀ (i : ℕ) (hi : i < l.length), l.next l[i] ⋯ = l[(i + 1) % l.length]

theorem List.prev_eq_getElem?_idxOf_pred_of_ne_head E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α} (ha : a ∈ l),
  a ≠ l.head ⋯ → some (l.prev a ha) = l[List.idxOf a l - 1]?

theorem List.prev_eq_getElem_idxOf_pred_of_ne_head E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α} (ha : a ∈ l),
  a ≠ l.head ⋯ → l.prev a ha = l[List.idxOf a l - 1]

theorem List.prev_infix_of_mem_tail E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α} (ha : a ∈ l), a ≠ l.head ⋯ → [l.prev a ha, a] <:+: l

theorem List.prev_eq_getElem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {l : List α} {a : α} (ha : a ∈ l),
  l.prev a ha = l[(List.idxOf a l + (l.length - 1)) % l.length]

theorem List.prev_getElem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α),
  l.Nodup → ∀ (i : ℕ) (hi : i < l.length), l.prev l[i] ⋯ = l[(i + (l.length - 1)) % l.length]

theorem List.next_getLast_eq_head E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (h : l ≠ []), l.Nodup → l.next (l.getLast h) ⋯ = l.head h

theorem List.pmap_next_eq_rotate_one E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l.Nodup → List.pmap l.next l ⋯ = l.rotate 1

theorem List.pmap_prev_eq_rotate_length_sub_one E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l.Nodup → List.pmap l.prev l ⋯ = l.rotate (l.length - 1)

theorem List.prev_next E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l.Nodup → ∀ (x : α) (hx : x ∈ l), l.prev (l.next x hx) ⋯ = x

theorem List.next_prev E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l.Nodup → ∀ (x : α) (hx : x ∈ l), l.next (l.prev x hx) ⋯ = x

theorem List.prev_reverse_eq_next E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l.Nodup → ∀ (x : α) (hx : x ∈ l), l.reverse.prev x ⋯ = l.next x hx

theorem List.next_reverse_eq_prev E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l.Nodup → ∀ (x : α) (hx : x ∈ l), l.reverse.next x ⋯ = l.prev x hx

theorem List.isRotated_next_eq E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {l l' : List α} (h : l ~r l'),
  l.Nodup → ∀ {x : α} (hx : x ∈ l), l.next x hx = l'.next x ⋯

theorem List.isRotated_prev_eq E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {l l' : List α} (h : l ~r l'),
  l.Nodup → ∀ {x : α} (hx : x ∈ l), l.prev x hx = l'.prev x ⋯

def Cycle E1 #

Type u_1 → Type u_1

Cycle α is the quotient of List α by cyclic permutation. Duplicates are allowed.

def Cycle.ofList E1 #

{α : Type u_1} → List α → Cycle α

The coercion from List α to Cycle α

instance Cycle.instCoeList E0 #

{α : Type u_1} → Coe (List α) (Cycle α)

theorem Cycle.coe_eq_coe E0 #

∀ {α : Type u_1} {l₁ l₂ : List α}, ↑l₁ = ↑l₂ ↔ l₁ ~r l₂

theorem Cycle.mk_eq_coe E0 #

∀ {α : Type u_1} (l : List α), Quot.mk (⇑(List.IsRotated.setoid α)) l = ↑l

theorem Cycle.mk''_eq_coe E0 #

∀ {α : Type u_1} (l : List α), Quotient.mk'' l = ↑l

theorem Cycle.coe_cons_eq_coe_append E0 #

∀ {α : Type u_1} (l : List α) (a : α), ↑(a :: l) = ↑(l ++ [a])

def Cycle.nil E1 #

{α : Type u_1} → Cycle α

The unique empty cycle.

theorem Cycle.coe_nil E0 #

∀ {α : Type u_1}, ↑[] = Cycle.nil

theorem Cycle.coe_eq_nil E0 #

∀ {α : Type u_1} (l : List α), ↑l = Cycle.nil ↔ l = []

instance Cycle.instEmptyCollection E0 #

{α : Type u_1} → EmptyCollection (Cycle α)

For consistency with EmptyCollection (List α).

theorem Cycle.empty_eq E0 #

∀ {α : Type u_1}, ∅ = Cycle.nil

instance Cycle.instInhabited E0 #

{α : Type u_1} → Inhabited (Cycle α)

theorem Cycle.induction_on E1 #

∀ {α : Type u_1} {motive : Cycle α → Prop} (s : Cycle α),
  motive Cycle.nil → (∀ (a : α) (l : List α), motive ↑l → motive ↑(a :: l)) → motive s

An induction principle for Cycle. Use as induction s.

def Cycle.Mem E1 #

{α : Type u_1} → Cycle α → α → Prop

For x : α, s : Cycle α, x ∈ s indicates that x occurs at least once in s.

instance Cycle.instMembership E0 #

{α : Type u_1} → Membership α (Cycle α)

theorem Cycle.mem_coe_iff E0 #

∀ {α : Type u_1} {a : α} {l : List α}, a ∈ ↑l ↔ a ∈ l

theorem Cycle.notMem_nil E0 #

∀ {α : Type u_1} (a : α), a ∉ Cycle.nil

instance Cycle.instDecidableEq E0 #

{α : Type u_1} → [DecidableEq α] → DecidableEq (Cycle α)

instance Cycle.instDecidableMemOfDecidableEq E0 #

{α : Type u_1} → [DecidableEq α] → (x : α) → (s : Cycle α) → Decidable (x ∈ s)

def Cycle.reverse E1 #

{α : Type u_1} → Cycle α → Cycle α

Reverse a s : Cycle α by reversing the underlying List.

theorem Cycle.reverse_coe E0 #

∀ {α : Type u_1} (l : List α), (↑l).reverse = ↑l.reverse

theorem Cycle.mem_reverse_iff E0 #

∀ {α : Type u_1} {a : α} {s : Cycle α}, a ∈ s.reverse ↔ a ∈ s

theorem Cycle.reverse_reverse E0 #

∀ {α : Type u_1} (s : Cycle α), s.reverse.reverse = s

theorem Cycle.reverse_nil E0 #

∀ {α : Type u_1}, Cycle.nil.reverse = Cycle.nil

def Cycle.length E1 #

{α : Type u_1} → Cycle α → ℕ

The length of the s : Cycle α, which is the number of elements, counting duplicates.

theorem Cycle.length_coe E0 #

∀ {α : Type u_1} (l : List α), (↑l).length = l.length

theorem Cycle.length_nil E0 #

∀ {α : Type u_1}, Cycle.nil.length = 0

theorem Cycle.length_reverse E0 #

∀ {α : Type u_1} (s : Cycle α), s.reverse.length = s.length

def Cycle.Subsingleton E1 #

{α : Type u_1} → Cycle α → Prop

A s : Cycle α that is at most one element.

theorem Cycle.subsingleton_nil E1 #

∀ {α : Type u_1}, Cycle.nil.Subsingleton

theorem Cycle.length_subsingleton_iff E0 #

∀ {α : Type u_1} {s : Cycle α}, s.Subsingleton ↔ s.length ≤ 1

theorem Cycle.subsingleton_reverse_iff E0 #

∀ {α : Type u_1} {s : Cycle α}, s.reverse.Subsingleton ↔ s.Subsingleton

theorem Cycle.Subsingleton.congr E1 #

∀ {α : Type u_1} {s : Cycle α}, s.Subsingleton → ∀ ⦃x : α⦄, x ∈ s → ∀ ⦃y : α⦄, y ∈ s → x = y

def Cycle.Nontrivial E1 #

{α : Type u_1} → Cycle α → Prop

A s : Cycle α that is made up of at least two unique elements.

theorem Cycle.nontrivial_coe_nodup_iff E0 #

∀ {α : Type u_1} {l : List α}, l.Nodup → ((↑l).Nontrivial ↔ 2 ≤ l.length)

theorem Cycle.nontrivial_reverse_iff E0 #

∀ {α : Type u_1} {s : Cycle α}, s.reverse.Nontrivial ↔ s.Nontrivial

theorem Cycle.length_nontrivial E1 #

∀ {α : Type u_1} {s : Cycle α}, s.Nontrivial → 2 ≤ s.length

def Cycle.Nodup E1 #

{α : Type u_1} → Cycle α → Prop

The s : Cycle α contains no duplicates.

theorem Cycle.nodup_nil E0 #

∀ {α : Type u_1}, Cycle.nil.Nodup

theorem Cycle.nodup_coe_iff E0 #

∀ {α : Type u_1} {l : List α}, (↑l).Nodup ↔ l.Nodup

theorem Cycle.nodup_reverse_iff E0 #

∀ {α : Type u_1} {s : Cycle α}, s.reverse.Nodup ↔ s.Nodup

theorem Cycle.Subsingleton.nodup E1 #

∀ {α : Type u_1} {s : Cycle α}, s.Subsingleton → s.Nodup

theorem Cycle.Nodup.nontrivial_iff E0 #

∀ {α : Type u_1} {s : Cycle α}, s.Nodup → (s.Nontrivial ↔ ¬s.Subsingleton)

def Cycle.toMultiset E1 #

{α : Type u_1} → Cycle α → Multiset α

The s : Cycle α as a Multiset α.

theorem Cycle.coe_toMultiset E0 #

∀ {α : Type u_1} (l : List α), (↑l).toMultiset = ↑l

theorem Cycle.nil_toMultiset E0 #

∀ {α : Type u_1}, Cycle.nil.toMultiset = 0

theorem Cycle.card_toMultiset E0 #

∀ {α : Type u_1} (s : Cycle α), s.toMultiset.card = s.length

theorem Cycle.toMultiset_eq_nil E0 #

∀ {α : Type u_1} {s : Cycle α}, s.toMultiset = 0 ↔ s = Cycle.nil

def Cycle.map E1 #

{α : Type u_1} → {β : Type u_2} → (α → β) → Cycle α → Cycle β

The lift of list.map.

theorem Cycle.map_nil E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β), Cycle.map f Cycle.nil = Cycle.nil

theorem Cycle.map_coe E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (l : List α), Cycle.map f ↑l = ↑(List.map f l)

theorem Cycle.map_eq_nil E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (s : Cycle α), Cycle.map f s = Cycle.nil ↔ s = Cycle.nil

theorem Cycle.mem_map E0 #

∀ {α : Type u_1} {β : Type u_2} {f : α → β} {b : β} {s : Cycle α}, b ∈ Cycle.map f s ↔ ∃ a ∈ s, f a = b

def Cycle.lists E1 #

{α : Type u_1} → Cycle α → Multiset (List α)

The Multiset of lists that can make the cycle.

theorem Cycle.lists_coe E0 #

∀ {α : Type u_1} (l : List α), (↑l).lists = ↑l.cyclicPermutations

theorem Cycle.mem_lists_iff_coe_eq E0 #

∀ {α : Type u_1} {s : Cycle α} {l : List α}, l ∈ s.lists ↔ ↑l = s

theorem Cycle.lists_nil E0 #

∀ {α : Type u_1}, Cycle.nil.lists = {[]}

def Cycle.decidableNontrivialCoe E1 #

{α : Type u_1} → [DecidableEq α] → (l : List α) → Decidable (↑l).Nontrivial

Auxiliary decidability algorithm for lists that contain at least two unique elements.

instance Cycle.instDecidableNontrivial E0 #

{α : Type u_1} → [DecidableEq α] → {s : Cycle α} → Decidable s.Nontrivial

instance Cycle.instDecidableNodup E0 #

{α : Type u_1} → [DecidableEq α] → {s : Cycle α} → Decidable s.Nodup

instance Cycle.fintypeNodupCycle E0 #

{α : Type u_1} → [DecidableEq α] → [Fintype α] → Fintype { s // s.Nodup }

instance Cycle.fintypeNodupNontrivialCycle E0 #

{α : Type u_1} → [DecidableEq α] → [Fintype α] → Fintype { s // s.Nodup ∧ s.Nontrivial }

def Cycle.toFinset E1 #

{α : Type u_1} → [DecidableEq α] → Cycle α → Finset α

The s : Cycle α as a Finset α.

theorem Cycle.toFinset_toMultiset E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α), s.toMultiset.toFinset = s.toFinset

theorem Cycle.coe_toFinset E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), (↑l).toFinset = l.toFinset

theorem Cycle.nil_toFinset E0 #

∀ {α : Type u_1} [inst : DecidableEq α], Cycle.nil.toFinset = ∅

theorem Cycle.toFinset_eq_nil E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {s : Cycle α}, s.toFinset = ∅ ↔ s = Cycle.nil

def Cycle.next E1 #

{α : Type u_1} → [DecidableEq α] → (s : Cycle α) → s.Nodup → (x : α) → x ∈ s → α

Given a s : Cycle α such that Nodup s, retrieve the next element after x ∈ s.

def Cycle.prev E1 #

{α : Type u_1} → [DecidableEq α] → (s : Cycle α) → s.Nodup → (x : α) → x ∈ s → α

Given a s : Cycle α such that Nodup s, retrieve the previous element before x ∈ s.

theorem Cycle.prev_reverse_eq_next E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.Nodup) (x : α) (hx : x ∈ s),
  s.reverse.prev ⋯ x ⋯ = s.next hs x hx

theorem Cycle.prev_reverse_eq_next' E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.reverse.Nodup) (x : α) (hx : x ∈ s.reverse),
  s.reverse.prev hs x hx = s.next ⋯ x ⋯

theorem Cycle.next_reverse_eq_prev E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.Nodup) (x : α) (hx : x ∈ s),
  s.reverse.next ⋯ x ⋯ = s.prev hs x hx

theorem Cycle.next_reverse_eq_prev' E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.reverse.Nodup) (x : α) (hx : x ∈ s.reverse),
  s.reverse.next hs x hx = s.prev ⋯ x ⋯

theorem Cycle.next_mem E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.Nodup) (x : α) (hx : x ∈ s), s.next hs x hx ∈ s

theorem Cycle.prev_mem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.Nodup) (x : α) (hx : x ∈ s), s.prev hs x hx ∈ s

theorem Cycle.prev_next E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.Nodup) (x : α) (hx : x ∈ s),
  s.prev hs (s.next hs x hx) ⋯ = x

theorem Cycle.next_prev E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (s : Cycle α) (hs : s.Nodup) (x : α) (hx : x ∈ s),
  s.next hs (s.prev hs x hx) ⋯ = x

instance Cycle.instRepr E0 #

{α : Type u_1} → [Repr α] → Repr (Cycle α)

We define a representation of concrete cycles, available when viewing them in a goal state or via #eval, when over representable types. For example, the cycle (2 1 4 3) will be shown as c[2, 1, 4, 3]. Two equal cycles may be printed differently if their internal representation is different.

def Cycle.Chain E1 #

{α : Type u_1} → (α → α → Prop) → Cycle α → Prop

chain R s means that R holds between adjacent elements of s.

chain R ([a, b, c] : Cycle α) ↔ R a b ∧ R b c ∧ R c a

theorem Cycle.Chain.nil E0 #

∀ {α : Type u_1} (r : α → α → Prop), Cycle.Chain r Cycle.nil

theorem Cycle.chain_coe_cons E0 #

∀ {α : Type u_1} (r : α → α → Prop) (a : α) (l : List α), Cycle.Chain r ↑(a :: l) ↔ List.IsChain r (a :: (l ++ [a]))

theorem Cycle.chain_singleton E1 #

∀ {α : Type u_1} (r : α → α → Prop) (a : α), Cycle.Chain r ↑[a] ↔ r a a

theorem Cycle.chain_ne_nil E1 #

∀ {α : Type u_1} (r : α → α → Prop) {l : List α} (hl : l ≠ []), Cycle.Chain r ↑l ↔ List.IsChain r (l.getLast hl :: l)

theorem Cycle.chain_map E1 #

∀ {α : Type u_1} {β : Type u_2} {r : α → α → Prop} (f : β → α) {s : Cycle β},
  Cycle.Chain r (Cycle.map f s) ↔ Cycle.Chain (fun a b ↦ r (f a) (f b)) s

theorem Cycle.chain_range_succ E1 #

∀ (r : ℕ → ℕ → Prop) (n : ℕ), Cycle.Chain r ↑(List.range n.succ) ↔ r n 0 ∧ ∀ m < n, r m m.succ

theorem Cycle.Chain.imp E1 #

∀ {α : Type u_1} {s : Cycle α} {r₁ r₂ : α → α → Prop},
  (∀ (a b : α), r₁ a b → r₂ a b) → Cycle.Chain r₁ s → Cycle.Chain r₂ s

theorem Cycle.chain_mono E1 #

∀ {α : Type u_1}, Monotone Cycle.Chain

As a function from a relation to a predicate, chain is monotonic.

theorem Cycle.chain_of_pairwise E1 #

∀ {α : Type u_1} {r : α → α → Prop} {s : Cycle α}, (∀ a ∈ s, ∀ b ∈ s, r a b) → Cycle.Chain r s

theorem Cycle.chain_iff_pairwise E1 #

∀ {α : Type u_1} {r : α → α → Prop} {s : Cycle α} [IsTrans α r], Cycle.Chain r s ↔ ∀ a ∈ s, ∀ b ∈ s, r a b

theorem Cycle.forall_eq_of_chain E1 #

∀ {α : Type u_1} {r : α → α → Prop} {s : Cycle α} [IsTrans α r] [Std.Antisymm r],
  Cycle.Chain r s → ∀ {a b : α}, a ∈ s → b ∈ s → a = b