2022 James B. Wilson
Colorado State University
Problem: To a computer(...to you...), what is R4/Null1000103904−10?
Problem: To a computer(...to you...), what is Q[x]/(2+x3)?
(Under suitable conditions)
(x+3)2
x:=9
(x+3)2∣x:=9⊳(9+3)2
--- Borrow from context import K:Comm, I:Type from Gamma --- Make a new type data Vec K I where ...
Free Module : FORMATION
KI:TypeK:CommI:Set(Fvec)
// Borrow from context import K:Comm, I:Type from Gamma // Make a new type class Vec[K,I] { ... }
Procedural
Functional
KI
I
Γ⊢K,I
import K:Comm, I:Type from Gamma data Vec K I where Unit : {K:Comm} -> {I:Type} -> (i:I) -> (Unit K I) > Unit Float (Fin 3) 2 Unit 2 : Unit Float (Fin 3)
Free Module : INTRODUCTION
ei:KIi:I(Ie−vec)
import K:Comm, I:Type from Gamma class Vec[K,I] case class Unit[K,I](i:I) extends Vec[K,I] // e_2 in R^3 > e2 = new Unit[Float,range(3)](2)
Procedural
Functional
KI
I
e
Γ⊢K,I
import K:Comm, I:Type from Gamma data Vec K I where Unit : {K:Comm} -> {I:Type} -> (i:I) -> (Vec K I) Sum : (u:Vec K I) -> (v:Vec K I) -> (Vec K I) Scl : (a:K) -> (u:Vec K I) -> (Vec K I)
Free Module : IMPLICIT INTRODUCTIONS
a∗u:KIa:Ku:KI(I∗−vec)
import K:Comm, I:Type from Gamma class Vec[K,I] case class Unit[K,I](i:I) extends Vec[K,I] case class Sum[K,I](u:Vec[K,I],v:Vec[K,I]) extends Vec[K,I] case class Scl[K,I](a:K, u:Vec[K,I]) extends Vec[K,I]
Procedural
Functional
u+v:KIu,v:KI(I+−vec)
Multiple intros called "Inductive Type"
import K:Comm, I:Type from Gamma data Vec K I where Unit : (i:I) -> (Vec K I) Sum : (u:Vec K I) -> (v:Vec K I) -> (Vec K I) Scl : (a:K) -> (u:Vec K I) -> (Vec K I) --- The Universal Mapping Property umap:{U:Mod}->(Vec K I)->(f:I->U)->U
Free Module : ELIMINATION
import K:Comm, I:Type from Gamma class Vec[K,I] { // Universal Mapping Property abstract def umap[U<:Mod[K]](f:I->U):U } case class Unit(i:I) extends Vec[K,I] case class Sum(u:Vec[K,I],v:Vec[K,I]) extends Vec[K,I] case class Scl(a:K, u:Vec[K,I]) extends Vec[K,I]
Procedural
Functional
f^(v):Uv:KIU:KModf:I→U(Evec)
KI
I
e
U
∃!f^
f
Γ⊢K,I
import K:Comm, I:Type from Gamma data Vec K I where Unit : (i:I) -> (Vec K I) Sum : (u:Vec K I) -> (v:Vec K I) -> (Vec K I) Scl : (a:K) -> (u:Vec K I) -> (Vec K I) umap:(U:Mod)->(Vec K I)->(f:I->U)->U ---Implement the computation umap U (Unit i) f = f i
Free Module : COMPUTATION
import K:Comm, I:Type from Gamma class Vec[K,I] { abstract def umap[U<:Mod[K]](f:I->U):U } case class Unit(i:I) extends Vec[K,I] { // Implement the computation override def umap(f:I->U):U = f(i) } case class Sum(u:Vec[K,I],v:Vec[K,I]) extends Vec[K,I] case class Scl(a:K, u:Vec[K,I]) extends Vec[K,I]
Procedural
Functional
f^(ei)=f(i)i:IU:KModf:I→U(Ce−vec)
KI
I
e
U
∃!f^
f
Γ⊢K,I
import K:Comm, I:Type from Gamma data Vec K I where Unit : (i:I) -> (Vec K I) Sum : (u:Vec K I) -> (v:Vec K I) -> (Vec K I) Scl : (a:K) -> (u:Vec K I) -> (Vec K I) --- The Universal Mapping Property umap:(U:Mod)->(Vec K I)->(f:I->U)->U umap U (Unit i) f = f i umap U (Sum x y) f = (umap U x f)+(umap U y f) umap U (Scl a x) f = a*(umap U x f)
Free Module : IMPLICIT COMPUTATION
import K:Comm, I:Type from Gamma class Vec[K,I] { abstract def umap[U<:Mod[K]](f:I->U):U } case class Unit(i:I) extends Vec[K,I] { override def umap(f:I->U):U = f(i) } case class Sum(u:Vec[K,I],v:Vec[K,I]) extends Vec[K,I] { override def umap(f:I->U):U = u.umap(f)+v.umap(f) } case class Scl(a:K, u:Vec[K,I]) extends Vec[K,I]{ override def umap(f:I->U):U = a*u.umap(f) }
Procedural
Functional
f^(u+v)=f(u)+f(v)u,v:KIU:KModf:I→U(C+−vec)
f^(a∗v)=a∗f(v)a:Kv:KIU:KModf:I→U(C∗−vec)
// [ 3.14159, 2.71828] v = Sum( Scl(3.14159, Unit(1)), Scl(2.71828, Unit(2))
Bulky syntax, but that can be fixed with a function; let that go.
HEAP
type:"Scl099F" a0001: 0000 0003, 0000 374F v0001: 7F66 A008
type:"Tree07A2"
l0001: 7F66 9800
r0001: 7F66 A000
type:"class" name:"Vec001B" K2B01:"Float64" I0458:"FinAA03" meth1:"eval" +p1:"func"<X,Y> +p2:K2B01 -r:<Y>
type:"Vec001B"
K2B01:"Float64"
I0458:"FinAA03"
type:"class"
name:"Unit70E0"
sup:"Vect001B"
type:"Vec001B"
K2B01:"Float64"
I0458:"FinAA03"
type:"class"
name:"FinAA03"
I0001:0000 0003
....
type:"Unit07A2"
i0001: 0000 0001
type:"Unit07A2"
i0001: 0000 0002
type:"Scl099F" a0001: 0000 0002, 0001 1894 v0001: 7F66 A001
type:"foo9056"
...
type:"foo9056"
...
type:"foo9056"
...
type:"bazEE01"
...
type:"Tree07A2"
l0001: 7F66 9805
r0001: 7F66 A001
type:"Tree07A2"
l0001: 7F66 9801
r0001: 7F66 98A2
....
// [ 3.14159, 2.71828] v = Sum( Scl(3.14159, Unit(1)), Scl(2.71828, Unit(2))
HEAP
type:"Tree07A2"
l0001: 7F66 9800
r0001: 7F66 A000
type:"class" name:"Vec001B" K2B01:"Float64" I0458:"FinAA03" meth1:"eval" +p1:"func"<X,Y> +p2:K2B01 -r:<Y>
type:"Vec001B"
K2B01:"Float64"
I0458:"FinAA03"
type:"class"
name:"Unit70E0"
sup:"Vect001B"
type:"Vec001B"
K2B01:"Float64"
I0458:"FinAA03"
type:"class"
name:"FinAA03"
I0001:0000 0003
....
type:"vev009E"
a0001: 0000 0003, 0000 374F a0001: 0000 0002, 0001 1894
type:"foo9056"
...
type:"foo9056"
...
type:"foo9056"
...
type:"bazEE01"
...
type:"Tree07A2"
l0001: 7F66 9805
r0001: 7F66 A001
....
Prop. Any two free modules on I are naturally isomorphic.
Proof. Let ⟨Fk,e(k):I→Fk⟩ be free.
Then e(2):I→F2 induces a linear map e^2:F1→F2 and vice-versa e^(1):F2→F1. Furthermore e^1∘e^2∘e(1)=e(1). But so does the identity, so by uniqueness of UMP, e^1∘e^2=idF1. Likewise if we reverse the composition. So these functions are isomorphisms.
Prop. Any two free modules on I are naturally isomorphic.
Proof. Let ⟨Fk,e(k):I→Fk⟩ be free.
Then e(2):I→F2 induces a linear map e^2:F1→F2 and vice-versa e^(1):F2→F1. Furthermore e^1∘e^2∘e(1)=e(1). But so does the identity, so by uniqueness of UMP, e^1∘e^2=idF1. Likewise if we reverse the composition. So these functions are isomorphisms.
PROOFS CARRY ALGORITHMIC CONTENT
(Curry-Howard Isomorphism Theorem)
> my_u:MyVec[K,I] = ... > f:I->YourVec[K,I] = i -> YourUnit[K,I](i) > your_u = my_u.ump(f)
Prop. Any two free modules on I are naturally isomorphic.
Proof. Let ⟨Fk,e(k):I→Fk⟩ be free.
Then e(2):I→F2 induces a linear map e^2:F1→F2 and vice-versa e^(1):F2→F1. Furthermore e^1∘e^2∘e(1)=e(1). But so does the identity, so by uniqueness of UMP, e^1∘e^2=idF1. Likewise if we reverse the composition. So these functions are isomorphisms.