Skip to content

[Merged by Bors] - fix: correct String.instLinearOrderString#3339

Closed
chabulhwi wants to merge 3 commits intomasterfrom
fix_String.instLinearOrderString
Closed

[Merged by Bors] - fix: correct String.instLinearOrderString#3339
chabulhwi wants to merge 3 commits intomasterfrom
fix_String.instLinearOrderString

Conversation

@chabulhwi
Copy link
Copy Markdown
Collaborator

Use the optimized compare function and provide a manual compare_eq_compareOfLessAndEq field.


Open in Gitpod

Use the optimized `compare` function and provide a manual
`compare_eq_compareOfLessAndEq` field.
Use the tactic combinator `<;>` to golf the proof.
Comment on lines +231 to +243
theorem List.lt_iff_lex_char_lt (l l' : List Char) : List.lt l l' ↔ List.Lex Char.lt l l' := by
constructor <;>
intro h
· induction h with
| nil b bs => exact Lex.nil
| @head a as b bs hab => apply Lex.rel; assumption
| @tail a as b bs hab hba _ ih =>
have heq : a = b := _root_.le_antisymm (le_of_not_lt hba) (le_of_not_lt hab)
subst b; apply Lex.cons; assumption
· induction h with
| @nil a as => apply List.lt.nil
| @cons a as bs _ ih => apply List.lt.tail <;> simp [ih]
| @rel a as b bs h => apply List.lt.head; assumption
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there's nothing specific about Char in this proof; the following works:

theorem List.lt_eq_lt [LinearOrder α] (l₁ l₂ : List α) : List.lt l₁ l₂ ↔ l₁ < l₂ := by
  dsimp only [List.LT', List.lt]
  constructor
  · intro h
    induction h with
    | nil b bs => exact Lex.nil
    | @head a as b bs hab => apply Lex.rel; assumption
    | @tail a as b bs hab hba _ ih =>
      have heq : a = b := _root_.le_antisymm (le_of_not_lt hba) (le_of_not_lt hab)
      subst b; apply Lex.cons; assumption
  · intro h
    induction h with
    | @nil a as => apply List.lt.nil
    | @cons a as bs _ ih => apply List.lt.tail <;> simp [ih]
    | @rel a as b bs h => apply List.lt.head; assumption

theorem List.lt_iff_lex_char_lt (l l' : List Char) : List.lt l l' ↔ List.Lex Char.lt l l' :=
  List.lt_eq_lt l l'

(Why do we override the LT instance on List anyway?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of this might be a mess made by porting stuff that std4 already had a competing implementation of.

Copy link
Copy Markdown
Collaborator Author

@chabulhwi chabulhwi Apr 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there's nothing specific about Char in this proof;

I changed the theorem List.lt_iff_lex_char_lt to List.lt_iff_lex_lt.

* Change the theorem `List.lt_iff_lex_char_lt` to `List.lt_iff_lex_lt`.
* Lint code.
@kim-em
Copy link
Copy Markdown
Contributor

kim-em commented Apr 8, 2023

bors merge

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review labels Apr 8, 2023
bors bot pushed a commit that referenced this pull request Apr 8, 2023
Use the optimized `compare` function and provide a manual `compare_eq_compareOfLessAndEq` field.
@bors
Copy link
Copy Markdown

bors bot commented Apr 8, 2023

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title fix: correct String.instLinearOrderString [Merged by Bors] - fix: correct String.instLinearOrderString Apr 8, 2023
@bors bors bot closed this Apr 8, 2023
@bors bors bot deleted the fix_String.instLinearOrderString branch April 8, 2023 22:23
MonadMaverick pushed a commit that referenced this pull request Apr 9, 2023
Use the optimized `compare` function and provide a manual `compare_eq_compareOfLessAndEq` field.
MonadMaverick pushed a commit that referenced this pull request Apr 9, 2023
Use the optimized `compare` function and provide a manual `compare_eq_compareOfLessAndEq` field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants