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

fixes #330 (floor and ceil subsumed by MathComp) #1244

Merged
merged 7 commits into from
Jul 16, 2024

Conversation

affeldt-aist
Copy link
Member

@affeldt-aist affeldt-aist commented Jun 17, 2024

Motivation for this change

fixes #330

Checklist
  • added corresponding entries in CHANGELOG_UNRELEASED.md
  • added corresponding documentation in the headers

Reference: How to document

Reminder to reviewers

@affeldt-aist affeldt-aist added this to the 1.3.0 milestone Jun 17, 2024
@affeldt-aist affeldt-aist marked this pull request as draft June 17, 2024 14:10
@affeldt-aist affeldt-aist added the renaming/refactoring 🔧 This is about a renaming or refactoring in the library label Jun 17, 2024
@affeldt-aist affeldt-aist changed the title fixes #330 fixes #330 (floor and ceil subsumed by MathComp) Jun 20, 2024
theories/reals.v Outdated Show resolved Hide resolved
@affeldt-aist
Copy link
Member Author

@proux01 could you take a quick look and potentially approved?
You'll notice that now reals.v is almost free of floor or ceil usage (except three deprecations).
What could be generalized to archimedean structures has been put into mathcomp_extra.v and
and this content is waiting for math-comp/math-comp#1235 to make its way into MathComp releases (so this'd rather be considered as a stage area).

After that it would remain to see if we still need the Rceil and Rfloor theories but that is maybe for a future PR.

@affeldt-aist
Copy link
Member Author

so this'd rather be considered as a stage area

for example, I'm keep ceil_ge has a lemma even though it is subsumed by Num.Theory.le_ceil
because le_ceil already existed with a different meaning and it now in deprecation phase

classical/mathcomp_extra.v Outdated Show resolved Hide resolved
theories/ereal.v Outdated Show resolved Hide resolved
@affeldt-aist affeldt-aist requested a review from proux01 July 9, 2024 09:04
@affeldt-aist
Copy link
Member Author

The CI errors look unrelated.

Lemma int1r {R : ringType} (i : int) : 1 + i%:~R = (1 + i)%:~R :> R.
Proof. by rewrite intrD. Qed.

From mathcomp Require Import archimedean.
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you import archimedean at the beginning of the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because only the next section needs it; if at some point this section moves to mathcomp I will not forget to erase even the Require Import.

Proof. by rewrite Num.Theory.ge_floor. Qed.

Lemma floor_ge0 x : (0 <= Num.floor x) = (0 <= x).
Proof. by rewrite -Num.Theory.floor_ge_int. Qed.
Copy link
Member

Choose a reason for hiding this comment

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

Importing Num.Theory after importing archimedean (equivalently, importing archimedean before importing Num.Theory) has the advantage that you can omit Num.Theory here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes of course. I'll do that asap if you want. (Note that I still need to double-check the naming before thinking of proposing to move the lemmas to MathComp proper, which might require us to wait a bit because of name clashes.)

@affeldt-aist
Copy link
Member Author

perfect

@affeldt-aist
Copy link
Member Author

perfect

do the names look ok to you? (that's one aspect of the review and you're in a good position to judge)

theories/altreals/realsum.v Outdated Show resolved Hide resolved
@pi8027 pi8027 force-pushed the fixes_330 branch 2 times, most recently from 50b5fd3 to b3c183c Compare July 11, 2024 15:56
classical/mathcomp_extra.v Outdated Show resolved Hide resolved
Comment on lines 402 to 403
Lemma floor_le0 x : x <= 0 -> Num.floor x <= 0.
Proof. by move/Num.Theory.floor_le; rewrite Num.Theory.floor0. Qed.
Copy link
Member

Choose a reason for hiding this comment

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

The condition x <= 0 here can be generalized to x < 1. Do you really need this lemma?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you really need this lemma?

At least it is used. Of course, you can inline the proof but I think that in practice it is good to have lemmas for constants for often show up like 0, even if they have short proofs; moreover they are easily named from the general case. I'll look a bit more in detail though.

classical/mathcomp_extra.v Outdated Show resolved Hide resolved
classical/mathcomp_extra.v Show resolved Hide resolved
classical/mathcomp_extra.v Show resolved Hide resolved
classical/mathcomp_extra.v Show resolved Hide resolved
classical/mathcomp_extra.v Outdated Show resolved Hide resolved
classical/mathcomp_extra.v Outdated Show resolved Hide resolved
rewrite mulr1 /j div1r -addn1 /= PoszD intrD mulr1z.
rewrite gez0_abs ?floor_ge0 ?invr_ge0 ?normr_ge0 //.
by rewrite -RfloorE; apply lt_succ_Rfloor.
pose j := `|Num.floor (`|f x|^-1)|%N; exists j; rewrite inE.
Copy link
Member

Choose a reason for hiding this comment

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

There are many occurrences of absz (Num.floor x). Did you check if Num.trunc can replace some of them or not? (That would be the case when x is positive and absz serves just as a type cast from int to nat.)

classical/mathcomp_extra.v Outdated Show resolved Hide resolved
@pi8027
Copy link
Member

pi8027 commented Jul 16, 2024

#1244 (comment)

I'd like to also flip equality lemmas such as ceil_ge0 to have the hand-side with the main identifier on the left.

I agree, but general versions of these lemmas, like floor_ge_int, are already in MathComp. We should discuss what we do in a MathComp dev meeting.

Copy link
Member

@pi8027 pi8027 left a comment

Choose a reason for hiding this comment

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

We should probably clean up the proofs further, but this PR is already mergeable IMO.

@pi8027
Copy link
Member

pi8027 commented Jul 16, 2024

@affeldt-aist Shall we merge? Or do you want me to wait?

@affeldt-aist affeldt-aist merged commit 319c75b into math-comp:master Jul 16, 2024
22 checks passed
@affeldt-aist
Copy link
Member Author

affeldt-aist commented Jul 16, 2024

@affeldt-aist Shall we merge? Or do you want me to wait?

Let's merge (it's pretty sure we'll come back to it because of the pending renamings and the cleanup of reals.v). Many thanks for all the input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
renaming/refactoring 🔧 This is about a renaming or refactoring in the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

floor and ceil to be subsumed by MathComp
3 participants