negations - university of tokyocontribution development of type systems refuting derivability in...

70
Negations in Refinement Type Systems T. Tsukada (U. Tokyo) 18th Nov, 2015 Oxford, UK

Upload: others

Post on 30-Jan-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negationsin Refinement Type Systems

T. Tsukada (U. Tokyo)

18th Nov, 2015Oxford, UK

Page 2: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

This TalkAbout refinement intersection type systems that refute judgements of other type systems.

Page 3: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

BackgroundRefinement intersection type systems are the basis for

• model checkers for higher-order model checking (cf. [Kobayashi 09] [Broadbent&Kobayashi 11] [Ramsay+ 14]),

• software model-checker for higher-order programs (cf. MoCHi [Kobayashi+ 11]).

In those type systems,

• a derivation gives a witness of derivability,• but nothing witnesses that a given derivation is

not derivable.

Page 4: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

MotivationA witness of underivability would be useful for

• a compact representation of an error trace

• an efficient model-checker in collaboration with the affirmative system

• cf. [Ramsay+ 14] [Godefroid+ 10]

• development of a type system proving safety• In some cases (e.g. [T&Kobayashi 14]), a type system

proving failure is easier to be developed.

Page 5: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

ContributionDevelopment of type systems refuting derivability in some type systems such as

• a basic type system for the 𝜆𝜆-calculus• a type system for call-by-value reachability

Theoretical study of the development

Page 6: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Outline• Negations in type systems for

• the call-by-name 𝜆𝜆→-calculus• Target language• Affirmative System• Negative System

• the call-by-name 𝜆𝜆→-calculus + recursion• a call-by-value language + nondeterminism

• Semantic analysis

• Discussions

Page 7: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

CbN 𝜆𝜆→-calculusA simply typed calculus equipped with 𝛽𝛽𝛽𝛽-equivalence.

Kinds (i.e. simple types):

Terms:

Page 8: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

CbN 𝜆𝜆→-calculusA simply typed calculus equipped with 𝛽𝛽𝛽𝛽-equivalence.

Typing rules:

Page 9: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

CbN 𝜆𝜆→-calculusA simply typed calculus equipped with 𝛽𝛽𝛽𝛽-equivalence.

Equational theory:

Page 10: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Outline• Negations in type systems for

• the call-by-name 𝜆𝜆→-calculus• Target language• Affirmative System• Negative System

• the call-by-name 𝜆𝜆→-calculus + recursion• a call-by-value language + nondeterminism

• Semantic analysis

• Discussions

Page 11: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Affirmative system for CbN 𝜆𝜆→

The type system for higher-order model checking (without the rule for recursion).

Types are parameterised by kinds and ground type sets:

We use the following syntax for types:

Page 12: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Sets of Types via Refinement RelationLet A be a kind.The set Ty𝑄𝑄(𝐴𝐴) of types that refines A is given by

where is the refinement relation:

Page 13: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

SubtypingThe subtyping relation is defined by induction on kinds.

Page 14: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Type EnvironmentsA (finite) map from variables to sets of types

(or intersection types).

Page 15: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Typing rules

Page 16: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Fact: Invariance under 𝛽𝛽𝛽𝛽-equivalenceSuppose that 𝑀𝑀 =𝛽𝛽𝛽𝛽 𝑁𝑁. Then

• This fact will not be used in the sequel.

Page 17: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Convention: Subtyping closureIn what follows, sets of types are assumed to be closed under the subtyping relation.

Now posets of types are simply defined by:

where

(cf. 𝑋𝑋 ⊆ 𝑌𝑌 implies ⋀𝑋𝑋 ≽ ⋀𝑌𝑌)

Page 18: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Convention: Subtyping closureIn what follows, sets of types are assumed to be closed under the subtyping relation.

The rule for variables becomes simpler.

Page 19: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Outline• Negations in type systems for

• the call-by-name 𝜆𝜆→-calculus• Target language• Affirmative System• Negative System

• the call-by-name 𝜆𝜆→-calculus + recursion• a call-by-value language + nondeterminism

• Semantic analysis

• Discussions

Page 20: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negative Type SystemNegative types are those constructed from the negative ground types :

Typing rules are the same as the affirmative system.

Page 21: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negation of a typeWe define the two anti-monotone bijections on types

as follows:

Page 22: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negation

Page 23: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Natural

Page 24: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Natural

Page 25: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Natural

… …

Page 26: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negation of a typeWe define the two anti-monotone bijections on types

as follows:

Page 27: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negation of a typeWe define the two anti-monotone bijections on types

as follows:

Page 28: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Main TheoremTheorem

• if and only if ,where

• Let . Then

Proof) By mutual induction on the structure of the term.

Page 29: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Main TheoremTheorem

• if and only if ,where

• Let . Then

Proof) By mutual induction on the structure of the term.under a certain condition

Page 30: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Outline• Negations in type systems for

• the call-by-name 𝜆𝜆→-calculus• the call-by-name 𝜆𝜆→-calculus + recursion• a call-by-value language + nondeterminism

• Semantic analysis

• Discussions

Page 31: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

𝜆𝜆→ + RecursionTerm:

Equational theory:

Page 32: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Recursion Rule in Affirmative SystemThe rule for recursion is given by:

This is a co-inductive rule: a derivation can be infinite.

Page 33: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Recursion Rule in Negative SystemThe rule for recursion is given by:

This is a inductive rule: a derivation must be finite.

Page 34: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Main TheoremLemma

Theorem

• if and only if .

• Let . Then

Page 35: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Outline• Negations in type systems for

• the call-by-name 𝜆𝜆→-calculus• the call-by-name 𝜆𝜆→-calculus + recursion• a call-by-value language + nondeterminism

• Semantic analysis

• Discussions

Page 36: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Target LanguageKinds (or simple types):

Terms:

Page 37: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Value judgements (Δ ⊢ 𝑀𝑀:𝐴𝐴):

Computation judgements (Δ ⊢ 𝑀𝑀:𝑇𝑇𝐴𝐴):

Simple Type System

Page 38: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Reduction SemanticsBase cases:

Evaluation context:

Page 39: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Affirmative SystemTypes (formally defined by induction on types):

Refinement relation:

Page 40: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Let

Then 𝜏𝜏 ∷ 𝑜𝑜 → 𝑇𝑇𝑜𝑜 → 𝑇𝑇𝑜𝑜.

Examples of derivable/underivable judgements

Example of a type

Page 41: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Typing RulesValue judgements (Γ ⊢ 𝑀𝑀: 𝜏𝜏 with 𝜏𝜏 ∷ 𝐴𝐴):

Computation judgements (Γ ⊢ 𝑀𝑀: 𝜏𝜏 with 𝜏𝜏 ∷ 𝑇𝑇𝐴𝐴):

Page 42: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Soundness and CompletenessTheorem

(where 𝑀𝑀 ≔ { 𝑣𝑣 ∣ 𝑀𝑀 →∗ 𝑣𝑣 })

In particular,

Page 43: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negative SystemTypes (formally defined by induction on types):

Refinement relation:

Page 44: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Typing RulesValue judgements (Γ ⊢ 𝑀𝑀: 𝜏𝜏 with 𝜏𝜏 ∷ 𝐴𝐴):

Computation judgements (Γ ⊢ 𝑀𝑀: 𝜏𝜏 with 𝜏𝜏 ∷ 𝑇𝑇𝐴𝐴):

Page 45: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Typing rules (cont.)Rules for conditional branch:

Page 46: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Typing rulesRule for let-expression:

Page 47: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Soundness and CompletenessTheorem

(where 𝑀𝑀 ≔ { 𝑣𝑣 ∣ 𝑀𝑀 →∗ 𝑣𝑣 })

In particular,

Page 48: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negation of a typeGiven a kind 𝐴𝐴, let

We define two operations:

Page 49: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Definition of the Negation

Page 50: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Examples

Page 51: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Examples

Page 52: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Let

Then

Examples

Page 53: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Main TheoremTheorem

• if and only if .

• Let . Then

Page 54: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Some (Possible) Extensions1. CbV calculus with integers

• Straightforward.• One needs infinite intersection and union.

2. CbV calculus with recursion

• I believe that it is straightforward, though I have not yet checked.

Page 55: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Outline• Negations in type systems for

• the call-by-name 𝜆𝜆→-calculus• the call-by-name 𝜆𝜆→-calculus + recursion• a call-by-value language + nondeterminism

• Semantic analysis

• Discussions

Page 56: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

How to Develop the Negative Systems1. The CbN system has a categorical description.

2. The negation induces an automorphism.

3. A CbV system is given by a monad on ScottL𝑢𝑢.

4. The negative system is given by the monad

Page 57: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Category ScottL𝑢𝑢Definition The category ScottL is given by:

Object Poset (𝐴𝐴,≤𝐴𝐴).

Morphism An upward-closed relation

Composition Let . Then

Page 58: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Interpretation of CbN 𝜆𝜆→in ScottL𝑢𝑢Fact ScottL𝑢𝑢 is a cartesian closed category.

Interpretation of kinds is given by:

Hence .

Fact

Page 59: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negation Functor on ScottL𝑢𝑢The functor 𝜑𝜑: ScottL𝑢𝑢 → ScottL𝑢𝑢 is defined by:

Lemma 𝜑𝜑 is an isomorphism on ScottL𝑢𝑢.

If R ∈ 𝑢𝑢 𝐴𝐴 𝑜𝑜𝑜𝑜 × 𝐵𝐵 and 𝐴𝐴 = ∅, then

which is essentially the complement of 𝑅𝑅.

Page 60: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Monad and Call-by-ValueA monad on a category 𝐶𝐶 is a functor 𝐶𝐶 → 𝐶𝐶 with some additional structures.

A (strong) monad on a CCC gives rise to a model of a call-by-value calculus [Moggi 91].

A monad on ScottL𝑢𝑢 can be seen as a refinement type system for a call-by-value calculus.

Page 61: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Negated Monad and Negative SystemLet 𝑇𝑇: ScottL𝑢𝑢 → ScottL𝑢𝑢 be a strong monad. Then

has the canonical monad structure. Furthermore the respective Kliesli categories are isomorphic

and the refinement type system corresponding to the right-hand-side is the negation of the left-hand-side.

Page 62: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

ExampleThe previous type system for CbV calculus is given by the following monad.

Page 63: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Outline• Negations in type systems for

• the call-by-name 𝜆𝜆→-calculus• the call-by-name 𝜆𝜆→-calculus + recursion• a call-by-value language + nondeterminism

• Semantic analysis

• Discussions

Page 64: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Automata complementationCorresponds to negation of a 2nd-order judgement.

Page 65: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Boolean Closedness of TypesLet 𝐴𝐴 be a kind and 𝐵𝐵𝐴𝐴 be the set of all Böhm trees of type 𝐴𝐴. A language is a subset of 𝐵𝐵𝐴𝐴.

Definition A language 𝐿𝐿 ⊆ 𝐵𝐵𝐴𝐴 is type-definable if there exists a type 𝜏𝜏 such that

in the type system for higher-order model checking [Kobayashi&Ong 09] [T&Ong 14].

Corollary The class of type-definable languages are closed under Boolean operations on sets.

Page 66: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Further ApplicationsThe technique presented in this talk is applicable to:

• the type system for the full higher-order model-checking [Kobayashi&Ong 09]

• a type system witnessing call-by-value reachability [T&Kobayashi 14]

• a dependent intersection type system in [Kobayashi+ 11], via the translation of dependent types to intersection and union types

Page 67: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Consistency and InconsistencyThe negation of a "small" type can be very large. So the negation may not be efficiently computable.

The notion of consistency and inconsistency may be useful in the practical use:

Definition Let and . They are consistent if and inconsistent otherwise.

Proposition If 𝜏𝜏 and �𝜎𝜎 are inconsistent, then

Page 68: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Inductive Definition of Consistency

Inductive definition of inconsistency is now trivial.

Page 69: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

Related Work"Krivine machines and higher-order schemes" [Salvati&Walkiewicz 12]

• The notion of consistency and inconsistency can be found in their work (called complementarityfor the former and the latter has no name).

• This talk is partially inspired by their work.

Page 70: Negations - University of TokyoContribution Development of type systems refuting derivability in some type systems such as • a basic type system for the 𝜆𝜆-calculus • a type

ConclusionNegation is a definable operation in the refinement intersection type system for the call-by-name 𝜆𝜆→.

This observation leads to the construction of negative type systems for other refinement type systems, e.g.,

• call-by-name 𝜆𝜆→ + recursion• the type system for HOMC• a type system for a call-by-value language

Application to verification needs some work.