Relatively Complete Refinement Type System for Verification of Higher-Order Non-deterministic Programs Hiroshi Unno (University of Tsukuba) Yuki Satake.

Slides:



Advertisements
Similar presentations
1 Verification by Model Checking. 2 Part 1 : Motivation.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Type-based termination analysis with disjunctive invariants Dimitrios Vytiniotis, MSR Cambridge with Byron Cook (MSR Cambridge) and Ranjit Jhala (UCSD)
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Partial Order Reduction: Main Idea
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Temporal Logic and the NuSMV Model Checker CS 680 Formal Methods Jeremy Johnson.
Game-theoretic approach to the simulation checking problem Peter Bulychev Vladimir Zakharov Lomonosov Moscow State University.
Hybrid Systems Presented by: Arnab De Anand S. An Intuitive Introduction to Hybrid Systems Discrete program with an analog environment. What does it mean?
Timed Automata.
Automating Relatively Complete Verification of Higher-Order Functional Programs Hiroshi Unno (University of Tsukuba) Tachio Terauchi (Nagoya University)
1 Temporal Claims A temporal claim is defined in Promela by the syntax: never { … body … } never is a keyword, like proctype. The body is the same as for.
A survey of techniques for precise program slicing Komondoor V. Raghavan Indian Institute of Science, Bangalore.
Review of topics Final exam : -May 2nd to May 7 th - Projects due on May 7th.
Relatively Complete Verification of Higher- Order Programs (via Automated Refinement Type Inference) Tachio Terauchi Nagoya University TexPoint fonts used.
An Integration of Program Analysis and Automated Theorem Proving Bill J. Ellis & Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt.
Towards a Logic for Wide-Area Internet Routing Nick Feamster and Hari Balakrishnan M.I.T. Computer Science and Artificial Intelligence Laboratory Kunal.
Lecture 4&5: Model Checking: A quick introduction Professor Aditya Ghose Director, Decision Systems Lab School of IT and Computer Science University of.
Inference and Resolution for Problem Solving
Transaction Ordering Verification using Trace Inclusion Refinement Mike Jones 11 January 2000.
A Type System for Expressive Security Policies David Walker Cornell University.
Review of the automata-theoretic approach to model-checking.
University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Timed UML State Machines Ognyana Hristova Tutor: Priv.-Doz. Dr. Thomas Noll June, 2007.
Using Abduction and Induction for Operational Requirements Elaboration Dalal Alrajeh Oliver Ray Alessandra RussoSebastian Uchitel AIAI 2007 Sept. 15 th.
Author: Graham Hughes, Tevfik Bultan Computer Science Department, University of California, Santa Barbara, CA 93106, USA Source: International Journal.
Refinement Type Inference via Horn Constraint Optimization Kodai Hashimoto and Hiroshi Unno (University of Tsukuba, Japan)
CS6133 Software Specification and Verification
On Reducing the Global State Graph for Verification of Distributed Computations Vijay K. Garg, Arindam Chakraborty Parallel and Distributed Systems Laboratory.
Model construction and verification for dynamic programming languages Radu Iosif
Analyzing relational logic Daniel Jackson, MIT WG 2.3 · Newcastle April 2000.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Recognizing safety and liveness Presented by Qian Huang.
Defining Liveness by Bowen Alpern and Fred B. Schneider Presented by Joe Melnyk.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
Verification & Validation By: Amir Masoud Gharehbaghi
lamsweerde Chap.4: Formal Requirements Specification © 2009 John Wiley and Sons Fundamentals of RE Chapter 4 Requirements.
Properties as Processes : FORTE slide Properties as Processes: their Specification and Verification Joel Kelso and George Milne School of Computer.
1 CSEP590 – Model Checking and Automated Verification Lecture outline for July 9, 2003.
Duminda WijesekeraSWSE 623: Introduction1 Introduction to Formal and Semi- formal Methods Based on A Specifier's Introduction to Formal Methods (J. Wing)
Model Checking Lecture 1. Model checking, narrowly interpreted: Decision procedures for checking if a given Kripke structure is a model for a given formula.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
Today’s Agenda  Quiz 4  Temporal Logic Formal Methods in Software Engineering1.
Model Checking Lecture 1: Specification Tom Henzinger.
6/12/20161 a.a.2015/2016 Prof. Anna Labella Formal Methods in software development.
CS5270 Lecture 41 Timed Automata I CS 5270 Lecture 4.
Complexity of Compositional Model Checking of Computation Tree Logic on Simple Structures Krishnendu Chatterjee Pallab Dasgupta P.P. Chakrabarti IWDC 2004,
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Introduction to Logic for Artificial Intelligence Lecture 2
Learning Invariants using Decision Trees and Implication Counterexamples Pranav Garg Amazon India.
Automating Induction for Solving Horn Clauses
MoCHi: Software Model Checker for a Higher-Order Functional Language
Stateful Manifest Contracts
Logical architecture refinement
Inferring Simple Solutions to Recursion-free Horn Clauses via Sampling
Lecture 5 Floyd-Hoare Style Verification
ITEC452 Distributed Computing Lecture 5 Program Correctness
Over-Approximating Boolean Programs with Unbounded Thread Creation
Automated Extraction of Inductive Invariants to Aid Model Checking
Formal Methods in software development
CS 583 Fall 2006 Analysis of Algorithms
Language-Independent Verification Framework
Predicates and Quantifiers
Automatic Abstraction of Microprocessors for Verification
Invertibility Conditions for Floating Point Formulas
Program Correctness an introduction.
Presentation transcript:

Relatively Complete Refinement Type System for Verification of Higher-Order Non-deterministic Programs Hiroshi Unno (University of Tsukuba) Yuki Satake (University of Tsukuba) Tachio Terauchi (Waseda University) POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Background Recent advances in (semi-)automated methods for verifying higher-order functional programs safety [Rondon+ ’08; U. & Kobayashi ’08,’09; Terauchi ’10; Ong & Ramsay ’11; Jhala+ ’11; Kobayashi+ ’11; U.+ ’13; …] termination [Sereni & Jones ’05; Giesl+ ’11; Kuwahara+ ’14; Vazou+ ’14] non-termination [Kuwahara+ ’15; Hashimoto & U. ’15] temporal properties [Koskinen & Terauchi ’14; Murase+ ’16] Different techniques are used to verify the different classes of properties, and are hard to combine in a unified framework dependent refinement types, predicate abstraction for higher-order model checking, program transformation for (binary) reachability analysis,… POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Our Contributions Novel dependent refinement type system that can: uniformly express and verify universal and existential branching properties of call-by-value, higher-order, and non-deterministic programs: (cond.) safety, non-safety, termination, and non-termination seamlessly combine universal and existential reasoning e.g., Prove non-safety via termination e.g., Prove non-termination via safety e.g., Prove termination and non-termination simultaneously Meta-theoretic properties of the type system: Closure of types under complement Soundness Relative completeness POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Our Contributions Novel dependent refinement type system that can: uniformly express and verify universal and existential branching properties of call-by-value, higher-order, and non-deterministic programs: (cond.) safety, non-safety, termination, and non-termination seamlessly combine universal and existential reasoning e.g., Prove non-safety via termination e.g., Prove non-termination via safety e.g., Prove termination and non-termination simultaneously Meta-theoretic properties of the type system: Closure of types under complement Soundness Relative completeness POPL'18, Los Angeles, United States

Dependent Refinement Types 𝝉 predicates on program values 𝒙 :𝐢𝐧𝐭 | 𝒙≥𝟎 Non-negative integers 𝒙 :𝐢𝐧𝐭 →{𝒓 :𝐢𝐧𝐭 | 𝒓≥𝒙} Functions that take an integer 𝒙 and (if terminated) return 𝒓 not less than 𝒙 A type system ensures that a type-checked expression behaves according to the type Only universal branching properties can be expressed POPL'18, Los Angeles, United States

Overview: Our Type System Extends dependent refinement types with: Qualified types 𝝉 𝑸 𝟏 𝑸 𝟐 to express universal/existential branching behaviors and partial/total correctness Qualified bindings 𝒙 : 𝑸 𝝉 to cope with non-determinism from program inputs Gödel encoding of function-type values & guarded intersection types to achieve relative completeness POPL'18, Los Angeles, United States

Overview: Our Type System Extends dependent refinement types with: Qualified types 𝝉 𝑸 𝟏 𝑸 𝟐 to express universal/existential branching behaviors and partial/total correctness Qualified bindings 𝒙 : 𝑸 𝝉 to cope with non-determinism from program inputs Gödel encoding of function-type values & guarded intersection types to achieve relative completeness POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Qualified Types 𝝉 𝑸 𝟏 𝑸 𝟐 𝑸 𝟏 ∈ ∀,∃ (universal/existential non-det.) specifies whether the expression being typed behaves according to the type: for any non-det. evaluation ( 𝑸 𝟏 =∀), or for some non-det. evaluation ( 𝑸 𝟏 =∃) 𝑸 𝟐 ∈ ∀,∃ (partial/total correctness) specifies whether: 𝝉 holds for all value obtained ( 𝑸 𝟐 =∀), or there exists a final value for which 𝝉 holds ( 𝑸 𝟐 =∃) POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Qualified Types 𝝉 𝑸 𝟏 𝑸 𝟐 𝑸 𝟏 ∈ ∀,∃ (universal/existential non-det.) specifies whether the expression being typed behaves according to the type: for any non-det. evaluation ( 𝑸 𝟏 =∀), or for some non-det. evaluation ( 𝑸 𝟏 =∃) 𝑸 𝟐 ∈ ∀,∃ (partial/total correctness) specifies whether: the evaluation diverges or 𝝉 is satisfied ( 𝑸 𝟐 =∀), or the evaluation terminates and 𝝉 is satisfied ( 𝑸 𝟐 =∃) POPL'18, Los Angeles, United States

Examples: Qualified Types 𝝉 𝑸 𝟏 𝑸 𝟐 ⊢𝒆 : 𝒖 :𝐢𝐧𝐭∣𝒖>𝟎 ∀∀ for any non-deterministic evaluation of 𝒆, if any integer 𝒖 is obtained, then 𝒖 is positive ⊢𝒆 : 𝒖 :𝐢𝐧𝐭∣𝒖>𝟎 ∃∃ for some non-deterministic evaluation of 𝒆, some integer 𝒖 is obtained, and 𝒖 is positive POPL'18, Los Angeles, United States

Typing Integer Constants Rule: 𝚫⊢𝒏 : 𝒙 :𝐢𝐧𝐭∣𝒙=𝒏 ∀∃ Type environment Universal and Total POPL'18, Los Angeles, United States

Converting Qualified Types Subtyping Rule: 𝚫⊢ 𝝉 𝟏 < : 𝝉 𝟐 𝑸 𝟏 𝑸 𝟏 ′ ⊑ 𝑸 𝟐 𝑸 𝟐 ′ 𝚫⊢ 𝝉 𝟏 𝑸 𝟏 𝑸 𝟏 ′ < : 𝝉 𝟐 𝑸 𝟐 𝑸 𝟐 ′ Universal and Partial ∀∃ ∀∀ ∃∃ ∃∀ ⊑ Universal and Total Existential and Partial Existential and Total POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Typing Let-Bindings Rule: 𝚫⊢ 𝒆 𝟏 : 𝝉 𝟏 𝑸 𝟏 𝑸 𝟐 𝚫,𝒙 : 𝝉 𝟏 ⊢ 𝒆 𝟐 : 𝝉 𝟐 𝑸 𝟏 𝑸 𝟐 𝒙∉𝒇𝒗𝒔 𝝉 𝟐 𝚫⊢𝐥𝐞𝐭 𝒙= 𝒆 𝟏 𝐢𝐧 𝒆 𝟐 : 𝝉 𝟐 𝑸 𝟏 𝑸 𝟐 POPL'18, Los Angeles, United States

Typing Recursive Functions for Partial Correctness Rule: 𝚫,𝒙 : 𝝉 𝟏 ,𝒇 : 𝒙 : 𝝉 𝟏 → 𝝉 𝟐 𝑸∀ ⊢𝒆 : 𝝉 𝟐 𝑸∀ 𝚫⊢𝐫𝐞𝐜 𝒇,𝒙,𝒆 : 𝒙 : 𝝉 𝟏 → 𝝉 𝟐 𝑸∀ (recursive) function 𝐥𝐞𝐭 𝐫𝐞𝐜 𝒇 𝒙=𝒆 POPL'18, Los Angeles, United States

Typing Recursive Functions for Total Correctness (cf. [Xi ’01]) Well-founded relation witnessing the termination of 𝒇, as a recursion guard Rule: 𝝉 𝒓𝒆𝒄 = 𝒙 ′ : 𝝉 𝟏 ′ → 𝝓⊳ 𝝉 𝟐 ′ 𝑸∃ = 𝜶 𝒙 : 𝝉 𝟏 → 𝝉 𝟐 𝑸∃ 𝚫⊨𝑾𝑭 𝝀 𝒙, 𝒙 ′ .𝝓 𝚫,𝒙 : 𝝉 𝟏 ,𝒇 : 𝝉 𝒓𝒆𝒄 ⊢𝒆 : 𝝉 𝟐 𝑸∃ 𝚫⊢𝐫𝐞𝐜 𝒇,𝒙,𝒆 : 𝒙 : 𝝉 𝟏 → 𝝉 𝟐 𝑸∃ 𝒙′ : 𝒙′∣𝒙′≥𝟎 → 𝒙> 𝒙 ′ ≥𝟎⊳ 𝒚′∣𝒚′≥𝒙′ ∀∃ Example: 𝒙 : 𝒙∣𝒙≥𝟎 ,𝒔𝒖𝒎 : 𝝉 𝒓𝒆𝒄 ⊢𝐢𝐟 𝒙=𝟎 𝐭𝐡𝐞𝐧 𝟎 𝐞𝐥𝐬𝐞… : 𝐢𝐧𝐭 ∀∃ ⊨𝑾𝑭 𝝀 𝒙, 𝒙 ′ .𝒙> 𝒙 ′ ≥𝟎 ⊢𝐫𝐞𝐜 𝒔𝒖𝒎,𝒙,𝐢𝐟 𝒙=𝟎 𝐭𝐡𝐞𝐧 𝟎 𝐞𝐥𝐬𝐞 𝒙+𝒔𝒖𝒎 𝒙−𝟏 :𝝉 𝒙 : 𝒙∣𝒙≥𝟎 → 𝐢𝐧𝐭 ∀∃ POPL'18, Los Angeles, United States

Overview: Our Type System Extends dependent refinement types with: Qualified types 𝝉 𝑸 𝟏 𝑸 𝟐 to express universal/existential branching behaviors and partial/total correctness Qualified bindings 𝒙 : 𝑸 𝝉 to cope with non-determinism from program inputs Gödel encoding of function-type values & guarded intersection types to achieve relative completeness POPL'18, Los Angeles, United States

Qualified Bindings 𝒙 : 𝑸 𝝉 Occur in type environments and the argument of dependent function types 𝑸∈ ∀,∃ specifies whether a certain fact must hold for: any input 𝒙 that satisfies 𝝉 (𝑸=∀), or some input 𝒙 that satisfies 𝝉 (𝑸=∃) POPL'18, Los Angeles, United States

Examples: Qualified Bindings 𝒙 : 𝑸 𝝉 𝒙 : ∀ 𝐢𝐧𝐭 → 𝒖 :𝐢𝐧𝐭∣𝒖>𝒙 ∀∃ functions that, for any integer 𝒙 and for any run with the argument 𝒙, return some integer 𝒖, which is greater than 𝒙 𝒙 : ∃ 𝐢𝐧𝐭 → 𝒖 :𝐢𝐧𝐭∣𝒖>𝒙 ∀∃ functions that, there exists an integer 𝒙, for any run with the argument 𝒙, return some integer 𝒖, which is greater than 𝒙 POPL'18, Los Angeles, United States

Skolemizing Existential Bindings Skolemization Predicate Rule: 𝚫, 𝒙 : ∃ 𝝉⊨𝝓 𝚫,𝒙 : ∀ 𝝉,𝝓,𝚪⊢𝒆 :𝝈 𝚫, 𝒙 : ∃ 𝝉,𝚪⊢𝒆 :𝝈 Type environment consisting of only ∀-bindings Type environment consisting of both ∀- and ∃-bindings Example: 𝒙 : ∀ 𝐢𝐧𝐭,𝒚 : ∃ 𝐢𝐧𝐭⊨𝒚=−𝒙 𝒙 : ∀ 𝐢𝐧𝐭,𝒚 : ∀ 𝐢𝐧𝐭,𝒚=−𝒙⊢𝒙+𝒚 : 𝒛∣𝒛=𝟎 ∀∃ 𝒙 : ∀ 𝐢𝐧𝐭,𝒚 : ∃ 𝐢𝐧𝐭⊢𝒙+𝒚 : 𝒛∣𝒛=𝟎 ∀∃ POPL'18, Los Angeles, United States

Typing Non-deterministic Choice Rule: 𝚫,𝒙 : 𝑸 𝟏 𝐢𝐧𝐭⊢𝒆 : 𝝉 𝑸 𝟏 𝑸 𝟐 𝒙∉𝒇𝒗𝒔 𝝉 𝚫⊢𝐥𝐞𝐭 𝒙= ∗ 𝐢𝐧 𝒆 : 𝝉 𝑸 𝟏 𝑸 𝟐 Example: 𝒙 : ∀ 𝐢𝐧𝐭,𝒚 : ∃ 𝐢𝐧𝐭⊢𝒙+𝒚 : 𝒛∣𝒛=𝟎 ∃∃ 𝒙 : ∀ 𝐢𝐧𝐭⊢𝐥𝐞𝐭 𝒚= ∗ 𝐢𝐧 𝒙+𝒚 : 𝒛∣𝒛=𝟎 ∃∃ POPL'18, Los Angeles, United States

Typing Function Applications (Universal Bindings) Rule: 𝚫⊢ 𝒗 𝟏 : 𝒙 : ∀ 𝝉 →𝝈 𝚫⊢ 𝒗 𝟐 :𝝉 𝚫⊢ 𝒗 𝟏 𝒗 𝟐 :[ 𝒗 𝟐 /𝒙]𝝈 POPL'18, Los Angeles, United States

Typing Function Applications (Existential Bindings) Observational equivalence Rule: 𝚫⊢ 𝒗 𝟏 : 𝒙 : ∃ 𝝉 →𝝈 𝚫,𝒙 : ∀ 𝝉,𝚪⊨𝒙∼ 𝒗 𝟐 𝚫,𝚪⊢ 𝒗 𝟏 𝒗 𝟐 :[ 𝒗 𝟐 /𝒙]𝝈 Example: 𝒇 : ∀ 𝝉⊢𝒇 :𝝉 𝒇 : ∀ 𝝉,𝒙 : ∀ 𝐢𝐧𝐭,𝒚 : ∃ 𝐢𝐧𝐭⊨𝒙=𝒚 𝒇 : ∀ 𝝉,𝒚 : ∃ 𝐢𝐧𝐭⊢𝒇 𝒚 : 𝒛 ⊥ ∃∀ 𝒇 : ∀ 𝝉⊢𝐥𝐞𝐭 𝒚= ∗ 𝐢𝐧 𝒇 𝒚 : 𝒛 ⊥ ∃∀ 𝒙 : ∃ 𝐢𝐧𝐭 → 𝒛 ⊥ ∃∀ POPL'18, Los Angeles, United States

Converting Function Types (1/4) Subtyping Rule: 𝚫⊢ 𝝉 𝟐 < : 𝝉 𝟏 𝚫,𝒙 : ∀ 𝝉 𝟐 ⊢ 𝝈 𝟏 < : 𝝈 𝟐 𝚫⊢ 𝒙 : ∀ 𝝉 𝟏 → 𝝈 𝟏 < : 𝒙 : ∀ 𝝉 𝟐 → 𝝈 𝟐 Example: ⊢ 𝒙 : ∀ 𝐢𝐧𝐭 → 𝒚∣𝒚=𝒙 ∀∃ < : 𝒙 : ∀ 𝒙∣𝒙≥𝟎 → 𝒚∣𝒚≥𝟎 ∀∃ POPL'18, Los Angeles, United States

Converting Function Types (2/4) Subtyping Rule: 𝚫⊢ 𝝉 𝟏 < : 𝝉 𝟐 𝚫,𝒙 : ∀ 𝝉 𝟏 ⊢ 𝝈 𝟏 < : 𝝈 𝟐 𝚫⊢ 𝒙 : ∃ 𝝉 𝟏 → 𝝈 𝟏 < : 𝒙 : ∃ 𝝉 𝟐 → 𝝈 𝟐 Example: ⊢ 𝒙 : ∃ 𝒙∣𝒙≥𝟎 → 𝒚∣𝒚=𝒙 ∀∃ < : 𝒙 : ∃ 𝐢𝐧𝐭 → 𝒚∣𝒚≥𝟎 ∀∃ POPL'18, Los Angeles, United States

Converting Function Types (3/4) Subtyping Rule: 𝚫⊢𝝉< : 𝝉 𝟏 𝚫⊢𝝉< : 𝝉 𝟐 𝚫,𝒙 : ∃ 𝝉⊢ 𝝈 𝟏 < : 𝝈 𝟐 𝚫⊢ 𝒙 : ∀ 𝝉 𝟏 → 𝝈 𝟏 < : 𝒙 : ∃ 𝝉 𝟐 → 𝝈 𝟐 Example: ⊢ 𝒙∣𝒙≥𝟎 < :𝐢𝐧𝐭 ⊢ 𝒙∣𝒙≥𝟎 < :𝐢𝐧𝐭 𝒙 : ∃ 𝒙∣𝒙≥𝟎 ⊢ 𝒚∣𝒚=𝒙 ∀∃ < : 𝒚∣𝒚=𝟎 ∀∃ ⊢ 𝒙 : ∀ 𝐢𝐧𝐭 → 𝒚∣𝒚=𝒙 ∀∃ < : 𝒙 : ∃ 𝐢𝐧𝐭 → 𝒚∣𝒚=𝟎 ∀∃ POPL'18, Los Angeles, United States

Converting Function Types (4/4) Subtyping Rule: 𝚫,𝒙 : ∀ 𝝉 𝟏 ∧ 𝝉 𝟐 ,𝒚 : ∀ 𝝉 𝟏 ∧ 𝝉 𝟐 ⊨𝒙∼𝒚 𝚫,𝒙 : ∀ 𝝉 𝟏 ∧ 𝝉 𝟐 ⊢ 𝝈 𝟏 < : 𝝈 𝟐 𝚫,𝒙 : ∀ 𝝉 𝟏 ∖ 𝝉 𝟐 ⊢ 𝝈 𝟏 < : ⊥ 𝚫,𝒙 : ∀ 𝝉 𝟐 ∖ 𝝉 𝟏 ⊢⊤< : 𝝈 𝟐 𝚫⊢ 𝒙 : ∃ 𝝉 𝟏 → 𝝈 𝟏 < : 𝒙 : ∀ 𝝉 𝟐 → 𝝈 𝟐 Observational equivalence Example: ⊢ 𝒙 : ∃ 𝒙∣𝒙=𝟎 → 𝒚∣𝒚=𝟎 ∀∃ < : 𝒙 : ∀ 𝒙∣𝒙=𝟎 → 𝒚∣𝒚=𝒙 ∀∃ POPL'18, Los Angeles, United States

Overview: Our Type System Extends dependent refinement types with: Qualified types 𝝉 𝑸 𝟏 𝑸 𝟐 to express universal/existential branching behaviors and partial/total correctness Qualified bindings 𝒙 : 𝑸 𝝉 to cope with non-determinism from program inputs Gödel encoding of function-type values & guarded intersection types to achieve relative completeness POPL'18, Los Angeles, United States

Gödel Encoding of Function-Type Values Enables predicates of the underlying logic 𝑻 (e.g., second-order arithmetic) to depend on function-type arguments encoded as 𝑻-objects 𝒇 : ∀ 𝐢𝐧𝐭→ 𝐢𝐧𝐭 ∀∃ → 𝒈 : ∀ 𝐢𝐧𝐭→ 𝐢𝐧𝐭 ∀∃ → 𝒖∣𝒇∼𝒈 ∀∀ Functions that, given two terminating functions 𝒇 and 𝒈, always diverge if 𝒇 is not observationally equivalent to 𝒈 POPL'18, Los Angeles, United States

Guarded Intersection Types 𝒊 𝝓 𝒊 ⊳ 𝝉 𝒊 𝑸 𝒊 𝑸 𝒊 ′ Collectively express different behaviors of functions depending on the arguments 𝒙 : ∀ 𝐢𝐧𝐭 → 𝒙>𝟎⊳ 𝐢𝐧𝐭 ∀∃ ∧ 𝒙<𝟎⊳ 𝒚 ⊥ ∀∀ ∧ 𝒙=𝟎⊳ 𝐢𝐧𝐭 ∃∃ ∧ 𝒙=𝟎⊳ 𝒚 ⊥ ∃∀ Functions that, given the argument 𝒙 : always terminate if 𝒙>𝟎, always diverge if 𝒙<𝟎, and otherwise, non-deterministically terminate or diverge POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Our Contributions Novel dependent refinement type system that can: uniformly express and verify universal and existential branching properties of call-by-value, higher-order, and non-deterministic programs: (cond.) safety, non-safety, termination, and non-termination seamlessly combine universal and existential reasoning e.g., Prove non-safety via termination e.g., Prove non-termination via safety e.g., Prove termination and non-termination simultaneously Meta-theoretic properties of the type system: Closure of types under complement Soundness Relative completeness POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Complement Types ¬𝝈 Thanks to having both modes of non- determinism, the type complement operator ¬ can be defined: ¬ 𝝉 𝑸 𝟏 𝑸 𝟐 ≜ ¬𝝉 ¬ 𝑸 𝟏 ¬ 𝑸 𝟐 POPL'18, Los Angeles, United States

Example: Complement Types ¬𝝈 𝝈≜ 𝒙 : ∀ 𝐢𝐧𝐭 → 𝒖 :𝐢𝐧𝐭∣𝒖=𝒙 ∀∀ functions that, for any integer 𝒙 and for any run with the argument 𝒙, diverge or return an integer 𝒖=𝒙 ¬𝝈= 𝒙 : ∃ 𝐢𝐧𝐭 → 𝒖 :𝐢𝐧𝐭∣𝒖≠𝒙 ∃∃ functions that, for some integer 𝒙 and for some run with the argument 𝒙, terminate and return an integer 𝒖≠𝒙 POPL'18, Los Angeles, United States

Example: Combined Reasoning (Non-safety via Termination) Goal: prove that 𝐥𝐞𝐭 𝐫𝐞𝐜 𝒇 𝒙 𝒚= 𝐢𝐟 𝒙=𝒚 𝐭𝐡𝐞𝐧 𝟎 𝐞𝐥𝐬𝐞 𝒇 𝒙−𝟏 𝒚 𝐥𝐞𝐭 𝒓=𝒇 𝟏𝟎 𝟗 𝟎 𝐢𝐧 𝐥𝐞𝐭 𝒛= ∗𝐢𝐧 𝒛+𝒓 violates 𝒖 ∣𝒖=𝟎 ∀∀ POPL'18, Los Angeles, United States

Example: Combined Reasoning (Non-safety via Termination) Goal: prove that 𝐥𝐞𝐭 𝐫𝐞𝐜 𝒇 𝒙 𝒚= 𝐢𝐟 𝒙=𝒚 𝐭𝐡𝐞𝐧 𝟎 𝐞𝐥𝐬𝐞 𝒇 𝒙−𝟏 𝒚 𝐥𝐞𝐭 𝒓=𝒇 𝟏𝟎 𝟗 𝟎 𝐢𝐧 𝐥𝐞𝐭 𝒛= ∗𝐢𝐧 𝒛+𝒓 satisfies ¬ 𝒖 ∣𝒖=𝟎 ∀∀ POPL'18, Los Angeles, United States

Example: Combined Reasoning (Non-safety via Termination) Goal: prove that 𝐥𝐞𝐭 𝐫𝐞𝐜 𝒇 𝒙 𝒚= 𝐢𝐟 𝒙=𝒚 𝐭𝐡𝐞𝐧 𝟎 𝐞𝐥𝐬𝐞 𝒇 𝒙−𝟏 𝒚 𝐥𝐞𝐭 𝒓=𝒇 𝟏𝟎 𝟗 𝟎 𝐢𝐧 𝐥𝐞𝐭 𝒛= ∗𝐢𝐧 𝒛+𝒓 satisfies 𝒖 ∣𝒖≠𝟎 ∃∃ Show that 𝒇 is conditionally terminating: The well-founded relation 𝝀 𝒙,𝒚 , 𝒙 ′ ,𝒚′ . 𝒙> 𝒙 ′ ∧𝒚= 𝒚 ′ ∧𝒙≥𝒚 witnesses that 𝒇 has the type: 𝒙 :𝐢𝐧𝐭 → 𝒚 : 𝒚∣𝒚≤𝒙 → 𝐢𝐧𝐭 ∀∃ Show that the actual call 𝒇 𝟏𝟎 𝟗 𝟎 always terminates by checking ⊨𝟎≤𝟏 𝟎 𝟗 Show that, for any integer 𝒓, we can choose an integer 𝒛 such that 𝒛+𝒓≠𝟎 Q.E.D. POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Our Contributions Novel dependent refinement type system that can: uniformly express and verify universal and existential branching properties of call-by-value, higher-order, and non-deterministic programs: (cond.) safety, non-safety, termination, and non-termination seamlessly combine universal and existential reasoning e.g., Prove non-safety via termination e.g., Prove non-termination via safety e.g., Prove termination and non-termination simultaneously Meta-theoretic properties of the type system: Closure of types under complement Soundness Relative completeness POPL'18, Los Angeles, United States

Closure of Types under Complement For any type 𝝈 refining a simple type 𝑺, 𝝈 ∩ ¬𝝈 =∅ and 𝝈 ∪ ¬𝝈 = 𝑺 where 𝝈 : the set of expressions that behave according to 𝝈 𝑺 : the set of expressions of the type 𝑺 POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Soundness 𝚪⊢𝒆 :𝝈 implies 𝒆∈ 𝚪⊢𝝈 the set of expressions that behave according to 𝝈 under any valuation conforming to 𝚪 POPL'18, Los Angeles, United States

Relative Completeness 𝑒∈ Γ⊢𝜎 implies Γ⊢𝑒 :𝜎 under the assumption that the underlying logic is sufficiently expressible to Gödel encode arbitrary functions definable in the target programming language to represent well-founded relations witnessing the termination of the definable functions POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Summary Novel dependent refinement type system that can: uniformly express and verify universal and existential branching properties of call-by-value, higher-order, and non-deterministic programs: (cond.) safety, non-safety, termination, and non-termination seamlessly combine universal and existential reasoning e.g., Prove non-safety via termination e.g., Prove non-termination via safety e.g., Prove termination and non-termination simultaneously Meta-theoretic properties of the type system: Closure of types under complement Soundness Relative completeness POPL'18, Los Angeles, United States

POPL'18, Los Angeles, United States Future Work Extensions with temporal specifications: Temporal trace specs. (e.g., LTL) Branching temporal specs. (e.g., CTL, modal-𝜇) Extensions with language features: Recursive data structures Linked data structures Call-by-name evaluation Probabilistic choice Automation of type checking and inference POPL'18, Los Angeles, United States

Towards Automation (Ongoing) Type Checking How to leverage off-the-shelf SMT solvers? Abstraction and counterexample guided refinement for the encoding of function-type values Type Inference How to synthesize inductive invariants, well-founded relations, and Skolemization predicates? Reduction to existentially-quantified Horn clause and well-foundedness constraints How to achieve scalable inference? Combination of universal and existential reasoning POPL'18, Los Angeles, United States