[Merged by Bors] - fix: correct String.instLinearOrderString#3339
Closed
[Merged by Bors] - fix: correct String.instLinearOrderString#3339
String.instLinearOrderString#3339Conversation
Use the optimized `compare` function and provide a manual `compare_eq_compareOfLessAndEq` field.
Use the tactic combinator `<;>` to golf the proof.
Mathlib/Data/String/Basic.lean
Outdated
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 |
Contributor
There was a problem hiding this comment.
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?)
Member
There was a problem hiding this comment.
Some of this might be a mess made by porting stuff that std4 already had a competing implementation of.
Collaborator
Author
There was a problem hiding this comment.
Note that there's nothing specific about
Charin 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.
Contributor
|
bors merge |
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.
|
Pull request successfully merged into master. Build succeeded: |
String.instLinearOrderStringString.instLinearOrderString
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use the optimized
comparefunction and provide a manualcompare_eq_compareOfLessAndEqfield.