Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

(a :: l ++ [b]).last' does not simplify to some b #18010

@jcpaik

Description

@jcpaik

For a list with ends a and b, simp does not simplify its last' to some b:

import data.list

variable {α : Type*}
example (a b : α) (l : list α) : (a :: l ++ [b]).last' = some b :=
begin simp, sorry end

A possible workaround is to add the following simp lemma.

import data.list

variable {α : Type*}
@[simp]
theorem list.last'_cons_append_cons (a b : α) (l1 l2 : list α) : 
  (a :: (l1 ++ b :: l2)).last' = (b :: l2).last' := 
by revert a; induction l1 with c l1 ih; simp; intro; exact ih c

-- Now this works
example (a b : α) (l : list α) : (a :: l ++ [b]).last' = some b := by simp

How about we add the lemma above to mathlib?

I think a similar lemma for list.last (without ticks) can be also proved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions