1 Modelling using Sequences Sequences The finite sequence constructor Value definitions: enumeration, subsequence Operators on Sequences Case Study: the.

Slides:



Advertisements
Similar presentations
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of the FSA is easy for us to understand, but difficult.
Advertisements

Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Python Mini-Course University of Oklahoma Department of Psychology
1 Modelling using sets Sets: The finite set type constructor Value definitions: enumeration, subrange, comprehension Operators on sets Case Study: the.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Comp 205: Comparative Programming Languages Functional Programming Languages: More Haskell Nested definitions Lists Lecture notes, exercises, etc., can.
A First Look at ML Chapter FiveModern Programming Languages, 2nd ed.1.
C++ Data Type String A string is a sequence of characters enclosed in double quotes. Examples of strings: “Hello” “CIS 260” “Students” The empty string.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Vienna Development Method SIM5104. one of the longest-established Formal Methods for the development of computer- based systemsFormal Methods Originating.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
CS5371 Theory of Computation Lecture 1: Mathematics Review I (Basic Terminology)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
Sequences. What is sequence? A sequence is an ordered collection of objects. We use sequences to model collections in which order or multiplicity is important.
Fall 2004COMP 3351 Languages. Fall 2004COMP 3352 A language is a set of strings String: A sequence of letters/symbols Examples: “cat”, “dog”, “house”,
Quadratic Time Algorithms for Finding Common Intervals in Two and More Sequences Thomas Schmidt Jens Stoye CPM 2004, Istanbul.
Sequences for system modelling. At the end of this lecture you should be able to: provide a definition of a VDM sequence; identify situations in which.
1 Recursion Simple recursion to traverse lists Recursive data structures and recursive functions.
Sequences At the end of this lecture you should be able to: provide a definition of a VDM sequence; utilize and interpret sequence notation; make appropriate.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
Sequences At the end of this lecture you should be able to: provide a definition of a VDM sequence; utilize and interpret sequence notation; make appropriate.
Chars and strings Jordi Cortadella Department of Computer Science.
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
Lecture 4 Sequences CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Introduction to Programming (in C++) Algorithms on sequences. Reasoning about loops: Invariants. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept.
Sequences Jordi Cortadella Department of Computer Science.
TIVDM1Modelling ordered collections1 Peter Gorm Larsen.
TIVDM1Modelling ordered collections1 Peter Gorm Larsen.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet:
An OO schema language for XML SOX W3C Note 30 July 1999.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
F28PL1 Programming Languages Lecture 13: Standard ML 3.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
Exercise 2 Introduction to C# CIS Create a class called Employee that contains the following private instance variables: Social Securitystring.
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
1 STRINGS String data type Basic operations on strings String functions String procedures.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
1 Logic Our ability to state invariants, record preconditions and post- conditions, and the ability to reason about a formal model depend on the logic.
Module #10: Proof Strategies Rosen 5 th ed., §3.1 (already covered)
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
Lecture 1 Data Structures Shafay Shamail September 05, 2006.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Formal Methods in SE Lecture 21.
Types CSCE 314 Spring 2016.
VDM: Vienna Development Method
ML: a quasi-functional language with strong typing
A lightening tour in 45 minutes
Primitive Types Vs. Reference Types, Strings, Enumerations
Announcements 2nd homework is due this week Wednesday (October 18)
String Processing.
Chapter 7: Strings and Characters
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
Summary of what we learned so far
Announcements 3rd homework is due this week Wednesday (March 15)
String class and its objects
CSC 221: Introduction to Programming Fall 2018
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Additional string operators
String Processing.
COMS 261 Computer Science I
Announcements HW1 is due TODAY.
Languages Fall 2018.
Presentation transcript:

1 Modelling using Sequences Sequences The finite sequence constructor Value definitions: enumeration, subsequence Operators on Sequences Case Study: the BASE Trusted Gateway

2 The finite sequence type constructor In VDM-SL, a sequence is a finite ordered collection of values. The presence of duplicates and the order in which elements are presented is significant. The finite sequence type constructor is: seq of X where X is an arbitrary type. The type seq of X is the class of all possible finite sequences of values drawn from the type X. For example: seq of nat1 seq of (seq of char)

3 Finite sequence value definitions Sequence values can be represented in various ways: Enumeration, e.g. [3, 5, 2, 5, 45] [ {34}, {34,7}, “Fred” ] empty sequence [] Sequences of characters may be given as strings in quotation marks, e.g. [‘l’,’i’,’n’,’u’,’x’] = “linux” Subsequence : If we have a sequence q then we can take an extract from q, e.g. q(3,…,5)= [q(3), q(4), q(5)] Comprehension: The sequence comprehension notation is not often used and is described in the text. Note that sequences, like sets, are finite.

4 Operators on finite sequences hd: seq of X -> X Partial operator: s <> [] First element tl: seq of X -> seq of X Partial operator: s <> [] Tail (NB: a sequence!) len: seq of X -> nat length of sequence elems: seq of X -> set of X elements in the sequence (reduced to a set) inds: seq of X -> set of nat indices of the sequence {1,…,len s} _ ^ _ : seq of X * seq of X -> seq of X sequence concatenation conc: seq of (seq of X) -> seq of X conc s = the concatenation of all the sequences in s

5 The BASE Trusted Gateway Trusted Gateway High Security System Low Security System High Security System

6 The BASE Trusted Gateway Each message is a non-empty sequence of characters starting with the sequence “STR” and ending with the sequence “STP”. The total length of a message must not exceed characters. String = seq of char Msg = String inv m == m <> []

7 The BASE Trusted Gateway A message may be of high or low security. Classification = | A message is defined as high security if it contains an occurrence of the string “SECRET”. If it does not contain the string “SECRET” and it does contain the string “UNCLASSIFIED” then the message is treated as low-security. If neither string is present, then the message is classes as high-security. Classify: Msg -> Classification Classify(m) == ???

8 The BASE Trusted Gateway We must model strings occurring as substrings of longer strings, so we use an auxiliary function for this: occurs: String * String -> bool occurs(s1,s2) == exists i,j in set inds s2 & s1 = s2(i,…,j) Then with the aid of this function, message classification is easy to model: Classify: Msg -> Classification Classify(m) == if occurs ( “SECRET”, m )then if (occurs( “UNCLASSIFIED”,m) and not occurs ( “SECRET”, m )) then then

9 The BASE Trusted Gateway Gateway :: input : seq of Msg outHi : seq of Msg outLo : seq of Msg AnalyseInput: Gateway -> Gateway AnalyseInput(g) == if g.input = nil then g else cases Classify (hd g.input) -> mk_Gateway(tail g.input, (hd g.input): g.outHi, g.outLo), -> mk_Gateway(tail g.input, g.outHi, (hd g.input): g.outLo)

10 Review Exercise In the real Trusted Gateway, we did not search for particular strings in the incoming messages. Instead, the gateway contained two collections of strings called categories: the “high category” and the “low category”. If the incoming string contained a string from the high category, then it was classed as high security. If the incoming string contained no high category strings and contained some low category strings, then it was classed as low security. Otherwise it was treated as high security. Add the categories as sets of strings to our model of the gateway and modify the classification function appropriately. Record the restriction that there should be at most 20 strings in each category.