Zulip Chat Archive
Stream: general
Topic: lists
Andrew Ashworth (Feb 28 2018 at 01:57):
theorem append_inj : ∀ {s₁ s₂ t₁ t₂ : list α}, s₁ ++ t₁ = s₂ ++ t₂ → length s₁ = length s₂ → s₁ = s₂ ∧ t₁ = t₂ | [] [] t₁ t₂ h hl := ⟨rfl, h⟩ | (a::s₁) [] t₁ t₂ h hl := list.no_confusion $ eq_nil_of_length_eq_zero hl | [] (b::s₂) t₁ t₂ h hl := list.no_confusion $ eq_nil_of_length_eq_zero hl.symm | (a::s₁) (b::s₂) t₁ t₂ h hl := list.no_confusion h $ λab hap, let ⟨e1, e2⟩ := @append_inj s₁ s₂ t₁ t₂ hap (succ.inj hl) in by rw [ab, e1, e2]; exact ⟨rfl, rfl⟩
why is length s1 = length s2
required explicitly as a hypothesis?
Mario Carneiro (Feb 28 2018 at 01:58):
It's not true otherwise
Andrew Ashworth (Feb 28 2018 at 02:01):
ahh. i guess you'd only have a weaker conclusion without the length requirement, that two lists exist that are subsets of s1 ++ t1
Mario Carneiro (Feb 28 2018 at 02:02):
Of course that's a trivial consequence, s1
and t1
are such
Simon Hudon (Feb 28 2018 at 02:02):
If you don't want the length assumption, you could prove s0 ++ t0 = s1 ++ t1 -> s0 = t0 -> s1 = t1
Mario Carneiro (Feb 28 2018 at 02:03):
I guess that follows from this pretty easily, since if s0 = t0
then length s0 = length t0
Simon Hudon (Feb 28 2018 at 02:04):
Yeah, you're right! What was I thinking :stuck_out_tongue:
Andrew Ashworth (Feb 28 2018 at 02:04):
yeah it's something i'm having an issue with, I'm trying to prove that list reversal is injective from scratch
Mario Carneiro (Feb 28 2018 at 02:04):
The easiest way is to note that reverse
is an involution
Andrew Ashworth (Feb 28 2018 at 02:05):
lemma rev_involutive : ∀ l : list ℕ, rev (rev l) = l | nil := rfl | (x::xs) := by simp [*, rev, rev_step, rev_distrib]
Mario Carneiro (Feb 28 2018 at 02:06):
actually, another way, using that theorem, is to use the mirror version that assumes length t1 = length t2
; then you get that concat
is injective since the right parts have length 1
Andrew Ashworth (Feb 28 2018 at 02:07):
somebody had a prose proof in a conference paper i'm reading of how you can automatically prove injectivity of list reversal, and it's not working for me, haha
Andrew Ashworth (Feb 28 2018 at 02:08):
the concat def is really slick in core lib, i was trying to avoid using it
Andrew Ashworth (Feb 28 2018 at 02:14):
EDIT: I can't read good, they assume the lengths are equal in the pseudocode figure
Topologic (Sep 09 2022 at 22:24):
I'm trying to get a sense of the built in methods associated to the list type. I know the basic stack methods for it.
- concatenate is ++
- (a :: l) is push
Now, do the following operations need to be defined by hand?
- delete the ith entry
- add in x : T in the ith entry
- get the ith entry
- splice the list
- length of the list
Jason Rute (Sep 09 2022 at 22:28):
(deleted)
Jason Rute (Sep 09 2022 at 22:48):
I answered in the duplicate topic #Is there code for X? > Lists
Bolton Bailey (Sep 12 2022 at 22:33):
Note that docs#list.append and docs#list.concat are reversed from their normal definitions (we should probably fix this, but it's in lean rather than mathlib).
Last updated: Dec 20 2023 at 11:08 UTC