LESSWRONG
LW

Logic & Mathematics World Modeling
Frontpage

6

Why associative operations?

by Sunny from QAD
16th Jul 2020
1 min read
7

6

This is a linkpost for http://questionsanddaylight.com/?p=88
Logic & Mathematics World Modeling
Frontpage

6

Why associative operations?
7Gurkenglas
5Pongo
3Gurkenglas
1Sunny from QAD
2aweinstock
2Pattern
1Sunny from QAD
New Comment
7 comments, sorted by
top scoring
Click to highlight new comments since: Today at 3:33 PM
[-]Gurkenglas5y70

In the same vein:

  • Commutativity is good in addition to associativity because then you can use Σ
  • Structure preservation in a morphism φ (aka φ(xy)=φ(x)φ(y)) is good because then if φ follows from the context, you can replace all of "φ(xyz)" and "φ(xy)φ(z)" and "φ(x)φ(yz)" with "xyz"
  • Bijectivity in a function f is good because then for any equation it is an equivalent transformation to apply f to both sides
  • Monotonicity in a function f is good because then you can apply it to both sides of an inequality
Reply
[-]Pongo5y50

Bijectivity in a function f is good because then for any equation it is an equivalent transformation to apply f to both sides

Don't you just need injectivity here?

Reply
[-]Gurkenglas5y30

Huh, you're right. That's too bad, "well-definedness & injectivity" doesn't flow so well, and I don't see what comparable property surjectivity is good for.

Reply
[-]Sunny from QAD5y10

Good stuff, thanks for your comment!

Reply
[-]aweinstock5y20

Another thing that you can do when folding associative operations over a sequence is re-parenthesize them in a way that makes them more efficient to compute.

For example, if A is a 1x1000 vector, B is a 1000x1000 square matrix, and C is a 1000x1 vector, (AB)(BC) takes less time and space to compute than A(BB)C since the intermediate 1000x1000 BB needs to be stored explicitly in the latter.

In the following python snippet, the computation of A(BB)C takes around 3/4ths of a second, while (AB)(BC) takes a handful of milliseconds.

from time import time
from numpy.random import random
A = random((1, 1000))
B = random((1000, 1000))
C = random((1000, 1))
a0 = time(); print(A.dot(B.dot(B)).dot(C)); a1 = time(); print(a1 - a0)
b0 = time(); print(A.dot(B).dot(B.dot(C))); b1 = time(); print(b1 - b0)

(Ironically, the values can be slightly different since floating point multiplication and addition aren't associative, unlike the corresponding operations over reals.)

Along the same lines, folds of associative operations over a sequence can be parallelized by parenthesizing the sequence as a balanced binary tree and evaluating the instances of the operation on separate nodes.

Reply
[-]Pattern5y20

The website has internal links prefixed with https but the site doesn't work with https.

Reply
[-]Sunny from QAD5y*10

It works, but it's self-certified, so your browser is probably blocking it. You can add an exception if you'd like, but I should have it fixed "soon" (3rd party certification can be gotten for free, I just need to get around to it).

Edit: I have done this now.

Reply
Moderation Log
More from Sunny from QAD
View more
Curated and popular this week
7Comments