four last forms can be transformed to first form axiomatic versus operational interpretation c Anne E. Haxthausen, Spring OH4 p.

Similar documents
Translation of a Subset of RSL into Java p.1/35

RSL Reference Manual

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

More Untyped Lambda Calculus & Simply Typed Lambda Calculus

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

Formal Systems and their Applications

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

CVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions

Principles of Programming Languages 2017W, Functional Programming

Programming Languages

Concepts of programming languages

CMSC 330: Organization of Programming Languages. Operational Semantics

The Design Recipe Fall 2017

Quick announcement. Midterm date is Wednesday Oct 24, 11-12pm.

Introduction to the Lambda Calculus. Chris Lomont

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators

The Substitution Model

Lecture 2. The SCADE Language Data Flow Kernel. Daniel Kästner AbsInt GmbH 2012

The Substitution Model. Nate Foster Spring 2018

Typed Lambda Calculus. Chapter 9 Benjamin Pierce Types and Programming Languages

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

COS 320. Compiling Techniques

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference

02157 Functional Programming Lecture 2: Functions, Basic Types and Tuples

PROGRAMMING IN HASKELL. Chapter 2 - First Steps

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

Functional Programming. Pure Functional Programming

IFAD. VDMTools Validated. Design through Modelling. Overview of VDM -SL/++ IFAD. IFAD A/S Forskerparken 10 DK-5230 Odense M Denmark.

Lecture #23: Conversion and Type Inference

Last class. CS Principles of Programming Languages. Introduction. Outline

The design of a programming language for provably correct programs: success and failure

COMP520 - GoLite Type Checking Specification

Type Checking and Type Inference

Organization of Programming Languages CS3200/5200N. Lecture 11

CMSC 330: Organization of Programming Languages. OCaml Higher Order Functions

The Design Recipe Fall 2018

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Z Notation. June 21, 2018

CMSC 330: Organization of Programming Languages

Higher-Order Logic. Specification and Verification with Higher-Order Logic

Dynamic Types, Concurrency, Type and effect system Section and Practice Problems Apr 24 27, 2018

Parsing. Zhenjiang Hu. May 31, June 7, June 14, All Right Reserved. National Institute of Informatics

CS4215 Programming Language Implementation

Built-in Module BOOL. Lecture Note 01a

CS 242. Fundamentals. Reading: See last slide

Lambda Calculus. Concepts in Programming Languages Recitation 6:

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Lecture 4. First order logic is a formal notation for mathematics which involves:

Formal Semantics. Prof. Clarkson Fall Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack

Haskell 98 in short! CPSC 449 Principles of Programming Languages

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

Functional Programming

Haskell Overview II (2A) Young Won Lim 8/9/16

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

Handout 2 August 25, 2008

Lambda Calculus. Variables and Functions. cs3723 1

Introductory Example

Programming Languages Third Edition

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

Lecture 15 CIS 341: COMPILERS

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions

(a) in assignment statements. (b) when invoking methods (with objects as parameters) (d) equality of references versus equality of objects

An introduction to Scheme

CSE-321 Programming Languages 2010 Final

COMP520 - GoLite Type Checking Specification

MIDTERM EXAMINATION - CS130 - Spring 2005

The Calculator CS571. Abstract syntax of correct button push sequences. The Button Layout. Notes 16 Denotational Semantics of a Simple Calculator

Typed Lambda Calculus and Exception Handling

Higher Order Functions in Haskell

(Refer Slide Time: 4:00)

CafeOBJ. CafeOBJ. Starting CafeOBJ. Wolfgang Schreiner 1. A Quick Overview. 2.

COMP520 - GoLite Type Checking Specification

Functional Programming. Pure Functional Languages

Introduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson

Begin at the beginning

15-819M: Data, Code, Decisions

Principles of Programming Languages

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS

Programming Languages

Semantics of programming languages

Functional Programming

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

Lambda Calculus and Type Inference

3.7 Denotational Semantics

A Brief Introduction to Scheme (II)

Mathematics for Computer Scientists 2 (G52MC2)

Shell CSCE 314 TAMU. Haskell Functions

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007

Functional Programming. Functional Programming

C++ Program Flow Control: Selection

1 Lexical Considerations

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Functional Programming in Haskell Part I : Basics

The List Datatype. CSc 372. Comparative Programming Languages. 6 : Haskell Lists. Department of Computer Science University of Arizona

Functions & First Class Function Values

Transcription:

Course 02263 Formal Aspects of Software Engineering RSL Value Definitions & Functions Anne E. Haxthausen DTU Informatics (IMM) Technical University of Denmark aeha@dtu.dk c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 1/24 Contents Part 1: Value Definitions 3 Part 2: Functions 16 c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 2/24 Contents of Part 1: Value Definitions different forms: axiomatic: using signatures (i.e. typings) and axioms explicit definition of constants implicit definition of constants explicit definition of functions implicit definition of functions under specification four last forms can be transformed to first form axiomatic versus operational interpretation c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 3/24 Definition of constants Examples explicit = 1 implicit x > 0 axiomatic axiom x > 0 c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 4/24

Definition of functions Examples explicit f(x) x + 1 implicit f(x) as r post r > x axiomatic axiom x : Int f(x) > x c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 5/24 Underspecification axiom x > 0 x is underspecified, may be refined to: = 1 or or... = 2 c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 6/24 Expansion of Explicit Value Definition = 1 axiom x 1 binding : type_expr = _expr binding : type_expr axiom binding _expr c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 7/24 Expansion of Implicit Value Definitions x > 0 axiom x > 0 binding : type_expr _expr binding : type_expr axiom _expr c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 8/24

Expansion of Explicit Function Definitions f(x) x + 1 axiom x : Int f(x) x + 1 id : type_expr1 type_expr2 id(x) _expr id : type_expr1 type_expr2 axiom x : type_expr1 id(x) _expr c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 9/24 Expansion of Implicit Function Definitions f(x) as r post r > x axiom x : Int f(x) as r post r > x id : type_expr1 type_expr2 id(x) as y post _expr id : type_expr1 type_expr2 axiom x : type_expr1 id(x) as y post _expr c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 10/24 Example of Expansion scheme SET_DATABASE = class type Database = Person-set, Person = Text end empty : Database = {}, register : Person Database Database register(p,db) db {p}, check : Person Database Bool check(p,db) p db scheme SET_DATABASE = class type Database = Person-set, Person = Text empty : Database, register : Person Database Database, check : Person Database Bool axiom empty {}, p : Person, db : Database register(p, db) db {p}, p : Person, db : Database check(p, db) p db end c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 11/24 Axiomatic versus Operational Interpretation Two different ways to of interpreting function definitions in languages: operational (as in programming languages) axiomatic (as in some specification languages, e.g. RSL) c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 12/24

Operational versus Axiomatic Interpretation (I) f: Int Int f(i) i+1 Operational interpretation: f(5) is computed by 1. substituting 5 for i in the body: i+1 2. evaluating the resulting expression: 5+1 to get 6 Axiomatic interpretation: The function is described by two properties: 1. its type: it must map integer arguments to integer results 2. an equivalence: f(i) must be semantically i+1 for all integers i c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 13/24 RSL has axiomatic interpretation f: Int Int f(i) i+1 is just a short form of: f: Int Int axiom i:int f(i) i+1 c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 14/24 Operational versus Axiomatic Interpretation (II) f: Int Int f(i) f(i) Axiomatic interpretation: all partial functions from Int to Int. Operational interpretation: only the infinite loop ( corresponding to chaos) c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 15/24 Contents of Part 2: functions functions are s 17 function type expressions 18 function expressions 20 function application expressions 22 operators 23 higher order functions 24 c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 16/24

Functions are s Functions are first class s! Hence, RSL allows: higher-order functions that take functions as argument and/or return functions. quantification over function types c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 17/24 Function Type Expressions type_expr1 type_expr2 denotes the type consisting of all total functions from type_expr1 to type_expr2. type_expr1 type_expr 2 denotes the type consisting of all partial functions from type_expr1 to type_expr2. ftot : T1 T2, fpar : T1 T 2, x : T1 defined deterministic (not chaos) ftot(x) yes yes fpar(x) might be might be ftot(x) is deterministic means:! y : T2 ftot(x) y c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 18/24 Function Type Expressions, Examples Bool Bool denote the type consisting of the following total functions: λ b : Bool true λ b : Bool false λ b : Bool b λ b : Bool b Bool Bool denote the type consisting of the following partial functions: λ b : Bool true λ b : Bool false λ b : Bool b λ b : Bool b λ b : Bool chaos λ b : Bool true false... c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 19/24 Function Value Expressions names of user-defined function, e.g.: distance lambda abstractions (anonymous functions), e.g.: λ b:bool b c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 20/24

Lambda Abstraction Basic form: λ binding : type_expr _expr Examples: λ b : Bool b λ (x,y) : Int Int x + y λ (b,(x,y)) : Bool (Nat Nat) if b then x else y end Semantics: represents function of type: type_expr T, where T = type_of(_expr) Derived form: λ (typing1,...,typingn) _expr, n 0 Examples: λ (x : Int, y : Int) x + y, λ (b : Bool, x,y : Nat) if b then x else y end c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 21/24 Function Application Expressions Examples: distance((1.0,2.3), (5.13, 5.13)) (λ(x,y) : Nat Nat x = y)(2,7) Typical form: function-expr(expr1,..., exprn), n 0 Context conditions: (expr1,..., exprn) must be of the argument type of expr c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 22/24 Associated Built-in Operators =, =, : (T 2 T 3) (T1 T 2) (T1 T 3) f g λ x : T1 f(g(x)) c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 23/24 Higher Order Functions: Example 3 ways of defining twice: twice : (Int Int) Int Int twice(f) f f twice : (Int Int) Int Int twice(f) λ i : Int f(f(i)) twice : (Int Int) Int Int twice(f)(i) f(f(i)) Applications of twice: twice(λ i : Int i + 1) λ i : Int i + 2 twice(λ i : Int i + 1)(1) 3 c Anne E. Haxthausen, Spring 2014 02263 OH4 p. 24/24