Difgeological Spaces and Denotational Semantics for Difgerential - - PowerPoint PPT Presentation

difgeological spaces and denotational semantics for
SMART_READER_LITE
LIVE PREVIEW

Difgeological Spaces and Denotational Semantics for Difgerential - - PowerPoint PPT Presentation

Difgeological Spaces and Denotational Semantics for Difgerential Programming Ohad Kammar, Sam Staton, and Matthijs Vkr Domains 2018 Oxford 8 July 2018 Kammar, Staton, and Vkr Difgeological Spaces and Denotational Semantics for


slide-1
SLIDE 1

Difgeological Spaces and Denotational Semantics for Difgerential Programming

Ohad Kammar, Sam Staton, and Matthijs Vákár Domains 2018 Oxford 8 July 2018

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-2
SLIDE 2

What is difgerential programming?

▶ PL in which all (some) constructs are difgerentiable… ▶ …and derivatives can be computed mechanically. ▶ Compute derivatives compositionally, using chain rule, rather than symbolically or using fjnite differences. ▶ AKA Automatic Difgerentiation.

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-3
SLIDE 3

Why study semantics of difgerential programming?

Important:

▶ Effjcient optimisation (in high dim); ▶ Effjcient integration/sampling (in high dim); ▶ Often combined with concurrency and probability ⇝ correctness non-trivial and good test-coverage hard to obtain;

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-4
SLIDE 4

Why study semantics of difgerential programming?

Non-Trivial:

▶ How to difgerentiate through traditional language constructs?

▶ conditionals ▶ iteration and term recursion ▶ higher order functions ▶ probability, state and other efgects

▶ How to difgerentiate at structured types?

▶ inductive/recursive types ▶ refjnement types ▶ function types ▶ quotient types

▶ So need to move beyond traditional calculus!

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-5
SLIDE 5

Concrete example of higher-order difgerential prog

Finding Shortest Arc Length

  • - Integrate :: ([0,1] => real) => real
  • - Differentiate :: ([0,1] => real) => [0,1] => real

ArcLength :: ([0,1] => real) => [0,infty) ArcLength(f) = Integrate(Sqrt(1 + Differentiate(f)^2)) Power :: (0,infty) => [0,1] => real Power(a)(t) = t^a

  • - Minimise :: ((0,infty) => real) => (0,infty)

Minimal_a :: real Minimal_a = Minimise(\a -> ArcLength(Power(a)))

  • - Should be 1

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-6
SLIDE 6

Is this not an artifjcial problem?

Stan language:

For specifying a smooth objective function and sampling from it /

  • ptimising it:

▶ conditionals (for custom combinations of objective functions), while loops, recursive functions (for iterative approximations); ▶ higher-order functions (ODE and algebraic solvers, used in pharmacokinetics); ▶ certain refjnement types (constraints: intervals, unit vectors, simplices, symmetric positive defjnite matrices); ▶ fwd and rev mode AutoDifg through everything.

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-7
SLIDE 7

Calculus 101 Refresher

▶ Traditional derivative (Jacobian) Txf : Rn ⊸ Rm

  • f f : U → V at x, where

U open in Rn and V open in Rm ▶ Best linear approximation: lim

v→0

||f(x + v) − f(x) − Txf(v)|| ||v|| = 0

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-8
SLIDE 8

Categories for Smoothness?

Category Open:

▶ objects - opens U in some Rn; ▶ morphisms f : U → V - smooth (C∞) functions from U to V ;

R

U V f Rn Rm

Category Mfd of fjn. dim. manifolds and smooth maps:

▶ Adds surfaces (certain refjnements); ▶ Whitney Embedding: idempotent completion of Open; ▶ Great! If only there were more...

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-9
SLIDE 9

Several Categories of Smooth Maps

▶ Many full subcategories:

EuclSp ⊆

✲ Open ⊆ ✲ Mfd

FreSp

∩ ⊆

✲ FreMfd ❄

ConvSp

∩ ⊆

✲ FroSp ❄

∩ ⊆

✲ Diffeo ⊆ ✲ Sh(Open) ⊆✲ [Openop, Set]

▶ Diffeo Grothendieck quasi-topos and well-pointed; ▶ Interprets tuples, function types, variant types, (co)inductive types, dependent types; ▶ Conservative extension: embeddings into Diffeo preserve all limits and coproducts, colimits of open covers;

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-10
SLIDE 10

Difgeological spaces [Souriau]

Objects

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: constant functions ; precomposition with a smooth gluing of compatible families along open covers .

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-11
SLIDE 11

Difgeological spaces [Souriau]

Objects

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: ▶ constant functions c; precomposition with a smooth gluing of compatible families along open covers .

α(r)=c

− − − − →

c

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-12
SLIDE 12

Difgeological spaces [Souriau]

Objects

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: ▶ constant functions c; ▶ precomposition with a smooth ϕ : U → V gluing of compatible families along open covers .

ϕ

− →

α

− →

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-13
SLIDE 13

Difgeological spaces [Souriau]

Objects

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: ▶ constant functions c; ▶ precomposition with a smooth ϕ : U → V ▶ gluing of compatible families along open covers U.

case{U.αU|U∈U}

− − − − − − − − − − − →

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-14
SLIDE 14

Difgeological spaces [Souriau]

Objects

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that...3 axioms...

Morphisms f : X → Y

Functions f : |X| → |Y | such that: α ∈ SX = ⇒ f ◦ α ∈ SY

Example: Traditional Spaces

▶ For manifold M, defjne (Yoneda) plots SU

M := Mfd(U, M).

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-15
SLIDE 15

Categorical structure

Objects

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that...3 axioms...

Products

SU

X×Y :=

{ r → ( α(r), β(r) )

  • α ∈ SU

X, β ∈ SU Y

}

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-16
SLIDE 16

Categorical structure

Morphisms f : X → Y

Functions f : |X| → |Y | such that: α ∈ SX = ⇒ f ◦ α ∈ SY

Function spaces

  • Y X
  • := Diffeo(X, Y )

SU

Y X :=

{ f : U →

  • Y X
  • uncurry f ∈ Diffeo(U × X, Y )

} NB: The exponential XU is the space of U-plots.

More structure

Coproducts, limits, colimits, (co)inductive types!

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-17
SLIDE 17

Categorical structure

Morphisms f : X → Y

Functions f : |X| → |Y | such that: α ∈ SX = ⇒ f ◦ α ∈ SY

Function spaces

  • Y X
  • := Diffeo(X, Y )

SU

Y X :=

{ f : U →

  • Y X
  • uncurry f ∈ Diffeo(U × X, Y )

} NB: The exponential XU is the space of U-plots.

More structure

Coproducts, limits, colimits, . . . (co)inductive types!

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-18
SLIDE 18

Our example revisited

Finding Shortest Arc Length

  • - Integrate :: ([0,1] => real) => real
  • - Differentiate :: ([0,1] => real) => [0,1] => real

ArcLength :: ([0,1] => real) => [0,infty) ArcLength(f) = Integrate(Sqrt(1 + Differentiate(f)^2)) Power :: (0,infty) => [0,1] => real Power(a)(t) = t^a

  • - Minimise :: ((0,infty) => real) => (0,infty)

Minimal_a :: real Minimal_a = Minimise(\a -> ArcLength(Power(a)))

  • - Should be 1

▶ Uncurry to see Power is smooth; ▶ Integrate sends smooth functions

  • f two arguments to smooth functions, so it is smooth.

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-19
SLIDE 19

Diffeo-morphisms are continuous!

D-Topology

▶ Adjunction with topological spaces (M ∈ Top, X ∈ Diffeo): SU

DiffeoM:= Top(U, M)

OTopX := { B ⊆ X

  • ∀U ∈ Open.α ∈ SU

X, α−1[X] ∈ OU

}

Set Diffeo Top Top Diffeo ⊥ =

▶ Generalises Euclidean topology.

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-20
SLIDE 20

Derivatives?

Covariant Derivative – Fwd Mode

R

U V f Rn Rm

▶ Write TU := U × Rn fst → U TV := V × Rm fst → V ; ▶ And write TU Tf

✲ TV

⟨x, v⟩

✲ ⟨f(x), Txf(v)⟩;

▶ This defjnes a functor

Open ⊆ T

✲ Open→

Open. cod

❄ ❄

i d

▶ Functoriality is chain rule!

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-21
SLIDE 21

Derivatives on Diffeo

▶ Observe that Diffeo→ and Poly(Diffeo) are cocomplete (and complete); ▶ Defjne through left Kan extension

Open ⊆ T

✲ Open→

⇓ Diffeo y

∩ ⊆

Lany(T ∗; y→)

✲ Diffeo→

y→

▶ Functor by construction ⇝ chain rule! ▶ y is full and faithful ⇝ extends usual defjnition; ▶ But many other ways to defjne in literature! Do they coincide..?

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-22
SLIDE 22

Contravariant Derivative – Rev Mode

▶ Write T ∗

xf : Rm ∼

= Rm ⊸ R

Txf⊸R

→ Rn ⊸ R ∼ = Rn; ▶ Defjne polynomials/containers T ∗U := U × Rn fst → U T ∗V := V × Rm fst → V and f∗T ∗V T ∗f

✲ T ∗U

⟨x, ξ⟩

✲ ⟨x, T ∗

xf(ξ)⟩;

▶ This defjnes a functor

Open ⊆ T ∗

✲ Poly(Open)

Open. cod

❄ ❄

id

▶ Functoriality is chain rule! ▶ Left Kan extension: Diffeo → Poly(Diffeo)

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-23
SLIDE 23

Derivatives are dependently typed!

(Co)tangent bundles not all trivial (product projections): take S2. ⇝ dependent types!

Type Formers:

▶ Given Γ ⊢ X type, we get Γ, x : X ⊢ TxX type and Γ, x : X ⊢ T ∗

xX type.

▶ TX is syntactic sugar for Σx:XTxX and T ∗X for Σx:XT ∗

xX.

Term Formers:

▶ Given Γ, x : X ⊢ f(x) : Y , we get Γ, x : X, v : TxX ⊢ Txf(v) : Tf(x)Y and Γ, x : X, ξ : T ∗

f(x)Y ⊢ T ∗ xf(ξ) : T ∗ xX.

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-24
SLIDE 24

Difgeological Domains [Kammar, Staton, Vákár]

Category ωDiffeo

▶ Objects: difgeological spaces X with an ω-cpo structure ≤X, s.t. SX is closed under lubs of ω-chains; ▶ Morphisms: Scott continuous Diffeo-morphisms; ▶ Gives a (co)complete ccc ωDiffeo (locally presentable); ▶ Recursive types through Fiore’s axiomatic domain theory! ▶ Defjne T, T ∗ as enriched Kan extensions, but working with ωDiffeo→

fib and its dual fjbration?

3 More Equivalent Characterisations

▶ ωCpo-Enriched separated sheaves on Open; ▶ Models of an essentially algebraic theory; ▶ Internal language ω-cpos in Diffeo.

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-25
SLIDE 25

Conclusion

Summary

▶ Diffeo: very simple, well-behaved and rich setting for semantics of difgerential languages ▶ 11AM - Ohad Kammar - A Domain Theory for Probability

Some Questions

▶ Derivative of a recursive function and T, T ∗ on ωDiffeo? ▶ An adequate semantics for difgerential programming? ▶ Prove corrects NUTS? ▶ Analyse the (co)tangent bundle of function types? ▶ C.f (co)tangent bundles in literature? ▶ Smooth probability monad? ▶ Relationship cotangent bundle and CPS? ▶ Boman’s theorem: why not restrict to SR

X?

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-26
SLIDE 26

Thanks!

Recall - defjnition

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: constant functions ; precomposition with a smooth gluing of compatible families along open covers .

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-27
SLIDE 27

Thanks!

Recall - defjnition

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: ▶ constant functions c; precomposition with a smooth gluing of compatible families along open covers .

α(r)=c

− − − − →

c

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-28
SLIDE 28

Thanks!

Recall - defjnition

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: ▶ constant functions c; ▶ precomposition with a smooth ϕ : U → V gluing of compatible families along open covers .

ϕ

− →

α

− →

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming

slide-29
SLIDE 29

Thanks!

Recall - defjnition

A difgeological space X = ( |X|, SX ) consists of: ▶ a carrier set |X|; ▶ a set of plots SU

X ⊆ |X|U for all U ∈ Open

such that the plots are closed under: ▶ constant functions c; ▶ precomposition with a smooth ϕ : U → V ▶ gluing of compatible families along open covers U.

case{U.αU|U∈U}

− − − − − − − − − − − →

Kammar, Staton, and Vákár Difgeological Spaces and Denotational Semantics for Difgerential Programming