Topology for functional programming

Similar documents
Domain theory and denotational semantics of functional programming

Constructive decidability of classical continuity

EXHAUSTIBLE SETS IN HIGHER-TYPE COMPUTATION

A Constructive Model of Uniform Continuity

Constructive decidability of classical continuity

Constructive mathematics in univalent type theory

On the versatile selection monad with applications to proof theory

Categorical axioms for functional real-number computation

Proof Theory and Subsystems of Second-Order Arithmetic

Chapter 1 A computational interpretation of forcing in Type Theory

Comparing cartesian closed categories of (core) compactly generated spaces

Operational domain theory and topology of sequential programming languages

A New Category for Semantics

Synthetic Computability (Computability Theory without Computers)

Filters in Analysis and Topology

Comparing hierarchies of total functionals

Part II Logic and Set Theory

An Effective Spectral Theorem for Bounded Self Adjoint Oper

Scott Domains for Denotational Semantics and Program Extraction

CM10196 Topic 2: Sets, Predicates, Boolean algebras

Handbook of Logic and Proof Techniques for Computer Science

We are going to discuss what it means for a sequence to converge in three stages: First, we define what it means for a sequence to converge to zero

Completeness in the Monadic Predicate Calculus. We have a system of eight rules of proof. Let's list them:

The Peirce Translation and the Double Negation Shift

Introduction to Topology

2.23 Theorem. Let A and B be sets in a metric space. If A B, then L(A) L(B).

Synthetic Topology of Data Types and Classical Spaces

König s Lemma and Kleene Tree

Synthetic Computability

CHAPTER 11. Introduction to Intuitionistic Logic

arxiv: v1 [math.lo] 30 Jan 2018

18.175: Lecture 2 Extension theorems, random variables, distributions

Between proof theory and model theory Three traditions in logic: Syntactic (formal deduction)

Part II. Logic and Set Theory. Year

ACLT: Algebra, Categories, Logic in Topology - Grothendieck's generalized topological spaces (toposes)

Classes of Polish spaces under effective Borel isomorphism

More Model Theory Notes

The Metamathematics of Randomness

4 Countability axioms

Introduction to type theory and homotopy theory

1 / A bird s-eye view of type theory. 2 A bird s-eye view of homotopy theory. 3 Path spaces and identity types. 4 Homotopy type theory

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

Realizable Extensions of Intuitionistic Analysis: Brouwer, Kleene, Kripke and the End of Time

Lecture Notes in Advanced Calculus 1 (80315) Raz Kupferman Institute of Mathematics The Hebrew University

10 Excision and applications

A constructive theory of classes and sets

Understanding Computation

Discrete Mathematics

Essential facts about NP-completeness:

Final Exam (100 points)

Topological and Limit-space Subcategories of Countably-based Equilogical Spaces

The intrinsic topology of Martin-Löf universes

01. Review of metric spaces and point-set topology. 1. Euclidean spaces

cse371/mat371 LOGIC Professor Anita Wasilewska Fall 2018

MH 7500 THEOREMS. (iii) A = A; (iv) A B = A B. Theorem 5. If {A α : α Λ} is any collection of subsets of a space X, then

Löwenheim-Skolem Theorems, Countable Approximations, and L ω. David W. Kueker (Lecture Notes, Fall 2007)

Descriptive Set theory

Lecture 2: Syntax. January 24, 2018

An injection from N N to N

Parametricity and excluded middle

Logic, Sets, and Proofs

CONTENTS. Appendix C: Gothic Alphabet 109

Introduction to Metalogic

Operational domain theory and topology of a sequential programming language

Solutions to Tutorial 8 (Week 9)

Discrete Mathematics. W. Ethan Duckworth. Fall 2017, Loyola University Maryland

Notes on induction proofs and recursive definitions

Introduction to Logic and Axiomatic Set Theory

Informal Statement Calculus

Symposium: L.E.J. Brouwer, Fifty Years Later. Free Choice Sequences: A Temporal Interpretation Compatible with Acceptance of Classical Mathematics

Proofs. Chapter 2 P P Q Q

Higher toposes Internal logic Modalities Sub- -toposes Formalization. Modalities in HoTT. Egbert Rijke, Mike Shulman, Bas Spitters 1706.

Models of Computation,

CIS 2033 Lecture 5, Fall

Then A n W n, A n is compact and W n is open. (We take W 0 =(

Halting and Equivalence of Program Schemes in Models of Arbitrary Theories

tp(c/a) tp(c/ab) T h(m M ) is assumed in the background.

arxiv:math/ v1 [math.lo] 5 Mar 2007

Effective descriptive set theory

CMPSCI 601: Tarski s Truth Definition Lecture 15. where

Operational domain theory and topology of a sequential programming language

Primitive recursive functions: decidability problems

Step-Indexed Biorthogonality: a Tutorial Example

1.A Topological spaces The initial topology is called topology generated by (f i ) i I.

7 Complete metric spaces and function spaces

Part III Logic. Theorems. Based on lectures by T. E. Forster Notes taken by Dexter Chua. Lent 2017

Languages, regular languages, finite automata

Meta-logic derivation rules

4 Choice axioms and Baire category theorem

Lecture 1: Overview. January 24, 2018

BOREL SETS ARE RAMSEY

TT-FUNCTIONALS AND MARTIN-LÖF RANDOMNESS FOR BERNOULLI MEASURES

Algorithmically random closed sets and probability

A Semantics of Evidence for Classical Arithmetic

MATH 3300 Test 1. Name: Student Id:

The space of located subsets

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms

SELF-DUAL UNIFORM MATROIDS ON INFINITE SETS

17.1 Correctness of First-Order Tableaux

Muchnik and Medvedev Degrees of Π 0 1

Transcription:

Topology for functional programming Martín Escardó University of Birmingham, England EWSCS, Palmse, Estonia, 26 Feb 2 Mar 2012

Computational fact Function types A B with A infinite don t have decidable equality. f = g x A(f(x) = g(x)). How could one possibly check infinitely many cases in finite time? Also, equality on B may not be decidable. 1

Computational fact Function types A B with A infinite don t have decidable equality. How could one possibly check infinitely many cases in finite time? This is certainly not possible if A = B = N. Turing, Kleene,... 2

Fact? There are function types with decidable equality! 1. N N 2. N Bool 3. (N Bool) N 4. (N N) N 5. (N Bool) (N Bool) 6. ((N Bool) N) Bool 7. (((N Bool) N) Bool) ((N Bool) N) 3

Pause to see and run such a decision algorithm http://www.cs.bham.ac.uk/~mhe/.talks/ewscs2012/ The programs won t be understandable at this point: 1. They exploit topological ideas to be introduced in the tutorial. 2. I have chosen an algorithm that exponentially reduces the time complexity of simpler algorithms. In the theory developed in these slides, I will sacrifice efficiency and show you simpler algorithms. 4

Topological explanation In the decidable cases: i. The domains of the function types are compact. ii. The codomains are discrete. 5

Topological explanation In the decidable cases: i. The domains of the function types are compact. ii. The codomains are discrete. 1. N N 2. N Bool 3. (N Bool) N 4. (N N) N 5. (N Bool) (N Bool) 6. ((N Bool) N) Bool 7. (((N Bool) N) Bool) ((N Bool) N) 6

Inductive definition of types with decidable equality Simultaneously defined with exhaustively searchable types: discrete has decidable equality compact exhaustively searchable. discrete ::= 2 N discrete discrete compact discrete, compact ::= 2 compact compact discrete compact. Here 2 = {0, 1} is (isomorphic to) the type of booleans. The types that are simultaneously discrete and compact are finite. 7

What is topology? Topology is the field of mathematics that studies spaces and continuous transformations between them. Topology comes with its own language: Topological space, continuous function, open set, closed set, limit, convergence, discrete space, Hausdorff space, compact space,.... 8

Brouwer. Topology in constructive mathematics (1920-1950) 9

Continuity in constructive mathematics Think of functions α: N N as sequences α 0, α 1, α 2,... of natural numbers. Consider a function f : (N N) (N N) in constructive mathematics. Brouwer reasoned that it must be the case that Finite parts of the output sequence f(α) can depend only on finite parts of the input sequence α. This amounts to saying that f is continuous. 10

We need a preliminary definition: Continuity more rigorously For sequences α, β : N N and a number n N, write α = n β i < n(α i = β i ). The two sequences agree in the first n positions. 11

Continuity more rigorously A function f : (N N) (N N) is continuous iff α n m β (α = m β = f(α) = n f(β)). If you want to know the first n positions of the output sequence f(α), it is enough to know the first m positions of the input sequence α. Notice that m depends on both α and n. 12

Non-continuous functions A function f : (N N) (N N) is continuous iff α n m β (α = m β = f(α) = n f(β)). Counter-example: f(α) = Notice that this uses excluded middle. { 0 ω if α = 0 ω, 1 ω otherwise. Without excluded middle you can t define a non-continuous function! 13

For those of you who already know a bit of topology 1. Endow N with the discrete topology. 2. Endow N N = (N N) with the product topology. (Which agrees with the compact-open topology, which gives the categorical exponential.) This space is known as the Baire space. 3. Then f : (N N) (N N) is continuous in the above sense if and only if it is topologically continuous. (Inverse images of open sets are open.) 14

The cantor space Let 2 = {0, 1} be the set of binary numbers. The space 2 N = (N 2) of binary sequences is known as the Cantor space. (Because it is homeomorphic to Cantor s third-middle set.) We can repeat the above story: A function f : (N 2) (N N) is continuous iff α n m β (α = m β = f(α) = n f(β)). But something new happens: given n, we can find m independently of α. 15

Uniform continuity A function f : (N 2) (N N) is continuous iff α n m β (α = m β = f(α) = n f(β)). A function f : (N 2) (N N) is uniformly continuous iff n m α β (α = m β = f(α) = n f(β)). Clearly, uniform continuity implies plain continuity. 16

Uniform continuity Theorem. Any continuous f : (N 2) (N N) is uniformly continuous. Proof ingredient in classical topology: Compactness of the Cantor space. Alternatively, König s Lemma. Proof ingredient in Brouwer s intuitionistic mathematics: The Fan Theorem, which is proved from the Bar induction axiom. 17

Another instance of (uniform) continuity A function f : (N 2) N is continuous iff α m β (α = m β = f(α) = f(β)). A function f : (N 2) N is uniformly continuous iff m α β (α = m β = f(α) = f(β)). The two notions are again equivalent. The smallest such number m = m(f) is called the modulus of uniform continuity of f. 18

Topology in recursion theory (1950-1980) Kleene, Kreisel, Lacombe, Myhill, Shepherdson, Rice, Nerode, Normann, Gandy, Hyland,... 1. Neighbourhood spaces. 2. Limit spaces. 3. Compactly generated topological spaces. 4. Sequential topological spaces. 5. Stone spaces. 19

Topology in computer science (1960 present) Scott. 1. Domain theory: denotational semantics & computability. 2. The main categories of domains are full subcategories of the category of topological spaces. Domain theory is good for partial computation. In this tutorial we ll tacitly concentrate on total functions. This will allow us to work with more traditional topological spaces. (But domain theory remains crucial.) 20

Topology in computer science (1980 present) Smyth. Predicate transformers: a topological view. Abramsky. Logic of observable properties. Vickers. Topology via logic. Weihrauch. Type 2 computability theory. Smyth was the first in the computer science community to take the topological view of domains seriously and to advocate the need for more general spaces. (See his Topology chapter in the Handbook of Logic in Computer Science.) 21

Topology in computer science (2000 present) Simpson & Schröder: 1. QCB spaces. Again a full subcategory of topological spaces, including domains. 2. A richer supply of spaces for semantics and computability. 3. Unifies Scott s and Weihrauch s approaches. 4. Allows explicit treatment of total objects (without bottom elements). 5. Arises from a convergence of ideas from semantics and computability. 22

Escardó & Ho. Topology in operational semantics (2005) 1. You don t need a denotational semantics to find and exploit domain theory and topology in programming languages. 2. It can be identified directly in operational terms. 3. Doesn t suffer from the so-called full abstraction problem. Operational domain theory and topology of sequential programming languages. Information and Computation 207 (2009). 23

Dictionary relating topology and computation space type continuous function computable function clopen set decidable set open set semi-decidable set closed set set with semi-decidable complement discrete space type with decidable equality Hausdorff space type with semi-decidable Compact set exhaustively searchable set, in a finite number of steps Another connection of topology with computation/constructive mathematics has recently been found in type theory, via homotopy types. These two connections should be combined! 24

What is this dictionary good for? 25

Algorithm for finding theorems in computability theory 1. Go the library. 2. Pick a book on topology. 3. Pick a theorem. 4. Apply the dictionary. 5. Get a theorem in computation. Synthetic topology of data types and classical spaces, 134 pages, ENTCS, 2004. Exhaustible sets in higher-type computation. Logical Methods in Computer Science, 2008. 26

Some examples 1. A compact subspace of a Hausdorff space is closed. 2. A closed subspace of a compact space is compact. 3. A product of arbitrarily many compact spaces is compact. 4. If X is compact and Y is discrete then X Y is discrete. 5. If Y is Hausdorff then X Y is Hausdorff. 6. If K X is compact and U Y is open, then {f (X Y ) f(k) U} is open. 7. A space X is compact iff for every space Y the projection X Y Y maps closed sets to closed sets. 8. Any non-empty, countably based, compact Hausdorff space is a continuous image of the Cantor space (N 2).. 27

Simple example A compact subspace of a Hausdorff space is closed. Assumptions: X is a Hausdorff space, K X is compact. Conclusion: K is closed. Assumptions: X has semi-decidable, the set K X is searchable. Conclusion: K has semi-decidable complement. Algorithm: For given x X, to semi-decide x K, exhaustively check that x y for every y K. 28

What is an exhaustively searchable set? There are two main versions of the notion: 1. Given a semi-decidable p, semi-decide whether p(x) holds for all x in the set. Synthetic topology of data types and classical spaces, ENTCS, 2004. 2. Given a decidable p, decide whether p(x) holds for all x in the set. Exhaustible sets in higher-type computation. LMCS, 2008. In this tutorial I will consider the decidable case. 29

Exhaustively searchable sets And there are two natural versions in the decidable case. Given a type X, a set K X and a decidable predicate p: X Bool, we may wish to: 1. Decide whether p(k) holds for some k K or not. 2. Find an example of a k K satisfying p, or a counter-example otherwise. 30

Exhaustively searchable sets 1. Decide whether p(k) holds for some k K. E K : (X Bool) Bool Characteristic function of the existential quantifier. 2. Find an example of a k K satisfying p, or a counter-example otherwise. ε K : (X Bool) X Selection function. (Cf. Hilbert s ε-calculus.) 31

A subset K X of a type X is: Exhaustively searchable sets 1. Exhaustible if there is a computable functional E K : (X Bool) Bool such that E K (p) = True k K(p(k) = True). 2. Searchable if there is a computable functional such that ε K : (X Bool) X i. ε K (p) K, and ii. p(ε(p)) = True k K(p(k) = True). 32

Exhaustively searchable sets 1. K X is Exhaustible if there is a computable functional E K : (X Bool) Bool. 2. K X is Searchable if there is a computable functional ε K : (X Bool) X. We can define E K (p) = p(ε K (p)), which shows that if K is searchable then it is exhaustible. 33

Theorem Consider the least set of types containing the booleans, natural numbers and closed under products and function types. 1. Any non-empty exhaustible set is searchable. 2. A computable image of an exhaustible set is exhaustible. 3. A decidable subset of an exhaustible set is exhaustible. 4. Searchable sets are closed under finite and countable products. 5. Hence the Cantor space n N 2 = (N 2) is searchable. 6. Any searchable set is a computable image of the Cantor space. And more. 34

The proofs 1. They are written in mathematical vernacular in the papers, with explicitly given algorithms. 2. I ve also written most of the algorithms in Haskell. 3. I ve also written some of the proofs/algorithms in Agda. I ll sketch one proof to illustrate how topology is used. 35

Cantor space search by Ulrich Berger (1990) data Bit = Zero One type Cantor = [Bit] -- I only care about the infinite lists find :: (Cantor -> Bool) -> Cantor forsome, forevery :: (Cantor -> Bool) -> Bool find p = if forsome(\a -> p(zero : a)) then Zero : find(\a -> p(zero : a)) else One : find(\a -> p(one : a)) forsome p = p(find p) forevery p = not(forsome(\a -> not(p a))) 36

Decidability of extensional equality: Corollary equal :: (Cantor -> Integer) -> (Cantor -> Integer) -> Bool equal f g = forevery(\a -> f a == g a) This is exponentially slow in a precise sense. So I looked for faster algorithms. Infinite sets that admit fast exhaustive search. LICS 2007. Exhaustible sets in higher-type computation. LMCS, 2008. 37

Proof sketch of Berger s algorithm Let s rewrite the code by inlining one mutual recursive call: find :: (Cantor -> Bool) -> Cantor find p = if p(zero : find(\a -> p(zero : a)) then Zero : find(\a -> p(zero : a)) else One : find(\a -> p(one : a)) Notice something odd: there is a recursive call in the condition! This, together with the uniform continuity of p :: Cantor -> Bool, is what makes the algorithm work. 38

Uniform continuity revisited A function p : (N 2) 2 is uniformly continuous iff m α β (α = m β = p(α) = p(β)). The number m = m(p) is called the modulus of uniform continuity of p. Notice that when m(p) = 0 the condition α = m β always holds. Hence in this case we get α β (p(α) = p(β)). That is, that p is constant. 39

Proof sketch of Berger s algorithm find :: (Cantor -> Bool) -> Cantor find p = if p(zero : find(\a -> p(zero : a)) then Zero : find(\a -> p(zero : a)) else One : find(\a -> p(one : a)) The proof that this algorithm is productive proceeds by induction on the modulus of continuity of p. 1. If m(p) = 0 then p doesn t depend on its argument. In this case the recursive call in the condition doesn t take place, and one bit of output is produced. 2. If m(p) > 0 then the two predicates \a -> p(zero : a) and \a -> p(one : a) have modulus of continuity m(p) 1 or smaller. 40

Technical subtlety I glossed over some important details in the above sketch for simplicity. If I get to talk about domain theory, I ll come back to this: There are two relevant notions of modulus of uniform continuity. Difference between being constant and not looking at its argument. The second condition is captured by a certain intensional modulus of continuity, which is what really has to be used in the proof. Have a look at e.g. Operational domain theory and topology of sequential programming languages. Information and Computation 207 (2009). 41

Some combinators for searchable sets type J r x = (x -> r) -> x type K r x = (x -> r) -> r -- Selection functions. -- Quantifiers. Here they are used with r = Bool But in related work with Paulo Oliva we use them with r more general. Type of searchable/exhaustible subsets of the type X: type Searchable x = J Bool x type Exhaustible x = K Bool x image :: (x -> y) -> Searchable x -> Searchable y times :: Searchable x -> Searchable y -> Searchable(x,y) prod :: (N -> Searchable x) -> Searchable(N -> x) 42

Some combinators for searchable sets forsome, forevery :: Searchable x -> Exhaustible x forsome e p = p(e p) forevery s p = not(forsome s (\x -> not(p x))) equal :: Eq y => Searchable x -> (x -> y) -> (x -> y) -> Bool equal s f g = forevery s (\a -> f a == g a) 43

Agda program/proofs http://www.cs.bham.ac.uk/~mhe/agda/ 44

Uses? 1. Alex Simpson s Lazy functional algorithms for exact real functionals. Compute maximum value and integral of a real function, with real numbers represented as infinite sequences of digits. 2. I ve also automatically verified some real-number programs by checking infinitely many cases. Verification of conventional programs? I ll show you one example in Haskell. 45

Johnstone s topological topos. Continuous model of dependent types 1. Fully embeds the category of sequential topological spaces. 2. Fully embeds the category of Kuratowski s limit spaces. 3. Validates the above continuity principles (and more). 46

Remark in passing The classical set-theoretical model of Gödel s system T is not fully abstract. But the topological model of sequential spaces is. Similarly for Martin-Löf type theory. See my note Kreisel s counter-example to full abstraction of the set-theoretical model of Goedel s system T. 47

Work with Paulo Oliva The countable product of selection functions, originally developed to realize the Tychonoff theorem from topology, also: 1. Optimally plays sequential games (such as Tic-Tac-Toe, to be mundane). 2. Realizes the double-negation shift from proof theory. In turn used to realize the classical axiom of countable (dependent) choice. http://www.cs.bham.ac.uk/~mhe/papers/msfp2010/ http://www.cs.bham.ac.uk/~mhe/pigeon/ 48

The only difference between reality and fiction is that fiction needs to be credible. Mark Twain 49