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

JDK-8294539: Augment discussion of equivalence relations on floating-point values #10498

Closed
wants to merge 7 commits into from

Conversation

jddarcy
Copy link
Member

@jddarcy jddarcy commented Sep 29, 2022

While the floating-point == operation is not an equivalence relation, there are useful equivalence relations that can be defined over floating-point values. Text is added to java.lang.Double to discuss and name those relations.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8294539: Augment discussion of equivalence relations on floating-point values

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10498/head:pull/10498
$ git checkout pull/10498

Update a local copy of the PR:
$ git checkout pull/10498
$ git pull https://git.openjdk.org/jdk pull/10498/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10498

View PR using the GUI difftool:
$ git pr show -t 10498

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10498.diff

@jddarcy jddarcy marked this pull request as draft September 29, 2022 22:14
@bridgekeeper
Copy link

bridgekeeper bot commented Sep 29, 2022

👋 Welcome back darcy! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 29, 2022

@jddarcy The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 29, 2022
* <br>{@code Double.doubleToRawLongBits(a) == Double.doubleToRawLongBits(b)}<br>
* Under this relation, {@code +0.0} and {@code -0.0} are distinguished
* from each other and every bit pattern encoding a NaN is distinguished
* form other bit patterns encoding a NaN.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/form/from

* Note that representation equivalence is often an appropriate notion
* of equivalence to test the behavior of {@linkplain StrictMath math
* libraries}.
* </dd>
Copy link
Contributor

Choose a reason for hiding this comment

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

This list deserves to include the not-quite-equivalence relation ==. Suggest:

  • numerical equivalence
  • {@code +0.0} and {@code -0.0} are equivalent to each other.
  • infinite numbers of the same sign are equivalent to each other

The two floating point numbers represent the same mathematical finite value or signed infinity.

Expressions implementing this ER include x == y, x > y | x < y, etc.

Numerical equivalence does not apply to NaN, as NaN violates the reflexive property required of all equivalences, but on the domain of all non-NaNs, numerical equivalence is in fact an equivalence relation.

@jddarcy jddarcy marked this pull request as ready for review September 30, 2022 01:01
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 30, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 30, 2022

Webrevs

@jddarcy jddarcy changed the title JDK-8294539: Augment discussion of equivlance relations on floating-point values JDK-8294539: Augment discussion of equivalence relations on floating-point values Sep 30, 2022
* <dd>The bits of the two floating-point values are the same. This
* equivalence relation for {@code double} values {@code a} and {@code b} is
* implemented by the expression
* <br>{@code Double.doubleTo}<code><b>Raw</b></code>{@code LongBits(a) == Double.doubleTo}<code><b>Raw</b></code>{@code LongBits(b)}<br>
Copy link
Member

@PaulSandoz PaulSandoz Sep 30, 2022

Choose a reason for hiding this comment

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

Place in a code snippet since it's hard to read in source otherwise? Snippets allow for highlighting e.g.

/**
 * {@snippet :
 * Double.doubleToRawLongBits(a) == Double.doubleToRawLongBits(b) // @highlight substring="Raw"
 * }
 */

Copy link
Member Author

Choose a reason for hiding this comment

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

Before sending out the PR, I used a snippet, but it formatted the code using too much vertical space for the definition list. I didn't look to see if there was a "compact" styling option that could be used.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, i am not aware of a compact style.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed JDK-8294814

@openjdk
Copy link

openjdk bot commented Sep 30, 2022

@jddarcy This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8294539: Augment discussion of equivalence relations on floating-point values

Reviewed-by: psandoz, smarks

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 15 new commits pushed to the master branch:

  • b2e86a6: 8294255: Add link to DEFAULT_WAIT_TIME in javadoc for SunToolKit.realsSync
  • b22a38d: 8292309: Fix java/awt/PrintJob/ConstrainedPrintingTest/ConstrainedPrintingTest.java test
  • 121d4a5: 8293579: tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java fails on Japanese Windows platform
  • 1166a8a: 8292214: Memory leak in getAllConfigs of awt_GraphicsEnv.c:386
  • 3644e26: 8294673: JFR: Add SecurityProviderService#threshold to TestActiveSettingEvent.java
  • 085949a: 8294712: G1: Use index-base iteration for G1FlushHumongousCandidateRemSets
  • b850f05: 8294758: JFR: Docs build fails after changes to RecordedObject and Timespan
  • 2dbedf0: 8294406: Test runtime/handshake/HandshakeDirectTest.java failed: JVMTI_ERROR_WRONG_PHASE
  • 4d6668e: 8294242: JFR: jfr print doesn't handle infinite duration well
  • 5a9cd33: 8294509: The sign extension bug applies to 'public static int[] convertSeedBytesToInts(byte[] seed, int n, int z)' in RandomSupport
  • ... and 5 more: https://git.openjdk.org/jdk/compare/ae79af2ad67b51a7608f4c9060421dd175cabf3f...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 30, 2022
* <p>While {@code ==} is not an equivalence relation, several useful
* equivalence relations can be defined over floating-point
* values. Comparing numerical equality to various kinds of
* equivalence:
Copy link
Member

Choose a reason for hiding this comment

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

The overall discussion is good, and the inclusion of numerical equality is good, but now this introductory paragraph is invalid. It starts off:

While == is not an equivalence relation,

OK, this continues the discussion, picking up from the assertion several paragraphs above that == is not an equivalence relation. Then,

several useful equivalence relations can be defined over floating-point values. Comparing numerical equality to various kinds of equivalence:

It sounds like what follows will be a list of equivalence relations that will be contrasted with numerical equality, yet the very first example is numerical equality and is not an equivalence relation.

I think this just needs to be reworded to be more inclusive. Maybe something like, "the following is a comparison of various relations among floating-point values."

* <ul>
* <li> {@code +0.0} and {@code -0.0} are distinguished from each other.
* <li> every bit pattern encoding a NaN is considered equivalent to each other
* <li> an infinite value is equivalent to an infinite value of the same sign
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this line on infinities could be reworded. I wouldn't quibble over this except that I had to read it several times to figure out what it meant. The statement on NaN is universally quantified, whereas the statement on infinite values starts off sounding like an existential quantifier. Possibly: "all infinite values of the same sign are considered equivalent to each other."

Copy link
Member Author

Choose a reason for hiding this comment

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

Update as suggested and added some cross-links in from BigDecimal; thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

PS To further spell things out, I added an additional trailing paragraph:

"For two binary floating-point values a and b, if neither of a and b is zero or NaN, then the three relations numerical equality, bit-wise equivalence, and representation equivalence of a and b have the same true/false value. In other words, for binary floating-point values, the three relations only differ if at least one argument is zero or NaN."

Copy link
Member

Choose a reason for hiding this comment

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

The additional paragraph sounds fine.

@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 4, 2022
@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 4, 2022
@jddarcy
Copy link
Member Author

jddarcy commented Oct 5, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Oct 5, 2022

Going to push as commit 1dafbe3.
Since your change was applied there have been 15 commits pushed to the master branch:

  • b2e86a6: 8294255: Add link to DEFAULT_WAIT_TIME in javadoc for SunToolKit.realsSync
  • b22a38d: 8292309: Fix java/awt/PrintJob/ConstrainedPrintingTest/ConstrainedPrintingTest.java test
  • 121d4a5: 8293579: tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java fails on Japanese Windows platform
  • 1166a8a: 8292214: Memory leak in getAllConfigs of awt_GraphicsEnv.c:386
  • 3644e26: 8294673: JFR: Add SecurityProviderService#threshold to TestActiveSettingEvent.java
  • 085949a: 8294712: G1: Use index-base iteration for G1FlushHumongousCandidateRemSets
  • b850f05: 8294758: JFR: Docs build fails after changes to RecordedObject and Timespan
  • 2dbedf0: 8294406: Test runtime/handshake/HandshakeDirectTest.java failed: JVMTI_ERROR_WRONG_PHASE
  • 4d6668e: 8294242: JFR: jfr print doesn't handle infinite duration well
  • 5a9cd33: 8294509: The sign extension bug applies to 'public static int[] convertSeedBytesToInts(byte[] seed, int n, int z)' in RandomSupport
  • ... and 5 more: https://git.openjdk.org/jdk/compare/ae79af2ad67b51a7608f4c9060421dd175cabf3f...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 5, 2022
@openjdk openjdk bot closed this Oct 5, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 5, 2022
@openjdk
Copy link

openjdk bot commented Oct 5, 2022

@jddarcy Pushed as commit 1dafbe3.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jddarcy jddarcy deleted the JDK-8294539 branch June 10, 2023 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants