Associativity
Associativity is the property of a binary operation whereby regrouping its operands does not change the result.
Functional Programming in Scala, Second Edition
The algebraic law stating that regrouping repeated applications of a binary operation does not change the result.
- How it is used
- Supports monoids, folds, and parallel combination by making regrouped combines agree.
- How deep it goes
- Defines the law algebraically, tests it with generated triples, and applies it to folds, monads, and applicatives.
- Examples
- Uses strings, integers, Booleans, lists, generated law tests, function composition, and nested effect pairs.
- What you can do after
- Evaluate/understand whether regrouping preserves a computation and why associative operations enable reusable folds.
Read how Functional Programming in Scala, Second Edition explains associativity →
Clojure: The Essential Reference
Associativity is the property that the grouping of operands does not affect the result of repeatedly applying a binary operation.
- How it is used
- Guides decisions about whether reducers and transducers can safely support parallel folding.
- How deep it goes
- Explains semantic failures through chunked dropping and marks several reducers as non-foldable, without developing a general algebraic definition.
- Examples
- Uses sequential and parallel dropping examples whose sums differ across repeated executions.
- What you can do after
- Diagnose whether a stateful reducer preserves sequential semantics when executed through parallel folding.
Read how Clojure: The Essential Reference explains associativity →
100 Java Mistakes and How to Avoid Them
Associativity is the property that the grouping of operands does not change the result of an operation.
- How it is used
- Constrains accumulator functions supplied to Java Stream.reduce, especially when computation may be parallelized.
- How deep it goes
- Defines regrouping algebraically and demonstrates the failure through a hash-code reduction, stopping short of general algebraic treatment.
- Examples
- Uses List.hashCode, a multiplication-and-addition accumulator, and contrasting sequential and parallel computation orders.
- What you can do after
- Evaluate reduction accumulators against associativity and identity requirements before using them with streams.
Read how 100 Java Mistakes and How to Avoid Them explains associativity →
Learn Haskell by Example
An associative function is a binary operation whose grouping does not affect the result.
- How it is used
- Uses CSV appending to motivate regrouping operations and introduce the Semigroup abstraction.
- How deep it goes
- Defines the equality law, distinguishes grouping from operand order, and notes that the compiler does not verify it.
- Examples
- Uses CSV values, lists, and strings to demonstrate associative combination with <> and mconcat.
- What you can do after
- Build it from scratch by implementing an associative append operation and checking its Semigroup law.
Advanced Algorithms and Data Structures
An associative operation gives the same result regardless of how operands are parenthesized, so regrouping intermediate results does not change the outcome.
- How it is used
- Uses associativity to determine whether grouped intermediate results can be safely combined in parallel reducers.
- How deep it goes
- Defines the operational requirement for reducers but stops short of formal notation or proof.
- Examples
- Uses grouped coin lists, coin counting, and total-value aggregation as reduction examples.
- What you can do after
- Evaluate whether a grouped computation is suitable for parallel reduction.
Read how Advanced Algorithms and Data Structures explains associativity →
Grokking GPU Programming
Associativity is the property that regrouping operands does not change the result of an operation.
- How it is used
- Enables tree-shaped parallel reductions by allowing operands to be regrouped without changing the result.
- How deep it goes
- Defines regrouping, tests reduction operators, and notes floating-point limits without developing formal algebra.
- Examples
- Uses integer and floating-point sums, subtraction, max, min, products, logical operations, and string concatenation.
- What you can do after
- Apply it to decide whether an operation supports tree reduction and whether its operand order must be preserved.
GPU Programming with Triton
Associativity is the algebraic property that regrouping operands does not change an operation's result.
- How it is used
- Uses associativity to reason about reductions and explain why parallel reduction order can affect floating-point results.
- How deep it goes
- Defines associativity, works through a floating-point counterexample, and traces consequences for parallel reductions.
- Examples
- Compares two groupings of 0.1 and 1e20 that produce 0.0 and 0.1.
- What you can do after
- Evaluate why parallel reductions can yield numerically close but nonidentical results across configurations.
Read how GPU Programming with Triton explains associativity →
Also covered in
- Data-Oriented Programming in JavaIn early access (MEAP)
- Functional Programming in C#, Second Edition
What to know first
- data transformationA data transformation is an operation that maps input data or representations to output by changing their values, structure, or form.
- matrix-matrix multiplicationMatrix multiplication is an operation on compatible matrices in which each entry of the product is the dot product of a row of the first matrix and a column of the second.
- reduction operationA reduction operation combines multiple input values according to a rule to produce fewer results, often a single aggregate.
- sequenceA sequence is an ordered collection of elements whose positions determine the order in which they are arranged or traversed.
Related concepts
- monadused by · A monad is a programming abstraction that provides operations for sequencing computations while encapsulating and preserving their computational context.
- applicative functoruses · An applicative functor is a functor with operations for applying a function in a computational context to a value in that context and combining the computations.
- binary operationuses · A binary operation is a rule that combines exactly two operands from specified sets or types to produce a result in a specified set or type.
- floating-point arithmeticcontrasts with · Floating-point arithmetic is numerical computation using finite-precision representations of real numbers, which can introduce rounding and range errors.
- monad lawkind of · A monad law is an algebraic rule governing the return and bind operations to ensure computations can be composed consistently.
Questions about associativity
What is associativity?
Associativity is the property of a binary operation whereby regrouping its operands does not change the result.
Which Manning books explain associativity?
Functional Programming in Scala, Second Edition, Clojure: The Essential Reference, 100 Java Mistakes and How to Avoid Them, Learn Haskell by Example, Advanced Algorithms and Data Structures, Grokking GPU Programming and GPU Programming with Triton.
What should I know before learning associativity?
Manning books that teach associativity usually introduce data transformation, matrix-matrix multiplication, reduction operation and sequence first.
What is the difference between associativity and floating-point arithmetic?
Associativity is the property of a binary operation whereby regrouping its operands does not change the result. Floating-point arithmetic is numerical computation using finite-precision representations of real numbers, which can introduce rounding and range errors.
What is associativity a kind of?
Associativity is a kind of monad law. A monad law is an algebraic rule governing the return and bind operations to ensure computations can be composed consistently.
What is associativity part of?
Associativity is part of monoid law. A monoid law is one of the associativity and identity properties required of a monoid.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.






