Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8183179

Clarify associativity/commutativity requirements of accumulator functions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • None
    • core-libs

      Stream classes such as DoubleStream as well as LongAccumulator and DoubleAccumulator generally require their functions to have "pretty good" associativity and commutativity for "pretty good" results. But word-smithing this is tricky. The problem is particularly noticeable for floating point operations, since often they are not strictly associative and equally often no one cares (e.g. "sum all the elements in the stream").

      In DoubleStream I see
      """The accumulator function must be an associative function."""
      ("must" is surely too strong... and not only for floating point)

      Can we expand the description of associativity here:
      https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/stream/package-summary.html#Associativity

      Another possibility is to abandon "predictable" and go for something more like
      """For best results, the accumulator function should be as associative and commutative as possible given the difficulties of floating point arithmetic."""

      Feel free to move to a better subcomponent.

            darcy Joe Darcy
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: