Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add String.splitOn_of_valid #743

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

chabulhwi
Copy link
Contributor

@chabulhwi chabulhwi commented Apr 16, 2024

String.splitOn_of_valid is the first of the eleven unproved theorems
about strings. I added the following to prove it:

  • lemmas about Nat.add and lists
  • the file Batteries.Data.List.SplitOnList
  • the theorem String.splitOnAux_of_valid

This is the third version of #495 and includes #531. The second version is #719.

@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch 4 times, most recently from 2df1e65 to 3699b5d Compare April 16, 2024 09:30
@chabulhwi
Copy link
Contributor Author

awaiting-review

@github-actions github-actions bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Apr 16, 2024
@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch 4 times, most recently from 75b032f to dd5f11a Compare April 17, 2024 01:22
@kim-em
Copy link
Collaborator

kim-em commented Apr 17, 2024

This is doing too many things at once. Can you split out the preliminary steps (upstreaming from Mathlib) as separate PRs?

@kim-em kim-em added awaiting-author Waiting for PR author to address issues and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Apr 17, 2024
@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch 4 times, most recently from e6b2836 to cf96e0e Compare April 19, 2024 14:53
@chabulhwi
Copy link
Contributor Author

chabulhwi commented Apr 19, 2024

This is doing too many things at once. Can you split out the preliminary steps (upstreaming from Mathlib) as separate PRs?

@semorrison I've split these commits into separate PRs.

@chabulhwi
Copy link
Contributor Author

awaiting-review

@github-actions github-actions bot added awaiting-review This PR is ready for review; the author thinks it is ready to be merged. and removed awaiting-author Waiting for PR author to address issues labels Apr 19, 2024
@chabulhwi chabulhwi changed the title feat: add String.splitOn_of_valid feat: add String.splitOn_of_valid Apr 19, 2024
@kim-em kim-em added depends on another PR This is stacked on top of another Batteries PR. and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Apr 24, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label May 2, 2024
@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch from cf96e0e to 55046a9 Compare May 3, 2024 01:28
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label May 3, 2024
@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch from 55046a9 to 4af3b7e Compare May 3, 2024 01:55
@chabulhwi
Copy link
Contributor Author

I resolved merge conflicts.

Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Sep 3, 2024
@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch 3 times, most recently from 753a314 to 46482de Compare September 3, 2024 06:14
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Sep 10, 2024
chabulhwi added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 14, 2024
`List.modifyHead_modifyHead` is from `Mathlib.Data.List.Basic`. I need
it to prove `String.splitOn_of_valid`. See
leanprover-community/batteries#743.

Corresponding Batteries PR:
leanprover-community/batteries#756
chabulhwi added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 14, 2024
`List.modifyHead_modifyHead` is from `Mathlib.Data.List.Basic`. I need
it to prove `String.splitOn_of_valid`. See
leanprover-community/batteries#743.

Corresponding Batteries PR:
leanprover-community/batteries#756
mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request Oct 14, 2024
`List.modifyHead_modifyHead` is from `Mathlib.Data.List.Basic`. I need
it to prove `String.splitOn_of_valid`. See
leanprover-community/batteries#743.

Corresponding Batteries PR:
leanprover-community/batteries#756



Co-authored-by: Kim Morrison <[email protected]>
@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch 2 times, most recently from f0f1fc8 to da23815 Compare October 14, 2024 08:01
@chabulhwi
Copy link
Contributor Author

awaiting-review

@github-actions github-actions bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Oct 14, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Oct 14, 2024
@chabulhwi
Copy link
Contributor Author

chabulhwi commented Oct 14, 2024

@chabulhwi said:

The following three lemmas about lists in Batteries#743 aren't necessary for proving the theorem String.splitOn_of_valid, which is the whole point of this pull request. Should I move these lemmas to a separate PR or just remove them?

import Batteries.Control.ForInStep.Lemmas
import Batteries.Data.List.Basic
import Batteries.Tactic.Init
import Batteries.Tactic.Alias

namespace List

-- NOTE: I need this lemma.
theorem head_cons_tail : ∀ l h, @head α l h :: l.tail = l
  | _::_, _ => rfl

theorem singleton_head_eq_self (l : List α) (hne : l ≠ []) (htl : l.tail = []) :
    [l.head hne] = l := by
  conv => rhs; rw [← head_cons_tail l hne, htl]

theorem singleton_prefix_cons (a) : [a] <+: a :: l :=
  (prefix_cons_inj a).mpr nil_prefix

-- NOTE: I need this lemma.
theorem ne_nil_of_not_prefix (h : ¬l₁ <+: l₂) : l₁ ≠ [] := by
  intro heq
  simp [heq, nil_prefix] at h

theorem not_prefix_and_not_prefix_symm_iff_exists [BEq α] [LawfulBEq α] [DecidableEq α]
    {l₁ l₂ : List α} : ¬l₁ <+: l₂ ∧ ¬l₂ <+: l₁ ↔ ∃ c₁ c₂ pre suf₁ suf₂, c₁ ≠ c₂ ∧
      l₁ = pre ++ c₁ :: suf₁ ∧ l₂ = pre ++ c₂ :: suf₂ := by
  constructor <;> intro h
  · obtain ⟨c₁, l₁, rfl⟩ := l₁.exists_cons_of_ne_nil (ne_nil_of_not_prefix h.1)
    obtain ⟨c₂, l₂, rfl⟩ := l₂.exists_cons_of_ne_nil (ne_nil_of_not_prefix h.2)
    simp only [cons_prefix_cons, not_and] at h
    cases Decidable.em (c₁ = c₂)
    · subst c₂
      simp only [forall_const] at h
      let ⟨c₁', c₂', pre, suf₁, suf₂, hc, heq₁, heq₂⟩ :=
        not_prefix_and_not_prefix_symm_iff_exists.mp h
      exact ⟨c₁', c₂', c₁::pre, suf₁, suf₂, hc, by simp [heq₁], by simp [heq₂]⟩
    · next hc =>
      exact ⟨c₁, c₂, [], l₁, l₂, hc, nil_append .., nil_append ..⟩
  · let ⟨c₁, c₂, pre, suf₁, suf₂, hc, heq₁, heq₂⟩ := h
    rw [heq₁, heq₂]
    simp [prefix_append_right_inj, cons_prefix_cons, hc, hc.symm]

end List

I moved them to a new PR: #987.

chabulhwi added a commit to chabulhwi/batteries that referenced this pull request Oct 14, 2024
These are 'leftover' lemmas I created while trying to prove
`String.splitOn_of_valid`. See
leanprover-community#743.
chabulhwi added a commit to chabulhwi/batteries that referenced this pull request Oct 14, 2024
These are 'leftover' lemmas I created while trying to prove
`String.splitOn_of_valid`. See
leanprover-community#743.
@chabulhwi chabulhwi force-pushed the String.splitOn_of_valid_v3 branch 2 times, most recently from 7e1376d to 42d0f82 Compare October 14, 2024 10:11
chabulhwi and others added 3 commits October 15, 2024 12:34
I need these lemmas to prove `String.splitOn_of_valid`.
* `List.splitOnceP` returns `(l₁, l₂)` for the first split `l = l₁ ++
  l₂` such that `P l₂` returns true.
* `List.splitOnList` splits a list at every occurrence of a separator
  list. The separators are not in the result.
* `List.splitOnListAux` is an auxiliary definition for proving
  `String.splitOnAux_of_valid`.

Co-authored-by: Mario Carneiro <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Add `String.splitOnAux_of_valid` and `String.splitOn_of_valid`.
chabulhwi added a commit to chabulhwi/batteries that referenced this pull request Oct 15, 2024
These are 'leftover' lemmas I created while trying to prove
`String.splitOn_of_valid`. See
leanprover-community#743.
chabulhwi added a commit to chabulhwi/batteries that referenced this pull request Oct 16, 2024
These are 'leftover' lemmas I created while trying to prove
`String.splitOn_of_valid`. See
leanprover-community#743.
chabulhwi added a commit to chabulhwi/batteries that referenced this pull request Oct 16, 2024
These are 'leftover' lemmas I created while trying to prove
`String.splitOn_of_valid`. See
leanprover-community#743.
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review This PR is ready for review; the author thinks it is ready to be merged. depends on another PR This is stacked on top of another Batteries PR. merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants