SlideShare a Scribd company logo
1 of 17
Formal methods in
software engineering
Lecture 3 Text editor in Z
Prof Engr Faiz ul haque Zeya
Modeling text editor in Z
 We'll model a simple text editor. All you can do with this editor is type in text,
move the cursor backwards and forwards through the text, and delete the
character in front of the cursor
Basic type and abbreviation type
 We declare a basic type: the set of all characters. Then we make an
abbreviation definition to say that a text is a sequence of characters. [CHAR]
TEXT = seq CHAR
CHAR is a full-fledged Z data type. In Z we can introduce a new data type just by
writing its name inside brackets . From now on we can use CHAR in declarations,
just like N and all the other predefined data types. The abbreviation definition
introduces another new data type, TEXT, a sequence of characters. We can use
seq to define a sequence of any type. Sequences and their operators are defined
in the mathematical tool-kit
Axiomatic description
State schemas
 The contents of a system's memory are called its state. Schemas model states as collections of
state variables and their values.
 A text editor does have memory: It stores the text you type and the changes you make. The
state of our text editor is very simple: We have a document with a cursor. The document is a
text (a sequence of characters) that is no larger than our upper limit. We model the document
as two texts: left is the text before the cursor, and right is text following it.
State schema (cont…)
Initializing schemas
 In Z this state is described by a schema conventionally named Init. For
example, we might say that our editor always starts up with an empty
document:
 The Init schema includes the Editor schema in its declaration section. This
indicates that all the declarations and predicates in Editor apply to Init as
well, so Init can use the local state variables right and left from Editor.
Operation schema
 We need to model another aspect of state: change. Our editor starts up
empty, but it fills with text as the user types, and its contents change as the
user edits. To model this kind of activity, Z provides the operation schema.
 the Insert operation that puts a single character in the document to the left
of the cursor.`
Operation schema cont…
Operation schema cont…
 Delta Editor (pronounced delta editor) tells us that Insert is an operation
schema that changes the state of Editor.
 operation schema declares the input variable ch?
 The unprimed variables left and right denote the texts to the left and right of
the cursor before the Insert operation, and the primed variables left’ and
right’ denote those texts after the operation.
Operation schema cont…
 The first line of the predicate, ch?E printing, is a precondition: It describes
what must be true before the operation can occur. Sometimes preconditions
are called entry conditions. This precondition says that the Insert operation
can only occur when the input is a printing character; it uses the set
membership operator e (pronounced in). The rest of the predicate is a
postcondition: It describes the state of the editor after the operation. The
line left' = left^ (ch?) says that the new character is appended to the end of
the text preceding the cursor (in other words, it is inserted to the left of the
cursor). Here again we use the concatenation operator. The next line right' =
right says that the text following the cursor does not change. In Z it is
necessary to say when things remain the same.
Implicit precondition
 The next operation moves the cursor forward one character. In many editors,
the user invokes this operation by pressing the right arrow key | -> | on the
workstation keyboard. We use an axiomatic definition to declare this right-
arrow character. We have to include a predicate that uses the set
nonmembership operator £ to say that rightuarrow is not a printing character;
otherwise our editor would try to insert the arrow character into the file,
instead of interpreting it as a command.
 The implicit precondition of Forward is that the cursor is not at the end of the
document: right =/= ().
Schema calculus
 We will define a total version of Forward that works in all situations. We'll
define it in pieces, where each piece is a schema. Then we'll use the schema
calculus to put the pieces together. This is the usual way to define complex
operations in Z.
 First we define a state schema to describe the end of file condition where the
cursor is at the end of the document.
Schema calculus cont…
 In Z it is necessary to say when nothing happens. "^Editor is the operation on
Editor that does not change the value of any state variable. We make
rightarrow into a schema by defining RightArrow
Schema calculus cont…
 This formula says that T.Forward behaves as the Forward operation when the
cursor is not at the end of the file, but pressing the right arrow key when the
editor is in the EOF state has no effect.


More Related Content

Similar to lec3forma.pptx

packaging procedures_and_state
packaging procedures_and_statepackaging procedures_and_state
packaging procedures_and_stateRajendran
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSAami Kakakhel
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANINikul4470
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptxAnisZahirahAzman
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsRai University
 
Matlab: Procedures And Functions
Matlab: Procedures And FunctionsMatlab: Procedures And Functions
Matlab: Procedures And Functionsmatlab Content
 
Procedures And Functions in Matlab
Procedures And Functions in MatlabProcedures And Functions in Matlab
Procedures And Functions in MatlabDataminingTools Inc
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsRai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-aneebkmct
 
From Scala Monadic Effects to Unison Algebraic Effects
From Scala Monadic Effects to Unison Algebraic EffectsFrom Scala Monadic Effects to Unison Algebraic Effects
From Scala Monadic Effects to Unison Algebraic EffectsPhilip Schwarz
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
 
Please write a code in JAVA to do line editor..Your program will b.pdf
Please write a code in JAVA to do line editor..Your program will b.pdfPlease write a code in JAVA to do line editor..Your program will b.pdf
Please write a code in JAVA to do line editor..Your program will b.pdffazilfootsteps
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsRai University
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and stringsRai University
 
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Dadangsachir WANDA ir.mba
 

Similar to lec3forma.pptx (20)

packaging procedures_and_state
packaging procedures_and_statepackaging procedures_and_state
packaging procedures_and_state
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Opps concept
Opps conceptOpps concept
Opps concept
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
Matlab: Procedures And Functions
Matlab: Procedures And FunctionsMatlab: Procedures And Functions
Matlab: Procedures And Functions
 
Procedures And Functions in Matlab
Procedures And Functions in MatlabProcedures And Functions in Matlab
Procedures And Functions in Matlab
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
 
From Scala Monadic Effects to Unison Algebraic Effects
From Scala Monadic Effects to Unison Algebraic EffectsFrom Scala Monadic Effects to Unison Algebraic Effects
From Scala Monadic Effects to Unison Algebraic Effects
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Please write a code in JAVA to do line editor..Your program will b.pdf
Please write a code in JAVA to do line editor..Your program will b.pdfPlease write a code in JAVA to do line editor..Your program will b.pdf
Please write a code in JAVA to do line editor..Your program will b.pdf
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
 

More from Faiz Zeya

structureformal1.ppt
structureformal1.pptstructureformal1.ppt
structureformal1.pptFaiz Zeya
 
elementsofZ.pptx
elementsofZ.pptxelementsofZ.pptx
elementsofZ.pptxFaiz Zeya
 
FOLBUKCFAIZ.pptx
FOLBUKCFAIZ.pptxFOLBUKCFAIZ.pptx
FOLBUKCFAIZ.pptxFaiz Zeya
 
Word2vec-08032022-012238pm (1).pptx
Word2vec-08032022-012238pm (1).pptxWord2vec-08032022-012238pm (1).pptx
Word2vec-08032022-012238pm (1).pptxFaiz Zeya
 
Code completion using OpenAI APIs.pptx
Code completion using OpenAI APIs.pptxCode completion using OpenAI APIs.pptx
Code completion using OpenAI APIs.pptxFaiz Zeya
 
Types of machine learning.pptx
Types of machine learning.pptxTypes of machine learning.pptx
Types of machine learning.pptxFaiz Zeya
 
Linear algebraweek2
Linear algebraweek2Linear algebraweek2
Linear algebraweek2Faiz Zeya
 
Query expansion for search improvement by faizulhaque
Query expansion for search improvement by faizulhaque Query expansion for search improvement by faizulhaque
Query expansion for search improvement by faizulhaque Faiz Zeya
 
Big data introduction
Big data introductionBig data introduction
Big data introductionFaiz Zeya
 

More from Faiz Zeya (9)

structureformal1.ppt
structureformal1.pptstructureformal1.ppt
structureformal1.ppt
 
elementsofZ.pptx
elementsofZ.pptxelementsofZ.pptx
elementsofZ.pptx
 
FOLBUKCFAIZ.pptx
FOLBUKCFAIZ.pptxFOLBUKCFAIZ.pptx
FOLBUKCFAIZ.pptx
 
Word2vec-08032022-012238pm (1).pptx
Word2vec-08032022-012238pm (1).pptxWord2vec-08032022-012238pm (1).pptx
Word2vec-08032022-012238pm (1).pptx
 
Code completion using OpenAI APIs.pptx
Code completion using OpenAI APIs.pptxCode completion using OpenAI APIs.pptx
Code completion using OpenAI APIs.pptx
 
Types of machine learning.pptx
Types of machine learning.pptxTypes of machine learning.pptx
Types of machine learning.pptx
 
Linear algebraweek2
Linear algebraweek2Linear algebraweek2
Linear algebraweek2
 
Query expansion for search improvement by faizulhaque
Query expansion for search improvement by faizulhaque Query expansion for search improvement by faizulhaque
Query expansion for search improvement by faizulhaque
 
Big data introduction
Big data introductionBig data introduction
Big data introduction
 

Recently uploaded

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 

Recently uploaded (20)

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 

lec3forma.pptx

  • 1. Formal methods in software engineering Lecture 3 Text editor in Z Prof Engr Faiz ul haque Zeya
  • 2. Modeling text editor in Z  We'll model a simple text editor. All you can do with this editor is type in text, move the cursor backwards and forwards through the text, and delete the character in front of the cursor
  • 3. Basic type and abbreviation type  We declare a basic type: the set of all characters. Then we make an abbreviation definition to say that a text is a sequence of characters. [CHAR] TEXT = seq CHAR CHAR is a full-fledged Z data type. In Z we can introduce a new data type just by writing its name inside brackets . From now on we can use CHAR in declarations, just like N and all the other predefined data types. The abbreviation definition introduces another new data type, TEXT, a sequence of characters. We can use seq to define a sequence of any type. Sequences and their operators are defined in the mathematical tool-kit
  • 5. State schemas  The contents of a system's memory are called its state. Schemas model states as collections of state variables and their values.  A text editor does have memory: It stores the text you type and the changes you make. The state of our text editor is very simple: We have a document with a cursor. The document is a text (a sequence of characters) that is no larger than our upper limit. We model the document as two texts: left is the text before the cursor, and right is text following it.
  • 7. Initializing schemas  In Z this state is described by a schema conventionally named Init. For example, we might say that our editor always starts up with an empty document:
  • 8.  The Init schema includes the Editor schema in its declaration section. This indicates that all the declarations and predicates in Editor apply to Init as well, so Init can use the local state variables right and left from Editor.
  • 9. Operation schema  We need to model another aspect of state: change. Our editor starts up empty, but it fills with text as the user types, and its contents change as the user edits. To model this kind of activity, Z provides the operation schema.  the Insert operation that puts a single character in the document to the left of the cursor.`
  • 11. Operation schema cont…  Delta Editor (pronounced delta editor) tells us that Insert is an operation schema that changes the state of Editor.  operation schema declares the input variable ch?  The unprimed variables left and right denote the texts to the left and right of the cursor before the Insert operation, and the primed variables left’ and right’ denote those texts after the operation.
  • 12. Operation schema cont…  The first line of the predicate, ch?E printing, is a precondition: It describes what must be true before the operation can occur. Sometimes preconditions are called entry conditions. This precondition says that the Insert operation can only occur when the input is a printing character; it uses the set membership operator e (pronounced in). The rest of the predicate is a postcondition: It describes the state of the editor after the operation. The line left' = left^ (ch?) says that the new character is appended to the end of the text preceding the cursor (in other words, it is inserted to the left of the cursor). Here again we use the concatenation operator. The next line right' = right says that the text following the cursor does not change. In Z it is necessary to say when things remain the same.
  • 13. Implicit precondition  The next operation moves the cursor forward one character. In many editors, the user invokes this operation by pressing the right arrow key | -> | on the workstation keyboard. We use an axiomatic definition to declare this right- arrow character. We have to include a predicate that uses the set nonmembership operator £ to say that rightuarrow is not a printing character; otherwise our editor would try to insert the arrow character into the file, instead of interpreting it as a command.  The implicit precondition of Forward is that the cursor is not at the end of the document: right =/= ().
  • 14.
  • 15. Schema calculus  We will define a total version of Forward that works in all situations. We'll define it in pieces, where each piece is a schema. Then we'll use the schema calculus to put the pieces together. This is the usual way to define complex operations in Z.  First we define a state schema to describe the end of file condition where the cursor is at the end of the document.
  • 16. Schema calculus cont…  In Z it is necessary to say when nothing happens. "^Editor is the operation on Editor that does not change the value of any state variable. We make rightarrow into a schema by defining RightArrow
  • 17. Schema calculus cont…  This formula says that T.Forward behaves as the Forward operation when the cursor is not at the end of the file, but pressing the right arrow key when the editor is in the EOF state has no effect. 