Techniques. Contextual equivalence

Similar documents
Contextual equivalence

Step-Indexed Biorthogonality: a Tutorial Example

Realizability Semantics of Parametric Polymorphism, General References, and Recursive Types

Review of The π-calculus: A Theory of Mobile Processes

Parametric Polymorphism and Operational Equivalence

CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008

Bisimulation and coinduction in higher-order languages

Relational Reasoning for Recursive Types and References

A Bisimulation for Type Abstraction and Recursion

Operationally-Based Theories of Program Equivalence

Logical Step-Indexed Logical Relations

Step-indexed models of call-by-name: a tutorial example

Typed Closure Conversion Preserves Observational Equivalence

Step-Indexed Logical Relations for Probability

A Bisimulation for Type Abstraction and Recursion

Trace Refinement of π-calculus Processes

Operational reasoning for functions with local state

The impact of higher-order state and control effects on local relational reasoning

MFPS LICS Special Session Honouring Dana Scott. Symmetric Scott. Andrew Pitts. Computer Laboratory MFPS/LICS /14

Relational Models and Program Logics: Logical Relations in Iris

Recursive types to D and beyond

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

Linearity and Passivity

Names and Symmetry in Computer Science

CMSC 631 Program Analysis and Understanding Fall Type Systems

Interpreting Polymorphic FPC into domain theoretic models of parametric polymorphism

VeriML: Typed Computation of Logical Terms inside a Language with Effects

Streams and Coalgebra Lecture 2

An Introduction to Logical Relations Proving Program Properties Using Logical Relations

Lecture Notes on Data Abstraction

Denotational semantics

A Bisimulation-Like Proof Method for Contextual Properties in Untyped λ-calculus with References and Deallocation

arxiv: v3 [cs.pl] 15 May 2011

Game semantics for an object-oriented language. Nicholas Wolverson

State-Dependent Representation Independence (Technical Appendix)

Equations, contractions, and unique solutions

Kleene realizability and negative translations

From parametric polymorphism to models of polymorphic FPC

Proof Methods for Corecursive Programs. 1. Introduction. Jeremy Gibbons. Graham Hutton

Domain theory and denotational semantics of functional programming

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017

Polymorphic Game Semantics for Dynamic Binding

Limitations of OCAML records

Dipartimento di Informatica Università degli Studi di Verona

Realization of Coinductive Types

A Propositional Dynamic Logic for Instantial Neighborhood Semantics

LOGICAL STEP-INDEXED LOGICAL RELATIONS

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

Typed Normal Form Bisimulation for Parametric Polymorphism

Beyond First-Order Logic

A Semantic Framework for Open Processes

Notes on Logical Frameworks

Predicate Logic. Xinyu Feng 11/20/2013. University of Science and Technology of China (USTC)

Relational Parametricity for Polymorphic Linear Lambda Calculus

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

Bringing class diagrams to life

Typed Closure Conversion Preserves Observational Equivalence

Relational Parametricity for a Polymorphic Linear Lambda Calculus

Streams and Coalgebra Lecture 1

Short Cut Fusion: Proved and Improved

Quantum groupoids and logical dualities

State-Dependent Representation Independence

Compositionality in SLD-derivations and their abstractions Marco Comini, Giorgio Levi and Maria Chiara Meo Dipartimento di Informatica, Universita di

Games for topological fixpoint logics

CATEGORY-THEORETIC MODELS OF LINEAR ABADI & PLOTKIN LOGIC

Operational Nominal Game Semantics

Prime Algebraicity. April 27, 2009

Logical Full Abstraction and PCF

A semantic framework for open processes

Abstract model theory for extensions of modal logic

Typed Closure Conversion Preserves Observational Equivalence

2 Results I: Lifting Computer Science

How to Prove Similarity a Precongruence in Non-Deterministic Call-by-Need Lambda Calculi

Views: Compositional Reasoning for Concurrent Programs

Taming Selective Strictness

Laws of Parallel Synchronised Termination

From Algebras and Coalgebras to Dialgebras

Categorical logics for contravariant simulations, partial bisimulations, modal refinements and mixed transition systems

Reasoning about Local Variables with Operationally-Based Logical Relations

Towards a quantum calculus

Simulation in the Call-by-Need Lambda-Calculus with Letrec, Case, Constructors, and Seq

Coinductive big-step semantics and Hoare logics for nontermination

Minimally Strict Polymorphic Functions

Logic for Computational Effects: work in progress

Simply Typed λ-calculus

Congruence of Bisimulation in a Non-Deterministic Call-By-Need Lambda Calculus

An Operational Domain-theoretic Treatment of Recursive Types

Subtyping and Intersection Types Revisited

Programming Languages and Types

A note on coinduction and weak bisimilarity for while programs

Neighborhood Semantics for Modal Logic Lecture 5

Operational domain theory and topology of sequential programming languages

State-Dependent Representation Independence

Algebraic Trace Theory

Polarized Multigames. Furio Honsell 1, Marina Lenisa 1. Contents

Polymorphism, Subtyping, and Type Inference in MLsub

1. The Method of Coalgebra

Verifying Data Independent Programs Using Game Semantics

Bounded Stacks, Bags and Queues

6- Normalization of classical call-by-need

Transcription:

Techniques 16/22 Contextual equivalence Two phrases of a programming language are ( Morris style ) contextually equivalent ( = ctx )if occurrences of the first phrase in any program can be replaced by the second phrase without affecting the observable results of executing the program. Gottfried Wilhelm Leibniz (1646 1716): two mathematical objects are equal if there is no test to distinguish them. ACS L16, lecture 2 4/10

Contexts are too concrete The semantics of programs only depends on their abstract syntax (parse trees) let a = ref 0 in fun x a :=!a + x ;!a = let a = ref 0 in fun x a :=!a + x ;!a 12/22 Contexts are too concrete The semantics of programs only depends on their abstract syntax (parse trees) modulo renaming of bound identifiers (α-equivalence, = α ). let a = ref 0 in fun x a :=!a + x ;!a = α let b = ref 0 in fun y b :=!b + y ;!b E.g. definition & properties of OCaml typing relation Γ M : τ are simpler if we identify M up to = α. 12/22

Contexts are too concrete The semantics of programs only depends on their abstract syntax (parse trees) modulo renaming of bound identifiers (α-equivalence, = α ). So it pays to formulate program equivalences using mathematical notions that respect α-equivalence. But filling holes in contexts does not respect = α : Contexts are too concrete The semantics of programs only depends on their abstract syntax (parse trees) modulo renaming of bound identifiers (α-equivalence, = α ). So it pays to formulate program equivalences using mathematical notions that respect α-equivalence. But filling holes in contexts does not respect = α : fun x ( ) = α fun y ( ) and x = α x but fun x x = α fun y x 12/22 12/22

Expression relations Language s typing relation expression typing environment Γ M : τ type dictates the form of relations like contextual equivalence: 13/22 Expression relations Language s typing relation Γ M : τ dictates the form of relations like contextual equivalence: Define an expression relation to be any set E of tuples (Γ, M, M, τ) satisfying: (Γ M E M : τ) (Γ M : τ) & (Γ M : τ) 13/22

Operations on expression relations Composition E 1, E 2 E 1 ; E 2 : Γ M E 1 M : τ Γ M E 2 M : τ Γ M (E 1 ; E 2 ) M : τ Reciprocation E E : Γ M E M : τ Γ M E M : τ Identity Id: Γ M : τ Γ M Id M: τ Operations on expression relations Compatible refinement E Ê: Γ M 1 : τ τ M 2 : τ Γ M 1 M 2 : τ 14/22 14/22

Operations on expression relations Compatible refinement E Ê: Γ M 1 E M 1 : τ τ Γ M 2 E M 2 : τ Γ M 1 M 2 Ê M 1M 2 : τ Operations on expression relations Compatible refinement E Ê: Γ M 1 E M 1 : τ τ Γ M 2 E M 2 : τ Γ M 1 M 2 Ê M 1M 2 : τ Γ, x : τ M : τ Γ (fun x M) : τ τ 14/22 14/22

Operations on expression relations Compatible refinement E Ê: Γ M 1 E M 1 : τ τ Γ M 2 E M 2 : τ Γ M 1 M 2 Ê M 1M 2 : τ Γ, x : τ M E M : τ Γ (fun x M) Ê (fun x M ) : τ τ Operations on expression relations Compatible refinement E Ê: Γ M 1 E M 1 : τ τ Γ M 2 E M 2 : τ Γ M 1 M 2 Ê M 1M 2 : τ Γ, x : τ M E M : τ Γ (fun x M) Ê (fun x M ) : τ τ Γ M : τ Γ ref M : τ ref 14/22 14/22

Operations on expression relations Compatible refinement E Ê: Γ M 1 E M 1 : τ τ Γ M 2 E M 2 : τ Γ M 1 M 2 Ê M 1M 2 : τ Γ, x : τ M E M : τ Γ (fun x M) Ê (fun x M ) : τ τ Γ M E M : τ Γ ref M Ê ref M : τ ref etc, etc (one rule for each typing rule) Contextual equiv. without contexts Theorem [Gordon, Lassen (1998)] = ctx (defined conventionally, using contexts) is the greatest compatible & adequate expression relation. where an expression relation E is 14/22 compatible if Ê E 15/22

Contextual equiv. without contexts Theorem [Gordon, Lassen (1998)] = ctx (defined conventionally, using contexts) is the greatest compatible & adequate expression relation. where an expression relation E is compatible if Ê E adequate if M E M : bool s. ( s. s, M s, true ) ( s. s, M s, true ) Precise definition varies according to the observational scenario. E.g. use bisimulation rather than trace based adequacy in presence of concurrency features. Contextual equiv. without contexts Definition = ctx is the union of all expression relations that are compatible and adequate. where an expression relation E is 15/22 compatible if Ê E adequate if M E M : bool s. ( s. s, M s, true ) ( s. s, M s, true ) So defined, = ctx is also reflexive (Id E), symmetric (E E) and transitive (E ; E E). 15/22

Brute force CIU Domains Games Logical relns Bisimulations Program logics sound: determines a compatible and adequate expression relation complete: characterises = ctx useful: for proving programming laws & PL correctness properties general: what PL features can be dealt with? CIU Domains Games Logical relns Bisimulations Program logics Brute force: sometimes compatible closure of {(M, M )} is adequate, and hence M = ctx M. (E.g. [AMP, POPL 2007].)

Domains Games Logical relns Bisimulations Program logics CIU: Uses of Closed Instantiations [Mason-Talcott et al]. Equates open expressions if their closures w.r.t. substitutions have same reduction behaviour w.r.t. any frame stack. Domains + ± + Games + + ± Logical relns Bisimulations Program logics Domains: traditional denotational semantics. Games: game semantics [Abramsky, Malacaria, Hyland, Ong,... ]

Domains + ± + Games + + ± Logical relns + ± + Bisimulations Program logics Logical relations: type-directed analysis of = ctx.at function types: relate functions if they send related arguments to related results. Initially denotational [Plotkin,... ], but now also operational [AMP, Birkedal-Harper-Crary, Ahmed, Johann-Voigtlaender,... ]. Domains + ± + Games + + ± Logical relns + ± + Bisimulations + ± + + Program logics Bisimulations the legacy of concurrency theory: M 1 M 2 T M 1

Domains + ± + Games + + ± Logical relns + ± + Bisimulations + ± + + Program logics Bisimulations the legacy of concurrency theory: M 1 T M 2 T (and symmetrically) M 1 M 2 Domains + ± + Games + + ± Logical relns + ± + Bisimulations + ± + + Program logics Bisimulations the legacy of concurrency theory: applicative [Abramsky, Gordon, AMP] environmental [Pierce-Sumii-Koutavas-Wand] up-to techniques [Sangiorgi, Lassen]

Domains + ± + Games + + ± Logical relns + ± + Bisimulations + ± + + Program logics + + ± Program logics e.g. higher-order Hoare logic [Berger-Honda-Yoshida] Beyond universal identities. Domains + ± + Games + + ± Logical relns + ± + Bisimulations + ± + + Program logics + + ± Q: How do we make sense of all these techniques and results?

Domains + ± + Games + + ± Logical relns + ± + Bisimulations + ± + + Program logics + + ± Q: How do we make sense of all these techniques and results? A: Category Theory can help! For example... Example Relational parametricity is a tool for proving contextual equivalences between polymorphic programs: Λα.e 1 =ctx Λα.e 2 : α.τ if and only if r for all τ 1, τ 2 and all good relations τ 1 τ 2, e 1 [τ 1 /α] and e 2 [τ 2 /α] are related by τ[τ 1 /α] τ[r/α] τ[τ 2 /α] Category theory guides us to free theorems via natural transformations [Wadler]; universal properties of recursive datatypes: initial algebras / final coalgebras / Freyd s free dialgebras [Hasagawa et al]. 18/22

Wise words But once feasibility has been checked by an operational model, operational reasoning should be immediately abandoned; it is essential that all subsequent reasoning, calculation and design should be conducted in each case at the highest possible level of abstraction. Tony Hoare, Algebra and models. In Computing Tomorrow. Future research directions in computer science, Chapter 9, pp 158 187. (Cambridge University Press, 1996). 19/22 Conclusions Operational models can support reasoning, calculation and design at a high level of abstraction especially if we let Category Theory be our guide. Calculus of expression relations provides a useful setting for developing the properties of contextual equivalence. 20/22

Research opportunities The development of programming language theory based on contextual equivalences lags far behind the development of programming language design. Type soundness results are two a penny, but correctness properties up to = ctx are scarce (because they are hard!). E.g. FP community is enthusiastically designing languages combining (higher rank) polymorphic types/kinds with recursively defined functions, datatypes, local state, subtyping,... In many cases the relational parametricity properties of = ctx are unknown. 21/22 Research opportunities The development of programming language theory based on contextual equivalences lags far behind the development of programming language design. Operationally-based work on programming language theory badly needs better tools for computer-aided proof. 21/22