Skip to content

More Archimedean lemmas#1510

Draft
pi8027 wants to merge 2 commits into
masterfrom
archimedan-lemmas
Draft

More Archimedean lemmas#1510
pi8027 wants to merge 2 commits into
masterfrom
archimedan-lemmas

Conversation

@pi8027
Copy link
Copy Markdown
Member

@pi8027 pi8027 commented Dec 4, 2025

Motivation for this change

This PR adds some lemmas for archiNumDomainType and archiRealDomainType using to_real (also to_nneg) suggested by @CohenCyril (cf. #1377 (comment)).

Most of these lemmas for floor and ceil generalize existing lemmas requiring the Num.real condition on a variable. Since the names of these lemmas have the prefix real_, the names of their general versions replace it with to_real_ for the moment. Similarly, some of the new lemmas for truncn have the prefix to_nneg_. (We probably need to think a bit more about the naming convention here.)

In the end, I didn't find floorP, ceilP, and truncnP stated using spec datatypes very useful (cf. #1377 (comment)). I keep their statements as comments for the moment.

I suggest extensively testing the new lemmas in MCA before merging this PR.

(Eventually) Fix #1377

Dependencies
Minimal TODO list
  • added changelog entries with doc/changelog/make-entry.sh
  • added corresponding documentation in the headers
  • tried to abide by the contribution guide
  • this PR contains an optimum number of meaningful commits

See this Checklist for details.

Automatic note to reviewers

Read this Checklist.

Comment thread algebra/archimedean.v Outdated

Lemma floor_def x m : m%:~R <= x < (m + 1)%:~R -> floor x = m.
Lemma to_real_floor_idP x n :
reflect (floor x = n) (n%:~R <= to_real x < (n + 1)%:~R).
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@affeldt-aist @proux01 @hoheinzollern To answer your question (#1377 (comment)), floor_def and real_floor_itv are more or less the converses of each other. This lemma to_real_floor_idP (also real_floor_idP and floor_idP below) reformulates them using reflect.
However, real_floor_idP below does not nicely subsume floor_def, because the assumption x \is Num.real is deduced from n%:~R <= x in the proof of the latter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(Now I think floor_idP is not the right name... floor_itvP?)

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.

floor_itvP sounds good

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I renamed it to (to_real_)floor_itvP.

@pi8027
Copy link
Copy Markdown
Member Author

pi8027 commented Dec 4, 2025

MCA still uses Num.floor/Num.ceil/Num.truncn with Num.normr or absz in a few places. If Num.truncn does not subsume them, we should try to use Num.bound. It's defined in archimedean.v but currently lacks lemmas.

Definition bound (x : R) := (truncn `|x|).+1.

@pi8027 pi8027 requested a review from affeldt-aist January 2, 2026 15:14
@pi8027 pi8027 force-pushed the archimedan-lemmas branch from f0fac3a to 24c11d8 Compare January 26, 2026 17:41
@pi8027 pi8027 mentioned this pull request Jan 26, 2026
2 tasks
@pi8027 pi8027 force-pushed the archimedan-lemmas branch from 24c11d8 to 934a425 Compare January 27, 2026 13:53
@pi8027
Copy link
Copy Markdown
Member Author

pi8027 commented Feb 25, 2026

Rebased. I will take a fresh look at the PR and fix the naming issue this afternoon.

Comment thread algebra/archimedean.v Outdated
Comment on lines +431 to +438
(* TODO1: rename to real_eq_floor? *)
(* TODO2: add a general version using to_real, and derive (to_)real_floor_itvP from it *)
Lemma real_floor_eq x n : x \is real_num ->
(floor x == n) = (n%:~R <= x < (n + 1)%:~R).
Proof. by move=> ?; apply/eqP/real_floor_itvP. Qed.

(* TODO: rename? *)
Lemma floor_def x n : n%:~R <= x < (n + 1)%:~R -> floor x = n.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Any opinion on the renaming of these lemmas? I think real_floor_eq should be called something like real_eq_floor or real_eq_floor_itv, cf., meet_idPl and eq_meetl.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

IMO, floor_def is almost the definition of floor, but only for the case where x \is real_num.

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.

Maybe just floor_eq

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.

and floor_default: x \isn't real_num -> floor x = 0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@CohenCyril Am I right that your suggestion was to rename (real_)floor_eq to (real_)eq_floor and then rename floor_def to floor_eq? (We can do the latter renaming only after releasing MC 2.7.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

And I prefer to add floor_default in a subsequent PR.

Comment thread algebra/archimedean.v Outdated
@pi8027 pi8027 requested review from CohenCyril and proux01 February 25, 2026 22:25
@pi8027 pi8027 added this to the 2.7.0 milestone Feb 26, 2026
@pi8027 pi8027 mentioned this pull request Feb 26, 2026
1 task
@pi8027 pi8027 requested a review from hoheinzollern February 27, 2026 23:31
@pi8027
Copy link
Copy Markdown
Member Author

pi8027 commented Feb 27, 2026

@CohenCyril @affeldt-aist @proux01 @hoheinzollern While this PR is far from ready, I think I have done almost everything I can. Since this PR addresses the issue you reported (#1377) or implements the solution you proposed (#1377 (comment)), your input is necessary at this point.

@pi8027 pi8027 force-pushed the archimedan-lemmas branch from 16f0e30 to 8bc40dc Compare March 12, 2026 14:57
@pi8027 pi8027 force-pushed the archimedan-lemmas branch 2 times, most recently from 2401b4f to 5677272 Compare March 25, 2026 16:18
Comment thread algebra/archimedean.v Outdated
@CohenCyril CohenCyril self-requested a review April 1, 2026 11:46
@pi8027 pi8027 force-pushed the archimedan-lemmas branch from 5677272 to 56f1f2e Compare April 8, 2026 16:32
@pi8027 pi8027 changed the title More Archimedan lemmas More Archimedean lemmas Apr 9, 2026
@pi8027 pi8027 force-pushed the archimedan-lemmas branch from 56f1f2e to 35d1b4f Compare April 9, 2026 12:33
Copy link
Copy Markdown
Member Author

@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.

I made some progress. I isolated the renaming of existing lemmas into the first commit. We can consider merging it first.

Comment thread algebra/archimedean.v
Comment on lines +932 to +939
#[deprecated(since="mathcomp 2.7.0", use=real_floor_gez)]
Notation real_floor_ge_int := real_floor_gez (only parsing).
#[deprecated(since="mathcomp 2.7.0", use=real_floor_ltz)]
Notation real_floor_lt_int := real_floor_ltz (only parsing).
#[deprecated(since="mathcomp 2.7.0", use=real_ceil_lez)]
Notation real_ceil_le_int := real_ceil_lez (only parsing).
#[deprecated(since="mathcomp 2.7.0", use=real_ceil_gtz)]
Notation real_ceil_gt_int := real_ceil_gtz (only parsing).
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Following Cyril's suggestion during the meeting, I replaced _int with z in these names.

Comment thread algebra/archimedean.v Outdated
Comment on lines +945 to +951
Notation truncn_ge_nat := truncn_gen (only parsing).
#[deprecated(since="mathcomp 2.7.0", use=truncn_gtn)]
Notation truncn_gt_nat := truncn_gtn (only parsing).
#[deprecated(since="mathcomp 2.7.0", use=truncn_ltn)]
Notation truncn_lt_nat := truncn_ltn (only parsing).
#[deprecated(since="mathcomp 2.7.0", use=real_truncn_len)]
Notation real_truncn_le_nat := real_truncn_len (only parsing).
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Similarly, I replaced _nat with n here.

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.

Shouldn't the suffixes _gen and _len by _geq and _leq like in ssrnat.v?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was hesitating between the two. To be honest, I don't know. @CohenCyril

Copy link
Copy Markdown
Member Author

@pi8027 pi8027 Apr 9, 2026

Choose a reason for hiding this comment

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

For example, the way I would read truncn_len is: truncn x is less than or equal to n, for some x and natural number n. I'm unsure if we can read it in the same way if we replace n with q.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That being said, I think _gen and _len are confusing. What about _ge(q)_n and _le(q)_n?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After thinking about it twice, I decided to use _leq and _geq.

Comment thread algebra/archimedean.v

(* Factories *)

HB.factory Record NumDomain_hasFloorCeilTruncn R & Num.NumDomain R := {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was the mixin of the Archimedean structures before this PR, and this should be deprecated and eventually removed. What is the right suffix (like _truncn_abs_floor) for this one?

@pi8027 pi8027 force-pushed the archimedan-lemmas branch 2 times, most recently from 5c2589f to fc46e67 Compare April 13, 2026 15:08
@pi8027 pi8027 force-pushed the archimedan-lemmas branch from fc46e67 to b2f972b Compare April 15, 2026 14:49
Copy link
Copy Markdown
Member Author

@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.

I think this PR is ready for another round of review. Currently, the first commit does all the renamings of existing lemmas, and the second commit does the other changes. Perhaps the former part can be merged quickly. (If it is the case, I will split the PR.)

Comment thread algebra/archimedean.v
Comment on lines -631 to -632
Lemma truncnD :
{in nat_num & nneg_num, {morph truncn : x y / x + y >-> (x + y)%N}}.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I renamed this to truncnDnr to introduce truncnDrn. I'm unsure if they are the right name since this r has to be non-negative.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looking at CONTRIBUTING.md and num_theory/, the shorthand for nneg_num seems to be wp (weak positive ?). So they should probably be called truncnDn(_)wp and truncnDwp(_)n. Any opinion?

Copy link
Copy Markdown
Member Author

@pi8027 pi8027 Apr 16, 2026

Choose a reason for hiding this comment

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

Another option is to use D as an infix symbol like M in rMn: truncn_nDwp and truncn_wpDn. But, we need to rename similar lemmas for floor and ceil too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can also postpone introducing truncnDrn to address this naming issue later.

@pi8027 pi8027 force-pushed the archimedan-lemmas branch from b2f972b to 9195dc8 Compare April 17, 2026 11:49
@pi8027
Copy link
Copy Markdown
Member Author

pi8027 commented Apr 24, 2026

@CohenCyril @affeldt-aist @proux01 @hoheinzollern This PR is waiting for review.

@proux01
Copy link
Copy Markdown
Contributor

proux01 commented Apr 28, 2026

I'll do it but this may take me a bit of time to get to it.

@pi8027 pi8027 force-pushed the archimedan-lemmas branch from 9195dc8 to d105851 Compare May 6, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Naming in archimedean.v

4 participants