Keynote, Lambdaconf 2017 - The Axes of Generalization

65
The Axes of Abstraction The Axes of Generalization "Give me six hours to generalize and I will spend the first four sharpening the axis." Paul Phillips Lambdaconf 2017 Boulder, CO

Transcript of Keynote, Lambdaconf 2017 - The Axes of Generalization

Page 1: Keynote, Lambdaconf 2017 - The Axes of Generalization

The Axes of AbstractionThe Axes of Generalization

"Give me six hours to generalize and I will spend the first four sharpening the axis."

Paul PhillipsLambdaconf 2017Boulder, CO

Page 2: Keynote, Lambdaconf 2017 - The Axes of Generalization

Situation

— Trend: axioms, logic, inference, laws— Math abstractions (e.g. monoids) succeeding— Domain abstractions remain mostly ad hoc— "More art than science"— That's a euphemism for "not science"

Page 3: Keynote, Lambdaconf 2017 - The Axes of Generalization

Thesis

There is science we can apply.

We can infer more.We can derive more.We can mine what is for what must be.We can resist adhocicity.

Page 4: Keynote, Lambdaconf 2017 - The Axes of Generalization

Axes

noun: axis, plural: axes

"an imaginary line that divides something into equal or roughly equal halves"

x^2 = -1? NOW what? -- Heron of Alexandria

Some imagination, Carl. -- Gauss's kindergarten teacher

Page 5: Keynote, Lambdaconf 2017 - The Axes of Generalization

Hold my beer.— W.R. Hamilton (paraphrased)

Page 6: Keynote, Lambdaconf 2017 - The Axes of Generalization

The axis of axis exoticity

I initially thought I'd talk about axes like:

- Parametricity # giver of free theorems

- Arity # size polymorphism

- Orderity # kind polymorphism

- Opacity # "boxity" says @xeno-by

- Inductivity # data vs. codata

Page 7: Keynote, Lambdaconf 2017 - The Axes of Generalization

Algebraic axes

Or algebraic properties:

- Associativity # category theory- Commutativity # CRDTs- Distributivity # belief propagation- Idempotency # lattices- Invertibility # isomorphisms- Selectivity # idempotent-er

Page 8: Keynote, Lambdaconf 2017 - The Axes of Generalization

Yet more exoticity

Other candidates:

- Longevity # Lifetimes- Evitability # evaluation strategy- Classity # "first class" is like "power"- Quotidity # macro depth polymorphism

Page 9: Keynote, Lambdaconf 2017 - The Axes of Generalization

Forget it!

Instead, I discovered something new (to me.)

I think it deserves a wider audience.

But first...

Page 10: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalizationby weakening

Page 11: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!

Page 12: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5

Page 13: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integer

Page 14: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbers

Page 15: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutative

Page 16: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identity

Page 17: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * exists

Page 18: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * existsdef f[A: Group](x: A): A = x + x // Don't assume + is commutative

Page 19: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * existsdef f[A: Group](x: A): A = x + x // Don't assume + is commutativedef f[A: Monoid](x: A): A = x + x // Don't assume + has an inverse

Page 20: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * existsdef f[A: Group](x: A): A = x + x // Don't assume + is commutativedef f[A: Monoid](x: A): A = x + x // Don't assume + has an inversedef f[A: Semigroup](x: A): A = x + x // Don't assume + has identity

Page 21: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * existsdef f[A: Group](x: A): A = x + x // Don't assume + is commutativedef f[A: Monoid](x: A): A = x + x // Don't assume + has an inversedef f[A: Semigroup](x: A): A = x + x // Don't assume + has identitydef f[A: Magma](x: A): A = x + x // Don't assume + is associative

Page 22: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * existsdef f[A: Group](x: A): A = x + x // Don't assume + is commutativedef f[A: Monoid](x: A): A = x + x // Don't assume + has an inversedef f[A: Semigroup](x: A): A = x + x // Don't assume + has identitydef f[A: Magma](x: A): A = x + x // Don't assume + is associativedef f[A](x: A): A = x // Assume nothing

Page 23: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * existsdef f[A: Group](x: A): A = x + x // Don't assume + is commutativedef f[A: Monoid](x: A): A = x + x // Don't assume + has an inversedef f[A: Semigroup](x: A): A = x + x // Don't assume + has identitydef f[A: Magma](x: A): A = x + x // Don't assume + is associativedef f[A](x: A): A = x // Assume nothing

Page 24: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

def f(x: 5): 10 = x + x // it's 10!def f(x: Int): Int = x + x // Don't assume 5def f[A <: Number](x: A): A = x + x // Don't assume integerdef f[A: CommutativeRing](x: A): A = x + x // Don't assume numbersdef f[A: Ring](x: A): A = x + x // Don't assume * is commutativedef f[A: Rng](x: A): A = x + x // Don't assume * has identitydef f[A: CommutativeGroup](x: A): A = x + x // Don't assume * existsdef f[A: Group](x: A): A = x + x // Don't assume + is commutativedef f[A: Monoid](x: A): A = x + x // Don't assume + has an inversedef f[A: Semigroup](x: A): A = x + x // Don't assume + has identitydef f[A: Magma](x: A): A = x + x // Don't assume + is associativedef f[A](x: A): A = x // Assume nothing

Page 25: Keynote, Lambdaconf 2017 - The Axes of Generalization

Abstractionv. Generalization

Page 26: Keynote, Lambdaconf 2017 - The Axes of Generalization

Abstraction

SAGREDO: This is a marvelous idea! It suggests that when we try to

understand nature, we should look at the phenomena as if they were

messages to be understood. Except that each message appears to be

random until we establish a code to read it. This code takes the form

of an abstraction, that is, we choose to ignore certain things as

irrelevant and we thus partially select the content of the message by

a free choice.

-- Gödel, Escher, Bach: an Eternal Golden Braid

Page 27: Keynote, Lambdaconf 2017 - The Axes of Generalization

Someone else's definitions, my emphasis:

Abstraction is an emphasis on the idea, qualities and properties rather than the particulars (a suppression of detail).

Generalization is a broadening of application to encompass a larger domain of objects of the same or different type.

Page 28: Keynote, Lambdaconf 2017 - The Axes of Generalization

Definition golf

Abstraction is ignoring differences

Generalization is expecting differences

Abstraction: Bats, whales, mice, humans... mammals!

Generalization: It lays EGGS? Hang on a second...

Page 29: Keynote, Lambdaconf 2017 - The Axes of Generalization

Abstraction

— Suppressing detail sounds like a quotient set— Partitioning elements into equivalence classes— all members in a class are "the same"— we position and dim the lights as we choose

Page 30: Keynote, Lambdaconf 2017 - The Axes of Generalization

Abstraction, concretely

— The set of natural numbers N— An equivalence relation P = "congruent modulo 1"— Equivalence classes: { 1, 3, ... }, { 2, 4, ... }

Page 31: Keynote, Lambdaconf 2017 - The Axes of Generalization

Abstraction

— I have objects B, C, and D— We notice B <: A, C <: A, D <: A— A abstracts B, C, and D

Page 32: Keynote, Lambdaconf 2017 - The Axes of Generalization

Generalization

— I have a property R: B => Bool— We notice property S: A => Bool can classify B, C, D— S generalizes R— Note contravariance!

Page 33: Keynote, Lambdaconf 2017 - The Axes of Generalization

Do these actually differ?

— The difference (in this conception) is the arrow— This duality pervades not only math but life itself— It is extension vs. intension

Page 34: Keynote, Lambdaconf 2017 - The Axes of Generalization

Extension <-> Intention

abstract generalize

unification anti-unification

data codata

being doing

Set[A] Indicator[A]

objects attributes

Page 35: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 36: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 37: Keynote, Lambdaconf 2017 - The Axes of Generalization

The Marriage ofExtent and Intent

Page 38: Keynote, Lambdaconf 2017 - The Axes of Generalization

What is this?

Page 39: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 40: Keynote, Lambdaconf 2017 - The Axes of Generalization

What am I describing?

- It has wings. "A dragonfly?" - It isn't an insect. "A bat?" - It lays eggs. "A pterosaur?" - It isn't a dinosaur. "A platypus in a bird costume?" - It flies. "...in a hot air balloon?" - It has feathers. "A realistic avian drone?"

Page 41: Keynote, Lambdaconf 2017 - The Axes of Generalization

Imperfection

— We usually work with "objects" already in mind— Naturally we will select properties they share— So the flaws tend to be in the "negative space"— How much "slack" is there in our abstraction?

Page 42: Keynote, Lambdaconf 2017 - The Axes of Generalization

Bagel abstraction

Page 43: Keynote, Lambdaconf 2017 - The Axes of Generalization

Mop abstraction

Page 44: Keynote, Lambdaconf 2017 - The Axes of Generalization

Muffin abstraction

Page 45: Keynote, Lambdaconf 2017 - The Axes of Generalization

Towel abstraction

Page 46: Keynote, Lambdaconf 2017 - The Axes of Generalization

Abstraction abstractly

— Ideally, extent and intent would converge— An object set induces a common attribute set— An attribute set induces a common object set— Where they correspond, we find stability— This is the idea behind formal concept analysis

Page 47: Keynote, Lambdaconf 2017 - The Axes of Generalization

Darwin's 'survival of the fittest' is really a special case of a moregeneral law of survival of the stable.

It may be a class of entities that come into existence at a sufficiently high rate to deserve a collective name.

-- R. Dawkins, "The Selfish Gene"

Page 48: Keynote, Lambdaconf 2017 - The Axes of Generalization

Formal Concept Analysis (FCA)

FCA finds practical application in fields including...

— data and text mining— machine learning— knowledge management— the semantic web— software development— chemistry & biology

Page 49: Keynote, Lambdaconf 2017 - The Axes of Generalization

FCA (cont)

— Imagine facts as a matrix of booleans— Each row is an object— Each column is an a!ribute— Each cell is true if object has attribute

Page 50: Keynote, Lambdaconf 2017 - The Axes of Generalization

This is an incidence matrix

Page 51: Keynote, Lambdaconf 2017 - The Axes of Generalization

This is its concept la!ice

Page 52: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 53: Keynote, Lambdaconf 2017 - The Axes of Generalization

Formal Concepts

— A formal context is K = (G, M, I) where— G, a set of objects (Gegenstand = object)— M, a set of attributes (Merkmal = characteristic)— I, a binary relation GxM (Inzidenzrelation = incidence)— From the formal context we derive the concept la!ice

Page 54: Keynote, Lambdaconf 2017 - The Axes of Generalization

Formal Concepts (cont)

— For any set A ⊆ G and any set B ⊆ M

— The attribute set common to objects in A is A'— The objects which have all attributes in B is B'— If A=B' and A'=B, then (A,B) is a formal concept.

Page 55: Keynote, Lambdaconf 2017 - The Axes of Generalization

Formal Concepts (cont)

— The concept lattice orders these formal concepts— The ordering is set inclusion— (A, B) is a subconcept of (A', B') if A ⊆ A' (and B' ⊆ B)

— Extent is covariant and intent is contravariant— A subconcept has fewer objects and more attributes

Page 56: Keynote, Lambdaconf 2017 - The Axes of Generalization

Formal Concepts (cont)

— I⇡ : P(G) => P(M) (attributes of all objects)

— I⇣ : P(M) => P(G) (objects with all attributes)— Compose both ways to create closure operators:

— I⇡⇣: P(G) => P(G) and I⇣⇡: P(M) => P(M)— Now for any set of objects A...

— (I⇡I⇣(A), I⇡(A)) is a formal concept— And vice versa.

Page 57: Keynote, Lambdaconf 2017 - The Axes of Generalization

Formal Concepts (cont)

— Given formal concept (A,B)— The objects in A are the concept's extent.— The attributes in B are the concept's intent.— An order isomorphism between subsets of G and M

Page 58: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 59: Keynote, Lambdaconf 2017 - The Axes of Generalization

BONUS: the EXTENDED ladderof functional programming

Page 60: Keynote, Lambdaconf 2017 - The Axes of Generalization

Profunctor intuition

Jean Bénabou, who invented the term and originally used profunctor, now prefers distributor, which is supposed to carry the intuition that a distributor generalizes a functor in a similar way to how a distribution generalizes a function.

-- n-lab ("wikipedia on brutal mode" - @griotspeak)

Page 61: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 62: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 63: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 64: Keynote, Lambdaconf 2017 - The Axes of Generalization
Page 65: Keynote, Lambdaconf 2017 - The Axes of Generalization

Welcome to the SECRET RUNG

"AXE-WIELDING FIRE MONSTER"

Profunctor Nuclei

NOTHING MORE TO LEARN