Seven trees in one
Mark Hopkins
@antiselfdual
Commonwealth Bank
LambdaJam 2015
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Unlabelled binary trees
data Tree = Leaf | Node Tree Tree
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Unlabelled binary trees
data Tree = Leaf | Node Tree Tree
T = 1 + T2
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T = 1 + T2
Suspend disbelief, and solve for T.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T = 1 + T2
Suspend disbelief, and solve for T.
T2
− T + 1 = 0
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T = 1 + T2
Suspend disbelief, and solve for T.
T2
− T + 1 = 0
T =
−b ±
√
b2 − 4ac
2a
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T = 1 + T2
Suspend disbelief, and solve for T.
T2
− T + 1 = 0
T =
−b ±
√
b2 − 4ac
2a
= 1
2 ±
√
3
2 i
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T = 1 + T2
Suspend disbelief, and solve for T.
T2
− T + 1 = 0
T =
−b ±
√
b2 − 4ac
2a
= 1
2 ±
√
3
2 i
= e±πi/3
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Re
Im
1
−1
i
−i
T
−T
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
So T6 = 1.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
So T6 = 1. No, obviously wrong.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
So T6 = 1. No, obviously wrong.
What about
T7
= T?
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
So T6 = 1. No, obviously wrong.
What about
T7
= T?
Not obviously wrong. . .
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
So T6 = 1. No, obviously wrong.
What about
T7
= T?
Not obviously wrong. . .
⇒ true!
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Theorem
There exists an O(1) bijective function from T to T7.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Theorem
There exists an O(1) bijective function from T to T7.
i.e.
we can pattern match on any 7-tuple of trees and put them
together into one tree.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Theorem
There exists an O(1) bijective function from T to T7.
i.e.
we can pattern match on any 7-tuple of trees and put them
together into one tree.
we can decompose any tree into the same seven trees it came
from.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Theorem
There exists an O(1) bijective function from T to T7.
i.e.
we can pattern match on any 7-tuple of trees and put them
together into one tree.
we can decompose any tree into the same seven trees it came
from.
Actually holds for any k = 1 mod 6.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Theorem
There exists an O(1) bijective function from T to T7.
i.e.
we can pattern match on any 7-tuple of trees and put them
together into one tree.
we can decompose any tree into the same seven trees it came
from.
Actually holds for any k = 1 mod 6.
Not true for other values.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T2
→ T
f :: (Tree , Tree) → Tree
t t1 t2 = Node t1 t2
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T2
→ T
f :: (Tree , Tree) → Tree
t t1 t2 = Node t1 t2
Not surjective, since we can never reach Leaf.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T → T2
f :: Tree → (Tree , Tree)
f t = Node t Leaf
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T → T2
f :: Tree → (Tree , Tree)
f t = Node t Leaf
Not surjective either.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T2
→ T, but cleverer
f :: (Tree , Tree) → Tree
f (t1, t2) = go (Node t1 t2)
where
go t = if leftOnly t then left t else t
leftOnly t = t == Leaf
|| right t == Leaf && leftOnly (left t)
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T2
→ T, but cleverer
f :: (Tree , Tree) → Tree
f (t1, t2) = go (Node t1 t2)
where
go t = if leftOnly t then left t else t
leftOnly t = t == Leaf
|| right t == Leaf && leftOnly (left t)
Bijective!
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
T2
→ T, but cleverer
f :: (Tree , Tree) → Tree
f (t1, t2) = go (Node t1 t2)
where
go t = if leftOnly t then left t else t
leftOnly t = t == Leaf
|| right t == Leaf && leftOnly (left t)
Bijective! but not O(1).
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
A solution
f :: T → (T, T, T, T, T, T, T)
f L = (L,L,L,L,L,L,L)
f (N t1 L) = (t1,N L L,L,L,L,L,L)
f (N t1 (N t2 L)) = (N t1 t2,L,L,L,L,L,L)
f (N t1 (N t2 (N t3 L))) = (t1,N (N t2 t3) L,L,L,L,L,L)
f (N t1 (N t2 (N t3 (N t4 L)))) = (t1,N t2 (N t3 t4),L,L,L,L,L)
f (N t1 (N t2 (N t3 (N t4 (N L L))))) = (t1,t2,N t3 t4,L,L,L,L)
f (N t1 (N t2 (N t3 (N t4 (N (N t5 L) L))))) = (t1,t2,t3,N t4 t5,L,L,L)
f (N t1 (N t2 (N t3 (N t4 (N (N t5 (N t6 L)) L))))) = (t1,t2,t3,t4,N t5 t6,L,L)
f (N t1 (N t2 (N t3 (N t4 (N (N t5 (N t6 (N t7 t8))) L))))) = (t1,t2,t3,t4,t5,t6,N t7 t8)
f (N t1 (N t2 (N t3 (N t4 (N t5 (N t6 t7 )))))) = (t1,t2,t3,t4,t5,N t6 t7,L)
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Where did this come from
T = 1 + T2
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Where did this come from
T = 1 + T2
Tk
= Tk−1
+ Tk+1
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Penny game
T0 T1 T2 T3 T4 T5 T6 T7 T8
start with a penny in position 1.
aim is to move it to position 7 by splitting and combining
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Why did this work?
If we have a type isomorphism T ∼= p(T) then
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Why did this work?
If we have a type isomorphism T ∼= p(T) then
q1(T) ∼= q2(T) as types
⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x)
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Why did this work?
If we have a type isomorphism T ∼= p(T) then
q1(T) ∼= q2(T) as types
⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x)
⇒ q1(x) ∼= q2(x) in the ring Z[x]/(p(x) = x)
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Why did this work?
If we have a type isomorphism T ∼= p(T) then
q1(T) ∼= q2(T) as types
⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x)
⇒ q1(x) ∼= q2(x) in the ring Z[x]/(p(x) = x)
⇒ q1(z) ∼= q2(z) for all z ∈ C such that p(z) = z.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Why did this work?
If we have a type isomorphism T ∼= p(T) then
q1(T) ∼= q2(T) as types
⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x)
⇒ q1(x) ∼= q2(x) in the ring Z[x]/(p(x) = x)
⇒ q1(z) ∼= q2(z) for all z ∈ C such that p(z) = z.
And, under some conditions, the reverse implications hold.
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Summary
Simple arithmetic helps us find non-obvious type isomorphisms
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Extensions
Are there extensions to datatypes of decorated trees?
(multivariate polynomials)
What applications are there?
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Extensions
Are there extensions to datatypes of decorated trees?
(multivariate polynomials)
What applications are there?
important when writing a compiler to know when two types
are isomomorphic
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Extensions
Are there extensions to datatypes of decorated trees?
(multivariate polynomials)
What applications are there?
important when writing a compiler to know when two types
are isomomorphic
It could interesting to split up a tree-shaped stream into seven
parts
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Rich theory behind isomorphisms of polynomial types
brings together a number of fields
distributive categories
theory of rigs (semirings)
combinatorial species
type theory
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Further reading
Seven Trees in one, Andreas Blass, Journal of Pure and
Applied Algebra
On the generic solution to P(X) = X in distributive
categories, Robbie Gates
Objects of Categories as Complex Numbers, Marcelo Fiore and
Tom Leinster
An Objective Representation of the Gaussian Integers, Marcelo
Fiore and Tom Leinster
http://rfcwalters.blogspot.com.au/2010/06/robbie-gates-on-
seven-trees-in-one.html
http://blog.sigfpe.com/2007/09/arboreal-isomorphisms-from-
nuclear.html
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Challenge
Consider this datatype (Motzkin trees):
data Tree = Zero | One Tree | Two Tree Tree
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Challenge
Consider this datatype (Motzkin trees):
data Tree = Zero | One Tree | Two Tree Tree
T = 1 + T + T2
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Challenge
Consider this datatype (Motzkin trees):
data Tree = Zero | One Tree | Two Tree Tree
T = 1 + T + T2
Show that T5 ∼= T
by a nonsense argument using complex numbers
by composing bijections (the penny game)
implement the function and its inverse in a language of your
choice
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
Photo credits
The Druid’s Grove, Norbury Park: Ancient Yew Trees by
Thomas Allom 1804-1872
http://www.victorianweb.org/art/illustration/allom/1.html
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
End
Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one

More Related Content

PDF
Trees (slides)
PPT
Discrete Math Lecture 01: Propositional Logic
PPTX
Discrete Mathematics - Propositional Logic
PPT
Red Black Trees
PDF
Discrete-Chapter 10 Trees
PPT
Mathematical Logic Part 2
PPTX
Logic
 
PPTX
Bba i-bm-u-1.2 set theory -
Trees (slides)
Discrete Math Lecture 01: Propositional Logic
Discrete Mathematics - Propositional Logic
Red Black Trees
Discrete-Chapter 10 Trees
Mathematical Logic Part 2
Logic
 
Bba i-bm-u-1.2 set theory -

What's hot (15)

PDF
Group Theory
PDF
MarkDrachMeinelThesisFinal
PPTX
Set theory
PPTX
Set theory-complete-1211828121770367-8
PDF
Discrete Structures lecture 2
PDF
Discrete Structures. Lecture 1
PPTX
Discrete Mathematics Tree
PPT
Discreet_Set Theory
PDF
BCA_Semester-I_Mathematics-I_Set theory and function
PDF
PPTX
Set Theory Presentation
PDF
Class XI CH 1 (sets)
PDF
CBSE Class X - Mathematics Set Theory Topic
PDF
A STUDY ON L-FUZZY NORMAL SUBl -GROUP
PDF
Unit I discrete mathematics lecture notes
Group Theory
MarkDrachMeinelThesisFinal
Set theory
Set theory-complete-1211828121770367-8
Discrete Structures lecture 2
Discrete Structures. Lecture 1
Discrete Mathematics Tree
Discreet_Set Theory
BCA_Semester-I_Mathematics-I_Set theory and function
Set Theory Presentation
Class XI CH 1 (sets)
CBSE Class X - Mathematics Set Theory Topic
A STUDY ON L-FUZZY NORMAL SUBl -GROUP
Unit I discrete mathematics lecture notes
Ad

Viewers also liked (20)

PPTX
Pokemon go の技術的注目点
PDF
はじめようlocalization
PPTX
Shake up the Culture with Automation!
PDF
Final san diego venture group keynote 2016
PPTX
Tsushima2015 talk event - ロボット・情報技術は生活の役に立つのか?? ~科学・技術を探求することの意味~
PPTX
Power bi for office365 技術ひろばnet
PDF
EL MEDIO AMBIENTE
PPTX
A Powerful Partnership: GIS and Sampling
ODP
Tic ii idea_de_negocio_abi
PPT
Calzado "Solsol"
PDF
Terapeutica tb
PPTX
gestion de la carga de trabajo de la evaluación continua para el profesor
ODP
Idea de negocio empresarial
PDF
Nº 33 año 2008, gaceta municipal extraordinaria (ordenanzas contraloría socia...
PPTX
Proyecto de historia clínica electrónica en cundinamarca
PPTX
Digital II Final Project
PDF
Engaging staff in Health and Safety, do rules work? - Golden rules thoughts 2...
ODP
Idea de negocio querubin sac
PDF
乱択データ構造の最新事情 -MinHash と HyperLogLog の最近の進歩-
PDF
Conquer CI Server! - Re-establishment of Order and Nurture of the Solid Organ...
Pokemon go の技術的注目点
はじめようlocalization
Shake up the Culture with Automation!
Final san diego venture group keynote 2016
Tsushima2015 talk event - ロボット・情報技術は生活の役に立つのか?? ~科学・技術を探求することの意味~
Power bi for office365 技術ひろばnet
EL MEDIO AMBIENTE
A Powerful Partnership: GIS and Sampling
Tic ii idea_de_negocio_abi
Calzado "Solsol"
Terapeutica tb
gestion de la carga de trabajo de la evaluación continua para el profesor
Idea de negocio empresarial
Nº 33 año 2008, gaceta municipal extraordinaria (ordenanzas contraloría socia...
Proyecto de historia clínica electrónica en cundinamarca
Digital II Final Project
Engaging staff in Health and Safety, do rules work? - Golden rules thoughts 2...
Idea de negocio querubin sac
乱択データ構造の最新事情 -MinHash と HyperLogLog の最近の進歩-
Conquer CI Server! - Re-establishment of Order and Nurture of the Solid Organ...
Ad

Similar to Seven trees in one (20)

PPT
Natural Trees for the future oil part 3.ppt
PDF
CDT & Trees
PDF
PDF
Robustness of supertree methods for reconciling dense incompatible data. SJ. ...
PDF
Pattern_avoidance_in_ternary_trees
PDF
1. Briefly state the Master Theorem.What type of problem is it usefu.pdf
PPT
Red black 1
DOCX
Read Section 11.4, pages 540 ( 547. Type in the answers below .docx
PDF
Skiena algorithm 2007 lecture13 minimum spanning trees
PDF
trees-and-forest.pdf
PPT
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
PPTX
Advanced data structure
PDF
Red Black Trees
PPTX
B.TECH Math project
PDF
Red black trees
PPSX
Trees
PDF
Dynamic Programming Over Graphs of Bounded Treewidth
PDF
Bt0080 fundamentals of algorithms2
PPT
lecture 14
Natural Trees for the future oil part 3.ppt
CDT & Trees
Robustness of supertree methods for reconciling dense incompatible data. SJ. ...
Pattern_avoidance_in_ternary_trees
1. Briefly state the Master Theorem.What type of problem is it usefu.pdf
Red black 1
Read Section 11.4, pages 540 ( 547. Type in the answers below .docx
Skiena algorithm 2007 lecture13 minimum spanning trees
trees-and-forest.pdf
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Advanced data structure
Red Black Trees
B.TECH Math project
Red black trees
Trees
Dynamic Programming Over Graphs of Bounded Treewidth
Bt0080 fundamentals of algorithms2
lecture 14

Recently uploaded (20)

PPT
Presentation of a Romanian Institutee 2.
PPTX
ap-psych-ch-1-introduction-to-psychology-presentation.pptx
PPT
Animal tissues, epithelial, muscle, connective, nervous tissue
PPTX
TORCH INFECTIONS in pregnancy with toxoplasma
PPTX
INTRODUCTION TO PAEDIATRICS AND PAEDIATRIC HISTORY TAKING-1.pptx
PPT
Heredity-grade-9 Heredity-grade-9. Heredity-grade-9.
PDF
Worlds Next Door: A Candidate Giant Planet Imaged in the Habitable Zone of ↵ ...
PPTX
POULTRY PRODUCTION AND MANAGEMENTNNN.pptx
PDF
Science Form five needed shit SCIENEce so
PPT
Enhancing Laboratory Quality Through ISO 15189 Compliance
PPTX
Microbes in human welfare class 12 .pptx
PDF
Warm, water-depleted rocky exoplanets with surfaceionic liquids: A proposed c...
PPT
Biochemestry- PPT ON Protein,Nitrogenous constituents of Urine, Blood, their ...
PDF
Communicating Health Policies to Diverse Populations (www.kiu.ac.ug)
PPTX
GREEN FIELDS SCHOOL PPT ON HOLIDAY HOMEWORK
PDF
Looking into the jet cone of the neutrino-associated very high-energy blazar ...
PPTX
Presentation1 INTRODUCTION TO ENZYMES.pptx
PPTX
gene cloning powerpoint for general biology 2
PPTX
Understanding the Circulatory System……..
PDF
S2 SOIL BY TR. OKION.pdf based on the new lower secondary curriculum
Presentation of a Romanian Institutee 2.
ap-psych-ch-1-introduction-to-psychology-presentation.pptx
Animal tissues, epithelial, muscle, connective, nervous tissue
TORCH INFECTIONS in pregnancy with toxoplasma
INTRODUCTION TO PAEDIATRICS AND PAEDIATRIC HISTORY TAKING-1.pptx
Heredity-grade-9 Heredity-grade-9. Heredity-grade-9.
Worlds Next Door: A Candidate Giant Planet Imaged in the Habitable Zone of ↵ ...
POULTRY PRODUCTION AND MANAGEMENTNNN.pptx
Science Form five needed shit SCIENEce so
Enhancing Laboratory Quality Through ISO 15189 Compliance
Microbes in human welfare class 12 .pptx
Warm, water-depleted rocky exoplanets with surfaceionic liquids: A proposed c...
Biochemestry- PPT ON Protein,Nitrogenous constituents of Urine, Blood, their ...
Communicating Health Policies to Diverse Populations (www.kiu.ac.ug)
GREEN FIELDS SCHOOL PPT ON HOLIDAY HOMEWORK
Looking into the jet cone of the neutrino-associated very high-energy blazar ...
Presentation1 INTRODUCTION TO ENZYMES.pptx
gene cloning powerpoint for general biology 2
Understanding the Circulatory System……..
S2 SOIL BY TR. OKION.pdf based on the new lower secondary curriculum

Seven trees in one

  • 1. Seven trees in one Mark Hopkins @antiselfdual Commonwealth Bank LambdaJam 2015 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 2. Unlabelled binary trees data Tree = Leaf | Node Tree Tree Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 3. Unlabelled binary trees data Tree = Leaf | Node Tree Tree T = 1 + T2 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 4. T = 1 + T2 Suspend disbelief, and solve for T. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 5. T = 1 + T2 Suspend disbelief, and solve for T. T2 − T + 1 = 0 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 6. T = 1 + T2 Suspend disbelief, and solve for T. T2 − T + 1 = 0 T = −b ± √ b2 − 4ac 2a Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 7. T = 1 + T2 Suspend disbelief, and solve for T. T2 − T + 1 = 0 T = −b ± √ b2 − 4ac 2a = 1 2 ± √ 3 2 i Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 8. T = 1 + T2 Suspend disbelief, and solve for T. T2 − T + 1 = 0 T = −b ± √ b2 − 4ac 2a = 1 2 ± √ 3 2 i = e±πi/3 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 9. Re Im 1 −1 i −i T −T Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 10. So T6 = 1. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 11. So T6 = 1. No, obviously wrong. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 12. So T6 = 1. No, obviously wrong. What about T7 = T? Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 13. So T6 = 1. No, obviously wrong. What about T7 = T? Not obviously wrong. . . Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 14. So T6 = 1. No, obviously wrong. What about T7 = T? Not obviously wrong. . . ⇒ true! Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 15. Theorem There exists an O(1) bijective function from T to T7. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 16. Theorem There exists an O(1) bijective function from T to T7. i.e. we can pattern match on any 7-tuple of trees and put them together into one tree. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 17. Theorem There exists an O(1) bijective function from T to T7. i.e. we can pattern match on any 7-tuple of trees and put them together into one tree. we can decompose any tree into the same seven trees it came from. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 18. Theorem There exists an O(1) bijective function from T to T7. i.e. we can pattern match on any 7-tuple of trees and put them together into one tree. we can decompose any tree into the same seven trees it came from. Actually holds for any k = 1 mod 6. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 19. Theorem There exists an O(1) bijective function from T to T7. i.e. we can pattern match on any 7-tuple of trees and put them together into one tree. we can decompose any tree into the same seven trees it came from. Actually holds for any k = 1 mod 6. Not true for other values. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 20. T2 → T f :: (Tree , Tree) → Tree t t1 t2 = Node t1 t2 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 21. T2 → T f :: (Tree , Tree) → Tree t t1 t2 = Node t1 t2 Not surjective, since we can never reach Leaf. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 22. T → T2 f :: Tree → (Tree , Tree) f t = Node t Leaf Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 23. T → T2 f :: Tree → (Tree , Tree) f t = Node t Leaf Not surjective either. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 24. T2 → T, but cleverer f :: (Tree , Tree) → Tree f (t1, t2) = go (Node t1 t2) where go t = if leftOnly t then left t else t leftOnly t = t == Leaf || right t == Leaf && leftOnly (left t) Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 25. T2 → T, but cleverer f :: (Tree , Tree) → Tree f (t1, t2) = go (Node t1 t2) where go t = if leftOnly t then left t else t leftOnly t = t == Leaf || right t == Leaf && leftOnly (left t) Bijective! Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 26. T2 → T, but cleverer f :: (Tree , Tree) → Tree f (t1, t2) = go (Node t1 t2) where go t = if leftOnly t then left t else t leftOnly t = t == Leaf || right t == Leaf && leftOnly (left t) Bijective! but not O(1). Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 27. A solution f :: T → (T, T, T, T, T, T, T) f L = (L,L,L,L,L,L,L) f (N t1 L) = (t1,N L L,L,L,L,L,L) f (N t1 (N t2 L)) = (N t1 t2,L,L,L,L,L,L) f (N t1 (N t2 (N t3 L))) = (t1,N (N t2 t3) L,L,L,L,L,L) f (N t1 (N t2 (N t3 (N t4 L)))) = (t1,N t2 (N t3 t4),L,L,L,L,L) f (N t1 (N t2 (N t3 (N t4 (N L L))))) = (t1,t2,N t3 t4,L,L,L,L) f (N t1 (N t2 (N t3 (N t4 (N (N t5 L) L))))) = (t1,t2,t3,N t4 t5,L,L,L) f (N t1 (N t2 (N t3 (N t4 (N (N t5 (N t6 L)) L))))) = (t1,t2,t3,t4,N t5 t6,L,L) f (N t1 (N t2 (N t3 (N t4 (N (N t5 (N t6 (N t7 t8))) L))))) = (t1,t2,t3,t4,t5,t6,N t7 t8) f (N t1 (N t2 (N t3 (N t4 (N t5 (N t6 t7 )))))) = (t1,t2,t3,t4,t5,N t6 t7,L) Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 28. Where did this come from T = 1 + T2 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 29. Where did this come from T = 1 + T2 Tk = Tk−1 + Tk+1 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 30. Penny game T0 T1 T2 T3 T4 T5 T6 T7 T8 start with a penny in position 1. aim is to move it to position 7 by splitting and combining Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 31. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 32. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 33. Why did this work? If we have a type isomorphism T ∼= p(T) then Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 34. Why did this work? If we have a type isomorphism T ∼= p(T) then q1(T) ∼= q2(T) as types ⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x) Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 35. Why did this work? If we have a type isomorphism T ∼= p(T) then q1(T) ∼= q2(T) as types ⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x) ⇒ q1(x) ∼= q2(x) in the ring Z[x]/(p(x) = x) Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 36. Why did this work? If we have a type isomorphism T ∼= p(T) then q1(T) ∼= q2(T) as types ⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x) ⇒ q1(x) ∼= q2(x) in the ring Z[x]/(p(x) = x) ⇒ q1(z) ∼= q2(z) for all z ∈ C such that p(z) = z. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 37. Why did this work? If we have a type isomorphism T ∼= p(T) then q1(T) ∼= q2(T) as types ⇐⇒ q1(x) ∼= q2(x) in the rig N[x]/(p(x) = x) ⇒ q1(x) ∼= q2(x) in the ring Z[x]/(p(x) = x) ⇒ q1(z) ∼= q2(z) for all z ∈ C such that p(z) = z. And, under some conditions, the reverse implications hold. Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 38. Summary Simple arithmetic helps us find non-obvious type isomorphisms Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 39. Extensions Are there extensions to datatypes of decorated trees? (multivariate polynomials) What applications are there? Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 40. Extensions Are there extensions to datatypes of decorated trees? (multivariate polynomials) What applications are there? important when writing a compiler to know when two types are isomomorphic Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 41. Extensions Are there extensions to datatypes of decorated trees? (multivariate polynomials) What applications are there? important when writing a compiler to know when two types are isomomorphic It could interesting to split up a tree-shaped stream into seven parts Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 42. Rich theory behind isomorphisms of polynomial types brings together a number of fields distributive categories theory of rigs (semirings) combinatorial species type theory Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 43. Further reading Seven Trees in one, Andreas Blass, Journal of Pure and Applied Algebra On the generic solution to P(X) = X in distributive categories, Robbie Gates Objects of Categories as Complex Numbers, Marcelo Fiore and Tom Leinster An Objective Representation of the Gaussian Integers, Marcelo Fiore and Tom Leinster http://rfcwalters.blogspot.com.au/2010/06/robbie-gates-on- seven-trees-in-one.html http://blog.sigfpe.com/2007/09/arboreal-isomorphisms-from- nuclear.html Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 44. Challenge Consider this datatype (Motzkin trees): data Tree = Zero | One Tree | Two Tree Tree Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 45. Challenge Consider this datatype (Motzkin trees): data Tree = Zero | One Tree | Two Tree Tree T = 1 + T + T2 Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 46. Challenge Consider this datatype (Motzkin trees): data Tree = Zero | One Tree | Two Tree Tree T = 1 + T + T2 Show that T5 ∼= T by a nonsense argument using complex numbers by composing bijections (the penny game) implement the function and its inverse in a language of your choice Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 47. Photo credits The Druid’s Grove, Norbury Park: Ancient Yew Trees by Thomas Allom 1804-1872 http://www.victorianweb.org/art/illustration/allom/1.html Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one
  • 48. End Mark Hopkins @antiselfdual Commonwealth Bank Seven trees in one