Algebraic specification and verification with CafeOBJ Part 1 Introduction

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

Computing Fundamentals 2 Introduction to CafeOBJ

BOBJ: A Quickstart for Software Engineers

Built-in Module BOOL. Lecture Note 01a

Program analysis parameterized by the semantics in Maude

type classes & locales

CS422 - Programming Language Design

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

CSE 3302 Programming Languages Lecture 8: Functional Programming

Data Types The ML Type System

CS 320: Concepts of Programming Languages

Control Flow February 9, Lecture 7

3.1 IMP: A Simple Imperative Language

Contents. Chapter 1 SPECIFYING SYNTAX 1

CSc 372 Comparative Programming Languages. 4 : Haskell Basics

Functional Programming and Haskell

CSCC24 Functional Programming Scheme Part 2

CS 11 Haskell track: lecture 1

ELAN. A rule-based programming language. Hélène Kirchner and Pierre-Etienne Moreau LORIA CNRS INRIA Nancy, France

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

The Maude 2.0 System. M. Clavel F. Durán S. Eker P. Lincoln. N. Martí-Oliet J. Meseguer C. Talcott

CSc 372. Comparative Programming Languages. 4 : Haskell Basics. Department of Computer Science University of Arizona

Specification, Verification, and Interactive Proof

Logical Methods in... using Haskell Getting Started

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

Functional Programming and Modeling

Data types for mcrl2

Programming Languages Fall 2013

Static Contract Checking for Haskell

3.7 Denotational Semantics

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

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

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Design

Programming Language Pragmatics

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

Pierce Ch. 3, 8, 11, 15. Type Systems

Functional Programming

Overloading, Type Classes, and Algebraic Datatypes

Introduction to Co-Induction in Coq

CS 320: Concepts of Programming Languages

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)

Logic - CM0845 Introduction to Haskell

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

LECTURE 16. Functional Programming

ACL2 Challenge Problem: Formalizing BitCryptol April 20th, John Matthews Galois Connections

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections p.

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Introduction to Functional Programming in Haskell 1 / 56

Programming in Omega Part 1. Tim Sheard Portland State University

Inductive datatypes in HOL. lessons learned in Formal-Logic Engineering

Theorem Proving Principles, Techniques, Applications Recursion

CPS 506 Comparative Programming Languages. Programming Language Paradigm

Application: Programming Language Semantics

CSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixed-points. Typed Lambda Calculi. Least Fixed Point

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Programming Languages Lecture 14: Sum, Product, Recursive Types

A CONSTRUCTIVE SEMANTICS FOR REWRITING LOGIC MICHAEL N. KAPLAN

Recursion. Tjark Weber. Functional Programming 1. Based on notes by Sven-Olof Nyström. Tjark Weber (UU) Recursion 1 / 37

Types and Type Inference

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Recursion. Lars-Henrik Eriksson. Functional Programming 1. Based on a presentation by Tjark Weber and notes by Sven-Olof Nyström

Functional Programming Languages (FPL)

A general introduction to Functional Programming using Haskell

Programming with Math and Logic

HANDLING NONLOCAL REFERENCES

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Chapter 15. Functional Programming Languages

3.4 Denotational Semantics

Type Checking and Type Inference

Unification in Maude. Steven Eker

Dorel LUCANU. University Al.I.Cuza of Iaşi Department of Computer Science Berthelot Iaşi, Romania

ISR 2014 Strategies. Hélène KIRCHNER Inria. August Topics, Objectives, Contents. Hélène KIRCHNER Inria ISR 2014 Strategies 1 / 48

CSCE 314 Programming Languages

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Example Scheme Function: equal

CSc 520. Principles of Programming Languages 11: Haskell Basics

CSCI312 Principles of Programming Languages!

Embedding Cryptol in Higher Order Logic

Introduction to Objective Caml

Why OCaml? Introduction to Objective Caml. Features of OCaml. Applications written in OCaml. Stefan Wehr

Recursion and Induction

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

Maude Manual (Version 2.5) Manuel Clavel Francisco Durán Steven Eker Patrick Lincoln Narciso Martí-Oliet José Meseguer Carolyn Talcott

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

LECTURE 17. Expressions and Assignment

Haskell through HUGS THE BASICS

Chapter 15. Functional Programming. Topics. Currying. Currying: example. Currying: example. Reduction

Maude Implementation of MSR

modulo associativity, commutativity, and/or identity. With its module database and its ability to incorporate Lisp code, this provides a very exible a

Types and Type Inference

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

Bijective Term Encodings

Proving Theorems with Athena

INTRODUCTION TO HASKELL

Programming Languages Lecture 15: Recursive Types & Subtyping

11. Recursion. n (n 1)!, otherwise. Mathematical Recursion. Recursion in Java: Infinite Recursion. 1, if n 1. n! =

Denotational Semantics. Domain Theory

Transcription:

Algebraic specification and verification with CafeOBJ Part 1 Introduction Norbert Preining ESSLLI 2016 Bozen, August 2016 Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 1/44

Intro Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 2/44

Famous bugs Therac-25 x-ray machine: over-exposition error (5 dead, 1985 1987) Ariane 5 rocket, Flight 501 (overflow, 1996, $370 million!) Mars Climate Orbiter: (lbf vs. N, 1999) Intel Pentium F00F bug: planning error Toyota s Electronic Throttle Control System (ETCS): sudden break accidents (2009 2011) Heartbleed bug (OpenSSL, 2012-2014) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 3/44

How to deal with bugs? formal methods post-coding Analysis and verification of already developed program code pre-coding Analysis and verification of domains, models, specifications, requirements, design, etc. all before coding starts Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 4/44

Current status of formal methods post-coding model checking big success, but limitations due to infinite to finite state transformation Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 5/44

Current status of formal methods post-coding model checking big success, but limitations due to infinite to finite state transformation pre-coding interactive theorem provers acceptance of software engineers/developers? Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 5/44

Our Approach reasonable blend of user and machine capabilities allow intuitive modelling while preserving a rigorous formal background various levels of modelling from high-level to hard-core not fully automated understanding of design and problems necessary Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 6/44

Our Approach reasonable blend of user and machine capabilities allow intuitive modelling while preserving a rigorous formal background various levels of modelling from high-level to hard-core not fully automated understanding of design and problems necessary CafeOBJ and proof scores Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 6/44

Selling Points rigid formal background order-sorted equational theory executable semantics via rewriting high-level programming facilities (inheritance, templates and instantiations, ) freedom of language syntactic elements can freely defined (postfix, infix, mixfix; overloading, ) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 7/44

Logical Foundation Order sorted algebras partial order of sorts Hidden algebras co-algebraic methods, infinite objects Rewriting logic transitions as first class objects Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 8/44

Logical Foundation Order sorted algebras partial order of sorts Hidden algebras co-algebraic methods, infinite objects Rewriting logic transitions as first class objects plus executable via rewriting engine Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 8/44

Proof Score Approach domain/design engineers construct proof scores hand-in-hand with formal specification proof scores are executable instructions evaluating/computing/rewriting proof scores provides proofs of the specification and related properties Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 9/44

Proof Score Approach domain/design engineers construct proof scores hand-in-hand with formal specification proof scores are executable instructions evaluating/computing/rewriting proof scores provides proofs of the specification and related properties proof by construction proof by rewriting model and describe a system in order-sorted algebraic specification construct proof score and verify the specification by rewriting Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 9/44

Functional and Logic programming Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 10/44

Who has progammed here...? Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 11/44

Who has progammed here...? C, Pascal, Python, Java, Vala, Perl, Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 11/44

Who has progammed here...? C, Pascal, Python, Java, Vala, Perl, versus Lisp, Scheme, Prolog, Maude, Coq, CafeOBJ, Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 11/44

Imperative versus Functional programming Imperative programming mixture of what is computed and how it is computed push a ; push b ; push c ; add ; mul variables indicate data locations sequence of states that is changing result is the final state Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 12/44

Imperative versus Functional programming Imperative programming mixture of what is computed and how it is computed push a ; push b ; push c ; add ; mul variables indicate data locations sequence of states that is changing result is the final state Functional programming separate what from how (to some degree) variables indicate universal properties (for all x) computation is evaluation of terms result is the evaluation of the term Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 12/44

Example: gcd Imperative style int gcd ( int a, int b ) { int c; while ( a!= 0 ) { c = a ; a = b%a ; b = c ; } return b; } Here we describe a procedure that computes a result. Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 13/44

Example: gcd Functional style open NAT. op gcd : Nat Nat -> Nat. var a : Nat. var b : NzNat. eq gcd(0,a) = a. eq gcd(b,a) = gcd(a rem b, b). reduce gcd(12, 8). close NAT. Here we describe mathematical properties of the function to be computed. Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 14/44

(Abstract) Data Types Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 15/44

Data types Traditional view Mathematics: set S = int char = {(a, b) a int b char} Programming: structs struct S { int a; char b } Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 16/44

Data types Modern view Mathematics: algebra T = (S, fst S int, snd S char) = (int char, λ(a, b).a, λ(a, b).b) Programming: mod S { protect(int + 2TUPLES)... ops fst snd : 2Tuple -> Int. eq fst( << a ; b >> ) = a. eq snd( << a ; b >> ) = b. } Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 17/44

Data types (cont) specification Company X needs a program that does the following things: if the customer requests foo, assign him a slot if all slots are consumed, put the customer into a waiting loop and give him a slot as soon as one becomes free if the customer is finished, free the slot Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 18/44

Data types (cont) specification Company X needs a program that does the following things: if the customer requests foo, assign him a slot if all slots are consumed, put the customer into a waiting loop and give him a slot as soon as one becomes free if the customer is finished, free the slot implementation first-in-first-out queues Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 18/44

Data types (cont) specification Company X needs a program that does the following things: if the customer requests foo, assign him a slot if all slots are consumed, put the customer into a waiting loop and give him a slot as soon as one becomes free if the customer is finished, free the slot implementation first-in-first-out queues Q How do we verify that the program matches the specification? Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 18/44

Data types (cont) specification a program that implements asymmetric encryption implementation various key formats, hash algorithms, Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 19/44

Data types (cont) specification a program that implements asymmetric encryption implementation various key formats, hash algorithms, Q How do we make sure that the NSA does not interfere? Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 19/44

Data types and implementations More formally datatype equivalence class of isomorphic Σ-algebras (e.g., class of all Boolean algebras isomorphic to {, }) abstract data type class of Σ-algebras closed under isomorphims (e.g., class of Boolean algebras that are either 2-valued or 4-valued) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 20/44

Data types and implementations More formally datatype equivalence class of isomorphic Σ-algebras (e.g., class of all Boolean algebras isomorphic to {, }) abstract data type class of Σ-algebras closed under isomorphims (e.g., class of Boolean algebras that are either 2-valued or 4-valued) implementation is a (concrete) data type concrete data representation provide realizations of the methods/operations specification is an abstract data type allows for different implementations no particular data representation Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 20/44

(Algebraic) specification languages programming languages describe the actual implementation Verification needs an additional description language for the specification. specification languages describe both the specification as well as the implementation Verification can be carried out within the system. Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 21/44

CafeOBJ Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 22/44

CafeOBJ history, background, and relatives algebraic specification language based on equational theory origin in CLEAR (Burstall and Goguen, early 70s) and OBJ language (Goguen et at., 70-80s SRI and UCI San Diego) OBJ2 (Futatsugi, Goguen, Jouannaud, Meseguer at UCI San Diego, 1984) based on Horn logic, sub-sorts, parametrized modules, OBJ3 (Claude-Kirchner), Maude (Meseguer, full Horn logic) formal background based on rewrite logic, initial semantics, and institutions similar but unrelated languages: Coq (Jouannaud, based on Marin-Löf s type theory) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 23/44

Examples specifications classical mutual exclusion protocols (QLock) simplified cloud protocol real time algorithms (Fischer s mutual exclusion protocol) railway signaling systems authentication protocols (NSLPK, STS, Otway-Rees) key secrecy PACE protocol (German passport) e-commerce protocols (SET practical sized 60000loc) UML semantics formal fault tree analysis secure workflow models Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 24/44

Availability http://cafeobj.org Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 25/44

http://cafeobj.org Available pages Home: Welcome and latest news Support & Contact: mailing list, bug tracker, email Download & Install: source, binary, installation instructions Documentation: reference manual, user manual, some other documents Sub-pages: Tutorials, examples, reference manual wiki Personnel: list of people Recent posts: list of all recent posts Links: some links Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 26/44

Getting information Contact info@cafeobj.org Mailing list users@cafeobj.org Registration at: https://cafeobj.org/mailman/listinfo/users Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 27/44

Getting information Contact info@cafeobj.org Mailing list users@cafeobj.org Registration at: https://cafeobj.org/mailman/listinfo/users Reference wiki Reference manual split into Wiki pages After logging in (various options): ability to change documentation, add entries, clarify, add examples Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 27/44

Getting information Contact info@cafeobj.org Mailing list users@cafeobj.org Registration at: https://cafeobj.org/mailman/listinfo/users Reference wiki Reference manual split into Wiki pages After logging in (various options): ability to change documentation, add entries, clarify, add examples Bug tracker If you find a bug, or have a feature request: http://tracker.cafeobj.org/ Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 27/44

Algebraic semantics the CafeOBJ Cube HOSA HOSRWL HA OSA HRWL OSRWL M = many S = sorted O = order H = hidden A = algebra RWL = rewriting logic MSA RWL Logical systems and morphisms are formalised as institutions and institution morphism Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 28/44

What is CafeOBJ Algebraic specification language Logic foundation: order sorted algebra co-algebra, hidden algebra rewriting logic Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 29/44

What is CafeOBJ Algebraic specification language Logic foundation: order sorted algebra co-algebra, hidden algebra rewriting logic Verification/Programming language Executable semantics equational theory rewriting engine (conditional, order-sorted, AC) module system parametrized modules inheritance (module reuse) completely free syntax (prefix, postfix, infix, mixfix) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 29/44

Computational semantics equational theory axioms are directed order-sorted rewriting Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 30/44

Computational semantics equational theory axioms are directed order-sorted rewriting CafeOBJ as programming language module system parametrized modules inheritance Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 30/44

Computational semantics equational theory axioms are directed order-sorted rewriting CafeOBJ as programming language module system parametrized modules inheritance completely free syntax Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 30/44

CafeOBJ basics Term rewriting append(nil, ys) ys append(x xs, ys) x append(xs, ys) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 31/44

CafeOBJ basics Term rewriting append(nil, ys) ys append(x xs, ys) x append(xs, ys) e.g. append(1 2 3 nil, 4 5 nil) 1 append(2 3 nil, 4 5 nil) 1 2 append(3 nil, 4 5 nil) 1 2 3 append(nil, 4 5 nil) 1 2 3 4 5 nil Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 31/44

CafeOBJ basics Sorts and order arbitrary sorts (distinct universes) [ sort1 sort2 sort3...] may be partially ordered, order is set inclusion [ Nat < Int < Rat, Int < Float ] operator overloading depending of type (domain/codomain) inheritance op f : Int -> Int works also for Nat. strictly typed language f( X:Float ) does not work out Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 32/44

CafeOBJ basics osa order signature (S, F) such that S is a set of sorts (sort names) F set of operations of the form f s 1 s k s s 1,, s k, s are sorts operation name: f argument sorts: s 1 s k target sort: s arity: s 1 s k s If k = 0 then it is a constant: c s of sort s Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 33/44

CafeOBJ basics osa order signature (S, F) such that S is a set of sorts (sort names) F set of operations of the form f s 1 s k s order sorted signature (S,, F) such that s 1,, s k, s are sorts operation name: f argument sorts: s 1 s k target sort: s arity: s 1 s k s If k = 0 then it is a constant: c s of sort s (S, F) is a order signature a partial ordering on S such that monotonicity condition holds: order in the argument sorts implies order in the target sort. Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 33/44

CafeOBJ basics osa order signature (S, F) such that S is a set of sorts (sort names) F set of operations of the form f s 1 s k s order sorted signature (S,, F) such that s 1,, s k, s are sorts operation name: f argument sorts: s 1 s k target sort: s arity: s 1 s k s If k = 0 then it is a constant: c s of sort s (S, F) is a order signature a partial ordering on S such that monotonicity condition holds: order in the argument sorts implies order in the target sort. order sorted algebra sets for sorts with proper order, operations follow the sorts, monotonicity condition Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 33/44

Advantages of OSA polymorphism (parametric, subsort) and overloading error definition and handling via subsorts multiple inheritance operational semantics that executes equations as rewrite rules (executable specifications) rigorous model-theoretic semantics based on institutions Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 34/44

First steps in CafeOBJ Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 35/44

Starting CafeOBJ $ cafeobj -- loading standard prelude -- CafeOBJ system Version 1.5.6(PigNose0.99,b3) -- built: 2016 Jan 20 Wed 14:12:49 GMT prelude file: std.bin *** 2016 Jan 23 Sat 11:09:58 GMT Type? for help *** -- Containing PigNose Extensions -- --- built on SBCL 1.3.1.debian CafeOBJ> Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 36/44

Getting help Documents Reference manual, user manual, some specific manuals (CITP, PigNose, mostly in Japanese) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 37/44

Getting help Documents Reference manual, user manual, some specific manuals (CITP, PigNose, mostly in Japanese) Help system CafeOBJ has a built-in documentation and help system, available commands:? general help Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 37/44

Getting help Documents Reference manual, user manual, some specific manuals (CITP, PigNose, mostly in Japanese) Help system CafeOBJ has a built-in documentation and help system, available commands:? general help?com <class> shows available commands classified by <class> (list of classes when no class is passed in) Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 37/44

Getting help Documents Reference manual, user manual, some specific manuals (CITP, PigNose, mostly in Japanese) Help system CafeOBJ has a built-in documentation and help system, available commands:? general help?com <class> shows available commands classified by <class> (list of classes when no class is passed in)? <name> gives the reference manual description of <name> Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 37/44

Getting help Documents Reference manual, user manual, some specific manuals (CITP, PigNose, mostly in Japanese) Help system CafeOBJ has a built-in documentation and help system, available commands:? general help?com <class> shows available commands classified by <class> (list of classes when no class is passed in)? <name> gives the reference manual description of <name>?ex <name> gives examples for <name>, if available Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 37/44

Getting help Documents Reference manual, user manual, some specific manuals (CITP, PigNose, mostly in Japanese) Help system CafeOBJ has a built-in documentation and help system, available commands:? general help?com <class> shows available commands classified by <class> (list of classes when no class is passed in)? <name> gives the reference manual description of <name>?ex <name> gives examples for <name>, if available?ap <term> searches all available documentation strings for the terms Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 37/44

Getting help Documents Reference manual, user manual, some specific manuals (CITP, PigNose, mostly in Japanese) Help system CafeOBJ has a built-in documentation and help system, available commands:? general help?com <class> shows available commands classified by <class> (list of classes when no class is passed in)? <name> gives the reference manual description of <name>?ex <name> gives examples for <name>, if available?ap <term> searches all available documentation strings for the terms Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 37/44

Simple computations $ cafeobj Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 38/44

Simple computations $ cafeobj -- loading standard prelude... Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 38/44

Simple computations $ cafeobj -- loading standard prelude... CafeOBJ> Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 38/44

Simple computations $ cafeobj -- loading standard prelude... CafeOBJ> open NAT... %NAT> Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 38/44

Simple computations $ cafeobj -- loading standard prelude... CafeOBJ> open NAT... %NAT> red 10 * 20 + 30. Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 38/44

Simple computations $ cafeobj -- loading standard prelude... CafeOBJ> open NAT... %NAT> red 10 * 20 + 30. -- reduce in %NAT : ((10 * 20) + 30):NzNat (230):NzNat (0.0000 sec for parse, 0.0000 sec for 2 rewrites + 2 matches) %NAT> close CafeOBJ> quit Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 38/44

Function Declaration mathematical definition square N N square(a) = a a f N N N f(a, b) = a a + b b Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 39/44

Function Declaration mathematical definition square N N square(a) = a a f N N N f(a, b) = a a + b b CafeOBJ: 1 open NAT. 2 vars A B : Nat 3 op square : Nat -> Nat. 4 eq square(a) = A * A. 5 op f : Nat Nat -> Nat. 6 eq f(a, B) = A * A + B * B. 7 8 red square(10). 9 red f(10,20). 10 close Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 39/44

Recursion mathematical definition sum N N sum(a) = 0 if a = 0 a + sum(a 1) otherwise Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 40/44

Recursion mathematical definition sum N N sum(a) = 0 if a = 0 a + sum(a 1) otherwise CafeOBJ: 1 open NAT. 2 var A : Nat. 3 op sum : Nat -> Nat. 4 eq sum(a) = if A == 0 then 0 else A + sum(p A) fi 5 6 red sum(10). 7 close Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 40/44

Recursion mathematical definition sum N N sum(a) = 0 if a = 0 a + sum(a 1) otherwise CafeOBJ: 1 open NAT. 2 var A : Nat. 3 op sum : Nat -> Nat. 4 eq sum(a) = if A == 0 then 0 else A + sum(p A) fi 5 6 red sum(10). 7 close NOTE p A is A 1, called predecessor function Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 40/44

Conditional Equalities mathematical definition sum N N sum(a) = 0 if a = 0 a + sum(a 1) if a > 0 Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 41/44

Conditional Equalities mathematical definition sum N N sum(a) = 0 if a = 0 a + sum(a 1) if a > 0 code simplified by ceq and inline (on-the-fly) variable declaration :Nat 1 open NAT. 2 op sum : Nat -> Nat. 3 eq sum(0) = 0. 4 ceq sum(a:nat) = A + sum(p A) if A > 0. 5 red sum(10). 6 close Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 41/44

Conditional Equalities mathematical definition sum N N sum(a) = 0 if a = 0 a + sum(a 1) if a > 0 code simplified by ceq and inline (on-the-fly) variable declaration :Nat 1 open NAT. 2 op sum : Nat -> Nat. 3 eq sum(0) = 0. 4 ceq sum(a:nat) = A + sum(p A) if A > 0. 5 red sum(10). 6 close CafeOBJ warns sort mismatch for p A: [Warning]: axiom :... contains error operators..* done. Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 41/44

Case Distinctions by Sorts mathematical definition NB. N = {0} {1, 2, 3, } sum N N sum(a) = 0 if a = 0 a + sum(a 1) if a {1, 2, 3, } Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 42/44

Case Distinctions by Sorts mathematical definition NB. N = {0} {1, 2, 3, } sum N N sum(a) = 0 if a = 0 a + sum(a 1) if a {1, 2, 3, } code simplified by subsort NzNat of Nat 1 open NAT. 2 op sum : Nat -> Nat. 3 eq sum(0) = 0. 4 eq sum(a:nznat) = A + sum(p A). 5 red sum(10). 6 close Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 42/44

Computational Model program is set of (directed) equalities execution is rewriting Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 43/44

Computational Model program is set of (directed) equalities execution is rewriting 1 open NAT. 2 op sum : Nat -> Nat. 3 eq sum(0) = 0. 4 eq sum(n:nznat) = N + sum(p N). 5 6 red sum(3). 7 close Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 43/44

Computational Model program is set of (directed) equalities execution is rewriting 1 open NAT. 2 op sum : Nat -> Nat. 3 eq sum(0) = 0. 4 eq sum(n:nznat) = N + sum(p N). 5 6 red sum(3). 7 close sum(3) 3 + sum(2) 3 + (2 + sum(1)) 3 + (2 + (1 + sum(0)) 3 + (2 + (1 + 0)) 6 Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 43/44

Challenge Implement the following functions in CafeOBJ Implement factorial(n) = n! Implement fib(n), n-th Fibonacci number, where fib(0) = 0, fib(1) = 1, and fib(n) = fib(n 2) + fib(n 1) otherwise Algebraic specification and verification with CafeOBJ [5pt]Part 1 Introduction 44/44