Sie sind auf Seite 1von 311

9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.

html

FÓTHI ÁKOS

INTRODUCTION
THE

programming
Third, improved edition

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 1/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

© Fóthi Ákos, 2012

contents

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 2/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Firstelements 11
1.1. clusters 11
1.2. Series 12
1.3. relations 12
1.3.1. Operations 14
1.3.2. Logical relationships. 16
1.4. direct product 17
1.5. function Spaces 18
1.6. Examples 19
1.7. Tasks 24

Second
Basic concepts of programming 29
2.1. The concept of state space 29
2.2. The task 30
2.3. The program 32
2.4. The program function 33
2.5. Solution 34
2.6. Programming task 35
2.7. Examples 36
2.8. Tasks 40

Third
Specification 43
3.1. The weakest prerequisite 43
3.2. Specification of the task. . 45
3.3. The concept of variable 47
3.4. Examples 50
3.5. Tasks 52

4th extensions 57
4.1. Extending the task. . 57
4.2. Extension of the program. 58

4 CONTENTS

4.3. Extension Items 59


4.4. Extending the job and making the specification 65
4.5. Extending the parameter space 65
4.6. Examples 66
4.7. Tasks 68

5th Generalization of the concept of solution 69


5.1. Extending the concept of solution 69
5.2. Solution to an equivalent state 70
5.3. Relationship Solution 71

6th Programkonstrukciók 73
6.1. Permissible constructions 73
6.2. Program function of program constructions 79
6.3. Tasks 81

7th Discharge rules 85


7.1. The sequencing rule of the sequence 85
7.2. The derivation rule of the branch 86
7.3. Cycle derivation rule 88
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 3/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
7.4. Tasks 92

8th Basic programs 95


8.1. Basic programs 95
8.2. The weakest prerequisite for basic programs 97
8.3. Assignment as a task specification 99
8.4. Tasks 100

9th Program Constructions and Predictability 101


9.1. Partial recursive functions 101
9.2. Calculation of partial recursive functions 103
9.3. relations 107

10. Type 109


10.1. The type specification 109
10.2. The type 110
10.3. Batch type specification 112
10.4. Abstract type 112
10.5. Examples 113
10.6. Tasks 117

CONTENTS 5

11. Type constructions 121


11.1. Permissible constructions 121
11.2. Szelektorfüggvények 124
11.3. Its iterated specification functions 126
11.4. The function type 126
11.5. Type operations of type designs 128

12. Programming Items (Deployment) 131


12.1. Programming Items Interval 131
12.1.1. Summary 133
12.1.2. counting 134
12.1.3. Up to Search 136
12.1.4. Conditional Maximum Search 137
12.1.5. Linear search 138
12.2. "Conditional" version of items 139
12.2.1. Summarize 140
12.2.2. Count up 141
12.2.3. Maximum search until condition 142
12.2.4. Conditional maximum search condition 142
12.2.5. Linear search 143
12.2.6. Items differently 145
12.3. Programming Items Set 147
12.4. More complicated tasks 149
12.4.1. Logarithmic search 149
12.4.2. Backward search 151
12.4.3. Backward counting 155
12.5. Calculation of function value 156
12.5.1. Calculation of a Function with Function Composition 156
12.5.2. Calculation of a function with a split-off function. . 157
12.5.3. Calculation of a function with a recursive formula. . 157
12.5.4. Function that can be processed per item 158
12.6. Tasks 164

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 4/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

13. Transformations 167


13.1. Stemming 168
13.2. Simple program transformations 168
13.3. Típustranszformációk 171
13.4. State space transformation 176
13.4.1. Sequential matching 176
13.4.2. Example of state space transformation 178
13.5. Programinverzió 181
13.5.1. One-Variable Case 181
13.5.2. Two-Variable Case 182

6 CONTENTS

13.6. Examples 184


13.7. Tasks 196

14. Abstraction strategy 203


14.1. Definition of timing 204
14.2. Timing with a clear modifier file 207
14.2.1. Reconnection to a union of sets 207
14.2.2. Reversal for single-variable element processing. 209
14.2.3. Reversal for two-variable processing per battery 211
14.3. Timing with an unambiguous modifier file 212
14.3.1. Solution with data abstraction 212
14.3.2. Solution with function abstraction 215
14.4. Tasks 221

15. Solutions 225


15.1. elements 225
15.2. Basic concepts of programming 236
15.3. Specification 239
15.4. Extension 249
15.5. Programkonstrukciók 251
15.6. Discharge rules 262
15.7. Basic programs 265
15.8. Type 266
15.9. deduction 272
15.10.Visszavezetés 300
15.11.Abstraction strategy 345

index 360

References 363

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 5/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Introduction

The primary purpose of formulating the programming model described in the book is
was to give a theoretical background to the step-by-step refinement method - algorithm-
as well as the data structures. In the meantime,
and the current most important goal is to support conscious programming.
Although the tools of the model can replace the task specification
with the specifications of tasks that are available when solving tasks
with the help of mathematical tools, the correctness of the original task can be seen,
we do not aim at the automatic program synthesis, so we did not turn to the formal es-
approaches, methods.
Examining program languages, programs, proof of their correctness is more than
forty years back, and even some important results are even older. Itself
programming has become a subject of investigations very soon both theoretical and theoretical
from a practical point of view. Here is just the relational model that is most important to us
and we try to place it in our opinion the most prominent
between trends.

History
The presented model builds on four important antecedents. Dijkstra "programming
discipline "[Dij 76], Hoare type management [Hoa 72], Jackson's program design
method [Jac 75] and Mills mathematical approach [Mills 72].
The phenomenon that emerged in the '60s as a software critique is significant
gave impetus to programming research. These are almost identical
Dijkstra's notorious article [Dij 68] became a bounty and the beginning of programming languages
has been supported by modular programming or rather after the structured program-
as the starting point of the trend.
The concepts and methods introduced by him [Dij 76] have been built so many, so
our relational model. For us, the most important are the weakest prerequisites,
rules, non-determinism, state space, used by Dikstra, though
Hoare [Hoa 72] pre- and post-condition specification.
Although Dijkstra used logical solutions in this book, no
striving for stringent formalization, shortly there are a lot of articles and books

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 6/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

8 INTRODUCTION

[Gri 81] has done so. Formalization was mostly done by logical means
due to the background of the state space and the weakest prerequisite
as a predicate transformer.
Significantly influenced the development of our relational model Mills [Mills 72] mate-
approach. The concept of the program function, the closing of the function
and the relationship of the cycle, the modeling of memory is what is primarily taken into account
we took. Relationships were the obvious solution to the non-determinism
use.
A different approach to programming problems was given by Jackson [Jac 75],
which is considered to be one of the ancestors of the methods halfformed today, and
many times in practice. These are program designing methods as well
we tried to make it workable in the relational model.

Programming paradigms

Current main programming trends are divided into two major groups. One
are formal methods that are based on a formal math
discipline.
The functional paradigm is based on the λ calculus and its extensions . THE
the need for programs with high reliability and complicated tasks, and the
due to the incredible increase in available resources
it is no longer theoretical, but rather of practical significance.
The logic-based programming (modeling) - particularly exten- different logic
for example, due to temporal logic - many general and special systems
is displayed.
A remarkable career is introduced in Method B [Abr 96], which is Dijkstra and Hoare
mentioned works. It is based on the concept of abstract machine and the Zermelo-Fraenkel axi-
use B-based B-language at all stages of system compilation.
The other large group includes so called semiformal systems . These
in general, supporters of object-based modeling, such as the UML, but here
we can design the sample-based planning [GHJV 95], which is the classic method library pseudo-
can also be considered as a nationalization. An important practical element of these systems is the
code reuse, which is also a resource increase.
The relational model for the first group is the derivation , the second is the recurrence
concept.
Recent trends include multiparadigmatic approaches
[Bud 95], when the basis of the method is not a single abstract term or abstraction,
strategy. We also include our relational model in this group, but what is not
but the theoretical context behind them.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 7/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

INTRODUCTION 9

About each chapter

In the first part we summarize the most important mathematical


galaxies and markings, and we will introduce some special
Galm.
In the following two sections we introduce the basic concepts of the relationship-based model:
space, task, program, solution. We provide a sufficient condition for the solution, a
from a practical point of view, we use the variable
and the weakest prerequisite.
In Chapters 4 and 5 we generalize the concepts introduced so far. These chapters
its significance is primarily theoretical. They can be omitted for first reading.
The following three sections cover the usual sequential program designs
and introduce some of the step-by-step refinements related to them
from a point of view useful.
Chapter 9 is also of a theoretical point of view, and there is no need for further
understanding.
Then, with the most important concept of programming, we are dealing with type 10 and
in chapter 11. Concepts related to the type are not only important but also sufficiently
they wandered too. For the first reading, you do not have to strive for a thorough knowledge of them. It's a good idea
return to these chapters after reading a whole book.
In the following three chapters we will show you how to use practical
solving tasks. In Chapter 12, the application of the deduction rules
the task is progressively refined to get the proven solution
ramhoz. Chapter 13 introduces recycling, ie existing solutions,
items are used. In Chapter 14, we solve a more complex task
in different ways.
In the last section, we will give you a way to solve the tasks at the end of the chapters.
pointers, and in many cases, we offer a possible solution.

Acknowledgments

This book is a program design mathematician at Eötvös Loránd University


was made on the basis of my lectures. For a note that has been published more than twenty years ago
many things have changed. During this time many and my current colleague took me
participated in the teaching of this subject and helped her develop. Over twenty years with thousands of students
I have met these lectures, their negative and sometimes positive opinions are many
it helped me.
Current and former colleagues: István Fekete, Tibor Gregorics, Zoltán Horváth,
Konczné Nagy Márta, Sándor Kozics, Tamás Kozsik, Judit Nyékyné Gaizler, Sike
Sándor, Ferenc Steingart, Szabó Nacsa Rozália, Pál Tőke, Zoltán Varga, Vargyas
Thanks to Miklós, Tibor Venczel.

10 INTRODUCTION

Special thanks to Ferenc Steingart for the great work that the book is the first
I did not cut it without making an electronic note
in writing this book.
Thank you Jozsef Bozsik, Péter Kovács, Gergely Riskó and Zsolt Szilárd Sztupák
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 8/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
students to have the task solved. Péter Kovács, József Bozsik
with the help of the 15.1.-15.8., Gergely Riskó on 15.9. and 15.11., Stupas Zsolt Szilárd a
15:10. part designed solutions.
Thanks to László Hunyadvári's careful reading work, there are a lot of useful things
comments.

Recommendation
I recommend this book primarily to program designer mathematician, program designer in-
formative students. I recommend it to those who are programming,
they love the challenges and are open. This book is not easy to read and not
useful knowledge, collection of recipes, but who carefully reads thinking,
he probably will have a different eye on his work so far.
Instead of the safety of the road I recommend the excitement and hope of the unfinished road.

Chapter 1

elements

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792c… 9/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
In this section, we introduce the markings and basic definitions that a
we will use it frequently. Most of these are from high school
is known from introductory mathematical studies.

1.1. clusters
First we introduce the markings of sets used in mathematics.
N - the set of natural numbers,
N - a set of non-negative integers,
0
Z - the set of integers,
L - the set of logical values,
∅ - the empty set.
It is customary to include zero in the set of natural numbers, but in this
we use a separate mark (N ) for this book .
0
The sets are often or by listing their elements

L :: = {true, false},
or by formulating a property

[ a..b ] :: = {x ∈ Z | x ≥ a and x ≤ b}
enter it.
Of course, we will use the set theory mathematics
operations
∪ - union,
∩ - engraving,
\ - difference

12 1. BASIC PROVISIONS

and relationships
∈ - element,
⊆ - subset,
⊂ - a real part.
A H set cardinality | H | assigned. That a set H is finite, sometimes so
we also write: | H | <∞ .
The set of sub-sets of a set H , that is, its set of powers with ℘ ( H )
finite subset of the subsets of the subgroups F ( H ).

1.2. Series
A
If in a given set, then α = < α 1 , α 2 ,. . . > , Α i ∈ A is finite in A
an endless series.
The A have US finite sequences α = < α 1 , α 2 ,. . . , Α n > , α i ∈ A be described shape.
The length of an α finite series | α | assigned.
* ∞
Of the set of finite sequences have US The asterisk, the set of infinite sequences of -
labeled. The union produced two previous sets available to have US finite or infinite
**
a set of series **A use nominations.
An α ∈ A domain of Series D are marked with, and the next
we mean a set of: α

{
[1 .. | α | ] ,if α ∈ A * ;
D :: = ∞
α N, if α ∈ A .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 10/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
1 2 * n **
- 1 ∈ A and α ∈ A
1 2 n
the αLet, αα ,,.α. . ,., we
. . ,get
α n the . Then
alpha1 n- 1 ,2 α series the series
in sequence,
n
thethat youseries
above
concatenation called and kon ( α** , α ,..., α n- 1 , α denoted at).
A reduction in a series of A is called a series that is obtained,
that the finite sequence of all the same elements of the original series is part of the sub-
**
replaced by a single element of the series. An α ∈ A series redukáltját red ( α ) with
mark.
We also introduce the function τ , which assigns it to a finite sequence
* *
its last element: τ : A → A , ∀α ∈ A :
τ ( α ) :: = α .
|α|

1.3. relations
Let A and B be arbitrary sets, then

A × B :: = { ( a, b ) | a∈A and b∈B}

1.3. relations 13

definition given set of A and B sets direct multiplication .


A set R ⊆ A × B is called a binary relation . Next, if not
causes misunderstanding, the binary flag is omitted.
The R relation domain of :
D :: = {a ∈ A | ∃b ∈ B : ( a, b ) ∈ R},
R

the value set of the relation :


R :: = {b ∈ B | ∃a ∈ A : ( a, b ) ∈ R},
R

the relation is a ∈ A location, or otherwise the R of graphic :

R ( a ) :: = {b ∈ B | ( a, b ) ∈ R},

an H ⊆ the set R of graphic elements that make up the set union of the images, i.e.

R(H)= R(h).
h∈H

The relation R ⊆ A × B can be understood as a non-deterministic mapping,


correspondence between elements A and B. The interpretation range is
below those of have US elements to which is assigned at least one B have US ELE
meth. Likewise, the set of values is a set of elements assigned to at least one element.
Section 1.1. Figure 1 illustrates a relationship. A = {a, b, c, d}, B = { 1 , 2 , 3 , 4 }, R =
{ ( a, 1) , ( a, 2) , ( b, 2) , ( c, 3) }. In the point is assigned to one and two also b Rates are relative

the
• •1
b 2
• •
c• •3
d •4

1.1. figure. Illustration of Relationship

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 11/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
only 2, c are assigned to 3, d and nothing is assigned to 4,
what to do.
An image of a ∈ A is the set of elements B that are
in relation to the provision of to. A picture of a set H with a union of the images of the elements
We defined. This can be explained differently by the fact that the H image of the elements-
b, which are assigned to at least one element H , that is

14 1. BASIC PROVISIONS

R ( H ) = {b ∈ B | ∃a ∈ H : ( a, b ) ∈ R}.
We say that a relationship is deterministic if

∀a ∈ A : | R ( a ) | ≤ 1 .
Deterministic relationships are called differently as partial functions . Function-
We have called an R relation when

∀a ∈ A : | R ( a ) | = 1 .
An A from B forming into main function is generally: A f → B , while a par-
facial function f ∈ A → B is indicated with. If this mark is used, f ( a ) is not
one-piece set, but its element.
Let R ⊆ A × B . Then the relation R ( - 1) is the inverse of R , if

R ( - 1) :: = { ( b, a ) ∈ B × A | ( a, b ) ∈ R}.

Let H ⊆ B be any set. H of the inverse relationship R ( - 1) ( H ) -


ta H sets R by the relation inverse image is called. From the definitions it appears to be

R ( - 1) ( H ) = {a ∈ A | R ( a ) ∩ H = ∅}.

It is important to distinguish the inverse image of the H, set R of relation archetype of,
the definition of which is as follows:

R - 1 ( H ) :: = {a ∈ D | R ( a ) ⊆ H}.
R

Ants usually do not match the inverse image but are always part of it.
The relationship between the two images is shown in Figure 1.2. figure. However, it should be noted that a
function,
or for a partial function, the two images are the same.
Let P ⊆ A × B and Q ⊆ A × B . If P ⊆ Q , P -t Q narrowing is called for.
If R ⊆ A × B and H ⊆ A , then

R| =R∩(H×B)
H

R is a narrowing of what is also referred to R H tightening on.

1.3.1. Operations
Interactions between relationships include operations as well. Let P ⊆ A × B and Q ⊆ B × C .
The relation R ⊆ A × C is called the composition of P and Q relationships , if

( A, b ) ∈ P and ( b, c ) ∈Q}, then R = { ( a, c ) ∈A × C | ∃b∈B :

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 12/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

1.3. relations 15

a
1
R -1( H )

a
2
R ( - 1) ( H )

THE B

1.2. figure. Inverse image and primeval

and Q ◦ P denoted.
The relation S ⊆ A × C is called a strict composition of P and Q relationships , if

S = { ( a, c ) ∈ A × C | ∃b ∈ B ( a, b ) ∈ P and ( b, c ) ∈ Q and P ( in ) ⊆ D },
Q

and Q ⊙ P denoted.
As in section 1.3. Also, the composition and the rigorous composition are generally shown
It does not match ( the , c ) ∈ Q ◦ P but is not an element Q P ⊙ unto. It's easy to see a
2 3
a strict composition is always part of the composition. It's not hard to see if either
at least one of the two relationships, or if the first partial function, a
two types of compositions are the same.

P Q
c
b 1
1
a
1
c
2
b
2

b
3

a
2
c
b 3
4

THE B C

1.3. figure. Composition and strict composition

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 13/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

16 1. BASIC PROVISIONS

If R ⊆ A × A then we say that R is a homogeneous relation. A homogeneous one


relationship can be composed itself. Based on this we define the power of R :
0
R :: = { ( a, a ) | a ∈ A},
and if n ∈ N,
n
R = = R ◦ R n- 1 .
The { ( a, a ) | a ∈ A} is also called a relation of identity , and is denoted by time
The relation R ⊆ A × A closes with the relation R ⊆ A × A , for which:
A.

(1) D :: = {a ∈ A | ∞
R ∃α ∈ A : α 1 = a and ∀i ∈ N: α i +1 ∈ R ( α i ) } and
k
(2) ∀a ∈ D R : R ( a ) :: = {b ∈ A | ∃k ∈ N 0 : b ∈ R ( a ) and b ∈ D R } .
The closed is thus interpreted in points from which the relationship is based
it can not be infinite many times in succession and is to such a point
points that are obtained by finite multiplication of the relation
we are out of the original domain's interpretation domain. So D ∩ R = ∅ always
met and ∀a ∈ D to the D ∈ and R ( in ) = {A} . Please note that this is
R R

R R
definition does not match what is termed a transitory termination .
The R ⊆ A × A relation is bounded closure of the the R ⊆ A × A relationship which:
(1) D = {a ∈ A | ∃k ∈N0:Rk a ( a ) = ∅} and
R a

(2) ∀a ∈ D R : R ( a ) :: = R ( a ).
Notice that a relationship is closed and its restricted closure may differ. The definition
it can be seen that this difference is only between the interpretative domains.
lentke can. However, this is a necessary condition for starting a suitable point
the relationship can not be used infinitely many times, but the finite multiplicity of applications
we can not limit it for long. Of course, this is only possible if
we can start infinite many finite sets of applications from the point. Let's look at this one
simple example: be R ⊆ Z × Z and
{
{a - 1 } if a> 0;
R(a)=
N, if < 0 .

Then Z = D = D =N .
R R 0

1.3.2. Logical relationships


Relationships R ⊆ A × L - where A is any set - for logical relations
called. For logical relationships we introduce some markings:
Let R ⊆ A × L. Then the truth set of R is:
⌈R⌉ :: = R - 1 ( {true} ) ,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 14/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
1.4. direct product 17

weakness of truth:
⌊R⌋ :: = R ( - 1) ( {true} ) .
If R is a function, then the truth set and the weak set of truths are the same.
Let H ⊆ A , the function A → L, whose truth set is H , H
is called a characteristic function of a set , and is designated P ( H ). The above definitions
It follows that you are basically a subset of a set
we are talking about the logical functions (statements) interpreted on the set, since they are
the concepts mutually clearly meet each other.
We will often use the same true and the same false functions:
True : A → L and ⌈Igaz ⌉ = A , False : A → L and ⌈Hamis ⌉ = ∅ . But also
A A A A
causing misunderstanding of the index is not written off.
Let R ⊆ A × A and π : A → L. The

R|π=R|
⌈Π⌉
∪ { ( a, a ) ∈ A × A | a ∈ ⌈π⌉ \ D R }
relationship is called a conditional relation , which is the narrowing and extension of the relationship a
condition, ie D = ⌈π⌉ .
R|π
Hereinafter, the termination or limitation of a conditional relation between the rela-
tion lezártjának on condition , and bounded on the condition lezártjának
we will call it.

1.4. direct product


We have previously defined the directives of two sets, now this term is
talánosítjuk.
Let A , i ∈ I be arbitrary sets, and X = {x | x : I → ∪ A } , ie X
i i∈I i
the I -t of the set of functions which -k into the union. That's it
i

×
A= A :: = {x ∈ X | ∀i ∈ I : x ( i ) ∈ A }
i∈ I i i

set for the , i ∈ I sets direktszorzatának called.


i
Set I is often the interval [ 1..n ], then the

×A
i=1 i

is used. In this case, we can say that the elements of the direct
an ordered n -esek. In general, the elements of the direct form are often arranged as well
n , assuming we can clearly decide which
which i ∈ I belongs to.
Note that I can be empty, in this case the direct form is only empty
set.

18 1. BASIC PROVISIONS

If J ⊆ I and K = I \ J then a
×
B= A
j ∈J j

direct product subspace and


' ×
A
B = k∈K k

a supplementary subdivision of A for A.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 15/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
The pr : A → B function projection is called when
B
∀a ∈ A : pr B ( a ) = a | J .
If J = {J} , the pr function j -th projection or j variable is also referred to.
B
Understand the projection of pairs, sequences, and sets:
for (( a , a )) = = ( pr ( a ) , pr ( a ))
B 1 2 B 1 B 2
pr ( < the of the ,... > ) :: = < pr B ( in 1 ) , pr B ( the two ) . . . >
for ( {a , a , ...}} ) = {pr ( a ) } ∪ {pr ( a ) } ∪. . .
B one two

B 1 2 B 1 B 2
The projection of couples is therefore a pair of components, the projection of the series is one,
the same length as the original, the elements of which are the original series
elements of its elements. The set is a set of projections, but it may be that the projection element
the number of pages smaller than the original was, for example, the projection of an infinite set
finite ones too.
× ×
We say that A = The direct product equivalent to B = B
i∈ I i j ∈J j
if there is a f : I → J is mutually clear
(bijection) that ∀i ∈ I : A = B f ( i ) . We can also say that interpretation
i
renaming elements obtained in the range of from B -t. It's easy to see that
we have actually defined an equivalence relation between the direct compounds.

1.5. function Spaces


If f, g : A → B functions and ⊕ an operation on B , ie ⊕ : B × B → B , then
we can define the function f ⊕g : A → B , such that
∀a ∈ A : f ⊕ g ( a ) = f ( a ) ⊕ g ( a ) .
For partial functions
D = {a ∈ A | ∈ D and ∈ D and ( f ( a ) , g ( a )) ∈ D }.
f⊕g f g ⊕
The function f, g , and a relation ≡ B ⊆ B relay define a logical function:
f ~ g : A → L and
{
true, if ∈ D and ∈ D and ( f ( a ) , g ( a )) ∈ II ;
∀a ∈ A : f ~ g ( a ) = false
f
anyway.
g

1.6. EXAMPLES 19

The logical functions thus obtained can be used as defined above


the usual logical operations: ∧, ∨, →, ≡, ¬ . Note that the definition
the following relationships immediately occur. Let p, q : A → L, then:

⌈P ∧ q⌉ = ⌈p⌉ ∩ ⌈q⌉,
⌈P ∨ q⌉ = ⌈p⌉ ∪ ⌈q⌉,
⌈¬p⌉ = A \ ⌈p⌉,
⌈P → q⌉ = ( A \ ⌈p⌉ ) ∪ ⌈q⌉.
The p = q mark if not ambiguous for p ≡ q meaning is used.

⌈P ≡ q⌉ = ⌈p⌉ ∩ ⌈q⌉ ∪ ⌈¬p⌉ ∩ ⌈¬q⌉.


The implication is often used to ⇒ sign instead of → what is the former
We use the term "follow", that is

p ⇒ q ⇔ ⌈p⌉ ⊆ ⌈q⌉.

Note that p ⇒ q and p → q = True is the same.


file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 16/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
The ∀ and ∃ signals so far as to use 'all' and 'there' Words ⋀
abbreviations. For the above
⋁ ⋀ ∀i ∈ I : ··· meaning⋁ i∈I · ·· , and
logical expressions,
∃i ∈ I : · · · meaning i∈I · ·· . If I = ∅ , i∈I · It is equally true, i∈I · ·· named
is equally fake.

1.6. Examples
1.1. Example: Write the elements of A × B , A × C , ( A × B ) × C and A × B × C ,
if A = { 0 , 1 }, B = { 1 , 2 , 3 }, C = {p, q} !
Solution:

A x B = { (0 , 1) , (0 , 2) , (0 , 3) , (1 , 1) , (1 , 2) , (1 , 3) },
A × C = { (0 , p ) , (0 , q ) , (1 , p ) , (1 , q ) },
( A × B ) × C = { ((0 , 1) , p ) , ((0 , 2) , p ) , ((0 , 3) , p ) , ((1 , 1) , p ) , ( (1 , 2) , p ) , ((1 , 3) , p ) ,
((0 , 1) , q ) , ((0 , 2) , q ) , ((0 , 3) , q ) , ((1 , 1) , q ) , ((1 , 2) , q ) , ((1 , 3) , q ) },
A × B × C = { (0 , 1 , p ) , (0 , 2 , p ) , (0 , 3 , p ) , (1 , 1 , p ) , (1 , 2 , p ) , (1 , 3 , p ) ,
(0 , 1 , q ) , (0 , 2 , q ) , (0 , 3 , q ) , (1 , 1 , q ) , (1 , 2 , q ) , (1 , 3 , q ) i}.

1.2. Let R ⊆ { 1 , 2 , 3 , 4 , 5 } × { 1 , 2 , 3 , 4 , 5 } .

R = { (1 , 2) , (1 , 4) , (2 , 1) , (3 , 4) , (3 , 3) , (3 , 5) , (4 , 5) }.

a) What are the interpreting domains and value sets of a relationship?

20 1. BASIC PROVISIONS

b) Is Relationship Deterministic and Functional?


c) Mi R 0 , 2 . power, what's the R inverse?
d) What is the inverse image of an { 4 , 5 } set, or its predecessor?
e) How many elements do the set of values of the set of values R have ?
Solution:
the)D = { 1 , 2 , 3 , 4 } ,
R
R ={1,2,3,4,5}.
R

b) Relationship is not deterministic, for example. | R (1) | = 2! Since the relationship is not de-
there is no terminological function.
c) Relationship 0 . the power of the identical mapping, ie:
0
R = { (1 , 1) , (2 , 2) , (3 , 3) , (4 , 4) , (5 , 5) }.
2
Since R = R ◦ R , we need to look at the points of how
apply twice in succession:

(1 , 2) - → (2 , 1)
(1 , 4) - → (4 , 5)
(2 , 1) - → (1 , 2)
(2 , 1) - → (1 , 4)
(3 , 4) - → (4 , 5)
(3 , 3) - → (3 , 4)
(3 , 3) - → (3 , 3)
(3 , 3) - → (3 , 5)

Based on the above table:


file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 17/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
2
R = { (1 , 1) , (1 , 5) , (2 , 2) , (2 , 4) , (3 , 5) , (3 , 4) , (3 , 3) }.
R ( - 1) based on the inverse inverse of the relation:

R = { (2 , 1) , (4 , 1) , (1 , 2) , (4 , 3) , (3 , 3) , (5 , 3) , (5 , 4) }.

d) Describe what the relationship is assigned to each point in the interpretation domain:

R (1) = {2,4}
R (2) = {1}
R (3) = {3,4,5}
R (4) = {5}

1.6. EXAMPLES 21

Based on the definition of inverse image:

R ( - 1) ( { 4 , 5 } ) = { 1 , 3 , 4 }.

Based on the definition of the original:

R - 1 ( { 4 , 5 } ) = { 4 }.

e) | ℘ ( R ) | = 2 | R R | = 2 5 = 32.
R

1.3. Example: Can any relationship be defined by the inverse image of an H set
and H set?
Solution:
Let R ⊆ A × B , H B ⊆ . At

R ( R ( - 1) ( H )) = R ( {a ∈ A | R ( a ) ∩ H = ∅} ) =

= R(a).
R(a)∩H=∅

Notice that in general we can not say anything about the two sets of vi-
since it is

1. If H ⊆ R , then H ⊆ R ( R ( - 1) ( H )) and
R

2. if ∃a ∈ R ( - 1) ( H ): R ( in ) ⊆ H , then R ( R ( - 1) ( H )) ⊆ H .

Consider this case in a simple example: Let A =B={1,2,3},R=


{ (1 , 1) , (1 , 2) } . Then H = { 2 , 3 } in case of R ( R ( - 1) ( H )) = { 1 , 2 } , i.e., one-way
no containment.
1.4. Example: Let R ⊆ A × B , P, Q B ⊆ . How to characterize it
R - 1 ( P ∪ Q ) and set R - 1 ( P ∩Q ) using the set R - 1 ( P ) and R - 1 ( Q )?
Solution:

R -1( P ∪ Q ) = {a ∈ D | R ( a ) ⊆ ( P ∪ Q ) }
R
⊇ {a ∈ D | R ( a ) ⊆ P} ∪ {a ∈ D | R ( a ) ⊆ Q}.
R R

However, there is no such thing as the other way, because there may be a ∈ D ,
R
lyre
R ( a ) ⊆ P, and R ( a ) ⊆ Q, but R ( a ) ⊆ P ∪ Q.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 18/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Let this with an example: Let A = B = { 1 , 2 } , R = { (1 , 1) , (1 , 2) } , P = { 1 } ,
Q = { 2 }. Then R - 1 ( P ) and R - 1 ( Q ) are empty, but R - 1 ( P ∪Q ) = { 1 }.

22 1. BASIC PROVISIONS

Let's look at the section now!

R -1( P ∩ Q ) = {a ∈ D | R ( a ) ⊆ ( P ∩ Q ) }
R
= {a ∈ D | R ( a ) ⊆ P} ∩ {a ∈ D | R ( a ) ⊆ Q}
R R
= R -1( P ) ∩ R -1( Q ) .

So we have proved that the predecessor of two sets of arbitrary sets is equal to the two
set of peppermint peppercorns.
1.5. Example: Let F ⊆ A × B, C × B ⊆ G . Is it true that

( G ◦ F ) ( - 1) = F ( - 1) ◦ G ( - 1) ?

Solution:

( G ◦ F ) ( - 1) = { ( c, a ) ∈ C × A | ∃b ∈ B : ( a, b ) ∈ F and ( b, c ) ∈ G}
= { ( c, a ) ∈ C × A | ∃b ∈ B ( b, a ) ∈ D ( - 1) and ( c, b ) ∈ G ( - 1) }
= F ( - 1) ◦G ( - 1) .

1.6. Example: Let F ⊆ A × B, C × B ⊆ G . Is it true that

∀Y ⊆ C : ( G ⊙ F ) - 1 ( Y ) = F - 1 ( G - 1 ( Y ))?
Solution: The definition of the strict composition immediately results if if ∈ A and
a ∈ D G then G ⊙ F ( a ) = G ( F ( a )) using this:
⊙F
( G ⊙ F ) -1( Y ) = {a ∈ A | a ∈ D and ( G ⊙ F ) ( a ) ⊆ Y}
F⊙G
= {a ∈ A | ∈ D and F ( a ) ⊆ D and G ( F ( a )) ⊆ Y}
F G
= {a ∈ A | ∈ D and F ( a ) ⊆ {b ∈ B | b ∈ D and G ( b ) ⊆ Y}}
F G
= F - 1 ( G - 1 ( Y )) .

**
1.7. Example: W = N × N × N . α ∈ W , where N = N ( i = 1 , 2 , 3). α = (1 , 1 , 1).
The other elements of1 the α 2series3 are obtained by first pointing
i the coordinates
1 of the points

starting with a coordinate, cyclically increased by 1. red ( pr1 × N 3 ( α )) =?


N
Solution:
First, write the first few of the series:

α = < (1 , 1 , 1) , (2 , 1 , 1) , (2 , 2 , 1) , (2 , 2 , 2) , (3 , 2 , 2) , (3 , 3 , 2) ... >

The projection of the α series for N × N :


1 3

for 1× N 3( α ) = < (1 , 1) , (2 , 1) , (2 , 1) , (2 , 2) , (3 , 2) , (3 , 2), ... >


N

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 19/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

1.6. EXAMPLES 23

Reduced by the above series:

red ( pr 1× N 3( α )) = < (1 , 1) , (2 , 1) , (2 , 2) , (3 , 2) ... >


N

From the above it can be clearly seen that the reduction exactly leaves the elements
out of the series in which the increase was made in the second component, so the
we get the elements of the series of results by increasing the coordinates by a cyclic one,
starting with (1 , 1).

1.8. Example: Let A = { 1 , 2 , 3 , 4 , 5 } and R ⊆ A × A .


R = { (1 , 2) , (1 , 4) , (2 , 1) , (3 , 4) , (3 , 3) , (3 , 5) , (4 , 5) } . We will be R closed and bounded
Closure?
Solution:
Since D = { 1 , 2 , 3 , 4 } , we only need to look at where we get from biz-
R
by repeatedly applying the relationship to 5. R (1) = { 2 , 4 } and R (2) = { 1 } , therefore
1 , 2 ∈ D , not 3, since every 3 can be from 3 to 3, 4 in one step,
R
5 out of a zero step to 5. Thus, R = { (4 , 5) , (5 , 5) } and R = R .

1.9. Example: A = { 1 , 2 , 3 , 4 , 5 }, R ⊆ A × A . R = { (1 , 2) , (1 , 5) , (2 , 5) , (3 , 2) , (3 , 4) , (5 , 2) } .
⌈Π⌉ = { 1 , 2 , 3 , 4 } . Write the relationship lockout condition. Solution:
R | π = { (1 , 2) , (1 , 5) , (2 , 5) , (3 , 2) , (3 , 4 ) , (4 , 4) } . The (5 , 2) omitted narrowing
, and (4 , 4) were included in the enlargement. R | π = { (1 , 5) , (2 , 5) , (5 , 5) } .

1:10. Example: Is there a non-empty relation and π condition that the relation is closed empty
set, and the term π for the condition is the same as the relation?
Solution:
Let A be any set. Obviously id = ∅ . If π = False , id | π = ∅ ,
A A
the closure of which date .
to

1:11. Example: R ⊆ N × N .
0 0
{
{a - 2 }, if > 1;
R(a)= k
{ 2 | k ∈ N }, if a = 1 .
What is the R Closing and Limiting Closure?
Solution:
D = N. For each a , if the pair, the relation assigns 0 in step / 2
R
and only if it is odd, the 1st, the image of which is all doubles.
Due to the dual potentials, since they are both even, the repeated use of R will lead to 0. so
D = N , and naturally ∀a ∈ N : R ( a ) = { 0 } .
R 0 0
Since there is no upper bound for the dual power, therefore,
doesD not include
R
lan numbers.
k k
Note that if the task is { 2 | k ∈ N } instead of { 2 | k ∈ N } szere-
dia, D would not contain odd numbers. 0
R

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 20/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

24 1. BASIC PROVISIONS

1.7. Tasks
1.1. At least, or at most, how many elements have an element of m and a set of n elements

- section; - unification;
Descartes product; - difference?

1.2. Prove that H ⊆ A × B in case


- ( ∀ ( a, b ) , ( c, d ) ∈ H : ( a, d ) ∈ H ) ⇔ ( ∃ K ⊆ A : ∃L ⊆ B : H =
K × L );
- if H is not empty then K and L are clear.

1.3. R ⊆ A × B . Since equal R - 1 ( B )?

1.4. R = { (( x, y ) , ( x + y, y )) | x, y ∈ N } . What is H = { ( a, b ) | a, b ∈ N and a + b < 5 }


the inverse image of a set, or its antecedent?

1.5. R = { (( x, y ) , ( x + y, y )) | x, y ∈ N } ∪ { ( x, y ) , ( x - y, y )) | x, y ∈ N } . What the


H = { ( a, b ) | the inverse image of an a, b ∈ N and a + b < 5 } , or an antecedent?

1.6. R = { (( x, y ) , ( f ( x, y ) , y )) | x, y ∈ N } , where f : N × N → N. What is H =


{ ( a, b ) | the antecedent or inverse image of the set a, b ∈ N and a + b < 5 } ?
1.7. R ⊆ A × B ⊆ Q B . Is there any relation between R - 1 ( B \ Q ) and
between the set A \ R - 1 ( Q )?

1.8. Create a non-empty relationship that is true for all its value sets
the true primordial subset of idols is an empty set!

1.9. Let F be G ⊆ N × N , Y = { 1 , 2 } . F = { ( a, b ) | b | a and b = 1 and b = a} .


G = { ( a, b ) | 2 | a and a = 2 b} .

G ◦ F =? G ⊙ F =?
F ( - 1) ◦ G ( - 1) =? F - 1 ( G - 1 ( Y )) =?
( G ◦ F ) - 1 ( Y ) =? ( G ◦ F ) ( - 1) =?

1:10. Let A = { 1 , 2 , 3 , 4 , 5 } , R ⊆ A × A , R = { (1 , 2) , (1 , 4) , (2 , 1) , (3 , 4) , (3 , 3),


(3 , 5) , (4 , 5) } , f⊆ A × L and f = { (1 , i ) , (2 , i ) , (3 , i ) , (4 , h ) , (5 , i ) } . We f ,
and ( f ◦ R ) the truth set and the weak set of truths?

1:11. R, Q ⊆ A × A . Is it true that ( R ⊙ Q ) ( - 1) = Q ( - 1) ◦ R ( - 1) ?

1:12. F ⊆ A × B, C × B ⊆ G . Is it true that ∀Y ⊆ C : ( G ◦ F ) -1( Y ) =


F - 1 ( G - 1 ( Y )) . Is the statement true if G or F is a function?

1.7. TASKS 25

1:13. F ⊆ A × B, C × B ⊆ G . Is it true that ( G ⊙ F ) ( - 1) = F ( - 1) ⊙ G ( - 1) . Is it true


is the statement if G or F function?
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 21/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

1:14. What is the range of interpretation of the composition of two relationships?


the interpretation of the strict composition of the same two relations
among the dwarves?
1:15. Create a non-empty R relation and f logic function to f ◦R
the truth set is empty!
2 2
1:16. R ⊆ A × A . Is it true that ( R ( - 1) ) = ( R ) ( - 1) ?
2
1.17. R ⊆ A × A . Is it true that ∀H ⊆ A : R - 1 ( R - 1 ( H )) = ( R ) - 1 ( H )?
1.18. P, Q ⊆ N × N. Q = { ( a, b ) | 2 | a and b | a and b prime } .

a) P = { ( a, b ) | b | a and b = 1 and b = a}
b) P = { ( a, b ) | b | a}
Enter Q ( - 1) , Q ◦ P and Q ⊙ P relation.

1.19. H ⊆ A × B × G B ⊆ C ⊆ C D × D . Are the following statements true?


a) If ∈ D ∩D then G ◦ H ( a ) = G ⊙ H ( a ).
G◦H G⊙H
b) D
G⊙H
⊆ D
G◦H
.
c) ( ∀a ∈ D : | H ( to ) | = 1) ⇒ G ◦ H = G ⊙ H .
H
d) D = B ⇒ G ◦ H = G ⊙ H .
G

1:20. Associativity: H A × B ⊆ G × B ⊆ C ⊆ C D × D . It is true:

(F◦G)◦H =F◦(G◦H),
( F ⊙ G ) ⊙ H = F ⊙ ( G ⊙ H )?

1.21. Let Q, R, S ⊆ A × A and enter the following mark: if X ⊆ A × A


any relation, then complement X :
X = { ( a, b ) ∈ A × A | ( a, b ) ∈ X}.

Is it true that
Q ⊙ R ⊆ S ⇐⇒ Q ( - 1) ⊙ S ⊆ R
?
Is this statement true for a non-strict composition?
1.22. Let Q, R, S ⊆ A × A . Is it true that
R⊆S ⇒ R ⊙ Q ⊆ S ⊙ Q,
R⊆S ⇒ Q⊙R⊆Q⊙S ?

26 1. BASIC PROVISIONS

1.23. Let R and Q be two relationships on the set of natural numbers. R is a natural one
denotes itself and its doubles, Q for a pair of natural numbers a
half.

a) Write down the two relationships and add their range of interpretations.
b) Write down the R relation k . power ( k ≥ 1) and this interpretation
tomany!
c) Write the relation Q ◦ R and its interpretation range.
d) F = Q R ⊙ . Write the Relationship F and the Interpretation Range.

1.24. F ⊆ A × B , G ⊆ B × C . Is it true that:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 22/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
a) D F = F - 1 ( D ),
G⊙ G
b) D F = F - 1 ( D )?
G◦ G

1:25. P ⊆ N × N . P = { ( a, b ) | b | a and b = 1 and b = a} . What will P be closed and


0 0
boundary closure?

1.26. R ⊆ N × N. R = { ( a, b ) | b | a and b = 1 and b = a} . ⌈Π⌉ = {x | ∃k ∈ N : x =


k 0
2 } . Write the R | relation, closure and boundary closure!
π

1.27. Give an example to a non-empty relation that closes empty set and is
is a condition π that the interpretation of the termination of the relation on condition
its range is the same as that of the original relationship.

1.28. R ⊆ A × A . Let's suppose the R domain is equal to


R domain of R archetype for PM. What can we say R
lezártjáról?

1.29. R ⊆ N × N . {
0 0
{a - 3 }, if > 2;
R(a)=
{ 3 k | k ∈ N }, if a = 1 .
What is the R Closing and Limiting Closure?

1:30. R ⊆ N × N. The relation R for each complex number is the largest real os-
order. Let q

(a) a fixed composite natural number,


b) a fixed prime number.
k
Let ⌈P ⌉ = {a ∈ N | ∃k ∈ N: a = q } . What will be the relation R P q condition
the relevant
q section of the relevant closure?

1.7. TASKS 27

1.31. R ⊆ N × N .
0 0

{b | ∃k ∈ N : b = 2 k + 1 } if x = 0 and x are even;


0
{x - 7 }, if x ≥ 7 and x are odd;
R(x)=
À { 0 }, if x = 1;
{ 7 }, if x = 0 .

What will be the closure and boundary closure of R ?


1.32. R is as defined in paragraph 1.29. relationship given in task. ⌈Π⌉ = {k ∈ N | 2 | k} . Enter it
R | π relation, closure and boundary closure!
1:33. Are the following statements true?

a) If a ∈ D ∩ D , then R ( a ) = R ( a ).
R R
b) D
R
⊆D R .
c) If the set is finite and R ⊆ A × A , then R = R .
d) If A is counted infinitely, R ⊆ A × A , and
∀a ∈ A ( ∃n ( the ) ∈ N 0 : | R ( in ) | ≤ n ( to )) ⇒ R = R .
1.34. Let R ⊆ N × N .
0 0
{
{b | b> 0 and b <x and 2 | b} if x is odd;
R(x)=
{x - 1 }, if x is even;
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 23/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

⌈Π⌉ = {x ∈ N | 2 | x} . What is the relation of R with the π condition is closed and bounded
Closure?

1.35. At most, or at least how long a series of lengths m and a is n


reduction of his reduced and concatenation?
1.36. Is it true that the projection of an α series reductor is as long as it is
Reduced by the α series?
1.37. Is it true that an α series projection reduces it to the same length
Reduced by the α series?
1.38. Let A = N × N × N × N , B = N × N , where N = N ( i ∈ [1 .. 4]).
1 2 3 4 4 1 i

α = < (1 , 1 , 1 , 1) , (1 , 2 , 1 , 1) , (1 , 2 , 3 , 1) , (1 , 2 , 3 , 4) ,
(5 , 2 , 3 , 4) , (5 , 7 , 3 , 4) , (5 , 7 , 10 , 4) , (5 , 7 , 10 , 14) . . . >

a) pr ( α ) =?
B
b) red ( pr ( α )) =?
B

Chapter 2

Basic concepts of programming

In this chapter we introduce the most important basic concepts of programming. Very
it is important to note our attention not on the properties of the programs,
but to turn it into making programs. That is why we ask the question why we are writing
program? The answer to this question determines the direction of our thinking. THE
Our answer is that because we have something to be solved, we have a problem. so
the starting point of our thinking is to have something to do
and this task determines the goal to be achieved.
In practice there are many different tasks. What do they have in common? This is also a question
can be approached in several ways. In our approach, the essence of the task is,
to determine what state we are in and what state we want to reach.
The state of affairs depends on the specific problem. For example, if we want a car
to prepare for a longer journey, you can characterize how much your tank is in
gasoline, how much is the window washer fluid, what is the pressure on the wheels, does it work?
the direction indicator and so on. The point is, there is a feature of the system,
the possible values of these characteristics form one set. Such a set can be
the number that expresses the quantity can be either {works, or works} .
If you select one of the set of possible values for each of these attributes
we get a possible state of the car. It is only a lack of notice
let's take, the set of possible states is a direct source mathematically.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 24/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

2.1. The concept of state space


The first abstract concept to be introduced is the fish-
maza.

2.1. DEFINITION : LICENSE


Let I be a finite set and let A , i ∈ I be finite or finite,
i

30 2. THE BASIC CONDITIONS OF PROGRAMMING

×
Countable, non-empty sets. Then A = Set is state-
i∈ I i

space , and sets A are called type sets .


i

When we make a model, we have to decide which part of reality


we want to model and what are the characteristics - and what values they can add
- which we want to take into account in our model.
In the above definition of state space, consider each component as
the set of possible values for some attributes. The type value set is named
indicates that these sets consist of elements with a certain common property
It does. Later on, we will also discuss what this common property means.
Since the value set of attributes may be the same, one of the components of the state space is one
set can be multiple times.
We have stipulated that the state space has only a finite number of components. It could be
a more general definition is given so that we do not bind the integrity of the set I at this time
the status space defined above is called a (finite) view of the generalized state space.
The fact that the components can be counted up to a maximum means that the components
there should be no substitute for example. the set
√ of real numbers. Of course, that√
even one type set can include 2 as well. The {x | ∃ n ∈ N: x = n }
can be a state space component.

2.2. The task


The concept of state space allows us to easily formulate what we mean
task. We have to say that a state (ie state space
from an item, its point) to what state (ie the state of the state)
to get to.

2.2. DEFINITION : F ELADATION


Task is called an F ⊆ A × A relation.

The above definition of task is naturally derived from the one task
is considered a mapping in the state of the state, and we are told at every point in the state space,
where to get to it if you have to get to it somewhere.
What a task will have on its status, of course, from the task itself
depends, but even with the knowledge of the task, it is unclear. For example, a dot planar co-
ordinates can be entered in a right-angled coordinate system, but you can specify polar-
ordinates.
Yet, what we choose as a state of affairs is very important,
what can we describe and how can we describe it later? If too few features are tested
- that is, the state space is too few components - then there are concepts that,
which we can not describe if there are too many components, then unnecessarily over
the model will be complicated.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 25/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

2.2. THE TASK 31

Consider the simple task of combining two natural


mot. The status space can be chosen in a rather straightforward way to three components.
The three components are the two sums up and the sum. So A = N × N × N, and
task
F = { (( a, b, c ) , ( x, y, z )) ∈ A × A | a + b = z,
or
G = { (( a, b, c ) , ( x, y, z )) ∈ A × A | b = x and c = y and a + b = z}.
The two tasks are different, though both are about the sum of two natural numbers. THE
The difference between them is that task F does not say anything about what it is
with G, and stipulate that they remain unchanged.
It is suggested that the two-state state space would not be enough? Let A =
N × N and
H = { (( a, b ) , ( x, y )) ∈ A × A | a + b = x}.
However, this task would not be interpreted as "adding two natures
number ", but by" increasing a natural number into a natural one
number ".
We note that they often formulate a task called so-called "input-output"
what kind of output data is assigned to the input data. This
the separation would not be a problem for tasks F and G , but similar to H
problems could be problematic, not to mention the introduction mentioned
car task. The real benefits of the state model will be felt later
We will.
It should be noted that, according to the definition, the task relationship,
nondeterministic bowls, such as G and H . Non-determinism is, however
even more "meaningful". Let the task be as follows:
natural number of a natural number (without changing the number)! In this case
A = N × N and

F = { (( a, b ) , ( x, y )) ∈ A × A | a = x and y | x and x = y and y = 1 }.


For example (6 , 5), point F is { (6 , 2) , (6 , 3) } . The 6 have 2 and 3 are real os-
, ie | F (6 , 5) | = 2.
It is very important to see the difference between the previous task and the
Next: Determine all real distributors of a natural number! in this
in that case, the status space will
'
be different as it is a real divisor of a natural number
not a number, but a set. So A = N × F, where F is the finite particle N,
mazai set.
G = { (( a, b ) , ( x, y )) ∈ A × A | a = x and y = {n ∈ N | n | x and x = n and n = 1 }}.
' '

Now | G (6 , { 5 } ) | = 1 and G (6 , { 5 } ) = { (6 , { 2 , 3 } ) } .
Note that D = A , for example (5 , 5) ∈ D , but D = A , for example
'

(5 , { 5 } ) ∈ D and G (5 , { 5 } ) = { (5 , ∅ ) } .
F F G

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 26/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

32 2. THE BASIC CONDITIONS OF PROGRAMMING

2.3. The program


When we try to clarify the concept of the program, the programs running on the computer
and we are watching the algorithms they implement. If a computer has a prog-
ram "runs", it means that the contents of the computer's memory are flow-
atosan varies. Here, the "memory" is commonly understood, we include the narrow one
from the memory through the registers to the screen everything that can be
DOZ.
A feature of a program is "working", ie dynamic in time
process. Dynamic systems are generally more difficult to handle,
like static ones. This is why we are thinking of replacing a dynamic flow-
atot with a static model?
Consider, for example, the following - far from programming - a problem.
There is a chemical experiment that is too fast to take off,
you can register successive events. This is similar to program running.
which is a dynamically running process at the same time. How can you keep track of
experiment? For example, taking the experiment as a film, and later the frames
are checked for static states. So the time changing process is one
with a static status line.
The example above illustrates how to add a static model to a di-
namic process.
In the definition of the program, the former is characterized by a timely running of the program
An example is analogous to introducing a static model: run-state serial-
with a case. As the memory content changes during the program run,
we went to newer and more points in the state of the state so these points were drawn in a series
we actually "take the film" for the film.

2.3. DEFINITION : P ROGRAM


**
We call the relation S ⊆ A × A , if
1. D = A ,
∀αS ∈ R S : α = red ( α ),
Second
∀a ∈ A : ∀α ∈ S ( a ): | α | = 0 and α = a .
Third
1

With the above definition we want the concept of "operation" in an abstract way,
, this explains the terms of the series. The first property is that
means that the program assigns at least one of the points to the total state space
series, meaning that the program "does" anything at all points. The "malfunction"
it is also described by the operation, that is, with a series of attributes and sequences.
The second property expresses that the set of values in the program is a series-
which do not contain the same element in succession. Exactly,
if this happens, then this element repeats infinitely many times. The operation ab-
whether the condition changes or, if not, is abnormal
operation sign. We remind you that everything in the status space is all

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 27/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

2.4. THE PROGRAMMING 33

so if anything happens, it means a point in another condition. It's that


to a point in a state space, the program assigns an infinite sequence, meaning that the prog-
ram does not end.
The third property only means that the sequence of operations is complete
history, including the starting state, so that a program is one
starting with a point, does not do anything, one of these is one point, one length
series.
The program is also defined as a relationship, meaning that there are more than one status point
series can be assigned, ie operation is non-deterministic. This is a first-
perhaps surprising, actually natural. Naturally even when on a computer,
we think of a program running on a computer system, since a program has many process-
times, in a system of many, even spaced apart components
running. But it is natural if we consider that the concept of the program is nonc-
the program running on the machine, but the abstraction of the algorithm that they may have
"Left open" parts.

2.4. The program function


Now we will return to the car example at the beginning of this chapter. The task was to
prepare the car for a longer journey. Depending on the status of the car,
which is what its features have: how much gasoline,
what is the pressure on the wheels, does the sequence of actions of the direction indicator function work
do it, pump the wheels, replace an bulb and so on, step by step
the status changes, the program works. If you finally get into a car,
that you can safely go on a longer journey then the program
solved the task.
In order to examine the relationship between a program and a task, it is sufficient if a
we know from the point of view of a state of the state space what state of space is
because the intermediate states are irrelevant for the solution.
Because of the above, we introduce the concept of the program function, which is the program
the result of its running.

2.4. DEFINITION : P ROGRAMPHONE


**
The relation p ( S ) ⊆ A × A is the program function of S ⊆ A × A , if
*
1. D p ( S ) = {a ∈ A | S ( a ) ⊆ A } ,
2. p ( S ) ( a ) = {b ∈ A | ∃α ∈ S ( a ): τ ( α ) = b} .

The first requirement states that it is only in those points


it's a good idea to look at where a program comes from, starting from the program
"Goes away". The second point describes where the program is going to be
the last element of the series.

34 2. THE BASIC CONDITIONS OF PROGRAMMING

If the program function of two programs is the same, it means the two programs
the result of its operation is the same. So let's say in this case that the two
program equivalent.
The function of the program function can be misleading, since a program program-
function is not necessarily a function, nor can it be a deterministic relation
(partial function). It expresses the meaning of the concept more accurately .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 28/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
We will use both of them.
It should be noted that, apart from the program function,
characteristics that relate to the quality of the program and
it does not matter how the program solves the task (such as
for example, the efficiency, the time and space requirements of the program), but will continue to do so
we are not dealing with it for the time being.

2.5. Solution
It is important that the program function is the same type of relationship as the task. so
so by introducing the concept of program function, we have the opportunity to do so
create a connection between a particular task and a particular program. Naturally
this relationship has to describe when to say about a program that it is
solve a given task.

2.5. DEFINITION : M APPLICATION


We say that S program solves the F task if
1. D ⊆ D p ( S ) ,
F
∀a ∈ D : p ( S ) ( a ) ⊆ F ( a ).
Second
F

D p(S) F(a)

the p(S)(a)
D
F

THE THE

2.1. figure. Solution

2.6. PROGRAMMING TASK 35

This definition will ultimately require that the state of the state
where the task is interpreted, the program only assigns finite sequences (ter-
min) and assign the endpoints of the series to the starting point.
Sometimes it is difficult to understand this definition. Why is the program-
is part of the image of the job? "So we can not get it all
solution! "But just think of the car example. For example, brake fluid level
must be between the minimum and maximum levels. This is maintenance
as a result, but it is unclear what will be the set
level. There is no point in setting "all possible levels".
Many times the question arises whether there is a relationship between two tasks
point of view. The following definition is related to this.

2.6. DEFINITION : S INSURANCE


We say that F ⊆ A × A task stricter than the F ⊆ A × A
1 2
task if
1. D
F
2 ⊆ DF 1 ,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 29/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
∀a ∈ D
Second F F
F2 : 1( a)⊆ 2( a ).
Compared to the definition of the tightening, the definition of the solution is easily attributed to
next simple but important statement:

2.1. statement: If F stricter than F , and S is F , then S is the solution


1 is 2 1
F too.
2

We also note that in the definition of the solution we did not rule out the
program and task status. The following statement is related to this:

2.2. statement: If the solution of S is F 1 ⊆ A × the function , then F 2 ⊆ B × B also


and F = F , then solution S for F ,
1 2 2

2.6. Programming task


Is there a solving program for any task? Let F = A × A . define
S as follows: ∀a ∈ D : S ( a ) = {red ( < a, b > ) | b ∈ F ( a ) } and
∀a ∈ F F : S ( a ) = { < a ,. . . > } . It isF obvious that p ( S ) = F , so solution S is F -
s. That is, for any task we can easily do a solving program. from this
starting from thinking that programming is a very simple task. Of course
not true. The task of programming is, in fact, much more complex because a program-
we have to put together programs based on fixed rules, for example one
we have to use programming language tools.

36 2. THE BASIC CONDITIONS OF PROGRAMMING

2.7. DEFINITION : P ROGRAMATION TASK


×
Let A = A . A programming task is called the ( F, P , K)
i∈ I i
mast where F ⊆ A × A is a task; P primitive (allowed) programs are finite
**
set ∀S ∈ P: S ⊆ A × A ; K the allowed program configurations are finite
A set ∀k ∈ K one of the read n the set of programs
operation.

2.8. DEFINITION : SOLVING THE P ROGRAMATION TASK


The solution of the program S ( F, P , K) is S if S is the primitive
programs may be permitted constructions and solve F unto.

The programming task can be generalized in two ways: one can expand
under the terms of the program's operation [Hor 98], in this book
we do not deal with it. On the other hand, we do not require the same status space for this
we generalize the concept of the solution and introduce the type specification, type,
compliance and the concept of type designs.
The kind of program design we give depends on what it is
we will only deal with the simplest ones, as these are enough
to solve a programming task.
We are now drawing attention to the important aspect of being really great
we often do not follow the path of putting together existing programs
solving program, but the task is broken down into subtasks by making them
solving programs "automatically" get the original job solving
program.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 30/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

2.7. Examples

2.1. Let A = { 1 , 2 }, A = { 1 , 2 }, A = { 1 , 2 , 3 , 4 , 5 }, A = A × A ×
1 2 3 1 2
A . F = { (( a, b, c ) , ( d, e, f )) | f = a + b}. F (1 , 1 , 1) =? How many points is that
3
state for which the task assigns the same to (1 , 1 , 1)?
Solution:
F (1 , 1 , 1) = { (1 , 1 , 2) , (1 , 2 , 2) , (2 , 1 , 2) , (2 , 2 , 2) }.
Because assignment assignment does not depend on the third component of the state space,
assigns the same points to all (1 , 1 , * ) points. For other points
but you can not assign the same points because the amount could not be 2!
So there are five points for the status field to which the task is assigned the same
to (1 , 1 , 1).
**
2.2. Let A = { 1 , 2 , 3 , 4 , 5 }, S ⊆ A × A .

2.7. EXAMPLES 37

S={ (1 , < 1251 > ) ,(1 , & lt; 14352 & gt (1


; ),,< 132 ... > ) ,(2 , & lt; 21 & gt ; ) ,
(2 , < 24 > ) , (3 , < 333333 ... > ) ,(4 , & lt; 41514 &(4gt, & ; ) lt;
, 431251 & gt ; ) ,
(4 , & lt; 41542 (5& ,gt<;524
), >), (5 , & lt; 534 & gt(5; ,) <, 5234 > ) }
F = { (2 , 1) (2 , 4) (4 , 1) (4 , 2) (4 , 5) } .
a) Give p ( S ).

b) Does S solve the task?

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 31/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

38 2. THE BASIC CONDITIONS OF PROGRAMMING

Solution:
a) Since the program assigns an infinite sequence to 1 and 3,
Function Interpretation Range:

D p ( S ) = { 2 , 4 , 5 }.

Then the program function:

p ( S ) = { (2 , 1) , (2 , 4) , (4 , 4) , (4 , 1) , (4 , 2) , (5 , 4) }.

b) We need to see two points of the definition of the solution.


i. D = { 2 , 4 } ⊆ { 2 , 4 , 5 } = D p ( S ) .
F
ii. p ( S ) (2) = { 1 , 4 } ⊆ { 1 , 4 } = F (2)
P ( S ) (4) = { 4 , 1 , 2 } ⊆ { 1 , 2 , 5 } = F (4) ,
so the S program is not a solution to task F.

2.3. Example: Express the programs function of the programs union


programfüggvényeivel!
**
Solution: Let S , S ⊆ A × A programs. This is the program function
1 2
definition of the domain of interpretation:
*
D p ( S1 ∪S 2 ) = {a ∈ A | ( S ∪ S 2 ) ( *a ) ⊆ A } =
1 *
= {a ∈ A | S ( a ) ⊆ A and S ( a ) ⊆ A } =
1 2
= D p ( S1 ) ∩D p ( S 2 ) .

Let a ∈ D p ( S 1) ∩D p ( S 2 ). Then

p(S
1
∪ S 2 ) ( a )= {τ ( α ) | α ∈ ( S
1
∪S2)(a)}=
= {τ ( α ) | α ∈ S ( a ) or α ∈ S ( a ) } =
1 2
= p(S )(a)∪p(S )(a).
1 2

2.4. Example: Let F and F a job in the same state. Is it true that
1 2 be
If all programs that solve F unto the solution F is also recorded, and all
1 2
program that solve F unto the solution D is also recorded, the F and F mege-
2 1 1 2
gyeznek?
Solution: The most common bug used to resolve this problem
to follow, is to confuse the statement of the claim with the evidence itself
and try to prove that each of the tasks of any of the
ram solution. Of course, this is not true, but it is not the job! therefrom
we must therefore start from exactly the same programs that solve both

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 32/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

2.7. EXAMPLES 39

and we need to look at whether this is the two tasks


agree.
Let's start by saying that any program that is solved by F is the
1
solution to F , and select a program whose program function
2
is equal to F . Then the chosen program trivially resolves it
1
F , so it should also solve F , ie:
1 2

i. D
F
⊆ DF2 1 ,
ii. ∀a ∈ D F F F
: 1( a ) ⊆ 2( a ) . 2

I use that all the programs that solve F unto the solution
2
F , and by selecting a program whose program function pre-
1
is taken with F , analogous to the foregoing in reverse order statements:
2

iii. D
F
⊆ DF 1 2 ,
arc. ∀a ∈ D F F F
: 2( a ) ⊆ 1( a ) .1

The i. and iii. It follows from the assertions that the interpretation range of the two
are the same, while ii. and iv. assertions guarantee that this common interpretation range
for each point, both tasks assign the same points, ie F = F .
1 2

2.5. Example: F ⊆ F . The S program solves F -t. Is it true that S solves F too?
1 2 2 1
Solution: Let's try to prove the statement. This is the definition of the solution
we have to see two points.
i. D
F
1 ⊆ D p(S),
ii. ∀a ∈ D F : 1 p ( S ) ( a ) ⊆ F ( a ).
1

The i. Point met easily seen, because S solution F unto so


2

D 1
F
⊆D F ⊆D p ( S ) .
2

The ii. However, it is problematic to prove the point, since the two following statements are
delkezésünkre:

∀a ∈ D F : 1 p(S)(a)⊆F (a),
2
∀a ∈ D F : 1 F (a)⊆F (a),
1 2

and the desired statement can not be proved. We have come to a standstill, it may be
is not the statement true? Let's make a counter-example using where we got it
proofs!
Let A = { 1 , 2 } , F = { (1 , 1) } , D = { (1 , 1) , (1 , 2) }, and P ( S ) agree
1 2
with the F task. Then S trivially solves F , but does not solve F ,
2 2 1
namely
1 ∈D 1 and p ( S ) (1) = F 2 (1) = { 1 , 2 } ⊆ { 1 } = F 1 (1) .
F

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 33/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

40 2. THE BASIC CONDITIONS OF PROGRAMMING

So the statement is not true.


**
2.6. Example: Let S and S ⊆ A × A programs, F ⊆ A × A and duty.
Suppose that S ⊆ S1 and S2 solve the function F. Is it true that S
1 2 2 1
solve F ?
Solution: If S ⊆ S , what can we know about their program function? Let's look first
1 2
the interpretative ranges! By definition, min-
den program assigns at least one sequence, such as S and S . Since S ⊆ S
1 2 1 2
so it is only possible to add S sequences to a given point,
2
of what S does not. If these series are all finite, then that is the point you are
1
it is included in the interpretation range of both programs' program functions,
or one of them; if there is infinite among them, that point is definitely not a component
p ( S ), but can be an element of D p ( S 1 ) -nek.Tehát D p ( S 2 ) ⊆D P ( S 1 )

and ∀a ∈ D p 2( )S: P ( S ) ( in ) ⊆ P ( S ) ( in ).
2

Since the solution of S is F then D ⊆ D p ( S 2 ) and ∀a∈D F : P ( S ) ( in ) ⊆ M ( to ).


1 2

Because of the above, D ⊆1 )D p(∀


S a∈D F : p ( S ) ( a ) ⊆ F ( a ) is also satisfied, ie S
2 F 2
and
F 1 1
We can solve F unto.

2.8. Tasks
**
2.1. Let A = { Ω , Φ , Ψ , Θ , Γ }, S ⊆ A × A .
S={ (Ω , < ΩΦΓΩ > ) , (Ω , < ΩΘΨΓ > ) , (Ω , < ΩΨΦ ... > ) ,
(Φ , < ΦΩ > ) , (Ψ , < ΨΘ > ) , (Ψ , < ΨΨΨΨΨΨ ... > ) ,
(Θ , < ΘΩΓΩΘ > ) (Θ, , < ΘΨΩΦΓΩ > )(Θ, , < ΘΩΓΘΦ > ) ,
(Γ , < ΓΦΨ > ) , (Γ , < ΓΨ > ) , (Γ , < ΓΦΨΩ > ) }

F = { (Φ , Ω) (Φ , Ψ) (Θ , Ω) (Θ , Φ) (Θ , Θ) } .

a) Give p ( S ).
b) Does S solve the task F ?
2.2. Let S program, F is a task that S solution F unto. Is it true that
a) if F is non-deterministic, then S is it not?
b) if F is deterministic then S is it?
c) if F is non-deterministic, then p ( S ) is not it?
d) if p ( S ) is deterministic, then F is the?
e) if F is deterministic, then p ( S ) is the?
f) if S is non-deterministic then p ( S ) is not it?
*
2.3. It true that P ( S range of values) was the archetype S respect to?

2.8. TASKS 41

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 34/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
2.4. We can say that S program solves F if the next is true
statement:
*
q∈D
⇒S(q)⊆A and P ( S ) ( q ) ⊆ M ( q )?
F

2.5. Let A = N × N, M , M ⊆ A × A .
1 2
F = { (( u, v ) , ( x, y )) | y | u} ,
1
F = { (( u, v ) , ( x, y )) | x = u and y | u} .
2
Are the two tasks the same? (Is there any connection between them?)
2.6. F ⊆ A × A . S , S programs A -n. The S and S can solve the F function.
Is it true that program S = ( S ∪ S ) also solves F task?
1 2 1 2

1 2

2.7. Consider the following textual assignment: Provided by a chess board and
the position of two bastions on it. Place a third bastion on the board,
to be in the blow of both. Prepare the model: write it up
state space and relation F !
2.8. We know that S solves F eth (in the status field). Is it true that if ∈ A ,
then
*
S ( a ) ⊆ A or p ( S ) ( a ) ⊆ F ( a ) ⇒ a ∈ D ?
F
** is
2.9. Let F ⊆ A × A be a job and S ⊆ A × A a program. Marked with FP
the relation between F and p ( S ). Is it true that
a) If D = D , then S solves F ?
FP F
b) if S solves F , then D =D ?
FP F

Chapter 3

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 35/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Specification
The definition of the solution can be used quite directly from the
since a program solves a task, the solution is so far
it is difficult to verify by definition. That is why we introduce some new concepts,
then we give them a sufficient condition of the solution.

3.1. The weakest prerequisite


First, enter the result of the operation of the program for a program function
more convenient feature.
3.1. DEFINITION : MORE THAT ŐFELTÉTEL
** be a
Let S ⊆ A × A program, R : A → L. Then the program S is R
is the weakest prerequisite for the following condition: lf ( S, R ): A → L
which:

⌈Lf ( S, R ) ⌉ = {a ∈ A | ∈ D p ( S ) and p ( s ) ( a ) ⊆ ⌈R⌉}.


The weakest prerequisite is exactly in those points where
Starting from the S program will surely point, and it all possible endstate R .
Of course, they may be beyond the truth of the weakest prerequisite
points from which a run of the program reaches the truth of the post-condition, only
those points are not guaranteed to get there.
The operation of a program can be characterized by specifying the program as well
the most vulnerable prerequisite for the latter. When solving this problem, a
our goal is to find a program that meets certain criteria
point terminals. Therefore, we can say that if we have a favorable end
the weakest prerequisite of the program, the program function will
without defining the program.

44 3. SPECIFICATION

It is recalled that we have also defined the concept of the old-fashioned relationship as well
you can see immediately
⌈Lf ( S, R ) ⌉ = p ( S ) - 1 ( ⌈R⌉ ) .
Using the definition of the truth set and the ancient composition of the strict composition
property:
P ( S ) - 1 ( ⌈R⌉ ) = p ( S ) - 1 ( R - 1 ( {true} )) = ( R ⊙ p ( S )) - 1 ( {true} ) = ⌈R ⊙ p ( S ) ⌉.

Since the function R , the composition and the strict composition are the same, then
3.1. statement:
⌈Lf ( S, R ) ⌉ = ⌈R ◦ p ( S ) ⌉.
In case p ( S ) is a function, lf ( S, R ) = R ◦ p ( S ).
The above contexts will often be referred to.
The next item is some of the most prominent features of the weakest prerequisite
speak.
3.1. COMPOSITION : The Z lf FEATURES
**
Let S ⊆ A × A be Q, R : A → L statements. At
(1) lf ( S, False ) = False ,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 36/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
(2) if Q ⇒ R , then lf ( S, Q ) ⇒ lf ( S, R )
(3) lf ( S, Q ) ∧ lf ( S, R ) = lf ( S, Q ∧ R )
(4) lf ( S, Q ) ∨ lf ( S, R ) ⇒ lf ( S, Q ∨ R ).
The first property is the principle of the exclusion of the miracle, the second is the monotonicity
principle,
we call it.
proof:
1. Indirect: Suppose that ∃a ∈ ⌈lf ( S, False ) ⌉ . At this point, the weakest prefix
line defines: a ∈ D p ( S ) and P ( S ) ( in ) ⊆ ⌈Hamis⌉ = ∅ . This is obvious
contradiction.
2. Indirect: Suppose that ∃a ∈ ⌈lf ( S, Q ) ⌉ \ ⌈lf ( S, R ) ⌉ . Then ∈ D p ( S ) and
p ( S ) ( a ) ⊆ ⌈Q⌉ and p ( S ) ( a ) ⊆ ⌈R⌉ . However, this contradicts the condition that,
according to which ⌈Q⌉ ⊆ ⌈R⌉
3. We confirm the claim in two parts, with the result of both directions.

(a) lf ( S, Q ) ∧-f ( S, R ) ⇒-f ( S, Q ∧ R ), namely:


Be a ∈ ⌈lf ( S, Q ) ∧ lf ( S, R ) ⌉ . Then a ∈ ⌈lf ( S, Q ) ⌉ and a ∈
⌈Lf ( S, R ) ⌉ , that is ∈ D p ( S ) and p ( S ) ( a ) ⊆ ⌈Q⌉ or p ( S ) ( a ) ⊆ ⌈R⌉ .
Then, p ( S ) ( a ) ⊆ ⌈Q⌉ ∩ ⌈R⌉ = ⌈Q ∧ R⌉ , that is , ∈ ⌈lf ( S, Q ∧
R)⌉.

3.2. SPECIFICATION OF THE TASK 45

THE p(S) THE


⌈R⌉
⌈Lf ( S, R ) ⌉
⌈Lf ( S, Q ) ⌉ ⌈Q⌉

3.1. figure. The weakest prerequisite and the relationship between engraving

( S, Q ) ∧ lf ( S, R ), for (b) lf ( S, Q ∧ R ) ⇒ lf ( S, Q )
Let ∈ ⌈lf ( S, Q ∧ R ) ⌉ . This is the definition of the weakest prerequisite
Based on the ∈ D p ( S ) and P ( S ) ( in ) ⊆ ⌈Q ∧ R⌉ . Used to ⌈Q ∧
R⌉ = ⌈Q⌉ ∩ ⌈R⌉ , implies that P ( S ) ( in ) ⊆ ⌈Q⌉ and P ( S ) ( in ) ⊆ ⌈R⌉ , i.e.
the ∈ ⌈lf ( S, Q ) ⌉ and a ∈ ⌈lf ( S, R ) ⌉ , so the ⌈lf ∈ ( S, Q ) ∧-f ( S, R ) ⌉ .

THE p(S) THE

⌈Lf ( S, R ) ⌉ ⌈R⌉
⌈Q⌉
⌈Lf ( S, Q ) ⌉

3.2. figure. The weakest prerequisite and union relationship

4. Let ∈ ⌈lf ( S, Q ) ∨lf ( S, R ) ⌉ . Then ∈ ⌈lf ( S, Q ) ⌉ or ∈ ⌈lf ( S, R ) ⌉ .


If a ∈ ⌈lf ( S, Q ) ⌉ then, based on the monotonicity attribute, a ∈

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 37/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
⌈Lf ( S, Q ∨ R ) ⌉ . Similarly, if ∈ ⌈lf ( S, R ) ⌉ then ∈ ⌈lf ( S, Q ∨ R ) ⌉ .
Property (4) is not backward. p ( S ) ( a ) ⊆ ⌈Q⌉ ∪ ⌈R⌉ does not follow
neither p ( S ) ( a ) ⊆ ⌈Q⌉ , nor p ( S ) ( a ) ⊆ ⌈R⌉ . Of course, if p ( S ) is deterministic,
ie ∀a ∈ A : p ( S ) ( a ) is a set of at most one element, then equality exists.

3.2. Specification of the task


Next, we introduce another way to enter the task and say
a very important item from a practical point of view.

46 3. SPECIFICATION

In general, the task does not depend on all the components of the state space,
the same thing for several points of space. These points will be summed up as a point
parameter space.
3.2. DEFINITION : P ARAMETER TREE
Let F ⊆ A × A task. Set B is called the parameter space of the task ,
if there are any relations F and F that
1 2

F
1
⊆ A × B,
F
2
⊆ B × A,
F = F ◦F .
2 1

It is important to note that a parameter space can always be found. For example,
dat state in each case an optional parameter space in the definition
the F relation to the identical mapping, and F the F task itself
1 2
selected. But what is the parameter space chosen in a specific case?
depends on the data. In general, we select the parameter space for the next item
we can use it comfortably.
3.2. COMPOSITION S PECIFIKÁCIÓ MAKING
Let F ⊆ A × A task B to F is a parameter space, F ⊆ A × B , F ⊆
B × A , F = F ◦ F . Let b ∈ B and define the following statements:
1 2

2 1

⌈Q b ⌉ = {a ∈ A | ( a, b ) ∈ F 1 } = F 1( - 1) ( b ) ,
⌈R b ⌉ = {a ∈ A | ( b, a ) ∈ F 2 } = F 2 ( b ) .
Then if ∀b ∈ B : Q ⇒-f ( S, R ) , then the S program resolves the F
b b
task.
Proof: We need to see two points of the definition of the solution:
1. D
F
⊆ D p ( S ) , since:
Let ∈ D be arbitrary. Then, for the definition of relations F and F , ∈
F 1 2
D 1 and
F
∃ b ∈ B : a ∈ ⌈Q ⌉. b
But then under the condition of the item:
a ∈ ⌈Q ⌉ ⊆ ⌈lf ( S, R b ) ⌉ ⊆ D p ( S ) .
b

∀a ∈ D : p ( S ) ( a ) ⊆ F ( a ) because:
Second
F
Let ∈ D be arbitrarily fixed, b ∈ B such that ∈ ⌈Q ⌉ . At
F b
under the condition:
p ( S ) ( a ) ⊆ ⌈R ⌉ = F 2 ( b ) ⊆ F 2 ( F 1 ( a )) = F ( a ) .
b

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 38/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

3.3. THE VARIOUS CONCEPT 47

The specification of the specification is only a sufficient condition for the solution, ie it does not
acting: you can give a task-program party where the program solves the task but
the specification of the specification is not met. This of course also depends on the task
how to specify which parameter space to choose and how to break the up-
data for compositions of F and F .
1 2
Later on, in defining a programming task, the specification, that is, the
starting from the task specified in the specification of the item's specification, and
we are looking for the solution program using the fiction item. Since the specification
This can not be reversed, we may not find a solution on this path
program. Can this problem be avoided? That is, we are looking for the answer
can a specification be specified for a specific task on which the specification is made
reversible. We call this specification good .
3.2. statement: If you select the param-
terrestrial and pre-conditions, so that the following two conditions are fulfilled:
(1) ∀b ∈ B : ⌈Q ⌉ = ∅ ⇒ ⌈R b ⌉ = ∅ ,
b
(2) ∀b , b ∈ B : ⌈Q 1 ∩ Qb ⌉ = ∅ or
2
1 2
⌈Q bb ⌉ = ⌈Q b ⌉ and ⌈R b ,
⌉ = ⌈R b ⌉
1 2
1 2

then the specification item can be reversed.


This statement can be easily demonstrated. It is to be seen that if Solution S is F -
then:

the.∀b ∈ B : ⌈Q ⌉ ⊆ D p(S)
b

b. ∀ b ∈ B : ∀ a ∈ ⌈Q b ⌉ : p ( S ) ( a ) ⊆ ⌈R b ⌉.
That. (1) if ∀b ∈ B : ⌈Q ⌉ ⊆ D , then b.
the fact that if ∈ ⌈Q ⌉ , then ∈ D and the solution
b F

b F

p(S)(a)⊆F(a)= ⌈R x ⌉ = ⌈R b ⌉,
x∈B and a∈ΘQ x ⌉

because (2) the union is one member or all members are equal.
So the specification that satisfies the two conditions of statement 3.2 is a good specification . The question
is it just that there is any such thing for each task? If the parameter space is
sheet space, F the identical mapping and F = F , then both conditions of statement 3.2
1 is 2
obviously fulfilled.

3.3. The concept of variable


Based on what has been said so far, the specification of the specification would not be effective yet
because all conditions in the parameter space should be checked

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 39/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

48 3. SPECIFICATION

fulfillment. That is why we introduce the concept of the variable,


the system becomes more easily verifiable.

3.3. DEFINITION : AVAILABLE


×
The A = A state space v : A → A one-dimensional projection function
i∈ I i i i is a
nyje are called variables .

Using variables, you can simplify state-based statements


(pre and post conditions, weakest prerequisite) and relationships (program function).
Because every variable's interpretation range is a state space and a set of values
type variables, we can characterize a variable with one type, that is, we can talk about
type.
If the parameter space is also direct-shaped - and this is often the case, as it is
usually an alter of the state space - then the parameter space is a one-dimensional projection
functions parameter variables are called.
The variables for the state space and the components of the parameter space, i-
let's read parameter variables under the given component.
We are now examining how to make assignments using the specification
drafted.
Consider a known task: Determine the sum of two integers!
First, write the state space as it is so far, just add the variable names
entering.
A=Z×Z×Z
xyz
Applying our marks so far is the task

F = { (( u , u , u ) , ( v , v , v )) ∈ A × A | v = u + u }.
1 2 3 1 2 3 3 1 2

To apply the specification item, write the parameter space:


B=Z×Z
' '
x y
Then we'll go back to why we've just chosen the parameter space.
So the state space consists of three whole components with variables x ,
'
y and z . The
'
parameter space consists of two whole components, the first component variable is x , a
second y .
Let F the following:
1 be

F = { (( u , u , u ) , ( b , b )) ∈ A x B | u = b and u = b },
1 1 2 3 1 2 1 1 2 2

F is:
2
F = { ( b , b ) , ( v , v , v )) ∈ B × A | v = b + b }.
2 1 2 1 2 3 3 1 2

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 40/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

3.3. THE VARIOUS CONCEPT 49

It follows from the above that the M ◦ F = F . The parameter space is an arbitrary b element
2 1
pre and post condition:

⌈Q b ⌉ = { ( a , a , a ) ∈ A | of = b and the = b },
1 2 3 1 1 2 2
⌈R b ⌉ = {(a ,a ,a )∈A|a =b +b }
1 2 3 3 1 2

which can also be written using the state space and variables of the parameter space:

⌈Q b ⌉ =
'
{a ∈ A | x ( a ) = x ( b ) and y ( a ) = y ( b ) },
'

⌈R b ⌉ =
'
{a ∈ A | z ( a ) = x ( b ) + y ( b ) }.
'

In the function spaces, we discussed that relationships in a function space are a logical one
' '
generating a space of functions. x, y, z are elements of a function space, x ( b' ) , y ( b )
they can be regarded as constant functions interpreted as A. Therefore x = x ( b ) and
' ' '
y = y ( b ) logic functions interpreted in the state space as x = x ( b ) ∧y = y ( b )
it is. From this we can conclude that

⌈Q b ⌉ =
' '
⌈x = x ( b )' ∧ y = y (' b ) ⌉,
⌈R b ⌉ = ( B ) ⌈z = x ( b ) + y ( b ) ⌉,
and since each function,
' '
Q =
b
( X = x ( b ) ∧ y = y ( b )) ,
' '
R = ( z = x ( b ) + y ( b )) .
b

The marking can be simplified since it is obvious that the parameter variables are argumen-
tuma b , they can be omitted, and in general, it does not make any misunderstandings if the pre and the
we will omit the indexes of the postponement conditions. These conditions are part of the parameter space
and thus depend on the values of parameter variables. The job specification is therefore:
A=Z×Z×Z
xyz
B=Z×Z
' '
x y
' '
Q:(x=x
'
∧ y'= y )
R:(z=x +y )
Hereinafter, the task is defined by specifying the state space ( A ),
the parameter space ( B ), and the pre and post condition ( Q or R ) is the parameter space
all parameters, ie parametric. In this case we say the task
in the form appropriate to the specification of the specification, or if there is no misunderstanding,
we specified the task.
One task can be specified in many ways, from among the many options
one is what is termed a precondition, a postponement specification, and very much

50 3. SPECIFICATION

is similar to what we are discussing now. We note the similarity


the two are not the same.
Normally a parameter space is used to choose an alteration of the state space. Those are
which depends on the value of what is assigned to the task.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 41/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
del, which parameterize the task. In essence, let's say that the
what kind of properties of a sheet space we want to get points in.
The parameter space is used to specify the relationship to be reached
and the starting states.
If a program can be defined for the (parametric) post-condition
the weakest prerequisite of the specification, it is easy to
whether it is a solution to the specified task, in other words, we can prove it
program is correct . However, we note that most of the time the "reverse" path
we will follow, we will not prove the correctness of the program, but it is proven to be correct
program is produced.
In the future, we will introduce tools to help
dat specification, you can create programs that solve it
the task.
In connection with the variables we introduce some simple notions,
the meaningful meaning of the words is quite obvious.
We say that the S program p ( S ) is not dependent on the state space programfüggvénye
the : The varying from you
i i

∀x, y ∈ D p ( S ) : ( ∀k ∈ I \ {i} : x ( k ) = y ( k ) ⇒ P ( S ) ( x ) = p ( S ) ( y )) .
We say that the S program, the : The variable constant, if
i i

∀a ∈ A : ∀α ∈ S ( in ): ∀k ∈ D α : α k ( i ) = in ( i ) .
We say that S implementation program does not alter the : The crisis
i i
tacos, ha
∀a ∈ D p ( S ) : ∀b ∈ p ( S ) ( a ): b ( i ) = a ( i ) .

3.4. Examples
3.1. Let A = {Bach, Bartók, Kodály, Liszt, M ozart, V ivaldi} , S ⊆
**
A×A program.
S = {V ivaldi → < V ivaldi, Bach > , Bach → < Bach, M ozart > ,
Bach → < Bach, Liszt, Bartók > , M ozart → < M ozart, V ivaldi > ,
Flour → < Liszt, Bartók > , Kodály → < Kodály M Ozark > ,
Bartók → < Bartók, Bach, Liszt > }

Also, set R : A → L:

3.4. EXAMPLES 51

∀x ∈ A : R ( x ) = ( x Hungarian).
What will be the weakest prerequisite for R for this program ?
Solution: Write the program function for the first time:

p ( S ) = { ( V ivaldi, Bach ) , ( Bach, M. ozart ) , ( Bach, Bartók ) ,


( M ozart, V ivaldi ) , ( Liszt, Bartók ) , ( Kodály, M ozart ) ,
( Bartók, Liszt ) }

After that, using the definition of the weakest prerequisite:


⌈Lf ( S, R ) ⌉ = {Bartók, Liszt} because it is
p ( S ) ( V ivaldi ) = {Bach} ⊆ ⌈R⌉
p ( S ) ( Kodály ) = {M ozart} ⊆ ⌈R⌉
p ( S ) ( Bartók ) = {Liszt} ⊆ ⌈R⌉
p ( S ) ( Bach ) =
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 42/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

p ( S ) ( M ozart ) = {M ⊆ ⌈R⌉ ⊆ ⌈R⌉


ozart, Bartók}
{V ivaldi}
p ( S ) ( flour ) = {Bartók} ⊆ ⌈R⌉

**
3.2. Example: Let H , H : A → L. Is it true that if all S ⊆ A × A Program
lf ( s, H ) = LF ( S, H1 ), 2then ⌈H ⌉ = ⌈H ⌉ ?
1 2 1 2
Solution: Using the weakest prerequisites for each program,
by choosing a suitable program, the answer can simply be given: ren-
Deleting the S program for each element of the state space is a one-length self
series. It is then easy to see that in case of arbitrary R condition:

lf ( S, R ) = R.

But then
H = 1 f ( S, H ) = 1 f ( S, H ) = H ,
1 1 2 2

so the two conditions are the same.


3.3. Example: Specify the following function: A = L × L , F ⊆ A × A ,

F = { (( 1, k ) , ( m, n )) | n = k and m = ( l∧k ) }.

52 3. SPECIFICATION

Solution:
A=L×L
xy
B=L×L
' '
x y
' '
Q:(x=x ∧y=y )
' ' '
R:(x=(x ∧y )∧y=y )
**
3.4. Example: Let F ⊆ A × A , S ⊆ A × A , B be an arbitrary set.
Let F ⊆ A × B and F ⊆ B × A be relations such that F = F ◦ F ,
and ∀b ∈ B :
1 2 2 1

⌈Q b ⌉ = F - 11( b ) ,
⌈R b ⌉ =F (b).
2

Is it true that if ∀b ∈ B : Q b⇒ lf ( S, R ), then S solves F ?


b
Solution: Try to see two points of the definition of the solution. Be
of D ∈ . We should see that ∈ D p ( S ) . Let's look at the specification item
: we usedF
that there is a b ∈ B that is ∈ ⌈Q ⌉ . True
b
this Q too? Unfortunately - since
b
Q was defined with the original - this is not necessarily the case.
b
Let's try to give a counter-example based on the above-mentioned thought:
Let A = { 1 } , B = { 1 , 2 } , F = { (1 , 1) } , D = { (1 , 1) , (1 , 2) } , D = { (2 , 1 ) } .
1 2
At Q = False and Q = False , so the terms of the statement are met,
1 2
irrespective of the program (since "everything is false"). Select now
the following program is S = { (1 , < 1 , 1 , ...> ) } . This program is not a solution to the

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 43/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
but the conditions of the claim are fulfilled. So the statement is not true.

3.5. Tasks
**
3.1. Let A = { 1 , 2 , 3 , 4 , 5 }, S ⊆ A × A .
S={ (1 , < 1251 > ) ,(1 , & lt; 14352 & gt (1 ; ),,< 132 ... > ) ,(2 , & lt; 21 & gt ; ) ,
(2 , < 24 > ) , (3 , < 333333 ... > ) ,(4 , & lt; 41514 &(4gt, & ; ) lt;
, 431251 & gt ; ) ,
(4 , & lt; 41542 (5 & ,gt<;524
), >), (5 , & lt; 534 & gt(5; ,) <, 5234 > ) }
and ⌈R⌉ = { 1 , 2 , 5 } . Write the set ⌈lf ( S, R ) ⌉ .
3.2. Since equal is lf ( S, True )?
3.3. Let A be any state space Q : A → L ( i ∈ N). Is it true that if
i

∀i ∈ N: Q and ⇒ Q and +1 ,
then
( ∃n ∈ N: lf ( S, Q )) = lf ( S, ( ∃ n ∈ N: Q ))?
n n

3.5. TASKS 53

3.4. It true that if lf ( S , R ) = LF ( S , R ), then lf ( S ∪ S , R ) = LF ( S, R ) ∨


1 2 1 2 1
lf ( S , R )?
2

3.5. It true that if ∀x, y ∈ A : x ∈ ⌈lf ( S , P ( {y} )) ⌉ ⇔ x ∈ ⌈lf ( S , P ( {y} )) ⌉ ,


1 2
then D p ( S D
1) = p ( S 2) ?
**
3.6. S , S : A → for L
1 2 ⊆ A × A programs. Is it true that if ∀H
lf ( S, , H ) = LF ( S , H ), then S equiv S with?
1 2 1 2

3.7. A = N. S ⊆ N × N ** .
S = { ( a, <a · · ·> ) | ≡ 1 (mod 4) }
∪ { ( b, <b> ) , ( b, <b, b / 2 > ) | b ≡ 2 (mod 4) }
∪ { ( c, <c, 2 c> ) | c ≡ 3 (mod 4) }
∪ { ( d, <d, d / 2 > ) | d ≡ 0 (mod 4) },
⌈H⌉ = {x ∈ N | 2 | x} . ⌈Lf ( S, H ) ⌉ =?
3.8. Given the state of A = V × V × L ( V = { 1 , 2 , 3 } ) and B = V × V
parameter space, and tasks F and F .
1 2

F = { (( a , a , 1 ) , ( b , b , k )) | k = ( a > a ) },
1 1 2 1 2 1 2

F specification:
2

A=V×V×L
a a l
1 2
B=V×V
' '
a1 a2
Q : ( a = a 1 ∧a 2 = a 2 )
' '

1 ' '
1> 2 ))
R:(Q∧l=(a a
Are the tasks F and F ?
1 2 the same

3.9. Consider the following two tasks. F Specification:


1

A=Z×Z
xy
B=Z

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 44/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'
'
Q : ( xx= x )
R:(Q∧x=yyy)

F = { (( a, b ) , ( c, d )) | c = a ∧ | d | · D = c}.
2

Can there be a relationship between F and F ?


1 2

54 3. SPECIFICATION

3:10. Write the following in a text message. Let f be Z → Z,

A=Z×Z×N
0
mnl
B=Z×Z
' '
m n
' '
Q:(m=m ∧Σn = n ∧ m ≤ n ) ,
R :( Q∧l = g ( i )) ,
i=m

where g : Z → { 0 , 1 } ,
{
1 , where ∀j ∈ [ m..n ]: f ( j ) ≤ f ( i ));
g(i)=
0 otherwise .

3:11. Is it correct to reverse the item's specification? (If S solves F , then ∀b ∈


B : Q ⇒ lf ( S, R ))
b b

3:12. Consider the following task:

A=N×N
kp
B=N
'
k
'
Q : ( k = k ∧ 0 <k )
R : ( Q ∧ prim ( p ) ∧ ∀i> 1: prim ( i ) → | k - i | ≥ | k - p | ) ,

where prim : N → L and ⌈prim⌉ = {x ∈ N | x prime number } .


What does the above task assign to a = (10 , 1) and b = (9 , 5)?
Write words in words.

3:13. A = N × N × N
x y z
B=N×N
' '
x
y
F ,F ⊆A×A
1 2
F Specification:
1
' '
Q:(x=x ∧y=y )
' ' ' ' ' '
R :( x = x ∧y = y ∧x | z∧y | z∧∀j ∈ N ( x | j∧y | j ) → z | j )

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 45/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

3.5. TASKS 55

F = { (( a, b, c ) , ( d, e, f )) | a = d and b = e and f | a · b and | f and b | f}


2
Can there be a relationship between F and F ?
1 2

3:14. There is a function f : Z → Z.


A=Z×Z×Z
mni
B=Z ×Z
' '
m n
F ,F ⊆A×A
1 2
F Specification:
1
' '
Q :( m = m ' ∧ n = n ' )
R :( m = m ∧ n = n ∧ i ∈ [ m..n ] ∧ ∀j ∈ [ m..i - 1]: f ( j ) <f ( i ) ∧
∀j ∈ [ i..n ]: f ( j ) ≤ f ( i ))
Specification of F :
2
' '
Q:(m=m ∧n=n )
' ' ' '
R:(i∈[m ..n ] ∧ ∀j ∈ [ m ..n ]: f ( j ) ≤ f ( i )).
Are the two tasks the same?
3:15. Specify the following task: A = N and v : N → { 0 , 1 } .
s' '
Σ
F ⊆ A × A , F = { ( s, ) | s = k = 1 v ( k ) }

3:16. Find a divisor of a natural number.


3:17. Find a real dealer of a complex natural number.

3.18. Find a real dealer of a natural number.


3.19. Find all the real dealers in a natural number.
3:20. Find the largest prion of a natural number.

3.21. Let's figure out how many real dealers have a natural number.

3.22. Look for the first number in the [ m..n ] interval that is real
divisor.

3.23. Look for the number that most real is in [ m..n ] interval
but not divisible by 6.

3.24. Which number does the most real distributor in the [ m..n ] interval?

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 46/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 4

extensions

In the previous chapters, we introduced the concept of the program and its task and defined it
the task program in the same state of the art pairs the concept of solution. THE
in practice, however, the task and the program are in different states
read; an example is the case where a problem is solved by a
additional variables should be introduced in the program, ie the state of the
with expansions.
We will now look at what we can say about the different state-
the relationship between the programs and the tasks related to the solution and this
the scope of the solution is also generalized in this case.

4.1. Extending the task


If the state space of a task is expanded with newer components, what is the meaning of this component?
related data? It is quite obvious that, in this case,
no clause for new components.

4.1. DEFINITION : EXTENSION OF F ELIMINATION


'
Let B state space be the A state space. The relation F ⊆ A × A is
The extension of the function F ⊆ B × B is called if
'
F = { ( x, y ) ∈ A × A | ( pr ( x ) , pr ( y )) ∈ F}.
B B

The definition can also be defined by extending the task to all


contains a point A × A , whose projection for B is in F -
in.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 47/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
58 4. EXTENSIONS

' '
B F THE

F B

4.1. figure. Expand your task

4.2. Extension of the program


In the definition of the extension of the program,
so that they do not change in the extended program. This is the practical one
requirement that the variables that the program does not use are not
during program run.
4.2. DEFINITION : P ROGRAM EXTENSION
'
Let B state space be a state space A and mark B for supplement B '
subspace of A respectively. Also, be S program in status state B. Then the S to have US
is referred to as the extension of the S program if ∀a ∈ A :
' **
S ( a ) = {α ∈ A | for ( α ) ∈ S ( pr ( a )) and ∀i ∈ D : pr ' ( α ) = pr ' ( a ) }.
B B α B i B

Based on the above definition, only in the value set of the extended program
There are sequences that are "parallel" to a series of original programs
value set.
Does the extension retain the program property? She answers this question
the following statement.
'
4.1. statement: Let B state space be a state space A and mark B with B '
Additional subspace of A respectively.
'
Also, be S program in status state B and S is
And the extension of on. Then S program.
Evidence is extremely simple, it's a task.
Two programs defined in the same state are called equivalents when the prog-
their ram function was the same. Now we also generalize this concept.

4.3. EXTENSION SUBJECTS 59

'
B THE

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 48/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

4.2. figure. Extend the program

4.3. DEFINITION : ECVIVALENANCE OF P ROGRAMS


** S
Let S ⊆ A × A 1 , 2 ⊆ A 2 × A 2 * programs, B in the room A 1 ,
both for
1 A 1. We say that S equiv S with B n where
2 1 2

pr ( p ( S )) = pr ( p ( S )) .
B 1 B 2

Obviously, the definition is really a generalization of the simple case. The definition
It is also a simple consequence of the two equivalents of programs on the common side
solve exactly the same tasks.
In fact, the fact that two programs are equivalent - that is, the program-
they may be very different. Such - not negligible
different - for example, their effectiveness. It does not matter at all
how long a program runs and how much memory is needed. The program e
but we do not discuss it here.
The following statement is directly derived from the definitions:

4.2. statement: Extend a program and the original program in the original state
equivalent.

4.3. Extension Items


The following article is the link between the solution and the extensions.
examination.

60 4. EXTENSIONS

Let A be a state space with a B space. The B -n-defined functions and programs
you can consider the extensions of A -na tasks and programs to A ,
of the defined task equivalent of n B n is the task dimension B to. The A -n
For screened programs, screening for B is not directly applicable since
the projection of a program may not be a program because the series is not certain
They reduced with. Of course, Sif⊆ A × A ** , then it is

**
S = { ( b, β ) ∈ B × B | ∃ ( a, α ) ∈ S : b = pr B ( a ) and β = red ( pr B ( α )) }
**
is already a program and in status state B
S equivalents.
is S and So one S⊆A×A prog-
**
always there is a program S ⊆ B × B which is equivalent to B for it .

' '
F F S S
THE
projection projection
extension extension

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 49/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

B
F S

4.3. figure. Contact between A and B.

In this way, as in 4.3. Figure 2 shows the extension and projection


we establish a connection between the programs defined in the status spaces A and B.
Of course, there are usually a lot of tasks in A that have a dimension of F , such
such as extension F , but not just. So, in Section 4.3. up arrows
injective mapping, and downward indexes are seamless.
We should note that F , that is, a task whose projection is F ,
always part of extension F. The same programs (program functions)
is not true.
We will investigate the cases in which we can conclude that the state A exists
solution, in the same state of B , and vice versa. For the conditions to be met,
we need to make some definitions.

4.4. DEFINITION : B IDENTIFICATION


'
Let B subspace in for, B of' the B complementary
a'
subspace ''
A is, G ⊆ aA'' × A relation.
The G extended identity B'' above, if ∀ ( a,
'
) ∈ G : ∃' ' a ∈ A , to ( a, ) ∈
G and pr ' ( a ) = pr ' ( a ) and pr ( a ) = pr ( a ).
B B B B

4.3. EXTENSION SUBJECTS 61

'
B THE
'
G the

''
the a
G

4.4. figure. Expanded identity

If a task is an extended identity, it means that the task "allows" that


the additional sub-components remain unchanged. It is easy to see the definition
that extending a task and extending a program to a pro-
ram function is both an extended identity.

4.5. DEFINITION : V INSTALLATION


Let B subspace in for, G ⊆ A × A task. The G-term projection B above, if
∀a , the ∈ D ( pr ( in ) = pr ( in )) ⇒ ( pr ( G ( the )) = pr ( G ( in ))).
1 two G B 1 B 2 B one B 2

'
B THE

a
1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 50/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
G(a )
1
a
2 G(a )
2

4.5. figure. Keeping Slideshow

Projection Projection does not mean that the relationship does not depend on the complementary subcomponent
as in 4.5. Fig. 2 shows two images of the same aspect,
but their projection is the same. In this case, it is true that it is an extension of a task

62 4. EXTENSIONS

projection screen (even the pictures are the same) and the extension of the program,
The program function of the fader is also a projection holder.

4.6. DEFINITION : FASTING OUTPUT


Let B subspace in for, G ⊆ A × A task H ⊆ B . We say that G
half extension above H if pr -B1( H ) ⊆D G .

'
B

THE

D
G

H B

4.6. figure. half Extension

The half-extension's meaningful meaning is that it is from the auxiliary altar


there are no "holes" in the interpretation range. It is also true that a task is
is over half of the scope of the task's interpretation domain. It is also true that a
program extension function is the original program function interpretation
half an extension of its range.
By means of the definitions that have just been introduced, statements which are
the relationship between the extensions and the projection and the solution
item. The markings are given in 4.3. Fig.

4.1. COMPOSITION : K ITERJESZTÉSI LINES


'
Let B subspace'
in for,' B of the B complementary subspace A is, S Program B n, F ⊆
B × B taskF ⊆ A × ADtask
S and S unto, and Fprmean those extension of on. Be **
to which
furthermore B
F ) = F , S ⊆ A × A is
a program which is equivalent to S strength loss & quot B -n. Then the following statements are
fulfilled:
It has:
' '
(1) if Solution S for F then Solution S for F ;

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 51/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'is a
(2)
(3) if
haS solution For
'
F , then Solution S for F ;
Solution S for F , then Solution S for F ;

4.3. EXTENSION SUBJECTS 63

(4) the. if S solution F , and p S ) over projection B , then S


solution to F ;
b. if S solution F , and F half-extension above D , then S
F
solution to F ;
' '
(5) if Solution S for F , then Solution S for F ;
(6) if S is a solution for F , and F expanded identity over B ' and projection holder B
'
above, it is S solution F;
(7) if Solution S for F , and p S ) half-extension above D , then S
' F
solution to F .
Proof: Before we certify each item, notice that (4)
' '
batch follows'
from the first three, 'as S eq S strength loss & quot B n, and p ( s ) vetítés-
and pr ( F ) = F and F half extension 'is an
D nm. Similar considerations
'
B F
the item (5) is also derived from item (6) as F extended identity over B and
projection screen over B. It is therefore sufficient to prove the items (4), (6) and (7).
Consider the proof of theorem 4: Let b ∈ D be arbitrary. At
F

b∈D ⇒ ∃a ∈ D F: for ( a ) = b
F B
solution
⇒ a∈D p ( S)

⇒ pr B ( a ) ∈ D p ( S ) ,
S ekv. S

so D ⊆ D p ( S ) , and thus the fulfillment of the first criterion of the solution has been proved.
Consider the second criterion now; let b ∈ D be arbitrarily fixed. At
F

F

p ( S ) ( b )= for ( pS ) ( a )) ,
B
a∈pr -B1 ( b ) ∩D p
S)

F(b) = for F ( a )) .
B
a∈pr -B1 ( b ) ∩ F

That. ie if p S ) projection holder, then ∀x, y ∈ Pr - B1 ( b ) ∩D p S ) to


for ( pS ) ( x )) = pr ( pS ) ( y )). Then ∈ pr - 1 is arbitrary B ( b ) ∩ F , mivela
B B
solution definition p S ( a )) ⊆F ( a ),
p ( S ) ( b ) = pr (Sp) ( a )) ⊆ pr F ( a )) ⊆ F ( b ) .
B B

So the second condition of the solution is fulfilled.


A b. case, ie if F is a half extension, then Bpr( b- 1) ⊆ F, that is , ∈ prB -(1b ) ∩
F = pr B- 1( b ) and the resolution definition
D

∀a ∈ pr B- 1( b ): p S ) ( a ) ⊆F ( a ) ,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 52/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

64 4. EXTENSIONS

so
∀a ∈ pr - 1 p S ) ( a )) ⊆ pr
B( b ): pr B ( B
F ( a ))
⋃ ⋃
⇒ for ( pS ) ( a )) ⊆
B
for F ( a ))
B
a∈pr -B1 ( b ) a∈pr -B1 ( b )

⇒P(S)(b)⊆M(b),
and in this case we realized that S program solves the task F.
Let's look at proof of item (6) now.

1. First, we show that D ⊆ Dp(S ). F


'

Let a ∈ F. Then pr B ( a ) ∈D F. Utilizing that solution S for F ,


for ( a ) ∈ D p ( S ) . It follows from the definition of the extension of the program that
D

then ∈ D p ( S ' ) .
B

2. Next, we show that ∀a ∈ F:


'
p ( S ) ( a )F
⊆( a ) is also satisfied.
D

' ' ' ''


the p(S ) a =a
'
B F
THE

F
''
a

'
b B

4.7. figure.

A 4.7. FIG be properly the ∈ a ' ∈ p ( S ' ) ( a ). At that time - up-


F and
'is D '
using the fact that S the extension of S - for the following property exists:
'
for ' ( a ) = pr ' ( a )
B B

= pr ' ( a ). Then b ∈ p ( S ) ( pr B ( a )). Since S solves F ,


' ' '
Let b
it follows that b ∈ F ( pr B'' ( a )). At this time - since
F Projection Holder B and F
B
'' '
theF projection - gives ∃a ∈ F ( a ): pr ( a ) = b . Used,
' ' ''
that F expanded identity over B , ∃a ∈ F ( a ) forB which
' '' ' '' '
pr ' ( a ) = pr ' ( a ) and pr ( a )=b .
B B B
' ' '' '
Then the = a , that is , ∈ F ( a ).

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 53/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

4.4. EXTENSION OF THE TASK AND SPECIFICATION 65

Now only the statement (7) has been proved:


(1) Let a ∈ D 'be . Then, based on the definition of the extension of the task, pr ( a ) ∈
D . SinceF p S ) extending semi D above, the ∈ D S ) p. (
B
F F
'
(2) Let a ∈ D ' , a ∈ p
' ' '
S ) ( a ) and b = pr ( a ). Then b ∈ p ( S ) ( pr ( a )),
since p ( SF ) a p B∈
'
B
S ). Since S solves F , it follows that b
F ( pr ( a )), but based on the extension of the job extension ∀x ∈ pr -B1 ( b ' ) :
B
' ' '
x ∈ F ( a ) so that ∈F ( a ). So the second condition of the solution is fulfilled.
This statement (7) has also been proved.

4.4. Extending the job and making the specification


We remind you of the state space specified in the form of the specification item,
parameter space, pre and post conditions - tasks. As an example we have written the sum of two numbers:
A=Z×Z×Z
xyz
B=Z×Z
' '
x y
' '
Q:(x=x ∧y=y )
' '
R:(z=x +y )
'
What will be the extension of this task to an A = Z × Z × Z × N × L state space?
The answer is at first glance surprising.
A=Z×Z×Z×N×L
xyzuv
B=Z×Z
' '
x y
' '
Q:(x=x ∧y=y )
' '
R:(z=x +y )
In general, it is true that the extension of the task extension is expanded
apart from status, is the same as the original job specification.

4.5. Extending the parameter space


Of course, not only the state space but the parameter space can be extended. Specification
two cases are distinguished from the point of view.
'
Let B be a parameter
'
space and an extension of B . If you specify a job
B instead of B is used in such a way that pre and postconditions depend not only on the

66 4. EXTENSIONS

'
B , then the task does' not change because ∀b ∈ B :
B ( b ): ( ⌈Q b ⌉ = ⌈Q b ⌉

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 54/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'
Otherwise, the task may alsoand ⌈R b ⌉Suppose
∈ pr - 1 conditions apply: change.
∀theb following = ⌈R ⌉ that
b
'). the new task is


∀ b ∈ B : ⌈Q b ⌉ = ⌈Q b ⌉
'
'
b ∈pr B- 1( b )

∀b ∈ B : ∀b ∈ pr B- 1( b ) :( ⌈R b ⌉ = ∅ and ⌈R b ⌉⊆⌈R b ⌉ ) ,
' ' '

then we say that refining the new task is the old ones.

4.3. statement: If refining an F task to a G task, F is stricter than


G.

4.6. Examples

4.1. Example: B = { 1 , 2 , 3 }, A = B × { 1 , 2 , 3 } . F ⊆ B × B . F = { (1 , 2) , (1 , 3) } . We
extension of F to B ?
Solution: Based on the definition of the task extension:

F={ ((1 , 1) , (2 , 1)) , ((1 , 1) , (2 , 2)) , ((1 , 1) , (2 , 3)) , ((1 , 2) , (2 , 1)) ,


((1 , 2) , (2 , 2)) , ((1 , 2) , (2 , 3)) , ((1 , 3) , (2 , 1)) , ((1 , 3) , (2 , 2)) ,
((1 , 3) , (2 , 3)) , ((1 , 1) , (3 , 1)) , ((1 , 1) , (3 , 2)) , ((1 , 1) , (3 , 3)) ,
((1 , 2) , (3 , 1)) , ((1 , 2) , (3 , 2)) , ((1 , 2) , (3 , 3)) , ((1 , 3) , (3 , 1)) ,
((1 , 3) , (3 , 2)) , ((1 , 3) , (3 , 3)) }

4.2. Example: Given the L × L state space F = { (( 1, k ) , ( m, n )) | n = ( l ∧ k ) } task,


'
and A = L × L × V status field ( V = { 1 , 2 } ) to the following scheme:

S={ ( Ii 1 , < ii 1 , H 2 , hi 2 > ) ,( ii 2 , < ii 2 , hh 1 , ii 1 > ) ,


( Ii 2 , < ii 2 , H 2 , hi one , hi 2>
( Ih 1 ,) <, ih 1 > ) ,
( Ih 2 , < ih 2 , ii 1 , hh 1 > )(,hi 1 , < hi 1 , hh 2 > ) ,
( hi 2 , < hi 2 , hi 1 , ih 1 > )(, hi 2 , < hi 2 , hh 1 , hh 2 > ) ,
( Hh 1 , < hh 1 , H 1 > ) , ( hh 2 , < hh 2 > ) }

'
Does S extend its extension to FA ?

4.6. EXAMPLES 67

'
Solution: Write the extension to FA :
'
F ={ ( ii 1 , ii 1) , ( ii 1 , hi 1) , ( ii 1 , ii 2) , ( ii 1 , hi 2) ,
( ii 2 , ii 1) , ( ii 2 , hi 1) , ( ii 2 , ii 2) , ( ii 2 , hi 2) ,
( H 1 , H 1) , ( Ih 1 , hh 1) , ( IH 1 , IH 2) ,( ih 1 , hh 2) ,
( H 2 , H 1) , ( ih 2 , hh 1) , ( H 2 , H 2) , ( ih 2 , hh 2) ,
( hi 1 , ih 1) , ( hi 1 , hh 1) , ( hi 1 , ih 2) , ( hi 1 , hh 2) ,
( hi 2 , ih 1) , ( hi 2 , hh 1) , ( hi 2 , ih 2) , ( hi 2 , hh 2) ,
( Hh 1 , H 1) ,( hh 1 , hh 1) , ( hh 1 , 2) , ( hh 1 , hh 2) ,
( hh 2 , ih 1) , ( hh 2 , hh 1) , ( hh 2 , i 2) , ( hh 2 , hh 2) }

The program function of program S is:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 55/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
p ( S ) = { ( ii 1 , hi 2) , ( ii 2 , ii 1) , ( ii 2 , hi 2) , ( H 1 , H 1) ,
( ih 2 , hh 1) , ( hi 1 , hh 2) , ( hi 2 , ih 1) , ( hi 2 , hh 2) ,
( Hh 1 , H 1) ,( hh 2 , hh 2) }

We need to see two points of the definition of the solution. D ' ⊆ D p ( S ) trivi-
F
is fulfilled, since both sets are the total status space. Let's look at it now
'
∀a ∈ D F : p ( S ) ( a ) ⊆ F ( a ) is satisfied!
p ( S ) ( ii 1) = {hi 2 } ⊆ {ii 1 , hi 1 , ii 2 , hi 2 } = F ( ii 1)
p ( S ) ( ii 2) = {ii 1 , hi 2 }⊆ {ii 1 , hi 1 , ii 2 , hi 2 } = F ( ii 2)
P ( S ) ( H 1) = {H 1 } ⊆ {ih 1 , hh 1 , H 2 , MM 2 } = F ( H 1)
P ( S ) ( H 2) = {hh 1 } ⊆ {ih 1 , hh 1 , H 2 , MM 2 } = F ( H 2)
p ( S ) ( hi 1) = {hh 2 } ⊆ { 1 , hh 1 , 2 , hh 2 } = F ( hi 1)
P ( S ) ( hi 2) = {H 1 , dd 2 }⊆ {i 1 , hh 1 , i 2 , hh 2 } = F ( hi 2)
P ( S ) ( hh 1) = {H 1 } ⊆ { 1 , hh 1 , 2 , hh 2 } = F ( hh 1)
p ( S ) ( hh 2) = {hh 2 } ⊆ { 1 , hh 1 , 2 , hh 2 } = F ( hh 2)

So, the program S solves the expanded task F.


4.3. Example: Is it true that if S ⊆ B × B, the subspace of B unto then

D A( p ( S )) = for ( D p ( S ) )?
pr A

Solution: Let's try to prove the statement with two-way content.


D The ( p ( S )) ⊆pr ( D p ( S ) ): Let a ∈ D The ( p ( S )). Then
pr A pr

' '
∃a ∈' A : ( a, a ) ∈ pr ( p ( S' )) '
⇒ ∃ ( b, b ) ∈ P ( S ): PR A ((A b, b )) = ( a, a )
⇒ b∈D p ( S ) ⇒pr A ( b ) = a∈pr of ( D p ( S ) ) .

68 4. EXTENSIONS

pr ( D p ( S ) ) ⊆ D D
A Apr( p ( S )) : Let a∈pr A ( p(S)) then
∃b ∈ D p ( S ) : pr A ( b ) = a
' '
⇒ ∃b ∈ B : ( b,' b ) ∈ p ( S )
⇒ ( a, pr A ( b )) ∈ pr A ( p ( S ))
⇒ a∈D pr ( p ( S )) .
A

and this statement has been proved.

4.7. Tasks
4.1. B = N , A = B × N. F ⊆ B × B. F = { ( q, r ) | r = q + 1 } . What is F
extended to A ?
**
4.2. Is it true that if S ⊆ A × A program, B subspace in for, then SB in to
extend its projection to A with the same S ?

4.3. Prove that an extension of a program is indeed a program!


4.4. A = A × A × · · · × A . Let's say, for example, a program that has one
1 2 n
its real-world projection is not a program. ( A = N , k = 1 , ..., n ).
k
' '
4.5. Let the subspace of B unto, F ⊆ A × A , F ⊆B×B,F of F was extended to B to.
Is it true that

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 56/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'' '' is
a) if 'F = pr ( F ), then F the extension F ?
A
- 1) ( F ) and F ' = pr - 1 A ( F )?
b) F = pr ( THE
' ' '' '
4.6. Let F ⊆ A × A , M ⊆ B × B , M ⊆ C × C , D ⊆' DF ×' ' DF ' ,'' where
B = A × A , C = A × A , D = A × A × A , and let D ,'' ' , ' ' of the
1 2 1 2
F is extended to B , C and D respectively.
' ''
Is it true that F is F extension
D ? Enter the link between F and F projection and extension
with the help of the concept!

4.7. B and C subspace of the for.⊆FA × A, F ⊆ B × B, M ⊆ C × C . F is F


1 2 1
projection of B to. F to F to extend the to. Is it true that the F job of is
2 1
has a projection of C to its extension C equal to F ?
2

Chapter 5

The concept of solution


generalization

In this chapter, the term solution is generalized. We originally claimed that a


program and task state are "identical". This clause will be made in two respects
weaken.

5.1. Extending the concept of solution


First, we broaden the concept of the solution based on the extension lines. The state-
instead of the "identity" of spaces, we are only demanding that a common space
fulfilling the task and the program, to satisfy the conditions of the solution.

5.1. DEFINITION : EXTENSION OF THE SOLUTION CONDITION


× × **
A= A and B =
i∈ I i j ∈J A j . F ⊆ A × The task and S ⊆ B × B
program. If there is C state space with A and B being an extension and S extension
C , in the original sense, to its extension to FC , then that

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 57/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
say S - extended sense - Solving F unto.
This definition is a generalization of the original definition since A = B = C is vis-
we cover it.
From the extension items, it is immediately from 1 to 5 that it is
in the definition, the word "exist" could be replaced by "all". It is also obvious that
A common multipath state space, that is, A and B are alteros, always
×
exists: A .
k∈I∪J k

70 5. GENERALIZE THE SOLUTION OF THE SOLUTION

×
Therefore, the definition can also be formulated by C = The state-
k∈I∪J k

expanding the task and the program, the conditions of the solution are fulfilled.
Knowing the concept of an extended solution, it is worth the extension items
to re-examine. The significance of Lot 1 and Lot 5 has already been discussed in the definition. THE 2.,
or item 3 means that if a program is solved for a task, then either
the terms of the solution are fulfilled either on the program or in the state of the task. The same
vice versa only if certain conditions are met (5, 6).

5.2. Solution to an equivalent state


In accordance with the definition of the equivalent direct source, we state that two
when we look at lapotter equivalent.
5.2. DEFINITION : THIS KIVIVAL STATE
× ×
We say that A = The state space equivalent to B = B
i∈ I I j ∈J j
state, if f : I → J is mutually clear
(bijection) that ∀i ∈ I : A = B f ( i ) .
i

~ B is indicated.
If two states are equivalent, then they are not just the interpretative ranges
there is a mutually clear correlation between status spaces:

( b ) ( b ) ( i ) = b ( f ( i )) γ : B → A and ∀b ∈ B : ∀i ∈ I : γ ( b ) .
f f

5.3. DEFINITION : M COUPLING WITH DENTAL


**
~ B , F ⊆ A × The task and S ⊆ B × B program. We say,
that S is the solution of f by renaming F , if

1. D
F
⊆Dγ f ◦p ( S ) ◦γ ( - 1) ,
f

∀a ∈ D F : γ f ◦ p ( S ) ◦ γ (f - 1) ( the ) ⊆ M ( to ).
Second

In the definition, we could have phrased that γ ◦ p ( S ) ◦ γ ( - 1) Solving


f f
- in the original sense - F unto. The γ ◦ p ( S ) ◦ γ (f - 1) relationship is also
f
we can offer to one of the have US item "rename" B -belivé, it used to
program function, and the elements received are " retransmitted " to A -belive.
It is clear that the definition is the generalization of the original, since if A = B and f = id ,
A
we'll get the original back.
With extension and renaming, we can formulate the solution
definition:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 58/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

5.3. RELATIONSHIP SOLUTION 71

5.4. DEFINITION : THE Z GENERAL SOLUTION


**
Let F ⊆ A × A be a task and S ⊆ B × B . If C and D exist
~ D , A for alte C , B for altee D , and extension S for D -
re-denomination solution to FC , we say S
- general terms - Solving F unto.

5.3. Relationship Solution


Not only can renaming and not just equivalent status spaces be matched
to each other. The solution can be defined as any program defined in any state space
and even if the status spaces are somewhat matched to each other.

5.5. DEFINITION : R ELECTION CONSOLIDATION


**
Let A and B be any arbitrary state space, F ⊆ A × A , S ⊆ B × B and
γ ⊆ B × A . We say that S γ is a solution to F , if
1. D
F
⊆ D γnostp ( S ) ⊙γ ( - 1) and
( A ) ⊆ F ( a ) ∀a ∈ D : γ ⊙ p ( S ) ⊙ γ ( - 1 ).
Second
F

We remind you that the composition and the strict composition are the same, if
at least one relation function. Therefore, the solution is renamed to the relationship
special case. Thus, the next item can also be applied.
5.1. COMPOSITION : R BY MAKING ELÁCIÓ SOLUTION
Let F be any task, its status space A , one parameter space B , pre and
** be a
the latter condition is Q and R . Let S ⊆ C × C program and γ ⊆ C × A
any relation to which D b ⊆ R b . Define the following function
F γ is
Vest:

⌈Q bγ ⌉ ⌊ Q b ◦ γ⌋ ,
γ
=
⌈R b ⌉ = ⌈ R b ◦ γ⌉ .
γ γ
Then if ∀b ∈ B : Q b ⇒ lf ( S, R b ) , then the program S determines it
the task F.

Proof: Do two points of the definition of γ have to be met


We.
1. D
F
⊆ D γ⊙p(S)⊙y ( - 1) .
Let a ∈ D . Then ∃b ∈ B : a ∈ ⌈Q ⌉ . Since D F ⊆ R γ ,
F b

γ ( - 1) ( a ) = ∅ and γ ( - 1) ( a ) ⊆ ⌈bQ⌉.
γ

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 59/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

72 5. GENERALIZE THE SOLUTION OF THE SOLUTION

Used to be ⌈Q
γ
b lf( S, R b ) ⌉ :

b ⌉.⌈R
γ
γ ( - 1) ( a ) ⊆ D p ( S ) and p ( S ) ( γ ( - 1) ( a )) ⊆

Since ⌈R
γ
b ⌉ = ⌈R b ◦γ⌉ ,
p ( S ) ( γ ( - 1) ( a )) ⊆ D ,
γ

so
a ∈ D γ ⊙ p ( S ) ⊙γ ( - 1) .

( A ) ⊆ F ( a ) ∀a ∈ D : γ ⊙ p ( S ) ⊙ γ ( - 1 ).
Second F
Let a ∈ D . Following the steps outlined in the first part of the proof: Whereas
p ( S ) ( γ ( - 1) ( a )) ⊆ ⌈R ◦ γ⌉ ,
F

γ ( p ( S ) ( γ ( - 1) ( a ))) ⊆ ⌈R ⌉⊆F(a).
b

γ
In the following example we show that if Q b instead of a trivial rule
a set of justifications, then the item would not be true.
Let T = { 1 , 2 } , F state space A = T , and the parameter space can also be the same:
B = T . Let F Specify:

⌈Q 1 ⌉ = { 1 }, ⌈R 1 ⌉ = {2};
⌈Q 2 ⌉ = ∅, ⌈R 2 ⌉ = { 1 }.

Then D = { 1 } and F (1) = { 2 } . Let E = {a, b} , C = E and


F

γ ( a ) = γ ( b ) = { 1 , 2 }.
**
Suppose that S ⊆ C × C and assign S to all points in its state of state
self-contained series of lengths. At

⌈Q 1 ◦ γ⌉ = ∅ and ⌈ Q 2 ◦ γ⌉ = ∅ ,
so

Q ◦γ
1
⇒ lf ( S, R 1 ◦ γ ) ,
Q ◦γ
2
⇒ lf ( S, R 2 ◦ γ ) .
But it is easy to see that

γ ⊙ p ( S ) ⊙ γ ( - 1) (1) = { 1 , 2 } ⊆ M (1) = { 2 },

so S does not solve F as γ .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 60/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 6

Programkonstrukciók

In this chapter, we discuss how new ones can be made from existing programs
programs. Of course, we can construct existing prog-
new programs, but now only three types of construction
gunk to allow for sequence, branching, and cycling. Later,
Let's say that these three design operations are sufficient for programming tasks
To solve. We not only define these constructs, but we also examine prog-
their ram function and their weakest prerequisites.

6.1. Permissible constructions


The first definition is about running a program directly after another,
*
let's go. In the definition we will use the following mark: let α be ∈A ,
**
β∈A ,

χ ( α, β ) :: = red ( con ( α, β )) .
2

6.1. DEFINITION : SQUARE


** be the **
Let S , S ⊆ A × A programs. The relation S ⊆ A × A is S and S
sequence
1 is2 called, and ( S ; S ) is denoted when ∀a ∈ A : 1 2
1 2

{α ∈ A | α ∈ S ( a ) } ∪

S(a) =
∪ **
1 *
{χ ( α, β ) ∈ A | α ∈ S ( a ) ∩ A and β ∈ S ( τ ( α )) }.
2 1 2

Note that if we form the sequence of two programs that value-


the set contains only finite sequences, then the sequence is only finite serial,
allocate tokens to your status point points.

74 6. PROGRAM STRUCTURES


S
1

S S
1 2
• ∞
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 61/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
• S
2

6.1. figure. Sequence

Similarly, it is also possible to control deterministic programs


the sequence is a deterministic relation (function).
The program constructs with structural diagrams, so-called structuralograms
we are depicted.
Let S , S program The -n. Then the S = ( S ; S ) sequence structures
1 2 1 2
togramja:
S

S
1
S
2

Our second design option is to have different existing programs


perform under certain conditions.
6.2. DEFINITION : THIS LIGHTING
Let π . . . , Π : A → condition L, S ,. . . , S programs A -n. That's it
1 A n 1 n
The IF × ⊆ relation of S skilled -kből, π branching as defined by s
**

( π : S , ..., π : S ) if ∀a ∈
i A : i
1 1 n n


IF ( a ) = w ( a ) ∪ w ( a ) ,
i 0
i=1

where ∀i ∈ [1 ..n ]:
{
S ( a ) , if a ∈ ⌈π ⌉ ;
w (a) =
i ∅ and otherwise;
and

and

6.1. CONFIRMED CONSTRUCTIONS 75

{
{ < A, a, a,. . . > }, If ∀i ∈ [1 ..n ]: a ∈ ⌈π ⌉ ;
w (a) =
0 ∅ otherwise .
and

S •
1


⌈Π 1 ⌉

S1 •

S •
2

• S ⌈Π 2 ⌉
2

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 62/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
S ∞
2

6.2. figure. Branching

In the definition of the branch we did not rule out that the conditions were disaggregated, therefore
there may be several conditions at a point in the state space. In this case the branch
assigns all the sequences to this point that is at least one
program assignment, the condition of which is true at this point. Therefore if a
the conditions are not discouraged, it is a branching of deterministic programs
can be non-deterministic.
The definition of the branching could also be written:
⋃ ⋂
IF = S | and ⌉ ∪ { < a, ... > ∈A ** |a∈ ⌈¬π and ⌉}.
and ⌈π
i=1 i=1

If we are only branching out programs that are only finite


are assigned to each point in the state space, the branch can still be ordered
infinite series of points (identical elements) if the truths of the conditions are true
does not cover the whole state of space.
Note that, according to the definition, if one of the conditions is not met,
the branching "gets away", unlike most programming languages used in practice.
Let S , S ,. . . S programs, π , π . . . , π conditions A -n. That's it
1 2 n 1 2 n
IF = ( π : S , π : S , ..., π : S ) elágazásstruktogramja:
1 1 2 2 n n

76 6. PROGRAM STRUCTURES

IF
1 2 n
\π \π \. \π
S S S
1 2 n

Our third design option is to make an existing program one


depending on the condition, every time we perform one after the other. To define the cycle
we need two more markings: finite many or infinite many series
reduction of its concatenation.
1 2 * n **
Let α , α ,. . . , α n- 1 ∈ A and α ∈A ,
1 2 n 1 2 n
χ ( α , α , ..., α ) :: = red ( kon ( α , α , ..., α )) .
n
i *
Let α ∈A ( i ∈ N),
1 2 1 2
chi ( α , α , ... ) :: = red ( kon ( α , α , ... )) .

6.3. DEFINITION : C IKLUS


**
Let π : A → L condition and S Program The -n. The relation DO ⊆ A × A is
S is called the cycle with the π0 condition and is ( π, S 0 ) when
0

• ∀a ∈ ⌈π⌉ :
DO ( in ) = { < to > } ;

• ∀a ∈ ⌈π⌉ :
** 1 n ** 1 n
DO ( a ) = {α ∈ A | ∃α . . . , Α ∈A : α = χ ( α ..., Α ), and
n

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 63/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
1 i *
α ∈ ∈S S0 ( a( τ) and
α i +1 (α ∀
i
∈ [1τ ..n
))i and
i
) ∈(⌈πα⌉ )∈and
( α- 1]: A (andn ∞
α ∈ A or
n *0 n
( α ∈ A and τ ( α ) ∈ ⌈π⌉ )) } ∪
∪ ∞ i * 1 2
{α ∈ A | ∀i ∈ N ∃α ∈ A : α = chi ( α , α ..., ) And
1 i ∞* i
α ∈ S ( the ), and ∀i ∈ N ( α ∈A and α i +1 ∈ S ( τ ( α )) and
i 0 0
τ ( α ) ∈ ⌈π⌉ ) }.

At first glance the definition is somewhat complicated. Let's take a closer look. The cycle-
seed - S - finite many times can be applied successively because either to a point
0
obtained, wherein the loop condition - π - is not satisfied (in the figure 6.3. of point), or the S
1 0
assigns an infinite sequence to a point (in Figure 6.3, point a ). These are the cases
2
contains the first set in the definition. Figure A third option (6.3. In the
3
point) is that none of the above are met, ie S infinitely many times applicable
0 is
one after another. This case is included in the definition of the second set.

6.1. CONFIRMED CONSTRUCTIONS 77

THE
S
S • 0
0

S •
0

a • S
⌈π⌉ 1
S • 0 ⌈¬π⌉
a • 0

2

• S
S 0
a • 0 •
3
S
0
• S
0

6.3. figure. Cycle

Based on these, we can also conclude that it is a deterministic program


cycle will be deterministic, in contrast, if a finite sequence is
cycle, then the value set for the cycle may still contain
endless series (see third option), that is, there are two reasons for being "infinite
cycle. "
We should also note that there are several cycles in different programming languages
exists; what we have now defined is the so-called "type while" cycle.
Let S be a condition , π condition A -n. Then the structure of the DO = ( π, S ) cycle is:
0 0
DO

π
S
0

The above described constructions can be applied to programs. But is it progra-


are they created? The following entry states that the three defined above
a constructive operation actually creates programs from existing programs.

6.1. COMPOSITION : The SEQUENCE , THE PROGRAM CYCLE AND branches .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 64/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
**
Let the
and π, πarbitrary
, π . . state
. , π of
: AS →, SL conditions
, S ,. . . , A
S -n. At ⊆A×A programs,
1 2 n 0 1 2 n

1. S = ( S , S ),
1 2
2. IF = ( π : S , π : S , ..., π : S ),
1 1 2 2 n n

78 6. PROGRAM STRUCTURES

3. DO = ( π S )
0

Programs The -n.

Proof: Definition of all three constructs explicitly states that part A ×


**
For . Hereinafter, the three criteria are met
construction.

Let ∈ A be arbitrary, then S ( a ) has at least one element. If this is the


First
1
series is infinite, the first set of definitions is not empty, if it is finite, it has its endpoint,
to which S assigns at least one sequence and hence the definition of second hal-
2
empty is empty, so S ( a ) is not empty.
Let α ∈ S ( a ). Two cases are possible:

• If α ∈ S ( a ), in this case α = a and α = red ( α ) are trivially fulfilled,


1 1
since S program.
1
1 2 1 2 1
• If α = χ ( α , α ) such that α ∈ S ( a ) and α ∈ S1 ( τ ( α )). Then a
χ defined as α reduced. On the other hand, α =1 ,αso α 1 = a .
2 1 2

2 is 1
Let a ∈ A is arbitrary, then one or π condition is true in on, so
Second
i
w ( a ) is not empty, or w ( a ) is not empty, so IF ( a ) is not empty.
i 0
Let α ∈ IF ( a ). At

α∈w (a).
i
i=0

• Suppose that α ∈ w ( to ). Then α = < a, a ,. . . > , So it fulfills the prog-


0
criterion of definition of ram.
• Suppose ∃i ∈ [1 ..n ]: α ∈ w ( in ). Then α ∈ S ( a ), so that S
i i i
program, α satisfies the properties required in the definition.
Let a ∈ A be arbitrary, then, or for every n ∈ N, the definition is met
Third
the second set of the set, or if not, then the first one, that is, the two
At least one of the sets is not empty, so DO ( a ) is not empty.
Let α ∈ DO ( a ).

• Suppose that ∈ ⌈π⌉ . Then α = < on > to give the required properties
trivially fulfilled.
• Suppose that ∈ ⌈π⌉ . Three cases are possible:
*
(a) α ∈ A : 1 N
Then ∃n ∈ N α = χ ( α , α... ), which1 - χ by the definition of
1
1,
- α reduced. On the other hand, using α ∈ S ( a ) and α = α
n n

α = a is also satisfied. 0 1
1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 65/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

6.2. THE PROGRAMMING OF PROGRAM STRUCTURES 79

1 N i *
(B) ∃n ∈ N α = χ ( α , α... ) and ∀i ∈ [1 ..n - 1]: α ∈ A and α ∈

n n
A : Then the criteria are met in the same way as in the previous section
verifiable.
1 2
(c) α = chi ( α , α ,... ): 1
Then α is a series reduced by the definition of χ and α = α 1 = the

is also met. ∞ 1

6.2. Program function of program constructions


After we've realized that existing programs are new with program design
you can create programs, examine the relationship between the built-
mok program function and the program function of the original programs.
The sequence is the simplest program design, accordingly the prog-
ram function can simply be described in the program function of the two component programs.
with help. Since the sequence means performing sequentially two programs,
its program function is expected to be the program function of the two component programs
composition. However, as we will see, rather than composing a strict composition
should be used.

6.2. SUBJECT : PROGRAM OF SEVEN


Let A be a state state, S , S programs A -n, S = ( S ; S ). At
1 2 1 2

P(S)=P(S )⊙P(S ).
2 1

Proof: Let ∈ A be arbitrary. At


*
a ∈ *D p ( S ) ⇐⇒ S ( a ) ⊆ A ⇐⇒ *
S ( a ) ⊆ A and ∀α ∈ S ( a ): S ( τ ( α )) ⊆ A ⇐⇒
1 a∈D p ( S 1 ) and p ( S11 ) ( a ) ⊆ 2 D p ( S 2 ) ⇐⇒

a∈D p ( S 2 ) ⊙ p ( S 1 ) ,

thus:
D p ( S ) = D p ( S2 ) ⊙ p ( S 1 ) .
Let ∈ D p ( S ) . At
'
( A, a ) ∈ P ( S ) ⊙ P ( S ' ) ⇐⇒
∃b ∈ A : ( a, b ) ∈ p ( S 1 )2 and ( b, a 1 ) ∈ p ( S 2 ) ⇐⇒'
∃α ∈ S 1 ( the ): ∃β ∈ S 2 ( 'b ): τ ( α ) = b and τ ( β ) = the ⇐⇒
( a, a ) ∈ p ( S ) .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 66/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

80 6. PROGRAM STRUCTURES

Notice that it is so in the interpretation range of the non-strict composition


the point to which the sequence also assigns an endless series. Let's look at this one
A simple example: Let A = { 1 , 2 } ,

S = { (1 , < 1 > ) , (1 , < 1 , 2 > ) , (2 , < 2 > ) }


1
S = { (1 , < 1 , 2 > ) , (2 , < 2 , 2 ,... > ) }.
2

Then 1 ∈ D p ( S 2 ) ◦p ( S 1 ) , but < 1 , 2 , 2 , 2 , ... > ∈ S (1).


Since the branching is made up of several programs, its program function is only slightly different
more difficult to formulate. It's a branch to a point
whether it's an endless series, it depends on the conditions that are true at that point. In fact,
if a single condition is not true at a point,
regardless of the function of the branch, there will be no program function of the branch
interpreted. Specify the program function of the junction for the next batch.

6.3. COMPOSITION : The Z branching PROGRAMFÜGGVÉNYE


**
Be the arbitrary state space, S , S ,. . . , S ⊆ A × A programs,
1 2 n
and π , π . . . , Π : A → condition L of n, IF = ( π : S ..., Π : S ).
1 2 n 1 1 n n
At

• D p ( IF ) = {a ∈ A | a ∈ ⌈Π and ⌉ and ∀i ∈ [1 ..n ]: a ∈ ⌈π and ⌉ ⇒ a ∈
i=1
D p ( Si ) }.
• ∀a ∈ D p ( IF ) :

p ( IF ) ( a ) = p ( S ) |and ⌉ ( a ) .
i ⌈π
i=1

Proof: Let ∈ A be arbitrary. At


*
a ∈ D p ( IF ) ⇐⇒ IF (⋃a ) ⊆ A ⇐⇒
∃i ∈ [1 ..n ]: a ∈ ⌈π ⌉ and w ( a ) ⊆ A * ⇐⇒
i
i=1 i
∃i ∈ [1 ..n ]: a ∈ ⌈π and ⌉ and ∀i ∈ [1 ..n ]: a ∈ ⌈π and ⌉ ⇒ a ∈ D) .p ( S i

Let ∈ D be p ( IF ) . At

⋃ ⋃
p ( IF ) ( a ) = {τ ( α ) | α ∈ w ( a ) } = p ( S ) |and ⌉ ( a ) .
i i ⌈π
i=1 i=1

Of course, if the branch conditions cover the whole status space, then a
It is a condition that any π must be true is obviously met.
i
The program function of the cycle is expressed by the closed condition of the condition.

6.3. TASKS 81

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 67/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
6.4. ITEM : CYCLE PROGRAM GUIDE
Let A be a state state, S program, π condition A -n, DO = ( π, S ).
At
p ( DO ) = p ( S ) | π.
Proof: Let ∈ A be arbitrary. At
*
a ∈ D p ( DO ) ⇐⇒ DO ( a ) ⊆ A

{ < To > } if ∈ ⌈π⌉ ;
* 1 n
{α ∈
1
A | ∃n ∈ N α = χ ( α ..., Α ), and
DO ( a ) = α ∈ S ( a ) and ∀i i ∈ [1 ..n - 1]:
n
i
≠ ( α and +1 ∈ S ( τ ( α )) and τ ( α ) ∈ ⌈π⌉ ) and
n
τ ( α ) ∈ ⌈π⌉}, if ∈ ⌈π⌉.


the ∈ ⌈π⌉ or ( ∃β ∈ A : β = to* and ∀i ∈ N ( β i +1 ∈ P ( S ) ( β ) and β ∈ ⌈π⌉ ))
and ( ∃β ∈ A ( β = to and ∀i ∈ [1 .. | β | - 1]:
1 i i

( Β i +1 ∈ P ( S ) ( β ) and β 1∈ ⌈π⌉ ) and τ ( β ) ∈ ⌈π⌉ and τ ( β ) ∈ D p ( S ) ) .


i i

a∈D p ( S ) | π ,
so D p ( DO ) = D p ( S ) | π . Let ∈ D p ( DO ) be on the other hand .
• If ∈ ⌈π⌉ , then
p ( DO ) ( a ) = {a} = p ( S ) | π ( a ) .

• If ∈ ⌈π⌉ then p ( DO ) ( a ) =
* 1 n 1
=
{τ ( α ) | α ∈ A and ∃n ∈ N α = χ (i α ..., α ),i and α ∈ S ( in ) and n
∀i ∈ [1 ..n -* 1] ( α i +1 ∈ S ( τ ( αn )) and τ ( α ) ∈ ⌈π⌉ ) and τ ( α ) ∈ ⌈π⌉}
= {τ ( β ) | β ∈ A and β = a and ∀i ∈ [1 .. | β | - 1]: ( β and +1 ∈ p ( S ) ( β ) and
β ∈ ⌈π⌉ ) and τ ( 1β ) ∈ ⌈π⌉} = i
and k
= {b ∈ A | ∃k ∈ N: b ∈ ( p ( S ) | π ) ( a ) and b ∈ ⌈π⌉}
= p(S)|π(a).

6.3. Tasks
6.1. A = { 1 , 2 , 3 , 4 , 5 , 6 } . ⌈Π ⌉ = { 1 , 2 , 3 , 4 } . ⌈Π 2 ⌉ = { 1 , 3 , 4 , 5 } .
1

S ={ 1 → 14 1 → 12 . . . 2 → 2132 3 → 36
1
4 → 463 4 → 451 5 → 563 6 → 612 },
S ={ 1 → 134 1 → 121 2 → 2132 . . . 3 → 36
2
4 → 463 4 → 451 . . . 5 → 5632 6 → 61 . . . }.

82 6. PROGRAM STRUCTURES

Enter the programs ( S , S ), IF ( π : S , π : S ), DO ( π , S )


1 2 1 1 2 2 1 1
programfüggvényeiket!
6.2. Let A = { 1 , 2 , 3 , 4 , 5 , 6 } , ⌈π ⌉ = { 1 , 2 , 3 , 4 } , ⌈π ⌉ = { 2 , 3 , 4 } , ⌈π ⌉ =
1 2 3
{ 1 , 4 , 6 } and
S ={ 1 → 12 . . . 2 → 23 3 → 3456
1
4 → 463 5 → 53 6 → 62 },
S ={ 1 → 12 2 → 24 3→3...
2
4 → 43 5→5 6 → 61 },
1 → 12 2 → 2 . . . 3 → 31

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 68/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
S ={ 4 → 432 5 → 5 . . . 6 → 63 . . . }.
3
What will be IF ( π : S , π : S , π : S ), D p ( IF ) , p ( IF )?
1 1 2 2 3 3

6.3. Let S and S a program in state A. Is it true that S ◦ τ ◦ S


1 2 be 2 1
is equal to ( S ; S )?
1 2

6.4. S = ( S , S ). Is it true that


1 2

a) D p ( S ) = ⌈lf ( S , P ( D p (2S) )) ⌉ ?
1
b) optional R postcondition: lf (( S ; S ) , R ) = LF ( S -f ( S , R ))?
1 2 1 2

6.5. Is there a program that can be written as a sequence, also as a branch, and
can also be written as a cycle?
6.6. Is it true that all programs can be described as sequences, as well as branching, and
can also be written as a cycle?

6.7. IF = ( π : S , ..., π : S ). Is it true that D p ( IF ) = ( ⌈Π ⌉ ∩ D p k( )S)?
1 1 n n k
k=1

6.8. Let S , S ,. . . , S program A -n. IF = ( π : S , ..., π : S ). S =


S ∪ S ∪ ··· ∪ S . Let us find π conditions and S programs that
1 2 n 1 1 n n

D p ( IF ) = A and D p ( S ) = ∅ !
1 2 n k k

6.9. IF = ( π : S , ..., π : S ). S = S ∪ S ∪ ··· ∪ S . Is it true that p ( IF )


1 1 n n 1 2 n
is part of p ( S )?
6:10. Is it true? If IF = ( π : S , π : S ) then D p ( IF ) = ( ⌈π ⌉ ∩ ⌈π ⌉ ∩ D p ( S1 ) ∩
D p ( S2 ) ) ∪ ( D p ( S1 ) ∩ ( ⌈Π ⌉ \ ⌈π ⌉ )) ∪ ( D p (2S) ∩ ( ⌈Π ⌉ \ ⌈π ⌉ ))?
1 1 2 2 1 2

1 2 2 1

6:11. A = { 1 , 2 , 3 , 4 } .
IF

\ i=1 \ i≤ 2
i:=2i SKIP

6.3. TASKS 83

What has sequences S , S , IF specific aspects of the state space?


1 2

6:12. S = ( S , S ). S solves F and S solves F . To solve S for


1 2 1 1 2 2

a) F = F ◦ F task?
2 1
b) F = F
2
⊙ F 1 task?
6:13. S = ( S , S ). Solution S ( F ⊙ F ).
1 2 2 1
To solve S to F eth or S in the F -t?
1 1 2 2

6:14. IF = ( π : S , ..., π : S ). F ⊆ A × The task. ∀k ∈ [1 ..n ]: S solves


1 1 n n k
the F | k ⌉ task.
⌈π
a) IF resolves the F task?
b) IF solves the function F if π
1
∨ π 2 ∨ · · · ∨ π n = Is it true?
c) IF solves the problem F if D
F
⊆ ⌈π 1 ∨ π 2 ∨ · · · ∨ π n ⌉ ?
6.15. IF = ( π : S , ..., π : S ). F ⊆ A × The task. IF solves task F.
Is it true that ∀k ∈ [1 ..n ]: S solves F |
1 1 n n
k ⌉ task?
k ⌈π
6:16. IF = ( π : S , ..., π : S ). F , ..., F ⊆ A × The task. ∀k ∈ [1 ..n ]: S
solve the F job. Solves IF to the F = F ∪ · · · ∪ M task?
1 1 n n 1 k k

's 1 n

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 69/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
6.17. IF = ( π : S , ..., π : S ). F ⊆ A × The task. IF solves the task F ,
and ⌈π ⌉ ∪ · · · ∪ ⌈π ⌉ ⊆ D . Is it true that ∀k ∈ [1 ..n ]: S solves F |
1 1 n n

1 n F k ⌈π
k ⌉
task?

6.18. IF = ( π : S , ..., π : S ). F , ..., F ⊆ A × The task. ∀k ∈ [1 ..n ]:


D k ⊆ ⌈π ⌉ , and S solves the M job. F = F ∪ · · · ∪ F . Resolves
1 1 n n 1 n

F k k 's 1 n
IF the F task?

6.19. Is it true that IF = ( π : S , π : S ) and IF = ( π : S , π ∧π : S ∪ S , π :


1 1 1 2 2 2 1 1 1 2 1 2 2
S )
2

a) is it equal?
b) Equivalent?

6:20. Let IF be = ( π : S , π : S ), IF = ( π : S , π : IF ), IF = ( π :
S , π ∧ π : S , π ∧ π : S ). Is it true that IF and IF
34 3 3 4 4 1 1 1 2 34 2 1

1 2 3 3 2 4 4 1 2

a) is it equal?
b) Equivalent?

6:21. F ⊆ A × The task. S program A -n. S solve M eth. Solves the


0 0
DO ( π, S ) is the closing of the task F for π ?
0

84 6. PROGRAM STRUCTURES

6:22. Let DO = ( π, S ). Is it true that

a) p ( DO ) ⊆ p ( S )?
b) p ( S ) ⊆ p ( DO )?

6.23. A = N ×N
0 0
i n
S = ( i : = 0; DO ( i = n, IF (2 | i : i : = i + 1 , 2 | i : i : = i + 2)))
S

i:=0
i=n
2|i 2|i
\ \
i:=i+1 i:=i+2

What sets do S (2 , 4) and (3 , 7) points for?

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 70/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 7

Discharge rules

In this chapter, we examine the relationship between program configurations and specification
Receipt.

7.1. The sequencing rule of the sequence


First, we will investigate whether the sequence corresponds to a given primary condition,
the weaker prerequisite of what the programs that make up the program are the weakest
It is acknowledged.

7.1. SUBJECT : THE RULES FOR THE SURVEY


'
Let S = ( S ; S ), and where Q , R and Q adjustment of -n. If
1 2
'
(1) Q ⇒ lf ( S , Q ) and
' 1
(2) Q ⇒ lf ( S 2 , R ),
then Q ⇒ lf ( S, R ).

Proof: Let q ∈ ⌈Q⌉ . Then for (1) q ∈ D p ( S .As


1 ) and P ( S 1 ) ( q ) ⊆⌈Q ' ⌉
2 ) ( q∈D p ( S
'
(2) ⌈Q ⌉ ⊆ D p ( S ) ) ⊙p ( S 1 ) = D p ( S ) .
Furthermore, (2) p ( S ) p ( S ) ( q ⊆ ) ⌈R⌉ , so q ∈ lf ( S, R ).
2 1
Based on the sequence deduction rule and the theorem of the specification, the following
we can say that if S and S are programs in which every parameter b point-
where Q ⇒ lf ( S , Q b ) and Qb ⇒ lf ( S 2 , R b ) is satisfied, then ( S 1 , S 2 ) resolves a
1 ' 2 '

Q , R pairs.
b 1
b b

7.2. ITEM : A SEQUENCE OF RECONCILIATION RULE REVERSAL


Let S = ( S ; S ) and Q , R be statements A -n for which Q ⇒ lf ( S, R ).
' 1 2
Then ∃Q : A → L, for which
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 71/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

86 7. RULES OF PROCESSING

⌈Q⌉ '
⌈R⌉
⌈Q ⌉
p(S ,S )
1 2


p(S ) •
2
• P(S ) •
1

7.1. figure. The sequencing rule of the sequence

'
(1) Q ⇒ lf ( S , Q ) and
' 1
(2) Q ⇒-f ( S 2 , R ).
'
Proof: Let Q = lf ( S , R ). Then (2) is automatically completed. Only (1)
we have to look at the2 situation. Indirectly, we assume that

∃q ∈ ⌈Q⌉ : q ∈ ⌈lf ( S 1 -f ( S 2 , R )) ⌉.
This can happen in two ways:

• q∈D p ( S 1) , a deezellentmond condition, whereby ⌈Q⌉⊆D p ( S ) ⊆


D p ( S1 ) .

• P ( S ) ( q ) ⊆ ⌈lf ( S , R ) ⌉ . Then let r ∈ p ( S ) ( q ) \ ⌈lf ( S , R ) ⌉ . Then two


1 2 1 2
case is possible:

- r∈ D p ( S 2 ). It is to be understood that q∈D p ( S 2 ) ⊙ p ( S 1 ) .


- P ( S ) ( r ) ⊆ ⌈R⌉ Let s ∈ P ( S ) ( r ) \ ⌈R⌉ . Then s ∈ p ( S ) ( q ) and
s ∈ ⌈R⌉ , and this contradicts the condition p ( S ) ( q ) ⊆ ⌈R⌉ .
2 2

7.2. The derivation rule of the branch


Let's examine what is the link between the branching and the programs that make up the given post-
which is the weakest prerequisite for this.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 72/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

7.2. THE RULES FOR THE JURISDICTION 87

7.3. COMPOSITION : The Z branching RECONCILIATION RULES


Be IF = ( π : S ..., Π : S ), and where Q , R assertion of -n. If
1 1 n n

(1) Q ⇒ π ,
i i= 1
(2) ∀i ∈ [1 ..n ]: Q ∧ π and ⇒ lf ( S i , R )
then
Q ⇒ lf ( IF, R ) .

Proof: Let q ∈ ⌈Q⌉ and assume that any condition is true of q , i.e.
∃i ∈ [1 ..n ]: q ∈ ⌈π ⌉ . Then q ∈ D p ( IF ) , in fact
and

∀j ∈ [1 ..n ] q ∈ ⌈π j ⌉ ⇒ q ∈ ⌈lf ( S j , R ) ⌉ ⇒ q ∈ D p ( S j) .

Since ∀j ∈ [1 ..n ]: q ∈ ⌈π ⌉ ⇒ p ( S j ) ( q ) ⊆ ⌈R⌉ :


j

p ( IF ) ( q ) = P ( S ) ( q ) ⊆ ⌈R⌉,
j
j ∈ [1 ..n ]
q∈⌈π j ⌉

ie q ∈ ⌈lf ( IF, R ) ⌉ .

⌈Q⌉ ⌈Π ⌉ P(S ) ⌈R⌉


1
1

p(S ) •
⌈Π 2 ⌉ 2

• •
p(S )
3

⌈Π 3 ⌉ •

p(S )
4

⌈Π 4 •⌉ •

7.2. figure. The derivation rule of the branch

Using the specification item and the derivation rule of the branch,
Let's say: Give the job specification F ( A, B, Q, R ). Then if all b ∈ B
parameter and each S scheme Q ∧ π ⇒-f ( S , R ) and each b parameter
there is a condition π for which Q ⇒ π then the branch solves Q , R
i b i i b

i b i b b
pair-specific task.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 73/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

88 7. RULES OF PROCESSING

Similarly to the derivation rule of the sequence, the derivation rule of the branch
reversible, so if a branch solves a specified task, it can be down
drive.

7.4. COMPOSITION : The Z branching RECONCILIATION RULE OF REVERSAL


Let IF = ( π : S , ..., π : S ), and Q , R be statements A -n for which
1 1 n n

Q ⇒ lf ( IF, R ) .

At

(1) Q ⇒ π ,
i i= 1
(2) ∀i ∈ [1 ..n ]: Q ∧ π and ⇒ lf ( S i , R ).
Proof: If q ∈ ⌈Q⌉ then q ∈ D p ( IF ) , ie ∃i ∈ [1 ..n ]: q ∈ ⌈π ⌉ . So (1)
i
met.
Then we see that (2) is also fulfilled. Let's suppose indirectly that

∃i ∈ [1 ..n ]: ⌈Q ∧ π and ⌉ ⊆ ⌈lf ( S i , R ) ⌉.


Let q ∈ ⌈Q ∧ π ⌉ \ ⌈lf ( S i , R ) ⌉ . Two cases are possible:
and

• q∈D p ( S i ). An absolute contradiction assumption is that q∈D p ( IF ) .

• p ( S ) ( q ) ⊆ ⌈R⌉ . At
i

p ( S ) ( q ) ⊆ p ( IF ) ( q ) ⊆ ⌈R⌉,
i

so we got a contradiction.

7.3. Cycle derivation rule


Like the previous two constructs, we are now examining the relationship
cycle and the weakest prerequisite of the cycle core.

7.5. BINDING : CYCLE PURPOSE RULES


Where P , Q , R assertion of n, is : A → Z function and let DO = ( π S ). If
0

(1) Q ⇒ P ,
(2) P ∧ ¬π ⇒ R ,
(3) P ∧ π ⇒ t> 0,
(4) P ∧ π ⇒-f ( S , P ),
0

7.3. CYCLE PURPOSE RULES 89

⌈P ⌉ ⌈π⌉ ⌈¬π⌉

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 74/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

P(S )
0 ⌈R⌉
⌈Q⌉

7.3. figure. Cycle derivation rule

(5) P ∧ π ∧ t = t ⇒-f ( S 0 , t < 0 ),


0

then
Q ⇒ lf ( DO, R ) .

According to the article, we should see that:


(1) ∀q ∈ ⌈Q⌉ : q ∈ D p ( DO ) = D p ( S 0) | π and

(2) ∀q ∈ ⌈Q⌉ : p ( DO ) ( q ) ⊆ ⌈R⌉, that is p ( S 0 ) | π ( q ) ⊆ ⌈R⌉ .


Be hereinafter referred to as g = p ( S ) | π . Before the deduction rule itself is proven
0
we see two attributes of this g relationship.

Claim 1: Let q ∈ ⌈P ⌉ . At
k
∀k ∈ N 0 : g ( q ) ⊆ ⌈P ⌉.
Proof of total induction by k :
0
• k = 0: g ( q ) = {q} ⊆ ⌈P⌉ .
k k
• Assume that g ( q ) ⊆ ⌈P ⌉ . Let r ∈ g ( q ) be arbitrary. Then there are two cases
possible:

- r ∈ ⌈P ∧ ¬π⌉ . Then g ( r ) = ∅ ⊆ ⌈P⌉ .


- r ∈ ⌈P ∧ π⌉ . Then for (4) r ∈ D p ( S 0) and g ( r ) = p ( S 0 ) ( r ) ⊆⌈P⌉ .

90 7. RULES OF PROCESSING

So: g k +1 ( q ) ⊆ ⌈P ⌉ .

Claim 2: Let q ∈ ⌈P ⌉ . At
n
∃n∈N0:g ( q ) = ∅.
n
Proof: Indirect: Suppose that ∀n ∈ N : g ( q ) = ∅ . Then ∀n ∈ N case
there exists max
n
t(b). 0 0

b∈ g ( q )
This is true for k = 0. If

m = maxk t ( b ) ,
b∈g ( q )
k
then ∀r ∈ g ( q ) has the following two possibilities:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 75/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
• r ∈ ⌈P ∧ ¬π⌉ . Then g ( r ) = ∅ .
• r ∈ ⌈P ∧ π⌉ . Then for (5) r ∈ D p ( S 0) and ∀x∈g ( r ): t ( x ) <t ( r ) ≤m .

Since we have assumed that g k +1 ( q ) = ∅ , the second option is satisfied for at least one r .
So the maximum for all n would exist, or even strictly monotonous.
This contradicts (3), since t is a whole-value function.

Proof: (Cycle derivation rule) Let q ∈ ⌈Q⌉ be arbitrary. Because of (1)


⌈Q⌉ ⊆ ⌈P ⌉ , so q ∈ ⌈P ⌉ is satisfied.
Then based on Statement 2
n
∃n ∈ N 0 : ( P ( S 0 ) | π ) ( q ) = ∅,
say
q∈D p ( S 0) |π= D p ( DO ) .
Based on the closed definition of the condition,

p ( DO ) ( q ) ⊆ ⌈¬π⌉.

Secondly, for the 1st statement


p ( DO ) ( q ) ⊆ ⌈ P ⌉,
and then (2)
p ( DO ) ( q ) ⊆ ⌈P ∧ ¬π⌉ ⊆ ⌈R⌉,
so
q∈∈lf ( DO, R ) ⌉.

7.3. CYCLE PURPOSE RULES 91

The P statement in the deduction rule is determined by the invariant property of the cycle , t
function is termination function . The invariant P is subject to conditions (1) and (4)
ensure: they guarantee that the invariant property is all run of the cycle core
before and after being fulfilled. The termination function provides the end of the cycle: the (5)
every run of the cycle core reduces at least one of the terminating dependencies,
(3), the termination function must be positive. Condition (2)
tel guarantees that if the cycle is completed, then the post-condition comes into the truth.
By using the cycle management method and the specification item,
a condition can be given for the solution: if the job specification ( A, B, Q, R ) is given,
and we find invariant statements and terminating functions such that the parameter space is all
the condition of the cycle deduction rule is fulfilled, the cycle resolves the
( Q , R ) pairs.
b b
The cycle's derivation rule is not true backward, ie there is a cycle that is
can not be deduced. This is because it is a function of a derived cycle
it is always barred closed, since the terminating function is at every point of the state space
value limits the number of threads of the loop core.
However, if the cycle function of a cycle is equal to the cyclic core cycles,
limiting the condition, the cycle can be deduced.

7.6. ITEM : A CYCLE REVERSAL OF RECONCILIATION RULE


Be DO = ( π, S ), and Q , R are statements A -n to which Q is
0

lf ( DO, R ) and suppose p ( DO ) = p ( S ) | π . Then there is a P statement
0
and t : A → Z functions to which
(1) Q ⇒ P ,
(2) P ∧ ¬π ⇒ R ,
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 76/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
(3) P ∧ π ⇒ t> 0,
(4) P ∧ π ⇒-f ( S , P ),
0
(5) P ∧ π ∧ t = t ⇒-f ( S , t < ).
0 0 0

Proof: Let P = lf ( DO, R ) and choose t such that ∀a ∈ A :


{
0, if ∈ D p ( DO ) ∩ ⌈π⌉ ;
t(a)=
max {i ∈ N | p ( S ) ( a ) ∩ ⌈π⌉ = ∅},if ∈ D p ( DO ) ∩ ⌈π⌉.
and

0
At
(1) Q ⇒ lf ( DO, R ) is trivially fulfilled.

(2) Let a ∈ ⌈P ∧ ¬π⌉ . Then because ∈ ⌈lf ( DO, R ) ⌉ , p ( DO ) ( a ) ⊆ ⌈R⌉ .


On the other hand because ∈ ⌈¬π⌉ , p ( DO ) ( a ) = {a} . So the ∈ ⌈R⌉ , that is, ⌈P ∧ ¬π⌉ ⊆
⌈R⌉ .
(3) t is obvious.

92 7. RULES OF PROCESSING

(4) Using the locked feature of that

a∈D =⇒R(a)⊆D ,
R R

the next result is obtained. Let ∈ ⌈lf ( DO, R ) ∧ π⌉ . At

a∈D p ( S 0) and p ( S ) ( a ) ⊆ ⌈lf ( DO, R ) ⌉,


0

so
a ∈ lf ( S , P ) .
0

(5) From the definition of t , it can be seen that one cycle execution of the loop core decreases
the termination function value is:
Let ∈ ⌈P ∧ π⌉ , t = t ( a ), b ∈ p ( S ) ( a ). Then if
0 0
and
t ( a ) = max {i ∈ N | p ( S ) ( a ) ∩ ⌈π⌉ = ∅},
0

then
t ( b ) <t ( a ) ,
say
t ( b ) <t .
0

That the sealed and the bounded seals are the same, we used the definition of t
out: this condition guarantees that the maximum finite in the definition is finite.
Note: Since the cycle's derivation rule can not be reversed, not all
but this is not a substantive restriction. If there is a cycle,
which solution to a task, there is certainly a cycle that a
condition is the same, it is also a solution to the task and its program function is limited
closed.
The definition of cycle seems that if S
1
⊆ S 2 then DO 1 ( π, S 1 ) ⊆
DO ( π, S ) and 2.7. example DO solution for all tasks that
2 2 1 is a
s DO solution. So S can be deterministic, and then it can be closed
2 1
p ( S ) | π is certainly bounded.
1

7.4. Tasks
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 77/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

7.1. Let us assume that all five conditions for the rule of the cycle's derivation are met and
Q is not empty. Can be empty a

the)⌈P ∧ R⌉ set?
b) ⌈P ∧ ¬π ∧ R⌉ set?

7.4. TASKS 93

7.2. Let us assume that all five conditions for the rule of the cycle deduction are fulfilled,
and ( Q ∧ π ) are not empty. Can the lf ( S , P ) and lf ( DO, R )
0
section of justice?

7.3. Let's assume that all five conditions of the cycle's derivation rule are met.
Let g = p ( S ) | and q ∈ ⌈P ⌉ ∩ ⌈π⌉ . Is it true that
0 ⌈Π⌉
the)∀k ∈ N : g k ( q ) ⊆ ⌈P ⌉ ?
k 0
b) b ∈ g ( q ) ∩ ⌈π⌉ ∩ ⌈P t ⌉ ⇒ ( b ) ≤ t ( q ) - k ?
c) g | π = p ( S ) | π ?
0
k
d) ∃k ∈ N : k ≤ t ( q ) and g ( q ) ⊆ ⌈¬π⌉ ?
0
'
7.4. Let S = ( S ; S ) and Q , Q and R be statements for which
' '
⇒ Q-f ( S 1 1, Q 2) ,, Q ⇒-f ( S 2 , R ) , Q-f ⇒ ( S,' R ). '
Is it possible that ⌈Q⌉ ∩ ⌈R⌉ = ∅ and ⌈Q⌉ ∩ ⌈Q ⌉ = ∅ and ⌈Q ⌉ ∩ ⌈R⌉ = ∅ ?
Reason if not, and write an example if yes.

7.5. A = Z × N
0
x y
B=Z×N
' 0 '
x y ' '
Q: ( x = x ' ∧ y' = y )
R: ( x = x - y ∧ y = 0)
S = { ( x, y ) , < ( x, y ) , ( x - 1 , y ) , ( x - 1 , y - 1) > ) | x ∈ Z and y ∈ N } ∪
{ (( X, 0) , < ( x, 0) > ) | x ∈ Z }
0

DO = { (( X, y ) < ( x, y ) , ( x - 1 , y ) , ( x - 1 , y - 1) , ( x - 2 , y - 1) ,
( X - 2 , y - 2) . . . , ( X - y + 1 , 1) , ( x - y 1) ( x - y, 0) > ) |
x ∈ Z and y ∈ N }.
0
Note: For pairs ( x, 0) 1 length, for ( x, 1) pair is 3 long, the
( x, 2) pairs a 5-series sequence.
We know that DO = ( π, S ) for some π . Is it true that there is a P
0
statement and t : A → Z is the condition of the rule for the derivation of the cycle
are fulfilled, and if so, enter a corresponding π , P and t .

7.6. A = Z × Z × Z × Z × Z
k x i the b
B=Z×Z
' '
a b
S = ( k : = 5; IF ( a> b : x : = a - b, a ≤ b : x : = b - a ); i : = i + 1)
' '
Q : ( in = the
'
∧ b =' b ∧ i ∈ [0 .. 1] ∧ | a - b |> 10)
R:(a=a ∧b=b ∧k·i≤x)
Prove that Q ⇒ lf ( S, R ).

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 78/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 8

Basic programs

In Chapter 2, we have always written about the programming task


we assume there is a set of programs that can be compiled from
our programs (2.7). These programs are commonly called primitive programs .
In this chapter we introduce some theoretical aspects of "simple" prog-
ram. These programs will often be used in the following chapters,
therefore we examine their program function and the most relevant
their weaker prerequisites.

8.1. Basic programs


8.1. DEFINITION : THIS LEMI PROGRAM
Of elements called one of a state space S program if
∀a ∈ A : S ( in ) ⊆ { < on > , < a, a, a,. . . > , < , B > | b = a}.
According to the definition, for each program there is an equivalent element program,
only the intermediate elements of the series should be omitted, and thus essentially, at a given level
all programs are elemental.
We select some of the elementary programs with some special features
and we will deal with them later.
The first such program will be what does not do anything.
8.2. DEFINITION : SKIP
SKIP is the program for which
∀a ∈ A : SKIP ( the ) = { < to > }.
The second program is the deletion, the most important feature of which is never
terminal.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 79/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

96 8. ELEMENTAL PROGRAMS

8.3. DEFINITION : ABORTION


ABORT indicates the program for which

∀a ∈ A : ABORT ( a ) = { < a, a, a ,. . . > }.


The two elementary programs listed so far are indeed very simple, but - perhaps surprising
they still have a significant role to play. The third special elementary program is
assignment. It's more complicated than before, but more important.
For the definition of the assignment we introduce a mark. Let A = A × · · · × A
and ∀i ∈ [1 ..n ]: F ⊆ A × A . We denote F = ( F , ..., F ) the following F ⊆ A × A
1 n

i i 1 n
relation:
⋂ ×
D = D i and ∀a ∈ D : F ( a ) = F (a).
F i=1 F F i ∈ [1 ..n ] i

8.4. DEFINITION : WRITING


Let A = A × · · · × A and F = ( F , ..., F ). The S program is general
assignment when ∀a ∈ A :
1 n 1 n

{
{red ( < a, b > ) | b ∈ F ( a ) } if a ∈ D ;
S(a)=
If a ∈ D .
F
{ < A, a, a,. . . > },
F

The above F component references accurately describe the given assignment


i
how to change some of the components of the state space.
Within the general value we distinguish special cases:
• If D = A , then the S program value selection is called does.
F

• If the F relation is a function, the S program assignments are called does.

• If D
F
⊂ A , then S is partial value selection .
• If D ⊂ A and F are deterministic ( F partial function) then S is partial
F
assignment .

Assignment and partial assignment with : = F ( a ), value selection and a


partial value selection is indicated by : ∈ F ( a ).
If except one, all F projections - that is, assignment to the state space only
i
it changes a component (just a variable value), then S is simple
assignment, otherwise called a simultaneous assignment.
Assignment is a bit more complicated than the previous two companions, but a little "value-
even though it is possible to solve all tasks by assigning it to them,
whether the assignment defined by the given task is a permissible operation. with this
the question will be discussed later in the course of solving the programming problem
addressed.
Examine the program functions of the special elementary programs defined above.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 80/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
8.2. BOTH PROGRAMS ARE THE LIGHTEST ŐFELTÉTELE 97

8.1. statement:

1. p ( SKIP ) = id ,
A
2. p ( ABORT ) = ∅ ,
3. p ( a : = F ( a )) = F ,
4. p ( in : ∈ F ( to )) = F .

Evidence is trivial (the task is included).

8.2. The weakest prerequisite for basic programs


Now that we have examined the program functions, let's look at the elementary programs
for the given prerequisite.
Because the program function of the SKIP program is the identical mapping, it is arbitrary
The weakest prerequisite for R post-condition:

lf ( SKIP, R ) = R.

Similarly, it can be seen that, since the ABORT program is program dependent,
premise is empty - based on the weakest prerequisite definition, an arbitrary R subtype
in case of
lf ( ABORT, R ) = False.
The weakest prerequisite of general value assurance is separately studied in determinist-
both non-deterministic and global and partial. Using the 3.
and claims 8:
⌈Lf ( a : ∈ F ( a ) , R ) ⌉ = ⌈R ◦ F ⌉.
If F : A → Function, then it is R ◦ F and therefore

lf ( a : = F ( a ) , R ) = R ◦ F.

If F is a partial function, so the assignment is partial, then the weakest one


prerequisite:
{
◦ F ( b ) , where b ∈ D ;
∀b ∈ A : lf ( a : = F ( a ) , R ) ( b ) = Rfalse, If b ∈ D .
F

We are now investigating the two cases where F is non-deterministic. Assuming D =


F
A , the weakest prerequisite for value selection
{
if F ( b ) ⊆ ⌈R⌉ ;
∀b ∈ A : lf ( a : ∈ F ( a ) , R ) ( b ) = true,
false anyway.

98 8. ELEMENTAL PROGRAMS

The same applies in partial cases:


{
if ∈ D and F ( b ) ⊆ ⌈R⌉ ;
∀b ∈ A : lf ( a : ∈ F ( a ) , R ) ( b ) = true,
false
F
anyway.

The assignment is usually described by variables. They should be in the status space variables
x , x , ..., x . Then use the following formula to mark a : = F ( a )
1 2 n
can:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 81/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
x , x , ..., x : = F ( x , x , ..., x ) , F ( x , x , ..., x ) , .. ., F ( x , x , ..., x ) .
1 2 n 1 1 2 n 2 1 2 n n 1 2 n
In practice, most of the components of F are in projection, that is
F ( x , x , ..., x ) = x . Then the assignment of marking the left x -t, improved
i 1 2 n i i
and F ( x , x , ..., x ) are omitted. Notice that it is simple assignment
i 1 2 n
only one variable on the left and only one expression on the right.
We can further simplify our marking if value is better
page ( F ) does not depend on all variables. Only the variables are on the right
i
, from which F depends.
i
Let's look at a simple example of the above. Be the state of space
A=Z×L
xl
As in the above, it is part of the components of the state space
variables will be included under the components. Let the components of the assignment be: ∀a =
(a ,a )∈A:
1 2

F ( a , a )= The , i.e. F = PR , and


1 1 2 1 1 Z
F ( a , a )= ( a > 0) .
2 1 2 1

Then for the : = F ( in ) written assignment variables:

x, l : = x, ( x> 0) .

Performing the simplifications described above as described above

l : = ( x> 0)

simple gain.
If we use that the weakest prerequisite for assignment is R◦F , then a
we can easily calculate the preconditions for the assignment of variables with variables
in accordance with the composition of the composition: substitute the post-
variables in their new value. We are introducing a new mark to this
x , x , ..., x are the state space variables at that time
1 2 n

lf ( x 1 , ..., x x ..., x ) , ..., F x ..., x ) , R ) =


R x:i 1=←FF and 1( 1,
i i m n i m( 1 , n
i 1 ( x 1 , ..., x n ) , ..., x im ← D in the ( x 1 , ..., x n )

8.3. VALUATION AS TASK SPECIFICATION 99

For partial assignment:

lf ( x 1 , ..., x x ..., x ) , ..., F x ..., x ) , R ) =


( X ,..., X )m∈
i i : =DF and
∧ R1 (x i 11←, F i 1n( x 1 , ..., x n )i , ...,m (x im1←, D in then( x 1 , .. ., x n )
1 n F

Value selection is a bit more complicated:

lf ( x 1 , ..., x ∈F x ..., x ) , ..., F x ..., x ) , R ) =


∀ ( e1i ,i ..., andi mi : and 1 ( 1 , x n..., x n ): Ri xm i(1 ←1e, i 1 ..., x imn ← e im
m) ∈ x j = 1 F i j( 1,

Finally, the partial value selection:

lf ( x 1 , ..., x ∈F x ..., x ) , ..., F x ..., x ) , R ) =


( x , ..., x ) ∈m :D and
∧ ∀1 (( e11i,, ..., and
i i n i m( 1 , n
x ..., x ):
1 n F m) ∈ x j = 1 F i j(
i 1, n
R x i 1 ← e i 1 ..., x im ← e im

Here, unless we say otherwise, we consider them as a primitive program


the - perhaps partial - valuations on the right side of the arithmetic,
Boolean functions are written.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 82/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

8.3. Assignment as a task specification


The assignment is essentially a program defined by a program function. Obviously,
so that this program function can be considered a task. Defined by a value assignment
task can easily be rewritten to the form corresponding to the specification item.
Let x ,. . . , x : = F ( x ,, x... ) . . . , F ( x , ..., x ) ⊆ A × A is one
1 n i 1 N n 1 n
assignment. In the állapotér analogy variables x ,. . . , x .
1 n
Consider the following job specifications:

A = A × ... × A
1 n
x x
1 n
B = B × ... × B
1 ' n 'n
x1 x
Q:(x =x
'
1 ∧··· ∧x = x )
'n

1 ' n'n ' 'n


R : ( x = F ( x1 , ... x ) ∧ ··· ∧ x = F ( x 1 , ... x ))
1 1 n n
Obviously, we have just specified the function F.
If it is not a valuation, but of a value selection, then in the post-conditions
not = but ∈ .
The partial cases, the preconditions should be narrowed down to the F Tar- interpretation
is denoted by x ∈ D i Conditions to account.
i F

100 8. ELEMENTAL PROGRAMS

8.4. Tasks
8.1. A = { 1 , 2 , 3 }, B = {a, b}, C = A × B . Let S be A -n, S = { 1 →
< 1 > , 2 → < 2222 . . . > , 3 → < 31 > } .
Let S the extension C of the S , and M on the program C that M ekvi-
1 be
valen S with A -n.
(a) Is the primary program S ?
(b) Is the elementary program S , and is the elementary program M ?
1

8.2. Consider the status space below:

A=N×N
xy
What Is ( x, y ) = F ( x, y ) , M = ( M , M ) , M ( x, y ) = y, F ( x, y ) = x , i.e.
the F ( p, q ) = {b ∈ A | x ( b ) = q and y ( b ) = p} assignment R = ( x <y )
1 2 1 2

is the weakest prerequisite for the post-condition?

8.3. Let A be a state of affairs. What are the tasks at A for which
solution of the SKIP program?

8.4. Let A be a state of affairs. What are the tasks at A for which
solution of the ABORT program?

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 83/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 9

Program Constructions and


predictability

In this chapter, we make a small breakthrough towards the predictability theory and
Let's say that with the three program designs that we have just introduced,
theoretically feasible - a task can be solved. To do this we will establish a relationship
between predictable functions and "well-constructed" programs, and thus
even if a task can be solved, it can also be solved by deduction.
The concept of predictability is usually partial recursive functions
customary. Other definitions options, such as
Turing machine, it can be proven that they are equivalent to predictability
partially recursive functions.
Please note that this section is always partial under the function
function. The totals are used for the functions defined everywhere.

9.1. Partial recursive functions


In the model of predictability based on partially recursive functions, only f ∈
m n
N → N functions. First, the basic functions are defined:
• suc : N → N , ∀x ∈ N:
suc ( x ) = x + 1 ,

• ∀n ∈ N : c ( n ) 1 n n
0 :N →N, ∀ ( x 1 , ..., x n ) ∈ N :

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 84/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
c1( n ) ( x 1 ,..., x n ) = 1 ,

102 9. PROGRAM STRUCTURES AND FREQUENCY

• ∀n ∈ N: ∀i ∈ [1 ..n ]: pr ( n ) n n
i : N → N , ∀ ( x , ..., x ) ∈ N :
1 n
pr i( n ) ( x 1 ,.., x. n ) = x i .

Hereinafter we define some elementary function-operators:


m n n k
Composition. Let f ∈ N → N and g ∈ N → N . The composition of f and g is
the following function:
m k
g◦f∈N →N ,D = {x ∈ D | f ( x ) ∈ D } and ∀x ∈ D :
g◦f f g g◦f
( G ◦ f ) ( x ) = g ( f ( x )) .
Note that this operator is the same as the basic concepts
relationship composition (actually with the strict composition, but
these two are the same).
m
Direct product. Let k ∈ N bem fixed, and ∀i ∈ [1 ..k ]: f ∈ N → N n i . In addition,
1 , f 2 , ..., f k ) =
( f , f , ..., f ) ∈ N → N n 1 × · · · × N n k , D ( f
i

⋂1 2 k
D i and ∀x∈D ( f 1 , f 2 , ..., f k ) :
i=1 f

( f , f , ..., f ) ( x ) = ( f ( x ) , ..., f ( x )) .
1 2 k 1 k
n
Recursion. Let n be fixed, f ∈ N → N and g ∈ N n + 2 → N. The function f g
recursion of ρ ( f, g ) ∈ F n + 1 → N, and
ρ ( f, g ) ( x ,..., x , 1) = f ( x , ..., x ) ,
1 n 1 n
ρ ( f, g ) ( x ,..., x , k + 1) = G ( x , ..., x , k, ρ ( f, g ) ( x , ..., x , k )) .
1 n 1 n 1 n

ρ ( f, g ) is a set of points starting from the above


recursion can be performed.
μ -operator. Let f ∈ N n +1 → N. Use the μ operator for this function
n
then μ ( f ) ∈ F → obtain N functions which D μ ( f ) = { ( x ,..., x ) ∈
N | ∃y ∈ N, f ( x , ..., x , y ) = 1 ∧∀i ∈ [1 ..y - 1]: ( x , ..., x , i ) ∈ D } ,
1 n

and ∀ ( x , ..., x 1) ∈ D μ n( f ) : 1 n f
1 n
μ ( f ) ( x ..., x ) = min {y | f ( x ,..., x , y ) = 1 }.
1 n 1 n

With the above basic functions and the introduced operators, you can already define the
a set of partial recursive functions.
9.1. DEFINITION : P ARCIAL RECURRY DISORDER
m n
The function f : N → N ( n, m ∈ N) is then partial recursive ,
if one of the following is true:
• f is one of the basic functions;
• f can be expressed by the above operators for partial recursive functions
with its finite multiplicity of applications.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 85/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

9.2. CALCULATION OF PARCIAL RECURRING PROVISIONS 103

9.2. Calculation of partial recursive functions


In order to be able to give programs to calculate the above functions, define it
m n
the task defined by such functions. Let f N →N a
any function ( m, n fixed). The main task set by the specification:
A = N × ... × N × N × ... × N
x x y y
1 m 1 m
B = N × ... × N
' 'm
x1 x
Q : ( x = x 1 ∧ ··· ∧ x = x ∧ ( x , ..., x ) ∈ D )
' 'm

1 m ' 1 'm m f
1,
R ( Q ∧ ( y , ..., y ) = f ( x ..., x ))
1 n
We assume that the basics calculating programs are included in the
allowed programs. We can do this safely, for everything
programming language contains such instructions.
We show that the elementary function operators (composition, direct,
recursion, μ -operator) can be calculated using well-constructed programs.

m n n k
Composition. Let f
∈ N → N and g ∈ N → N . Then the g ◦ f by
Specified task specification:
A = N × ... × N × N × ... × N
x x y y
1 m 1 k
B = N × ... × N
' 'm
x1 x
Q : ( x = x 1 ∧ ··· ∧ x = x ∧ ( x , ..., x ) ∈ D )
' 'm

1 m '1 'mm g◦f


R ( Q ∧ ( y , ..., y ) = ( g ◦ f ), ( x 1 , ..., x ))
1 n
Denote z ,. . . , z : = f ( x , ..., x ) the program that calculates f -
1 n 1 m
et, and similarly y ,. . . , y : = g ( z , ..., z ) is the one that calculates g . Let's
1 k 1 n
make these two programs a well-constructed program. In this case, the two programs
'
its sequence calculates g ◦ f , ie it solves the above-specified task. Let Q
the weakest prerequisite for the second condition for R is:
' ' 'm
Q ( Q ∧ g ( z , ..., z ) = ( g ◦ f ), ( x1 , ..., x ) ∧ ( z , ..., z ) ∈ D )
1 n 1 n ' g
Now let's examine the first program to be the weakest one for this Q suffix
precondition:
'
lf ( z , ..., z : =' f ( x'm , ..., x ) , Q ) = ( Q ∧ g ( f ( x , ..., x ))) =
(( G ◦ f ), (1x, ..., x ) ∧ f ( x , ..., x ) ∈ D ∧ ( x , ..., x ) ∈ D )
1 n 1 m 1 m

1 m g 1 m f
It is easy to see that this is the weakest prerequisite from Q , and so on
the sequence deduction rule and the specification specification,
that the

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 86/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

104 9. PROGRAM STRUCTURES AND FREQUENCY

z , ..., z : = f ( x , ..., x )
1 n 1 m
y , ..., y : = g ( z , ..., z )
1 k 1 n

program solves the above-specified task, ie computes its composition f and g .

m
Direct product. Let k ∈ N be fixed, and ∀i ∈ [1 ..k ]: f ∈ N → N n i . That's it
Specification of the task specified by the direct methodi of these functions:
A = N × ... × N × N × ... × N × ... × N × ... × N
x x y y 1 n1 y k1 y k
1 m 11 kn
B = N × ... × N
' 'm
x1 x
Q : ( x = x 1 ∧ ··· ∧ x = x ∧ ( x , ..., x ) ∈ D ( f 1 , ..., f k ) )
' 'm

R : ( Q 1∧ (( y , ..., y 1mn 1 ) ,. . . , ( y 1k 1 , ..., ym k )) = ( F ,... F ) ( x1' , ..., x 'm ))


11 kn
1 k
Let's say that component functions can be calculated using well constructed prog-
RAM. Mark y i 1 . . . , y i
: f ( x , ..., x ) the i -th function (1 ≤ i ≤ k )
in i 1 m
calculating program. Then the sequence of these programs resolves the
the above task. Let Q the weakest one for the second condition of k- th program R
k be
prerequisite:
Q ( Q ∧ (( y , ... y 1 n 1 ) ,. . . , ( y k- 11 , ..., y k- 1 n k- 1 ) , F ( x ,..., X )) =
s 11 k 1 m
' 'm
( f , ..., f ) ( x1 , ..., x ) ∧ ( x , ..., x ) ∈ D k )
Furthermore, every i ∈ [1 ..k - 1] If select Q of the i th program Q i +1 Rates are relative
1 k 1 m f
i
which is the weakest precondition for this. It is easy to see that the assignment is weakest
applying the prerequisite rule:
' 'm
Q ( Q ∧ ( f ( x , ..., x ) , ..., f ( x , ..., x )) = ( f , ... f ) ( x 1 , ..., x ) ∧
1 1
( x , ..., x 1 ) ∈ D m1 ∧ ··· ∧ k( x 1, ..., x m) ∈ D 1k ) k
1 m f 1 m f
If you're Q -t and Q compared eth, we notice that the same. The sequence-
1
cia's derivation rule and the specification of the

y , ..., y 1 n 1 : = f ( x , ..., x )
11 1 1 m

y k 1 , ..., y k
: = f ( x , ..., x )
kn k 1 m

( f , ..., f ) is the solution to the above-specified task .


1 k

n
Recursion. Let n be fixed, f ∈ N → N and g ∈ N n + 2 → N. Let us suppose,
that they can both be calculated with well-constructed programs. The main function g of
Specification of the task specified by the recursion:
A = N × ... × N ×N
x x n +1 y
1

9.2. CALCULATION OF PARCIAL RECURRING PROVISIONS 105

B = N × ... × N
'
x1 x 'n +1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 87/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Q : ( x = x 1 ∧ ∧ ··· x n '+1 = x 'n + 1 ∧ ( x 1 , ..., x n +1 ) ∈ D ρ ( f, g ) )


'

R ( Q ∧1 y = ρ ( f, g ) ( x 1 , ..., x 'n +1 ))
Check f and g to calculate the program y : f ( x , ..., x ) or y :=
1 n
g ( x , ..., x n + 2 ). Solve the task with a cycle that has an invariant
1
lajdonsága:
' 'n
P ( Q ∧ k ∈ [1 ..x n +1 ] ∧ y = ρ ( f, g ) ( x 1 , ..., x , k ))
Examining the derivation rules of the cycle it is found that Q of not apparent from P .
'
Therefore, we provide a Q condition '
that follows P and we give a prog-
ram, which comes from Q to Q '
(so the solver program will be a sequence of which
second' part is a cycle). Let Q is as follows:
Q ( Q ∧ k = 1 ∧ y = f ( x , ..., x ))
1 n
This k, y : = 1 , f ( x , ..., x ) is available simultaneously. The best way to
1 n
using a rule for weaker prerequisites, it is easy to see that
followed by a Q of.
Based on the second point of the cycle deduction rule, the cycle condition is k = x n +1
will.
In accordance with the third point, select t = x n +1 - k terminating-
function.
The fifth point describes the value of the termination function defined as a
cycle core. This is achieved by increasing the number one.
To satisfy the four points, look at what the weakest prerequisite is
k -t increasing assignment of P on to.
'
Q = lf ( k : = k + 1 , P ) = ( Q ∧ k + 1 ∈ [ 1..x n +1 ] ∧
' 'n
y = ρ ( f, g ) ( x1 , ..., x , k + 1))
Now, according to the rule of deduction of the sequence, only one program is needed
''
where P ∧ ( k = x n +1 ) ⇒ lf ( S, Q ). This program is used to define the recursion
vaccination of fittingly right y : = g ( x ,, x... , k, y will be).
1 n
Thus, the sequence and cycle derivation rule and the specification of the specification
guarantees that a

k, y : = 1 , f ( x , ..., x )
1 n
k = x n +1
y : = g ( x ,, x... , k, y )
1 n
k:=k+1
program resolves the ρ ( f, g task specified by), i.e., it calculates fg of
recourse.

106 9. PROGRAM STRUCTURES AND FREQUENCY

μ -operator. Let f ∈ N n +1 → N, and assume that f can be calculated easily


or a well-constructed program. Let us consider μ ( f )
task:

A = N × ... × N × N
x x y
1 n
B = N × ... × N
' 'n
x1 x
Q:(x =x
'
1 ∧ ∧ ··· x = x 'n ∧ ( x , ..., x n +1 ) ∈ D μ ( f ) )
1 ' n 'n 1
R ( Q ∧ y = μ ( f ) ( x 1 , ..., x ))
Mark z : = f ( x , ..., x , x n +1 ) for the f- computing program. Solve the up-
1 n

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 88/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
data with a cycle whose invariant is:
P ( Q ∧ z = f ( x , ..., x , y ) ∧ ∀i ∈ [1 ..y - 1]: f ( x , ..., x , i ) = 1 )
1 n 1 n

The invariant is z, y : = f ( x , ..., x , 1) , 1 can be performed simultaneously.


1 n
It is easy to see that this program is the weakest for P
a prerequisite

lf ( z, y : = f ( x , ..., x , 1) , 1; P ) = ( Q ∧ f ( x ,..., X , 1) = f ( x ..., X, , 1)


1 n 1 n 1 n
∧ ∀i ∈ [1 .. 1 - 1]: f ( x 1 ...,, X, n , i ) = 1)
followed by a Q of. According to the second point of the cycle deduction rule,
condition z = 1.
The prerequisite for this task guarantees that there is a m ∈ N number to which
f ( x ,..., x , m ) = 1 exists. Let N be a fixed property of such a property,
1 n
natural number. This value can be used to define the termination function:
t = N - y . This satisfies the third point of the deduction rule.
The fifth point requires the termination function during the cycle core run
reduced. This can be achieved by increasing y by one.
'
To complete the fourth point, let Q be the P for this increment
weakest prerequisite:
'
Q ( Q ∧ z = f ( x , ..., x , y + 1) ∧ ∀i ∈ [1 ..y - 1]: f ( x , ..., x , i ) = 1)
1 n 1 n
'
Now we only need to find a program between P ∧ ( z = 1) and Q . THE
z : = f ( x ..., x , y + 1) holds the value added to
1 n

'
P ∧ ( z = 1) ⇒ lf ( z : = f ( x , ..., x , y + 1) , Q ) .
1 n

The specification of the specification and the rule of deduction of the cycle and the sequence guarantee,
that the

9.3. relations 107

z, y : = f ( x , ..., x , 1) , 1
1 n
z=1
z : = f ( x ,, x... , y + 1)
1 n
y:=y+1
program solves the function defined by μ ( f ), ie calculates μ ( f ).

Consequence. We have shown that if the basic functions calculate


the partial recursive functions are allowed,
Functions built with throat can also be calculated using well-constructed programs. for this
we can say the following item:

9.1. ITEM : S TRUKTURÁLT and predictability PROGRAMMING


All predictable functions can be calculated using a well-constructed program.

9.3. relations
Let us turn our attention now to relations. To make the relationships predictable
we must examine the concept of predictable relationship.

9.2. DEFINITION : R EXACTLY LISTED RELAY


k k
Let R ⊆ N × N be any relation. R then and only recursively
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 89/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
can be enumerated if there is a partial recursive function f ∈ N 2 k → N
interpretation range: D = R .
f

According to the predictability theory, it will only recursively recite


we will deal with relationships. To show it, everything is predictable
(recursively enumerable) task - remember that each task is a relationship -
can be solved by a structured program, first the recursively listed rela-
another characterization.

9.2. COMPOSITION : R Lee [1936]


If R is an arbitrary relation, then the following three statements are equivalent:

(1) R is recursively listed.


(2) R a f partial recursive functions set value.
(3) R = ∅ or R is a set of values for a recursive function φ .

The proof of this item is constructive, ie it gives both f and φ


structure. We will use this function φ for our computable task.
dóprogramjában.

108 9. PROGRAM STRUCTURES AND FREQUENCY

k k be
Let F ⊆ N × N a recursively-quoted relation, and denote φ the previous one
(total) recursive function obtained by constructing a batch. Specify the task for
as follows:
k k
A=N ×N
x y
k
B=N '
x
'
Q:(x=x ∧x∈D )
R : ( Q ∧ ( x, y ) ∈ FF)
This task can be solved by a cycle whose invariant property is:
P : ( Q ∧ i ∈ N ∧ ( z, y ) = φ ( i ))
By using the cycle deduction rule it is easy to see the following
program solution for the above task:

i, ( z, y ): = 1 , φ (1)
z=x
( z, y ): = φ ( i + 1)
i:=i+1
In the proof, the same technique is applied to the termination function
z as the μ -operator.
Here, we can generalize our previous function references to relationships:

9.3. ITEM : S TRUKTURÁLT PROGRAMMING AND PREDICTABLE comparison


All predictable relationships can be calculated using a well-constructed program.

Note that these results can be extended to relatively predictable


functions (with the same operators from a basic set of arbitrary bases)
or the set of partial recursive functionalities [Odi 98].

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 90/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 10

The type

The sets in the status space definition are called type value sets, and
all we said was that they could be counted at most.
The following will be how these sets come up, how
a common property is characteristic of their elements.

10.1. The type specification


First, we introduce a concept that can be used to
we describe our requirements with a type set of values and can do it
operations.

10.1. DEFINITION : TITLE DESIGNATION


The T = ( H, I , F) triad típusspecifikációnak called if it met the
s s
the following conditions:

1. H is the base set,


2. I : H → L is the specification invariant,
s
3. T = { ( T, x ) | x ∈ ⌈I ⌉} is the type set ,
T s
4 F = {F , F ,. . . , F } is the specification of the type operations where
1 2 n
∀i ∈ [1 ..n ]: F i ⊆ A and × A i , A i = A1 i× ··· × A i so,
ni

that ∃j ∈ [1 ..n ]: A j = T .
i i T

By means of the basic set and the invariant property,


what is the set T whose elements we want to deal with while the task
T
a set of tokens describes how these actions can be performed with these elements
a.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 91/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

110 10. TYPE

The type set of values in the status space definition


are defined in cation. A component of a state space is a program only for type-
operations.

10.2. The type


Examine how the requirements described in the type specification are met
a.
10.2. DEFINITION : TITLE
The T = ( ρ, I, S) triplet type is called if the following conditions are met
it:
*
1. ρ ⊆ E × T is the representation function (relation),
T is the type set,
This is the elemental set of values,
*
2. I : E → L type invariant,
S 3 = {S , S ,. . . , S } , where
1 2 m
**
∀i ∈ [1 ..m ]: S i ⊆ B and × Band* program, B i = B and ×··· × B i so, we

that ∃j ∈ [1 ..m ]: B
1

i i = E and ∃j ∈ [1 ..m ]: B = T .
j j
i i
The first two components of the type describe the representation of abstract type values,
while the program set contains the implementation of the type operations. The elementary
a set of pusps may be a type value set of any other type or a
how to define a maximum number of countable sets.
An element type is called T = ( ρ, I, S) if T = E and ρ | = Id .
⌈I⌉ E
We still have to give a type when it meets the type specification, ie
when it fulfills the requirements described in the specification.
Let hereinafter referred to as=T ( H, I , F), T = ( ρ, I, S), F ∈ F, and S ∈ S,
s s **
F ⊆ A × A , A = A × ··· × A , S ⊆ B × B , B = B × ··· × B .
Let the subspace
1 C. unto and
p B subspace D unto. 1 q

We say that the status spaces C = C × · · · C and D = D × · · · × D


1 R 1 r
fit , if { *
∀i ∈ [1 ..r ]: D i = E , if C = T ;
C anyway.
i T
and
In this case, let γ ⊆ D × C be the relation:
∀d ∈ D : γ ( d ) = γ 1 ( d 1 ) × γ 2 ( d 2 ) ×. . . × γ r ( d r ) ,
where ∀i ∈ [1 ..r ]: γ ⊆ D i × C i and
i
{
ρ | , if C = T ;
γ = ⌈I⌉ i T
i id i otherwise.
D

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 92/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

10.2. TYPE 111

Note that γ is a kind of extension of ρ in several components,


but for mutually matching states of space.

T H T F T H T

ρ | ⌈I⌉ (-1) id ρ | ⌈I⌉ (-1) ρ | ⌈I⌉ id ρ | ⌈I⌉


H H

p (S)

E* H E
*
E
*
H E
*

10.1. figure. The solution ρ -n is in matching state spaces

10.3. DEFINITION : M APPLICATION ρ - N


**
We say that S ⊆ B × B program ρ through -n solve the
F ⊆ A × The task if there are C and D fitting spaces for which
' '
subspace A and B that S γ the' Solution F unto where' γ ⊆ D × C, the
As defined above mapping, S of S extension D to, F is the F
extension C to.

According to the extension items, if there are matching spaces corresponding to the definition,
all of them are.
10.4. DEFINITION : M ANALYSIS
A type T = ( ρ, I, S) corresponds to the type specification T = ( H, I , F) if
s s

1. ρ ( ⌈I⌉ ) = T ,
T
∀F ∈ F: ∃S ∈ S: S solves F by ρ .
Second
Of course, a type specification can be more than one type.
Then, which one we choose, the representation and the implementation of the operations,
such as the memory requirement of the representation or the
Implementation Operations Required - Depends. This is always the decision to solve the program
function.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 93/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

112 10. TYPE

10.3. Batch type specification


By introducing the concept of type specification and the concept of type,
generalization, while matching the concept of solution was a kind of
talánosítása. Specifying the specification is a sufficient condition for solving the problem. Now ρ -n
a similar condition is given.

10.1. ITEM : T ÍPUSSPECIFIKÁCIÓ MAKING


Let T = ( H, I , F) and T = ( ρ, I, S) given type specification and type, and
Suppose that representation is correct, i.e. ρ ( ⌈I⌉ ) = T . Also be
s s

F ∈ F, state F of A , is a parameter space B , its pre and post condition is Q b


T

and R . Let S ∈ S, and suppose that S state space fits D status


b
tere. Define the following statements:

⌈Q bγ ⌉ ⌊ Q b ◦ γ⌋ ,
γ
=
⌈R b ⌉ = ⌈ R b ◦ γ⌉ ,
where γ is the solution between the program and the task state space, ρ -n
γ γ
definition in the definition. Then if ∀b ∈ B : Q b ⇒ lf ( S, R b ) , then
the S program, ρ solve for n F task.

Proof: Because of the relationship between the relationship, we just have to realize that
D ⊆ R satisfied. It is obvious, as assumed that the ρ ( ⌈I⌉ ) = T .
F γ is T

The fact that the terms of the above item stipulated the status of the program
fit into the status space of the task, it can be omitted. At this point the item is
dat and extensions of the program whose status spaces fit
(exactly as the correspondence was defined as a non-matching state-
space).

10.4. Abstract type


This section focuses on generalizing the concept of compliance. First
defining the concept of equivalent task. This is quite obvious in Chapter 5.
The markings introduced in 5.2 are used.
10.5. DEFINITION : EQUIVALENCY OF EARNINGS
The F ⊆ A × A and M ⊆ B × B functions equivalent is called, and
1 2
~ B and γ ( F ) = F .
f 2 1

Now we define the equivalence of two types specification. Two t-


pouchpecification is equivalent, if only in their name,
they are:

10.5. EXAMPLES 113

10.6. DEFINITION : ECVIVALENCY OF TEXT PROSPECTS


The T s 1 = ( H , I s 1 , F ) and T s 2 = ( H I s 2 , F ) type specification equivalents ,
if ⌈I 1 ⌉ = ⌈I s 2 ⌉ , and there exists ξ : F 2 M
→ a bijection to ∀F ∈ F : ξ ( D ) ~
1 1 2 2

s 1 2
F T 2 ← T 1 , where
F T 2 ← T 1 = { ( x T 2 ← T 1 , y T 2 ← T 1 ) | ( x, y ) ∈ F} , where
x T 2 ← T 1 = { ( i, a T 2 ← T 1 ) | ( i, a ) ∈ x} , where

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 94/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
{
a T 2← T 1= ( T , e ) , if a = ( T , e );
1 2
the otherwise.

Then, the concept of compliance is generalized.


10.7. DEFINITION : GENERALIZATION
We say that T = ( ρ, I, S) type - in general terms - corresponds to a
T = ( H, I , F) type specifi- cation if there is an equivalent type
s s
fiction, which corresponds in the original sense.
Types of Types are defined as sets of pairs. The above definition
, however, from the point of view of compliance, the first component - the name
- is of no relevance, so we will not deal with it anymore.
As a generalization of the program function, you can define the abstract type:
10.8. DEFINITION : THE BRAZIL TYPE
Let T = ( ρ, I, S) be a type. The p ( T ) = ( p ( ρ ) , p t - (S)) abstract type T
let's call it
*
First
∀ε ∈ E : p ( ρ ) ( ε ) = ρ | ( ε ) 2 ,
2. p (S) = {p ( S ) | S ∈ S }. ⌈I⌉
Like the program, the T = ( ρ , I , S ) and T = ( ρ , I , S ) type ekvi-
1 1 1 1 2 2 2 2
valence if p ( T ) = p ( T ). The name is justified because of compliance
1 2
the equivalent types are the same.

10.5. Examples
10.1. Example: The set of type values should be the vowels of the Hungarian alphabet: {a, á,
e, e, i, í, o, oh, ö, he, u, ú, ü, ű}. We want to know about a particular vowel
which is the (short or long) pair. Let's have one of our type operations to do this
you can answer the question. The set of elementary values should be set to {0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14}. Enter the type specification and make one
a type that matches the specification!
Solution: Write the type specification first. Be a vowel of vowels
M GH . At
T = ( MGH, True, {F} ) where F ⊆ T × T ,
s T T

114 10. TYPE

F= (e, e), (i, í), (í, i), (o, o), (a, a), (e,
(u, u), (u, u), (u, u), (u, u), (u, u) }.

Note that T elements are for simplicity ( T, x ) instead


T
marked with x . We will continue to use this solution as well. Enter the type.
*
T = ( ρ, I, {S} ) where ρ ⊆ E × MGH ,
ρ= {( < 0 > , a), ( < 14 > , o), ( < 1 > , e), ( < 13 > , E), ( < 2 > , i);
( < 12 > , í), ( < 3 > , o), ( < 11 > , ó), ( < 4 > , ö), ( < 10 > , he)
( < 5 > , u), ( < 9 > , ú), ( < 6 > , ü),
}; ( < 8 > , û)
*
∀α ∈ E : {
true, ha | α | = 1 and α = 7;
I(α)= 1
false anyway.
* * **
S⊆E ×(E ) ,
S = { ( < I > , red ( << i > , < 14 - i >> )) | i ∈ E} ∪
∪ { ( Α, < α, α,... > ) | | α | = 1 }.
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 95/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

That the type you have just meets this type specification is easy
can be seen: the representation of the representation can be read from the definition of ρ and I , while that of
the Srepresentation
program, ρ solve for n D tasks, the program is simple hozzáren-
and the ρ "tricky" choice.
Of course, other representation functions can also be provided, but at this time
we need to change the type invariant and the program.
10.2. Example: Specifies the type with values of [0 .. 127] of subsets,
and its type operations include training and union of two sub-sets and an-
to determine if an element is a subset of a subset. Please enter a type,
which meets the specifications! (The set of elementary values is { 0 , 1 } , the programs
enough to enter their program function.)
Solution: T = ( H, I , F) where
s s

H = ℘ ([0 .. 127]) ,
I = True,
s
F = {F , F , F },
m u e

and A = T × T × T, F
m m
⊆Am×Am,
F = { (( a, b, c ) , ( p, q, r )) | p = a and q = b and r = a ∩ b} ;
m

A = T × T × T, F
u u
⊆Au×Au,
F = { (( a, b, c ) , ( p, q, r )) | p = a and q = b and r = a ∪ b} ;
u

10.5. EXAMPLES 115

A = T × [0 .. 127] × L , F
e and
⊆ A and × A e ,
' ' ' ' ' '
F = { (( h, e, l ) , ( h , e , l )) | h = h and e = e and l = ( e ∈ h ) }.
e
*
Give the type of the above specification. T
*
= ( ρ, I, S), and ρ ⊆ E × ℘ (N),
∀α ∈ E :
ρ ( α ) = {{i | α and +1 = 1 }} ;
* *
I : E → L , ∀α ∈ E :
{
true, ha | α | = 128;
I(α)=
false anyway .
* * *
S = {S , S , S }, and B = E × E × E , S
m u e m m
⊆ B m × B m program:
' ' ' ' '
p(S ) = { (( α, β, γ ) , ( α , β , γ )) | α ∈ ⌈I⌉ and β ∈ ⌈I⌉ and γ ∈ ⌈I⌉ and α = α and
m
' '
β = β and ∀i ∈ [1 .. 128]: γ α ;
i= i· β i}
* * *
B =E xE xE S
u u
⊆ B u × B u program:
' ' ' ' '
p(S ) = { (( α, β, γ ) , ( α , β , γ )) | α ∈ ⌈I⌉ and β ∈ ⌈I⌉ and γ ∈ ⌈I⌉ and α = α and
u
' '
α β ;
β = β and ∀i ∈ [1 .. 128]: γi = i+ i -α i · β i}
*
B = E × [0 .. 127] × L S
e E
⊆ B E × B E scheme:
' ' ' ' ' '
p ( S ) = { (( a, x, 1 ) , ( α , x , 1 )) | α ∈ ⌈I⌉ and α = α and x = x and l = ( α x +1 = 1) }.
e

Does the above described type correspond to the above type specification? The representation is correct,
since the exact 128 long sequences are represented by the representational function

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 96/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
sub-sets, ie
ρ ([ I ]) = [ I ] .
s

Examine the relationship between programs and tasks. Notice that a


the state spaces of the programs fit into the state of the corresponding task, so it can be written
the relation γ between them .

γ = ),
m (ρ ⌈I⌉ ; ρ ⌈I⌉⌈;I⌉ ρ
γ = ),
u (ρ ⌈I⌉ ; ρ ⌈I⌉⌈;I⌉ ρ
γ = (ρ ⌈I⌉ ; id [0 .. 127] ; id ) .
L
e

Using these, the solution through ρ is simply a representation


function and semantics of program functions.

116 10. TYPE

10.3. Let T = ( H, I , F) be a type specification, F = {F} . Let T =


s s 1
( Ρ , I , S ) and T = ( ρ , I , S ) types for which: S = {S }, S = {S }, ρ =
ρ , [ I ] = [ I ], and S ⊆ S .
1 1 1 2 2 2 2 1 1 2 2 1

2 1 2 2 1
Is it true that if T corresponds to T , then T too?
1 s 2
Solution: The correct representation is ρ = ρ and [ I ] = [ I ] is trivially fulfilled,
1 2 1 2
since at this time:
ρ ([ I ]) = ρ ([ I ]) = [ I ] .
2 2 1 1 s
It is therefore necessary to examine whether the S program resolves the F task
2
through ρ . Since the status of the programs is common, we can assume that the program-
2
mok state space and the state of the task are correlated to each other, as opposed
In case of both solutions, the task should be the same extension
and so replacing the original task with this extension is the following
can be traced back.
Since S ⊆ S , the program functions of the two programs are fulfilled as follows:
2 1

i. D p ( S 1 ) ⊆ D p ( S 2 ) ,
ii. ∀a ∈ D p ( S ) : 1 P ( S ) ( in ) ⊆ P ( S ) ( in ) .
2 1

Let us also indicate γ with the state of the program and the task in the correspondence
defined mapping. It is easy to see that i. property

D γnostp (1 S) ⊙γ ( - 1) ⊆D γ⊙p ( S 2 ) ⊙γ ( - 1) .

On the other hand, since S program solves F eth of ρ for n,


1

D
F
⊆ D γ⊙p ( S 1) ⊙γ ( - 1)

is also met. Based on the above two statements

D
F
⊆ D γ⊙p ( S 2) ⊙γ ( - 1) .

Use the second property as well! The ii. the following is true for the property
also claim:

∀a ∈ D γnostp ( S) ⊙γ 1 ( - 1) : γ ⊙ P ( S 2 ) ⊙ γ ( - 1) ( the ) ⊆ γ ⊙ P ( S 1 ) ⊙ γ ( - 1) ( in ) .

At the same time, since the solution of program S through ρ is the task,
1
is that it
∀a ∈ D : γ ⊙ P ( S ) ⊙ γ ( - 1) ( the ) ⊆ M ( to ) ,
F 1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 97/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
and because of this ∀a ∈ D F : γ ⊙ P ( S 2 ) ⊙ γ ( - 1) ( the ) ⊆ M ( to ) ,
that is, the program S also solves the task F through ρ , that is the type T 2 too
2
meets the specification.

10.6. TASKS 117

10.6. Tasks
10.1. Enter a type specification, representation function, type (corresponding to
specification). Possible values are: [0 .. 99999]. The operations are the following and
with the rest of the previous 100,000. Elementary values are decimal digits:
{ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } . Show that the type corresponds to the type specification
Zion!

10.2. E = { 0 , 1 , 2 }, T = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, F = {F}.

F = { (( a, b, c ) , ( d, e, f )) | ∃k ∈ Z: f + k · 10 = a + b}

Create a type that matches the specification.

10.3. Let T s 1 = ( H , I s 1 , F ) , T s 2 = ( H , I s 2 , F ) are two types of specifications.


1 1 2 2

Claim 1. All T type: T satisfies T s 1 unto ⇔ T satisfies T s 2 unto.


Claim 2: [ I s 1 ] = [ I s 2 ] and F = F .
1 2

Are the two statements equiva- lent?

10.4. The type specification T = ( H, I , F) is given, and T = ( ρ , I , S )


s s 1 1 1 1
T = ( ρ , I , S ) types. Suppose that [ I ] = [ I ] , S = S and ρ ([ I ]) =
2 2 2 2 * 1 2 1 2 1 1
ρ ([ I ]) and ∀α ∈ E : ρ ( α ) ⊆ ρ ( α ) and T correspond to T .
2 2 2 1 1 s
Is it true that T also corresponds to T ?
2 s

10.5. Let T = ( H, I , F) is a type specification, T =(Ρ ,I ,S ),T =


( ρ , I , S ). Let [ I ] ⊆ [ I ] , S = S and ρ ([ I ]) = ρ ([ I ]), and ∀α ∈
s s 1 1 1 1 2

*2 2 2 2 1 1 2 1 1 2 2
E : ρ ( α ) = ρ ( α ) and T correspond to T .
2 1 1 s
Is it true that T also corresponds to T ?
2 s

10.6. Let T = ( T, I , F) be the following type specification:


S S
I = True, T = N , F = {F , F } .
S 2 0 1 2
F Specification:
1

A=T
x
B=T
'
x
'
Q:(x=x )
'
2= 8 · z + x and 0 ≤ x < 8)
R : ( ∃z ∈ Z: x 2 2

Specification of F :
2

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 98/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

118 10. TYPE

A=T×T×L
x y l
B=T ×T
' '
x y
' '
Q:(x=x ∧y=y )
' ' ' '
R(l=(x =y )∧x=x ∧y=y )
T = ( ρ, I, § ) , E = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 }
*
Σ | e | -i
∀e ∈ E : ρ ( e ) = { ( T, i = 1( E · 8 ) } i

the) {
true, ha | e | ≥ 1 and ( e = 0 ⇒ | e | = 1);
I(e)= 1
false anyway.
b) {
true, ha | e | ≥ 1;
I(e)=
false anyway.
* * **
S
1
⊆(E )×(E )
* * *
∀e ∈ E : S 1 ( e ) = {α ∈ ( E ) | | α | = | e | and
∀i ∈ [1 .. | α | ]:| α i | = | α | - i + 1 and
∀i ∈ [2 .. | α | ]:∀j ∈ [1 .. | α i | ]: α i= α i- 1 j j +1
)}
* * * * **
S ⊆ ( E *× E × L) × ( E × E × L)
∀e,2 d ∈ E : ∀i ∈ L:
* * * * **
S ( e, d, l ) = {β ∈ ( E × E × L) × ( E × E × L) |
2 | β | = min ( | e |, | d | ) + 1 and
∀i ∈ [2 .. | β | ]: β i = ( ee, dd, ll ) and
ll = ( ∀j ∈ [ 1..i - 1]: ee = dd ) and
j j
| ee | = i - 1 and | dd | = i - 1 and
∀j ∈ [1 ..I - 1] ( ee = e | e | j +1 and d = d | d | j + 1 ) }
i-j i, j

Write the words F , F , the relationship ρ and the program functions S , S


PSA! Does the type1 correspond
2
to the specification in a) and ab)? 1 2.

10.7. Enter a type specification, representational function, abstract type (which


meets the specification)! Type values: set of plane vectors, a
operations: add two vectors, and decide whether they are two vectors
are several times different.
10.8. Enter a type specification, representational function, abstract type (which
meets the specification)! Type values: set of vector vectors, a
operations: subtraction of two vectors, and a vector with one number
Multiplying.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a792… 99/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

10.6. TASKS 119

10.9. Enter a type specification, representational function, abstract type (which


complies with the specification) for the type of complex numbers where the operations are
the addition of two complex numbers and the imaginary part of a complex number
Determination.
10:10. Enter a type specification, representational function, abstract type (which
complies with the specification) for the type of complex numbers where the operations are two
complex number summing and a complex number n- d ( n ∈ N) power
Determination.

10:11. Enter a type specification, representational function, abstract type (which


meets the specification). The type values are the set of circles, the operations are:
shifting a circular disk and deciding whether a point in a plane is on it
circular disk.
10:12. Enter a type specification, representational function, abstract type (which
meets the specification). Type values: the set of spheres, the operations are:
to move a sphere and to decide if a spatial point is in it
sphere.
10:13. Enter a type specification, representational function, abstract type (which
meets the specification). Type values: the set of squares, the operations are:
shifting a square, changing a square size, is a square
calculating the area and determining whether or not a plane point is present
the square.
10:14. Enter a type specification, representational function, abstract type (which
meets the specification). The type values are the set of cubes, the operations are:
shifting a cube, changing a cube size, cube volume
and deciding whether a spatial point is within the cube-
of.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 100/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 11

Típuskonstrukciók

We are already exploring what opportunities we have from existing programs


to make new ones. We will look at how to use it
existing types to create new types. These methods are type-structured
the types they can obtain are called type designs.
The most obvious option is to create a new type that is a particular type
we change the set of its operations, add a new operation, leave it
from it, change the existing operation. This is a simple and very often sub-
procedure.
The other, a bit more complicated option is to change the invariant property
Tatas. Restricting the invariant is an easy-to-use and easy-to-use option.
The third option is to change the representation function. This is also important
possibility. Hereinafter we will deal with a more general case of this, existing
we create new ones from representational functions.

11.1. Permissible constructions


Of course, we have a wide variety of options from existing representation functions
but we will only deal with three special constructs: a
direct, union, and iterated. These will be permitted for type
called.
The first type design method we get acquainted with is direct. Juice-
mark T = ( ρ , I , S ) ( i = 1 , 2 ,..., n ) types and designated T , T ,. . . , T with a
i i i i 1 2 n
corresponding type value sets, E , E ,. . . , With E theirs
element type sets and introduce the E = E ∪ E ∪ · · · ∪ E and B =
1 2 n being

1 2 n
T × T × ··· × T .
1 2 n

122 11. TYPICAL CONSTRUCTIONS

11.1. DEFINITION : D REPRODUCTION


The T = ( ρ, I, S) type direct multiplication of T 1 , T 2 , ..., T types if
n

ρ = φ ◦ψ
D D
*
where φ
D
⊆B×T,ψD⊆E × B and
{ ( ε, b ) ∈ E × B | ∀i ∈ [1 ..n ]: ∃ε ∈ Ei : ( ε i , b i ) ∈ ρ i and
* *
ψ =
D
i
ε = cone ( ε , ..., ε ) }.
1 n

The value of the direct derivative is given by the T = ( T , T , ..., T ).


1 2 n

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 101/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
If φ mutually clear mapping, then the direct result is a record type-
D is a
. Directtypes are usually records, but not always. for example
consider a possible representation of the set of rational numbers:
B = Z × Z, φ ⊆ B × Q:
D

( x, y ) , t ) ∈ φ ⇐⇒ y = 0 and t = x / y
D

It is easy to see that the relation φ defined above is the set of rational numbers
D
represent, but not mutually unambiguous.

T
t

T T T T φ
1 2 3 n D
ρ
B t t t t
1 2 3 n

ψ
* ρ ρ ρ ρ D
1 2 3 n
E

11.1. figure. Direct construction design

It is also important that the new type value set ( T ) should not be mixed with
with intermediate direct ( B ), since there is a very large number of φ D between a given B and T
mapping can be given, and nothing new for the new type
of which we choose.
Consider, for example, the set of complex integers ( a + bi, a, b ∈ Z-shaped numbers).
Let B be Z × Z , x, y ∈ Z, and

φ 1
(( x, y )) = x + yi,
D
φ 2
(( x, y )) = y + xi.
D

11.1. LOSSED CONSTRUCTIONS 123

The difference between the two φ becomes first of all significant, for example,
Ds
lex complexes should be implemented at the level of pair pairs,
since the value of the first and second components is then set
( a + bi ) ( c + di ) = ( ac - bd ) + ( ad + bc ) i
calculated using different formulas.
The next method to create new ones from old types is the union. Juice-
mark T = ( ρ , I , S ) ( i = 1 , 2 ,..., n ) type and mark T , T ,. . . , T to them
i i i i 1 2 n
type value sets are included, and E , E ,. . . , E the corresponding elementary type
tékhalmazokat. Let us also introduce E = E ∪ E ∪ · · · ∪ E and B = T ∪ T ∪
1 2 n is

··· ∪ T .
1 2 n 1 2

11.2. DEFINITION : U NIÓ


We say that T = ( ρ, I, S) type union of T , T ,. . . , T types,
1 2 n
if
ρ = φ ◦ψ ,
U U
*
where φ
U
⊆B×T,ψU⊆E × B and
*
ψ = { ( ε, b ) ∈ E × B | ∃i ∈ [1 ..n ]: ( ε, b ) ∈ ρ }.
U i
The value of a union's value is T = ( T ; T ; ... ; T ).
1 2 n

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 102/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Here, too, we have given a distinct name to the case where the φ mapping borrows,
sen clear, then the union unification is called. U

' T
t t

φ
T T T T U
1 2 3 n
ρ
B t t t t
1 2 3 n

ψ
* ρ ρ U
3 n
E

11.2. figure. Union construction

In this case, it is very important to always distinguish the construction


( B ) at the intermediate level ( B ) of the new type value set ( T ).
The third allowed type design operation is the iterated one with which one
we can create a new type of existing type. Let T = ( ρ , I , S ) type, T for it
0 0 0 0 0 *
0.
an appropriate type set of values, E is the elemental set of values of type T and B = T
0

124 11. TYPICAL CONSTRUCTIONS

11.3. DEFINITION : I TERMINAL


We say that the type T = ( ρ, I, S) iterates to type T if
0

ρ = φ ◦ψ ,
I I
* *
0 and
where φ
I
⊆B×T,ψI⊆E ×T
* *
ψ = { ( ε, b ) ∈ E × B | ∃ε . . . , ε ∈ E : ( ε , b ) ∈ ρ and
I
1 |b| i i 0
ε = cone ( ε , ..., ε ) }.
1 |b|

The iterated type value set is T = it ( T ).


0

We distinguish three special cases of the iterated type design,


what are the conditions for φ mapping?
I

• If φ mapping mutually clear, then sequence típuskonstrukcióról


I
and its type value set is indicated by T = seq ( T ).
0

• If
( α, t ) , ( β, t ) ∈ φ ⇔ α ∈ perm ( β ) ,
I

then the iterated construct is called a combination type. The combination


value of the value set: T = com ( T ).
0

• If
⋃ ⋃
( α, t ) , ( β, t ) ∈ φ ⇔ {α } = {β },
I i i
i=1 i=1

then we are talking about a set- type construction. The value set for the set type
Marking: T = set ( T ).
0

Of course, the three cases mentioned above are only a special form of iterative
a precious; there is also an iteration that does not fulfill any of the above criteria.
Like the programs, unless we say otherwise, we will be primitive

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 103/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Iintegers,
observelogical
those elementary types that have a type set of values for natural numbers,
values, or characters.

11.2. Szelektorfüggvények
For the types of constructions defined above, we now introduce some functions
and markings that simplify the allegations, programs, and
Glazed.
Let T = ( T , T , ..., T ) be a record. A φD (function
- 1) components T record
1 2 n
selectivity functions or short selectors. if the above record

11.2. SZELEKTORFÜGGVÉNYEK 125

T
t

φ
* I
T0 ρ
B < T , t , t , ..., t >
1 2 3 |t|

ψ
* ρ ρ ρ ρ I
0 0 0 0
E

11.3. figure. Iterated construction

so there are exactly n pieces of selector, and if s is the i -selector, then


i
s : T → T , and
i i
∀ t ∈ T : φ ( s ( t ) , s ( t ) , ..., s ( t )) = t.
D 1 2 n
So the selection functions can be used to retrieve the record of each
(its components). The selectors are used to write the tele-
for the marking of a pusse value set; in the above case, the nomination with the selectors:
T = ( s : T , s : T , ..., s : T ) .
1 1 2 2 n n

Similarly to the record type, we introduce optic functions for joining.


Since in the case of union, the intermediate level is a union of type value sets, so
there is no point in talking about a component. How do we define the selectors in this case?
It will be returned to which original type value set a given T element is to be returned
the function φ assigned to one of its elements .
U was
Let T = ( T , T ; ... , T ) merge type, and : T → L ( i = 1 , ..., n ). it
let s logical functions s i be the selector of union T if ∀i ∈ [1 ..n ]:
1 2 n i

∀t ∈ T :
the
( )
s ( t ) = φ ( - 1) ( t ) ∈ T
i U i

Similarly to the record type, we are writing the joysticks of unification to the new one
type value set. Marking of the type set with the selectors:
T = ( s : T ; s : T ; ... ; s : T ) .
1 1 2 2 n n

Among the iterated type designs, a series of selective functions is defined for the series.
The series of intermediate level type T have US in series, the selectors this
0
returns the members of the series.
Formally: Let T = seq ( T ). The s : T × N → T partial function of T
where ∀t ∈ T : ∀i ∈ [1 .. | φ ( - 1) ( t ) | ]:
0 0
I

s ( t, i ) = φ ( - 1) ( t ) i .
I

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 104/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

126 11. TYPICAL CONSTRUCTIONS

We do not name the selector of the series, instead we use indexing,


ie the t = s ( t, i ) is used.
i

11.3. Its iterated specification functions


If the iterated type is one of the three advanced classes introduced above
, we define additional functions.
Let T = it ( T ), ( α, t ) ∈ φ , and suppose that the iterated sequence, combination
0 I
or set. At this time, dom : T → N ,
0

| α |, if T = seq ( T ) or T = com ( T );
0 0
dom ( t ) = ⋃
| {α } |, if T = set ( T ) .
i 0
i=1

The dom function therefore specifies the number of elements t . The function is well-defined,
starts using the definition of the series, combination and set type,
that the function value is independent of the choice of α .
Hereinafter we will deal with the series type. Where not marked separately, there
T = seq ( T ), ( α, t ) ∈ φ , α = < α , α , ... α > .
0 I 1 2 |α|

• The first and last element of a non-empty series: lov ∈ T → T , hiv ∈ T → T ,


0 0

hunting (=t α) ;
1
HIV ( t ) = α .
|α|

• Extend the sequence at the beginning or end of the series (let e ∈ T ): loext : T ×
0
T → T , hiext : T × T → T ,
0 0

loext ( t, e ) = φ ( con ( < e > , α ));


I
hiext ( t, e ) = φ ( cone ( α, < e > )) .
I

• The series that was left out of the first or last element of an empty series:
lorem ∈ T → T , hirem ∈ T → T ,

lorem ( t ) = φ ( < α , ..., α > );


I 2 |α|
hirem ( t ) = φ ( < α , ..., α | α | - 1 > ) .
I 1

11.4. The function type


In practice, a special record type plays a very important role. Let H
is an arbitrary (countable) set that has a follow-up relationship.
Let us denote this incoming relation with succ and inverse the pred- mark in inverse .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 105/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

11.4. TYPE OF PURPOSE 127

11.4. DEFINITION : TYPE TYPE


Let E be a value set of any type. Then F = ( H, seq ( E )) re-
is called a string function type and is F = f un ( H, E ).

We also introduce some important specification functions to the function type. Furthermore,
be referred to as F = f un ( H, E ) , (( h, t ) , f ) ∈ φ . At
D

• home : F → N ,
0
dom ( f ) = dom ( t ) .

• lob : F → H ,
lob ( f ) = h.

• error : F → H ,
error ( f ) = succ dom ( f ) - 1 ( h ) .

• Hunt ∈ F → E ,
hunt ( f ) = hunt ( t ) .

• hiv ∈ F → E ,
hiv ( f ) = hiv ( t ) .

• loext, hiext : F × E → F ,

loext ( f, e ) = φ ( pred ( h ) , loext ( t, e ));


D
hiext ( f, e ) = φ ( h, hiext ( t, e )) .
D

• lorem, hirem ∈ F → F ,

lorem ( f ) = φ ( succ ( h ) , lorem ( t ));


D
hirem ( f ) = φ ( h, hirem ( t )) .
D

Similarly to the series, we are introducing a function type to a partial selection


function. Consider the f used above . Then s
f
∈H→E,D f = s
i k
{succ ( lob ( f )) | 0 ≤ i <dom ( f ) } , and if g ∈ Df , g = succ ( lob ( f )), then
s

s ( g ) = t k +1 .
f

We do not name the function of the function type separately, instead of the ma-
the parentheses used to denote the substitution value of the function -
or just index it, that is

f =f(g)=s (g).
g f

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 106/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

128 11. TYPICAL CONSTRUCTIONS

The function type name reflects the illustrative image of a function type,
s value can be interpreted as a partial function H → E , for which interpretation is given
its range ranges from " lobe to error " and its values are contained in the serial component.

We can extend the functions dom, hunt, hiv, lob, hib functions introduced above
for the whole state: compose with the corresponding variable. So if for example x is one
series variable, then dom ◦ x is a function that is interpreted as a whole state.
We introduce a new mark for such function compositions: if t above the dependencies,
any prescriptions and x the corresponding type variable, the t ◦ x instead xt -t
writing.

11.5. Types of Types of Types of Types


There has been something missing from the type of constructions so far: we have not talked yet
about the operations of the constructed types. For the special cases listed above - just the one
with defined functions - we will introduce some types of operations.
We will now be referred to as permissible conditions as A → L
many of which may be the conditions of a branch or cycle.
Let T = ( s : T , ..., s : T ) record, t : T , t : T ( i ∈ [1 ..n ]). Since t
1 1 n n i i
the state of space variables, t can be composed by the selector functions and thus the state-
field interpreted functions. The s ◦t function is described below
i
ts will be marked. For a record type, use the select function
i
we look at it.
'
In addition,
'
we introduce
'
ts : = t . In the t : = t refers assignments,
i i
wherein t .s = t , and t each other component of equal to is respective system component
chinense. i i

The above types of operations give you the option of making a "field" for a record
can be retrieved or changed. The operation defined above is disturbing
it may be that we add a function ( ts ). Therefore, it is important to note that
i
it is just a mark for the assignment.
Let T = ( s : T ;, ... ; s : T ) merge, t : T , t : T ( i ∈ [1 ..n ]). At
1 1 n n i i
the mark applied to the record type is also introduced in the case of unification, ts -n is s ◦ t
i i
composition, and is considered to be a permitted function.
In addition, the allowed operation is t : = φ ( t ). This value
U i
the symbol will be simplified, hereinafter referred to as t : = t .
i
We can "reverse" the introduction of certain reasonable limitations.
So we get the following partial assignment: t : = t . This assignment is only available
i
can be done if ts true.
i
The series type design is very common and can be defined with a variety of operations
relationship. Depending on what we consider to be implemented different
we are talking about constructions. Now we will give you a few possible actions then
sort types are categorized by their permitted operations.

11.5. TYPES OF TYPE CONSTRUCTION TYPES 129

Let hereinafter referred to as T = seq ( E ), t : T , E : E . Then for the previous selectors


similarly introduce the following markings:
dom ◦ t → t.dom

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 107/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
hunt◦ t◦ t →
hiv → t.lov
t.hiv
Of course, t.lov and t.hiv are only partial functions. In addition, the following (possibly
partial) assignments, we will use the following markings:
t : = lorem ( t ) → t : lorem
t : = hirem ( t ) → t : hirem
t : = loext ( t, e ) → t : loext ( e )
t : = hiext ( t, e ) → t : hiext ( e )
e, t : = hunt ( t ) , lorem ( t →
) e, t : lopop
e, t : = hiv ( t ) , hirem ( t ) → and, t : hipop
Markings introduced may seem confusing at first glance, since the same key-
word as a function on the left, and on the right as the name of the action.
It is therefore important to note that the operations on the right are just the left hand side
simplification markings .
Depending on the operations defined above,
we are talking about different constructions.
Let T = seq ( E ). Then the T
• sequential input file if only the finop is the allowed operation;
• Sequential output file if only the hiext is the allowed operation;
• stack if permitted actions are loext and lopop , or hiext and hipop ;
• place when the permitted operations hiext and lopop or loext and Hipop .
In order for the sequential input file to be used with the lopop operation,
we need to know when we read the last item from the file. This problem is so
we are resolved to introduce an extremal element and stipulate that the file-
this is the last item (so even the empty file is included). This technique is being implemented
in operating systems where the end of text files end file end (EOF)
character indicates.
Since the lopop operation may in some cases be uncomfortable -
when cumbersome extremal elements are found - we are introducing another reader
too. Is used for indicating the success in reading {norm, aberrant} set ELE
MEIT. Then, in the sx, dx, x : read operation, we mean the following simultaneous assignment:
{
norm, hunt ( x ) , lorem ( x ) , if dom ( x ) = 0;
sx, dx, x : read =
abnorm, dx, x, has dom ( x ) = 0 .

130 11. TYPICAL CONSTRUCTIONS

If the read operation is allowed for a sequential file , it is not necessary


extremal element, and instead of the value of the sx variable, it can be decided by the end
we understand the file.
Let F = f un ( H, E ), f : D , E : E , i : H . This is similar to the series type
introduce the following markings:

dom ◦ f → f.dom
hunt ◦ f → f.lov
hiv ◦ f → f.hiv
lob ◦ f → f.lob
error ◦ f → f.hib

In addition to the above functions, the function of the function type, f ( i )


we are considered as covered. Specifies for a selector (field) introduced for the record type

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 108/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
In this case,isthe
assignment assignment
partial becausehas the equivalent:
it can only be donef (ifi ): = this
f.lob ≤ i partial
≤ f.hib assignment.
. At The
'
above the mark f : = f refers assignments for which:
' '
f .obl = f.lob and f .ib = f.ib and
'
f ( i ) = e and
∀j ∈ [ f.lob..f.hib ]: j = i → f ( j ) = f ( j ) .
Expanded and aborted operations for sequences as function type
It is defined as:

f : = lorem ( f ) → f : lorem
f : = hirem ( f ) → f : hirem
f : = loext ( f, e ) → f : loext ( e )
f : = hiext ( f, e ) → f : hiext ( e )

If the operations listed in this last group are not assigned to a function type,
then we get a special function type, the vector. The general
a distinction is made for the type of vector by a function type:
V = vector ( H, E ).

Chapter 12

Programming Items
(Derivation)

First, we are looking for a solution for some simple tasks. These tasks
are important for us in two ways. First, there are many specific tasks
they have their generalizations, so their solution gives many concrete opportunities
(more concrete) task; so we call them programming items.
On the other hand, through their solution, we show you how to solve a
drive. Then we put some more complex items down. Finally, the items are an important group
port, calculating the substitution value for functions with special properties
deal.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 109/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
In this
report: chapter
given in f we: use
X →the
Y following
function. By this we will understand that the task is A
state space has an H alter whose X → Y functions are defined, and
variables of the H aliquot with a corresponding parameter variable in the pre and post condition
recorded.

12.1. Programming Items Interval


The following items have many common features. Each of them is about a [ m..n ]
interval is a property of φ . The φ outside the interval of the state space
can depend on many other components.

A = Z × Z × ...
mn ...
B = Z × Z × ...
' '
m n ...

132 12. PROGRAMMING ITEMS (DESIGN)

' ' *
Q:(m=m ∧n=n ∧m ≤n)
R : ( Q ∧ φ ( m, n, ... ))
*
In the prerequisite m m- 1 or m , depending on whether the task has any meaning
empty interval or none.
Such tasks can be solved by cycling. It is an invariant property
we choose that φ is not for the whole [ m..n ] interval, but for only one [ m..k ]
therefore, the state space is expanded with a new whole component ( k ) and extended
we will go to the new state of play. Of course, the extension is only
since the specification of the expanded task is formally only the state-
differs from the original in space. So the invariant property is:
*
P ( m, k, ... )) P = ( Q ∧ k ∈ [ m ..n ] ∧ φ
This invariant property is appropriate because:
1. The cycle condition k= n is chosen P ∧ ¬π ⇒ R , ie the cycle is satisfied
condition 2 of the deduction rule.
2. The first condition of the deduction rule is usually not met, but we can easily
' '
a Q -t choose,
'is
which is apparent from the P , and easy to get to Q of Q into.
This Q usually the case of an empty or sometimes one-length interval,
say
' *
Q = ( Q ∧ k = m ∧ φ ( m, k, ... )) .
3. You have to choose a terminating function, in which case it is obvious choice:

t = ( n - k ), for P ∧ π ⇒ t> 0 .

4. The following two conditions must now be fulfilled:


'
Q ⇒ lf ( S , Q ) and P ∧ π ∧ t = t ⇒ lf ( S , P ∧ t <t ) .
1 0 0 0
In general, it can be said that, in the second case,
lying to look for S in sequence. It is easy to see that
0
the second member of the sequence
k:=k+1
assignment reduces the value of the termination function. For the fact that the invariant
the property of the sequence is also fulfilled

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 110/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Q = ( lf ( k : = k + 1 , P ) ∧ t = t ) = ( P k ← k + 1 ∧t = t 0 )
''

0
because it is so
( )
''
Q ⇒ ( lf ( k : = k + 1 , P ∧ t <t )) = P k ← k + 1 ∧n-k- 1 <t
0
0
is actually fulfilled.

12.1. PROGRAMMING ITEMS IN INTERVAL 133

For the specification of the specification, if S and S are programs that are ∀b ∈ B or
1 2
in other words, irrespective of the value of the parameter variables
'
Q ⇒ lf ( S , Q )
1

and
Q ''
P∧π∧t=t ⇒-f ( S 2 , ∧ t = t 0 )
0
is met, the schema of the solver program is:
Q
'
S
1
Q k=n
P∧π∧t = t
S ''
0
2
k:=k+1 Q
R P ∧t <t
0

12.1.1. Summary
Let f : Z → Z be given. Our task is to give a given [ m..n ] ⊂ Z
we sum up the values of the function f . Specify the task first.
A=Z×Z×Z
nec
B=Z×Z
' '
m n
' '
Q:(m=m ∧n=n ∧ m ≤ n + 1)
Σ
R : ( Q ∧ s = f ( i ))
i=m
In this case

Σ
φ ( m, n, s ) = ⎝ s = f(j) ,
j=m

so the invariant property is:

Σ
P = ∪ Q ∧ k ∈ [ m - 1 ..n ] ∧ s = f(j) ,
j=m

'
the Q statement:
'
Q = ( Q ∧ k = m - 1 ∧ s = 0) .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 111/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

134 12. PROGRAMMING ITEMS (DESIGN)

'
Now we need to look for a program that comes from Q to Q . The k, s : =
m - 1 , 0 corresponds to this criterion, since
Q'
⇒ Q-f ( k, s : = m - 1 , 0 , ) = ( Q ∧ m - 1 = m - 1 ∧ 0 = 0) = Q .
I no longer have to do is find a program that P ∧ π ∧ t = t of
' 0
Q , where

(P k ← k + 1 ∧ t = t ) Σ
''
0 = Q ∧ k + 1 ∈ [ m - 1 ..n ] ∧ s = f ( j ) ∧ t = t .
Q = 0
j=m

'
Let us see what is not fulfilled in Q : since k ∈ [ m - 1 ..n ] ( P ) and k = n ( π )
k +1 ∈ [ m- 1 ..n ] exists. However, the value of s is not good because it contains only k to P
''
f amount values of Q according named already k shall + 1. Based on the above considerations
so s increases with f ( k + 1), ie:
Q'
P∧π∧t=t ⇒ (lf ( s : = s + f ( k + 1) , ) = )
0 Σ
= Q ∧ k + 1 ∈ [ m - 1 ..n ] ∧ s + f ( k + 1) = f ( i ) ∧ t = t
0 i=m
Based on the above deduction, the following item can be stated:
Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q
k, s : = m - 1 , 0
'
Q k=n
P∧π∧t = t
s = s + f ( k + 1) ''
0

k:=k+1 Q
R P ∧t <t
0

12.1.2. counting
Let β be a logical function interpreted in integers. The task is to
calculate the number of places true β in the interval [ m..n ] ⊂ Z.
A=Z×Z×N
0
MND
B=Z×Z
' '
m n
' '
Q : ( m = m ∧ n = n ∧ m ≤ n + 1)
Σ
R : ( Q ∧ d = χ ( β ( i )))
i=m
In the above specification χ : L → { 0 , 1 } for which χ ( true ) = 1 and χ ( false ) = 0.
Solving this problem is analogous to the description of the summation:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 112/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

12.1. PROGRAMMING ITEMS IN INTERVAL 135

Σ
φ ( m, n, d ) = d= χ ( β ( j )) χ ,
j=m

the invariant property:

Σ
P = ∪ Q ∧ k ∈ [ m - 1 ..n ] ∧ d = χ ( β ( j )) χ ,
j=m

'
the Q statement:
'
Q = ( Q ∧ k = m - 1 ∧ d = 0) .
'
The Q of Q per program into Q'
the k d : = m - 1 , 0 assignment because
⇒ Q-f ( k, d : = m - 1 , 0 , ) = ( Q ∧ m - 1 = m - 1 ∧ 0 = 0) = Q .
( )
Σ
Q
''
= Q ∧ k + 1 ∈ [ m - 1 ..n ] ∧ d = χ ( β ( i )) ∧ t = t
0
i=m
''
Now it is necessary to determine whether P ∧ π ∧ t = t , this follows from Q . If
¬β ( k + 1), then in the case of β ( k + 1), as in the summary,
0
"is
we need to increase the value of d . Therefore, the program in P ∧ π ∧ t = t to Q the
IF ( β ( k + 1): d : = d + 1 , ¬β ( k + 1): SKIP ) will be branching because the
0 branching

applying the rule of deduction:

P ∧ π ∧ t = t ∧ β ( k + 1)
''
0 ⇒ lf ( d : = d + ''1 , Q ),
P ∧ π ∧ t = t ∧ ¬β ( k + 1) ⇒ lf ( SKIP, Q )
0

''
because P ∧ π ∧ t = t ⇒ lf ( IF, Q ) is satisfied.
Based on the above considerations,
0 the following item is obvious:
Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q
'
k, d : = m - 1 , 0
Q k=n
P∧π∧t = t
\ β ( k + 1) / 0

d:=d+1 SKIP ''

k:=k+1 Q
R P ∧t <t
0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 113/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
136 12. PROGRAMMING ITEMS (DESIGN)

12.1.3. Up to Search
Let H be any arbitrary set and f : Z → H is a given function. loading
we find that in a given [ m..n ] ⊂ Z interval, look for the function f
maximum and a place where this maximum value is added.
A=Z×Z×Z×H
mni max
B=Z×Z
' '
m n
' '
Q:(m=m ∧n=n ∧m≤n)
R ( Q ∧ i ∈ [ m..n ] ∧ max = f ( i ) ∧ ∀j ∈ [ m..n ]: f ( j ) ≤ f ( i ))
Contrary to the foregoing, we did not allow this specification to be empty
interval. The reason is very simple: there is no point in blank intervals
to ask where is the maximum. Now

φ ( m, n, i max ) = ( i ∈ [ m..n ] ∧ max = f ( i ) ∧ ∀j ∈ [ m..n ]: f ( j ) ≤ f ( i )) .

So the invariant property is:

P = ( Q ∧ k ∈ [ m..n ] ∧ i ∈ [ m..k ] ∧ max = f ( i ) ∧ ∀j ∈ [ m..k ]: f ( j ) ≤ f ( i )) .


'
Q = ( Q ∧ k = m i ∧ = m ∧ max = f ( m )) ,
and S a i, k, max : = m, m, f ( m ). THE
1'
Q = ( Q ∧ k + 1 ∈ [ m..n ] ∧ i ∈ [ m..k + 1] ∧ max = f ( i ) ∧
∀j ∈ [ m..k + 1]: f ( j ) ≤ f ( i ) ∧ t = t ) . 0
"
A program in P ∧π ∧t = t to Q will also have a branch here: IF ( f ( k +1) ≥
max : i, max : = k + 1 , f ( k + 01); f ( k + 1) ≤ max : SKIP ), since

P ∧ π ∧ t = t ∧ f ( k + 1) > = max
''
0 ⇒ lf ( i, max : ='' k + 1 , f ( k + 1) , Q ),
P ∧ π ∧ t = t ∧ f ( k + 1) < = max ⇒ lf ( SKIP, Q )
0
''
because P ∧ π ∧ t = t ⇒ lf ( IF, Q ) is satisfied.
Item: Solution of the following
0 program in the form of a structure, as described above:
fictitious task:
Q
'
i, k, max : = m, m, f ( m )
Q k=n
P∧π∧t = t
f ( k + 1) ≥ max \ f ( k +1) ≤max 0
\
i, max : = k + 1 , f ( k + 1) SKIP ''

k:=k+1 Q
R P ∧t <t
0

12.1. PROGRAMMING ITEMS IN INTERVAL 137

12.1.4. Conditional Maximum Search

Let H be any arbitrary set and f : Z → H is a given function.


Let β be a logical function interpreted in integers. Determine the
⌈Β⌉ ∩ [ m..n ] the maximum function f and the element of the set,
on which f adds its maximum value.

A=Z×Z×Z×H ×L

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 114/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
mni max l
B=Z×Z
' '
m n
' '
Q : ( m = m ∧ n = n ∧ m ≤ n + 1)
R ( Q ∧ L = ( ∃i ∈ [ m..n ]: β ( i )) ∧ → l ( i ∈ [ m..n ] ∧ β ( i ) ∧ max = f ( i ) ∧
∀j ∈ [ m..n ]: β ( j ) → f ( j ) ≤ f ( i )))
Again, the blank interval is allowed again, and the answer is that the interval-
there is no β -element in lumban .
The derivation as above:
P = ( Q ∧ k ∈ [ m - 1 ..n ] ∧ L = ( ∃i ∈ [ m..k ]: β ( i )) ∧ → l ( i ∈ [ m..k ] ∧ β ( i ) ∧
max = f ( i ) ∧ ∀j ∈ [ m..k ]: β ( j ) → f ( j ) ≤ f ( i )))
'
Q = ( Q ∧ k = m - 1 ∧ l = false )
'
Q = ( Q ∧ k + 1 ∈ [ m - 1 ..n ] ∧ L = ( ∃i ∈ [ m..k + 1]: β ( i )) ∧
l → ( i ∈ [ m..k + 1] ∧ β ( i ) ∧ max = f ( i ) ∧
∀j ∈ [ m..k + 1]: β ( j ) → f ( j ) ≤ f ( i )))
''
P ∧ π and Q , it can be seen that there are three main possibilities:

• ¬β ( k + 1): then SKIP;

• β ( k + 1) ∧ ¬l : this is the first property with β , so l, i, max : = true, k +


1 , f ( k + 1);

• β ( k + 1) ∧ l : then two cases are known at the maximum search:

- f ( k + 1) ≥ max : then i, max : = k + 1 , f ( k + 1)

- f ( k +1) ≤max : then SKIP .

138 12. PROGRAMMING ITEMS (DESIGN)

Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
k, l : = m - 1 , false
k=n
\ ¬β ( k +1) \ β ( k + 1) ∧ ¬l \ β ( k + 1) ∧ l
\ f ( k +1) ≥max \ f ( k +1) ≤max
SKIP l, i, max : = i, max : = SKIP
true, k + 1 , f ( k + 1) k + 1 , f ( k + 1)
k:=k+1

12.1.5. Linear search


Let β : Z → L be a function and [ m..n ] be an interval. Find the first one
a space in the interval [ m..n ] where β is true if it is at all
such a place.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 115/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

A=Z×Z×Z×L
mnil
B=Z×Z
' '
m n
' '
Q : ( m = m ∧ n = n ∧ m ≤ n + 1)
R ( Q ∧ L = ( ∃j ∈ [ m..n ]: β ( j )) ∧ → l ( i ∈ [ m..n ] ∧ β ( i ) ∧
∀j ∈ [ m..i - 1]: ¬β ( j )))
The invariant property of the cycle:
P = ( Q ∧ i ∈ [ m - 1 ..n ] ∧ L = ( ∃j ∈ [ m..i ]: β ( j )) ∧ ∀j ∈ [ m..i - 1]: ¬β ( j )),
'
Q ' = ( Q ∧ i = m - 1 ∧ l = false ),
Q = ( Q ∧ i + 1 ∈ [ m - 1 ..n ] ∧ L = ∃j ∈ [ m..i + 1]: β ( j )
∧ ∀j ∈ [ m..i ] ¬β ( j ) ∧ t = t 0 ),
and thus the first half of the cycle core will be the value of l : = β ( i + 1).
Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q
i, l : = m - 1 , false
'
Q ¬l ∧ i = n
P∧π∧t = t
l : = β ( i + 1) ''
0

i:=i+1 Q
R P ∧t <t
0

12.2. SUBJECTS "CONDITIONAL" VERSION 139

Note: this programming item is also called linear search version 2.8 .

12.2. "Conditional" version of items


The following mark is used. Let δ : Z → L and m ∈ Z. Let us
up to ∃i ≥ m : δ ( i ). Let α ( m, δ ) be the first integer that does not
is less than m and is true of δ , ie

α ( m, δ ) :: = min {x ∈ Z | x ≥ m and δ ( x ) }.

Let's put the items in the previous section in a little different form. The fulfillment of φ
now not at an interval [ m..n ], but from m to the first δ property
demand it.
A = Z × ...
m ...
B = Z × ...
'
m ...
'
Q : ( m = m ∧ ∃i ≥ m : δ ( i ))
R : ( Q ∧ φ ( m, α ( m, δ ) ... ))
The solution will now be a cycle. The state space is defined by a whole and one logical com-
propagate with the proxy, be the appropriate variables k and v . The cycle is invariant
its property is that k ≥ m - 1, from φ m to k , v accordingly
True or false, it 's on δ is true, and eventually he even demand that 's before
there is no place with δ , ie
P = ( Q ∧ k ≥ m - 1 ∧ φ ( m, k, ... ) ∧
v = ∃i ∈ [ m..k ]: δ ( i ) ∧ ∀j ∈ [ m..k - 1]: ¬δ ( j )) .
The cycle condition: ¬v since v ∧ P in case of k = α ( m, δ ), therefore v ∧ P ⇒ R .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 116/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'
In this case, Q is optional:
'
Q = ( Q ∧ k = m - 1 ∧ φ ( m, k, ... ) ∧ ¬v ) .
The termination function is as follows: because of the precondition there exists an integer N ,
which is greater than m and is true of δ , so be it

t = ( N-k ) ,

which is positive for P ∧ ¬v .


Now we define the cycle nucleus as a sequence. The second half of the sequence
be
k, v : = k + 1 , δ ( k + 1)

140 12. PROGRAMMING ITEMS (DESIGN)

and
''
Q = ( lf ( k, v : = k + 1 , δ ( k + 1) P ) ∧ t = t ) = P k ← k + 1 , v ← δ ( k +1) ∧ t = t .
0 0

because
P k ← k + 1 , v ← δ ( k +1) = ( Q ∧ k + 1 ≥ m - 1 ∧ φ ( m, k + 1 , ... ) ∧
δ ( k + 1) = ∃i ∈ [ m..k + 1]: δ ( i ) ∧ ∀j ∈ [ m..k ]: ¬δ ( j )) ,
''
if P ∧ π ∧ t = t fulfilled, then it is necessary to satisfy Q only that φ ( m, k +
1 ,. . . ) should be
0 is true.
' '
So, extending the parameter space with a k integer and a v logical component,
we only look for the following two programs:
'
Q ⇒ lf ( S , Q )
1

and
' ' ' '
P∧π∧k=k ∧ v = v ⇒-f ( S 2 , φ ( m, k + 1 , ... ) ∧ k = k ∧ v = v ).

So the Solution Program Scheme:


Q
'
S1
Q ¬v
P∧π∧t = t
S ''
0
2
k, v : = k + 1 , δ ( k + 1) Q
R P ∧t <t
0
Note that in the invariant property v = ∃i ∈ [ m..k ]: not δ ( i )
write v = δ ( k ), because k = m - 1, and we can not find anything from δ ( k - 1).

12.2.1. Summarize
Let f : Z → Z and δ : Z → L be given functions. Suppose it exists
i ≥ m , which δ is true. Our task is to give the given m to the first i to which δ
True, we sum up the values of the function f . Specify the task first.
A=Z×Z
ms
B=Z
'
m
'
Q:(m=m ∧ ∃j ≥ m : δ ( j ))
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 117/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
R :( Q∧s = Σ f ( j ))
j=m

12.2. SUBJECTS "CONDITIONAL" VERSION 141

In this case, then


Σ
φ ( m, i, s ) = ⎝ s = f(j) ,
j=m

that is, it is the same as in the interval summing, so S can be selected as a


1
k, s, v : = m- 1 , 0 , false assignments and S had the same as that in the interval
2
for summation: s : = s + f ( k + 1).
So the following item can be said:
Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q k, s, v : = m - 1 , 0 , false P∧π∧
'
Q ¬v t=t 0
''
s = s + f ( k + 1) Q
k, v : = k + 1 , δ ( k + 1) P ∧
R t <t
0

12.2.2. Count up
Let β and δ be the logical functions interpreted in the integers. Suppose that
there exists i ≥ m , for which δ is true. The task is to calculate the number of places true β
from m to the first i until δ true.
A=Z×N
0
md
B=Z
'
m
'
Q : ( m = m ∧ ∃i ≥ m : δ ( i ))
Σ
R :( Q∧d = χ ( β ( i )))
i=m
Solving this problem is analogous to the description of the summation.
Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q
'
k, d, v : = m - 1 , 0 , false P∧π∧
Q ¬v t=t
0
β ( k + 1)
\ / ''
d:=d+1 SKIP Q
k, v : = k + 1 , δ ( k + 1) P ∧
R t <t
0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 118/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

142 12. PROGRAMMING ITEMS (DESIGN)

12.2.3. Maximum search until condition


Let H be any arbitrary set and f : Z → H is a given function and δ is
integer logical function. Suppose that there are i ≥ m , which
δ true. Our task is to find m from the first i until δ true
the maximum value of the function f and a location where this maximum value is added.

A=Z×Z×H
we max
B=Z
'
m
'
Q : ( m = m ∧ ∃j ≥ m : δ ( j ))
R ( Q ∧ i ∈ [ m..α ( m, δ )] ∧ max = f ( i ) ∧ ∀j ∈ [ m..α ( m, δ )]: f ( j ) ≤ f ( i ) )
Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q
i, k, max, v : = m, m, f ( m ) , δ ( m ) P∧π∧
'
Q ¬v t=t
0

f ( k + 1) ≥ max \ f ( k +1) ≤max


\
''
i, max : = k + 1 , f ( k + 1) SKIP Q
k, v : = k + 1 , δ ( k + 1) P ∧
R t <t
0

12.2.4. Conditional maximum search condition


Let H be any arbitrary set and f : Z → H is a given function.
Let β and δ be the logical functions interpreted in the integers. Determine
for the ⌈β⌉ ∩ [ m..α ( m, δ )] if it is not empty, the maximum function f and the
a set of elements on which f adds its maximum value.

A=Z×Z×H ×L
we max l
B=Z
'
m
'
Q : ( m = m ∧ ∃j ≥ m : δ ( j ))
R ( Q ∧ L = ( ∃i ∈ [ m..α ( m, δ )] β ( i )) ∧ → l ( i ∈ [ m..α ( m, δ )] ∧ β ( i ) ∧
max = f ( i ) ∧ ∀j ∈ [ m..α ( m, δ )] β ( j ) → ( f ( j ) ≤ f ( i ))))

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 119/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

12.2. SUBJECTS "CONDITIONAL" VERSION 143

Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
k, l, v : = m - 1 , false, false
¬v
\ ¬β ( k +1) \ β ( k +1) ∧¬l \ β ( k + 1) ∧ l
\ f ( k +1) ≥max \ f ( k +1) ≤max
SKIP l, i, max : = i, max : = SKIP
true, k + 1 , f ( k + 1) k + 1 , f ( k + 1)
k, v : = k + 1 , δ ( k + 1)

12.2.5. Linear search


Now we are slightly different from the general scheme and we are examining several special cases.
Let β : Z → L be a property. The first task is to find it
the integer with the smallest β property, which is not smaller than the given m ∈ Z
provided that there is one.
A=Z×Z
we
B=Z
'
m
'
Q : ( m = m ∧ ∃j ≥ m : β ( j ))
R ( Q ∧ i ≥ m ∧ β ( i ) ∧ ∀j ∈ [ m..i - 1]: ¬β ( j ))
The task is solved by cycling. The invariance weakens the postponement, el-
leave it β ( i ):
P = ( Q ∧ i ≥ m ∧ ∀j ∈ [ m..i - 1]: ¬β ( j ))

'
1) Q = ( Q ∧ i = m )
2) π = ¬β ( i )

3) Let N ≥ m be any number fixed for which β ( N ) is true (such


because of the prerequisite). Then t = N - i .

5) The i : = i + 1 assignment reduces the termination function value.

4) P ∧ π ⇒ lf ( i : = i + 1 , P )

144 12. PROGRAMMING ITEMS (DESIGN)

Item: Solution of the following program in the form of a structure, as described above:
fictitious task:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 120/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Q
'
i:=m
Q ¬β ( i )
P ∧π
i:=i+1
R P
The above program solves the problem only if β is the property
permitted condition. If that is not the case then we have to look for another solution.
Select the following invariant (the job remains the same!):
P = ( Q ∧ i ≥ m - 1 ∧ ( ∀j ∈ [ m..i - 1]: ¬β ( j )) ∧ L = ∃j ∈ [ m..i ]: β ( j ))
At:
'
1) Q = ( Q ∧ i = m - 1 ∧ l = false )
2) π = ¬l
3) Let N ≥ m be any number fixed for which β ( N ) is true (such
because of the prerequisite). Then t = N - i .

5) The i : = i + 1 assignment reduces the termination function value.


4) The cycle core sequence will be the intermediate condition:
'
Q = ( Q ∧ i + 1 ≥ m - 1 ∧ ( ∀j ∈ [ m..i ] ¬β ( j )) ∧ L = ∃j ∈ [ m..i + 1]: β ( j )) ,
and thus the first half of the cycle core will be the value of l : = β ( i + 1).

Item: Then the following program can be solved for the specified task.
Q
i, l : = m - 1 , false
'
Q ¬l
P ∧π
l : = β ( i + 1) ''

i:=i+1 Q
R P
Let γ, δ : Z → L and m be given . Mark β with γ ∨ δ ,
and suppose there exists j ≥ m to be β ( j ). Find the earliest i ≥ m : γ ( i )
element (if any) before which ( m from) was not true δ ! This version
the specification will be different as the task has changed.
A=Z×Z×L
miu
B=Z
'
m

12.2. SUBJECTS "CONDITIONAL" VERSION 145

'
Q : ( m = m ∧ ∃j ≥ m : β ( j ))
R ( Q ∧ u = ( ∃j ≥ m : γ ( j ) ∧ ∀k ∈ [ m..j - 1]: ¬δ ( k )) ∧
u → ( i ≥ m ∧ γ ( i ) ∧ ∀j ∈ [ m..i - 1]: ¬β ( j )))
The invariant of the cycle that solves the problem:
P = ( Q ∧ i ≥ m - 1 ∧ u = ( ∃j ∈ [ m..i ]: γ ( j )) ∧ v = ( ∃j ∈ [ m..i ]: δ ( j )) ∧
∀j ∈ [ m..i - 1]: ¬β ( j ))
At:
'
1) Q = ( Q ∧ i = m - 1 ∧ u = false ∧ v = false )
2) π = ¬u ∧ ¬v

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 121/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
3) Let N ≥ mofbethe
because any number fixed
prerequisite). for twhich
Then = N - βi .( N ) is true (such

5) The i : = i + 1 assignment reduces the termination function value.


4) The cycle core sequence will be the intermediate condition ( lf ( i : = i + 1 , P )):
'
Q = ( Q ∧ i + 1 ≥ m - 1 ∧ u = ( ∃j ∈ [ m..i + 1]: γ ( j )) ∧
v = ( ∃j ∈ [ m..i + 1]: δ ( j )) ∧ ∀j ∈ [ m..i ] ¬β ( j ) ∧ t = t ) ,
0

so that the first half of the loop core will be u, v : = γ ( i + 1) , δ ( i + 1).

Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q
i, u, v : = m - 1 , false, false P∧π∧
'
Q ¬u ∧ ¬v t=t
0
''
u, v : = γ ( i + 1) , δ ( i + 1)
Q
i:=i+1 P ∧
R t <t
0
Note: The above three versions of linear search are ordered by linear search 1,
2, 3, too.

12.2.6. Items differently


The items in this chapter could have been expressed in a little different form or form
too. You can get different versions of these items. Let's look at some examples.
So far, the "conditional" tételeinket is formulated to φ met m from
we require the first δ property, including that of the δ property.
We could also say that φ is fulfilled from m to only the properties of ¬δ
demand it.

146 12. PROGRAMMING ITEMS (DESIGN)

*
Let m be m + 1 or m , depending on whether *
or not there is
task at the blank interval. Suppose that ∃i ≥ m : δ ( i ) and be
' *
α ( m, δ ) :: = min {x ∈ Z | x ≥ m and δ ( x + 1) }.

A = Z × ...
m ...
B = Z × ...
'
m ...
' *
Q:(m=m ∧ ∃i '≥ m : δ ( i ))
R : ( Q ∧ φ ( m, α ( m, δ ) ... ))
The solution will be very similar to the previous, only in the invariant property
[ m..k ] is replaced by [ m..k + 1]
*
P = ( Q ∧ k ≥ m - 1 ∧* φ ( m, k, ... ) ∧ *
v = ∃i ∈ [ m ..k + 1]: δ ( i ) ∧ ∀j ∈ [ m ..k ] ¬δ ( j )) ,
1
'
and Q in named ¬v instead of v = δ ( k ),
' *
Q 1 = ( Q ∧ k = m - 1 ∧ φ ( m, k,... ) ∧ v = δ ( k + 1)) .
From this point on, the derivation proceeds in exactly the same way and the solving program
schema:
Q
S '1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 122/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

P∧π∧t = t
'
¬v
Q S 0
2 ''

k, v : k + 1 , δ ( k + 2) Q
R P ∧t <t
0
'
1 specification
where S ' ,
Q ⇒ lf ( S 1 , Q 1 )
which means that it is in the specific items . . . , v : = . . . , fake instead . . . , v :=
..., δ ( m ).
Another option for variants: the programs in this and the previous section
could have been more generalized.
Functions can be interpreted as a whole instead of an arbitrary,
zon, all of which has the following ( succ ) and its predecessor ( pred ). This
there is no special problem, just substituting succ ( x ) instead of x + 1 instead of x - 1
pred ( x ) must be a letter.
It's a little more complicated if we just make up the set
of any element of succ or pred finite multiparty element
, which is a frequently occurring case in practice. The solution to this
' '
1 programotspecifications.
in the case of similarly modifying P and Q new S

12.3. PROGRAMMING ITEMS IN HALMAZON 147

12.3. Programming Items Set


Items for the functions interpreted in the interval can be formulated
more generally.
Let the functions be interpreted on arbitrary finite sets, and suppose,
so that we can decide on this set whether it's empty, if not empty, we can choose
one element, and finally one element in it, can be left out of it.
That is, a component H of the state space whose elements are E
finite subset of the set. The E is also a component of the state space. Appropriate
variables should be h and e ; the permissible condition h = ∅ and e : ∈ h and h : = h \ {e}
allowed programs. With regard to these programs,
that if condition R does not depend on e , then lf ( e : ∈ h, e ∈ h ∧ R ) = h = ∅ ∧ R , and
h ← h \ {e}
for any R condition lf ( h : = h \ {e}, R ) = R .
The scheme of tasks in this case is:
A = H × E × ...
he ...
B = H × ...
'
h
'
Q : ( h = h ( ∧ h = ∅ ))
'
R : ( φ ( h , ... ))
Note: ( ∧ h = ∅ ) is required if the task does not make sense
for empty set (maximum search).
The task is now solved with a cycle. The invariant property
' '
P = ( h ⊆ h ∧ φ ( h \ h, ... )) ,
the cycle condition is h = ∅ ,
the termination function: | h | .
' '
Q = ( h = h ∧ φ ( ∅, ... )) .
Solution Program Schema:
Q
'
S
1
Q h=∅
P∧π∧t = t
e:∈h 0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 123/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
S '''' '

h : = h 2\ {e} Q
R P ∧t <t
0
''
The Q = ( E h ∈ ∧ ''P' ∧ π ∧h t←=h \t{e} ) e : ∈ h is satisfied after, h : = h \ {e} reduces
, so in the usual
'
way Q = ( P
0
''
∧ t = t 0' '').
Thus, Q, Q pair specified S and Q and Q pair specified S programs
has been defined. 1 2

Let's look at the specific items!

148 12. PROGRAMMING ITEMS (DESIGN)

First
Summary ( )
Σ
φ ( g, s ) = s = f(x)
x∈g

S
1

s:=0

S
2

s:=s+f(e)

Second
counting ( )
Σ
φ ( g, d ) = d = χ ( β ( x ))
x∈g

S
1

d:=0

S
2

β(e) ¬β ( e )
\ \
d:=d+1 SKIP

Third
Up to Search
'
φ ( g, i, max ) = ( i ∈ h ∧ max = f ( i ) ∧ ∀x ∈ g : f ( x ) ≤ max )
S
1

e:∈h
i, max : = e, f ( e )

S
2

f ( e ) ≥ max \ f ( e ) ≤max
\
i, max : = e, f ( e ) SKIP

4thConditional Maximum Search


φ ( g, 1, i, max ) = ( 1 = ∃x ∈ g : β ( x ) ∧

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 124/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

12.4. BONYOLULAR TASKS 149

l → ( i ∈ ∧ g ∩ ⌈β⌉ max = f ( i ) ∧ g ∀x ∈ ∩ ⌈β⌉ : f ( x ) ≤ max ))


S
1

l : = false

S
2

\ ¬β ( e ) \ β ( e ) ∧¬l \ β(e)∧l
\ f ( e ) ≥max \ f ( e ) ≤max
SKIP l, i, max : = i, max : = SKIP
true, e, f ( e ) e, f ( e )

5th"Linear Search"
In this case
φ ( g, l, e ) = ( l = ∃x ∈ g : β ( x ) ∧
L → ( e ∈ G ∧ β ( e )))
and the cycle condition is reminiscent. Now h = ∅ ∧ ¬l is the preferred choice, since
P ∧ ( h = ∅ ∨ l ) was also from R .
S
1

l : = false

S
2

l:=β(e)

Note: This item can be considered as equivalent to linear search 2.8, with that
with the exception that we can not talk about the first β -element since it is not
we assumed the order of the set.

12.4. More complicated tasks


In this section, we will outline some of the less simple items that are primarily to be made
let's show that it is possible to use the derivation for more complex tasks, and on the other hand
the items thus obtained are quite important.

12.4.1. Logarithmic search


Let H be a set that is interpreted as a sorting relation. Let f :
Z → H is a monotone increment function. It is a function to determine the function f ,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 125/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

150 12. PROGRAMMING ITEMS (DESIGN)

if the given [ m..n ] ⊂ Z interval adds the given value h ∈ H , and if so, then
enter a point of the interval where the function value is h .
A=Z×Z×H×Z×L
mnhil
B=Z×Z×H
' ' '
m n h
' ' '
Q : ( m = m ∧ n = n ∧ h = h ∧ m ≤ n + 1 ∧ ∀k, j ∈ [ m..n ]:
( K <j ) → ( f ( k ) ≤ f ( j )))
R ( Q ∧ L = ( ∃j ∈ [ m..n ]: f ( j ) = h ) ∧ → l ( i ∈ [ m..n ] ∧ f ( i ) = h ))
Using monotony, the interval is narrowed from both ends of the inva-
Rians:
P = ( Q ∧ [ u..v ] ⊆ [ m..n ] ∧ ∀j ∈ [ m..n ] \ [ u..v ]: f ( j ) = h ∧
L → ( i ∈ [ u..v ] ∧ f ( i ) = h ))
At:
'
1) Q = ( Q ∧ u = m ∧ v = n ∧ l = false )
2) π = ¬l ∧ u ≤ v

3) Informally speaking select is the number of components will be assessed. This


you can specify a case separation:
{
v - u + 1 , if ¬l ;
t=
0, if l.

4) The cycle core should be a sequence with an intermediate condition:


'
Q = ( Q ∧ [ u..v ] ⊆ [ m..n ] ∧ ∀j ∈ [ m..n ] \ [ u..v ]: f ( j ) = h ∧
¬l ∧ ( i ∈ [ u..v ]))
At this point, the first half of the sequence could be: ∈i [ u..v ] value selection.
However, taking into account efficacy considerations,
the central element of the river: i : = ⌈ ( u + v ) / 2 ⌉ . The second half of the cycle core is three
case is possible:

- f ( i ) <h : then the value u : = i + 1 holds the invariant;


- f ( i ) = h : then we found the searched element, so l : = true ;
- f ( i ) > h : then the v : = i - 1 assignment holds the invariant.

5) It is easy to check that all three branches of the above branch reduce the
terminálófüggvényt.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 126/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

12.4. BONYOLULAR TASKS 151

Item: Solution of the following program in the form of a structure, as described above:
fictitious task:
Q
u, v, l : = m, n, ↓
'
Q ¬l ∧ u ≤ v
P∧π∧t = t
i:=⌈(u+v)/2⌉ ''
0

\ f ( i ) <h \f(i)=h \f(i)>h Q

in : = i + 1 l:=↑ v:=i-1
R P ∧t <t
0

12.4.2. Backward search


Let N ∈ N and N> 1. Let U ( i ∈ [1 .. N ]) be arbitrary finite at least
i
denoted sets (1 <σ = | U | <∞ ). U = U × · · · × U .
Let ρ : U → L be divisible ρ : U → L ( i ∈ [0 .. N ])
i i 1 N

i
as follows:

1. ρ = true ;
0

∀i ∈ [0 .. N - 1]: ∀u ∈ U : ρ and +1 ( u ) → ρ ( u );
Second
i

∀i ∈ [1 ..N ] ∀u, v ∈ U : ( ∀j ∈ [1 ..I ]: u = v ) → ρ ( u ) = ρ ( v );


Third
j j i i

4. ρ = ρ .
N

The task is to determine if there exists an element U in which ρ is satisfied


condition, and if so, add such an element.
A=U×L
ul
B = {X}
Q : That's right
R ( l = ∃v ∈ U : ρ ( v ) ∧ → l ( u ∈ ∧ U ρ ( u )))

Count U elements in the following way. The elements of each U set


i
move from zero to σ - 1. Then U has every u element ( i , ..., i )
i 1 N
arranged N , to which u = ( u 1 , ..., u N ) Where 0 ≤ i <σ . . . , 0 ≤ i <σ . E
i i 1 1 N N
megszámozás a lexicographical ordering defined U n.
Let N = [ 0..σ - 1] × · · · × [0 ..σ - 1]. Then the above number is one
1 N
establishing a bijection N and U between. Mark this N → U mapping φ .
Note that elements of the N set can be considered as a mixed-based numeric system,
as well. Based on this, a numeric value of ν ∈ NN :

152 12. PROGRAMMING ITEMS (DESIGN)

Σ
f(ν) =ν ·Ω , where:
i i
i=1
Π
Ω = σ ( i ∈ [ 1..N ]) .
i j

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 127/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
j = i +1
With the introduced markings, the task is redefined and is now required
let us also say that if there is an element with a sought-after property, then the first one is given
at:
A=N×L
ν l
B = {X}
Q : That's right
R : ( l = ∃μ ∈ N : ρ ( φ ( μ )) ∧
l → ( ρ ( φ ( ν )) ∧ ∀μ ∈ N : f ( μ ) <f ( ν ) → ¬ρ ( φ ( μ ))))
If we do not use the special properties of ρ , then the above can be solved
with linear search, the [0 .. | N | - 1] interval. Let's look at how to use
we have the specialty of ρ ! Namely, the ρ 3 . for its property, if ρ ( φ ( ν ))
' i
true, ρ i +1 ( φ ( ν )) is false, then every ν ∈ N with the first ' i + 1
component equal to ν first i + 1 component of ρ i + 1 ( φ ( ν )) will be false.
Let ε = (0 ,... 0) ∈ N and ∀i ∈ [1 ..N ]: ε ∈ N such that ∀j ∈ [1 ..N ] \
{i} : ε j = 0 and εi = 1. It is evident that f ( ε ) = 0, f ( ε ) = 1 ∀j ∈ [1 ..N ]:
0 i

i i 0 F
f(ε )=Ω .
i i
Add ν with an "overflow bit" with 1 value indicating that ν
its value can no longer be increased.
Extend the function f as follows:
f:{0,1}×N→N ,
0

Σ
f(ν ,ν) =ν *Ω +ν ·Ω , where:
0 0 0 i i
i=1
Π
Ω =σ .
0 j
j=1

Using these markings, we define the action of adding two N elements


between.
' ' '' ' ' '' '' '
ν + ν = ν ⇐⇒ f ( ν ) + f ( ν ) = f ( ν , ν )
0
Now we can formulate a simple, but important statement to exploit,
we will use ρ specialty during the solution .

12.4. BONYOLULAR TASKS 153

12.1. statement: Let ν ∈ N , for some i ∈ [1 ..N ] ¬ρ ( φ ( ν )) and ∀j ∈ [ i +


1 .. N ]: ν = 0. Then for ∀μ , which is greater than ν and less than ν + ε ,
i

j i
¬ρ ( φ ( μ )).
i

The following is a mixed number based number system type


two types of operations are defined, taking into account the above statement.
Increase the first operation ν by ε .
m
The =N×N ×{0,1}
increase 0
ν mν
0
B =N×N
increases ' 0 '
ν m
' ' ' '
Q : ( ν = ν ∧ m = m ∧ m ∈ [1 ..N ] ∧ ∀i ∈ [ m + 1 ..N ]: ν = 0)
increase ' ' i
R : (( ν , ν ) = ν + ε ' ∧ m ∈ [0 ..m ] ∧
increases
∀i ∈0 [ m + 1 .. N ]:m ν = 0 ∧ ν = 0)
i m

The solution is a cycle whose invariant property is:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 128/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
' '
' ∧ m ∈ [0 ..m ] ∧
'
P : (∀fi (∈ν[)m+ +ν 1 *..N
Q ]: =
ν f =( ν0 ∧) ∀
+ iQ∈ [1 ..m - 1]: ν = ν i)
increases 0 m m
Cyclic condition: ν = 0 ∧ m = 0, and the terminating function is ν + m .
i i

0 0
Then the solver program:
increase ( ν , ν, m )
0

ν :=1
0
ν =0∧m=0
0

\ ν =σ -1 /
m m
m, ν : = m - 1 , 0 ν ,ν :=0,ν +1
m 0 m m

We also define the other operation, which, besides ρ ( φ ( ν )), decides the
also gives the smallest index for which ρ ( φ ( ν )) is false.
i

The =N×N ×L
search 0
ν ml
B=N×N
Search ' 0
m
ν
' ' '
Q : ( ν = ν ∧ m = m ∧ m ∈ [1 ..N ] ∧ ρ '- 1( φ ( ν )))
searching ' m
R is a
search for
∧ l =' ρ ( φ ( ν )) ∧
:(ν=ν
¬l → ( m ∈ [ m ..N ] ∧ ρ m 1 ( φ ( ν )) ∧ ¬ρ ( φ ( ν )) ∧
m
l→m=N)
The derivation of this task is almost the same as the linear search.

154 12. PROGRAMMING ITEMS (DESIGN)

looking for ( ν, m, l )

m, l : = m - 1 , true
l∧ m = N
l : = ρ m + 1 ( φ ( ν ))
m:=m+1

Note that the last line of the post-condition in our case is superfluous, but the back-
we will build on it.
With all of these, the solving program will be easy to derive. Let it be
invariant property:

P = ( ∀μ ∈ N 0 ≤ f (0 , μ ) <f ( ν , ν ) → ¬ρ ( φ ( μ )) ∧ L = ρ ( φ ( ν )) ∧
0
¬l → ( ν = 1 ∨ m ∈ [1 ..N ] ∧ ¬ρ ( φ ( ν )) ∧ ρ m 1 ( φ ( ν )) ∧
0 m
∀i ∈ [ m + 1 .. N ]: ν i = 0))

The cyclic condition and the terminating function are apparent in the following way: ¬l ∧ ν = 0
0
Π
and σ - f ( ν , ν ).
j 0
j=1
The invariant property is met by a
'
Q =(ν=ε ∧ν0=0∧
0 l = ρ ( φ ( ε )) ∧ → ¬l ( m ∈ [1 ..N ] ∧ ¬ρ ( φ ( ν )) ∧ ρ m 1 ( φ ( ν ))))
0 m
guarantees.
'

''
Q is achieved by a sequence having the intermediate property
Q = ( ν = ε ∧ ν = 0 ∧ m = 1).
0 0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 129/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'' '
selected
The Q from
met Rfollows, which
that Q in
is turn follows
, so the that
second
Q member
. Of course,of the
thesequence
sequenceof searching ( ν, m, l ) -t
the first member of ν, ν , m : =looking
looking ε , 0 , 1 is chosen.
0 0
Leading the loop core is also easy. P ∧ π , Q , so the cyclic
increases
first half lusmag increase ( ν , ν, m will) was separated from right R , in fact P -t and 12.1.
it is also true that ∀μ ∈ N
0 to increase
: 0 ≤ f (0 , μ ) <f ( ν , ν ) →
0
¬ρ ( φ ( μ )). In case ν = 1 is true, P is also satisfied. If ν = 1, then
¬l = ρ ( φ ( ν )) ∧
0 0

¬l → ( ν = 1 ∨ m ∈ [1 ..N ] ∧ ¬ρ ( φ ( ν )) ∧ ρ m 1 ( φ ( ν )) ∧
∀i ∈ [ m +0 1 .. N ]: ν i = 0) m

must ensure the fulfillment, but for R longer enough, and to be true
looking
after looking for ( ν, m, l ) because Q true.
search was
Since increasing ( ν , ν, m ) obviously reduces the termination function value, the following
0
solution to the task:

12.4. BONYOLULAR TASKS 155

ν, ν , m : = ε , 0 , 1
0 0
looking for ( ν, m, l )
¬l ∧ ν = 0
0
increase ( ν , ν, m )
0

\ ν =0 /
0

looking for ( ν, m, l )SKIP

12.4.3. Backward counting


As with the step-by-step search, several algorithm-
such as backward counting.

A=N×N
0
ν d
B = {X}
Q : That's right
( )
Σ
R:d= ρ ( φ ( μ ))
μ∈ N
Solving this problem will now be a cycle that is invariant
Σ
P=(d= ρ ( φ ( μ )) ∧
μ<(ν ,ν)
( Ν = 1 ∨ m ∈ [1 ..N ] ∧ ρ m 1 ( φ ( ν )) ∧ ∀i ∈ [ m + 1 ..N ]: ν = 0)) .
0

0 i
The second row of invariants guarantees the 12.1. applicability of the claim. Now it is
invariant fulfillment can be achieved by a simultaneous assignment: ν, ν , m, d : = ε , 0 , 1 , 0.
0 0
The cycle condition is ν = 0. The termination function is the same as the step back
0
search.
From the invariant property, Q ( looks for , so after searching ( ν, m, l ) )
Σ Σ
R is true. If ¬l , then ρ ( φ ( μ )) = ρ ( φ ( μ )).
looking for
( μ<(ν ,ν) μ ≤ )( ν , ν )
0 0
Σ Σ
otherwise ρ ( φ ( μ )) + 1 = ρ ( φ ( μ ))
μ<(ν ,ν) μ≤(ν ,ν)
0 0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 130/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

and Finally,
reducesthe
theincrement ( νterminating
value of the 0
, ν, m ) retains the invariant
function. We note property in Figure
that we used 12.1. because of the claim,
it here,
the search task ρ ( φ ( ν determined event))), we have m value.

156 12. PROGRAMMING ITEMS (DESIGN)

ν, ν , m, d : = ε , 0 , 1 , 0
0 0
ν =0
0
looking for ( ν, m, l )
l
\ /
d:=d+1 SKIP
increase ( ν , ν, m )
0

12.5. Calculation of function value


Hereinafter, the calculation of the substitution value of certain special functions
we will deal with it. Suppose we have a function f : X → Y where X is
and Y are arbitrary sets. The job specification is therefore:
A=X×Y
xy
B=X
'
x
'
Q:(x=x )
'
R : ( y = f ( x ))
Of course, the solution of y : = f ( x ) assignment to the task. If that is the assignment
is not allowed, and nothing else is known about the function, then a
we can not say anything about creating a solving program either. Therefore,
we will use more assumptions.

12.5.1. Calculation of a Function with Function Composition


Suppose f = h ◦ g , where g : X → Z and h : Z → Y functions.
Then the solution of the problem will be a sequence. We extend the status space to one
with a new ( Z- type) component that has a variable of z . The sequence is intermediate
condition
' '
Q : ( z = g ( x )) .
Item: Program for calculating the replacement value of a composition:

z:=g(x)
y:=h(z)

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 131/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

12.5. CALCULATION OF VALUE VALUE 157

12.5.2. Calculation of a function with a split-off function


Let π , π . . . , Π : X → L conditions, and g , g ,. . . , g : X → Y functions,
1 2 n 1 2 n
and suppose that the conditions π cover the set X. Let f :X →Ya
i
following:
g ( x ) , if π ( x );
1 1
g ( x ) , if π ( x );
f(x)= 2 2

g ( x ) , if π ( x ) .
n n

The first condition branching f fulfilled for definition. The values of y : = g ( x )


i
guarantee their second fulfillment.
Item: The program calculating the value of a function with a random separation:

π (x) π (x) \. π (x)


\ 1 \ 2 \ n

y:=g (x) y:=g (x) y:=g (x)


1 2 n

12.5.3. Calculation of a function with a recursive formula


k
Let H be an arbitrary set, k> 0 is an integer, and F : Z × H → H
function, t , t - 1 . . . , t k +1 ∈ H are fixed, and we define f ∈ Z → H partial
0
function as follows:

f(m) =t ,
0
f ( m - 1) = t - 1 ,

f ( m - k + 1) = t k +1 ;

and ∀i ≥ m :

f ( i + 1) = F ( i + 1 , f ( i ) , ..., f ( i - k + 1)) .

Task is to determine the f function n ≥ m accepted value place.


A = Z × Z × H × H × ... × H
mnyt t -k +1
0
B = Z × Z × H × ... × H
' ' '
t '-k +1
m n t 0

Q:(m=m ∧n=n
' '
∧n≥m∧t0=t
'
0 ∧ '
··· ∧ t k +1 = t -k + 1)
R :( Q ∧ y = f ( n ))

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 132/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

158 12. PROGRAMMING ITEMS (DESIGN)

This task is also part of the interval tasks discussed at the beginning of this chapter. Juice-
'
is conducted
''
in the same way. The invariant property of the cycle, Q
and Q :
P = ( Q ∧ i ∈ [ m..n ] ∧ y = f ( i ) , y - 1 = f ( i - 1) ∧ ··· ∧ y k + 1 = f ( i - k + 1) ) ,
'
Q =(Q∧i=m∧y=t ∧ y - 1 = t - 1 ∧ ··· ∧ y k + 1 = t k + 1 ) ,
' 0
Q = ( Q ∧ i + 1 ∈ [ m..n ] ∧ y = f ( i + 1) ∧ y - 1 = f ( i ) ∧ ...
∧ y k +1 = f ( i - k + 2)) .
'
The i, y, y - 1 , .., y k + 1 : = 0 , t , t - 1 , .., t k + 1 simultaneous assignment Q of Q comes into,
and P ∧ π follows from 0
''
lf ( y, y - 1 , .., y k + 1 : = D ( i + 1 , y, ..., y k +1 ) , y, .., y k + 2 ) , Q ).
By selecting n - i for the variant function , the i : = i + 1 assignment reduces it.
Item: Solve a program with the following structure for the specified task:

i, y, y - 1 , .., y k +1 : = m, t , t - 1 , .., t - +1
0
i=n
y, y - 1 , .., y k + 1 : = D ( i + 1 , y, ..., y k +1 ) , y, .., y k +2 )
i:=i+1

We note that in practice, k is very many times equal to one, so it is


in case of case, we write the solution program separately.

i, y : = m, t
0
i=n
y:=F(i+1,y)
i:=i+1

12.5.4. Function that can be processed per item


Let H and H be any set, X and Y are the following
1 2
sets that can be formatted:

X = X × ... × X ,
1 n
Y = Y × ... × Y ,
1 m

wherein ∀i ∈ [1 ..n ]: X = {x ∈ ℘ ( H ) | x | <∞}, ie F ( H ) and ∀i ∈ [1 ..m ]: Y =


{y ∈ ℘ ( H ): | y | <∞} , ie F ( H ). As can be seen from the foregoing description, X is
i 1 1 i

2 2
all the set of n contains bash which any given component of the H
1
finite subset of the set. Similarly, the Y elements are a set of m -esek,
which are finite subset of H .
2

12.5. CALCULATION OF VALUE VALUE 159

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 133/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
12.1. DEFINITION : DIFFLY DISCOVER
We say that x , x ∈ X is a fully disjunctive resolution of x ∈ X if
i) ∀i ∈ [1 ..n ]: x i = x i ∪ x i and
ii) ∀i, j ∈ [1 ..n ]: x and ∩ x j = ∅ .
Note that if X is one-dimensional, then the fully disjunctive resolution is
disjunctive resolution, but in a multidimensional case, the fully disjoint
breakdown is a much stronger condition.
12.2. DEFINITION : EARTH DEFINITION
Let f : X → Y . If every x ∈ X every x , x is completely disjointed,
packet
i) ∀i ∈ [ 1..m ]: f i ( x ) ∪ f i ( x ) = f i ( x ) and
ii) ∀i ∈ [ 1..m ]: f i ( x ) ∩ f i ( x ) = ∅ ,
then f is called element-by-process .
Example: Let H be an arbitrary set, X = X = Y = {x ∈ ℘ ( H ): | x | <∞} ,
f : X × X → Y , f (( x , x )) = x ∪ x . Then f can be processed per element, since
1 2

1 2 1 2 1 2
Consider the ( x , x ) sets an arbitrary pair ( x , x ), ( x , x completely disjoint)
1 2 1 2 1 2
resolution. Then, based on the definition of fully disjunct resolution:
x ∪x =x ,x ∪x =x
x ∩ x = ∅, x ∩ x = ∅
1 1 1 2 2 2

x ∩ x = ∅, x ∩ x = ∅
1 1 2 2

1 2 2 1

Let us now examine the two criteria for processability per element:

1. f (( x , x )) ∪ f (( x , x )) = ( X ∪ X ) ∪ ( X ∪ X ) = ( x ∪ x ) ∪ ( x ∪ x ) =
x ∪ x = f (( x , x )),
1 2 1 2 1 2 1 2 1 1 2 2

1 2 1 2

2 f (( x , x )) ∩ f (( x , x )) = ( X ∪ X ) ∩ ( X ∪ X ) = ( x ∩ x ) ∪ ( x ∩ x ) ∪
(x ∩x )∪(x ∩x )=∅.
1 2 1 2 1 2 1 2 1 1 1 2

2 1 2 2

Thus, the two-variable-union function per element can be processed.


We will use the next batch frequently to process each item
define a function.
12.1. ITEM E AIR CONDITION ITEM BY-making workability
Let X = X × ... × X , Y = Y × ... × Y , X = F ( H ) i ∈ [1 ..n ] and
Y = F ( H ), i ∈ [1 ..m ].
1 n 1 m i 1

i 2
The f : X → Y function can be processed per element ha

∀j ∈ [1 ..m ]: f ( x , ..., x ) =
j
f ( s ( e ) , ..., s ( e ))
1 n j 1 n
e∈x 1 ∪ ··· ∪x n

160 12. PROGRAMMING ITEMS (DESIGN)

and
∀a, b ∈ x 1 ∪ · · · ∪ x n , a = b :
∀j ∈ [1 ..m ] f j ( s 1 ( on ) ..., S n ( to )) ∩ f j ( s 1 ( b ) ..., S n ( b )) = ∅,
where {
∀i ∈ [1 ..n ]: s i ( e ) = ∅{E} if e ∈ x ,
if e ∈ x .
i

Proof: The theorem simply follows from the fact that if x , x is completely disjoint up-
break down to x , then

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 134/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
(X
1
∪···∪xn)∪(X1∪···∪xn)=X1∪···∪xn
and
(X
1
∪ · · · ∪ x N ) ∩ ( x 1 ∪ · · · ∪ x n ) = ∅.

Here is the substitution value of the functions that can be processed per element
will be dealt with.
Before we begin to specify and solve the problem, we will introduce two
the partial assignment of sets that are then solved by the solver-
we are considered primitive.

• Let H be an arbitrary set and define f ~



:∈F(H)×H→F(H)
partial function:

f ~ ( h, e ) = h ∪ {e}, if e ∈ h.

• Use the same marking even if f ~



∈ F ( H ) × F ( H ) → F ( H ) and
f ∪~ ( h, g ) = h ∪ g, where h ∩ g = ∅.

• Similarly, it is H, an arbitrary set, and define the f ∈ F ( H ) ×



H → F ( H ) partial function:

f ( h, e ) = h \ {e}, if e ∈ h.

• In this case, if f

∈ F ( H ) × F ( H ) → F ( H ) is a partial function:
f ( h, g ) = h \ g if g ⊆ h.

The h : = f ~ ( h, x ) and h : = f ≃ ( h, x ) that compute the above functions are partial



∪ x and h : = h ≃ x .

12.5. CALCULATION OF VALUE VALUE 161

Univariate single value case


First, examine the case when both X and Y are one component, i.e.
m = 1 and n = 1. Then, f assigns another set to a set.
A=X×Y
xy
B=X
'
x
'
Q:(x=x )
'
R : ( y = f ( x ))
Resolve the task with a cycle: in the invariant, let's say x
the set of elements to be processed, and the set y is the elements that have been processed
f images, ie
'
P=(y∪f(x)=f(x )∧y∩f(x)=∅).
Examine the conditions of the cycle management rule:

1) From Q in the case of the existence of y = ∅ , P is the result , so before the cycle y : = ∅
will be added.

2) The post- condition follows from the invariant f ( x ) = ∅ , but this is not a good chance

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 135/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
aHowever,
permissible
f forcondition (sinceprocessability
element-wise x = ∅ fcase
we are calculating f ( x ) it= ∅ also
). Notice
is fulfilled (a completely disjunct resolution of the empty set of empty sets).
So the cycle condition is: π = ( x = ∅ ).

3) Ha (according to the cycle condition) x is not empty, it is a terminating function


optional x is the numeral, ie t = | x | .

5) x many of you, we can reduce if you leave it in a - in it -


battery. This can be done with the partial recognition introduced: x : = x ≃ e .

4) Write down the weakest precondition for P of the above partial assignment :
'' '
Q ( y ∪ f ( x \ {e} ) = f ( x ) ∧ y ∩ f ( x \ {e} ) = ∅ ∧ e ∈ x )
It is clear that this does not follow from P ∧ π . But note that if
e is an element of x , then a fully disjunctive resolution of {e} and x \ {e} x ,
So f due processability per item:

f ( {e} ) ∪ f ( x \ {e} ) =f(x)


f ( {e} ) ∩ f ( x \ {e} ) = ∅
∪f ( {e} ) can be given as it is

162 12. PROGRAMMING ITEMS (DESIGN)

' '
∪ f ( {e} ) , Q ) = ( y∪f ( {e} ) ∪f ( x \ {e} ) = f ( x ) ∧ ( y∪f ( {e} )) ∩
f ( x \ {e} ) = ∅ ∧ e ∈ x ).
Compared to this condition, P ∧ π shows that only the e ∈ x statement is required
fulfill. This can be done with the value selection e : ∈ x , of which
the weakest prerequisite for the statement above is P ∧ π .

Item: Then solve the following program for the specified task:
Q
'
y:=∅ P∧π∧
Q x=∅ t=t
0

e:∈x
'' '
Q
''
∪ f ( {e} ) Q
x:=x≃e P ∧
R t <t
0
Proof: The item follows from the above derivation.

Two-variable single value case


Let f be : X × Y → Z ( X, Y, Z ⊆ F ( H )).
A=X×Y×Z
xyz
B=X×Y
' '
x y
' '
Q:(x=x ∧y=y )
' '
R : ( z = f ( x , y ))
Item: Then solve the following program for the specified task:

z:=∅
x = ∅∨y = ∅
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 136/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

e:∈(x∪y)
\ e∈x∧e∈y \ e∈x∧e∈y \e ∈x∧e∈y
∪ f ( {e}, ∅ ) ∪ f ( {e}, {e} ) ∪ f ( ∅, {e} )
x:=x≃e x:=x≃e y:=y≃e
y:=y≃e
Proof: The theorem can be inferred from the one-variable case if it is invariant
attribute the following statement:

12.5. CALCULATION OF VALUE VALUE 163

', '
P = ( z ∪ f ( x, y ) = f ( x y ) ∧ f ∩ z ( x, y ) = ∅ ∧
' '
(X \x)∩y=∅∧(y \y)∩x=∅),
and terminating function t = | x ∪ y | is selected.

One-variable divalent case


Let f : X → Y × Z ( X, Y, Z ⊆ M ( H ) , f : X → Y, f : X → Z, f = ( f , f ))
1 2 1 2
function that can be processed per element.
A=X×Y×Z
xyz
B=X
'
x
'
Q:(x=x )
' '
R : ( y = f ( x ) ∧ z = f ( x ))
1 2
Item: Then solve the following program for the specified task:

y, z : = ∅, ∅
x=∅
e:∈x
∪ f 2 ( {e} )
x:=x≃e
Proof: The derivation of the theorem from the monovalent case is only thequality
invariant
is different:
'
P(y∪f (x)=f (x )∧y∩F (x)=∅∧
1 1 ' 1
z∪f (x)=f (x )∧z∩F (x)=∅)
2 2 2
The termination function remains and the steps of the derivation are the same.

General version
Let n, m record natural numbers, f : X × ··· × X → Y × ··· ×
Y ( X , Y ∈ F ( H ) , ( i ∈ [1 ..n ] , j ∈ [1 ..m ])) is a function that can be processed per element,
1 n 1

and are the f : X × × · · · X → Y ( j ∈ [1 ..m ]) functions of f of components


m i j

j 1 n j
, ie f = ( f , ..., f ).
1 m

A = X × ... × X × Y × ... × Y
1 n 1 m
x x y y
1 n 1 m
B = X × ... × X
1 ' n 'n
x1 x

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 137/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

164 12. PROGRAMMING ITEMS (DESIGN)

Q:(x =x
'

··· ∧x = x )
1
'n

1 n'n ' ' 'n


1, 1,
R ( y = f ( x ..., x ) ∧ ··· ∧ y = f ( x ..., x ))
1 1 m m
Item: Then solve the following program for the specified task:

y , ..., y : = ∅, ..., ∅
1 m

x =∅
i=1 i


e:∈ x
i
i=1
...
\ ∀i ∈ I : e ∈ x i ∧ ∀i ∈ [1 ..n ] \ I : e ∈ x i ...
\ \
y , ..., y : =
1 m

∪ f m ( s 1 ( e ) , ..., s n ( e ))
∀i ∈ I : x i : = x i ≃ e
where I ⊆ [1 ..n ] and I = ∅ ,
{
if i ∈ I ;
∀i ∈ [1 ..n ]: s i ( e ) = {e},
∅, if i ∈ I.
n
The branches of the branches are 2 - 1.
Proof: The item has the following invariant property and terminating function
can be deduced.
' 'n
1,
P : ( ∀j ∈ [1 ..m ] ( y ∪ f ( x , ..., x ) = f ( x ..., x ) ∧
y ∩ f ( x , ..., x ) = ∅ ∧ ∀i, k ∈ [1 ..n ] ( x and \ x i ) k = ∅ ))
j j 1 n j ' ∩x

⋃j j 1 n

t= x
i
i=1

Note: The above programming betting follows that a 12.1 item


condition is not only a sufficient but necessary condition for the
zhatóságnak.

12.6. Tasks
12.1. There is a function f : Z → Z. Determine which one of the two functions is
the maximum and the minimum in the [ m..n ] interval.

12.2. Determine the largest common divisor of x and y natural numbers!


12.3. Determine the smallest common multiple x and y natural numbers.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 138/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

12.6. TASKS 165

12.4. Determine your power-without operation - the x number


n -one's power!

12.5. Determine whether the natural number k divides the natural number x .

12.6. Determine whether the natural number x is the prime number.

12.7. We have x and y vectors ( x.dom = y.dom ). Apply x + y and x - y


vectors scalar!

12.8. Determine the sum of the elements of vector x with the odd index
elements with their negatives in the summary!

12.9. There is a vector of integers and two integers. Let's figure it out
the two numbers are in the vector, and if so, which one is the first one!

12:10. An x vector containing the whole number is given. Permute elements of the vector
(locally) so that one element of the vector is in the monotone sort location
so do not prey on the bigger element, and then do not have it
less!

12:11. The quadratic matrix x is given . Determine the elements of the lower triangle
The amount!

12:12. The quadratic matrix x is given . They are mirrored (transposed)


(i.e. the result in x ).

12:13. The quadratic matrix x is given . They are mirrored (transposed) on their main antibodies locally
(ie the result in x ).

12:14. The vector x is given. Calculate the value of vector b ( b.dom ≤ x.dom )
so that the bi -factor element is the sum of the first i- piece x- element.
( )
12:15. Given the n and k numbers. Calculate it kn value!

12:16. The vector of x integers contains the digits of a decimal number


in descending order of local value. Calculate the value of the displayed number.

12:17. A natural number is given. The x integer vector to be prepared the number
digit by local value in descending order, and enter it as well
how many digits the number is!

12:18. The vector of x integers contains the digits of a decimal number


in descending order of local value. Create x in the original with one
the same figure for a larger number, or say overflow
volt!

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 139/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

166 12. PROGRAMMING ITEMS (DESIGN)

12:19. The vector of x integers contains the digits of a decimal number


in descending order of local value. Create x in the original with one
the same number of figures in a smaller number, or say if there is a underflow
volt!
12:20. The vectors x and y of the same range of interpretations are a decimated decimals of x.dom,
number of digits. On smaller indexes there are 10 higher
coefficients of powers. Apply the sum of the numbers in z vector
Determine whether an overflow has occurred!
12:21. An x vector is given, whose elements are k 2 digit numerals. adjust
produce the k- numbered system numbers of the thus-represented number in the vector y (number
higher local values are found in the lower indexed locations of the vector)!

12:22. An x vector is given, whose elements are k -s numeric numerals. adjust


2
produce the k -number- numbered digits of the thus-represented number in the vector y (a
higher local values of the number are found in the lower indexed locations of the vector)!
12:23. A vector represents an integer so that each element of the vector is a
contains a decimal number. Reduce this number to a particular
a local value 0 - - value between 9!
12:24. Determine the number of digits of the decimal number of the natural number x .
12:25. Determine the digits of the decimals of the natural number x
The amount!
12:26. A vector of integers is given. Arrange vector elements (locally)
in descending order!
12:27. The vector x and b are given such that b takes its elements from the x indices. The x vector
each b write zeros th element!
j

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 140/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 13

transformations

In this chapter, we will discuss how to programmatics


apply to specific tasks.
First, we look at a task that apparently has nothing to do with prog-
2
For example: solve the x - 5 x + 6 = 0 equation. One option is to
with some kind of thought (the relationship between radicals and coefficients or complete
( x- 3) ( x- 2) = 0, and then solve x- 3 = 0
and equations x - 2 = 0. That is, instead of the original task, two other but one-
a more robust task needs to be solved. That is exactly the essence of the derivation . This method
used in the previous chapter.
2
The other option is to solve the following general task: ax + bx +
c = 0.Confirm that if a = 0, then you have a known pattern
get it:
√ 2
-B ±
b - 4 ac
2a

Then, the item is used: wherein the replaced 1, b is replaced by - 5 and c is replaced by
Replacing 6, we get the roots. In this programming we call this method
recirculation .
The pattern of the second-order equation can often be applied not second-degree
4 2
For example,
2
if equations are solved, for example, be the equation to be solved: x - 5 x +4 =
0. Using x = y substitution ,2we get y for
2
a quadratic equation
solving only the equations x = 1 and x = 4 must be resolved. You say,
we are concerned that we have solved the task with a transformation .
Hereinafter, we will first discuss recycling.

168 13. TRANSFORMATIONS

13.1. Stemming
In the simplest case, the task to be solved and the status area of the programming items
identical, at most in the mark, and pre- and post-nomination conditions
they also agree. In this case, we get the solution program with simple assignment. This
however, the case is quite rare, with limited recourse to usability
would be limited.
However, we remind you that the solution 5.1. Definition of the task and the
the status of the program may be different; on the other hand,
that solving a more rigorous task is also a solution to the weaker task,
see Section 2.1. claim.
It follows that if the batch of the batch is stricter than the task, or
if there are components in the state of the item that are not in the task
(according to the definition of extension 4.1 the item is even stricter in this case) then a
batch program, after a possible assignment, will solve the problem. In such cases

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 141/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
let'sIfsay
thewe're back with
task status tightening
space contains .components that are not included in it
in the state of the item, such as 4.2. definition, the batch solution program has not
tastes it they are one of these variables in the pre and post condition of the task
parameter variables. Such variables are recirculation
parameters are called, and are determined by the item "specific functions".
Occasionally, the range of interpretations of a batch job is narrower than the
task to be solved, in this case we will narrow it by using a condition
interpretation range. In fact, here is a deduction step, the task
solving a branch if the condition is met, the solver program is the item program,
anyway, or any other item or derivative.

13.2. Simple program transformations


Using the following transformations, an equivalent program with the original
which is, in some ways, more advantageous to us than the original.
The criterion is basically two types. One: the transformed program is allowed
program design, while the original is not. Often occurs with recirculation
we will get an unlicensed program. Another aspect is the connection to recirculation
is that the program with recycle is often clumsy and the transformation
this will improve us.

Translating an unconditional condition from branching. Let S be ⊆A×


**
A , S = IF ( π
' '
: S , ..., π
'**
: S ), A = A × ... × A . Construct the
1 1 n n 1 m
S ⊆A ×A program as follows:
'
A = A × ... × A × L × ... × L
a1 m a l l
1 m 1 n

13.2. SIMPLE PROGRAMMING INFORMATION 169

l , ..., l : = π ( the , ..., a ) , ..., π ( in , ..., a )


1 n 1 1 m n 1 m
IF ( l : S , ..., l : S )
1 1 n n
'
Then the S program equiv S strength loss & quot The -n.
**
Coding of a non-permitted cycle condition. Let' S ⊆ A' × A'** with
,S=
DO ( π : S ) A = A × ... × . We construct S ⊆ A × A the
as follows:0 1 m

'
A = A × ... × A × L
a1 m a l
1 m

l : = π ( a , ..., and )
1 m
l
S
0
l : = π ( a , ..., and )
1 m
'
Then the S program equiv S strength loss & quot The -n.

Replacing a simultaneous assignment with simple assignments. Let S ⊆ A ×


**
A The following simultaneous assignment:
A = A × ... × A
1 m
a a
1 m
S

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 142/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
the , ..., a : = f ( the , ..., a ) , ..., f ( in , ..., a )
' ' 1 '** m 1 1 m m 1 m
We construct S ⊆A ×A as follows:
'
A = A × ... × A × A × ... × A
a1 m a 1b m b
1 m 1 m
'
S
b : = f ( a , ..., a )
1 1 1 m

b : = f ( a , ..., a )
m m 1 m
a :=b
1 1

a :=b
m m

170 13. TRANSFORMATIONS

'
Then the S program equiv S strength loss & quot The -n.

Replacing sequence sequence. If S = ( S , S ) , S = ( S , S ) and the


12 1 2 21 2 1
state components that S depends on, S does not change and vi-
1 2
weave, then S equivalents of S -gyel.
12 21

S S
12 21

S S
1 2
S S
2 1

Replacing the sequence of a sequence of cyclic nuclei. Let S = DO ( π : S ),


0
S = ( i : = i + 1; S ) and suppose that i is constant in S . Also be
'0 01 01
S = ( S 01 and ← and +1 ; i : = i + 1).
'
S S
π π
i:=i+1 S 01
i ← and +1

S i:=i+1
01

'
Then S equals S .

**
Replace a function with a variable. Let S ⊆ A × A , A = A × ... × A , and
Let f be an A 1 × ... × A
k
a function defined above a subset,
1 the mvalue set of which
i i
H . Suppose further that the 1 , ..., and variables are constants in S and make
k
' ' '** isi performed i
the program S ⊆A ×A as follows:
'
A = A × ... × A × H
a1 m a z
1 m

z : = f ( a 1 , ..., and
k
)
i i

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 143/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
←z
' S f ( a i 1 , ..., and ik )
Then S eq S strength loss & quot The -n.

Replace a recursively defined function. Let H be an arbitrary set,


k
k> 0egyegészszám and F : Z × H → H function, t , t - 1 , ..., t k +1 ∈H
0

13.3. TÍPUSTRANSZFORMÁCIÓK 171

and define the partial function f ∈ Z → H as follows:


f(m) =t ,
0
f ( m - 1) = t - 1 ,

f ( m - k + 1) = t -k +1 ,
and ∀i ≥ m :
f ( i + 1) = F ( i + 1 , f ( i ) , ..., f ( i - k + 1)) .
Consider the following S program:

i:=m
S
1
π
S
0
i:=i+1

where i and S in both S in the constant, S in reference to f ( i + 1.)


value, S in a maximum of f ( i ) and to π = i = n ( ∧ ... ). Then S is equivalent to
0 1 0

1
with the following program:

i, z, z - 1 , .., z k +1 : = m, t , t - 1 , .., t - +1
0
S
1
π
z, z - 1 , .., z k + 1 : = D ( i + 1 , f ( i ) , ..., f ( i - k + 1)) , z, .., z -k + 2
f ( i +1) ← z
S
0
i:=i+1
In each case, it is easy to see the identity of the program functions.

13.3. Típustranszformációk
Type transformation can be talked about when certain components of the state space
we are replacing something with a related type.
Programming Items - and in general (pairing, solving) pairs -
can be generalized through the transformations presented below if
the transformation between the status spaces is actually a type transformation. That's it
Figure 1 shows a simple program to solve a program
can be transferred to a related type.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 144/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

172 13. TRANSFORMATIONS

function pile

depending on type series

vector input file

13.1. figure. Relationships between types

Transcription of programming items to other types. The following schemes are programming
substitutions for transformation of items between types are defined.
The transformation is done by the second type of operation of the first type
(in the same line).
Let's start with the functions interpreted in the interval. It is for the type of function
transition does not necessarily require transformation, since f : f unc (Z , H ) is one
[ function of the function Z → H on the lob ( f ) ..hib ( f )] interval . If you have a program
This is where the function is fixed - our sets are the same - then it is also a vector
We were transformed.

• A function defined over interval over a series

The s : seq ( H ) sequence can be considered as the [1 ..dom ( s )] interval


Z → H , but there is no indexing in the operations. Therefore
not all of our programs can be written in series. Suppose a program-
we always refer to f ( i + 1) where f is within the interval [ m..n ]
interpreted function. The first reference is i : = m - 1 and then
except for i : = i + 1, i is a constant in all other programs . If
these conditions are met, then the following invariant property-
pany: s = <f ( i + 1) ,. . . , f ( n ) > . That is, by substituting transformation
we can program:

i:=m-1
i=n a.dom = 0
f ( i + 1) f ( a.lov )
i:=i+1 a : lorem

Example (Batch Count):

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 145/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

13.3. TÍPUSTRANSZFORMÁCIÓK 173

k, d : = m - 1 , 0 d:=0
k=n a.dom = 0
β ( k + 1) β ( a.lov )
\ / \ /
d:=d+1 SKIP d:=d+1 SKIP
k:=k+1 a : lorem

• From sequential to sequential input file ( dx, x : lopop or sy, dy, y : read )

Matching between the two types: if the series is not empty then it is the same
with loext ( x, dx ) and loext ( y, dy ) sequences, while in the empty sequence the x and y
sequences.

dx, x : fin eye, two, y : read


a.lov dx dy
a : lorem dx, x : fin eye, two, y : read
a.dom = 0 dx = extr sy = norm

The program transformed an extra lopop (or read begins) operation,


so this transformation is called a forward- reading technique .

Example (Batch Count):

eye, two, y : read


d:=0 d:=0
a.dom = 0 sy = norm
β ( a.lov ) \ β ( two ) /
\ /
d:=d+1 SKIP d:=d+1 SKIP
a : lorem eye, two, y : read

• From set to set (for an input set / series)

The matching between the two types: the a and b series members list the x and y
sets of elements.

174 13. TRANSFORMATIONS

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 146/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

y:=∅ b : = <>
x=∅ a.dom = 0
e:∈x
e a.lov
∪ b : hiext
x≃ a : lorem

The above correspondence can also be applied to the processing per element,
assuming the f function is to set a single set for a single-element set,
of it. This is relatively rarely met, however, it is very common for that
the most unique element of the image. In this case b : hiext is replaced by a branching,
IF ( d = ∅ : SKIP, d = ∅ : ( b : hiext ( d ))).
Note that instead of e : ∈ x , you can write e : = a.lov ,
which is also a tightening of the original value selection.
Example (single-variable monospaced processing):

y:=∅ b : = <>
x=∅ a.dom = 0
e:∈x b : hiext ( f ( {a.lov} ))
∪ f ( {e} ) a : lorem
x:=x≃e
Using the pre-reading technique discussed above, you can get the
sequential file.
Example (single-variable monospaced processing):
sx, dx, x : read
b : = <> b : = <>
a.dom = 0 sx = norm
e : = a.lov e : = dx
b : hiext ( f ( {e} )) b : hiext ( f ( {e} ))
a : lorem sx, dx, x : read

• From series to vector


Transformation is impeded by the fact that the vector is not interpreted
we can change it. This problem can be easily handled by input series

13.3. TÍPUSTRANSZFORMÁCIÓK 175

but for the output series, the transformation can only be


if we assume that the number of elements in a series does not exceed the vector
the numeracy of its interpretation range.

Let x ( y ) be the pair ( u, i ) (or ( v, j )), where u, v


vectors and i, j nonnegative integers, such that i is x (or j is y )
Number of series elements and the elements of the u vector u . . . U u.lob + i- 1 (yl
u.lob
letve the v vector v . . . , v v.lob + i- 1 ).
v.lob

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 147/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
x.dom = 0 i=0
x.lov in u.lob + i- 1
x : lorem i:=i-1
y : hiext ( d ) v jb + j , j : = d, j + 1
y : = <> j:=0

Example (single-variable monospaced processing):

y : = <> j:=0
x.dom = 0 i=0
y : hiext ( f ( {x.lov} )) v v.lob + j , j : = f ( {u u.lob + i- 1 } ) , j + 1
x : lorem i:=i-1

• From sets to sets

Two (multiple) input sets between the discussed items are the two (more) variable ele-
in case of processing per week. The two-variable processing per
you may need to decide which one item is
it is in series. Therefore, we assume that the sequences are increasing
because the first element of both series is the smallest and if any of these
the smaller ones are chosen, the content can be easily decided. otherwise
the rest of the transformation is the same as in the one-variable case (here too
it is necessary for the function value to be up to one component). Naturally
the choice of the element can be omitted here as the loving operation is always the sequence
returns the same element.

176 13. TRANSFORMATIONS

c : = <>
a.dom = 0 ∨ b.dom = 0
( a.dom = 0 ∧ b.dom = 0 ∧ ( a.dom = 0 ∧ b.dom = 0 ∧ a.dom = 0 ∧ b.dom = 0 ∧
\ a.lov <b.lov ) ∨b.dom = 0 \ a.lov> b.lov ) ∨a.dom = 0 a.lov = b.lov
\
c : hiext ( f ( {a.lov}, ∅ )) c : hiext ( f ( ∅, {b.lov} )) c : hiext ( f ( {a.lov},
a : lorem b : lorem {b.lov} ))

a : lorem
b : lorem

For the sake of completeness, we will present the version of the sequential files
, using the forwarding technique:

sx, dx, x : read


eye, two, y : read
c : = <>
sx = norm ∨ sy = norm
sy = abnorm∨ sx = abnorm∨ sx = sy∧
\ sx = sy∧dx <two \ sx = sy∧dx> two dx = dy
\

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 148/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
c : hiext ( f ( {dx}, ∅ )) c : hiext ( f ( ∅, {dy} )) c : hiext ( f ( {dx}, {dy} ))
sx, dx, x : read eye, two, y : read sx, dx, x : read
eye, two, y : read

Note that we could write in the terms sx = norm ∧ sy = norm


instead of sx = sy , because the cycle condition does not allow both of them to be abnormal .

13.4. State space transformation


Below is an example of state space transformation
not a simple type transformation. The task will be solved by
instead of a sheet space, we choose a new (abstract) state space,
then the actions in the solution are implemented in the original space.

13.4.1. Sequential matching


When solving a task, we often face the problem of having a separate task,
we need to describe the relationship between values in various types of values
values should be compared. This is most common when something happens
state space transformation, and we must provide the original and the abstract space

13.4. STATE-SPACE TRANSFORMATION 177

. The formal granting of such correspondence is generally insufficient,


hézkes. Using the proper concept of sequencing, however, these
even easier to write.
Let E , E ,. . . , E elementary types. Be
1 2 n


E = E and F = {E , E , ..., E }.
i 1 2 n
i=1

Suppose that the representational function of type T is true for the following constraint
many:

*
• ρ≡E × T ,

• ρ mutually clear (bijective),

• ρ permissible type construction (ie direct, union and iterated construct)


of the European Union).

Furthermore, let B = {B , B ,. . . , B } is the so-called base set where B ( i =


1 ,. . . , m ) any type of set of values. Then t ∈ T is related to base B
1 2 m i

Sequential equivalent:

<T>, if T ∈ B ;
<> , if T ∈ B ∧ T ∈ F ;
seq ( t | B ) = R ( t | B ) , if T ∈ B ∧ T ∈ F and T record;
E ( T | B ) , where T B ∈ ∈ F ∧ T and T union;
S ( t | B ) , if T ∈ B ∧ T ∈ F and T series ,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 149/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

where

R ( t | B ) = con ( seq ( ts | B ) , ..., seq ( ts | B ));


1 k
E ( t | B ) = seq ( φ - 1u ( t ) | B );
S ( t | B ) = con ( seq ( t | B ) , ..., seq ( t dom ( t ) | B )) .
1

To simplify the markup, if the base is single, then it is instead of the base set
element can be written, i.e., B = {B } case
1

seq ( t | B ) :: = seq ( t | B ) .
1

178 13. TRANSFORMATIONS

Consider the following example:

T = seq ( R ) ,
R = ( name : N EV, ul : SZU L ) ,
NAME = seq ( CHAR ) ,
parent = ( location : LOCATION, time : DAT UM ) ,
PLACE = seq ( CHAR ) ,
DATE = ( EV : EV, ho : HO, day : N AP ) ,
YEAR = N ,
0
MONTH=N ,
0
DAY =N .
0

Let M = {CHAR, N, } , t ∈ T . At
0

seq ( t | EV EV ) a series of parts of name series t series records


*
( ∈ N EV );
seq ( t | CHAR ) the name of part of the t series records and birth
place it in a row
string;
seq ( t | {HELY, EV} ) the t series records are place of birth and year
sequentially stacked
*
( ∈ ( HELY ∪ EV ) );
seq ( seq ( t | EV EV ) | CHAR ) is formed from the names of t series records
string;
seq ( t | Z) empty series.

13.4.2. Example of state space transformation


Suppose we have a single-character sequential file that is a text
contain. The task is to calculate how many of the letters are in the letter
in the text whose length is greater than a given value k !
So at first glance, the task can not be traced back to any known programming
nor to batch. The task is therefore transformed by introducing a new state-
space. Suppose we have a file instead of the text file in which words -
a series of letters and separating parts - a series of non-letter characters
- they are. That is, the original state of space:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 150/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
A = X × N , X = file ( CH ) ,
x d

13.4. STATE-SPACE TRANSFORMATION 179

and the new state of play:


'
A =F × N , F = file ( WORD, ELVR ) ,
f d
+ +
WORD = seq ( letters ) , a pre = seq ( NBETU˝ ) ,
where BETU is the letter and NBETU is the set of non-letter characters. The F is still
we also write an invariant property. There can be no two consecutive elements
same, that is
I ( z ) = ( ∀i ∈ [ 1..dom ( z ) - 1]: z .SZÓ = z i +1 .SZÓ ) .
f i

What is the relationship between the two state spaces? Of course, x and f are the same,
of the characters, and their order is the same. That is what it is
seq ( x | {BETU, NBETU˝} ) = seq ( f | {BETU, NBETU˝} ) .

Now we can say that we want to define the lengths of words,


but no separating parts are needed, so they are discarded.
''
A =G × N , G = file ( WORD ) ,
g d
and the relationship between f and g
seq ( f | {SZÓ} ) = seq ( g | {SZÓ} ) .
Because we do not need words, but only their length, then
we transform the state space.
'' '
A =H × N H = file (N)
h d
and the relationship between g and h
dom ( h ) = dom ( g ) and ∀i ∈ [1 ..dom ( g )]: h = dom ( g ) .
i i

So the job specification is:


A=H×N
hd
B=H
'
h
'
Q:(h=h )
Σ
R :( d = χ ( h > k ))
i
i=1
This task can be traced back to the sequential file
tozatára:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 151/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

180 13. TRANSFORMATIONS

open ( h )
sh, dh, h : read
d:=0
sh = norm
dh> k
\ /
d:=d+1 SKIP
sh, dh, h : read
It is also back to the abstract open and read operations.
The abstract h file has exactly the same element if it is in the original x file
even character. This is why an open operation is needed to
provide the invariant property required at the beginning of the read operation: or sx = abnorm
or dx contains the first character of the next word. This invariant property
in the read operation, it is easy to decide if there is any return value,
or the abstract file has already been emptied.
This is usually the technique of managing abstract files: an open operation
we provide the required invariant property at the beginning of the read ,
that the read operation keeps this invariant property. The abstract read
always a branch in accordance with the read definition.
Let's look at the realization of abstract operations in the original state:
as well as the simple applications of programming items:

open ( h )

sx, dx, x : read


sx = norm ∧ dx ∈ NBETU
sx, dx, x : read

sh, dh, h : read

\ sx = norm /
sh : = norm sh : = abnorm
dh : = 0
sx = norm ∧ dx ∈ NBETU
dh : = dh + 1
sx, dx, x : read
sx = norm ∧ dx ∈ NBETU
sx, dx, x : read

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 152/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

13.5. PROGRAMINVERZIÓ 181

13.5. Programinverzió
13.5.1. One-Variable Case
Let C , D , E and F be any type. Let X = seq ( E ) and Y =
seq ( F ) and f : C → X , f : X → Y and f : Y → D functions.
1 2 3
Consider the task specified below:
A=C×D
c d
B=C
'
c
'
Q:(c=c )
'
R : ( d = f ◦ f ◦ f ( c ))
3 2 1

Suppose the program calculating the value of f is in the following form


1
can be written:
A=C×X
c x
B=C
'
c
'
Q:(c=c )
'
R : ( x = f ( c ))
1

S (c)
11
x : = <>
π
S ( c, e )
12
x : hiext ( e )
S (c)
13

If the execution of programs S , S and S not changed by the variable x


11 12 13 is
, then the above program is called a program that produces elements per element .
Similarly, suppose the program calculating the value of function f is
3
the following form:
A=Y×D
y d
B=Y
'
y

182 13. TRANSFORMATIONS

'
Q:(y=y )

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 153/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'
R : ( d = f ( y ))
3 S (d)
31
y.dom = 0
S ( d, y.lov )
32
y : lorem
S (d)
33

If the execution of programs S , S and S does not change the variable y


31 32 33
, then the above program is called a user program per element .
Let us suppose that function f can be processed per element and min-
2
For a single set of elements, the function value is one element. This is the function of the function
on the basis of the programming item for calculating the substitution
it can be solved by the above element, by processing one element and by the same
as the sequencer of a user program presented per element.
However, a more effective solution to the problem is the following
program transformation, called a program version. The middle two
we omit the series type and we combine the three cycles as follows:

S (a)
11

S (d)
31
π
S ( a, e )
12

ε : = f ( {e} )
2

S ( d, ε )
32
S (a)
13

S (d)
33

13.5.2. Two-Variable Case


1 2
Let A , A , B , C and
1
D be any 1type. Let X2 = seq 2( B ) and
Y = seq ( C ) and f 1 :A → X , f 1 : A → X , f 2 : X × X → Y and
f : Y → D functions.
3
Consider the task specified below:
1 2
A=A ×1
A ×2 D
a a d

13.5. PROGRAMINVERZIÓ 183

1 2
B=A ×A
a 1' a 2'

1 2
Q : ( a = a 1'∧ a = a 2')
1
R : ( d = f ◦ f ( f 1 ( a 1 ' ) , 1f 2 ( a 2 ' )))
3 2

1
1 and 1 function calculator element production programs
Let f
the following:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 154/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
11
1 1 11
2 2
S1 ( a ) S2 ( a )
x : = <> x : = <>
1 2
π π
1 1 1 2 2 2
S 12 ( The , e ) S 12 ( a , e )
1 1 2 2
x : hiext ( e ) x : hiext ( e )
1 1 2 2
S 13 ( a ) S 13 ( a )

1 2
and suppose that the produced x and x series are arranged.

Let f , as before, depend on the prgram calculated per element,


3
prescription. Suppose f processed for a bivalent, monovalent element
2 can be
function for all pairs of members with up to one element
contain a single set of elements.

This is the calculation of the substitution value of the function composition


based on the programming item, the task can be solved by producing the above two elements, a
binary processing, a value of each element and f -at calculation for each item up
3
as a sequencing program. In this case, they can also be compiled into a
the above programs?

The answer is of course: yes, but the solution here is not as simple as it is
one-way case. The problem is analogous to the sequential files:
2 1
1, 1 ) each element is supplied in the same way,
the battery producing program ( Sor S
as if reading from a file: you can only look at the next item if it is down-
1 2
generáltatjuk. This suggests a solution to the x and x series
abstract files for each item processing. The prog-
ram does not cause any problems, it does the same as in the univariate case.

184 13. TRANSFORMATIONS

1 2
open ( x ) , open ( x )
1 1 1 2 2 2
sx , dx , x : read, sx , dx , x : read
S (d)
31
1 2
sx = norm ∨ sx = norm
2 1 2 1 2 1 1 2
sx = abnorm ∨ ( sx = sx sx = sx sx = abnorm ∨ ( sx = sx
1 2 1 2 1 2
\ ∧ dx <dx ) \ ∧ dx = dx \ ∧ dx > dx )
1 1 2 2
e : = f ( {dx }, ∅ ) e : = f ( {dx }, {dx } ) e : = f ( ∅, {dx } )
2 2 2
1 1 1 1 1 1 2 2 2
sx , dx , x : read sx , dx , x : read sx , dx , x : read
2 2 2
sx , dx , x : read
S ( d, e )
32
1 1
S 13 ( a )
2 2
S 13 ( a )
S (d)
33

where the actions of the abstract file operations are implemented:


1 2
open ( x ) open ( x )
2 2
S 111 ( a 1 ) S 11 ( a )
1 1 1 2 2 2
sx , dx , x : read sx , dx , x : read
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 155/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

1 2
\ π / \ π /
1 1 2 2
sx : = norm sx : = abnorm sx : = norm sx : = abnorm
1 1 1 2 2 2
S 12 ( a , dx ) S 12 ( a , dx )

13.6. Examples
13.1. Example: Find the maximum of the values for f : Z → Z
the [ a, b ] interval (and a location index) where the argument and its associated
value parity is the same!
Solution:
A=Z×Z×Z×Z ×L
the b i up l
B=Z×Z
' '
a ' b '
Q :( a = a ∧b = b ∧a≤b +1)

13.6. EXAMPLES 185

R ( Q ∧ L = ( ∃i ∈ [ a..b ] 2 | i + f ( i )) ∧ → l ( i ∈ [ a..b ] ∧ 2 | i + f ( i ) ∧ max =


f ( i ) ∧ ∀j ∈ [ a..b ]: (2 | j + f ( j )) → ( f ( j ) ≤ f ( i ))))
The specification is very similar to the conditional maximum search programming
making. The differences can be summarized as follows:
task conditional maximum search
the ↔ m
b ↔ n
2|i+f(i) ↔ β(i)
Tasks whose specifications are only renaming an already-
as compared to the specification of the programming line, natural recirculation sel solubility
let's do it. This renaming may affect the names of the variables of the item, the general
expressions (eg β ( i )) or constant values of the post-condition. Known program-
we consider the different transcription of the programming batches (eg, vector,
series, input file).
If we get the specifications in this way to a shape, it is
renaming on a known program of the programming item we get the
a program to solve the task set out in 5.3.

k, l : = a - 1 , false
k=b

2 | ( k + 1 + f ( k + 1)) 2 | ( k + 1 + f ( k + 1))
2 | ( k + 1 + f ( k + 1))
∧ ¬l ∧l
f ( k + 1) f ( k + 1)
≥ max ≤ max
l, i, max : =
SKIP
true, k + 1 , f ( k + 1) i, max : =
k + 1 , f ( k +1) SKIP

k:=k+1

13.2. Example: Enter a prime number between n and 2 n natural numbers.


Solution:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 156/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
A = N n× N p
B=N
'
n '
Q : ( n = n ∧ ∃j ∈ [ n. 2 n ]: prime ( j ))
R : ( Q ∧ p ∈ [ n. 2 n ] ∧ prime ( i ))
Linear Search Version 1 specification is similar. Let's see the following
what are the differences after renaming!

186 13. TRANSFORMATIONS

task linear search 1.0


n ↔ m
p ↔ i
prime ( i ) ↔ β(i)
It is a difference that our prerequisite is more stringent, since the j rune index is not just
n fölött, hanem 2n alatt kell lennie. (Megjegyezzük, hogy a specifikáció előfeltétele
az általánosságot nem szorítja meg, ugyanis minden n természetes szám esetén létezik
egy prím n és 2n között (Csebisev-tétel).
A lineáris keresés 1. utófeltételének behelyettesítés utáni alakja:
R′ = (Q ∧ p ≥ n ∧ prím(p) ∧ ∀j ∈ [n..p − 1] : ¬prím(j))
Ez az utófeltétel biztosítja az R feltételt a Csebisev-tétel miatt. Hiszen, ha p-nek
olyannak kell lennie, hogy p − 1-ig ne legyen prím n-től, és p prím, akkor p biztosan
nem nagyobb mint 2n. Ugyanakkor az R nem követeli meg, hogy p − 1-ig minden
szám n-től kezdve összetett legyen, ezért a két feltétel között egyenlőség nem, csupán
következés áll fenn (R′ ⇒ R).
Tehát a tétel szigorúbb, mint a feladatunk, ezért szigorítással vezetünk vissza.

p := n
¬prím(p)
p := p + 1

13.3. példa: Állapítsuk meg, hogy van-e az f : Z → Z függvény értékei között páros
szám az [m..n] intervallumban!
Megoldás:
A= Z × Z × L
mnl
B= Z ×Z
m′ n′
Q : (n = n ∧ m = m′ ∧ m ≤ n + 1)

R : (Q ∧ l = (∃j ∈ [m..n] : 2|f(j)))


A lineáris keresés 2.8 specifikációja hasonló. Lássuk, hogy az alábbi megfeleltetés
után milyen különbségek maradnak:
task linear search 2.8
2|f(i) ↔ β(i)
The difference is that i , that is, the component that would show the pair found
item is not included in our status box. This difference naturally induces it
also eliminating all members of the post-condition that have been bound by i .
In this case, when the task is expanded, the entry is more stringent,
we are driven back by burning. The program of the item is defined by definition 5.4
task.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 157/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

13.6. EXAMPLES 187

This reconnection can also be called alteres reconnection , because it is our job
state space of the programming item's state space. . When programming
(ie, it is not included in the prerequisite,
but the post-condition makes it a constraint) we can not find it in the state of the task (and so
of course, in its post-condition), alteres recurrence is generalized
we are talking about this case.
i, l : = m - 1 , false
¬l ∧ i = n
l : = 2 | f ( i + 1))
i:=i+1

13.4. Example: Determine the number of natural number distributors n .


Solution:
A=N×N
0
n d
B=N
'
n '
Q:(n=n )
Σ
R : ( Q ∧ d = χ ( i | n ))
i=1

The specification is very similar to the programming item for the counting. The differences
can be summarized as follows:
task counting
1 ↔m
i|n ↔β(i)
At first glance here is only the problem that the status of the lot is more extensive. Now
but we can not apply the "extension, tightening" recipe because it is not just the
lap materials and post-conditions differ, but parameter fields and prerequisites
too.
Based on the specific item or its reversibility if one "well"
narrowing the parameter space of a specific task, we get a new task for which
solution will be the original solution program. In our case counting
the following task is obtained:
A=N×N×N
0
MND
B={1}×N
' '
m n '
Q : ( m = 1 ∧ n = n ∧ 1 ≤ n + 1)
Σ
R : ( Q ∧ d = χ ( i | n ))
i=1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 158/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

188 13. TRANSFORMATIONS

If the task to be solved is extended to A = { 1 } × N × N state-


0
MND
we can apply statement 2.2 to square.
The recirculation with the above property is also an alteration to the regeneration
within constant constituency .
It is necessary to verify that the constant value with which m has been replaced,
does the non-trivial part
√ of the prerequisite for the counting fulfill (( m ≤ n +1) =
(1 ≤ n + 1) ( n ∈ N) ).
With these remarks, you can now write the solution program:

k, d : = 0 , 0
k=n
k+1|n
d:=d+1 SKIP
k:=k+1

13.5. Example: Find the lowest number k for [ m..n ] interval for which
p and k are relative primes!
Solution:
A=NŨNŨNŨLŨN
mnklp
B=N×N×N
' ' '
m ' n '
p '
Q:(n=n ∧m=m ∧m≤n+1∧p=p )
R ( Q ∧ L = ( ∃j ∈ [ m..n ]: gcd ( p, j ) = 1) ∧ → l ( k ∈ [ a..b ] ∧ gcd ( p, k ) = 1 ∧
∀j ∈ [ m..k - 1]: lnko ( p, j ) = 1))
The specification is very similar to the line item's 2.8 programming item. The
Differences can be summarized in the following table:
task linear search 2.8
k ↔ i
lnko ( p, i ) = 1 ↔ β(i)
This feedback is a parametric reconnection because the state space is more extensive and a
substitution table substituting β ( i ) is used for this plus comp
ponens. At the same time, the introduced p is a prerequisite of value and the program
'in
(p=p the post-condition ).

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 159/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

13.6. EXAMPLES 189

k, l : = m - 1 , false
¬l ∧ k = n
l : = ( lnko ( p, k + 1) = 1)
k:=k+1

13.6. Example: Determine whether there is a number between the values of the function f ,
which k to relative primes!
Solution:
f : [ m, n ] → N
A=Z×Z×L×N
the b l k
B=Z×Z×Z
' ' '
a ' b '
k '
Q:(a=a ∧b=b ∧a≤b+1∧k=k )
R : ( Q ∧ l = ( ∃j ∈ [ a..b ]: lnko ( k, j ) = 1))
This line item can be retrieved to 2.8, however,
modified alteres because we are not interested in the
for which the function value is relative to prime k . However, vis-
also parsed according to parameter k .
Replacements:
task linear search 2.8
the ↔ m
b ↔ n
lnko ( k, i ) = 1 ↔ β(i)

i, l : = a - 1 , false
¬l ∧ i = b
l : = ( lnko ( k, i + 1) = 1)
i:=i+1

13.7. Example: Given the starting point of the ascending order of the number line N pieces
interval. Determine the number of k numbers in the interval.
Solution:
Iv = ( ah : Z , fh : Z)
I ( i ) = ( i.ah ≤ i.fh + 1)
Iv
V = vect ([ 1..N ] , iv )
A=V ×Z×N
0
v k d

190 13. TRANSFORMATIONS

B=V ×Z
' '
v ' k '
Q : ( v = v ∧ k = k ∧ ∀i ∈ [1 ..N - 1] v [ i ] .ah ≤ v [ i + 1] .ah )
Σ
R : ( Q ∧ d = χ ( v [ i ] .ah ≤ k ≤ v [ i ]. Fh ))
i=1
The specification is very similar to the programming item for the counting. The differences
can be summarized as follows:
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 160/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
task counting
1 ↔m
N ↔n
v [ x ] .ah ≤ k ≤ v [ x ] .fh ↔ β ( x )
i ↔k
Reversal is parametric according to k , and counting is programmed
does not require some kind of settling of the input vector, so the task
prerequisite is stronger than the batch, so we tighten it.

i, d : = 0 , 0
i=N
v [ i + 1] .ah ≤ k ≤ v [ i + 1] .fh
d:=d+1 SKIP
i:=i+1

13.8. Example: Decline the monotone increasing function f in the strict sense
monotony!
Solution:
f : [ m..n ] → Z
A=Z×Z×Z
mnl
B=Z ×Z
' '
m ' n '
Q : ( m = m ∧ n = n ∧ m ≤ n + 1 ∧ ∀i ∈ [ m..n - 1]: f ( i ) ≤ f ( i + 1))
R ( Q ∧ L = ( ∀i ∈ [ m..n - 1]: f ( i ) <f ( i + 1))) = ( Q ∧ ¬l = ( ∃i ∈ [ m..n - 1]:
f ( i ) ≥ f ( i + 1)))
If we take into account the second form of the second condition, the specification is similar
to the specification of linear search 2.8, with few minor differences. Such a difference
(összefoglalhatókon outside of the table), that the items of state-space component of our
is not included in our specification or the item does not require the test
function monotony. So, on the one hand , according to the generalized alteres, on the one hand,
due to the variety of prerequisites - this recurrence is tightened.

13.6. EXAMPLES 191

task linear search 2.8


f ( i ) ≥ f ( i + 1) ↔ β(i)
¬l ↔ l
n-1 ↔ n
In case of substitution of n by n- 1, the prerequisite is met only,
if m ≤ n , then this additional condition is required for recirculation.
Reversal is parametric according to k , and counting is programmed
does not require some kind of settling of the input vector, so the task
the prerequisite is stronger than the batch, so recycling is also tightened.

i, ¬l : = m - 1 , false
¬¬l ∧ i = n - 1
¬l : = f ( i + 1) ≥ f ( i + 2)
i:=i+1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 161/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

not This structure


defined has several
assignments. problems.
For the Theofbiggest
definition is to beonly
assignment, included
the marking
we allowed the names on the left to change. Here, however,
namely ¬l is where L variable name already. However, based on simple considerations
you can see that this type of assignments can be rewritten if "both pages are
once even negate, "and then the resulting ¬¬l place simply formulas l eth
writing. With this last step, another unnecessary expression of the structure, a
the included ¬¬l part was also eliminated.
so:

i, l : = m - 1 , true
l∧i = n- 1
l : = f ( i + 1) <f ( i + 2)
i:=i+1

13.9. Example: Look for the twin references in [ a..b ] interval. We can assume that >
Second
Solution:
A=NŨNŨLŨN
the b l p
B=Z×Z
' '
a ' b '
Q :( a = a ∧b = b ∧a≤b +1 ∧a> 2)

192 13. TRANSFORMATIONS

R ( Q ∧ L = ( ∃i ∈ [ a..b - 2]: (a prime ( i ) ∧ prime ( i + 2))) ∧ → l ( p ∈ [ a..b - 2] ∧


prime ( p ) ∧ prime ( p + 2)))

The specification is similar to the specification of linear search 2.8, with some minor differences
apart. These are summarized in the table:
task linear search 2.8
prime ( i ) ∧ prime ( i + 2)↔ β(i)
p ↔ i
the ↔ m
b- 2 ↔ n
For the last substitution, the prerequisite is true only if ≤ b - 1, therefore
we have to do this.
Recirculation is tightened, as the prerequisite for the intervals is
the task is worse in the task than the batch (mi
we do not require the first twin link to be found in the program).

p, l : = a - 1 , false
¬l ∧ p = b - 2
l : = prime ( p + 1) ∧ prime ( p + 3)
p:=p+1

The initial ( p + 3) prime of l : = prime ( p + 1) ∧ in the solution is replaced by a new up-


we can formulate data as well: Determine a p number for himself and for him
two are more prime! This task specifies an alteration in the original state space,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 162/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'
in:
A =L ×N
l p
'
B =N '

'
p '
Q ' : ( p = p ∧ p> 2)
R ( Q ∧ L = ( ∀i ∈ [2 ..p - 1]: ( ¬ ( i | p ) ∧ ¬ ( i | ( p + 2))))) = ( Q ∧ ¬l = ( ∃i ∈
[ 2..p - 1]: ( i | p ∨ i | ( p + 2))))

This can be traced back to linear search 2.8. Returning to alteres back-
both cases of driving (since the beginning of the interval is con-
but we did not use the i result component of the item
in the specification). Recirculation is also general because what is the constant 2 as the in-
and the expression p- 1 ≥ 2 as the end of the interval, the empty inter-
processing is excluded in the prerequisite, so it is stricter in the prerequisite of the item.

13.6. EXAMPLES 193

task linear search 2.8


and | p ∨ i | ( p + 2)
↔ β(i)
¬l ↔ l
2 ↔ m
p- 1 ↔ n

l: = prime (p) ∧ prime (p + 2)

i, l : = 1 , true
l∧i = p- 1
l : = ¬ ( i + 1) | p ∧ ¬ ( i + 1) | ( p + 2)
i:=i+1

So the solution can be written:

p, l : = a - 1 , false
¬l ∧ p = b - 2
i, l : = 1 , true
l∧i = p- 1
l : = ¬ ( i + 1) | ( p + 1) ∧ ¬ ( i + 1) | ( p + 3)
i:=i+1
p:=p+1

Later on, we will not make this substitution since no new information
does not give, or even in many cases encrypt the actual programming language
hezítheti.
13:10. Example: Find the f : Z → between the values of a function Z k number p th
occurrence in the [ a..b ] interval.
Solution:
To formulate the task, we define a partial function g ∈ Z → N ,
0
where g ( i ) specifies how many times the function f has taken the k value for [ a..i ]
interval.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 163/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
g ( a - 1) = 0, ∀i ∈ [ a - 1 ..b - 1]:
{
g(i), if f ( i + 1) = k ;
g ( i + 1) =
g ( i ) + 1 , if f ( i + 1) = k.

194 13. TRANSFORMATIONS

A=Z×Z×Z×N×Z×L
the b k p i l
B=Z×Z×Z×N
' ' ' '
a ' b '
k p ' '
Q:(a=a ∧b=b ∧a≤b+1∧k=k ∧p=p )
R ( Q ∧ L = ( ∃j ∈ [ a..b ] g ( j ) = p ) ∧ → l ( i ∈ [ a..b ] ∧ g ( i =) P ∧ f ( i ) = k ))

task linear search 2.8


the ↔ m
b ↔ n
g(i)=p ↔ β(i)

i, l : = a - 1 , false
¬l ∧ i = b
l : = ( g ( i + 1) = p )
i:=i+1

Using the substitution of the recursive function with a variable,


its formation method for g :

z:=0
i, l : = a - 1 , false
¬l ∧ i = b
z:=F(i+1,z)
l:=(z=p)
i:=i+1

If we know the programming of the branch-defined function calculation


you can get the solution program if it is applied to F :

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 164/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

13.6. EXAMPLES 195

z:=0
i, l : = a - 1 , false
¬l ∧ i = b
f ( i + 1) = k
z:=z+1 z : = z ( ⇔ SKIP)
l:=(z=p)
i:=i+1

13:11. Example: Find the [ m..n ] interval f : Z → Z function is one


which is equal to the average of your immediate neighbors!
Solution:
A=Z×Z×L×Z
MnlI
B=Z ×Z
' '
m '
n '
Q = ( m = m ∧ n = n ∧ m ≤ n + 1)
R = ( Q ∧ L = ( ∃j ∈ [ m + 1 , n - 1]: ( f ( j ) = f ( j- 1) + f ( j + 1) ) ∧l→(i∈
2
[ M + 1 , n - 1] ∧ f ( i ) = f ( i- 1) + f ( i +1) ))
2

Linear Search 2.8 specification is similar. Let's see the following renaming
what are the differences:
task linear search 2.8
m +1 ↔ m
n-1 ↔ n
f ( i ) = f ( i- 1) + f ( i +1) ↔ β(i)
2
For the first two substitutions, the prerequisite of the theorem is true only if m <n ,
so we have to do this.
Recirculation is generalized, as we do not demand that the first is this
you'll find a specialty element.

i, l : = m, false
¬l ∧ i = n - 1
l : = ( f ( i + 1) = f ( i ) + f ( i + 2) )
2
i:=i+1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 165/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

196 13. TRANSFORMATIONS

13.7. Tasks
Functions in tasks (if not otherwise stipulated) are integers in an inter-
they are interpreted and are of value.

13.1. Determine the number of positive values of f function that are


directly after a negative value!
13.2. Állapítsuk meg, hogy az n természetes számnak van-e páratlan valódi osztója!

13.3. Határozzuk meg az n természetes szám legkisebb páratlan osztóját!


13.4. Adottak az x és y vektorok, ahol y elemei az x indexei közül valók. Keressük
meg az x vektornak az y-ban megjelölt elemei közül a legnagyobbat!

13.5. Adjuk meg, hány olyan elem van az x vektorban, amely kisebb az indexénél!
13.6. Határozzuk meg az n természetes szám legkisebb egyszeres osztóját!

13.7. Adottak az azonos értelmezési tartományú f és g függvények. Az f értékei


egészek, g pedig csak a 0, 1 értékeket veszi fel. Határozzuk meg azoknak a páros
f -értékeknek a számát, amelyek olyan pozícióban vannak, ahol a g függvény
értéke 1!

13.8. Keressük meg azt a helyet, ahol az f függvény értékének decimális alakjában
az egyesek helyén a legnagyobb számjegy áll!
13.9. Az x vektor egy szöveget tartalmaz. Állapítsuk meg, hogy visszafelé olvasva a
szöveg ugyanaz-e!

13.10. Adott egy gráf a csúcsmátrixával. Állapítsuk meg a k-adik csúcs fokszámát!
13.11. Határozzuk meg az f függvény legnagyobb k-val osztható értékét!

13.12. Határozzuk meg az n természetes szám valódi páros osztóinak számát!


13.13. Határozzuk meg az f függvény lokális minimumai közül a legnagyobbat! (Egy
érték akkor lokális minimum, ha mindkét szomszédjánál kisebb.)

13.14. Adjuk meg az f függvény egy k-val osztható értékéhez tartozó argumentumát!
13.15. Határozzuk meg az f függvénynek a k-nál kisebb legnagyobb értékét!

13.16. Adott a középpontjával és a sugarával a síkon egy kör, és további N darab pont.
Keressünk egy olyan pontot, amely a körbe esik!
13.17. Határozzuk meg az f függvénynek az [a, b] intervallumba eső legnagyobb
értékét!

13.7. FELADATOK 197

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 166/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
13.18. Határozzuk
vagy a [c, d]meg az f függvény
intervallumba azon értékeinek a számát, amelyek vagy az [a, b]
esnek!

13.19. Határozzuk meg az f függvénynek azt a legnagyobb értékét, amely k-val osztva
1-et ad maradékul!

13.20. Adjuk meg az f függvénynek azt az értékét, amely mod N a legnagyobb!

13.21. Adottak az azonos értelmezési tartományú f és g függvények. Az (f (i), g(i))


számpárok egy-egy síkbeli pont koordinátái. Számoljuk meg, hogy a pontok
közül hány esik az (x0, y0) középpontú, r sugarú körbe!
13.22. Keressük meg az f függvénynek az első n-nél kisebb vagy 0 értékét!

13.23. Adottak az x és y vektorok, valamint a k szám. Az y vektor az x indexeinek egy


részhalmazát tartalmazza. Számoljuk meg, hány olyan k-val osztható elem van
x-ben, amelynek indexe megtalálható y-ban!
13.24. Adott az x vektorban egy szöveg. Állapítsuk meg, hogy a szöveg tartalmaz-e
magánhangzót!

13.25. Keressük meg az f függvény egy olyan értékét, amely beleesik az [a, b] és a
[c, d] intervallumba is!
13.26. Az x vektor egy szöveget tartalmaz. Számoljuk meg, hány magánhangzó van a
szövegben!

13.27. Állapítsuk meg, hol van a monoton növekedő f függvényben a legnagyobb


ugrás, azaz az f (k) − f (k − 1) érték mely k-ra maximális!

13.28. Határozzuk meg az f függvény legnagyobb páros értékéhez tartozó argumentu-


mot!

13.29. Keressünk az x vektorban két olyan szomszédos elemet, amelyek szorzata


negatív!

13.30. Adottak az [m, n] intervallumon értelmezett f és g függvények. Állapítsuk meg,


hány egész koordinátájú pont esik a függvényértékek közé!
13.31. Adottak az x és b vektorok. „Fektessük” b-t az x vektorra folyamatosan egymás
után, ahányszor csak lehet, és számoljuk meg, hány helyen egyeznek az egymás
feletti értékek!

13.32. Adott az n természetes szám. Határozzuk meg n egy valódi osztóját!

13.33. Adjuk meg az f függvénynek azt az értékét, amelynek szomszédai átlagától


való eltérése a legnagyobb!

198 13. TRANSZFORMÁCIÓK

13.34. Keressünk az x vektorban egy olyan elemet, amely osztható az indexével!

13.35. Adott az x mátrix, amelynek elemei sorfolytonosan növekvő sorozatot alkotnak.


Keressük meg a mátrixban az n értéket!

13.36. Adott egy x vektor, amely színeket tartalmaz sötétedő sorrendben ( színeken
értelmezve van egy úgynevezett sötétségi reláció, amely teljes rendezés). Ke-
ressük meg az x vektorban a világoskéket!

13.37. Adott a síkon N darab pont. Keressük meg az origótól legtávolabb eső pontot!

13.38. Adjuk meg az f függvény utolsó pozitív értékének argumentumát!

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 167/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
13.39. Adott az x vektor, amelynek elemei nullák és egyesek. Számoljuk meg, hánys-
zor fordul elő a vektorban a ’0101’ szakasz!

13.40. Állapítsuk meg, hogy van-e az f függvény értékei között olyan szám, amely
k-hoz relatív prím!

13.41. Határozzuk meg az n természetes szám legkisebb valódi nem prím osztóját!
13.42. Given the f and g monotonically growing function and the k numbers. Determine
( i ) + g ( j ) = k , if i find the i and j argument for which f ( i ) + g ( j ) = k !
13:43. Enter the index of a row of x matrix that does not contain positive
item!

13:44. Determine whether the text in vector b occurs in the character x vek-
tor!

13:45. The injective f function is given. Enter a space that is at least one
precedes where the function value is larger!
13:46. Determine the first place where the function f takes up a value that
take at least twice!
13:47. Find the row of x matrix with all elements of 1!

13:48. Enter the number of prime numbers in the [ a, b ] interval.


13:49. Determine n numbers less than n , relative to parent numbers
The number!

13:50. There are two matching 2 n angles. Both sides are randomly blue
red painted. Place the two polygons on each other as far as possible
most places have the same color pages on each other!
13:51. Calculate the zero values of f : [ m, n ] × [ m, n ] → Z.

13.7. TASKS 199

13:52. Calculate the number of lines in x matrix that are only one
contains zero elements!

13:53. Determine which function f is the most commonly used value.

13:54. Determine the value of the function f that most na-na-


bigger element ahead!

13:55. Find the column of the square x matrix in which the maindiagonal is
over the top!

13:56. Determine the squared x matrix for the largest element under the main diagonal
mét!

13.57. Számoljuk meg, hogy az x mátrixnak hány olyan sora van, amely csak egy
nullától különböző elemet tartalmaz!

13.58. Adott a sík N pontja. Állapítsuk meg, melyik a két legtávolabbi pont!

13.59. Egy sakkbajnokság végeredményét egy x négyzetes mátrixban tároltuk, ahol az


i-edik sorban a j-edik elem az i-edik játékos és a j-edik játékos közti mérkőzés
eredményét jelenti az i-edik játékos szempontjából ( xi,j értéke 0, ha j nyert;
2, ha i nyert; 1, ha a játékosok döntetlenben egyeztek meg). Keressük meg a
champion (one) winner (the winner is the one who has most points)!
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 168/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

13.60. There is a f : [ a, b ] → Z function. The scope of the interpretation of this function is one
i is called the peak of the function if ∀j ∈ [ i + 1 , b ]: f ( j ) <f ( i ).
Define how many vertices f unto!

13.61. Find the quadratic matrix x parallel to the maindialogal


where the sum of the elements is the greatest!

13.62. The function f , which captures 0 , 1 is given . Find the function for interpretation
which is the beginning of the longest single series of values!

13.63. Determine whether there is a negative number for the function values of f (starting)
among its sums!

13.64. The section of the interpretation range of a function to which it belongs


values are negative, so that the section is a nonnegative value from the right and left
is defined by the end of the range of interpretations, called the negative island of the function
Zuk. Define the negative islands in the interpretation range of f function
The number!

13.65. Give a k number to which the n natural number is binary


s s -adik local value is 1!

200 13. TRANSFORMATIONS

13.66. Enter the length of the length of the interpretation range of f ,


within which the values are rising!

13.67. Determine how many pieces of 1-bit in the binary form of the x number,
erep!

13.68. An x vector is given with elements of characters. The vector contains words,
which are separated by a comma. Enter the longest word
your starting index!

13.69. One f : [ a, b ]→ The section of the Z domain,


the two endpoints of which are the local minimum position of the function such that the endpoints
but not those, are called a tip of the function. Give it
the starting point for the widest mountain!

13.70. A section of a vector that contains all negative elements such that
the section is bordered by the right and left nonnegative elements or by the end of the vector, a
the negative island of the vector. Enter x is the largest negative vector
island starting point!

13.71. A museum of the i -th hour x visitor arrivals and y visitors go away.
of i
What hour did most visitors have in the museum?

13.72. There is a vector of two integers and two integers. Let's say that a
two numbers are in the vector; and if so, which one is the first!

13.73. Place n knives on a n x n size chessboard with one


no leader should attack another!

13.74. Hányféleképpen helyezhetünk el n darab vezért egy n × n méretű sakktáblán


úgy, hogy egyik vezér se támadjon másikat?

13.75. Legfeljebb hány vezért lehet egy n × n méretű tórikus sakktáblán elhelyezni
úgy, hogy egyik vezér se támadjon másikat?

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 169/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
13.76. Adott
közöttinszimpátiát
fiú és ugyanennyi lány. Egy x logikai
(ez egy szimmetrikus mátrixban
reláció) tároljuk a fiúk
a következőképpen: xi,jés lányok
igaz,
ha az i-edik fiú és a j-edik lány szimpatizál egymással, hamis, ha nem szimpa-
tizálnak egymással. A feladat az, hogy ha lehet, akkor párosítsuk (házasítsuk)
össze őket úgy, hogy minden párban a felek szimpatizáljanak!

13.77. There is a hussar in a mezze of n × m size ( i, j ). Can it be all the time


to drive on the board by entering all the fields, but only once and every step
regular (hussar step)?

13.78. How many ways can I pay n for m from different denominations?

13.7. TASKS 201

13.79. How many ways can n pay HUF m different denominations of money if
at most d , d ,. . . D can be used?
1 2 m

13.80. A natural subset of S numbers is given . Can you choose from this n
piece of items so that their amount should be m ?

13.81. The x sequential file (allowed operation is sx, dx, x : read ) is a company
the following information about his employees:

• the worker's identification number;


• is in a senior position;
• highest educational level.

Select the data of the employees who are the leader in the v series
are assigned to the z series with the names of the senior executives,
and they did not graduate!

13.82. The sequential file x (permissible operation is sx, dx, x : read ) earthquakes
your data. An item consists of:

• the coordinates of the location of the detection;


• the strength of the ripple;
• the duration of the shake;
• the identity of the continent;
• Tune is predicted.

Select the detection areas for unmarked earthquakes in t series, a


z series with more than 20 seconds of earthquakes!

13.83. The names of the first names and the names of flowers are given, both in alphabetical order.
(allowed operation is sx, dx, x : read ). Determine those
names that are not flower names!

13.84. There is a file containing integers. If the file contains a positive element,
then look for the biggest, otherwise the smallest!

13.85. In a file (permissible operation with the extremop extremal element) they are given
some types of cactus (name, homeland, flower color, size). Sort out
a file into Mexican, another red-flowered cacti!

13.86. Given in a file (allowed operation is sx, dx, x : read ) an OTP-


register (name, amount) in the form of pairs. Enter the name of the person to whom
no debt, but the smallest of its deposits (if any)!

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 170/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

202 13. TRANSFORMATIONS

13.87. The sequential file x contains integers (permissible operation is


sx, dx, x : read ). Find the local maximum in the file,
which is larger than both of its immediate neighbors!

13.88. The vector x and y are sequential files with elements that are both positive
whole numbers. In x and y , a number occurs at most once,
two are growing orderly. The Y is a sequential file which only
end operation is allowed and the end of the file is indicated by a negative number. Prepare it
the ordered series of z , containing x and y elements.

13.89. They are given in the x sequential file (allowed operation is sx, dx, x : read )
the data of a student of a year. One item is the student's name, group number, and
ten grades (zero indicates that the rating is missing). THE
file is growing according to group numbers. Prepare the sequence y ,
which includes students' names, group numbers and average.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 171/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 14

Abstraction strategy

Always have some abstraction procedure when solving programming problems


which can be the same throughout the course of the solution, but may also vary by step. THE
different programming methods are characterized by their abstraction
strategy.
In the previous section, we have shown a simple example of state space transformation. The
building state-space transformation strategies adatabsztrakciós strategy is nevez-
because the state of the state is the abstraction of the data.
Now we are solving this task again, but with a different set of thoughts. It's not
state, we define functions in the original state,
by which the post-condition can be easily typed and easier to handle
we get to work. In this case we are talking about function abstraction.
So the task is as follows: Suppose there is a sequence of characters,
cial file containing a text. Calculate how many of them are
there is a section of letters in the text that has a length greater than the specified number
value!
Let x be a series of characters. Define the following partial dependency
prescription:
f (0) = 0 and
∀i ∈ [0 ..dom ( x ) - 1]:
{
f ( i ) + 1 , where x i +1 ∈ BET ;
Ü
f ( i + 1) =
0, if x and +1 ∈ BET Ü.
The function f specifies that the letter n in the place has a break
in the x . Therefore the job specification is:
A = X × N if X = file ( CH ) ,
xD
B=x
'
x

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 172/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

204 14. ABSTRACTION STRATEGY

'
Q:(x=x )
' Σ
R :( k = k ∧d = χ ( f ( i ) = k ))
i=0
For this task, apply the counting to a sequential file
and the replacement of the recursive function with a variable transform
we get the next solved program.

sx, dx, x : read


z:=0
d:=0
sx = norm

\ dx ∈ BET Ü /
z = z +1 z=0
\ z=k /
d=d+1 SKIP
sx, dx, x : read
A következőkben egy összetettebb feladaton mutatjuk meg e két alapvető stratégia
összehasonlítását.

14.1. Az időszer űsítés definíciója


Először néhány, a sorozatok (szevenciális fájlok) estén gyakran használt jelölést, fo-
galmat vezetünkbe. Legyen x egy sorozat. {x} jelöli a sorozat elemeinek halmazát,
azaz

{x} = {xi}.
i=1
Gyakran használunk olyan sorozatot, amelynek kulcsa van. Ez azt jelenti, hogy
S = seq(X), ahol X = (k : K,d : D) és K egy rendezett halmaz. K a kulcsok, D az
adatrészek lehetséges értékeinek halmaza. Legyen s ∈ S, ekkor {s.k} az s kulcsainak
halmaza, azaz

{s.k} = {si.k}.
i=1
Azt mondjuk, hogy az s ∈ S sorozat kulcs szerint rendezett, ha
∀i ∈ [1..dom(s) − 1] : si.k ≤ si+1.k.
Ha S minden eleme kulcs szerint rendezett, akkor S kulcs szerint rendezett sorozat
típus.

14.1. AZ ID ŐSZER ŰSÍTÉSDEFINÍCIÓJA 205

Ha az s ∈ S sorozat minden elemének kulcsa különbözik, azaz

∀i, j ∈ [1..dom(s)] : i = j ⇒ si.k = sj .k,


akkor azt mondjuk, hogy s egyértelmű kulcsú sorozat. Ha S minden eleme egyértelmű

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 173/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
kulcsú, akkor S egyértelmű kulcsú sorozat típus.
Legyen S egyértelmű kulcsú sorozat típus. Definiáljuk a következő K :∈ S ×K →
X parciális függvényt:
(s, q) ∈ DK ⇔ q ∈ {s.k}
és
K(s, q) ∈ {s} és K(s, q).k = q.
Most lássuk az időszerűsítés feladatát. Induljunk ki egy olyan adatfájlból, amely-
ben azonos típusú elemek találhatóak. Ezt a fájlt törzsfájlnak fogjuk nevezni. Legyen
az elemek típusa E, ekkor
T = seq(E).
Legyen adott továbbá egy olyan fájl, amely transzformációk sorozatát tartalmazza. Ezt
a fájlt fogjuk módosítófájlnak nevezni. Legyen F = {f | f : T → T }, ekkor
M = seq(F).
A feladat az, hogy időszerűsítsük a törzsfájlt a módosítófájlban leírt transzformá-
ciókkal. Jelölje Υ az időszerűsítés transzformációt. Ekkor Υ : T × M → T és

Υ(t, m) = mdom(m) ◦ · · · ◦ m2 ◦ m1(t).

To give a solution to the task, this description is still too general, therefore
we will make further stipulations for the files.

1. Timing is key.
Let E = ( k : K, d : D ) and F = ( k : K, v : V ) where K is a key; D a
part of master record data; V is the type that defines the transformation to be performed.
We also assume that both the root file and the modifier file are key ( s )
orderly.

2. The root file is clear in the key.

3. The transformation can only be the following three types (deletion, insertion, correction):

V = ( tr : W ; be : W ; jav : W );
1 2 3
W = {Α},
1
W = (d:D),
2
W = ( G : G ) , where G = seq ( H ) H = {γ | γ : D → D}.
3

206 14. ABSTRACTION STRATEGY

There is still a description of how the above transformations affect a


master data files. Since the root file is clear and orderly, just enough
specify what elements it consists of.
Three cases are distinguished depending on whether the transformation is deleted,
insertion or repair.

(a) m .tr , i.e. m deletion:


i i
{
{e | e ∈ t and ek = m k}, if m k ∈ {tk} ;
{m ( t ) } = i. i.
i {T} otherwise .

(b) m .be , i.e. m insertion:


i i
{

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 174/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
{m , t} = {t} ∪ { ( m k, m
{T} vv ) }, if m k ∈ {tk}
otherwise . ;
i i, and i.

(c) m .java , i.e. m repair:


i i

{e | e ∈ t and ek = m k} ∪
if m k ∈ {tk}
i.
{ ( M .K, m .g dom i(.gm) ◦
{m , t} = i i i.
i ··· ◦ m .g ( K ( t, m k ) .d )) } ;
i 1 i
{T} otherwise .

4thThe repair action replacement.


Ez azt jelenti, hogy dom(mi.g) = 1 és mi.g1 konstans. Ebben az esetben a
mi.g1(K(t,k).d) = mi.d.

A feladat specifikációja tehát:

A=T×M×T
t0 mt
B=T×M
t′0 m′
Q : (t0 = t′ 0 ∧m=m′ ésaz1..xpontokteljesülnek)
R : (t = Υ(t′ 0,m′))

Ha a fenti specifikációban x = 3, akkor közönséges, ha x = 4, akkor egyszerű


időszerűsítésről beszélünk.

14.2. ID ŐSZER ŰSÍTÉSEGYÉRTELM ŰMÓDOSÍTÓFÁJLLAL 207

14.2. Időszer űsítés egyértelm ű módosítófájllal


A továbbiakban az egyszerű időszerűsítéssel fogunk foglalkozni. Közönséges idősze-
rűsítés esetére csak utalni fogunk.
A feladatot három irányból is megpróbáljuk megoldani: visszavezetjük halmazok
uniójára, egyváltozós egyértékű; illetve kétváltozós egyértékű elemenkénti feldolgo-
zásra.

14.2.1. Visszavezetés halmazok uniójára


Ez a megoldás Dijkstra könyvében [Dij 76] található. Az alapgondolat az, hogy a t
elemei vagy olyanok, hogy a kulcsuk t0-ban is kulcs vagy olyanok, hogy a kulcsuk
m-ben is kulcs. Tehát {t} = x ∪ y, ahol x = {e ∈ {t} | e.k ∈ {t0.k} és y = {e ∈
{t} | e.k ∈ {m.k}.
A transzformált feladat tehát a következő: A = T× T× T
xyt
B=T×T
x′ y′
Q : (x = x′ ∧ y = y′)
R:(t=x∪y)

Idézzük fel az unió programját:


t := x ∪ y

t := ∅

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 175/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
x=∅∨y=∅
e :∈ (x ∪ y)
\ e∈x∧e∈y \e ∈x∧e∈y \ e∈x∧e∈y

∪e ∪e ∪e
x := x ≃ e y := y ≃ e x := x ≃ e
y := y ≃ e
Most már csak a fenti programot kell transzformálni az eredeti állapottérre.
x=∅∨y=∅ → t0 =∅∨m=∅
e :∈ (x ∪ y) → e.k :∈ ({t0.k} ∪ {m.k})
e∈x → e.k ∈ {t0.k}
e∈y → e.k ∈ {m.k}

208 14. ABSZTRAKCIÓS STRATÉGIA

Jelöljük q-val az e.k kulcsot, ekkor a megfelelő program:

t := ∅
t0 = ∅ ∨ m = ∅
q :∈ ({t0.k} ∪ {m.k})
\q∈{t0.k}∧q∈{m.k} \q∈{t0.k}∧q∈{m.k} \q∈{t0.k}∧q∈{m.k}

S1 S2 S3

Vizsgáljuk meg most, hogy mit kell tenni az elágazás egyes ágaiban:

1. Ha a q kulcs csak a t0 eredeti törzsfájlban szerepelt, akkor a K(t, q) elemre nem


vonatkozott módosítás, változtatás nélkül kell kiírni az új törzsfájlba.
S1

∪Q(t0,q)
t :=t
0 0
≃K(t0,q)
2. If q is the key value in both the original file and the modifier file
the deletion and repair operations can be performed. In this branch a
q key must be deleted from both files.
S
2

\ K ( m, q ) .tr\ K ( m, q ) .be\ R ( m, q ) .java


SKIP FAULT ∪ ( q, k ( m, q ) . D )
m = m ≃ K ( m, q )
t :=t
0 0
≃K(t0,q)
3. If the k key was only in the modifier file, then only the insert operation
It can be carried out, and the q key ele met by deleting the módosítófájlból.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 176/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
S
\ K ( m, q ) .tr K ( m,3 q ) .be \ R ( m, q ) .java
\
FAULT ∪ ( q, k ( m, q ) . D ) FAULT

m = m ≃ K ( m, k )

14.2. ID AUTHORIZATION TREATMENT WITH A DIFFERENTIAL DOCTOR 209

If the program has to provide an error signal, it should be given in the above structure charts
In ERROR- marked locations. Let us now return to the original task,
where there are sequential files instead of sets. Make the input files a
read operation interpreted. At this point, the program will be as follows:

st , dt , t : read ; sm, dm, m : read


0 0 0
t : = <>
st = norm ∨ sm = norm
( st = sm ∧ dt .k <dm.k ) st = sm ∧ ( st = sm ∧ dt k> dm.k )
0 0 0 0 0.

\
∨sm = abnorm \ dt 0 .k = dm.k
\
∨st = abnorm
0
* *
t : hiext ( dt ) S2 S3
0
st , dt , t : read
0 0 0

where
*
S2

\ dm.t \ dm.b \ DM.J


SKIP FAULT t : hiext ( dm.k, dm.d )
st , dt , t : read
0 0 0

sm, dm, m : read


*
S3
\ dm.t \ dm.b \ dm.j
FAULT t : hiext ( dm.k, dm.d ) FAULT
sm, dm, m : read

14.2.2. Reversal for single-variable element processing


A state transformation is used. Let X = seq ( Y ) and Y = ( k : K, d :
' ' ' '
D , v : V ) where D = D ∪ { " empty " } and V = V ∪ { " empty " } .
Let x be ∈ X and {xk} = {t K} ∪ {mk} .
0.

{
" Empty " , if x k ∈ {t k} ;
∀i ∈ [ 1..x.dom ]: x i .d =
K ( t , x K ) .d,if x k ∈ {t k}.
i. 0.

{ 0 i. i. 0.
" Empty " , if x k ∈ {mk} ;
x .v =
K ( m, x K ) .v, if x k ∈ {mk}.
i.
i
i. i.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 177/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

210 14. ABSTRACTION STRATEGY

Let f : X → T .

f(x)= f ( {e} ) and
e∈ {x}

( s, ed ) , if ev = " empty ";

" Empty " , if evtr ∧ ed = " empty " ,


( ek, evd ) , if evbe ∧ ed = " empty " ,
f ( {e} ) = " Empty " , if evjav ∧ ed = " empty ";

" Empty " , if evtr ∧ ed = " empty " ,


≠ ( ek, ed ) , if evbe ∧ ed = " empty " ,
( S, EVD ) , if evjav ∧ ed = " blank " .

The specification:
A=X×T
xt
B=X
'
x
'
Q:(x=x )
'
R : ( t = f ( x ))

The solving program for the sets:

t:=∅
x=∅
e:∈x
ed = " empty " ∧ ed = " empty " ∧ ed = " empty " ∧
\ ev = " empty " \ ev = " empty " \ ev = " empty "
d : = ( ek, ed ) S S
2 3

∪d
x:=x≃e
where
S
2

e.tr e.be \ e.jav


\ \
FAULT d : = ( ek, evd ) FAULT

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 178/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

14.2. ID ŐSZER ŰSÍTÉSEGYÉRTELM ŰMÓDOSÍTÓFÁJLLAL 211

S3

\ e.tr \ e.be \ e.jav


d := ∅ HIBA d := (e.k, e.g(e.d))
Térjünk vissza most az eredeti állapottérre:

x=∅ ⇒ t0 = ∅ ∨ m = ∅
e :∈ x ⇒ q :∈ ({t0.k} ∪ {m.k})
e.d = ”üres” ∧ e.v = ”üres” ⇒ q ∈ {t0.k} ∧ q ∈ {m.k}

e.d = ”üres” ∧ e.v = ”üres” ⇒ q ∈ {t0.k} ∧ q ∈ {m.k}


e.d = ”üres” ∧ e.v = ”üres” ⇒ q ∈ {t0.k} ∧ q ∈ {m.k}
x := x ≃ e ⇒ q ∈ {t0.k} q ∈ {t0.k} q ∈ {t0.k}
\∧ q ∈ {m.k} \∧ q ∈ {m.k} \∧ q ∈ {m.k}
t0 := t0 ≃ t0 := t0 ≃ m := m ≃
K(t0, q) K(t0, q) K(m, q)
m := m ≃
K(m, q)

Használjuk fel azt a tényt, hogy a d := f ({e}) értékadást kiszámító programok-


ban és az x := x ≃ e értékadás megfelelőjében szereplő elágazások feltételrendszere
∪ d értékadást csak azokba az ágakba írjuk bele, ame-
lyekben d = ∅. Ekkor ugyanazt a programot kapjuk, mint az első megoldásban.

14.2.3. Visszavezetés kétváltozós elemenkénti feldolgozásra


A feladat megoldásának talán legegyszerűbb módja az, ha kétváltozós egyértékű -
hibakezelés esetén kétértékű - elemenkénti feldolgozásra vezetjük vissza, úgy, hogy
az elemeket a kulcsukkal azonosítjuk. Tekintsük a feladat eredeti specifikációját.
Ha a módosítófájl kulcs szerint egyértelmű, akkor az időszerűsítés függvénye (Υ)
a kulcsokra nézve elemenként feldolgozható. A kulcsértékekre felírt függvény:
Υ({q}, ∅) = {K(t0, q)}.
∅, ha K(m, q).tr;
Υ(∅, {q}) = {(q,K(m,q).d)},haK(m,q).be;
∅, if K ( m, q ) .
∅, if K ( m, q ) .tr ;
Σ ( {q}, {q} ) = {R ( t 0 , q ) }, if K ( m, q ) .be ;
{ ( Q, R ( m, q ) .g ( R ( t , q ) .d )) }, where R ( m, q ) .java.
0

212 14. ABSTRACTION STRATEGY

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 179/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

If this function is replaced by two-variable processing per item


we will get the same solution program - only in a much shorter way
- as the first solution.
Comparing the three solutions, we can make two observations. Surprisingly
with three seemingly completely different solution strategies for the same program-
we got there. In fact, the result is not so surprising as we know it is
union bivariate element processing.
Our other remark is that the stronger the item, the more single
we get to the solving program with a lot of confidence.

14.3. Temporizing with an unmistakable editing file


How does the task change if the modifier file is not clear by the key?
In this case, the task can not be processed per element, since the elements are not
can be considered the same as their key. There are two ways to solve this problem
we will examine: one is typically a data- abstraction of the other primarily function-
abstraction approach.

14.3.1. Solution with data abstraction


As mentioned earlier, if the modifier file is not clear by key, then
the task can not be processed per element. Let's try to do it. That's right
we need to make the modifier file clear by key. This is a state-
it is easy to get through transformation, since all we have to do is,
we will combine the same key modifier records into a new record. So the new one
the modification record will look like this:

(key, transformation sequence)

State space transformation is given in two steps. Let Z = seg ( U ), where


U = seq ( F ).
'
A =T×Z×T
t z t
For z it is satisfied that ∀i ∈ [1 ..dom ( z )]: ∀j ∈ [1 ..dom ( z ) - 1]:
0
j=zK = z and j- 1 .K ,
i i
z is a clear key, and the relation between m and z : seq ( m | F ) = seq ( z | F ).
' '
Let S = seq ( V ); and F = ( k : K, s : S ) and X = seq ( F ).
'
A =T×X×T
t xt
0
x is clear, { xK } = {zK} and seq ( x | V ) = seq ( z | V ).
With this modifier file, we have reached the bivalent monovalent (File error
if binary used) for each item. The only difference is only

14.3. ID AUTHORIZATION WITH THE MODERNIZATION FILM 213

is that the implementation of a given transformation sequence must be implemented in the


sea state space. To do this, we will need the " empty " symbol,
'
let us pause for the type of data part: D = D ∪ { " empty " } . That's a master record
The data part is " blank ", meaning that the record does not have to be written to the result file.
The function that can be processed per element is:

Υ ( {q}, ∅ ) = {R ( t , q ) }
0
Υ ( ∅, {q} ) = { ( q, K ( x, q ) .s (" empty ") }}

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 180/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Υ({q}, {q}) = {(q, K(x, q).s(K(t0, q).d))}

A transzformációsorozat elvégzése csak a transzformációk megfelelő sorrendje ese-


tén lehetséges. Ha egy transzformációsorozat egy tagját nem lehet elvégezni, akkor
azt a sorozatból ki kell hagyni (esetleg hibát kell jelezni). Ezzel az Υ függvény
egyértelműen definiált.
Írjuk fel tehát a fenti megfontolások alapján a kétváltozós elemenkénti feldolgozás
programját a megfelelő behelyettesítésekkel:

t := 0
st0, dt0, t0 : read
sx, dx, x : read
st0 = norm ∨ sx = norm
sx = abnorm ∨ (sx = st0 sx = st0 ∧ st0 = abnorm ∨ (sx = st0

\
∧ dt0.k < dx.k) \ dx.k=dt0.k
\
∧ dx.k < dt0.k)
t : hiext(dt0) ak := dx.k ak := dx.k
st0, dt0, t0 : read ad := dx.s(dt0.d) ad := dx.s(”üres”)
t : HIEXT(ad,ak) t : HIEXT(ad,ak)
st0, dt0, t0 : read sx, dx, x : read
sx, dx, x : read

Definiálnunk kell még, hogy mit jelent a fenti struktogramban a transzformáció-


sorozat elvégzése. Ehhez bevezetjük az f : N0 → D′ rekurzívan definiált függvényt:

dx.s(p) = f (dx.v.dom),

ahol

f (0) = p;
f ( i + 1) = dx.s and +1 ( f ( i )) .

214 14. ABSTRACTION STRATEGY

To perform the dx.v i +1 operation in the above definition, perform the following function values
'
We understood. Let d ∈ D , then:

" Empty " , if dx.s and +1 .t ∧ d = " empty ";


d. if dx.s and +1 .t ∧ d = " empty ";
d. if dx.s and +1 .b ∧ d = " empty ";
dx.s and +1 ( d ) =
dx.s and +1 .d, if dx.s and +1 .b ∧ d = " empty ";
D d xs and +1 .d, if dx.s and +1 .j ∧ d = " empty ";
d. if dx.s and +1 .j ∧ d = " empty " .

The program that compiles the function f - the series of the series of amendments:

ad : = dx.s ( p )

ad : = p

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 181/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
dx.s.dom = 0
\ dx.s.lov.t \ dx.s.lov.b \ dx.s.lov.j

\ ad = " empty "


/\ ad = " empty " /\ ad = " empty "
/
FAULT ad : = " empty " ad : = dx.s.lov.d FAULT FAULT ad : = dx.s.lov.d
dx.s : lorem

Since the current value can be " empty, " instead of the hiext operation
program is used:

t : HIEXT ( ak, ad )

\ ad = " empty " /


t : hiext (( ak, ad )) SKIP

Let's go back to the original state of affairs. The main program then:

14.3. ID AUTHORIZATION WITH THE MODERNIZATION FILM 215

t:=0
st 0 , dt 0 , t 0 : read
sm, dm, m : read
st 0 = norm ∨ sm = norm
sm = abnorm ∨ (sm = st0 sm = st0 ∧ st0 = abnorm ∨ (sm = st0

\
∧ dt0.k < dm.k) \ dm.k=dt0.k \
∧ dm.k < dt0.k)
t : hiext(dt0) ak := dm.k ak := dm.k
st0, dt0, t0 : read ad := T R(dt0.d, ak) ad := T R(”üres”, ak)
t : HIEXT(ad,ak) t : HIEXT(ad,ak)
st0, dt0, t0 : read

Az ad := T R(p, ak) a már korábban definiált rekurzív függvényt kiszámító prog-


ram megvalósítása az eredeti állapottéren:

ad := T R(p, ak)

ad := p
sm = norm ∧ ak = dm.k

\ dm.t \ dm.b \ dm.j


ad = ”üres” \ ad=”üres” ad = ”üres”
\ / /\ /
HIBA ad := ”üres” ad := dm.d HIBA HIBA ad := dm.d
sm, dm, m : read

14.3.2. Megoldás függvényabsztrakcióval


Egy adott feladat megoldását mindig elkerülhetetlenül befolyásolja a specifikáció

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 182/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
módja. A függvényabsztrakció lényege abban rejlik, hogy a megoldást egy alkalmasan
választott függvény helyettesítési értékének kiszámítására vezetjük vissza.

Kulcsok egyértelm űsítése. A gyakorlatban sokszor találkozhatunk olyan fájlokkal,


amelyek rekordjaiban van valamilyen kulcsmező, ami szerint a fájl rendezett, de a fájl
mégsem egyértelmű kulcs szerint és így a kulcsmezőre vonatkoztatva nem elemenként
feldolgozható. A következőkben egy olyan technikát fogunk bemutatni, amelyben egy
új kulcsot definiálunk a fájlra, és ezen új kulcs szerint a fájl már egyértelmű.
Tegyük fel, hogy a fájl U = (k : K, z : Z) típusú rekordokból áll. Az új kulcsot
úgy kapjuk, hogy az egymás után levő azonos kulcsokat megsorszámozzuk. Legyen
tehát V = (h : H, z : Z), ahol H = (k : K, s : N). Legyen továbbá g : seq(U ) →
seq(V ):

216 14. ABSZTRAKCIÓS STRATÉGIA

1. g(u).dom = u.dom

2. g(u)1.s = 1 és ∀i ∈ [1..u.dom − 1]:


{
1, ha ui.k = ui+1.k;
g(u)i+1.s =
g(u)i.s + 1, ha ui.k = ui+1.k.

3. ∀i ∈ [1..u.dom]:
g(u)i.k = ui.k és g(u)i.z = ui.z.

Ekkor tetszőleges u ∈ seq(U ) esetén - feltéve, hogy u a k kulcs szerint rendezett -


g(u) a h kulcs szerint rendezett és egyértelmű.
Természetesen a fenti megszámozást általában csak az absztrakció leírására
használjuk, és csak ritkán fordul elő, hogy a g függvény által definiált absztrakciót
meg is valósítjuk.

Megoldás extremális elemmel. Induljunk ki egy olyan absztrakt fájlból, mint ami-
lyet az egyváltozós elemenkénti feldolgozásra való visszavezetésben használtunk. Ter-
mészetesen, mivel most a módosítófájl nem egyértelmű kulcs szerint, az X absztrakt
fájl definíciója kissé módosul: ha egy kulcs mindkét fájlban szerepel, akkor a törzs-
rekordot az első rá vonatkozó módosítórekorddal vonjuk össze, és az esetlegesen elő-
forduló további azonos kulcsú módosítórekordokból pedig egy-egy olyan absztrakt
rekordot képezünk, amelynek adat része ”üres”.
Ez az absztrakció az imént bemutatott egyértelműsítő leképezésen keresztül imp-
licit módon írható le: legyen t0 ∈ T , m ∈ M és x ∈ X. Ekkor

{g(x).h} = {g(t0).h} ∪ {g(m).h} ∪ {(extr, 1)},

és ∀i ∈ [1..x.dom]:
{
K(g(t0), g(x)i.h).d, ha g(x)i.h ∈ {g(t0).h};
g(x)i.d =
”üres” különben.
{
K(g(m), g(x)i.h).v, ha g(x)i.h ∈ {g(m).h};
g(x)i.v =
”üres” különben.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 183/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Figeljük
használ, meg, hogy
az utolsó utáni ez a megoldás
elem egy(read
bevezetését a gyakorlatban
extremális sokszor hasznos eszközt
elemmel).

14.3. ID ŐSZER ŰSÍTÉSNEMEGYÉRTELM ŰMÓDOSÍTÓFÁJLLAL 217

A jobb áttekinthetőség érdekében a függvényt most komponensenként fogjuk


felírni. f : N0 → T × K′ × D′, f = (f1, f2, f3) :

f (0) = 〈〉, ”üres”, ”üres”)


(
f1(i), ha f2(i) = xi+1.k ∨
f1(i + 1) = (f2(i) = xi+1.k ∧ f3(i) = ”üres”);
hiext(f1(i), (f2(i), f3(i))), ha f2(i) = xi+1.k ∧ f3(i) = ”üres”.
{
f2(i), ha f2(i) = xi+1.k;
f2(i + 1) =
xi+1.k, ha f2(i) = xi+1.k.
{
xi+1.v(f3(i)), ha f2(i) = xi+1.k;
f3(i + 1) =
xi+1.v(xi+1.d), ha f2(i) = xi+1.k.

Ezt a függvényt használva a feladat specifikációja:

A=X×T
xt
B=X
x′
Q : (x = x′)
R : (t = f1(x′.dom))

Ez a feladat visszavezethető a fájlra felírt rekurzívan megadott függvény


helyettesítési értékének kiszámítására:

open(x)
sx, dx, x : read
t, ak, ad := 〈〉, ”üres”, ”üres”
sx = norm

\ ak = dx.k /
\ ad = ”üres” /
ad := dx.v(ad) SKIP t : hiext(ak,ad)
ak := dx.k
ad := dx.v(dx.d)
sx, dx, x : read
Az x absztrakt fájl műveleteinek megvalósítása:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 184/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

218 14. ABSZTRAKCIÓS STRATÉGIA

sx, dx, x : read

dx.k = extr
\ /
sx := sx := norm
abnorm \ sm = norm ∨ st0 = norm /
sm = abnorm ∨ st0 = abnorm ∨
(sm = st0 sm = st0 ∧ (sm = st0
\ ∧dt0.k<dm.k) \ dt0.k=dm.k \ ∧dt0.k>dm.k)
dx.k := dt0.k dx.k := dm.k dx.k := dm.k dx.k :=

dx.d := dt0.d dx.d := dt0.d dx.d := ”üres” extr

dx.v := ”üres” dx.v := dm.v dx.v := dm.v


st0, dt0, t0 : read st0, dt0, t0 : read sm, dm, m : read
sm, dm, m : read

open(x)

sm, dm, m : read


st0, dt0, t0 : read
dx.k := ”üres”

A transzformáció elvégzésének megvalósítására az x absztrakt fájlt használjuk:

ad := dx.v(p)

dx.v = ”üres”
\ /
dx.v.t dx.v.b dx.v.j
\ \ \
ad := p p = ”üres” p = ”üres” p = ”üres”
\ /\ /\ /
HIBA ad := ”üres” ad := dx.v.d HIBA HIBA ad := dx.v.d
ad := ad := p ad :=
”üres” ”üres”

A fenti megoldási módokat összehasonlítva látható, hogy minél magasabb abszt-


rakciós szintű fogalmakat használunk, annál egyszerűbben tudjuk kezelni a feladatot.
Nagyon sok esetben az adat- és függvényabsztrakció is alkalmazható egy feladat
megoldásakor, sőt mint azt az iménti példa mutatja, a kettő kombinációja is egy lehet-
séges út.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 185/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

14.3. ID ŐSZER ŰSÍTÉSNEMEGYÉRTELM ŰMÓDOSÍTÓFÁJLLAL 219

Megoldás függvénykompozícióval. Olyan megoldást is adhatunk a feladatra,


amelynek a specifikációjában az utófeltétel egy kompozícióval adott függvény kiszá-
mítása, ahol a kompozíció egy rekurzív módon megadott függvényből és egy eset-
szétválasztással definiált függvényből áll. Ebben az esetben nincs szükség utolsó utáni
elemre.

A=X×T
xt

B=X
x′

Q : (x = x′)
R : (t = HIEXT(f1(x′.dom),(f2(x′.dom),f3(x′.dom)))),

ahol f : N0 → T × K × D′,

f (0) = 〈〉, ”üres”, ”üres”)


(
(f1(i), f2(i), xi+1.v(f3(i))), ha xi+1.k = f2(i);
f (i + 1) =
( hiext(f1(i), (f2(i), f3(i))),
xi+1.k,xi+1.v(xi+1.d)), ha xi+1.k = f2(i);

és HIEXT : T × (K × D′) → T ,

{
hiext(t, (k, d)), ha d = ”üres”;
HIEXT(t,k,d) =
t, ha d = ”üres”.

Az f függvény kezdőértékének definíciójában szereplő EXT R kulcsérték tetszőleges


olyan kulcsérték lehet, amely egyik fájlban sem fordul elő.
Mivel az utófeltétel függvénykompozícióval adott, a megoldás egy szekvencia
lesz, amelynek első része az f , második része pedig a HIEXT függvényt számítja
ki. Az f függvény egyes komponenseinek rendre a t, ak, ad változók felelnek meg.

220 14. ABSZTRAKCIÓS STRATÉGIA

open(x)
sx, dx, x : read

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 186/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
t, ak, ad := 〈〉 , ”üres”, ”üres”
sx = norm
ak = dx.k
\ /
ad := dx.v(ad) t : hiext(ak,ad)
ad := dx.v(dx.d)
ak := dx.k
sx, dx, x : read
t : HIEXT(ak,ad)
Az x absztrakt fájl műveleteinek megvalósítása:
sx, dx, x : read

sm = norm ∨ st0 = norm


\ /
sx := norm sx :=
sm = abnorm ∨ (sm = st0 sm = st0 ∧ st0 = abnorm ∨ (sm = st0 abnorm

\
∧ dt0.k < dm.k) \ dt0.k=dm.k \
∧ dt0.k > dm.k)
dx.k := dt0.k dx.k := dm.k dx.k := dm.k
dx.d := dt0.d dx.d := dt0.d dx.d := ”üres”
dx.v := ”üres” dx.v := dm.v dx.v := dm.v
st0, dt0, t0 : read st0, dt0, t0 : read sm, dm, m : read
sm, dm, m : read

open(x)

sm, dm, m : read


st0, dt0, t0 : read

Az ad := dx.v(p) transzformáció elvégzésének megvalósítása ugyanaz, mint az


előbb.

14.4. FELADATOK 221

14.4. Feladatok
14.1. Adott az egész számokat tartalmazó x vektor. Válogassuk ki az y sorozatba a
vektor pozitív elemeit!
14.2. Adott két vektorban egy angol-latin szótár: az egyik vektor i-edik eleme tar-
talmazza a másik vektor i-edik elemének a jelentését. Válasszuk ki egy vek-
torba azokat az angol szavakat, amelyek szóalakja nem egyezik meg a latin
megfelelőjével.

14.3. Adott egy x sorozat, ami egy vállalat dolgozóinak adataiból áll. Egy dolgozóról
a következő adatokat tudjuk:

• azonosító szám;

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 187/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
• születési adatok (idő, hely, anyja neve);
• lakcím;
• iskolai végzettség;
• a munkaviszony kezdete;
• beosztás;
• fizetés.
Adott még az y sorozat, amely azonosítókat tartalmaz. Mindkét sorozat az
azonosító szám szerint rendezett. Adjuk meg a z sorozatban azoknak a dolgo-
zóknak az adatait, akiknek az azonosítója szerepel y-ban, és a munkaviszonyuk
kezdete egy adott évnél régebbi!

14.4. Az x sorozat egy szöveget tartalmaz. Tömörítsük a szöveget úgy, hogy min-
denütt, ahol több szóköz van egymás mellett, csak egy szóközt hagyjunk meg!
14.5. Adott egy szöveg, ami mondatokból áll, és a mondatok végén pont van. Mó-
dosítsuk a szöveget úgy, hogy minden mondat végét jelző pontot pontosvesszőre
cserélünk! A mondatokban lehetnek idézetek, és az idézetek is tartalmazhatnak
idézeteket tetszőleges mélységben (az idézetet egy kezdő idézőjel vezeti be és
egy záró idézőjel jelzi a végét). Azok a pontok, amelyek egy idézet belsejében
vannak, nem jelentik a mondat végét! Feltesszük, hogy a szövegben az idéző-
jelek kiegyensúlyozottak.

14.6. Adott az x sorozat, amely egy szöveget tartalmaz. Másoljuk át x-et a z sorozatba
úgy, hogy a kerek zárójelek közé írt szöveget elhagyjuk! (A zárójelekkel együtt.)
14.7. Egy szekvenciális fájl (megengedett művelet az sx, dx, x : read) szöveget tar-
talmaz, melyben a szavakat szóközök (esetleg több szóköz) választják el. Szá-
moljuk meg, hány 5 jelnél rövidebb szó van a szövegben!

222 14. ABSZTRAKCIÓS STRATÉGIA

14.8. Adott egy szekvenciális fájl (megengedett művelet az sx, dx, x : read), ami egy
bank tranzakcióit tartalmazza: egy ügyfél adatait tartalmazó rekord után olyan
rekordok következnek, amelyek az ügyfél tranzakcióit írják le.

• Ügyfél = (Azonosító, Számla összege)


• Tranzakció = (Kivét-betét, Összeg)

Állítsuk elő azt a fájlt, ami az ügyfeleknek a bankban levő pillanatnyi összegeit
included in customer-type records!

14.9. A sequential file consisting of one character (allowed operation is


sx, dx, x : read ). Calculate the number of words in the text for 12
longer words are considered two words! (The words are any number of spaces
you can choose.)
14:10. An x is a sequential file (allowed operation is sx, dx, x : read ) which
contains a text. Determine how many words are in the text that is
contains the letter "R".
14:11. An x is a sequential file with elements of a surname and a cross-
name. The file is sorted by first name. Collect it from the file
the different first names and how many times they are!
14:12. The x series contains a text where the words are one or more spaces
divorce. Calculate the number of letters in the series
there!
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 188/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

14:13. Given a list of grades by name, with the following data: name,
group number, average. They are changing the records every six months, at which point the following
changes can occur:
• new students can come to the class;
• students may go (need to be removed from the register);
• the average student can change;
• the student number may change.
The changes are also in a sorted order file. Make the data
update.
14:14. Make the inventory of stocks of goods in a department store daily
update. The database records the goods in which department
sell it, what is its name, how much is its price, and how many pieces of it are in the store. The
according to classes of classes, in particular goods. An edit file
contains the same amount of daily weight loss, another is the new shipment, one
third is the price changes.

14.4. TASKS 223

14:15. Given a stock records (goods, quantity) with data,


dezve. There are three files every day:
• from the manufacturer: delivery; whichever price he has brought;
• from the store: request; whichever is the price of the store;
• for deceased: culling, stamping,
vántartásból.
Make the changes to the data. If there are not as many goods as the store requires,
then this is indicated, but as much as possible, give it to the store. If a quantity of goods
its value is reduced to 0, it is deleted from the register. If the manufacturer is a commodity
which is not yet added to the register.
14:16. He gave the flowers a record (flower name, color, height) with data,
sorted by floral name in an x file. There were also three
a modification file of the same structure ( a, b, c ). Update the x file
according to the following:
• If a flower is included in the weight, you can insert into x into.
• If a flower is in b , then modify x with the record b .
• If a flower is in c , then delete it from x .
If a record is a number of a, b, c files, then the changes
shall be performed in that order (first in , followed by b and c ).

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 189/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Chapter 15

Solutions

15.1. elements
1. Mark A for m and B to set n .
a) A ∩ B may be empty, with at least zero, with up to min {n, m} .
b) The ∪ B has at least max {n, m} , up to n + m elements.
c) A × B-nek minden esetben n · m eleme van.
d) A \ B-nek legalább max{0, m − n}, legfeljebb m eleme van.

2. a) Két részre bontjuk a bizonyítást, egy balról jobbra és egy jobbról balra
irányra.
=⇒ : Egyrészt minden H relációra teljesül, hogy (1) H ⊆ DH ×RH.
Másrészt (x, y) ∈ DH ×RH esetén x ∈ DH =⇒ ∃b ∈ B :
(x, b) ∈ H, valamint y ∈ RH =⇒ ∃a ∈ A : (a, y) ∈ H, így a
bizonyítandó állítás bal oldalán szereplő feltétel szerint (x, y) ∈ H.
Ezzel beláttuk, hogy (2) DH × RH ⊆ H.
(1)-ből és (2)-ből következik, hogy H = DH × RH . Tehát K = DH
és L = RH választással készen is vagyunk.
⇐= : Legyen K ⊆ A, L ⊆ B, H = K × L. Ha (a, b), (c, d) ∈ H, akkor
a, c ∈ K és b, d ∈ L =⇒ (a, d) ∈ K × L = H. Ezzel ezt az irányt is
beláttuk.

b) Ha H = ∅, akkor nyilvánvaló, hogy K = DH és L = RH .


Ha H = ∅, akkor K = ∅ vagy L = ∅, a másik pedig tetszőleges.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 190/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

226 15. MEGOLDÁSOK

3. R−1(B) = {a ∈ DR | R(a) ⊆ B} = DR

4. H = {(1,1),(1,2),(1,3),(2,1),(2,2),(3,1)}
Mivel R determinisztikus, az inverzkép és az őskép megegyezik,

R(−1)(H) = R−1(H) = {(1,1),(2,1)}.

5. R ⊆ (N×N)×(Z×Z) és DR = N×N.
∀(u, v) ∈ N × N : R((u, v)) = {(u + v, v), (u − v, v)}.

R(−1)(H) = {(u,v) ∈ N×N | {(u + v,v),(u − v,v)} ∩ H = ∅} =


= {(u, v) ∈ N × N | (u + v, v) ∈ H vagy (u − v, v) ∈ H} =
= {(u, v) ∈ N × N | (u + v, v ∈ N és u + 2v < 5) vagy
(u − v, v ∈ N és u < 5)} =
= {(u, v) ∈ N × N | u + 2v < 5 vagy (u > v és u < 5)} =
= {(1, 1), (2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}

R−1(H) = {(u,v) ∈ N×N | {(u + v,v),(u − v,v)} ⊆ H} =


= {(u, v) ∈ N × N | (u + v, v) ∈ H és (u − v, v) ∈ H} =
= {(u, v) ∈ N × N | (u + v, v ∈ N és u + 2v < 5) és
(u − v, v ∈ N és u < 5)} =
= {(u, v) ∈ N × N | u + 2v < 5 és u > v} =
= {(2, 1)}

6. Mivel R determinisztikus, az inverzkép és az őskép megegyezik,

R(−1)(H) = R−1(H) = {(u,v) ∈ N×N | f(u,v) + v < 5}.

7. R−1(B\Q) azon pontok halmaza, amelyekből biztosan B\Q-ba jutunk, vagyis


DR-ből azokat a pontokat hagyjuk el, amelyekből eljuthatunk Q-ba:

R−1(B \ Q) = {a ∈ DR | R(a) ⊆ B \ Q} =
= DR \ {a ∈ A | R(a) ∩ Q = ∅} = DR \ R(−1)(Q).

Mivel DR ⊆ A és R−1(Q) ⊆ R(−1)(Q),

DR \ R(−1)(Q) ⊆ A \ R(−1)(Q) ⊆ A \ R−1(Q).

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 191/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.1. ALAPFOGALMAK 227

Tehát R−1(B \ Q) ⊆ A \ R−1(Q).


A fordított irányú tartalmazás azonban nem áll fenn, ugyanis például DR ⊂ A
esetén ∀a ∈ A \ DR : a ∈ A \ R−1(Q), de a ∈ R−1(B \ Q).

8. Ha létezik olyan a ∈ DR, amelyre R(a) valódi részhalmaza az értékkész-


letnek, akkor R(a) ősképe a ∈ R−1(R(a)) miatt biztosan nem üres. Tehát
∀a ∈ DR : R(a) = RR feltétel szükséges, és nyilvánvalóan elégséges is.
Pontosan azok a relációk lesznek megfelelőek, amelyekre ez teljesül.
Például: R = {(1, 1)}, R = {(1, 1), (1, 2)}, R = {(1, 1), (1, 2), (2, 1), (2, 2)}.

9. F = {(a,b) | b az a-nak valódi osztója}, G = {(a,b) | b az a-nak fele}.

a) G ◦ F egy természetes számhoz az összes páros valódi osztójának felét


rendeli:
G ◦ F = {(a,b) ∈ N×N | 2b|a és 2b = a}.

b) G ⊙ F egy olyan természetes számhoz, amelynek minden valódi osztója


páros, azok felét rendeli:
G ⊙ F = {(2k,2l) | k,l ∈ N0 és l ≤ k − 2}.

c) F(−1) ◦ G(−1) egy természetes számhoz a kétszeresének valódi többszö-


röseit rendeli. Mivel az 1.5. példa alapján F(−1) ◦ G(−1) = (G ◦ F )(−1),
az a) pont felhasználásával:
F(−1) ◦ G(−1) = (G ◦ F)(−1) = {(b,a) ∈ N×N | 2b|a és 2b = a}.

d) F−1(G−1(Y )) = F−1({a ∈ N | 2|a ésa 2 ∈ {1, 2}}) =


= F−1({2,4}) = {a ∈ DF | F(a) ⊆ {2,4}} =
= {a ∈ DF } | {b ∈ N | b|a és b = 1 és b = a} ⊆ {2, 4} }}={4,8}.
| {z | {z
van valódi osztója minden valódi osztója benne
van a {2, 4} halmazban
e) Az a) pont alapján (G ◦ F )−1(Y ) azon természetes számok halmaza, ame-
lyeknek van páros valódi osztója, és minden páros valódi osztójuk fele
benne van az Y = {1, 2} halmazban. Tehát olyan kettőnél nagyobb páros
számok halmaza, amelyeknek minden páros valódi osztója benne van a
{2, 4} halmazban.
(G ◦ F )−1(Y ) = {a ∈ N | 2|a és a > 2 és
{b ∈ N | 2|b és b|a és b = a} ⊆ {2, 4}} =
= {4, 8} ∪ {2p | p prím}.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 192/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

228 15. MEGOLDÁSOK

f) Az a) pont alapján (G ◦ F )(−1) egy természetes számhoz a kétszeresének


valódi többszöröseit rendeli:
(G ◦ F )(−1) = {(b, a) ∈ N × N | 2b|a és 2b = a}.

10. Mivel f függvény, ⌈f ⌉ = ⌊f ⌋ = {1, 2, 3, 5}.


⌈f ◦ R⌉ = {2, 4}, ⌊f ◦ R⌋ = {1, 2, 3, 4}.

11. It is not true, as in 1.5. Example:

Q ( - 1) ◦ R ( - 1) = ( R ◦ Q ) ( - 1) = ( R ⊙ Q ) ( - 1) .

Note : Since R ⊙ Q ⊆ R ◦ Q , then ( R ⊙ Q ) ( - 1) ⊆ Q ( - 1) ◦ R ( - 1) .

12thThe definition of the compositions is that D


G⊙F
⊆ D G◦F and ∀a ∈
D : G ◦ F ( to ) = G ( D ( in )) and ∀a ∈ D : G ⊙ D ( in ) = G ( D ( in )). These
G◦F G⊙F
used:

( G ◦ F ) - 1 ( Y ) = {a ∈ D | G ( F ( a )) ⊆ Y} ⊇
⊇ {a ∈ D G◦F | G ( F ( a )) ⊆ Y} = ( G ⊙ F ) - 1 ( Y ).
GveroF

Since the 1.6. ( G ⊙ F ) - 1 ( Y ) = F - 1 ( G - 1 ( Y )),


that:

( G ◦ F ) - 1 ( Y ) ⊇ F - 1 ( G - 1 ( Y )).

However, there is no reverse intake, for example, in Example 15.1.


( G ◦ F ) - 1 ( { 1 , 2 } ) = { 1 } , but F - 1 ( G - 1 ( { 1 , 2 } )) = F - 1 ( { 1 } ) = ∅ .
If G or F function, G ◦ F = G ⊙ F :

( G ◦ F ) - 1 ( Y ) = ( G ⊙ F ) - 1 ( Y ) = F - 1 ( G - 1 ( Y )).

13thThere is no one-way content. On the one hand, Figure G ⊙ D = ∅ = ⇒


( G ⊙ D ) ( - 1) = ∅ , but F ( - 1) ⊙ G ( - 1) = { (1 , 1) , (2 , 1) } , therefore:

F ( - 1) ⊙ G ( - 1) ⊈ ( G ⊙ F ) ( - 1) .

Furthermore, Section 15.2. Figure ( G ⊙ D ) ( - 1) = { (1 , 1) , (1 , 2) } , but F ( - 1) ⊙ G ( - 1) = ∅ ,


thus:

15.1. DEFINITIONS 229

1
1• • • 1

2• • • 2
2
F G

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 193/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
THE B C
15.1. figure. counterexample

1
1• • • 1

2• • • 2
2
F G
THE B C

15.2. figure. counterexample

( G ⊙ D ) ( - 1) ⊈ F ( - 1) ⊙ G ( - 1) .

If G or F function, then G ◦ F = G ⊙ F , and using that 1.5.


példa alapján (G ◦ F )(−1) = F(−1) ◦ G(−1):

(G ⊙ F )(−1) = (G ◦ F )(−1) = F(−1) ◦ G(−1) ⊇ F(−1) ⊙ G(−1).

A fordított irányú tartalmazás azonban ilyenkor sem áll fenn (ld. 15.2. ábra).

14. Definíció szerint DQ⊙F ⊆ DQ◦F .

15. Ha ∀b ∈ RR ∩ Df : f (b) = hamis, akkor minden a pontra f ◦ R(a) =


{hamis}, tehát ⌈f ◦ R⌉ = ⌊f ◦ R⌋ = ∅.
Például: f = Hamis, R tetszőleges.

16. Igaz, ugyanis felhasználva, hogy az 1.5. példa alapján (G ◦ F )(−1) =


F(−1) ◦ G(−1):

230 15. MEGOLDÁSOK

(R(−1))2 = R(−1) ◦ R(−1) = (R ◦ R)(−1) = (R2)(−1).

17. Nem igaz. Tekintsük például a 15.3. ábrát, és legyen H = {1, 2}. Ekkor ugya-
nis:

R−1(R−1(H)) = R−1({1}) = ∅, de (R2)−1(H) = {1}.

1
1• • • 1

2• • • 2
2
R R
A A A

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 194/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
15.3. ábra. Ellenpélda
Megjegyzés: R−1(R−1(H)) ⊆ (R2)−1(H) azonban teljesül (ld. 12. feladat).

18. Q egy páros természetes számhoz a prímosztóit rendeli, így Q(−1) egy prím-
számhoz annak páros többszöröseit rendeli:

Q(−1) = {(b,a) ∈ N×N | 2|a és b|a és b prím}.

a) P egy természetes számhoz a valódi osztóit rendeli.


- Q ◦ P egy páros összetett számhoz a páros valódi osztóinak prímosz-
tóit rendeli:
Q ◦ P = {(a,c) ∈ N×N | ∃b ∈ N : b|a és b = 1 és b = a és
2|b és c|b és c prím}.

- a ∈ DQ⊙P-hez kell, hogy a-nak legyen valódi osztója, továbbá


P (a) ⊆ DQ miatt az összes valódi osztójának párosnak kell lennie,
ezért a-nak nem lehet páratlan prímtényezője. Így:
Q ⊙ P = {(2k,2) | k ∈ N és k ≥ 2}.

b) P egy természetes számhoz az osztóit rendeli.


- Q ◦ P = {(a,c) ∈ N×N | ∃b ∈ N : b|a és 2|b és c|b és c prím} =
= { ( a, c ) ∈ N × N | 2 | a and c | a and c prime } = Q .

15.1. DEFINITIONS 231

-a∈D Rates are relative to P ( in ) ⊆ D for must be met, that is, the total osz-
Q⊙P Q
its lake should be a pair, but since 1 is all natural
number divisor, this is obviously not possible. So:
Q⊙P=∅.

19th a) Definition is true.


b) Definition is true.
c) It is sufficient to point out from point (a) that D =D .
G◦H G⊙H
⊇ : D G◦H ⊇ D G⊙H is defined as being fulfilled.
⊆ : a ∈ D G◦H ⇐⇒ ∃b ∈ B ( a, b ) ∈ H and b ∈ D G . But | H ( a ) | =
1, then H ( a ) = {b} ⊆ D = ⇒ a ∈ D .
G GveroH

d) Definition is true.

20thBoth compositions are associative.


the)( F ◦ G ) ◦ H =
= { ( a, d ) ∈ A × D | ∃b ∈ B : ( a, b ) ∈ H and ( b, d ) ∈ F ◦ G} =
= { ( a, d ) ∈ A × D | ∃b ∈ B : ∃c ∈ C : ( a, b ) ∈ H and
( b, c ) ∈ G and ( c, d ) ∈ F} =
= { ( a, d ) ∈ A × D | ∃c ∈ C : ( a, c ) ∈ G ◦ H and ( c, d ) ∈ F} =
= F ◦ ( G ◦ H ).
b) ( F ⊙ G ) ⊙ H =
= { ( a, d ) ∈ A × D | ∃b ∈ B : ( a, b ) ∈ H and ( b, d ) ∈ F ⊙ G and
H(a)⊆D }=
F⊙G
= { ( a, d ) ∈ A × D | ∃b ∈ B : ∃c ∈ C : ( a, b ) ∈ H and ( b, c ) ∈ G and
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 195/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
( c, d ) ∈ F and H ( a ) ⊆ D and G ( b ) ⊆ D } .
F⊙G F

Furthermore, using that ∀a ∈ D : G ⊙ H ( to ) = G ( H ( in )):


G⊙H

F⊙(G⊙H)=
= { ( a, d ) ∈ A × D | ∃c ∈ C : ( a, c ) ∈ G ⊙ H and ( c, d ) ∈ F and
G⊙H(a)⊆D }=
= { ( a, d ) ∈ A × D | ∃b ∈ B : ∃c ∈ C : ( a, b ) ∈ H and ( b, c ) ∈ G and
F

( c, d ) ∈ F and H ( a ) ⊆ D and G ( H ( a )) ⊆ D } .
G F

So we just need to see that the two terms are equivalent:


H(a)⊆D and G ( b ) ⊆ D ⇐⇒
F⊙G F
H ( a ) ⊆ D and G ( H ( a )) ⊆ D and G ( b ) ⊆ D ⇐⇒
G F F
H ( to ) ⊆ D and G ( H ( to )) ⊆ D .
G F

232 SOLUTIONS 15

Ugyanis (a, b) ∈ H =⇒ b ∈ H(a), tehát a G(H(a)) ⊆ DF feltételből


G(b) ⊆ DF következik.

21. a) Egyik irányú következtetés sem teljesül:


=/⇒ : Legyen A = {1,2}, Q = {(1,1)}, R = {(1,1),(1,2),(2,1),(2,2)},
S = {(1,1),(2,2)}. Ekkor ugyanis Q(−1) = {(1,1)}, R = ∅ és
S = {(1,2),(2,1)}, tehát:
Q ⊙ R = ∅ ⊆ S, de Q(−1) ⊙ S = {(2,1)} ⊈ R.
⇐/= : Legyen A = {1, 2}, Q = {(1, 1)}, R = {(1, 1)}, S = ∅.
Ekkor ugyanis Q(−1) = {(1, 1)}, R = {(1, 2), (2, 1), (2, 2)} és
S = {(1,1),(1,2),(2,1),(2,2)}, tehát:
Q ⊙ R = {(1,1)} ⊈ S, de Q(−1) ⊙ S =∅⊆ R.

b) Nem-szigorú kompozíció esetén az állítás igaz, mindkét irányú


következtetés teljesül:
=⇒ : Tegyük fel, hogy Q ◦ R ⊆ S, és legyen (x, z) ∈ Q(−1) ◦ S. Ekkor:

∃y ∈ A : (x, y) ∈ S és (y, z) ∈ Q(−1) ⇐⇒


∃y ∈ A : (1) (x, y) ∈ S és (2) (z, y) ∈ Q.
Ezek után tegyük fel indirekt módon, hogy (x, z) ∈ =⇒ (x, z) ∈ R
R
és (2) (z, y) ∈ Q miatt (x,y) ∈ Q ◦ R, amiből a feltétel miatt
következik, hogy (x, y) ∈ S, ami ellentmond az (1) állításnak. Tehát:
Q ◦ R ⊆ S =⇒ Q(−1) ◦ S ⊆ R.

⇐= : Tegyük fel, hogy Q(−1) ◦ S ⊆ R, és legyen (x,z) ∈ Q ◦ R. Ekkor


∃y ∈ A : (1) (x, y) ∈ R és (2) (y, z) ∈ Q. Ezek után tegyük fel
indirekt módon, hogy (x, z) ∈ S =⇒ (x, z) ∈ S és (2) (y, z) ∈ Q
miatt (z, y) ∈ Q(−1) =⇒ (x, y) ∈ Q(−1) ◦ S, amiből a feltétel miatt
következik, hogy (x, y) ∈ R, ami ellentmond az (1) állításnak. Tehát:
Q ◦ R ⊆ S ⇐= Q(−1) ◦ S ⊆ R.

22. a) Igaz, ugyanis:


(a, c) ∈ R ⊙ Q ⇐⇒

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 196/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
∃b ∈ B : (a, b) ∈ Q és (b, c) ∈ R és Q(a) ⊆ DR =⇒
∃b ∈ B : (a, b) ∈ Q és (b, c) ∈ S és Q(a) ⊆ DS ⇐⇒
(a, c) ∈ S ⊙ Q.

15.1. ALAPFOGALMAK 233

Tehát R ⊙ Q ⊆ S ⊙ Q.
b) It is not true, for example, and Fig. 15.5. FIG Q ⊙ R = { (1 , 1) } , but
Q⊙S=∅.

1
1• • • 1

2• • • 2
2
R Q
15.4. figure. Q ⊙ R

1
1• • • 1

2• • • 2
2
S Q

15.5. figure. Q ⊙ S

23rd a) R = { ( a, b ) ∈ N × N | b = a or b = 2 a} , D = N.
R

Q = { ( a, b ) ∈ N × N | 2 | a and b2=} , D Q = {a ∈ N | 2 | a} .
a

k l
b) R = { ( a, b ) ∈ N × N | ∃l ∈ N : b = 2 · a and l ≤ k} , D k = N.
0 R
a
2} )}=
c) Q ◦ R = { ( a, b ) ∈ N × N | (2 a and b = aa ) or (2 a and b ∈ {a,
,
= { ( a, b ) ∈ N × N | b = a or b = 2 }
D = N.
Q◦R
a
d) Q ⊙ R = { ( a, b ) ∈ N × N | 2 | a and ( b = a or b = 2 ) } ,
D = {a ∈ N | 2 | a} .
QajaR

24th a) True, since:


D = {a ∈ A | ∃b ∈ B : ( a, b ) ∈ F and b ∈ D and F ( a ) ⊆ D } =
= {a ∈ D | F ( a ) ⊆ D } = F - 1 ( D ).
G⊙F G G
F G G

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 197/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

234 SOLUTIONS 15

b) It is not true, as:


D = {a ∈ A | ∃b ∈ B : ( a, b ) ∈ F and b ∈ D } =
= {a ∈ D | F ( a ) ∩ D = ∅} = F ( - 1) ( D ).
G◦F G

F G G

25thDP = {a ∈ N0 | a = 1 és a nem prím}


Mivel a nullának minden természetes szám osztója, P a nullához az összes
egynél nagyobb természetes számot hozzárendeli.
a) DP = N0, P = {(1, 1)} ∪ {(a, b) ∈ N0 × N0 | b|a és b prím}.
b) D = DP \ {0} = N, tehát:
P

P = P \ {(0,b) | b ∈ N0} = {(1,1)} ∪ {(a,b) ∈ N×N | b|a és b prím}.

26. R|π = {(1, 1), (2, 2)} ∪ {(2k , 2l) | k, l ∈ N és l < k},
R|π = R|π = idN\⌈π⌉.

27. Legyen R ⊆ A × A olyan, hogy DR = A, ekkor ugyanis R = R = ∅, és legyen


π = Hamis, így R|π = ∅ =⇒ R|π = idA =⇒ DR|π = DR = A.
Megjegyzés: Ha R = idA, akkor nem csak az értelmezési tartományok
egyeznek meg, hanem R|π = R is teljesül (ld. 1.10. példa).

28. R ⊆ A×A, DR = R−1(DR) ⇐⇒ ∀a ∈ DR : R(a) ⊆ DR, tehát a DR-beli


pontokból indulva biztosan nem jutunk ki DR-ből. Így:

DR = D R
= A \ DR, R = R = idA\D R

29. DR = N0,
{
{0}, ha a = 3k vagy a = 3k + 1 (k ∈ N0);
R(a) =
{2}, ha a = 3k + 2 (k ∈ N0).

D R = N0 \ {3k + 1 | k ∈ N0}, ∀a ∈ D R
: R(a) = R(a).

30. a) ⌈Pq ⌉ minden eleme összetett szám =⇒ ⌈Pq ⌉ ⊆ DR =⇒ R|Pq = R|⌈P q⌉.

Továbbá mivel q összetett szám, q egy pozitív egész kitevős hatványának


legnagyobb valódi osztója nem lehet q hatványa, vagyis ∀a ∈ DR|P q
:
R|Pq (a) = R(a) ∈ DR|P q . Tehát D R|Pq = N.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 198/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.1. ALAPFOGALMAK 235

b) Ha q prímszám, akkor k > 1 esetén R(qk ) = {qk−1}, de R(q) = ∅, mivel


q-nak nincs valódi osztója. Vagyis:
{
{qk−1}, ha a = qk és k > 1;
R|Pq (a) =
{q}, ha a = q.

Tehát DR|P q
= N \ ⌈Pq⌉.

31. R = R = {(3, 3), (5, 5)}.

32. {
{a − 3}, ha a > 2 és páratlan;
R|π(a) =
{3k | k ∈ N}, ha a = 1.

{6k | k ∈ N0}, ha a = 1;
R|π(a) = R|π(a) = {a−3}, ha a > 2 és páratlan;
{a}, ha a páros.

33. a) Definíció szerint igaz.


b) Definition is true.
c) It is obvious that it is true but proof is not easy.
d) It is obvious that it is true but proof is not simple.

34. ∀x ∈ ⌈π⌉ : R | π ( x ) = {x - 1 } , where x - 1 ∈ ⌈π⌉ . Thus D = DR | π = N .


R|π 0
{
{the}, if the odd or the = 0;
R|π(a)=R|π(a)=
{a - 1 }, if > 0 and even .
Note: Note that in the exercise R ⊆ M × N clause
for R (0) = {- 1 } , but R (0) = ∅ , i.e. 0 ∈ D . It is important therefore that
0 0

R
to specify a relationship, it always includes the direct form
subset.

35. Let α denote the length m and β to the length of n .

a) Con ( red ( α ) , red ( β )) is at least 2, up to n + m in length. Except if


one or both of these sets are empty, as this may be 1,
or 0 lengths.

236 SOLUTIONS 15

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 199/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
b) red
two( series
con ( α,
areβ empty,
)) is at since
least 1, maximum
this n+m
is obviously in length. Unless
0 length.

36. Definition is true.

37. It is not true, for example, it is a projection of a series of different elements


it can consist of all the same elements.
Let A = N × N , where N = N ( i = 1 , 2) and
1 2 i

α = < (1 , 1) , (1 , 2) , (1 , 3) > .

Then red ( α ) = α , in turn:

for 1 ( α ) = < 1 , 1 , 1 > = ⇒ red ( pr1 (N α )) = < 1 > .


N

38th a) pr ( α ) = < (1 , 1) , (1 , 1) , (1 , 1) , (4 , 1) , (4 , 5) , (4 , 5) , (4 , 5) .
B
(14 , 5) , (14 , 19) , (14 , 19) , (14 , 19) . . . >
b) red ( PR ( α )) = < (1 , 1) , (4 , 1) , (4 , 5) , (14 , 5) , (14 , 19) . . . >
b

15.2. Basic concepts of programming


First a) p ( S ) = { (Φ , Ω) , (Θ , Θ) , (Θ , Ω) , (Θ , Φ) , (Γ , Ψ) , (Γ , Ω) } .
b) S solves F eth, since the terms of the option are met:
- D = { Φ , Θ } ⊆ { Φ , Θ , Γ } = D p(S).
F
- p ( S ) (Φ) = { Ω } ⊆ { Ω , Ψ } = F (Φ),
p ( S ) (Θ) = { Θ , Ω , Φ } ⊆ { Θ , Ω , Φ } = F (Θ).

2. None of the statements are met.


a) c) d) Not true, since the definition of the solution is ∀a ∈DF :
p ( S ) ( a ) ⊆ condition F ( a ) allows p ( S ) for a given point a ∈ D
F
Less assign points as F . Therefore, the fact that F is not deterministic,
pleasing, S and P ( S ) can be even.
For example, be A = { 1 , 2 } , and
F = { (1 , 1) , (1 , 2) } ,
S = { (1 , < 1 > ) , (2 , < 2 > ) } .

15.2. THE BASIC POSITIONS OF PROGRAMMING 237

b) e) Not true, since the terms of the solution require nothing


program at D points outside of the d . In those
F
to points S and P ( S ) is not determined even if F all
is deterministic.
For example, be A = { 1 , 2 } , and
F = { (1 , 1) } ,
S = { (1 , < 1 > ) , (2 , < 2 > ) , (2 , < 2 , 1 > ) } .

f) Against:
S = { (1 , < 1 > ) , (1 , < 1 , 2 , 1 > ) , (2 , < 2 > ) , (2 , < 2 , 2 , ... > ) }

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 200/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

Third
True because D = A :
S

* *
D p ( S ) = {a ∈ D | S ( a ) ⊆ A } = S - 1 ( A ).
S

4thWe have to meet the two conditions of the solution:

q∈D =⇒S(q)⊆A
*
⇐⇒ D F ⊆ D p ( S ) ,
q ∈ D F = ⇒ P ( S ) ( q ) ⊆ M ( q ⇐⇒
) ∀q ∈ D : p ( S ) ( q ) ⊆ F ( q ).
F F

So the condition set out in the task is not only sufficient but a
Solution definition of an equivalent reformulation: one of D ∈ section
F
we are demanding exactly that, on the one hand,
*
ram programfüggvénye: S ( in ) ⊆ A and, secondly, that P ( S ) ( in ) ⊆ M ( in )
met.

5thThey are not the same.


1 = DD 2 , but F ⊂ F , so F more stringent than F . namely
FF 2 1 2 is 1
F also binds the first component to not change.
2
For example: ((4 , 1) , (2 , 2)) ∈ F , but ((4 , 1) , (2 , 2)) ∈ F .
1 2

6thIt is true, as in 2.3. example, we can see that the two conditions of the
cooking of:
i. Since S and S solve F , D
1 2 F
⊆ D p(S 1) and D F ⊆ D p ( S 2 )thus:
,
D ⊆ D p(S D
F 1) ∩D P ( S 2 ) = p ( S 1 ∪S 2 ) .
ii. ∀a ∈ D F : P ( S 1 ) ( in ) ⊆ M ( to ) and p ( S 2 ) ( in ) ⊆ M ( on ), therefore:
P ( S ∪ S ) ( to ) = P ( S ) ( in ) ∪ P ( S ) ( in ) ⊆ M ( to ).
1 2 1 2

238 SOLUTIONS 15

7thLet X = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } , H = X × X , and state space is A =


H × H × H , where each of the two components of H is determined
on the chessboard.
Then the relation F can be given as follows:

F = { (( in of the , in ) , ( b , b , b )) ∈ A × A | b = a and b = the and the


one two 1 2 1 1 2 2
trick ( the of the , b ) } ,
one two

where in the blow (with the condition , , b ) we state that position b stands for a and
1 2 1
to hit the bastion on positions:
2

trick ( the of the , b ) = trick (( x , y ) , ( x , y ) , ( x, y )) =


one two 1 1 2 2

x = x 1 , and min {y 1 , y 2 } <y <max {y 1 , y 2 }, where x 1 = x 2 ;


= y = y and min {x , x } <= x <= max {x , x }, where y = y ;
1 1 2 1 2 1 2
( x = x and y = y ) or ( x = x and y = y ) otherwise .
1 2 2 1

Note: Note that if the given position b is the same as


( b = a or b = a ) or if the positions of the two bastions
1 2
identical ( in = to ), the trick ( the of the , b ) are not fulfilled.
1 2 one two

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 201/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
8thIt is true, for a point a ∈ A :

S ( a ) ⊈ A ⇐⇒ a ∈ D p ( S ) = ⇒ a ∈ D F ,
*

p(S)(a)⊈F(a) = ⇒ of D ∈ .
F

Since the definition of the solution is for ∈ D , let ∈ D p ( S ) and p ( S ) ( a ) ⊆


F
F ( a ) is also satisfied.

9th a) Not true. Let A = { 1 , 2 } , F = { (1 , 1) } , S is such


program for which p ( S ) = { (1 , 1) , (1 , 2) } . Then D = D = { 1 } ,
FP F
however, S obviously does not solve the F eth.

b) True. If S solves F then D = D , since:


FP F
⊆ : FP = F ∩ P ( S ) = ⇒ D FP ⊆ D F .
⊇ : Let a ∈ D F . Then as S solves F , a ∈ D p ( S ) and
P ( S ) ( in ) ⊆ M ( on ), therefore (1) ∃ ( a, b ) ∈ P ( S ), to which p ( S ) ( in ) ⊆ M ( in )
due to (2) ( a, b ) ∈ F is also fulfilled. So for (1) and (2) ( a, b ) ∈
F ∩p ( S ) = FP , so the ∈D .
FP

15.3. SPECIFICATION 239

15.3. Specification
First =⇒
P ( S ) = { (2 , 1) , (2 , 4) , (4 , 1) , (4 , 2) , (4 , 4) , (5 , 4)F }( S, R ) ⌉ = ∅ .

⌈Lf ( S, True ) ⌉ = {a ∈ D p ( S ) | p ( S ) ( a ) ⊆ ⌈Igaz⌉ = A} = D p ( S ) , ie:


Second

lf ( S, True ) = P ( D p ( S ) ).

Third
Claim:

(1) ( ∃n ∈ N -f ( S, Q )) ⇒-f ( S ( ∃n ∈ N, Q )) ,
n n

however:

(2) ( ∃n ∈ N: lf ( S, Q )) ⇍ lf ( S, ( ∃ n ∈ N: Q )) .
n n

proof:
First, we need to understand the two logic functions in the task,

which can be made easier by using the terms ( ∃n ∈ N: ... ) ( n∈ N . . . )
write:
⋁ ⋃
- ⌈∃n ∈ N: lf ( S, Q ) ⌉ = ⌈ n∈ N -f ( S, Q n ) ⌉ = n∈ N ⌈lf ( S, Q n ) ⌉ .
n
So ( ∃n ∈ N -f ( S, Q )) set of truth as the there are points,
for which there exists a Q such that ∈ ⌈lf ( S, Q ) ⌉ , that is , of p ( S )
n

We will definitely get ⌈Q ⌉ .


n n

n

- ⌈lf ( S, ( ∃ n ∈ N: Q )) ⌉ = ⌈lf ( S, n∈NQ n) ⌉ .
n

⋁ of lf ( S, ( ∃⋃
So there are the points in the truth set n ∈ N: Q )
from which p ( S ) is sure to be ⌈ = .n
n∈ N Q n ⌉ n∈ N ⌈Q n ⌉
We can then prove the two statements above as follows:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 202/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

a ∈∈⌈⌈∃
(1): Let ∈Q
lf (n S, N: lf) (⌉ S, Q )Q⌉ , then
. With
n ⇒ ⋁based on the above ∃m ∈ N:

for its tonality lf ( S, Q ) ⇒ lf ( S, n∈ N Q n ), so a∈⊥lf ( S, Q m ) ⌉ = ⇒
m m

⋁ m
a ∈ ⌈lf ( S, n∈ N Q n ) ⌉ = ⌈lf ( S, ( ∃ n∈ N: Q n )) ⌉ Thus:
( ∃n ∈ N: lf ( S, Q )) ⇒ lf ( S, ( ∃ n ∈ N: Q )).
n n

Note: We did not use ∀i ∈ N: Q ⇒ Q i +1


: A → L ( i ∈ N)
i
so that statement (1) is arbitrary Q
i
are fulfilled. It is therefore considered to be the property of lf
(4) lf ( S, Q ) ∨ lf ( S, R ) ⇒ lf ( S, Q ∨R ) statement counts many

240 SOLUTIONS 15

generalization of the function. (Finite many functions for the era-


it is obviously fulfilled on the basis of the statement.) On this basis,
that arbitrary I finite or countable set and Q : A → L
( i ∈ I ) functions:
i

⋁ ⋁
i∈I lf ( S, Q i ) ⇒lf ( S, i∈I Q i ).

(2): Let A = N, ⌈Q ⌉ = {x ∈ N | x ≤ i} ( i ∈ N), so ∀i ∈ N: Q ⇒


and i
Q i +1 is obviously fulfilled. Let S be a program for which p ( S ) (1) = N.
1 ∈ σ ( S, ( ∃ n ∈ N:⋃Q )) ⌉ , because 1 ∈ D p ( S ) and p ( S ) (1) ⊆
⌈∃n ∈ N: Q n ⌉ = n∈ N ⌈Q n ⌉ = N.Vontotus n∈ N: 1 ∈ { S ( S, Q n ) ⌉ ,
n

for every n ∈ N, ⌈Q ⌉ finite ( n element), but p ( S ) (1) =


N, so p ( S ) (1) ⊈ ⌈Q ⌉ . So:
n

n
( ∃n ∈ N: lf ( S, Q )) ⇍ lf ( S, ( ∃ n ∈ N: Q )).
n n

Note: This task creates a kind of continuity property


lf which is analogous to the known transfer principle ⋁ from the analysis. This is
that if ∀n ∈ N: Q ⇒ Q n +1 , then it is fulfilled n∈ N Q n to be considered as this
n
Q limits, so in the task we examine the individual ⋁
n
Q obtained -ekre -f ( S, Q ) a function limit values ( n ∈ N lf ( S ⋁ Q n )),
n n
are equal to the function value in the limit of Q ( lf ( S, n ∈ N Q n )).
n
For fixed S , lf is a condition dependent on conditions,
presumed.
However, based on the above (2) statement, this continuity property-
is not met. It is important to note, however, that this was the case
in our model, we also allow programs that are program-dependent,
its presidency is unlimitedly non-deterministic, ie there is at least one point,
to which infinite many different points are assigned. If we did not allow this,
or if we only look at a finite number of Q , it is in the task
n
property would be fulfilled.

4thIt is true, as in 2.3. Example:

⌈Lf ( S 1 ∪ S 2 , R ) ⌉ = {a ∈ D p ( S∪S ) | p ( S 1 ∪S 2 ) ( a ) ⊆⌈R⌉} =


1 2

= {a ∈ D p ( S ) ∩D P ( S ) | P ( S 1 ) ( in ) ∪p ( S 2 ) ( in ) ⊆⌈R⌉} =
1 2

= {a ∈ A | a ∈ D p ( S ) and p ( S 1 ) ( a ) ⊆⌈R⌉ and


1

a∈D p ( S ) and p ( S 2 ) ( a ) ⊆⌈R⌉} =


2

= ⌈lf ( S, R ) ⌉ ∩ ⌈lf ( S , R ) ⌉ = ⌈lf ( S, R ) ∧-f ( S , R ) ⌉ .


1 2 1 2

And since we assumed that lf ( S , R ) = LF ( S , R ),


1 2

lf ( S
1
∪ S 2 , R ) = lf ( S 1 , R ) ∧ lf ( S 2 , R ) = lf ( S 1 , R ) ∨ lf ( S 2 , R ).

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 203/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.3. SPECIFICATION 241

5. It is not true, since the condition in the task is equivalent to:

∀y ∈ A : P ( S 1 ) - 1 ( {y} ) = P ( S 2 ) - 1 ( {y} ).
So , according to the relations p ( S ) and p ( S ) we can only know the pics taken from each point,
1 2
to agree that it does not follow that D p ( S D
1) = p ( S 2 ). Let's look at it
for example, 15.6. Fig.
Note: If the predecessor of any set is identical to the two program functions
the programs are equivalent (see next task).

1• • 1 1• •1

2• •2 2• • 2

3• •3 3• •3
P ( S) p(S )
1 2
THE THE THE THE

15.6. figure. counterexample

6thTrue.

- D p(S D
1) = p ( S 2 ) , because H = True choice:
D p ( S1 ) = ⌈lf ( S , True ) ⌉ = ⌈lf ( S , True ) ⌉ = D p (2S) .
1 2

- Each of ∈ D p ( S 1 ) = D p ( S 2 ) In case of P ( S 1 ) (=in p () S ) ( a ), since


⌈H 1 ⌉ = P ( S 1 ) ( in ) or ⌈H 2 ⌉ = P ( S 2 ) ( the selection) added
2
to the sausage
containment:
the ∈ ⌈lf ( S , H ) ⌉ = ⌈lf ( S , H ) ⌉ = P ( S ) - 1 ( p ( S ) ( to )) = ⇒
1 1 2 1 2 1
P ( S ) ( in ) ⊆ P ( S ) ( in )
2 1

and the like:


the ∈ ⌈lf ( S , H ) ⌉ = ⌈lf ( S , H ) ⌉ = P ( S ) - 1 ( p ( S ) ( to )) = ⇒
2 2 1 2 1 2
P ( S ) ( in ) ⊆ P ( S ) ( in ).
1 2

7th⌈Lf ( S, H ) ⌉ = {x ∈ N | x ≡ 3 (mod 4) or x ≡ 0 (mod 4) }

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 204/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

242 SOLUTIONS 15

8thThey are not the same.DD so F stricter than F . namely


2F, but F 2 ⊂ F 1 ,
In F , we also bind1 =thatFthe
2 is 1
first two components do not change.
2

For example: ( a, b ) = ((2 , 1 , false ) , (1 , 3 , right )) where ( a, b ) ∈ F , but ( a, b ) ∈


1
F .
2

9thLet ∈ N. Then, on the one hand:

2 two 2 two 2
F (( the , b )) = { ( the , in ) , ( the , -a ) } ⊈ { ( the , in ) } = F (( the , b )),
1 2

on the other hand:

2 2 2
F (( -a , b )) = ∅ ⊉ { ( -a , -a ) } = F (( -a , b )).
1 2

So F ⊈ F and F ⊈ F .
1 2 2 1

But D
F
1 ⊆DF 2 and ∀a ∈ D
F
1 : F ( a ) ⊆ F ( a ), so F
2 1 2 is
more stringent,
such as F .
1

Note: Note that the specification given in the task is listed in Section 3.2. statement
is not a good specification because we can not read the Q precondition
the scope of interpretation of the task, so there is no program that
the specification of the specification. This is to be achieved if the Q pre-
we would stipulate that x ≥ 0. (For more detail , see p. 11 and p
We are dealing with the 18th task.)

10thThe variables m and n define an interval and i ∈ [ m..n ]


g ( i ) = 1 if and only if i to f as a function of a maximum location of the
[ m..n ] interval, otherwise g ( i ) = 0. So the job is to give it
and the maximum number of maximum spaces of the function f [ m..n ].

11thWhile emphasizing the point of specification, we emphasized that the theorem in general
can not be reversed, and in Section 3.2. we have formulated a good specification
relevant criteria. Below is an example of such
conditions are really needed, ie if they are not met, the item is not
it must be reversed.
Easiest way to add a counter-example, where there is b ∈ B para-
the point of the point of measurement , for which ⌈Q ⌉ = ∅ , but ⌈R ⌉ = ∅ . It does not exist at that
b b
atime
program that would fulfill the requirements of the specification, as one
such a b ∈ B for any S program ( property lf (1)
Use):

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 205/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.3. SPECIFICATION 243

⌈Lf ( S, R b ) ⌉ = ⌈lf ( S, False ) ⌉ = ∅ .


Thus ⌈Q ⌉ = ∅ due ⌈Q ⌉ ⊈ ⌈lf ( S, R ) ⌉ , i.e. Q ⇒ lf ( S, R b ) no
b b b b
met.
For example, see section 15.7. Fig. Let A be = { 1 , 2 } , B = {α, β} , F =
1
{ (1 , α ) , (2 , β ) } , F = { ( α, 1) } , F = { (1 , 1) } . It is obviously fulfilled that:
2

F
1
⊆ A × B , F 2 ⊆ B × A and F = F 2 ◦ F 1 .
Let S is software for which p ( S ) = F . Then S solves F , in turn:

⌈Q β ⌉ = { 2 } ⊈ ∅ = ⌈lf ( S, R β ) ⌉ , therefore Q β ⇏ -f ( S, R β ).

F=p(S)

1• α •1

⌈Q β ⌉

2• β •2
F F
1 2
THE B THE

15.7. figure. counterexample

Usually, however, such specifications are avoided, therefore,


a F and F relationships are given for which R 1 ⊆ D 2 At the time
1 2 F F
In any case, the reversal of the item specification is not met either: a
various b ∈ B for points ⌈Q ⌉ sets are not necessarily diszjunk-
b
tock.
For example, see section 15.8. Fig. Let A = { 1 , 2 , 3 } , B = {α, β} , F =
1
{ (1 , α ) , (2 , α ) , (2 , β ) , (3 , β ) } , F = { ( α, 1) , ( β, 2) } . Then
= FF ◦ F =
2 2 1
{ (1 , 1) , (2 , 1) , (2 , 2) , (3 , 2) } , and S be a program for which p ( S ) = F ,
so S obviously solves F , but:

Q ⇏ lf ( S, R ) and Q ⇏ lf ( S, R ).
α α β β

So even at the point of the parameter space, the specification of the specification is not met
but S program solves the task F.

244 SOLUTIONS 15

F=p(S)

⌈Lf ( S, R α ) ⌉
1•
•1 ⌈R α ⌉

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 206/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
⌈Q α ⌉ α•
2• •2 ⌈R β ⌉

⌈Q β ⌉ β
3•
F F •3
⌈Lf ( S, R β ) ⌉ 1
B
2

F=p(S)
THE THE

15.8. figure. counterexample

12thThe task is to give the prime (one) closest to the positive integer k,
number. F for a pair ( k, q ) assigns a pair ( k, p ) with prime number p and
there is no k prime close to p ( p is not always clear).
Based on these:

F ((10 , 1)) = { (10 , 11) } and F ((9 , 5)) = { (9 , 7) , (9 , 11) } .

13thD D so F more stringent than F . Because F a ( a, b, c )


F =
( a,1 b, d F) 2for F 1 ⊂dFis2 ,the smallest
andwhich 1 is 2
common multiplier a and b,
1

times, M is an ( a, b, e ) points for which this is a and b numbers a


2
their common multiplication is not greater than their product.

For example: F (4 , 6 , 1) = { (4 , 6 , 12) } ,


1
F (4 , 6 , 1) = { (4 , 6 , 12) , (4 , 6 , 24) } .
2

14thThey are not the same.


1 =DD 2 and F ⊂ F , so F more stringent than F . Two
FF 1 2 1 is 2
there is also an important difference between the tasks because F the function f
1 is
look for the first maximum position on the [ m..n ] interval so that it is the first
two variables (range boundaries) do not change, and in F the [ m..n ] inter-
2
vallumon took a look for maximum space and the first two components is
change.
Note: Note that the two specifications given in the task are listed in Section 3.2. statement
is not a good specification because we can not read the Q precondition

15.3. SPECIFICATION 245

the scope of interpretation of the task, so there is no program that


the specification of the specification. This could be avoided in both cases
if we are to impose the precondition Q , m ≤ n . (With such questions,
although we are dealing with tasks 11 and 18.)

15thThe task worded in words is to sum up v : N → { 0 , 1 }


function on the [1 ..n ] interval. Notice that the status space is one
component, the value of which does not depend on the task, that is,
to order the same. (The n number is not one of the components of the state
but just like the function v .) So there are none
components that parameterize the task, so it is not the state space now
an alternative is chosen as a parameter space, but an arbitrary single element hal-
This document was, and D relation assigns this item every point in space conditions.
1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 207/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
A=N
s
B = {χ}

Q : That's right
Σ
R : ( s = v ( k ))
k=1

16th A=N×N
n d
B=N
'
n
'
Q:(n=n )
R:(Q∧d|n)

17th A=N×N
n d
B=N
'
n
'
Q : ( n = n ∧ ∃a ∈ N ( the | n of ∧ = 1 ∧ in = n ))
R : ( Q ∧ d | n∧ d = 1 ∧ d = n )

246 SOLUTIONS 15

18thBased on the text of the task, the following specification is directly available:

A=N×N
n d
B=N
'
n
'
Q:(n=n )
R:(Q∧d|n∧d=1∧d=n)

However, note that, in the above specification,


that not every natural number exists as a real divisor. Thus, F and
1
F relationships, for which F = F ◦ F task interpreter
Justice not equal to M domain of interpretation ( D ⊂ D
2 2 1
1 ), tehta
1 M F
We can not read the interpretation range of the task from Q prerequisite. In other words,
this specification does not meet the requirements of 3.2. the criteria set out in the statement,
not a good specification . There are points in the parameter space b ∈ B (a
not complex numbers), for which ⌈Q ⌉ = ∅ , but ⌈R ⌉ = ∅ , so it does not exist
b b
a program that would meet the requirements of the specification. Since min-
den for such b ∈ B for any S program ( lf (1))
used):

⌈Lf ( S, R b ) ⌉ = ⌈lf ( S, False ) ⌉ = ∅ .


So for ⌈Q ⌉ = ∅ , Q ⇏ lf ( S, R ). Therefore, such specifications are evident
b b b
we will avoid it.
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 208/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

In this case, as usual, there are two possible solutions. One


is that we are already precluded in the prerequisite that it is only complex natural
the task is interpreted in figures. Then exactly the same specification and
in writing, we get the same task as the previous one.
toluene layer was separated. Note that this specification is the same F = F ◦ F relation
2 1
defines it as the first variant (although F not the same) but the
1 is
a very important difference in the application of the specification
between the two.
The other solution is to redraw the task so that all products
You can make a definite number: choose a natural number to make
if there is a real divider, and if so, then add one. Then the status space
b must be completed with a logical component and obviously a completely different speci-
we get fiction, completely different programs solve this task like
previous ones.

15.3. SPECIFICATION 247

A=N×L×N
n l d
B=N
'
n
'
Q:(n=n )
R ( Q∧l = ( ∃a ∈ N ( the | n∧a = 1 ∧a = n )) ∧l → ( d | n∧d = 1 ∧d = n ))

19th A=N×H
n h
B=N
'
n
Where H = {X ∈ ℘ (N) | | X | <∞} = F (N), ie finite particle N,
mazai set. H is necessary because ℘ (N) does not count
so it can not be defined as a state space component as defined.

'
Q:(n=n )
R : ( Q ∧ h = {d ∈ N | d | n ∧ d = 1 ∧ d = n} )

Note: In this task, there are no problems with non-complex numbers,


because there is the same set of genuine divisors, namely, the
empty set.

20th A=N×N
n p
B=N
'
n
'
Q : ( n = n ∧ n = 1)
R ( Q ∧ p | n ∧ primers ( p ) ∧ ∀q ∈ N (( q | n ∧ primers ( q )) → q ≤ p ))

Of the natural numbers, only 1 has no primes, so it is


excluded.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 209/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

21st A=N×N
0
n s
B=N
'
n

248 SOLUTIONS 15

'
Q:(n=n )
Σ
R : ( Q ∧ s = class ( k, n ))
k=2

Where divisor N × N → { 0 , 1 } ,
{
1 , if k | n ;
os ( k, n ) = 0 otherwise .

Note: In this task, there are no problems with non-complex numbers,


their real number of divisors is zero.

22ndThe whole interval [ m..n ] is understood to be n - m + 1


so it is an empty interval exactly when it is the end point
one smaller than its starting point, ie n = m - 1. Therefore, an interval [ m..n ]
If we enter lum, we conclude that m ≤ n + 1 or if the interval is not
can be empty then m ≤ n .
Since not all intervals are complex, we need to introduce it
a logical variable, and the task according to the following wording
should be interpreted as specifying whether it is within the interval [ m..n ]
number that has a real divisor, and if so, give the first one.

A=NŨNŨLŨN
MnlI
B=N×N
' '
m n
' '
Q : ( m = m ∧ n = n ∧ m ≤ n + 1)
R ( Q ∧ L = ( ∃j ∈ [ m..n ]: β ( j )) ∧ → l ( i ∈ [ m..n ] ∧ β ( i ) ∧
∀j ∈ [ m..i - 1]: ¬β ( j )))

Where β : N → L, ⌈β⌉ = {a ∈ N | ∃b ∈ N: b | a and b = 1 and b = a} , ie β ( a )


exactly to the ∈ N numbers will be right , which is a real divisor.
Note: This task is outlined in the chapter 12 linear search of a
concrete case.

23rdLike the previous task, we will also need a logical variable,


and we need to clarify the task because not every interval has 6
no divisible number.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 210/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.4. EXTENSION 249

A=NŨNŨLŨN
MnlI
B=N×N
' '
m n
' '
Q : ( m = m ∧ n = n ∧ m ≤ n + 1)
R ( Q ∧ L = ( ∃j ∈ [ m..n ] 6 | j ) ∧ → l ( i ∈ [ m..n ] ∧ 6 | i∧
∀j ∈ [ m..n ]: (6 | j → f ( j ) ≤ f ( i ))))

Where f : N → N is the number of real numbers of a natural number


0
enter:
Σ
f(n)= os ( k, n ) ,
k=2

where divisor N × N → { 0 , 1 } ,
{
1 , if k | n ;
os ( k, n ) =
0 otherwise .

24. Contrary to the previous two tasks, we are now not allowing empty inter-
religion, we stipulate that m ≤ n .

A=N×N×N
mni
B=N×N
' '
m n
' '
Q:(m=m ∧n=n ∧m≤n)
R ( Q ∧ i ∈ [ m..n ] ∧ ∀j ∈ [ m..n ]: f ( j ) ≤ f ( i ))

Where f is a function defined in the previous task.

15.4. Extension
'
1. F = { (( q, a ) , ( r, b )) ∈ A × A | r = q + 1 }

**
2. Not true. Let A = { 1 , 2 } × {a, b} , B = { 1 , 2 } , S ⊆ A × A ,

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 211/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

250 SOLUTIONS 15

S={ ((1 and ) , < (1 and ) , (2 , ((1b ) b> )) ,, < (1 , b ) , (2 and ) > ) ,
(2 , a ) , < (2 , a ) , (1 , b ) ((2
> ) ,, b ) , < (2 , b ) , (1 , a}) .> )

Then pr ( S ) = { (1 , < 1 , 2 > ) , (2 , < 2 , 1 > ) } , so:


B

'
for ( S ) = { ((1 and ) , < (1 and ) , (2 and((1 )b>) ), <
, (1 , b ) , (2 , b ) > ) ,
B ((2 , to ) , < (2 , on ) , (one((2
of ), >
b ) , < (2 , b ) , (1 , b}). > )

Note: Note that a projection of a program may not necessarily be


program (see Task 4).

** '
Third
Let B subspace of the state space, S ⊆' B × B ** program, S of S extension
made of is. Then, it is obvious that S ⊆ A × A , so we have to see that it is fulfilled
the three conditions in the program definition.
' '
i. S comes from the definition of that ∀a ∈ A : S ( in ) = ∅ , so D ' = A .
' S
ii. Let α ∈ R ' = ⇒ ∃a ∈ A ( a, α ) ∈ S = ⇒ ( pr ( in ) , pr ( α )) ∈ S .
Since S isS a program, pr ( α ) = red ( pr ( αB )), so α = Bred ( α ), since
∀i ∈ D α : pr B ' ( α i ) = prBB ' ( a ), the two members
B
of α series exactly
then it will be identical if the corresponding members of the pr ( α ) series are identical.
B

∈ A and α ∈ S ( a ). Then ( pr B ( a ) , pr B ( α )) ∈ S = ⇒
'
iii. Be a
| pr ( a ) | = 0 and pr ( α ) = pr ( a ). So | α | = 0, pr ( α ) = pr ( a )
B B 1 B B 1 B
and pr ' ( α ) = pr ' ( to ), i.e., α = the .
B 1 B 1

4thLet S be a program for which:

S ((1 , 1 ,..., 1)) = { < (1 , 1 , 1 ,..., 1) , (2 , 1 , 1 ,..., 1) , (2 , 2 , 1 , ..., 1) ,. . . .


(2 , 2 , ..., 2 , 1) , (2 , 2 , 2 , ..., 2) > } .

Let B of A is a real subspace. Then there exists k ∈ [1 ..n ] to which A


is not included among the components of B , so pr ( S ) is the (1 , 1 , ..., 1) ∈ B point-
k

B
to order a finite sequence of k. and ( k + 1) . member is the same,
so it can not be reduced.

'' '' ' 'is


5th a) Not true. If F
= pr ( F ) then F ⊆ F . F the most abundant
property relationship, since
A all the parties are organized,
s projection of F have US.
b) Since the projection function prTHE
( - 1) ( F ) = prA- (1 F ).

15.5. PROGRAMKONSTRUKCIÓK 251

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 212/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

( - 1) ( F ) = pr A- 1( F ) = {x∈D pr A | pr A ( x ) ∈ F} =
pr THE
'
= { ( a, b ) ∈ B × B | pr (( a, b )) ∈ F} = F
A

Note: We do not normally distinguish between pr : B →


A
A and pr : B × B → A × The function, but here it is obviously the latter
A
so D A = B × B .Továbbámivel PR A ( x ) is the -belielemetjelöl,

not a single elements, and the definition of archetype ∈ signal to be Irish


pr

instead of ⊆ .

6thThe definition of the extension is that:

F '' = { (( a, a 1 ) , ( b, b 1 )) ∈ B × B | ( a, b ) ∈ F} ,
'

F '' ' = { (( a, a 2 ) , ( b, b 2 )) ∈ C × C | ( a, b ) ∈ F} ,
F = { (( a, a , a ) , ( b, b , b )) ∈ D × D | ( a, b ) ∈ F} .
1 2 1 2
◦ '' ◦
Mark F the D extension of the D to. Then F ⊆D×D,
◦ ''
F = { (( a, a , a ) , ( b, b , b )) | pr ((( A, A and ) , ( b,'' b , b ))) ∈ F } =
= { (( a, a , a ) , ( b, b , b )) | (( a, a ) , ( b, b '' ')) ∈ F } =
1 2 1 2 C 1 2 1 2

= { (( a, a , a ) , ( b, b , b )) | ( a, b ) ∈ F} = F .
1 2 1 2 2 2

1 2 1 2
'' ' ''
So we have proved that F to F to extend D to.
' '' '' '
Since F and F The projection is in F , so F to F the projection
' ''
is taken
extension to C and, similarly, to extend the projection of F to F A
B to.

7thNot true. Consider, for example, section 15.9. Fig. Let A = B × C , B = { 1 , 2 } ,


C = {α} , F = { (1 , 2) } = ⇒ F = { (1 , α ) , (2 , α ) } = ⇒ F = { ( α, α ) } . At:
2 1
'
1= { ((1 , α ) , (1 , α )) , ((1 , α ) , (2 , α )) , ((2 , α ) , (1 , α )) , ((2 , α ) , (2 , α )) } ,
F
'
1 ) = { (1 , 1) , (1 , 2) , (2 , 1) , (2 , 2)
= {} (1 , 2) } = F .
for ( F 2
C

15.5. Programkonstrukciók
First the) ( S , S )= { 1 → 1463 , 1 → 1451 ..., 1 → 12 ...,
1 2
2 → 2132132 ..., 3 → 361 ..., 4 → 4636 ,
4 → 45134 , 4 → 45121 , 5 → 5636 ,
6 → 612132 ... }
p (( S ; S ))= { (4 , 1) , (4 , 4) , (4 , 6) , (5 , 6) }
1 2

252 SOLUTIONS 15

C C

'

F F1
• • • • • •
F F
1 1

• • • •
B B

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 213/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
'
F 1)
2 for ( F
C

15.9. figure. counterexample

b) IF ( π : S , π : S ) =
1 1 2 2
={ 1 → 14 , 1 → 12 ..., 2 → 2132 ,
3 → 36 , 4 → 463 , 4 → 451 } ∪
∪{ 1 → 134 , 1 → 121 , 3 → 36 ,
4 → 463 , 4 → 451 ..., 5 → 5632 } ∪
∪{ 6 → 6 ... }=
={ 1 → 14 , 1 → 12 ..., 1 → 134 ,
1 → 121 , 2 → 2132 , 3 → 36 ,
4 → 463 , 4 → 451 , 4 → 451 . . . .
5 → 5632 , 6 → 6 ... }
p ( IF ) = { (2 , 2) , (3 , 6) , (5 , 2) }

c) Enter some markings so that we can easily write the cycle.


If there is a feature above a subset of a series, then it is
report that there is a finite number of repetitions of the corresponding sequence
received all series. So → α β γ denotes the following set:
1 2 N
{ ( a, con ( α, ω, γ )) | ∃n ∈ N ω = kon ( β , βi , β... ) and
∀i ∈ [1 ..n ]: β = β} .
And if there is a → sign over a subset of a series , then
it is the repetition of the endless repetition of the right part
series. So:
α
β ... = cone ( α, β, β, β, ... ).

Using these markings:

15.5. PROGRAMKONSTRUKCIÓK 253

DO = { 1 → 14636 , 1 → 12 ..., 1 → 1 451 4636 ,


1 → 14 2 → 213 . . . .
1 → 1 451 2 ..., 1 ...,
3 → 36 , 4 → 4636 , 4 → 451 4636 ,
4 → 451 . . .
4 → 451 2 ..., }∪
∪{ 5→5, 6→6 },

p ( DO ) = { (3 , 6) , (5 , 5) , (6 , 6) } .

Note: In this problem in the programs ( a, < a, b, c,... > )


pairs for the sake of simplicity → abc. . . .

Second
IF ( π : S , π : S , π : S )=
1 1 2 2 3 3
={ 1 → 12 ..., 1 → 12 , 2 → 23 , 2 → 24 ,
3 → 3456 , 3 → 3 ..., 4 → 463 , 4 → 43 ,
4 → 432 , 5 → 5 ..., 6 → 63 ... },
D p ( IF ) = { 2 , 4 } , p ( IF ) = { (2 , 3) , (2 , 4) , (4 , 2) , (4 , 3) } .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 214/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Note: As with the previous task in the program ( a, < a, b, c,... > )
pairs here too → abc. . . .

Not true. For a point a ∈ A , S ◦ τ ◦ S ( a ) = S ( τ ( S ( a )))


Third
so R
S
2 ◦τ ◦S 1 ⊆ R S 2 , but R2 ( S 11; S 2 ) ⊈ R S2 2 . (For1 example, every 1Rhave
S
US
endless series is defined as R ( S 1 ; S 2 ) -benzyl)

We may also think that when we form τ ◦ S , then


1
the S runs attributed by some points of the state space of only a finite SO
1
the end points of roses remain, the endless series and the finite series
we lose the other members. However, according to the definition of the sequence,
1 have USR
S
we need every member of the series, so S ◦ τ ◦ S can not be the same
2 1
( S , S ).
1 2

Let A = {a, b} , for example,

S = { ( a, < a, b > ) , ( b < b, b, ... > ) } ,


1
S = { ( a, < to > ) , ( b < b > ) } .
2

At that time:

(S ,S ) = { ( A, < a, b > ) , ( b < b, b,... > ) } = S ,


1 2 1
S ◦τ◦S = { ( a, < b > ) } .
2 1

254 SOLUTIONS 15

So S ◦ τ ◦ S = ( S , S ), and even one-way containment does not exist.


2 1 1 2

Note: Note that S ◦ τ ◦ S not a program.


2 1 is

4th a) It is true, because it is used simply as D G⊙F from the definitions =


F - 1 ( D ) relation:
G

D p ( S ) = D p ( S2 ) ⊙ p ( S 1 ) = p ( S 1 ) - 1 ( D p2 )( )S = ⌈lf ( S 1 , P ( D p ( S 2 ) )) ⌉ .

(b) It is true, firstly, that:


⌈lf ( S 1 -f ( S 2 , R )) ⌉ =
= {a ∈ D p ( S ) | p ( S 1 ) ( a ) ⊆⊥lf ( S 2 , R ) ⌉} =
1

= {a ∈ D p ( S ) | p ( S 1 ) ( in ) ⊆ {b∈D P ( S ) | P ( S 2 ) ( b ) ⊆⌈R ) ⌉}} =


1 2

= {a ∈ D p ( S ) ( p ( S 1 ) ( a ) ⊆ D p ( S ) and p ( S 2 ) ( p ( S 1 ) ( a )) ⊆⌈R ) ⌉} .
1 2

On the other hand, using D = F - 1 ( D ) and ∀a ∈ D :


G⊙F
G ⊙ F ( a ) = G ( F ( a )):
GveroF G

⌈lf (( S 1 ; S 2 ) , R ) =⌉
= {a ∈ D p ( S ) ⊙p ( S ) | p ( S 2 ) ⊙p ( S 1 ) ( in ) ⊆⌈R⌉} =
2 1

= {a ∈ p ( S ) - 1 ( D p ( )S ) | P ( S ) ( P ( S ) ( in )) ⊆ ⌈R⌉} =
2
1 2 1
= {a ∈ D p ( S ) p ( S 1 ) ( a ) ⊆ D p ( S ) and p ( S 2 ) ( p ( S 1 ) ( a )) ⊆⌈R⌉} .
1 2

5thLet A be an arbitrary state space and in accordance with the definitions in Chapter 8
introduce the SKIP and ABORT marks for two special programs:
**
SKIP = { ( A, < to > ) ∈ A × A | a**∈ A} ,
ABORT = { ( a, < a, a, ... ) > ∈ A × A | a ∈ A} .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 215/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
The SKIPLet
It helps. and ABORT
S be programπcan
any program, be written
is any in all
condition. At:three construction program

SKIP = ( SKIP ; SKIP )


SKIP = IF ( True : SKIP ) = IF ( π : SKIP, ¬π : SKIP )
SKIP = DO ( False, S )

ABORT = ( ABORT ; S ) = ( SKIP ; ABORT )


ABORT = IF ( True : ABORT ) = IF ( π : ABORT, ¬π : ABORT )
ABORT = IF ( False : S )
ABORT = DO ( True, SKIP )

15.5. PROGRAMKONSTRUKCIÓK 255

6thAs a cycle, you can not record all programs, just as sequences and
as a branch. Let S be an arbitrary state program. That's it
with the markings introduced in the previous task:
a) S = ( SKIP ; S ) = ( S ; SKIP )
b) S = IF ( True : S ) = IF ( π : S, ¬π : S ) ( π any condition)
c) Let A = {a, b} , for example,
S = { ( a, < to > ) , ( a, < a, b > ) , ( b < b > ) } .
It can not be described as a cycle. Indeed suppose indirectly that
there exists a condition π and program S for which S = DO ( π, S ). At:
0 0
- the ∈ ⌈π⌉ = ⇒ S ( in ) = { < to > } ,
0
*
- the ∈ ⌈π⌉ = ⇒ ∀α ∈ S ( the ) ∩ A : τ ( α ) ∈ ⌈π⌉ = ⇒ < to > ∈ S ( to ).
0 0
Since none of the S programs is fulfilled, S = DO ( π, S ).
0


7thNot true. ( ⌈Π ⌉ ∩ D p ( S) )
k it contains the points to which it belongs
k
k=1
a branch of the branched structure where the true condition of the weight, and the corresponding S
k
program certainly terminals to from starting. Conversely, D p ( IF ) is only one
the points in which at least one condition is satisfied, and each is
S , the condition of which is true, is sure to be terminal a .
k

If ∈ D p ( IF ) , then obviously ∃k ∈ [1 ..n ]: ∈ ⌈π ⌉ and ∈ D p ( S k) , so


k

D p ( IF ) ⊆ ( ⌈Π ⌉ ∩ D p k( )S). It does not exist in the reverse order
k
k=1
maintained. For example, let A = { 1 , 2 } , ⌈π ⌉ = { 1 , 2 } , ⌈π 2 ⌉ = { 1 } ,
1

S = { (1 , < 1 , 1 , ... > ) , (2 , < 2 > ) } ,


1
S = { (1 , < 1 > ) , (2 , < 2 , 2 , ... > ) } .
2


⌈Π ⌉ ∩ D p k( )S) = { 1 , 2 } .
Then D p ( IF ) = { 2 } , on the other( hand
k
k=1

8th D p ( S ) = ∅ ⇐⇒ S 1 ∪ S 2 ∪ · · · ∪ S n infinitely to every point


series.
D p ( IF ) = A ⇐⇒ A π k conditions cover the entire state space and all
S program for a ∈ ⌈π ⌉ points is only finite
k k
series.

For example:
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 216/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
π = True
False, , S = SABORT
= SKIP
, ( k ∈ [2 .. n ]),
k1 1 k

256 SOLUTIONS 15

where SKIP and ABORT are programs introduced in Chapter 8.

9thNot true, there is no one-way content. First, in the previous task


we have seen that D p ( IF ) ⊈ D p ( S ) , so p ( IF ) ⊈ p ( S ). On the other hand, for example
S = SKIP , π = False ( k ∈ [1 ..n ]) where SKIP is introduced in Chapter 8
program. Then p ( IF ) = ∅ , but p ( S ) = p ( SKIP ) = id , therefore
k k

A
p ( S ) ⊈ p ( IF ).

10thTrue, since:

D p ( IF ) = {a ∈ A | a ∈ ⌈π ⌉ ∪ ⌈π ⌉ and a ∈ ⌈π ⌉ = ⇒ a ∈ D p ( S1 ) and
a ∈ ⌈π ⌉ = ⇒ a ∈ D p ( S =
1 2 1

2) }
= {a ∈ A | ( a ∈ ⌈π ⌉ and ∈ ⌈π ⌉ and ∈ D p ( S 1 ) and a∈D p ( S 2 ) ) or
2

( a ∈ ⌈π ⌉ and ∈ ⌈π ⌉ and ∈ D p ( S1 ) ) or
1 2

( a ∈ ⌈π ⌉ and ∈ ⌈π ⌉ and ∈ D p ( S2 ) ) } =
1 2

= ( ⌈Π ⌉ ∩ ⌈π ⌉ ∩ D p 1()S∩D p ( S 2 ) ) ∪ (( ⌈π ⌉ \ ⌈π ⌉ ) ∩ D p ( S ∪
1 2

1) )
∪ (( ⌈π ⌉ \ ⌈π ⌉ ) ∩ D p (2 S) ).
1

2
2

1
1 2

11thIn this task we refer to the definitions in Chapter 8.

S = { (1 , < 1 , 2 > ) , (2 , < 2 , 4 > ) , (3 , < 3 , 3 ,... > ) , (4 , < 4 , 4 ,... > ) }
1
S = { (1 , < 1 > ) , (2 , < 2 > ) , (3 , < 3 > ) , (4 , < 4 > ) }
2
IF = { (1 , < 1 , 2 > ) , (1 , < 1 > ) , (2 , < 2 > ) , (3 , < 3 , 3 ,... > ) , (4 , < 4 , 4 , ... > ) }

12th a) Since the program function of the sequence is the prog-


ramfüggvényének strict composition ( p ( S ) = P ( S ) ⊙p ( S )), D is
the composition of the two tasks, so D ⊆ D p ( S ) is not always met, S is not
2 1

F
necessarily solve F eth.
For example, Fig. Let A = { 1 , 2 } ,
F = { (1 , 1) , (1 , 2) } , D = { (1 , 1) } ,
1 2
S = { (1 , < 1 > ) , (1 , < 1 , 2 > ) , (2 , < 2 , 2 , ... > ) } ,
1
S = { (1 , < 1 > ) , (2 , < 2 , 2 , ... > ) } .
2

Then P ( S ) = M and P ( S ) = F so S solves F eth, S solves


1 1 2 2 1 1 2
F , in turn:
2

S = ( S ; S ) = { (1 , < 1 > ) , (1 , < 1 , 2 , ... > ) , (2 , < 2 , ... > ) } ,


1 2
F = F ◦ F = { (1 , 1) } .
2 1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 217/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.5. PROGRAMKONSTRUKCIÓK 257

1
1• • •1

2• • •2
2
F =p(S ) F =p(S )
1 1 2 2
THE THE THE
15:10. figure. counterexample

Thus p ( S ) = ∅ , so S does not solve M eth.

b) As in F two tasks strict composition, S solves F eth.


We know that S solves F , S solves F , so:
1 1 2 2

(1) D 1 ⊆ D p ( S 1 ) (3) D 2 ⊆ D p ( S 2 )
(2) ∀a ∈ D 1 : p ( S ) ( a ) ⊆ F ( a(4)
) ∀a ∈ D 2 : p ( S ) ( a ) ⊆ F ( a )
F F

F 1 1 F 2 2
Using these, let's look at the two conditions of the solution:
i. D 2 ⊙F 1 ⊆D P ( S 2 ) ⊙p ( S 1 ) ,
F
ii. ∀a ∈ D 2 ⊙F 1 : p ( S ) ⊙ p ( S ) ( a ) ⊆ F ⊙ F 1 ( a ).
F 2 1 2

i. Let ∈ D 2 ⊙F 1. You can use the definitions in a simple way

resultingF in D = H = H - 1 ( D ) relation:
G G

a∈D 2 ⊙F 1 = 1 ( D ⇐⇒
F F2 )
a∈D 1 and F 1 ( a ) ⊆ D F 2 = ⇒ (1) , (3)
F
a∈D p ( S 1 ) and F 1 ( a ) ⊆ D p ( S 2 ) = ⇒ (2)
a∈D p ( S 1 ) and p ( S 1 ) ( a ) ⊆ D p ( S 2 ) ⇐⇒
a ∈ p ( S ) - 1 ( D p2 () S) = D p ( S 2 ) ⊙ p ( S 1 ) .
1

So we have found that D


F
⊆ D p(S).
ii. Let ∈ D 2 ⊙F 1 recorded. On this supersubjective (5) a∈D F 1

and (6) F ( a ) ⊆ D2. Using that ∀a∈D GveroH : G⊙H ( a ) =


F

1 F
G ( H ( a )):
P ( S ) ⊙ P ( S ) ( to ) = P ( S ) ( P ( S ) ( in )) ⊆ (5) , (2)
2 1 2 1
P ⊆ ( S ) ( M ( on )) ⊆ (6) , (4) F ( F ( to )) = F ⊙ F 1 ( on ).
2 1 2 1 2

So we have found that ∀a ∈ D : p ( S ) ( a ) ⊆ F ( a ).


F

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 218/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

258 SOLUTIONS 15

13thNone of these are met. Consider, for example, section 15.11. Fig. Let A = { 1 , 2 , 3 } ,

F = { (1 , 1) , (2 , 2) } , D = { (1 , 1) , (3 , 3) } ,
1 2
S = S = { (1 , < 1 > ) , (2 , < 2 , 2 , ... > ) , (3 , < 3 , 3 , ... > ) } .
1 2

P(S ) p(S )
1 2

1• • • 1
1
2• • • 2
2
3• • • 3
3
F F
1 2
THE THE THE

15:11. figure. counterexample

Then P ( S ) ⊙ p ( S ) = F ⊙ F = { (1 , 1) } , so S solves F ⊙ F ,
2 1 2 1 2 1
however, P ( S ) = P ( S ) = { (1 , 1) } , therefore, S does not solve the F -ethyl, and S is not
1 2 1 1 2
solve F .
2

⋁ ⋃
14th a) No, because if D ⊈ ⌈ π ⌉= ⌈Π and ⌉ then there exists a ∈ D F
F i
i=1 i=1

point to which ∈ ⌈Π and ⌉ , so a ∈ D p ( IF ) = ⇒ D F ⊈ D p ( IF ) .
i=1

For example, be F = id , π = False , S arbitrary ( k ∈ [1 ..n ]).


Then ∀k ∈ [1 ..n ] is F | ∅ , sok any program S k can
A k
k⌉ =
⌈π
but ∀k ∈ [1 ..n ]: π = For fake it is obvious that p ( IF ) = ∅ , so
k
IF does not solve the F eth.
b) It follows from c) above, as here ⌈π ∨π2∨∨π···n⌉=A.
1
c) Yes. We know that ∀k ∈ [1 ..n case] S solve F | k ⌉ , so:
k ⌈π
(1) ∀k ∈ [1 ..n ]: D F ∩ ⌈π k ⌉ ⊆ D p ( S ) , k

(2) ∀k ∈ [1 ..n ]: ∀a ∈ D F ∩ ⌈π k ⌉ : p ( S k ) ( a ) ⊆ F | ⌉⌈π( a ) = F ( a ). k

Using these, let's see if the two conditions of the solution are fulfilled.
i. Let a ∈ D . First, because of the condition in the task
⋁ F ⋃
a∈⌈π ⌉= ⌈Π ⌉ and ∀k ∈ [1 ..n ] if ∈ ⌈π ⌉ ,
i =and
1 i=1 and k

15.5. PROGRAMKONSTRUKCIÓK 259

for (1), ∈ D p ( S k) , so ∈ D p ( IF ) . We saw that


D ⊆ D p ( IF ) .
F

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 219/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
ii. Let ∈ D fixed. Then ∈ D p ( IF ) , so:
F be
⋃ ⋃
p ( IF ) ( a ) = p ( S ) |k ⌉ ( a ) = p ( S ) ( a ).
k ⌈π k
k=1 k∈ [1 ..n ] , a∈∈π ⌉
k

Since every k ∈ [1 ..n ] and ∈ ⌈π ⌉ (2), p ( S ) ( a ) ⊆


k k
F ( a ), the connotation of these sets is also part of F ( a ). We saw that
∀a ∈ : p ( IF ) ( a ) ⊆ F ( a ).
FF

15thTrue. We know that IF solves F , so:


(1) D
F
⊆ D p ( IF ) ⇐⇒ ∀a ∈ D F : ( a ∈ ⌈Π and ⌉ and ∀k ∈ [1 ..n ]:
i=1
( a ∈ ⌈π ⌉ = ⇒ a ∈ D p ( S) ) ) k

(2) ∀a ∈ F F : p ( IF ) ( a ) ⊆ F ( a ). k

Let k ∈ [1 ..n ] be recorded, and let S solve F | k ⌉ -t.


k ⌈π

i. D ⌈πk⌉ = D ∩ ⌈π ⌉ ⊆ D p ( S k ) , because all the D ∈ ∩ ⌈π ⌉ case of


(1) for ∈ D p ( S
F| F k F k
k) .

ii. Let ∈ D ∩ ⌈π ⌉ be fixed. For (1), for ∈ D p ( IF ) and (2):


F k


p ( IF ) ( a ) = p ( S ) |and ⌉ ( a ⊆
) F ( a ).
i=1 i ⌈π

Since ∈ ⌈π ⌉ , F | ⌈π |
k k ⌉ ( a ) = F ( a ) and p ( S k ) ⌈Π k ⌉ ( a ) = p ( S k ) ( a ). Then:
P ( S ) ( to ) = P ( S k ⌉)(|a ) ⊆ p ( IF ) ( a ) ⊆ F ( a ) = F | ⌈Π k ⌉ ( a ).
k k ⌈π

We can see that ∀a ∈ D ⌈πk⌉ : p ( S ) ( a ) ⊆ F k| ⌉ ( a ).


F| k ⌈π

16thNo. For example, let A = { 1 , 2 } , ⌈π ⌉ = A ( k ∈ [1 ..n ]) and


k

F = { (1 , 1) } , S = { (1 , < 1 > ) , (2 , < 2 , 2 , ... > ) } ;


D = { (2 , 2) } , S = { (1 , < 1 , 1 , ... > ) , (2 , < 2 >( k) }∈ [2 .. n ]).
1 1

k k

Then S solves F ( k ∈ [1 ..n ]), but p ( IF ) = ∅ , so IF is evident


does not solve F = F ∪. . . ∪ F = ∅ .
k k

1 n

260 SOLUTIONS 15

17thTrue, since this task is a special case for task 15, which we have seen,
that is true. Here is an additional condition, but we do not have to use it
present evidence.

18thNo, consider, for example, a 16th example. Note


but that ∀k ∈ [1 ..n ]: D k = ⌈Π ⌉ more stringent conditions can be seen,
F k
that IF solve F eth.

19thEqual, therefore equivalent. Consider their structure:

IF IF
1 2

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 220/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
π π π π ∧π π
S1 S2 S1 S 1∪S2 S2
1 2 1 1 2 2

According to the definition of branching for ∀a ∈ A :


S (a), if ∈ ⌈π ⌉ \ ⌈π ⌉ ;
if a ∈ ⌈π ⌉ \ ⌈π ⌉ ;
1 1 2
S (a),
IF ( a ) = = IF ( a )
S 1 ( In ) ∪ S ( on ) , when the ∈ ⌈π ∧ π ⌉ ; 1
2 2 1
2

{ < A, a,. . . > }, if ∈ ⌈π ∨ π ⌉.


2 1 2

1 2

20thThey are not equal or equivalent. Consider their structure:

IF IF
1 2

π
1
π
2
π
1
π
2
∧π3 π
2
∧π4
π π
3 4
S S S S
1
S S 1 3 4
3 4

At first glance, they look the same, but they are not. There are points of ∈ A
can be different for which ∈ ⌈π ⌉ , ∈ ⌈π ⌉ , but ∈ ⌈π ⌉ and ∈ ⌈π ⌉ .
= { < A, a,. . . > } , IF ( a )= S ( a ) ∪ IF ( a ) =
1 2 3 4
Then IF ( a )
S ( a ) ∪ { < a, a, ... > } , but IF ( a ) = S ( a ).
34 1 1 34

1 2 1
For example, be S = S = S = SKIP , where SKIP is in Chapter 8
program introduced π k and conditions, which ∃a ∈ ⌈π ∧ π ∧
1 3 4

¬π ∧ ¬π ⌉ . Then, for ∈ D p ( IF 1 ) , but ∈ D p ( IF 2 ) . So IF


i 1 2
and IF
3 4 1 2
is not equal and is not equivalent.

15.5. PROGRAMKONSTRUKCIÓK 261

21stYes. We know that S solves F , so:


0

(1) D ⊆ D p ( S 0 ) ,
(2) ∀a ∈ D : p ( S ), ( the ) ⊆ M ( to ).
F

D 0

Using these, let's look at the two conditions of the solution:

i. D
F|π
⊆ D p ( DO ) = D p ( S 0) |π,

ii. ∀a ∈ D F | π : p ( DO ) ( to ) = p ( S 0 ) | π ( the ) ⊆ M | π ( in ).
In other words, it must be plain to see that one of the ∈ A point et eten ha
a∈D , then on the one hand∈ aD p ( S 0 ) | π , secondly, P ( S ) | π ( ⊆
in F
) | π ( a ).
End the proof into three parts: ( a ∈ ⌈π⌉ and the ∈ D F ) or ( a ∈ ⌈π⌉
F|π 0

and ∈ D ) or ∈ ⌈π⌉ .
F

If ∈ ⌈π⌉ and ∈ D , then ∈ D , F | π ( a ) = {a} , so the ∈ D .


F F|π F|π
Let ∈ ⌈π⌉ and ∈ D and suppose that ∈ D . Not then
F F|π
There is an infinite series whose members are the starting of F | π relation
sequential applications. It follows that F | π
we can not get into ⌈π⌉ \ D so long as we have successive applications
= ⌈π⌉ , so we will definitely stay in D , therefore
F
we can not get D
(1) and (2) for each x point x ∈ D p ( S 0 ) and p ( S 0 ) ( x ) ⊆
F|π F

F ( x ). That is, the of starting p ( S ) | π applications sequential only


0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 221/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
we
thencan
it follows from ∈ that
get sequences D wethat,
get on
by the
F | one
π . from , ∈ D p ( S 0 ) | π , on the other hand
handthis
F|π
P ( S ) | π ( the ) ⊆ M | π ( in ).
0
- If ∈ ⌈π⌉ then obviously ∈ D and ∈ D p ( S 0) |π, and F | π ( a ) =
F|π
P ( S ) | π ( in ) = {A} .
0

Thus we have seen every point a ∈ A that if ∈ D , then ∈ D p ( S 0) | π and


F|π
p ( S ) | π ( a ) ⊆ F | π ( a ), so DO ( π, S ) solves the task F | π .
0 0

22ndUse the SKIP and ABORT programs introduced in Chapter 8 .


a) Not true. For example, be S = ABORT and π = False . That's right
DO ( π, S ) = SKIP , so:
p ( DO ) = id ⊈ ∅ = p ( S ).
A

b) Not true. For example, be S = SKIP and π = True . That's right


DO ( π, S ) = ABORT , so:

262 SOLUTIONS 15

p ( DO ) = ∅ ⊉ id = p ( S ).
A

23. In this task we refer to the definitions of Chapter 8.

S ((2 , 4)) = { < (2 , 4) , (0 , 4) , (1 , 4) , (3 , 4) , (5 , 4) , (7 , 4) , (9 , 4) ,. . . > }


S ((3 , 7)) = { < (3 , 7) , (0 , 7) , (1 , 7) , (3 , 7) , (5 , 7) , (7 , 7) > }

15.6. Discharge rules


First
Let DO ( π, S ) be the cycle of the cycle derivation rule
0
conditions, ie:
(1) Q ⇒ P ,
(2) P ∧ ¬π ⇒ R ,
(3) P ∧ π ⇒ t> 0,
(4) P ∧ π ⇒-f ( S , P ),
0
(5) P ∧ π ∧ t = t ⇒-f ( S 0 , t < 0 ).
0

the no. Indirectly suppose that ⌈P ∧ R⌉ = ∅ . At this time (2)


for ⌈P ∧ ¬π⌉ = ∅ , that is (6) ⌈P ⌉ ⊆ ⌈π⌉ , and since ⌈Q⌉ = ∅ ,
(1) ⌈P ⌉ = ∅ . Let ∈ ⌈P ⌉ , then (6) be due to ∈ ⌈π⌉ and (3)
t ( a ) > 0. Furthermore, it follows from the terms (4) and (5) that ∈ ⌈lf ( S , P ) ⌉
and the ∈ ⌈lf ( S , t <T ( on )) ⌉ , so there is certainly b ∈ P ( S ) ( the points),
0

for which b ∈ ⌈P ⌉ and t ( b ) <t ( a ). For (6), then b ∈ ⌈π⌉ , so (3)


0 0

due t ( b ) > 0. In other words, we proved that ∀a ∈ ⌈P ⌉ : ∃b ∈ ⌈P ⌉ : 0 <T ( b ) <



t ( a ). Since ∃q ∈ ⌈P ⌉ , then ∃α ∈ ⌈P ⌉ : α = q
and ∀i ∈ N: 0 <t ( α i +1 ) <t ( α ). So the t ( 1α ) values are a natural one
i i
numbers of strictly monotonous decreasing endless series,
which obviously is a contradiction. We can see that ⌈P ∧ R⌉ can not be empty.
b) No, because (2) ⌈P ∧ ¬π ∧ R⌉ = ⌈P ∧ ¬π⌉ , of which a)
we can see that it can not be empty.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 222/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Second
No. Let DO ( π, S ) cycle be the cycle of derivation
(1) to (5) of the Regulation.
0 Then, based on the theorem Q ⇒ lf ( DO, R ), ie:

⌈Q ∧ π⌉ ⊆ ⌈Q⌉ ⊆ ⌈lf ( DO, R ) ⌉ .


In addition:
(1) (4)
⌈Q ∧ π⌉ ⊆ ⌈P ∧ π⌉ ⊆ ⌈lf ( S 0 , P ) ⌉ .

15.6. DRAWING RULES 263

Thus ⌈Q ∧ π⌉ ⊆ ⌈lf ( S , P ) ⌉ ∩ ⌈lf ( DO, R ) ⌉ and since ⌈Q ∧ π⌉ not empty,


⌈lf ( S , P ) ⌉ ∩ ⌈lf ( DO,
0
0
R ) ⌉ not be empty.

Third
Let DO ( π, S ) be the cycle of the cycle derivation rule
0
(1) to (5).
the)It is true, as it has been said before the proof of the rule of deduction of the cycle
1 statement follows.
b) True. Let us know by total induction according to k .
0
If k = 0 then b ∈ g ( q ) ∩ ⌈π⌉ ∩ ⌈P ⌉ = {q} = ⇒ b = q = ⇒
t ( b ) = t ( q ) - 0.
k
- Suppose that ∀b ∈ g ( q ) ∩ ⌈π⌉ ∩ ⌈P ⌉ : t ( b ) ≤k t ( q ) - k , and
be c ∈ g k +1 ( q ) ∩ ⌈π⌉ ∩ ⌈P⌉ = ⇒ ∃b ∈ g ( q ): c ∈ g ( b ).
Then, according to point ( a) b ∈ ⌈P ⌉ , and b ∈ ⌈π⌉ , since
otherwise g ( b ) = p ( S ) | ( b ) would be empty. Therefore, the induction
0 ⌈Π⌉
based on t ( b ) ≤ t ( q ) and condition (5)
b ∈ ⌈lf ( S , t <t ( b )) ⌉ , so ∀x ∈ P ( S ) ( b ): t ( x ) <t ( b ). because
However c0 ∈ g ( b ) = p ( S ), ( b ), so t0 ( c ) <t ( b ) ≤ t ( q ) - k , so
0
t ( c ) ≤ t ( q ) - ( k + 1).
We have seen this statement.
c) True, since:
g|π=(P(S )|
0 ⌈π⌉
)|π=p(S )|
0 ⌈Π⌉
∪ id ⌈π⌉ \ D
p ( S 0)
=P(S )|π.
0

k
d) True. First, let us know if k ∈ N for g ( q ) ⊆
⌈¬π⌉ is satisfied, then ( k + 1) is also
0 satisfied because D
g
⊆ ⌈π⌉ due
k
g k +1 ( q ) = g ( g ( q )) = ∅ . So if there exists such k ≤ t ( q ) then k = t ( q )
it is.
k
Let k = t (k q ) and suppose indirectly that g ( q ) ⊈ ⌈¬π⌉
= ∃x ∈ g ( q ) ∩ ⌈π⌉ . Then x ∈ ⌈P pont is satisfied according to point a)
Thus b) is for t ( x ) ≤ t ( q ) - k = 0. However, x ∈ ⌈P ⌉ ∩ ⌈π⌉ therefore
(3) for t ( x ) > 0, so we have a contradiction. We saw that
g t ( q ) ( q ) ⊆ ⌈¬π⌉ .

'
4thYes. For example, let A = { 1 , 2 } , ⌈Q⌉ = { 1 } , ⌈Q ⌉ = { 1 , 2 } , ⌈R⌉ = { 2 } ,
S = S = { (1 , < 1 , 2 > ) , (2 , < 2 > ) } . Then S = S = S , so:
1 2 1 2

⌈Q⌉ = { 1 } ⊆ { 1 , 2 } = ⌈lf ( S , Q ) ⌉ ,
'

⌈Q ⌉ = { 1 , 2 } ⊆ { 1 , 2 } = ⌈lf ( S 1 , R ) ⌉ ,
'
2
⌈Q⌉ = { 1 } ⊆ { 1 , 2 } = ⌈lf ( S, R ) ⌉ .

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 223/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

264 SOLUTIONS 15

' '
But ⌈Q⌉ ∩ ⌈R⌉ = ∅ , ⌈Q⌉ ∩ ⌈Q ⌉ = { 1 } = ∅ and ⌈Q ⌉ ∩ ⌈R⌉ = { 2 } = ∅ .

5thIn this task we refer to the definitions and definitions in Chapter 8.


act accordingly. The definition of S the same as the following structure
0 is
with the specified program:

y≥ 1 y=0
x:=x-1
SKIP
y:=y-1

So the DO program can be defined using the following structure:

π
y≥ 1 y=0
x:=x-1
SKIP
y:=y-1

The task worded in words is the value of the variable x and y


reduce by y . The S program and all the ciklusiterációban
0
x and y are reduced by one, so in the cycle invariant,
we find that x and y have decreased the same with the original value,
ie:
' '
P = ( ∃z ∈ N: ( x = x - z ∧ y = y - z )) .
Thus, the cyclic condition= is( yπ = 0) will be appropriate, as it is obvious at this time
the paragraph (2) of the cycle deduction rule is met. Also because y is π
if it is positive, and decreases in every iteration, t = y is the corresponding ter-
mining function.
Then use the sequence and the derivation rule of the branch
using the methods used in the derivations in Chapter 12
rectally also be appreciated that for this DO program as defined above P , π and t case
the conditions of the loop management rule are met.

6thIn this task we refer to the definitions and statements in Chapter 8


much. The S = ( S ; ( S ; S )) program struktogramja:
1 2 3

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 224/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.7. BACKGROUND PROGRAMS 265

S : k:=5
1
a> b a≤b
S :
2
x:=a-b x:=b-a
S : i:=i+1
3

' ''
Introduce an intermediate condition Q and Q :
'
Q '' = ( Q ∧ k = 5), ' '
Q = lf ( S, R ) = R i ← i + 1 = ( the = the ∧ b = b ∧ k · ( i + 1) ≤ x ).
3
Then using the methods used in the derivations in Chapter 12
it can be seen that (1) Q ⇒ lf ( S , Q ' ), (2) Q ' ⇒ lf ( S , Q '' ) and Q ''
(3) Q
''
1 ⇒ lf ( S , R ). At this2 time the sequence
(2) and (3), it follows that (4) Q
' 3

lf (( S ; S ) , R ) occurs, and (1) and (4) statements that:
2 3

⇒ Q-f (( S 1 , ( S 2 ; S 3 )) , R ) = LF ( S, R ).
Note: Note that this task requires the deduction rules
used to prove correctness , that is to say, evidence of an existing
We've been involved to solve a given task. However, it is presented in Chapter 12
we do not follow this path in the method of deduction, but from the task (its
based on the derivation rules for sub-tasks
we will create a predefined solution program.

15.7. Basic programs


First a) Definition yes.
b) It is derived from the definition of extension that S elementary program, but M is not
** be 1 is
absolutely. Let M ⊆ C × C a program for which:
M ((2 , a )) = { < (2 , a ) , (2 , b ) , (2 , a ) , (2 , b ) , (2 , a ) ,. . . > } And
M (( x, y )) = S (( x, y )), if ( x, y ) = (2 , a ).
1

Then pr ( M ) = S is satisfied, not only to Mn eq S strength loss & quot


of the
On -n, but M is not an elementary program.

x ← y, y ← x
2 -f ( x, y : = F ( x, y ) , R ) = lf ( x, y : = y, x <y ) = ( x <y ) =y<
x.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 225/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

266 SOLUTIONS 15

3. Make F a job with A that is solved by SKIP . At


p ( SKIP ) = time result D ⊆ A and ∀a ∈ D : period ( in ) = {A} ⊆ M ( to ).
The F F A
So the SKIP program precisely addresses the tasks for which
id F ⊆F .
D

4. Since p ( ABORT ) = ∅ , therefore D ⊆ D p ( ABORT ) is only satisfied with F = ∅ ,


so the ABORT program solves only the task F = ∅ .
F

15.8. Type
First
Let T = ( H, I , F) where
s s

H = [0 .. 99999],
I = Of course ,
s
F = {F , F } .
k e

We pay attention to each task the10.1. and 10.2.


Like Examples T elements for simplicity ( T, x instead) x -
designated segments and T instead of T writing=-t⌈Isuch
⌉ ⊆T H . In this case
T

T s
T = H = [0 .. 99999].

The = T , F
k k
⊆Ak×k,
' '
F = { ( a, a ) | a = f ( a ) } ,
k k

where f : T → T ,
k
{
x + 1 , if x = 99999;
f (x)=
k 0, if x = 99999 .

A =T,F
e and
⊆ A and × A e ,
' '
F = { ( a, a ) | a = f ( a ) } ,
e e

where f : T → T , {
e
x - 1 , if x = 0;
f (x)=
e 99999 , if x = 0 .

Enter the type that matches the type specification. Based on the text of the task
to represent the model values a 10 is a numerical system
their shape as a series of decimals, which two are plain

15.8. TYPE 267

solution. One is to have up to five lengths of sequences


let's let go and let's get started with zero if you can
long and the other is that the series are always exactly five long.
Then, in some cases, we get longer representative sequences, but the
I invariant writing and making operations simpler, so this is the way
selected.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 226/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
*
Let T = ( ρ, I, S) where E = [0 .. 9], I : *E → L,
⌈I⌉ = {α ∈ E | | α | = 5 } ;
*
ρ ⊆ E * × T , ∀α ∈ E :
ρ ( α ) = {g ( α ) } ,
* *
where g : E → T , ∀α ∈ E :
Σ | α | -i
g ( α ) =i α= 1 · 10 .
i

* **
S = {S , S } where B = E and S
k e k k
⊆ B k × Ba program for which:
' ' '
p ( S ) = { ( α, α ) | α ∈ ⌈I⌉ and α ∈ ⌈I⌉ and g ( α ) = f ( g ( α )) } ;
k k
* **
is a program for which:
B = E and S
e e
⊆Be×B
' ' '
p ( S ) = { ( α, α ) | α ∈ ⌈I⌉ and α ∈ ⌈I⌉ and g ( α ) = f ( g ( α )) } .
e e

Then this type corresponds to the above type specification, because it is the ρ definition,
it is clear that the representation is correct ( ρ ( ⌈I⌉ ) = T ), and on the other hand
the programming functions and the representation function simply by entering
that the programs are able to solve the proper tasks through ρ .

Second
Notice that the task F is nothing other than the addition 10
leftovers. Let T = ( ρ, I, S) where S = {S} . Compared to the previous task,
Loan first thought here could be that since E = { 0 , 1 , 2 } , represen-
put the model values in their 3-digit format.
* *
Then ρ ⊆ E × T , ∀α ∈ E :
ρ ( α ) = {g ( α ) } ,
* *
where g : E → T , ∀α ∈ E :

268 SOLUTIONS 15

Σ | α | -i
g ( α ) =i α= 1 · 3 .
i

*
However, I would get the type I : E → L type, for which:
*
⌈I⌉ = {α ∈ E | | α | = 3 and α ≤ 1 and ( α = 1 = ⇒ α = α = 0) } .
1 1 2 3

And obviously, the implementation of the operation would be relatively complicated.


Let's try to give a representation more easily than that
we can formulate the operation on the representative series as the first one
case. Notice that nothing demands that the 3-digit system-
. It's a much simpler representation
is obtained if only one of E's elements (such as 1) is used
a T- element simply with a sequence of equal lengths
* *
represent ρ ⊆ E × T , ∀α ∈ E :
ρ ( α ) = {| α |} ;

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 227/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
*
I : E → L,
*
⌈I⌉ = {α ∈ E | | α | < 10 and ∀i ∈ [1 .. | α | ]: α = 1 } .
i

At this point, the implementation of the operation becomes much simpler. Let B =
* * * **
E × E × E and S ⊆ B × B are programs which:
' ' ' '
p ( S ) = { (( α, β, γ ) , ( α , β , γ )) | α ∈
'
⌈I⌉ and β '∈ ⌈I⌉ and' γ ∈ ⌈I⌉ and
α = α and β = β and | γ | = h ( | α |, | β | ) } ,
where h : N × N → N ,
0 0 0
{
a + b, if a + b < 10;
h ( a, b ) =
a + b - 10 , if a + b ≥ 10 .

Notice that we have not used it anywhere in the series


is the same, so from the type invariant ∀i ∈ [1 .. | α | ]: α = 1 restriction left off
i
can. Then we would get a representation that is not mutually clear,
since ρ | ⌈I⌉ ( - 1) is not deterministic, but it does not cause any problems.
The implementation of this operation would be even simpler if it
to represent the representation of an element ∈ T not necessarily with its value
represent a sequence of the same length, but an arbitrary one
with a sequence that divides the length by ten into the same as a ,
* *
so ρ ⊆ E × T , ∀α ∈ E :

15.8. TYPE 269

ρ ( α ) = { a | α | With 10 for dividing } .

At that time, I can be selected as true for the above and the operation
simply by concatenating two series. However, at this time
ρ | ⌈I⌉ ( - 1) is not deterministic or even unlimitedly deterministic! Ráadá-
our operation is so that it has been repeatedly applied for several times,
so that such a representation does not work in practice
to use.

6thThe set of values is a set of natural numbers, for which the two
we have formulated:

F : give a residual distribution of a natural number to 8;


1
F : Decide from two natural numbers whether they are the same.
2

A natural number is represented by the numerical shape of the number 8.


In both cases we conclude that a representative series is at least one
and in case a) even if zero can only begin if
is a length (ie if it represents zero). So in ab) cases the representative
we are not mutually clear because ρ | ⌈I⌉ ( - 1) is not deterministic.
*
The S program is an e ∈ E element has a series composed of these
the last1 one contains all the members, each member one less,
like the previous, so the last of the series is a series of this last member
will. For example:

S ( < 4 , 1 , 7 , 3 > ) = { << 4 , 1 , 7 , 3 > , < 1 , 7 , 3 > , < 7 , 3 > , < 3 >> } .
1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 228/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
*
So p ( S ) assigns a set of its last member to an e ∈ E element,
which is1obviously the residual distribution of the number represented by this by its 8
represent.
* *
The S program is a ( e, d, l ) ∈ E × E × L element has a series of
( ee, dd,
2 ll ) of which ee and dd are always one of the longest starters

e and d , and ll tell whether ee and dd are the same,


until we reach the end of a series. For example:

S (( < 4 , 1 , 7 , 3 > , < 4 , 1 , 7 , 3 , 2 > , h )) = { < ( < 4 , 1 , 7 , 3 > , < 4 , 1 , 7 , 3 , 2 > , h ),


2
( < 4 > , < 4 > , i ),
( < 4 , 1 > , < 4 , 1 > , i ),
( < 4 , 1 , 7 > , < 4 , 1 , 7 > , i ),
(<4,1,7,3>,<4,1,7,3>,i)>}.

270 SOLUTIONS 15

So p ( S ) is one ( e, d, l ) ∈ E * × E * × L,' there are (e


,d ,l )
' '

'

* *2 ' are the


E × E × L assigns an element for which '
e and' d same starting line of the same length
e and d , such that at least one of e = e and d = d is satisfied,
l ' then specify whether e ' and d 'are the same.
Based on these, it can be seen that representation in both a) and ab) is correct,
and that S both cases resolve F eth ρ through -n. However the
1 1
It is seen from the above example that S does not resolve the F -t ρ through -n, ugya-
2 2
on the one hand p ( S ) does not always keep both series (only if
2
of the same length), and it is even true when the two series do not
it is the same starting point for the other. So, one type of case,
does not meet the specification.

7thIn the following, we will only look at each task


what representation you should choose, based on this in Chapter 10
examples and previous tasks, you can specify the type-specific
fiction and type.
In this task, the most natural representation is the plane vectors
with some coordinates in their base. Then the necessary operations
easy to implement. So if, for example, our model values have a fixed base-
In vectors in integer coordinates, then this could be the set of integers
so we can write each vector with a two-length sequence.

8thLike the previous task, space vectors can be represented by a fixed one
base co-ordinates (three-length series), and so obviously
the operations can be easily implemented.

9thIn this task, a complex number is derived from its algebraic shape ( z = a + ib )
it is desirable to represent it, it is the addition and the imaginary
part definition can be easily implemented. For example, if only Gauss-
(ie, complex numbers with real and
the imaginary part is an integer), then E = Z selects all model values
can be represented by a series of two lengths.

10thIn this task, our model values are just as complex as the numbers
before, but we have to implement other operations. The multiplication is the previous one
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 229/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
even when it comes to representation in a task
the natural exponent is much simpler in case
a complex number is not the algebraic but the trigonometric figure

15.8. TYPE 271

represented properly. Then a z = r ( cosφ + i sinφ ) komp-


n n
lex number n . power of ( n ∈ N): z = r ( cos ( nφ ) + isin ( nφ )). so
provided that there is a type in which a set of real numbers exists
A "sufficiently thick" number set with normal arithmetic operations
we have implemented this type of value set to E , a complex
number can be represented by a trigonometric figure of two
long series, one of which is the absolute value of the complex number
so we have to make sure it is non-negative.

Note: We are reminded that a state space component is a definition


they can be counted at most, so complex or real
set of numbers can not be included as a set of values.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 230/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

272 SOLUTIONS 15

15.9. deduction
First
Specification:
A=Z×Z×Z×Z
mnlb
B=Z ×Z
' '
m ' n '
Q:(m=m ∧n=n ∧m≤n)
R ( Q ∧ b ∈ [ m..n ] ∧ l ∈ [ m..n ] ∧ ∀i ∈ [ m..n ]: f ( b ) ≥ f ( i ) ≥ f ( l ))
It is clear from the specification that we are not allowed to enter the blank interval
and the result is two variables in the state space ( b and l , meaning
the largest, smallest index).
Solution:
This task is used in the programming batches given at intervals,
let's solve it first, we will first assign the function φ .
φ ( m, n, b, l, on, off ) = ( b ∈ [ m..n ] ∧ l ∈ [ m..n ] ∧ f ( l ) = le ∧ f ( b ) = in ∧
∀i ∈ [ m..n ]: be ≥ f ( i ) ≥ le )
With this φ, we actually fix a tightening of the task,
what the function values are in the points in question.
'
Accordingly,
''
the tightened post-condition, invariant property, and Q ,
or Q statement:
R = ( Q ∧ b ∈ [ m..n ] ∧ l ∈ [ m..n ] ∧ f ( l ) = le ∧ f ( b ) = in ∧ ∀i ∈ [ m..n ]:
be ≥ f ( i ) ≥ i )
P = ( Q ∧ k ∈ [ m..n ] ∧ b ∈ [ m..k ] ∧ l ∈ [ m..k ] ∧ f ( l ) = le ∧ f ( b ) = in ∧
∀i ∈ [ m..k ]: be ≥ f ( i ) ≥ le )
'
Q ' = ( Q ∧ k = m ∧ b = m ∧ l = m ∧ off = at = f ( m ))
Q = ( Q ∧ k + 1 ∈ [ m..n ] ∧ b ∈ [ m..k + 1] ∧ l ∈ [ m..k + 1] ∧ f ( l ) = le ∧
f ( b ) = be ∧ ∀i ∈ [ m..k + 1]: be ≥ f ( i ) ≥ le ∧ t = t )
0
S is k, b, l, in, let : = m, m, m, f ( m ) , f ( m ). But what can S mean?
1
The solution will of course be a branch, which is P ∧ 2π ∧ t = t 0

''
lf ( S , Q ).
2

S
2

f ( k + 1) ≤ le f ( k + 1) ≥ be Let ≤ f ( k + 1) ≤ be
1, let : = k + 1 , f ( k + 1) b, be : = k + 1 , f ( k + 1) SKIP

Let's look at this branch.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 231/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.9. deduction 273

( )

1. P ∧ π ∧ t = t ⇒ π
0
i=1 i
f ( k + 1) ≤ down ∨ f ( k + 1) ≥ to ∨ down ≤ f ( k + 1) ≤ in ⇔ ( f ( k + 1) ≤ down ∨
f ( k + 1) ≥ to ∨ down ≤ f ( k + 1)) ∧ ( f ( k + 1) ≤ down ∨ f ( k + 1) ≥ ≥ introduced into ∨
f ( k + 1)) ⇔ true . And everything is right.

''
2. ∀i ∈ [1 ..n ]: P ∧ π ∧ t = t ∧ π i ⇒-f ( S i , Q )
0
(the)f ( k + 1) ≤ le :
( Q ∧ k ∈ [ m..n - 1] ∧ b ∈ [ m..k ] ∧ l ∈ [ m..k ] ∧ f ( l ) = le ∧ f ( b ) =
in ∧ ∀i ∈ [ m..k ]: in ≥ f ( i ) ≥ down ∧ t = t ∧ f ( k + 1) ≤ le )
0
⇒?
lf ( 1, le : = K + 1 , f ( k + 1) , Q ' ) = ( Q ∧ k + 1 ∈ [ m..n ] ∧ b ∈
[ M..k + 1] ∧ k + 1 ∈ [ m..k + 1] ∧ f ( k + 1) = k + 1 ∧ f ( b ) =
be ∧ ∀i ∈ [ m..k + 1]: be ≥ f ( i ) ≥ f ( k + 1) } ∧t = t 0 ))
| {z
√ ∀i∈ [ m..k ] be≥f ( i ) ≥f ( k +1) ∧f ( k +1) ≥f ( k +1)

(B) f ( k + 1) ≥ be : Similarly
(C) Let ≤ f ( k + 1) ≤ be :
( Q ∧ k ∈ [ m..n - 1] ∧ b ∈ [ m..k ] ∧ l ∈ [ m..k ] ∧ f ( l ) = le ∧ f ( b ) =
in ∧ ∀i ∈ [ m..k ]: in ≥ f ( i ) ≥ down ∧ t = t ∧ down ≤ f ( k + 1) ≤ in )
0
⇒?
Q'
lf ( SKIP, ) = ( Q ∧ k + 1 ∈ [ m..n ] ∧ b ∈ [ m..k + 1] ∧ l ∈ [ m..k +
1] ∧ f ( l ) = le ∧ f ( b ) = in ∧ ∀i ∈ [ m..k + 1]: in ≥ f ( i ) ≥ down } ∧ t =
| {z
∀i∈ [ m..k ]: be≥f ( i ) ≥le∧be≥f ( k +1) ≥le
t√ )
0

k, b, l, be, le : = m, m, m, f ( m ) , f ( m )
k=n
f ( k + 1) ≤ le f ( k + 1) ≥ be Let ≤ f ( k + 1) ≤ be
1, let : = k + 1 , f ( k + 1)b, be : = k + 1 , f ( k + 1) SKIP
k:=k+1

Second
Specification:
A=N×N×N
x y the

274 SOLUTIONS 15

B=N×N
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 232/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
' '
x ' y '
Q:(x=x ∧y=y )
R : ( Q ∧ a = lnko ( x, y ))
Solution:
The solution is a cycle whose invariant is:
P = ( Q ∧ a ∈ [1 ..x ] ∧ b ∈ [1 ..y ] ∧ gcd ( a, b ) = gcd ( x, y ))
Check the terms of the cycle:
1. Q ⇒ P

'
As usual, we introduce the new state Q , which is already
'
fulfilled,
also indicate by S program with which Q ⇒-f ( S 1 , Q ).
1
'
Q =(Q∧a=x∧b=y)
S = ( a, b : = x, y )
1

2. P ∧ ¬π ⇒ R
This condition puts the cycle condition in hand, as it compares P and R
¬π is given by a = b (since a = b = lnko ( a, b ) can only be fulfilled). so
π = ( a = b ).

a, b : = x, y
a=b

3. P ∧ π ⇒ t> 0
In this case, this is: Q ∧ a ∈ [1 ..x ] ∧ b ∈ [1 ..y ] ∧ lnko ( a, b ) = lnko ( x, y ) ⇒
t> 0. So t : = a + b is an appropriate termination function.

5. P ∧ π ∧ t = t ⇒-f ( S , t < )
0 0 0
Verify that the following program provides this property:

S
0

<b
b:=b-a a:=a-b

15.9. deduction 275

( )

5/1. P ∧ π ∧ t = t ⇒ π
0 i
i=1

This is obviously fulfilled (indeed it is true that the whole state of space is described).
5/2. ∀i ∈ [1 ..n ]: P ∧ π ∧ t = t ∧ π ⇒ lf ( S , t <t )
0 and i 0

(a) a <b : P ∧ π ∧ a + b = t Lf ⇒ ( b : = b - a, t <t ) = to + b - a = b <


?
t √ (since a> 0) 0 0
0

(b) a ≥ b : P ∧ π ∧ a + b = t ⇒? lf ( the : = a - b, t <t 0 ) = a - b + b = the <


t √ (since b> 0) 0
0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 233/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

4. P ∧ π ⇒-f ( S , P )
0
In our case:
( Q ∧ a ∈ [1 ..x ] ∧ b ∈ [1 ..y ] ∧ gcd ( a, b ) = gcd ( x, y ) ∧ of = b ) ⇒?
lf ( S , P )
0 ( )
⋁ √
4/1. P ∧ π ⇒ π
i
i=1

4/2. ∀i ∈ [1 ..n ]: P ∧ π ∧ π ⇒ lf ( S i , P )
and

(a) a <b : P ∧ π ∧ a <b ⇒? lf ( b : = b - a, p )


( Q ∧ a ∈ [1 ..x ] ∧ b ∈ [1 ..y ] ∧ gcd ( a, b ) = gcd ( x, y ) ∧ <b )
⇒?
lf ( b : = b - a,√ P ) = ( Q ∧ a ∈ [1 ..x ] ∧ b - ∈ [1 ..y ] ∧ gcd ( a, b - a ) =
lnko ( x, y ))
⇒ lf ( a : = a - b, p )
( Q ∧ a ∈ [1 ..x ] ∧ b ∈ [1 ..y ] ∧ gcd ( a, b ) = gcd ( x, y ) ∧ a> b )
⇒?
lf ( the : = a -√b, P ) = ( Q ∧ - b ∈ [1 ..x ] ∧ b ∈ [1 ..y ] ∧ gcd ( a - b, b ) =
lnko ( x, y ))
The following items are necessary to recognize these consequences:
Let y ( x, y ) = q ⇒ lnko ( x - y, x ) = q if x> y.
proof:
C : = {c ∈ N, c | c ∧ x | y} ⇒ ∀c ∈ C ( ∃k, n ∈ N : kc = x ∧ nc = y ∧ k>
n ∧ ( k - n ) c = x - y ) ⇒ ∀c ∈ C : c | x - y
However, D = {d ∈ N, d | x ∧ d | x - y} ⇒ ∀c ∈ C : d | y
So C = D = {e ∈ N: e | x ∧ e | y ∧ e | x - y} . But if it is a set of common divisors
is exactly equal (and finite), then the maximum element (lnko) equals. with this
the item was shown.

276 SOLUTIONS 15

a, b : = x, y
a=b
<b
b:=b-a a:=a-b

Third
Specification:
A=N×N×N
x y the
B=N×N
' '
x ' y '
Q:(x=x ∧y=y )
R : ( Q ∧ a = lkkt ( x, y ))
From the specification, it can be seen that the result is the variable of the state space
providers.
Solution:
The solution-matching program will consist of a sequence,
the first half of which is the least common shared algorithm (Fig.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 234/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
' '
Q ∧ latter
R = ( The
task). a = lnko
condition
( x, y ))is called R :
Let's look at the sequencing rule now:
' '
( Q-f ⇒ ( S , R ) ∧ R ⇒-f ( S 1 , R )) ⇒ ( Q ⇒ lf (( S 0 ; S 1 ) , R ))
0 '
The first half of the condition is justifiedxyby the proof of task 2, so we are only R ⇒
We prove that f ( S , R ) is S : = ( a : = a ) program.
1xy 1
lf (' S , R ) = ( Q ∧ the = lkkt ( x, y )), where a = lnko ( x, y ) (taking
xy
into account
) = ( x, y ) ) jutot-
1
R ). So from the mathematics well known theorem ( lkkt ( x, y lnko
We.

a, b : = x, y
a=b
<b
b:=b-a a:=a-b
xy
a:= the

4th

15.9. deduction 277

• Solution 1
Specification:
A=Z×N×Z
x n r
B=Z×N
' '
x ' n '
Q : ( x = x ∧ nn= n ∧ n = 0)
R:(Q∧r=x )
Solution:
Now, look for the solution program that matches the specification! THE
solution is believed to be found by a cycle. Well, what should be
the invariant of this cycle?
k
P = ( Q ∧ k ∈ [1 ..n ] ∧ r = x )
Check the terms of the cycle:
1. Q ⇒ P
'
Q =(Q∧k=1∧r=x)
' '
Q ⇒ P and Q ⇒ lf ( k, r : = 1 , x, Q ) = Q ∧ 1 = 1 ∧ x = x ⇔ Q .

2. P ∧ ¬π ⇒ R
P and R compare to ¬π for k = n . So π = ( k = n ).

k, r : = 1 , x
k=n

3. P ∧ π ⇒ t> 0
k
In this case, this is: Q ∧ k ∈ [1 ..n - 1] ∧ r = x ⇒ t> 0. So t : = n - k
an appropriate termination function.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 235/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
4./5. P ∧ π ∧ t = t ⇒-f ( S , P ∧ t < )
The solution is provided
0 by0 a sequence
0 whose intermediate state is lf ( k : =

k + 1 , P ) ∧ t = t selected.
0 is
' s
Q = ( Q ∧ k + 1 ∈ [1 ..n ] ∧ r = x k +1 = x · x ∧t=t0)
To this state P ∧ t = t by r : = x r ,
k 0 can be obtained
because P is r = x .
Q ∧ k ∈ [1 ..n - 1] ∧ r = x ∧k t = t
k
√ ⇒? lf ( r : = x · r, Q ' ) = Q ∧
k + 1 ∈ [1 ..n ] ∧ x · r = x · x ∧ t = t
0

Q ∧ k + 1 ∈ [1 ..n ] ∧ r = x k +1 = x · x
0s
∧n-k=t0 ⇒? lf ( k : =

278 SOLUTIONS 15

k
k + 1 , P ) ∧ t <t√ = Q ∧ k + 1 ∈ [1 ..n ] ∧ r = x k +1 = x · x ∧
n-k- 1 <t 0
0

k, r : = 1 , x
k=n
r:=x·r
k:=k+1

• Solution 2
Specification:
A=Z×N×Z
x n r
B=Z×N
' '
x ' n '
Q : ( x = x ∧ nn= n ∧ n = 0)
R:(Q∧r=x )
Solution:
From the first solution, only 4./5. . The new cycle core:

2 · k≤n
k, r : = 2 · k, r · r k, r : = k + 1 , r · x

That this branch reduces the termination function value to triviality.

4. P ∧ π ⇒-f ( S( , P ) )
0

4/1. P ∧ π ⇒ π
i=1 i

For simplified branches of this form, this is always true, since the
the condition of the sod is really the first accurate negation, so the state space is all
two of them are true.
4/2. ∀i ∈ [1 ..n ]: P ∧ π ∧ π ⇒ lf ( S , P )
and i

(a) k · 2 ≤ n :
k k ⇒ Q ∧ 2 · k ∈ [1 ..n ] ∧
r · r = x 2·k= x · x √
(b) k · 2 > n :
k ⇒ Q ∧ k + 1 ∈ [1 ..n ] ∧
· x r = x k + 1 = x · x√

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 236/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.9. deduction 279

k, r : = 1 , x
k=n
2 · k≤n
k, r : = 2 · k, r · r k, r : = k + 1 , r · x

Note that in this second solution, the same cycle-


we have written a different cycle core for invariant.
• Solution 3
Specification:
A=Z×N×Z×Z
x n r b
B=Z×N
' '
x ' n '
Q : ( x = x ∧ nn= n ∧ n = 0)
R:(Q∧r=x )
Solution:
n k
P = ( Q ∧ k ∈ [0 .. ] ∧ x = r · b )
n

Check the terms of the cycle:


1. Q ⇒ P
'
Q ' = ( Q ∧ k = n ∧ b = x ∧ r = 1) '
Q ⇒ P and Q ⇒ lf ( s, b, r : = n, x 1 , Q ) = Q .
2. P ∧ ¬π ⇒ R
P and R compare to ¬π to k = 0. So π = ( k = 0).
(Note: Currently b = 1 can be considered, but the task is later
it would not be appropriate for part of it.)
k, b, r : = n, x, 1
k=0
S
2

3. P ∧ π ⇒ t> 0
n k
In this case, this is: Q ∧ k ∈ [1 ..n ] ∧ x = r · b ⇒ t> 0. So t : = k is a
appropriate termination function.
5. P ∧ π ∧ t = t ⇒-f ( S , t < )
0 0 0

Since t = k , the solution can only be reduced by k . Let's look at the following struk-
togram for S :
2

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 237/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

280 SOLUTIONS 15

2|k
k, b : = k / 2 , b · b k, r : = k - 1 , r · b

To prove that this branch always reduces the value of k, it is


I leave the reader.

4. P ∧ π ⇒-f ( S , P )
0
To justify this claim, the conditions for the derivation rule of the branch must be met
check :( )

4/1. P ∧ π ⇒ π
i=1 i

For simplified branches of this form, this is always true, since the
the condition of the sod is really the first accurate negation, so the state space is all
two of them are true.
4/2. ∀i ∈ [1 ..n ]: P ∧ π ∧ π ⇒ lf ( S , P )
and i

(the)2 | k :
n k ? n
=
r · ∧( bk ·∈b[1) k../ 2 √] ∧ x = r · b ∧ 2 | k ⇒ Q ∧ k / 2 ∈ [0 .. n ] ∧ x
n
Q

(B) ¬ (2 | k ):
∧ ¬ (2 | k ) ⇒ Q ∧ k - 1 ∈ [0 ..n ] ∧
n k ?

x ∧=kr ∈· b[1· b..nk-]1 ∧√ x = r · b


n
Q

k, b, r : = n, x, 1
k=0
2|k
k, b : = k / 2 , b · b k, r : = k - 1 , r · b

7th
Specification:
V = vect ( H, Z)
A=V ×V ×Z
x y r
B=V ×V
' '
x ' y '
Q : ( x = x ∧ y = y ∧ x.dom = y.dom )
R:(Q∧
Σ
r= ( X i ( x.lob ) - y succ ( y.lob ) ) · ( x succ ( x.lob ) - y succ ( y.lob ) ))
j i j

succ
i=0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 238/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.9. deduction 281

Solution:
The invariant of the solving cycle:
P = ( Q ∧ k ∈ [0 ..x.dom ]
Σ
∧r = ( X i ( x.lob ) - y succ j ( y.lob ) ) · ( x succ i ( x.lob ) - y succ j ( y.lob ) ))
succ
i=0

Check the terms of the cycle:


1. Q ⇒ P

'
Q = ( Q ∧ k = 0 ∧ r = 0)
' '
It can be seen that Q ⇒ P and Q ⇒ lf ( k, r : = 0 , 0 , Q )=Q.

2. P ∧ ¬π ⇒ R
π = ( k = x.dom ).
The program looks like this:

k, r : = 0 , 0
k = x.dom
S
2

3. P ∧ π ⇒ t> 0
In this case, this is: ( Q ∧ k ∈ [0 ..x.dom - 1] ∧ r = · · · ) ⇒ t> 0,
t = x.dom - k is an appropriate termination function.

4./5. P ∧ π ∧ t = t ⇒-f ( S , P ∧ t < )


0 0 0
Be the sequence S , intermediate condition:
'' 2
Q = ( lf ( k : = k + 1 , P ) ∧ t = t ) = ( Q ∧ k + 1 ∈ [0 ..x.dom ] ∧
Σ 0
∧r = ( X i ( X.lob ) + y succ ( y.lob ) ) · ( x succ ( x.lob ) -y succ ( y.lob ) )) ∧ t = t 0 )
succ
j i j

i=0

lf ( P ∧ π ∧ t = t , r : = r + ( x k ( X.lob ) + y succ
k
( y.lob ) ) · ( x succ
k
( x.lob ) -
?
0
'√ succ
y k ( y.lob ) )) ⇒ Q '
succ

Q = ( lf ( k : = k + 1 , P ) ∧ t = t })⇒ lf ( k : = k + 1 , P ∧ t <t ) = lf ( k : =
'' ?

k + 1 , P ) ∧ lf ( k : = k + 1 , t < 0)
0

| {z 0
x.dom-k- 1 <t 0

282 SOLUTIONS 15

k, r : = 0 , 0
k = x.dom
r:=r+(x k ( X.lob ) + y succ
k
( y.lob ) ) · ( x succ
k
( x.lob ) - y succ
k
( y.lob ) )
succ

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 239/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
k:=k+1

Note: If you do not consider permissible actions in the program a


succ reference to a hatványára, the function in question
can be replaced by a variable, then we get the following program:

xi, yi, r, k : = pred ( x.lob ) , pred ( y.lob ) , 0 , 0


k = x.dom
( xi ) + y succ ( yi ) ) · ( x succ ( xi ) - y succ ( yi ) ) r : = r + ( x succ ( xi )
k, xi, yi : = k + 1 , succ ( xi ) , succ ( yi )

Also, if the vector (less commonly) vector (Z , Z)


i
Let's imagine, then add formulas like succ ( x.lob )
i.e., x.lob + i are simplified:

k, r : = 0 , 0
k = x.dom

r : = r + ( x x.lob + k + y y.lob + k ) ·
· ( X x.ob + k - y y.lob + k )

k:=k+1

8th
Specification:
V = vect (Z , Z)
A=V ×Z
x r
B=V
'
x '
Q:(x=x ) )
Σ and
R:Q=r= ( - 1) ·x
i = x.lob i

15.9. deduction 283

Solution:
Cycle( invariant for the solution: )
Σ
P = Q ∧ k ∈ [ x.ob - 1 ..x.ib ] ∧ r = ( - 1)
and
·x
i = x.lob i
Check the terms of the cycle:
1. Q ⇒ P
'
Q = ( Q ∧ k = x.lob - 1 ∧ r = 0)
' Q'
Q ⇒ P and Q ⇒ lf ( k, r : = x.lob - 1 , 0 , )=Q.

2. P ∧ ¬π ⇒ R
π = ( k = x.hib ).

k, r : = x.lob - 1 , 0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 240/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
k = x.hib
S
2

3. P ∧ π ⇒ t> 0
In this case: ( Q ∧ k ∈ [ x.lob - 1 ..x.hib - 1] ∧ r = · · · ) ⇒? t> 0, ie
the terminal function: t : = x.hib - k . This function is P ∧ π is obvious
positive.

4./5. P ∧ π ∧ t = t ⇒-f ( S , P ∧ t < )


0 0 0
The solution is searched as a sequence, the second instruction of which is k : =
''
k + 1 seems to be impractical, so the Q condition, the LF ( k : = k + 1 , P ) ∧ t = t
form: 0
( )
'
Σ and
Q = Q ∧ k + 1 ∈ [ x.lob - 1 ..x.hib ] ∧ r = i = x.lob
( - 1) · x ∧ t = t
i 0
'' is
( r : = r + ( - 1) k +1 x k + 1 )
Q replaced by S : =
in the first part of the
21 sequence.

Σ
P ∧ π ∧ t = t = ( Q ∧ k ∈ [ x.lob- 1 ..x.hib- 1] ∧ r =
and
0
i = x.lob
( - 1) · x ∧ t =
i

t )⇒?
lf ( S , Q ' ) = ( Q ∧ k +1 ∈ [ x.lob- 1 ..x.hib ] ∧ r + ( - 1) k + 1 · x k +1 =
0 21
Σ i √
( - 1) · x ∧ t = t )
i = x.lob i 0

''
Q = lf ( k : = k + 1 , P ) ∧ t = t ⇒
√ lf ( k : = k + 1 , P ∧ t <t 0 ) = ( lf ( k : =
?

k + 1 , P ) ∧lf ( k : = k + 1 , t <t 0 ))
0

284 SOLUTIONS 15

k, r : = x.lob - 1 , 0
k = x.hib
r : = r + (( - 1) k + 1 · x k +1 )
k:=k+1

9th
Specification:
V = vect (Z , Z)
A=V ×Z×Z×L×L×{1,2}×Z
v z z l l r rsz
1 2 1 2
B=V ×Z ×Z
' ' '
v ' z1 z2
Q : ( v = v ∧ z = z 1∧ z = z 2∧ z 2 = z 1 )
' '

R ( Q ∧ ∀i ∈ [1 .. 2]: l = ( ∃
1 2 j ∈ [ v.lob..v.hib ]: z = v ) ∧ ( L ∧ L ) → ( r =

1 ↔ g ( z ) <g ( z )) i ∧ ( L ∧ ¬l ) → r = 1 ∧ (i l ∧j ¬l ) → 1
r = 22 ∧ ( l ∨
1 2 1 2 2 1 1
l ) → rsz = z ), where
D = {x ∈ Z | ∃i ∈ [ v.lob..v.hib ]: v = x}, ∀x ∈ D : g ( x ) = i , if
2 r

i ∈ [ v.lob..v.ib ] ∧ v = x ∧ ∀j ∈ [ v.lob..i - 1]: v = x


g i g

i j
Informally: enter the index of the first occurrence of g ( x ) x in the vector. THE
the specification thus describes that the two logical variables separately show the
at the end of the program, whether the given integers are present. If all
Two occurs, including those previously occurring number rsz and to
"index" for r . If only one number occurs, the rsz
this number, while r contains the "index".

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 241/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Solution:
Use it at the programming batches given at the interval
with the remark that m - 1 , n is now the function v.lob - 1 , v.hib
will take over.
φ ( m, n, z , z , l , l , r, rsz ) = ( ∀i ∈ [1 .. 2]: l = ( ∃j ∈ [ m, n ]: z = v ) ∧
( L ∧ L ) → ( r = 1 ↔ g ( z ) <g ( z )) ∧ ( L ∧ ¬l ) → r = 1 ∧ ( l ∧ ¬l ) →
1 2 1 2 i i j

r = 2 ∧ ( l ∨ l ) → rsz = z )
1 2 1 2 1 2 2 1

1 2 r
Using this:
R = ( Q ∧ φ ( v.lob, v.hib, z , z , , l , r, rs ))
P = ( Q ∧ k ∈ [ v.lob - 1 ..v.hib
1
]2 ∧ 11φ ( v.lob,
2
k, ... )) = ( Q ∧ k ∈ [ v.lob -
1 ..v.hib ] ∧ ∀i ∈ [1 .. 2]: l = ( ∃j ∈ [ v.lob..k ]: z = v ) ∧ ( L ∧ L ) → ( r =
1 ↔ g ( z ) <g ( z )) ∧ ( L ∧ ¬l ) → r = 1 ∧ ( l ∧ ¬l ) → r = 2 ∧ ( l ∨
i i j 1 2

1 2 1 2 2 1 1
l ) → rsz = z )
2' r
Q = ( Q ∧ k = v.lob - 1 ∧ φ ( v.lob, k, ... )) = ( Q ∧ k = v.lob - 1 ∧ L =
false ∧ l = false ) 1
2

15.9. deduction 285

''
Q = ( lf ( k : = k + 1 , P ) ∧ t = t ) = ( Q ∧ k + 1 ∈ [ v.lob - 1 ..v.hib ] ∧ ∀i ∈
[1 .. 2]: l = ( ∃j ∈ [ v.lob..k + 1]: 0z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <
g ( z )) ∧ ( L ∧ ¬l ) → r = 1 ∧ ( l ∧ ¬l ) → r = 2 ∧ ( l ∨ L ) → rsz =
i i j 1 2 1

z ∧t=t )
2 1 2 2 1 1 2

r 0
The initial assignment k, l , l : = v.lob - 1 , false, false .
1 2

k, l , l : = v.lob - 1 , false, false


1 2

k = v.hib

k:=k+1

The first subprogram of the cycle core (before increasing the cycle variable) is one
Q ''
S must be a branched structure which satisfies P ∧ π ∧ t = t ⇒-f ( S , ) condition.
2
For technical reasons, we differ from the usual stuktogram: 0 2

•l
1
∧ l 2 then SKIP ,
• z = v k +1 ∧ z = v k +1 , then SKIP ,
1 2
• ¬l ∧ ¬l 2 ∧ v k +1 = z 1 then l 1 , r, rsz : = true 1 , z 1 ,
1
• ¬l ∧ ¬l ∧ v k +1 = z , then l , r, rsz : = true 2 , z ,
1 2 2 2 2
• ¬l ∧ l ∧ v k +1 = z then l : = true ,
1 2 1 1
• ¬l ∧ l ∧ v k +1 = z then SKIP ,
1 2 1
• ¬l ∧ l ∧ v k +1 = z , then l : = true ,
2 1 2 2
• ¬L ∧ l ∧ v k +1 = z then SKIP .
2 1 2

( )

1. P ∧ π ∧ t = t ⇒ π
0 i
i=1
The common disjunction of the conditions is always true.
''
2. ∀i ∈ [1 ..n ]: P ∧ π ∧ t = t ∧ π i ⇒-f ( S i , Q )
0

(a) l ∧ l
Q ∧ k ∈ [ v.lob - 1 ..v.hib - 1] ∧ ∀i ∈ [1 .. 2]: l = ( ∃j ∈ [ v.lob..k ]:
1 2

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 242/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
z ∧=(vl )∧∧¬l
1 ( L )∧ 2 ∧((rl= ∨
→Lr =) → 1↔ L g) →( z RSZ ∧ ∧( L( L1 ∧1 ∧L ¬l
) <g= (zz ) )) ) ∧)t →
= tr =
?i
= ( Q ∧ k + 1 ∈ [ v.lob - 1 ..v.hib ] ∧ ∀i ∈ [1 .. 2]:
j2 11 2 1 2 1 r2 2 2 0
' '
⇒ lf ( SKIP, Q )
l = ( ∃j ∈ [ v.lob..k + 1]: z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <
g ( z )) ∧ ( L ∧ ¬l√ ) → r = 1 ∧ ( l ∧ ¬l ) → r = 2 ∧ ( l ∨ L ) →
i i j 1 2 1

RSZ = z ∧ t = t )
2 1 2 2 1 1 2

r 0

286 SOLUTIONS 15

(B) z = v k +1 ∧ z = v k +1
Q ∧ k ∈ [ v.lob - 1 ..v.hib - 1] ∧ ∀i ∈ [1 .. 2]: l = ( ∃j ∈ [ v.lob..k ]:
1 2

z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <g ( z )) ∧ ( L ∧ ¬l ) → r =
i

1 ∧ ( 1 ∧ ¬ ) → r = 2 ∧ ( l ∨ l ) → rs = z ) ∧ z = v k +1 ∧ z =
i j 1 2 1 2 1 2

v k+1∧ t = t
2 11 1 2 r 1 2

⇒ lf ( SKIP, Q ) = ( Q ∧ k + 1 ∈ [ v.lob - 1 ..v.hib ] ∧ ∀i ∈ [1 .. 2]:


? ' '

l = ( ∃j ∈ [ v.lob..k + 1]: z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <


g ( z )) ∧ ( L ∧ ¬l√ ) → r = 1 ∧ ( l ∧ ¬l ) → r = 2 ∧ ( l ∨ L ) →
i i j 1 2 1

RSZ = z ∧ t = t )
2 1 2 2 1 1 2

r 0
(C) ¬l ∧ ¬l ∧ v k +1 = z
Q ∧ k ∈ [ v.lob - 1 ..v.hib - 1] ∧ ∀i ∈ [1 .. 2]: l = ( ∃j ∈ [ v.lob..k ]:
1 2 1

z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <g ( z )) ∧ ( L ∧ ¬l ) → r =
i

1 ∧ ( l ∧ ¬l ) → r = 2 ∧ ( l ∨ L ) → RSZ = z ) ∧ v k +1 = z ∧ ¬l ∧
i j 1 2 1 2 1 2

¬l ∧ t = t
2 1 1 2 r 1 1

⇒? -f ( l 1 , r, rsz : = true, 1 , z 1 , Q ' ) = ( Q ∧ k + 1 ∈ [ v.lob - 1 ..v.hib ] ∧


2 0

right = ( ∃j ∈ [ v.lob..k + 1]: z = v ) ∧ L = ( ∃j ∈ [ v.lob..k + 1]: z =


v ) ∧ ( true ∧ L ) → (1 = 1 ↔ g ( z ) <g ( z )) ∧ ( true ∧ ¬l√ ) → 1 =
1 j 2 2

1 ∧ ( l ∧ ¬igaz ) → 1 = 2 ∧ ( true ∨ L ) → z = z ∧ t = t )
j 2 1 2 2

2 2 1 1 0
(D) ¬l ∧ ¬l ∧ v k +1 = z
1 2 2
like
(E) ¬l ∧ l ∧ v k +1 = z
Q ∧ k ∈ [ v.lob - 1 ..v.hib - 1] ∧ ∀i ∈ [1 .. 2]: l = ( ∃j ∈ [ v.lob..k ]:
1 2 1

z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <g ( z )) ∧ ( L ∧ ¬l ) → r =
i

1 ∧ ( 1 ∧ ¬ ) → r = 2 ∧ ( l ∨ l ) → rsz = z ) ∧ z = v k +1 ∧ l ∧
i j 1 2 1 2 1 2

¬l ∧ t = t
2 11 1 2 r 1 2

? 1 0

⇒ lf ( l 1 : = true, Q ) = ( Q ∧ k + 1 ∈ [ v.lob - 1 ..v.hib ] ∧ true =


' '

( ∃j ∈ [ v.lob..k + 1]: z = v ) ∧ L = ( ∃j ∈ [ v.lob..k + 1]: z = v ) ∧


( True ∧ L ) → ( r = 1 ↔ g ( z ) <g ( z )) ∧ ( true ∧ ¬l ) → √ r=1∧
1 j 2 2 j

( L ∧ ¬igaz ) → r = 2 ∧ ( true ∨ L ) → RSZ = z ∧ t = t )


2 1 2 2

2 2 r 0
(F) ¬l ∧ l ∧ v k +1 = z
Q ∧ k ∈ [ v.lob - 1 ..v.hib - 1] ∧ ∀i ∈ [1 .. 2]: l = ( ∃j ∈ [ v.lob..k ]:
1 2 1

z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <g ( z )) ∧ ( L ∧ ¬l ) → r =
i

1 ∧ ( 1 ∧ ¬ ) → r = 2 ∧ ( l ∨ l ) → rsz = z ) ∧ z = v k +1 ∧ l ∧
i j 1 2 1 2 1 2

¬l ∧ t 2= t 1 1 1 2 r 1 2

? 1 0

⇒ lf ( SKIP, Q ) = ( Q ∧ k + 1 ∈ [ v.lob - 1 ..v.hib ] ∧ ∀i ∈ [1 .. 2]:


' '

l = ( ∃j ∈ [ v.lob..k + 1]: z = v ) ∧ ( L ∧ L ) → ( r = 1 ↔ g ( z ) <


g ( z )) ∧ ( L ∧ ¬l√ ) → r = 1 ∧ ( l ∧ ¬l ) → r = 2 ∧ ( l ∨ L ) →
i i j 1 2 1

RSZ = z ∧ t = t )
2 1 2 2 1 1 2

r 0
(G) ¬l ∧ l ∧ v k +1 = z
2 1 2
similarly to (e).

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 243/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.9. deduction 287

(H) ¬l ∧ l ∧ v k +1 = z
2 1 2
similarly to (f).
10th
First we solve a little simpler task: the vector is a specific el-
we put it in its place.
Note: This task and first solution was originally implemented by Hoare, a
as part of a rapid deployment. He gave the following solution (the correctness of which was
we do not prove it, we only serve a state-of-the-art explanatory table):
THEthe vector to be sorted
i left-handed indicator
j right-hand cursor (shows the new index of the pivot element at the end)
p the lower index of the vector, and the index of the pivot element
r the upper index of the vector

x, i, j : = A [ p ] , p + 1 , r
i <j
A [ i ] ≤ x ∧ i <j
i:=i+1
A[j]≥x∧i≤j
j:=j-1
i <j
A [ i ] , A [ j ]: = A [ j ] , A [ i ]
SKIP
i, j : = i + 1 , j - 1
A [ j ] , A [ p ]: = A [ p ] , A [ j ]

We take another solution, namely Lomu's solution


look. This is also different from Hoare's solution to being the first one
restores the last element.
Specification:
A=V ×Z
x i
V = vect (Z , Z)
B=V
'
x '
Q :( x = x )

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 244/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

288 SOLUTIONS 15

' '
R : ( x ∈ perm ( x ) ∧ i ∈ [ x.lob..x.hib ] ∧ x [ i ] = x .hiv ∀k ∈ ∧ [ x.lob..i- 1]:
x ≤ x ∧ ∀k ∈ [ i + 1 ..x.hib ]: x > x )
k i k i
' '
x ∈ perm ( x ) describes the x components of the vector are the same as the x e,
only their order is different.
Solution:
The solution is easy to reach (with a permissible simultaneous assignment)
'
if 'R condition is already
'
fulfilled : '
R = ( x ∈ perm ( x ) ∧ i ∈ [ x.lob - 1 ..x.hib - 1] ∧ x.hiv = x .hiv ∈ ∧ ∀k
[ X.lob..i ]: x ≤ x.hiv ∧ ∀k ∈ [ i + 1 ..x.hib - 1] x > x.hiv )
k k
'
Thus, they expel R for a new condition , and if we get there, then the sequence
derivation rule then applied to the existing program and R into the leading
i, x and +1 , x.hiv : = i + 1 , x.hiv, x and +1 , so that the full resolution program-
we get it.
Now write the invariant of the cycle leading to the new post-condition:
=P(x∈
' '
perm ( x ) ∧ j ∈ [ x.lob..x.hib ] ∧ i ∈ [ x.lob - 1 ..j - 1] ∧ x.hiv = x .hiv ∧
∀k ∈ [ x.ob..i ]: x ≤ x.hiv ∧ ∀k ∈ [ i + 1 ..j - 1]: x > x.hiv )
k k
Check the terms of the cycle:
1. Q ⇒ P
'
Q = ( Q ∧ i = x.lob - 1 ∧ j = x.lob )
' '
It can be seen that Q ⇒ P and Q ⇒ lf ( i, j : = x.lob - 1 , x.lob, Q )=Q.
'
2. P ∧ ¬π ⇒ R '
It is obtained in the condition of the cycle from this point, since P and R com-
¬π is given by x.hib = j . So π = ( j = x.hib ).

i, j : = x.lob - 1 , x.lob
j = x.hib

i, x and +1 , x.hiv : = i + 1 , x.hiv, x and +1

3. P ∧ π ⇒ t> 0
In this case, this is: j ∈ [ x.lob..x.ib - 1] ∧ · · · ⇒ t> 0. So t : = x.hib - j
an appropriate termination function.
4. P ∧ π ⇒-f ( S , P )
0

Let's look at the following structure for S :


0

15.9. deduction 289

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 245/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

x ≤ x.hiv
j

i, j, x and +1 , x : =
j j:=j+1
i + 1 , j + 1 , , x and +1
xj

To show that this branch is always increasing j value (and thus


reduces the termination function), I trust the reader.

4. P ∧ π ⇒-f ( S , P )
0
In order to justify this claim, the conditions for the derivation rule should be
lenőríznünk: ( )
⋁ √
4/1. P ∧ π ⇒ π
i
i=1

4/2. ∀i ∈ [1 ..n ]: P ∧ π ∧ π ⇒ lf ( S i , P )
and

(a) x ≤ x.hiv :
j '
x ∈ perm ' ( x ) ∧ j ∈ [ x.lob..x.hib - 1] ∧ i ∈ [ x.lob - 1 ..j - 1] ∧
x.hiv = x .hiv ∀k ∈ ∧ [ x.lob..i ]: x ≤ x.hiv ∧ ∀k ∈ [ i + 1 ..j - 1]:
x > x.hiv ∧ x ≤ x.hiv k
k j
⇒?
lf ( i, j, x and +1 , x: = I + 1 , j + 1 , x , x i + 1 , P ) = ( y ∈ perm ( x ' ) ∧ j +
j '
1 ∈ [ y.lob..y.ib ] ∧ i + 1 ∈ [ y.lob - 1 ..j ] ∧ y.hiv = x .hiv ∧ ∀k ∈
j

[ y.ob..i + 1]: y ≤ y.hiv ∧ ∀k ∈ [ i + 2 ..j ]: y > y.hiv , where y.hib =


x.hib y.lob ∧ = x.lob ∀h ∈ ∧√ [ x.lob, x.hib ] \ {i + 1 , j} : y = x ∧
k k

y and +1 = x ∧ y = x and +1 .
h h

j j

(b) x > x.hiv :


j '
x ∈ perm ' ( x ) ∧ j ∈ [ x.lob..x.hib - 1] ∧ i ∈ [ x.lob - 1 ..j - 1] ∧
x.hiv = x .hiv ∀k ∈ ∧ [ x.lob..i ]: x ≤ x.hiv ∧ ∀k ∈ [ i + 1 ..j - 1]:
x > x.hiv ∧ x > x.hiv k
k j
⇒?
'
lf ( j : = j + 1 , P ) = ( x ∈' perm ( x ) ∧ j + 1 ∈ [ x.lob..x.hib ] ∧ i ∈
[ x.ob - 1 ..j ] ∧ x.hiv = x√ .hiv ∧ ∀k ∈ [ x.lob..i ]: x ≤ x.hiv ∧ ∀k ∈
[ i + 1 ..j ]: x > x.hiv ) k
k

By this we got the job done to remedy the problem of the problem (this
was our simplified task).

290 SOLUTIONS 15

takes place

i, j : = x.lob - 1 , x.lob
j = x.hib
x ≤ x.hiv
j

i, j, x and +1 , x : =
j
i + 1 , j + 1 , , x and +1 j:=j+1
xj

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 246/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
i, x and +1 , x.hiv : = i + 1 , x.hiv, x and +1

But it was our job to replace a particular item.


Complete the specification accordingly:
A=V ×Z×Z
x n i
V = vect (Z , Z)
B=Z×Z
' '
x ' n '
Q : ( x = x ' ∧ n = n ∧ n ∈ '[ x.lob..x.hib ]) 'n
R : ( n = n ∧ x ∈ perm ( x ) ∧ i ∈ [ x.lob..x.hib ] ∧ x = x ' ∧ ∀k ∈
[ X.lob..i - 1] x ≤ x ∧ ∀k ∈ [ i + 1 ..x.hib ]: x > x )i
k i k i
The sequence deduction rule demonstrates that this task is as follows
program solves:

x , x.hiv : x.hiv, x
n n

i, j : = x.lob - 1 , x.lob
j = x.hib
x ≤ x.hiv
j

i, j, x and +1 , x : =
j
i + 1 , j + 1 , , x and +1 j:=j+1
xj

i, x and +1 , x.hiv : = i + 1 , x.hiv, x and +1

The most important algorithm now known is that it is currently known


the fastest (and at the same time "the most brilliant") algorithm.
For the sake of interest, here is a version of this director,
which really does not fit into the model framework (for example, because of the recursion) but in-
can be comprehensively understood. The director's deep discussion of the algorithms and data
in the framework of the subject "Structures".

15.9. deduction 291

correct ( x, i, p, r )

i, j : = p - 1 , p
j=r
x ≤x
j r

i, j, x and +1 , x : =
j
i + 1 , j + 1 , , x and +1 j:=j+1
xj

i, x and +1 , x : = i + 1 , x , x and +1
r r

quick alignment ( x, p, r )

p <r
correct ( x, i, p, r )
layout ( x, p, i - 1)
p:=i+1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 247/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

11th
Specification:
M = VEKTRA (Z , VEKTRA (Z , Z)), invariant: I ( x ) = ( ∀i ∈ [ x.lob, x.hib ]: x .lob =
x.lob ∧ x .ib = x.hib )
i

i
A=M×Z
t r
B=M
'
t '
Q:(t=t ) )
Σ Σ
R:Q=r= t
ij
i = t.lob j = t.lob

Solution:
The invariant
( of the solving cycle: )
Σ Σ
P = Q ∧ k ∈ [ t.lob - 1 ..tb ] ∧ r = t
ij
i = t.lob j = t.lob

Check the terms of the cycle:


1. Q ⇒ P
'
Q = ( Q ∧ k = t.lob - 1 ∧ r = 0)
' '
It can be seen that Q ⇒ P and Q ⇒ lf ( k, r : = t.lob - 1 , 0 , Q )=Q.

292 SOLUTIONS 15

2. P ∧ ¬π ⇒ R
P and R comparing ¬π to k = t.hib arises. So π = ( k = t.hib ).

k, r : = t.lob - 1 , 0
k = t.hib

3. P ∧ π ⇒ t> 0
In the present case, this is: ( Q ∧ k ∈ [ t.lob - 1 ... t - error - 1] ∧⇒
?
r =t>· ·0,· )ie
the termination function: t : = t.hib - k . This function is P ∧ π is obvious
positive.

4./5. P ∧ π ∧ t = t ⇒-f ( S , P ∧ t < )


0 0 0
This point is provided with the usual shaped core core, which is a sequence. THE
The second instruction of the sequence increases the cycle variable.
''
(Q = ( lf ( k : = k + 1 , P ) ∧ t = t ) = )
0
Σ Σ
Q ∧ k + 1 ∈ [ t.lob - 1 ..tb ] ∧ r = t ∧t = t 0
ij
i = t.lob j = t.lob
''
The first part of the sequence is ∧ πP ∧ t = t 0 ⇒ lf ( S 01 , Q ) must be satisfied
(jesítse! Let's take a closer look at this condition ( S 01 for) SKIP):
Σ Σ
Q ∧ k ∈ [ t.lob - 1 ..tb - 1] ∧ r = t ∧t = t 0 ⇒?
ij
i = t.lob j = t.lob
( )
Σ Σ
Q ∧ k + 1 ∈ [ t.lob - 1 ..tb ] ∧ r = t ∧t = t 0 ⇔
ij
i = t.lob j = t.lob
( )
Σ Σ Σ
t k +1 j
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 248/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
⇔ Q ∧ k + 1 ∈ [ t.lob - 1 ..t.hib ] ∧ r = ( i = t.lob j = t.lob t )+ j = t.lob ∧
t=t ij
0
S can not be a single assignment, because then the unacceptable sum
01 ''
let go to the right side. The P ∧ π ∧ t = t and Q ''state joining
0
a cycle is suitable. Invariant is obtained by the Q in the second
we reduce the scope of the sum:
P = ( Q ∧ k + 1 ∈ [ t.lob - 1 ..t.hib ] ∧ g ∈ [ t.lob - 1 ..k + 1] ∧ r =
'

Σ Σ Σ
( t )+ t k+1j∧ t = t )
ij 0
i = t.lob j = t.lob j = t.lob
The additional states needed to derive the internal cycle:
'' '
Q = ( Q ∧ k + 1 ∈ [ t.lob - 1 ..t.hib ] ∧ g = t.lob - 1 ∧

15.9. deduction 293

Σ Σ
r=( t ) ∧ t = t ),
ij 0
i = t.lob j = t.lob
*
Q = ( Q ∧ k + 1 ∈ [ t.lob - 1 ..t.hib ] ∧ g + 1 ∈ [ t.lob - 1 , k + 1] ∧ r =
Σ Σ Σ
( t )+ t k +1 j ).
ij
t.lob = 1 j = t.lob j = t.lob

Q k, r : = t.lob - 1 , 0
'
Q k = t.hib
g : = t.lob - 1 P ∧π
'' '
g = k +1 Q
' '
r : = r + t k +1 g +1 P ∧π
*
g:=g+1 Q
''
k:=k+1 Q
R
16th
V = vector (Z , { 0 , 1 , ···, 9 } )
When solving this problem, we will use the following two functions:
Σ
( ∀x ∈ V )
i
f ( x ) :: = x · 10
i=0 x.hib-i
Σ
g ( x, l ) :: = x x.lob + l-i- 1 · 10 i ( ∀x ∈ V : ∀i ∈ [0 , x.dom ])
i=0
The function f calculates the value of a number in a vector while g is the same
It makes, but first I take into consideration digits. Notice that
g ( x, x.dom ) = f ( x ).
Specification:
A=V ×N
0
x d
B=V
'
x '
Q:(x=x )
R : ( Q ∧ d = f ( x ))
Solution:
P = ( Q ∧ k ∈ [0 , x.dom ] ∧ d = g ( x, k ))
'
Q = ( Q ∧ k = 0 ∧ d = 0)
Check the terms of the cycle:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 249/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
1. Q ⇒ P

294 SOLUTIONS 15

'
⇒ Q-f ( k, d : = 0 , 0 , Q )=Q.

2. P ∧ ¬π ⇒ R
P and R compare to ¬π for k = x.dom . So π = ( k = x.dom ).

k, d : = 0 , 0
k = x.dom

3. P ∧ π ⇒ t> 0
t : = x.dom - k this statement is trivially fulfilled.

4./5. P ∧ π ∧ t = t ⇒-f ( S , P ∧ t < )


0 0 0
A sequence with an intermediate condition:
''
Q = ( lf ( k : = k + 1 , P ) ∧ t = t ) = ( Q ∧ k + 1 ∈ [0 , x.dom ] ∧ d =
g ( x, k + 1) ∧ t = t ) 0
0
This is a good choice, because from this state, k :=k+1
we can move to P ∧ t <t .
0
According to the sequence deduction rule P is required ∧π∧t=t0⇒
Q ''
lf ( S , ) and the assertion S = ( d : = d · 10 + x x.lob + k ) program tel-
we can 1 eat it, because: 1

( P ∧ π ∧ t = t ) = ( Q ∧ k ∈ [0 , x.dom - 1] ∧ d = g ( x, k ) ∧ t = t )
0 0
⇒? -f ( S √1 , Q ' ) = ( Q ∧ k +1 ∈ [0 , x.dom ] ∧ d · 10+ x x.lob + k = g ( x, k + 1) ∧
t=t ) .
0
Σ i
For g ( x, k ) · 10 + x x.lob + k = ( x x.lob + k-i- 1 · 10 ) · 10 + x x.lob + k =
i=0
Σ 0
Σ i
( x x.lob + k i · 10 i- 1 ) · 10+ x x.lob + k · 10 = ( ix= x.lob + k i · 10 ) = g ( x, k + 1).
i=1 0

k, d : = 0 , 0
k = x.dom
d : = d · 10 + x x.ob + k
k:=k+1

20th

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 250/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15.9. deduction 295

V = vector (Z , { 0 , 1 , ···, 9 } )
When solving this problem, we will use the following two functions:
Σ
f ( x ) :: = x · 10
i
( ∀x ∈ V )
i=0 x.hib-i
Σ
( ∀x ∈ V : ∀i ∈ [0 , x.dom ])
i
g ( x, l ) :: = x · 10
i=0 x.hib-i

The function f calculates the value of a number in a vector while g is the same
It makes, but only the last one I take into consideration digits.
If x and y are vectors with the same range of interpretations, then x is a vector on x ⊕ y
we will understand a vector with the same range of interpretations as mentioned above,
each element of which is the sum of the corresponding element of the two vectors. Formally:
∀i ∈ [ x.lob, x.hib ]: ( x ⊕ y ) :: = x + y .
i i i
Specification:
A=V ×V ×V ×Z×L
x y z k c
B=V ×V
' '
x ' y '
Q : ( x = x ∧ y = y ∧ x.dom
x.dom
= y.dom = z.dom ∧ x.ib = y.hib = z.hib )
R ( Q ∧ f ( x ⊕ y ) = 10 · χ ( c ) + f ( z ))
Solution:
Notice that f ( w ) = g ( w, w.dom ) for each w vector. Using this a
ciklusinvariáns:
k
P = ( Q ∧ k ∈ [0 ..x.dom ] ∧ g ( x ⊕ y, k ) = 10 · χ ( c ) + g ( z, k ))
Check the terms of the cycle:
1. Q ⇒ P

'
Q = ( Q ∧ o = false ∧ k = 0)
' '
It can be seen that Q ⇒ P and Q ⇒ lf ( p, k : = false, 0 , Q )=Q.

2. P ∧ ¬π ⇒ R
This condition puts the cycle condition in hand, as it compares P and R
¬π is given to k = x.dom . So π = ( k = x.dom ).

c, k : = false, 0
k = x.dom
S
2

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 251/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

296 SOLUTIONS 15

3. P ∧ π ⇒ t> 0
t : = x.dom - k this statement is trivially fulfilled.

4./5. P ∧ π ∧ t = t ⇒-f ( S , P ∧ t < )


0 0 0
The cycle nucleus is reworded as a sequence in which the second is
''
instruction only takes care of increasing the cycle variable and thus the Q intermediate
the statement is as follows:
Q = Lf ( k : = k + 1 , P ) ∧ t = t 0 = ( Q ∧ k + 1 ∈ [0 ..x.dom ] ∧
''

g ( x ⊕ y, k + 1) = 10 k +1 · χ ( c ) + g ( z, k + 1) ∧ t = t )
0

From this state, k : = k + 1 arrives in P ∧ t <t .


0
∧ π ∧core
The harder question is that the P- axis at the beginning of the cycle t=t
0
''
what kind of program can we get to Q . Let's look at this
how to write g ( w, j + 1) for some meaningful j :
Σ i
Σ i j
g ( w, j + 1) = x · 10 = x · 10 + x · 10
i=0 i=0x.hib-i x.hib-i x.hib-j
j
= G ( w, j ) + x · 10
x.hib-j ''
This
'
is used to describe another form of Q : k
Q = ( Q ∧ k + 1 ∈ [0 ..x.dom ] ∧ g ( xk ⊕ y, k ) + x ⊕ y · 10 =
x⊕y.hib-k
10 k +1 · χ ( c ) + g ( z, k ) + z · 10 ∧ t = t )
z.hib-k 0
Thus it can be recognized that the following program should be used to obtain Q from P ∧ π :
''

c, z := c, z :=
x.hib-k x.hib-k
1+x +y ≥ 10 , x +y ≥ 10 ,
x.hib-k y.hib-k x.hib-k y.hib-k
1+x +y mod 10 x +y mod 10
x.hib-k y.hib-k x.hib-k y.hib-k

k
P = ( Q ∧ k ∈ [0 ..x.dom ] ∧ g ( x ⊕ y, k ) = 10 · χ ( c ) + g ( z, k ))
After all: ( )

1. P ∧ π ⇒ π Obviously fulfilled.
i=1 i

''
2. ∀i ∈ [1 ..n ]: P ∧ π ∧ t = t ∧ π i ⇒-f ( S i , Q )
0

(a) c : P ∧ π ∧ t = t ∧ c ⇒? ( Q ∧ k + 1 ∈ [0 ..x.dom ] ∧ g ( x ⊕ y, k ) + x ⊕
k 0
y · 10 = 10 k +1 · χ (1 + x k + y √
≥ 10) + g ( z, k ) +
(1x.hib-k
+x +y mod 10) · 10 x.hib-k∧ t = x.hib-k
t )
x.hib-k x.hib- 0

15.9. deduction 297

(B) ⇒ ( Q ∧ k +1 ∈ [0 ..x.dom ] ∧ g ( x⊕y, k ) + x⊕y x.hib-k ·


k
10 = 10 k +1 · χ ( x +y ≥ 10) + g ( z, k ) + ( x +
x.hib-k x.hib-k x.hib-k

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 252/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
k √
y mod 10) · 10 ∧t=t0)
Q x.hib-k
c, k : = false, 0
'
k = x.dom
Q
c P ∧π

c, z := c, z :=
x.hib-k x.hib-k
1+x +y ≥ 10 , x +y ≥ 10 ,
x.hib-k y.hib-k x.hib-k y.hib-k
1+x +y mod 10 x +y mod 10
x.hib-k y.hib-k x.hib-k y.hib-k

''
k:=k+1 Q
R

26th Specification:
V = vect (Z , Z)
A=V
x
B=V
'
x '
Q : ( x = x ∧ dom
'
( x ) = 0)
R : ( x ∈ P ( x ) ∧ x is reduced orderly)
Let's define its less- ordered concept: x vector to given k index
decreasingly arranged if ( ∀i ∈ [ x.ob..k - 1] :x ≥ x and +1 ) ∧ ( ∀i ∈
i
[ k +1 ..x.hib ]: x ≥ x ). Moreover x vector into descending sound when x x.hib to
k i
downward orderly. From the definitions, it follows that x vector is decreasing
even if x x.ib - 1 is reduced. So now this is what
we mean this time. Each x vector should be reduced to x.lob - 1 by definition
orderly.
Solution:
P = (x ∈P(x
'
) ∧k ∈ [ x.lob - 1 ..x.hib - 1] ∧
up to xk )
Check the terms of the cycle:
1. Q ⇒ P

'
Q = ( Q ∧ k = x.lob - 1)
'
Q ⇒ P (since x x.lob - 1 always '
has a low order)
and Q ⇒ lf ( k : = x.lob - 1 , Q ) = Q .

298 SOLUTIONS 15

2. P ∧ ¬π ⇒ R
This condition gives the cycle condition, ¬π is k = x.hib - 1. So π = ( k =
x.ib - 1).

k : = x.lob - 1
k = x.hib - 1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 253/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
3. P ∧ π ⇒ t> 0
In this case: ( Q ∧ k ∈ [ x.lob - 1 ..x.hib - 2] ∧ · · · ) ⇒? t> 0, ie
the terminal function: t : = x.hib - k . This function is P ∧ π is obvious
positive.

4./5. P ∧ π ∧ t = t ⇒-f ( S 0 , P ∧ t < 0 )


0 ''
Sequence
''
in the loop core intermediate Q condition
'
is as follows:
Q = lf ( k : = k + 1 , P ) ∧ t = t = ( x ∈ perm ( x ) ∧ k + 1 ∈ [ x.lob -
1 ..x.hib - 1] ∧ xk into descending
0 sound + 1 until ∧ t = t )
0

What kind of program can we get to Q state P ∧ π ∧ t = t 0 state-


''

from? With a sequence the first half of which looks for the vector backward
the second element replaces the maximum value element and the second half replaces the k +
with battery.

So Q
'' '
=(x∈P(x )
'
∧ k + 1 ∈ [ x.lob - 1 ..x.ib - 1] ∧
up to xk ∧ t = t 0 ∧ i ∈ [ k + 1 ..x.hib ] ∧ ∀j ∈
'' '
[ k + 1 ..x.hib ]: x ≤ x )). Note that the Q in in i shall thenceforth,
j
that is the index of the largest
i element behind the vector k + 1, is one
element index, which, according to the definition of degradation, needs
is much smaller than any element in the pre- k part of the vector . That's why it is true
'' ' ''
claim that Q ⇒ lf ( x k +1 , x i : = x i , x k +1 , Q ).
We only have to find the program S with which P ∧ π ∧ t = t ⇒
'' ' 010 0
Q . This is very similar to the maximum search (but it works in vector)
program, the deduction of which is based on the maximum
it is trivial, therefore only the stogra- phogram is presented in the ready prog-
ram:

15.9. deduction 299

Q k : = x.lob - 1
Q' k = x.hib - 1
i, j, max : = k + 1 , k + 1 , x k +1 P ∧π
j = x.hib
x j +1 > max
i, max : = j + 1 , x j +1 SKIP
j:=j+1
'' '
x k+1, x = x , x k+1 Q
i i
''
k:=k+1 Q
R

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 254/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

300 SOLUTIONS 15

15:10. Stemming
First
A=Z×Z×N
0
MND
B=Z×Z
' '
(m n ' '
)
Q : ( m = m ∧n = n ∧m≤n +1 )
Σ
R : Q∧d = χ (0 <f ( j ) ∧ f ( j - 1) < 0)
j = m +1
1. Reversal: counting
Condition: m ≤ n Parameter: - Strengthening: -
compliance:
m ← m +1 i, d : = m, 0
n ←n i=n
i ←i 0 <f ( i + 1) ∧ f ( i ) < 0
d ←d d:=d+1 SKIP
β ( j ) ← 0 <f ( j ) ∧ f ( j - 1) < 0 i:=i+1
Second
A=N×L
nl
B=N
'
(
n '
Q: (n=n ) )
Q ∧ L = ∃j ∈ [2 , n - 1]: (2 ∤ j ∧ j | n ) ∧
R:
l → ( i ∈ [2 , n - 1] ∧ (2 ∤ i ∧ i | n ))
1. Reverse: linear search 2.8.
Condition: - Parameter: - Strengthening: If so, find out which one is
compliance:
m←2 i, l : = 1 , false
n ← n- 1 ¬l ∧ i = n - 1
l ←l l : = (2 ∤ i + 1 ∧ i + 1 | n )
i ←i i:=i+1
β ( j ) ← (2 ∤ j ∧ j | n )
Third

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 255/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
A = Nnil
×N×L
B=N
'
(n )
Q : ( n = n ' ∧ 2 <n )
Q ∧ L( = ∃j ∈ [2 , n - 1]: (2 ∤ j ∧ j | n ) ∧ )
R:
l → i ∈ [2 , n - 1] ∧ (2 ∤ i ∧ i | n ) ∧ ∀j ∈ [2 , i - 1]: (2 | j j ∨ ∤ n )
1. Reverse: linear search 2.8.

15:10. DRIVING BACK 301

Condition: - Parameter: - Strengthening: -


compliance:
m←2 i, l : = 1 , false
n ← n- 1 ¬l ∧ i = n - 1
l ←l l : = (2 ∤ i + 1 ∧ i + 1 | n )
i ←i i:=i+1
β ( j ) ← (2 ∤ j ∧ j | n )

4th
V = vect (Z , Z)

A=V×V×Z ×Z
xy max i
B=V×V
' '
(x y ' ' )
x = c ∧ y = y ∧)
Q:
( ∀j ∈ [ y.lob, y.hib ]: y j ∈ [ x.lob, x.ib ] ∧ 0 <x.dom ∧ 0 <y.dom )
R : Q ∧ i ∈ [ y.lob, y.ib ] ∧ max = x and ∧∀j∈ [ y.lob, y.hib ]: x y j ≤max
y
1. Reverse: maximum search
Condition: - Parameter: x, y Strengthening: -
compliance:
m ← y.lob max, i, k : = x y.lob , Y.lob, y.lob
y
n ← y.hib k = y.hib
up ← max
max ≤ x k + 1
i ←i y

k ←k max, i : = x k + 1 , k +1 SKIP
y
a≤b ← a≤b k:=k+1
f(j) ←x j
y

5th
V = vect (Z , Z)

A=V×N
0
xD
B=V
'
x( '
Q: (x=x ) )
Σ
R : Q∧d = χ ( x <j )
j
j = v.lob
1. Reversal: counting
Condition: - Parameter: x Strengthening: -

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 256/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

302 SOLUTIONS 15

compliance:
i, d : = v.lob - 1 , 0
m ← v.lob
n ← v.hib i = v.hib
i ←i x and +1 <i + 1
d ←d d:=d+1 SKIP
β ( j ) ← x <j i:=i+1
j

6th
V = vect (Z , Z)

A=N×N
ni
B=N
'
(n '
)
Q : (n = n ∧ 2 ≤ n ( ))
n n
R : Q∧ 2 ≤i∧i | n∧i ∤ i ∧ ∀j ∈ [2 , i - 1]: j ∤ n ∨ i | j
1. Retraction: Linear Search 2.
Condition: - Parameter: - Strengthening: -
compliance: i, l : = 1 , false
m←2 ¬l
l ←l l : = i + 1 | n ∧ i + 1 ∤ and
n
+1
i ←i
n i:=i+1
β(j) ←j|n∧j∤ j

7th
A=Z×Z×N
0
MND
B=Z×Z×
' '
( n
m )
Q : ( m = m ' ∧n = n ' ∧m≤n +1 )
Σ
R : Q ∧ d = χ (2 | f ( j ) ∧ g ( j ) = 1)
j=m
1. Reversal: counting
Condition: - Parameter: - Strengthening: -
compliance:
m←m i, d : = m - 1 , 0
n ←n i=n
i ←i 2 | f ( i + 1) ∧ g ( i + 1) = 1
d ←d d:=d+1 SKIP
β(j) ←2|f(j)∧g(j)=1 i:=i+1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 257/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:10. DRIVING BACK 303

8th
A=Z×Z×L
mnl
B=Z×Z
' '
(m n ' '
)
Q : ( m = m ∧n = n ∧m≤n +1 )
R : Q ∧ i ∈ [ m, n ] ∧ ∀j ∈ [ m, n ]: f ( j mod) 10 ≤ f ( i ) mod 10
1. Reverse: maximum search
Condition: - Parameter: - String: Enter the value of the digit
compliance:
m←m max, i, k : = f ( m ) mod 10 , m, m
n ←n k=n
up ← max
i ←i max ≤ f ( k + 1) mod 10
k ←k max, i : = f ( k + 1) mod 10 , k + 1 SKIP
a≤b ← a≤b k:=k+1
f ( j ) ← f ( j ) mod 10

9th
V = vector (Z , C )

A=V×L
xl
B=V
'
(x '
Q: (x=x ) )
R : Q ∧ l = ∀j ∈ [0 , x.dom - 1]: x x.ob + j = x
x.hib-j
1. Reverse: linear search 2.8.
Condition: - Parameter: x Stretching: Enter the location of the first deviation
compliance:
i, l : = - 1 , true
m←0
n ← x.dom - 1 l ∧ i = x.dom - 1
l ← ¬l l = x x.lob + i +1 = x x.hib-i- 1
i ←i i:=i+1
β ( j ) ← x x.ob + j = x
x.ib-j

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 258/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

304 SOLUTIONS 15

10th
NNM = vect (Z , V )
V = vect (Z , Z)
I ( x ) = ∀i ∈ [ x.lob, x.hib ]: ( x .dom = x.dom ∧ x .lob = x.lob )
NNM i i

A = NNM × N × Z
t kd
B = NNM × N
' '
( t k )
Q : ( t = t ' ∧ k = k ' ∧ k ≤ k) ≤ t.dom ∧ t.dom
Σ
R : Q∧d = t
k, j
j = t.lob
1. Reversal: summary
Felt: - Parameter: t, k Strengthening: -
compliance:
i, d : = t.lob - 1 , 0
m ← t.lob
n ← t.hib i = t.hib
d ←d d : = d + t k, and +1
i ←i i:=i+1
f(j) ←t
k, j

11th
A=Z×Z×N×L×Z×Z
mnkl max i
B=Z×Z×N
' ' '
(m n k ' ' '
)
Q: m = m ∧n = n ∧ k = k ∧m≤n +1
Q∧L ( = ∃j ∈ [ m, n ]: k | f ( j ) ∧ )
R:⎝ i ∈ [ m, n ] ∧ max = f ( i ) ∧ k | f ( i ) ∧
l→
∀j ∈ [ m, n ]: k | f ( j ) → f ( j ) ≤ max
1. Reverse: conditional maximum search
Condition: - Parameter: k Strengthening: -
compliance:

15:10. DRIVING BACK 305

m←m n ←n l ←l
up ← max i ←i k ←p
a≤b ← a≤b f(j) ←f(j) β(j) ←k|f(j)
l, p : = false, m - 1
p=n
k ∤ f ( p + 1) k | f ( p + 1) ∧ ¬l k | f ( p + 1) ∧ l

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 259/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
SKIP true,l,p i,+max
1 , f :( =p + 1)
i, max : = max
p + 1≤, ff (( pp ++ 1)
1) SKIP
p:=p+1

12th
A=N×N
0
nd
B=N
'
(n '
Q: (n=n ) )
Σ
R : Q ∧ d = χ (2 | j ∧ j | n )
j=2
1. Reversal: counting
Condition: - Parameter: - Strengthening: -
m ← 2 n ← n- 1 i←i ←dd β(j)←2|j∧j|n

13th
A=Z×Z×L×Z×Z
mnli max
B=Z×Z
' '
(m n )
Q : m = m ' ∧n = n ' ∧m +1 ≤n- 1 ( )
f ( j ) <f ( j - 1) ∧
Q ∧ l = ∃j ∈ [ m + 1 , n - 1]: ∧
f ( j ) <f ((j + 1) )
f ( i ) <f ( i - 1) ∧
R: i∈ [ m + 1 , n- 1] ∧max = f ( i ) ∧ ∧
l→ ( f ( i ) )<f ( i + 1)
f ( j ) <f ( j - 1) ∧
⎝ ∀j ∈ [ m + 1 , n - 1]: f ( j ) <f ( j + 1)
→ f ( j ) ≤ max
1. Reverse: conditional maximum search
Condition: - Parameter: - Strengthening: -
m ← m +1 n ← n- 1 l ←l
up ← max i ←i k ←k( )
f ( j ) <f ( j - 1) ∧
a≤b ← a≤b f(j) ←f(j) β(j) ←
f ( j ) <f ( j + 1)

306 SOLUTIONS 15

14th
A=Z×Z×Z×L×Z
mnkli
B=Z×Z×Z
' ' '
(m n k ' ' '
Q: (m=m ∧n=n ∧m≤n+1∧k=k ) )
R : Q ∧ l = ∃j ∈ [ m, n ]: k | f ( j ) ∧ l → ( i ∈ [ m, n ] ∧ k | f ( i ))
1. Reverse: linear search 2.8.
Condition: - Parameter: k Strengthening: look for the first such argument
m←m ←nn ←ll i←i β(j)←k|f(j)

15th
A=Z×Z×Z×L×Z×Z
mnkl max i
B=Z×Z×Z
' ' '
(m n k' ' '
Q: m=m ∧n=n ∧m≤n+1∧k=k )


file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 260/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
R:⎝ ( )
∧ Li∀=∈j∃∈[j m,
lQ→ ∈[ m, ] ∧n max
[nm,
n ]: ]:
i )∧∧ f ( i ) <k ∧
= )f (<k
f (f j()j <k → f ( j ) ≤ max

1. Reverse: conditional maximum search


Condition: - Parameter: k Strengthening: -
m←m n ←n l ←l
up ← max i ←i k ←p
a≤b ← a≤b f(j) ←f(j) β ( j ) ← f ( j ) <k

16th
V = vector (Z , P )
P = ( x : Z , y : Z)

A=V×P×Z×L×Z
vcrl i
B=V×P×Z
' ' '
(vc' r ' '
Q: =v ∧c=c ∧r=r )
(v 2 2 )
Q ∧ L( = ∃j ∈ [ v.lob, v.hib ]: ( v .x - cx ) + ( v .y - cy ) ) ∧
≤r
2
R: j 2 j 2 2
l → i ∈ [ v.lob, v.hib ] ∧ ( v .x - cx ) + ( v .y - cy ) ≤ r
1. Reverse: linear search 2.8. i i

Condition: - Parameter: v, c, r Strengthening: Look for the first such point


m ← v.lob n ← v.hib ← l l i ← i 2 2
β ( j ) ← ( v .x - cx ) + ( v .y - cy ) 2 ≤r
j j

15:10. DRIVING BACK 307

17th
A=Z×Z×Z×Z×L×Z×Z
mnabl max i
B=Z×Z×Z×Z
' ' ' '
(mn a 'b ' ' '
Q: m=m ∧n=n ∧m≤n+1∧a=a ∧b=b )
Q∧L ( = ∃j ∈ [ m, n ] of ≤ f ( j ) ≤ b∧ )
R:⎝ i ∈ [ m, n ] ∧ max = f ( i ) ∧ a ≤ f ( i ) ≤ b∧
l→
∀j ∈ [ m, n ]: a ≤ f ( j ) ≤ b → f ( j ) ≤ max
1. Reverse: conditional maximum search
Condition: - Parameter a, b Strengthening: -
m←m n ←n l ←l
up ← max i ←i k ←k
a≤b ← a≤b f(j) ←f(j) β(j) ←a≤f(j)≤b
18th
A=Z×Z×Z×Z×Z×Z×N
0
mnabcdp
B=Z×Z×Z×Z×Z×Z
' ' ' ' ' '
(m
n a 'b c d ' ' ' ' '
Q: M = m ∧ n = n ∧ m ≤ n + 1 ∧ the = the ∧ b = b ∧ c = c ∧ d = d )
( Σ )
R:Q∧p=χ(a≤f(j)≤b≤f∨c(j)≤d)
j=m
1. Reversal: counting
Condition: - Parameter: a, b, c, d Strengthening: -
m←m ←nn i←i d←p β(j)←a≤f(j)≤b∨c≤f(j)≤d
19th
A=Z×Z×Z×L×Z×Z
mnkl max i
B=Z×Z×Z

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 261/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
' ' '
( ' ' '
Q : mm n= mk ∧n=n ∧m≤n+1∧k=k )
Q∧L ( = ∃j ∈ [ m, n ]: k | f ( j ) - 1 ∧ )
R:⎝ i ∈ [ m, n ] ∧ max = f ( i ) ∧ k | f ( i ) - 1 ∧
l→
∀j ∈ [ m, n ]: k | f ( j ) - 1 → f ( j ) ≤ max
1. Reverse: conditional maximum search
Condition: - Parameter: k Strengthening: -
m←m n ←n l ←l
up ← max i ←i k ←k
a≤b ← a≤b f(j) ←f(j) β(j) ←k|f(j)-1

308 SOLUTIONS 15

20th
A=Z×Z×Z×Z×Z
mn N max i
B=Z×Z×Z
' ' '
(m n N ' ' '
Q: (m=m ∧n=n ∧m≤n∧N=N ) )
Q ∧ i ∈ [ m, n ] ∧ max = f ( i ) ∧
R:
∀j ∈ [ m, n ]: f ( j ) mod N ≤ max mod N
1. Reverse: maximum search
Condition: - Parameter: N Strengthening: -
m←m ←nn max ← max
i←i ← k k a ≤ b ← a mod N ≤ b mod N
f(j)←f(j)

21st
A=Z×Z×Z×Z×Z×N
0
mnx y r d
0 0
B=Z×Z×Z×Z×Z
' ' ' ' '
(m n x ' 0 y 0' r 0' ∧r = r ' )
Q: (m=m ∧n = n( (∧Fm≤n
'
0 ∧y 0 =
- x∧x) =+ x( g ( j ) - y ) ≤ yr ))
2 2 2
Σ ( j )+1
R:Q∧d=χ
0
0 0
j=m
1. Reversal: counting
Condition: - Parameter: x , y , r Strengthening: -
0 0 2 2 2
m←m ←nn i←i ←dd β(j)←(f(j)-x ) +(g(j)-y ) ≤r
0 0

22nd
A=Z×Z×Z×Z×L
abnil
B=Z×Z×Z
' ' '
(a
b ' n ' '
Q: a=a ∧b=b ∧a≤b∧n=n )
Q∧L ( = ∃j ∈ [ a, b ]: ( f ( j ) = 0 ∧ f ( j ) <n ) ∧)
R:⎝ I ∈ [ a, b ] ∧ ( f ( i ) = 0 ∧ f ( i ) <n ) ∧
l→
( F ( j ) = 0 ∨ f ( j ) ≥ n ) ∀j ∈ [ a, i - 1]
1. Reverse: linear search 2.8.
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 262/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Condition: - Parameter: approx
Strengthening: -
← a m ← n b ← l l i ← i β ( j ) ← ( f ( j ) = 0 ∧ f ( j ) <n )

15:10. DRIVING BACK 309

23rd
V = vect (Z , Z)

A=V×V×Z×N
0
xykd
B=V×V×Z
' ' '
(x y k' ' ' )
X = x ∧ y = y ∧ k = k ∧ ∀j ∈ [ y.lob, y.hib ]: y ∈ [ x.lob, x.hib ] ∧
Q:
( ∀a, b ∈ [ y.lob, y.hib ]: ( y a )= y b → a = b )
j

Σ ( )
R : Q∧d = χ k|x j
y
j = y.lob
1. Reversal: counting
Condition: - Parameter: x, y, z Strengthening: -
m ← y.lob n ← y.hib i ← i ← d d β ( j ) ← k | x j
y

24th
V = vector (Z , C )

A=V×L
xl
B=V
'
(x '
Q: (x=x ) )
R : Q ∧ L = ∃j ∈ [ x.lob, x.hib ]: x ∈ [ 'a', 'e', 'i', 'o', 'u']
j
1. Reverse: linear search 2.8.
Condition: - Parameter: x Narrowing: look for the first vowel location
m ← x.lob n ← x.hib ← l l i ← i β ( j ) ← x ∈ ['a', 'e', 'i', 'o', 'u']
j

25th
A=Z×Z×Z×Z×Z×Z×L×Z
mnabcdli
B=Z×Z×Z×Z×Z×Z
' ' ' ' ' '
(m n a ' b c d ' ' ' ' '
Q : ( M = m ∧ n = n ∧ m ≤ n + 1 ∧ the = the ∧ b = b ∧ c =) c ∧ d = d )
Q ∧ L = ∃j ∈ [ m, n ] of ≤ f ( j ) ≤ b ≤ c ∧ f ( j ) ≤ d∧
R:
l → ( i ∈ [ m, n ] ∧ a ≤ f ( i ) ≤ b ≤ c ∧ f ( i ) ≤ d )
1. Reverse: linear search 2.8.
Condition: - Parameter: a, b, c, d Stretching: Look for the first such item
m←m ←nn ←ll i←i β(j)←a≤f(j)≤b∧c≤f(j)≤d

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 263/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

310 SOLUTIONS 15

26th
V = vector (Z , C )

A=V×N
0
xD
B=V
'
x( '
Q: (x=x ) )
Σ
R : Q∧d = χ(x ∈ ['a', 'e', 'i', 'o', 'u'])
j
j = x.lob
1. Reversal: counting
Condition: - Parameter: x Strengthening: -
m ← x.lob n ← x.hib i ← i ← d d β ( j ) ← x
j
∈ ['a', 'e', 'i', 'o', 'u']

27th
A=Z×Z×Z
MNK
B=Z×Z
' '
(m n )
Q : ( m = m ' ∧n = n ' ∧m +1 ≤n )
R : Q ∧ k ∈ [ m + 1 , n ] ∧ ∀j ∈ [ m + 1 , n ]: f ( j ) - f ( j - 1) ≤ f ( k ) - f ( k - 1)
1. Reverse: maximum search
Condition: - Parameter: - Strengthening: Let's say the degree of difference
m ← m +1 ←nn max ← max
ik← p k ← ← a≤b a≤b
f ( j ) ← f ( j ) - f ( j - 1)

28th
A=Z×Z×L×Z
MnlI
B=Z×Z
' '
(m n )
Q : ( m = m ' ∧n = n ' ∧m≤n +1 )
Q ∧ l(= ∃j ∈ [ m, n ]: 2 | f ( j ) ∧ )
R:
l → i ∈ [ m, n ] ∧ 2 | f ( i ) ∧ ∀j ∈ [ m, n ]: 2 | f ( j ) → f ( j ) ≤ f ( i )
1. Reverse: conditional maximum search
Condition: - Parameter: - Strengthening: We also specify the highest value
m←m n ←n l ←l
up ← max i ←i k ←k
a≤b ← a≤b f(j) ←f(j) β(j) ←2|f(j)

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 264/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:10. DRIVING BACK 311

29th
V = vect (Z , Z)

A=V×N×L
xyl
B=V
'
x( '
Q: (x=x ) )
Q ∧ l = ∃j ∈ [ x.lob, x.hib - 1]: x x j +1 < 0 ∧
R:
l → ( i ∈ [ x.lob, x.hib - 1] ∧ x x i + 1 < 0)
j

i
1. Reverse: linear search 2.8.
Condition: 0 <x.dom Parameter: x Strengthening: look for the first
m ← x.lob n ← x.hib - 1 ← l l i ← i β ( j ) ← x x j +1 < 0
j

30th
A=Z×Z×Z
MND
B=Z×Z
' '
( n '
m '
)
Q : ( m = m ∧n = n ∧m≤n +1 )
Σ
R : Q∧d = |f(j)-g(j)|
j=m
1. Reversal: summary
Condition: - Parameter: - Strengthening: -
m←m ←nn ←dd i←i f(j)←|f(j)-g(j)|

31st
V = vect (Z , Z)

A=V×V×N
0
XBD
B=V×V
' '
(x b ' '
Q: (x=x ∧b=b ) )
Σ
R : Q∧d = χ ( x x.lob + j = b b.lob + j mod b.dom )
j=0
1. Reversal: counting
Condition: - Parameter: - Strengthening: -
m ← 0 n ← x.dom - 1 i ← i ← d d β ( j ) ← x x.lob + j = b b.lob + j mod b.dom

312 SOLUTIONS 15

32nd
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 265/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
A=N×N×L
nil
B=N
'
(n '
Q: (n=n ) )
R : Q ∧ l = ∃j ∈ [2 , n - 1]: j | n ∧ l → ( i ∈ [2 , n - 1] ∧ i | n )
1. Reverse: linear search 2.8.
Condition: - Parameter: - Stretching: Look for the smallest real dealer
m ← 2 n ← n- 1 ←ll i←i β(j)←j|n
33rd
f( x- 1) + f ( x +1)
g(x)= f(x)- 2

A=Z×Z×Z
mni
B=Z×Z
' '
(m n )
Q : ( m = m ' ∧n = n ' ∧m +1 ≤n- 1 )
R : Q ∧ i ∈ [ m + 1 , n - 1] ∧ ∀j ∈ [ m + 1 , n - 1]: g ( j ) ≤ g ( i )
1. Reverse: maximum search
Condition: - Parameter: - Strengthening: Enter the degree of deviation
m ← m +1 n ← n- 1 max ← max
i←i ←kk ← a≤b a≤b
f(j)←g(j)
34th
V = vect (Z , Z)

A=V×N×L
xyl
B=V
'
(x '
Q: (x=x ) )
R : Q ∧ l = ∃j ∈ [ x.lob, x.hib ]: j | x ∧ → l ( i ∈ [ x.lob, x.hib ] ∧ i | x )
j i
1. Reverse: linear search 2.8.
Condition: - Parameter: x Stretching: Look for the first such item
m ← x.lob n ← x.hib ← l l i ← i β ( j ) ← j | x
j

15:10. DRIVING BACK 313

35th
V = vector
( (Z , vector (Z , Z)) ( ) )
t .dom = t j +1 .dom∧
I (t)= ∀j ∈ [ t.lob, t.hib- 1]: j ∧ t.lob = t t.lob .lob
V t .lob = t j +1 .lob
⌊ ⌋ j
i
g ( i ) = t.lob + t .dom h ( i ) = t.lob + and mod t .dom
t.lob t.lob

A=V×Z×L
TNL
B=V×Z
' '
t n )

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 266/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
Q : (( ∀j ∈' [0 , x · x.dom ' .dom - 2]: t g ( j ) , h ( j ) ≤ t g ( j + 1) .h ( j +1) )
tQ=∧t l ∧= n∃j=∈n[0∧, t.dom>
x.dom · 0x ∧ .dom - 1]: t
x.lob
(j),h(j)) = n ∧
R: (
l → i ∈ [0 , x · x.dom .dom - 1] ∧ t g ( i ) h ( i ) = n
x.lob g

x.lob
1. Reversal: logarithmic search
Condition: - Parameter: - Strengthening: -
m←0 n ← x.dom · x .dom - 1 i ←i
x.lob
k ←n u ←u v ←v
l ←l <b ← a <b f ( j ) T ← g(j),h(j)
u, v, l : = 0 , x.dom · x .dom - 1 , false
x.lob
¬l ∨ in ≤ v
⌊ u+v⌋
i:= 2
t g ( i ) , h ( i ) <n t g(i),h(i)= n t g(i),h(i)> n
in : = i + 1 l : = true v:=i-1

36th
V = vector (Z , S )
z

A=V×N×L
xyl
B=V
'
(x '
Q: (x=x ) )
Q ∧ l = ∃j ∈ [ x.lob, x.hib ]: x = 'light blue' ∧
R:
l → ( i ∈ [ x.lob, x.ib ] ∧ x = 'light blue')
j

1. Reversal: logarithmic search i


Condition: - Parameter: - Strengthening: -
m ← x.lob n ← x.hib i ←i
k ← 'light blue' u ←u v ←v
l ←l <b ← a≺b f(j) ←x
j

314 SOLUTIONS 15

37th
V = vector (Z , P )
P = ( x : Z , y : Z)

A=V×P
vp
B=V
'
(v '
Q: (v=v ) )
Q ∧ i ∈ [ v.lob, v.hib ] ∧ p = v ∧
R: 2 i 2 2 2
∀j ∈ [ v.lob, v.hib ]: v .x + v j .y ≤ px + py
1. Reverse: maximum searchj
Condition: - Parameter: v Stretching: Locate the space occupied in the vector
m ← v.lob n ← v.hib max ← p
2 2 2 2
i←i ←kk a ≤ b ← ax + ay ≤ bx + by
f(j)←v
j

38th

A=Z×Z×L×Z
MnlI
B=Z×Z
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 267/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
' '
( n ' )
Q: m '
( m = m ∧n = n ∧m≤n +1 )
Q ∧ l(= ∃j ∈ [ m, n ]: 0 <f ( j ) ∧ )
R:
l → i ∈ [ m, n ] ∧ 0 <f ( i ) ∧ ∀j ∈ [ m, i - 1] 0 ≥ f ( j )
1. Reverse: linear search 2.8. typ. variant
Condition: - Parameter: - Strengthening: -
←mn ←nm ←ll i←i
Next ( i ) ← i : = i + 1 before ( i ) ← i : = i - 1 β ( j ) ← 0 <f ( j )

39th
V = vector (Z , { 0 , 1 } )

A=V×N
0
xD
B=V
'
x( '
Q: (x=x ) ( ))
Σ x = x j+2= 0 ∧
R : Q∧d = χ j
j = t.lob x j +1 = x j + 3 = 1
1. Reversal: counting

15:10. DRIVING BACK 315

Condition: 3 <t.dom Parameter: x Strengthening: -


x = x j+2 = 0 ∧
m ← t.lob n ← t.hib - 3 i←i ←dd β(j)← j
x j +1 = x j + 3 = 1
40th
A=Z×Z×Z×L×Z
mnkli
B=Z×Z×Z
' ' '
(m n k ' ' '
Q: (m=m ∧n=n ∧m≤n+1∧k=k ) )
R : Q ∧ L = ∃j ∈ [ m, n ]: RPRI ( f ( j ) , k l → ∧ ( i ∈ [ m, n ] ∧ RPRI ( f ( i ) , k )
1. Reverse: linear search 2.8.
Condition: - Parameter: - Strengthening: Look for the first such value
compliance:
m←m
i, l : = m - 1 , false
n ←n
l ←l ¬l ∧ i = n
i ←i l : = rprim ( f ( i + 1) , k
β ( j ) ← rprim ( f ( j ) , k
2. Reverse: Linear Search 2.8. i:=i+1
Condition: - Parameter: k Strengthening: where will "no relative prime"
compliance:
l : = rprim ( f ( i + 1) , k )
m←2
n ←k ii, l : = 1 , true
l ← ¬l
l ∧ ii = k
i ← ii
β ( j ) ← j | f ( i + 1) ∧ j | k l : = ii + 1 ∤ f ( i + 1) ∨ ii + 1 ∤ k
41st ii : = ii + 1
A=Z×Z×L
nil
B=Z
'
(n '
)
Q:
n=n ∧2≤n

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 268/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
R:⎝ ( )
∧ Li=∈∃[2j ∈, n[2- ,1]n -∧1]:
lQ→ ( i (| nj |∧n¬prim ( i ())j ∧)) ∧
∧ ¬prim
∀j ∈ [2 , i - 1]: ( j ∤ n ∨ prim ( j ))
1. Reverse: linear search 2.8.
Condition: - Parameter: - Strengthening: -
m ← 2 n ← n- 1 ← l l i ← i β ( j ) ← ( j | n ∧ ¬prim ( j ))
2. Reverse: Linear Search 2.8.
Condition: - Parameter: i, n Strengthening: where will "no prime"
m ← 2 ← i n ← l l and ← iiβ ( j ) ← i + 1 | n ∧ j | i + 1

316 SOLUTIONS 15

42nd
A=Z×Z×Z×Z×Z×Z×Z×L
mnabkijl
B=Z×Z×Z×Z×Z
' ' ' ' '
(m n a ' b k ' ' ' '
Q : ( m = m ∧ n = n ∧ m ≤ n + 1 ∧ a = a ∧ b = b ∧ k = k ))
Q ∧ L = ∃p ∈ [ m, n ]: ∃q ∈ [ a, b ]: f ( p ) + g ( q ) = k∧
R:
l ⇒ ( i ∈ [ m, n ] ∧ j ∈ [ a, b ] ∧ f ( i ) + g ( j ) = k )

1. Reverse: linear search 2.8.


Condition: - Parameter: a, b, k Stretching: find the first one
m ← m ← n n ← l l i ← i β ( p ) ← ∃q ∈ [ a, b ]: f ( p ) + g ( q ) = k
2. Reversal: logarithmic search
Condition: - Parameter: a, b, i, k Strengthening: -
m←a n ←b i ←j
k ←k u ←u v ←v
l ←l <b ← a≤b f ( j ) ← f ( i + 1) + g ( j )

43rd
V = vector (Z , vector (Z , Z))
g:V×Z→L
g ( t, j ) = ∀k ∈ [ t .lob, t .ib ]: t ≤ 0
j j j, k

A=V×L×Z
t l i
B=V
'
(t '
Q: (t=t ) )
R : Q ∧ L = ∃j ∈ [ t.lob, t.hib ]: g ( t, j ) ∧ → l ( i ∈ [ t.lob, t.hib ] ∧ g ( t i ))
1. Reverse: linear search 2.8.
Condition: - Parameter: t Strengthening: -
compliance: i, l : = t.lob - 1 , false
m ← t.lob ¬l ∧ i = t.hib
n ← t.hib
l ←l l : = g ( t, i + 1)
i ←i i:=i+1
β ( j ) ← g ( t, j )
2. Reverse: Linear Search 2.8.
Condition: - Parameter: t, i Strengthening: -

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 269/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:10. DRIVING BACK 317


l : = g ( t, i + 1)
compliance:
m ← t and +1 .lob ii, l : = t i +1 .lob - 1 , true
n ← t i +1 .hib l ∧ ii = t and +1 .hib
l ← ¬l l : = t and +1 , and +1 ≤ 0
i ← ii ii : = ii + 1
β ( j ) ← t and +1 , j > 0
44th
V = vector (Z , C )
g:V×V×Z→L
g ( x, b, j ) = ∀k ∈ [0 , b.dom - 1]: x j + k = b b.lob + k

A=V×V×L
XBL
B=V×V
' '
(x b ' '
)
Q : ( x = x ∧ b = b ∧ b.dom ≤ x.dom )
R : Q ∧ L = ∃j ∈ [ x.lob, x.hib - b.dom ]: g ( x, b, j )
1. Reverse: linear search 2.8.
Condition: - Parameter: x, b Stretching: Enter the first occurrence location
compliance:
m ← x.lob i, l : = x.lob - 1 , false
n ← x.ib - b.dom
¬l ∧ i = x.ib - b.dom
l ←l
i ←i l : = g ( x, b, i + 1)
β ( j ) ← g ( x, b, j ) i:=i+1
2. Reverse: Linear Search 2.8.
Condition: - Parameter: x, b, i Strengthening: - l : = g ( x, b, i + 1)
compliance:
m←0 ii, l : = - 1 , true
n ← b.dom - 1 l ∧ ii = b.dom - 1
l ← ¬l l : = x i +1+ ii +1 = b b.lob + ii + 1
i ← ii
β ( j ) ← x i +1+ j = b b.lob + j ii : = ii + 1
45th
g:Z→L
g ( j ) = ∃k ∈ [ m, j - 1]: f ( j ) <f ( k )

A=Z×Z×L×Z
MnlI
B=Z×Z
' '
(m n ' '
)
Q : ( m = m ∧n = n ∧m≤n +1 )
R : Q∧l = ∃j ∈ [ m, n ]: g ( j ) ∧l → ( i∈ [ m, n ] ∧g ( i ))

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 270/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

318 SOLUTIONS 15

1. Reverse: linear search 2.8.


Condition: - Parameter: - Stretching: Entering this first value
m←m ←nn ←ll i←i β(j)←g(j)
2. Reverse: Linear Search 2.8.
Condition: - Parameter: i Strengthening: Look for the first such value
m ← m ← i n ← l l and ← iiβ ( j ) ← f ( i + 1) <f ( j )

46th
g:Z×Z→L
g ( j, n ) = ∃k ∈ [ j + 1 , n ]: f ( j ) = f ( k )

A=Z×Z×L×Z
MnlI
B=Z×Z
' '
(m n )
Q : ( m = m ' ∧n = n ' ∧m≤n +1 )
Q ∧ l(= ∃j ∈ [ m, n - 1]: g ( j, n ) ∧ )
R:
l → i ∈ [ m, n - 1] ∧ g ( i, n ) ∧ ∀j ∈ [ m, i - 1]: ¬g ( j, n )
1. Reverse: linear search 2.8.
Condition: m ≤ n Parameter: - Strengthening: -
m ← m n ← n- 1 ← l l i ← i β ( j ) ← g ( j, n )
2. Reverse: Linear Search 2.8.
Condition: - Parameter: i, n Stretch: Specify where the element occurs for the second time
m ← i +2 ← n n ← l l and ← iiβ ( j ) ← f ( i + 1) = f ( j )

47th
M = vector (Z , vector (Z , Z))
g:M×Z→L
g ( x, j ) = ∀k ∈ [ x .lob, x .hib ]: t =1
j j j, k

A=M×Z×L
xyl
B=M
'
(x '
Q: (x=x ) )
R : Q ∧ L = ∃j ∈ [ x.lob, x.hib ]: g ( x, j ) ∧ → l ( i ∈ [ x.lob, x.hib ] ∧ g ( x, i ))
1. Reverse: linear search 2.8.
Condition: - Parameter: x Stretching: Look for the first such sort
m ← x.lob n ← x.hib ← l l i ← i β ( j ) ← g ( x, j )
2. Reverse: Linear Search 2.8.
Condition: - Parameter: x, i Stretching: Specify where you will not first 1
m ← x i +1 .lob n ← x i +1 .hib l ← ¬l and ← iiβ ( j ) ← x and +1 , j = 1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 271/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:10. DRIVING BACK 319

48th
A=Z×Z×N
0
abd
B=Z×Z
' '
(a b )
Q : ( a = a ' ∧b = b ' ∧a≤b +1 )
Σ
R : Q ∧ d = χ ( prim ( j ))
j=a
1. Reversal: counting
Condition: - Parameter: - Strengthening: -
compliance:
m←a i, d : = a - 1 , 0
n ←b i=b
i ←i prim ( i + 1)
d ←d d:=d+1 SKIP
β ( j ) ← prim ( j )
i:=i+1
2. Unconditional branching condition is not allowed i, d : = a - 1 , 0
l : = prim ( i + 1) i=b
l: = primer (i + 1)
l
d : = d + 1 SKIP
i:=i+1
3. Reversal: Linear Search 2.8.
Condition: - Parameter: i Strengthening: where will "no prime"
compliance:
m←2 l : = prim ( i + 1)
n ←i
ii, l : = 1 , true
l ← ¬l
i ← ii l ∧ ii = i
β(j) ← j | and +1 l : = ii + 1 ∤ i + 1
ii : = ii + 1
49th
A=N×N
0
nd
B=N
'
'
(n
Q : (n = n ) )
Σ
R : Q ∧ d = χ ( rprim ( j, n ))
j=2
1. Reversal: counting
Condition: - Parameter: - Strengthening: -

320 SOLUTIONS 15

m ← 2 n ← n- 1 i ← i ← d d β ( j ) ← rprim ( j, n )
2. Unconditional branching condition is not allowed
l : = rprim ( i + 1 , n )
3. Reversal: Linear Search 2.8.
Condition: - Parameter: i, n Strengthening: where is the first "no relative prime"

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 272/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
m←2 n ← and +1 l ← ¬l and ← iiβ ( j ) ← j | i + 1 ∧ j | n

50th
V = vector (Z , S )
z
g:V×V×N→N
Σ ( )
g ( a, b, j ) = χ a (( j + k- 1) mod a.dom ) +1 = b
k
k=1

A=V×V×N
0
ab i
B=V×V
' '
(a b )
Q : ( a = a ' ∧ b = b ' ∧ a.lob = b.lob = 1 ∧ 1 <a.dom = b.dom )
R : Q ∧ i ∈ [ a.lob, a.hib ] ∧ ∀j ∈ [ a.lob, a.hib ]: g ( a, b, j ) ≤ g ( a, b, i )
1. Reverse: maximum search
Condition: - Parameter a, b Strengthening: Let's say how many places you match
compliance:
m ← a.lob max, i, k : = g ( a, b, a.lob ) , a.lob, a.lob
n ← a.hib k = a.hib
up ← max
i ←i max ≤ g ( a, b, k + 1)
k ←k max, i : = g ( a, b, k + 1) , k + 1 SKIP
a≤b ← a≤b k:=k+1
f ( j ) ← g ( a, b, j )
2. Replace a function with a variable
d : = g ( a, b, j )
3. Reversal: counting
Condition: - Parameter: a, b, j Strengthening: -
m ← 0 n ← a.dom - 1 and ← ii← d d β ( j ) ← a (( j + i- 1) mod a.dom ) +1 = b
j

15:10. DRIVING BACK 321

d: = g (a, b, a, b)
d : = g ( a, b, j )
max, i, k : = d, a.lob, a.lob
k = a.hib ii, d : = - 1 , 0
d: = g (a, b, k + 1) ii = a.dom - 1
the (( j + ii ) mod a.Do ) +1 = b i +1
max ≤ d
max, i : = d, k + 1 SKIP d:=d+1 SKIP
k:=k+1 ii : = ii + 1
51st
g:Z×Z×Z→Z
Σ
g ( m, n, j ) = χ ( f ( j, k ) = 0)
k=m

A=Z×Z×Z
MND

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 273/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
B = Z ×' Z '
(m n )
Q : ( m = m ' ∧n = n ' ∧m≤n +1)
Σ
R : Q ∧ d = g ( m, n, j )
j=m
1. Reversal: summary
Condition: - Parameter: - Strengthening: -
m ← m ← n n ← d d i ← i f ( j ) ← g ( m, n, j )
2. Replace a function with a variable ( z : = g ( m, n, i + 1))
3. Reversal: counting
Condition: - Parameter: m, n, i Strengthening: -
m ← m ← n n and ← iid ← z β ( j ) ← f ( i + 1 , j ) =0
52nd
V = vector (Z , vector (Z , Z))
g:V×Z→Z
Σ
g ( t, j ) = χ ( t = 0))
j, k
k=t
j

A=V×N
0
t d
B=V
'
(t '
Q: (t=t ) )
Σ
R : Q∧d = χ ( g ( t, j ) = 1)
j = t.lob
1. Reversal: counting

322 SOLUTIONS 15

Condition: - Parameter: t Strengthening: -


m ← t.lob n ← t.hib i ← i ← d d β ( j ) ← g ( t, j ) = 1
2. Replace a function with a variable ( z : = g ( t, i + 1))
3. Reversal: counting
Condition: - Parameter: t, i Strengthening: -
m ← t and +1 .lob n ← t i +1 .hib and ← iid ← z β ( j ) ← t and +1 , j = 0

53rd
g:Z×Z×Z→Z
Σ
g ( j, m, n ) = χ ( f ( k ) = f ( j ))
k=m

A=Z×Z×Z
mn max
B=Z×Z
' '
(m n )
Q : ( m = m ' ∧n = n ' ∧ m≤n )
R : Q ∧ ∃i ∈ [ m, n ] max = g ( i, m, n ) ∧ ∀j ∈ [ m, n ]: g ( j, m, n ) ≤ max
1. Reverse: maximum search
Condition: - Parameter: - String: Specify where this value is added
m←m ←nn max ← max
i←i ← k k ← a≤b a≤b
f ( j ) ← g ( j, m, n )
2. Replacing a function with a variable ( z : = g ( k + 1 , m, n ))
3. Reversal: counting
Condition: - Parameter: - Strengthening: -
m ← m ← n n and ← iid ← z β ( j ) ← f ( j ) = f ( k + 1)
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 274/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
54th
g:Z×Z→Z
Σ
g ( m, j ) = χ ( f ( j ) <f ( k ))
k=m

A=Z×Z×Z
mni
B=Z×Z
' '
( n
m )
Q : ( m = m ' ∧n = n ' ∧ m≤n )
R : Q ∧ i ∈ [ m, n ] ∧ ∀j ∈ [ m, n ]: g ( m, j ) ≤ g ( m, i )
1. Reverse: maximum search
Condition: - Parameter: - String: Specify how many elements it will precede
m←m ←nn max ← max
i←i ← k k ← a≤b a≤b
f ( j ) ← g ( m, j )

15:10. DRIVING BACK 323

2. Replace a function with a variable ( z : = g ( m, k + 1))


3. Reversal: counting
Condition: - Parameter: k, m Strengthening: -
m ← m n k ← and ← iid ← z β ( j ) ← f ( k + 1) <f ( j )
55th
M = vector (Z , V ) V = vector (Z , Z)
I ( x ) = ∀i ∈ [ x.lob, x.hib ]: ( x .dom = x.dom ∧ x .lob = x.lob )
M i i
g:M×Z→L
g ( t, j ) = Σ j- 1
m = t.lob t m, j

A=M×Z×Z
t max i
B=M
'
(t '
Q: (t=t ) )
R : Q ∧ i ∈ [ t.lob, t.hib ] ∧ max = g ( t, i ) ∧ ∀j ∈ [ t.lob, t.hib ]: g ( t j ) ≤ max
1. Reverse: maximum search
Condition: - Parameter: t Strengthening: -
m ← t.lob n ← t.hib max ← max
i←i ←kk ← a≤b a≤b
f ( j ) ← g ( t, j ) z: = g (t, t.lob)

max, i, k : = g ( t, t.lob ) , t.lob, t.lob max, i, k : = z, t.lob, t.lob


k = t.hib k = t.hib
max ≤ g ( t, k + 1) z: = g (t, k + 1)
max, i : = g ( t, k + 1) , k + 1 SKIP max ≤ z
k:=k+1 max, i : = z, k + 1 SKIP
k:=k+1
2. Replace a function with a variable
z : = g ( t, k + 1)

3. Reversal: summary
Felt: - Parameter: t, k Strengthening: - z : = g ( t, k + 1)
compliance:
m ← t.lob ii, z : = t.lob - 1 , 0
n ←k ii = k
d ←z z : = z + t ii + 1 , k + 1
i ← ii ii : = ii + 1
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 275/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
f ( j ) ← t j, k + 1

324 SOLUTIONS 15

56th
M = vector (Z , V )
V = vect (Z , Z)
I ( x ) = ∀i ∈ [ x.lob, x.hib ]: ( x .dom = x.dom ∧ x .lob = x.lob )
M i i
g:M×Z→Z
g ( t, j ) = max { tm | m ∈ [ j + 1 , t.hib ] }
,j

A=M×Z
t up
B=M
'
(t '
Q: (t=t ) )
Q ∧ ∃i ∈ [ t.lob, t.hib - 1] max = g ( t, i ) ∧
R: ∀j ∈ [ t.lob, t.hib - 1]: g ( t, j ) ≤ max
1. Reverse: maximum search
Condition: - Parameter: t String: Specify which line it is in
m ← t.lob n ← t.hib - 1 max ← max
i←i ←kk ← a≤b a≤b
f ( j ) ← g ( t, j )
2. Replace function with variable ( y : = g ( t, k + 1))
3. Reverse: maximum search
Condition: - Parameter: k, t Stretch: Give it a place
m ← k +2 n ← t.hib max ← y
and ← ii ← k kk ← a≤b a≤b
f ( j ) ← t k+1,j
57th
V = vector (Z , vector (Z , Z))
g ( t, gj ): =V Σ×t Zj → Z
k=t
jbob
χ ( t j, k = 0))

A=V×N
0
t d
B=V
'
(t '
Q: (t=t ) )
Σ
R : Q∧d = χ ( g ( t, j ) = 1)
j = t.lob
1. Reversal: counting
Condition: - Parameter: t Strengthening: -
m ← t.lob n ← t.hib i ← i ← d d β ( j ) ← g ( t, j ) = 1
2. Replace a function with a variable (z: = g (t, i + 1))
3. Reversal: counting

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 276/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:10. DRIVING BACK 325

Condition: - Parameter: t, i Strengthening: -


m ← t and +1 .lob n ← t i +1 .hib and ← iid ← z β ( j ) ← t and +1 , j = 0

58th
V = vector (Z , P )
P = ( x : Z , y : Z)
E = ( p : P, q : P )
g:V×Z→Z
h:P×P→Z
g ( v, j ) = m ∈ [ v.lob, v.hib ]: ( ∀q ∈ [ v.lob, v.hib ]: h ( v , v ) ≤ h ( v , v ) )
2 2 j q j m
h ( p, q ) = ( px - qx ) + ( py - qy )
A=V×E
v max
B=V
'
(v '
Q: (v=v ) )
Q ∧ ∃i ∈ [ v.lob, v.hib ]: max = ( v , v ( v, i ) ) ∧
R:
∀j ∈ [ v.lob, v.hib ]: ( v j , v g ( v, j ) ) ≤ max
i g

1. Reverse: maximum search


Condition: - Parameter: v String: Enter the space occupied in the vector
m ← v.lob n ← v.hib max ← max
i←i ←kk a ≤ b ← h ( ap, aq ) ≤ h ( bp, bq )
f ( j ) ← ( v , v g ( v, j ) )
j
2. Replace a function with a variable
z : = ( v k + 1 , v g ( v, k +1) )

max, i, k : = ( v , v g ( v, v.lob ) ) , v.lob, v.lob z:=(v , v g ( v, v.lob ) )


v.lob v.lob

k = v.hib max, i, k : = z, t.lob, t.lob


h ( max.p, max.q ) ≤ k = v.hib
h (( v k +1 , v g ( v, k + 1) ) .p, ( v k +1 , v g ( v, k + 1) ) .Q ) z : = ( v k + 1 , v g ( v, k +1) )
max, i : = ( v k + 1 , v g ( v, k +1) ) , k + 1 SKIP
max ≤ h ( zp, zq )
k:=k+1 max, i : = z, k + 1 SKIP
3. Reverse: maximum search k:=k+1
Condition: - Parameter: v, k Stretching: Locate the space occupied in the vector
compliance:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 277/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

326 SOLUTIONS 15

z : = ( v k + 1 , v g ( v, k +1))
m ← v.lob
n ← v.hib
up ←z z, ii, kk : = ( v k + 1 , v ) , v.lob, v.lob
v.lob
i ← ii kk = v.hib
k ← kk
a≤b ← h ( ap, aq ) ≤ h ( bp, bq ) h ( zp, zq ) ≤
f ( j ) ← ( v k+1, v ) h (( v k +1 , v kk +1 ) .p, ( v k +1 , v mk + 1 ) .Q )
j

z, ii : = ( v k + 1 , v kk +1 ) , kk + 1 SKIP

month : = month + 1
59th
M = vector (Z , V )
V = vect (Z , Z)
I ( x ) = ∀i ∈ [ x.lob, x.hib ]: ( x .dom = x.dom ∧ x .lob = x.lob )
M i i
g:M×Z→Z
g ( t, j ) = Σ t
k = t.lob t j, k

A=M×Z
t i
B=M
'
(t '
Q: (t=t ) )
R : Q ∧ i ∈ [ t.lob, t.hib ] ∧ ∀j ∈ [ t.lob, t.hib ]: g ( t j ) ≤ g ( t, i )
1. Reverse: maximum search
Condition: - Parameter: t Strengthening: Let's say how many points the winner is
compliance:
m ← t.lob max, i, k : = g ( t, t.lob ) , t.lob, t.lob
n ← t.hib k = t.hib
up ← max
i ←i max ≤ g ( t, k + 1)
k ←k max, i : = g ( t, k + 1) , k + 1 SKIP
a≤b ← a≤b k:=k+1
f ( j ) ← g ( t, j )
2. Replace a function with a variable
z : = g ( t, k + 1)
3. Reversal: summary
Felt: - Parameter: t, k Strengthening: -
compliance:
z : = g ( t, k + 1)
m ← t.lob
n ← t.hib ii, z : = t.lob - 1 , 0
d ←z ii = t.hib
i ← ii
f ( j ) ← t k+1,j z : = z + t k + 1 , yl + 1
ii : = ii + 1

15:10. DRIVING BACK 327

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 278/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

60th
g:Z×Z→L
g ( b, i ) = ∀j ∈ [( i + 1) , b ]: f ( j ) <f ( i )

A=Z×Z×N
0
abd
B=Z×Z
' '
(a b )
Q : ( a = a ' ∧b = b ' ∧a≤b +1 )
Σ
R : Q ∧ d = χ ( g ( b, j ))
j=a
1. Reversal: counting
Condition: - Parameter: - Strengthening: -
← a m ← n b i ← i ← d d β ( j ) ← g ( b, j )
2. Replace a function with a variable
l : = g ( b, i + 1)
3. Reversal: Linear Search 2.8.
Condition: - Parameter: i, b Stretching: Specify where it is first off
m ← i +2 ← n b l ← ¬l and ← iiβ ( j ) ← f ( j ) ≥ f ( i + 1)

61st
M = vector (Z , V )
V = vect (Z , Z)
I ( x ) = ∀i ∈ [ x.lob, x.hib ]: ( x .dom = x.dom ∧ x .lob = x.lob )
M i i
g : M{ × Z × Z → L
0, if j + k < 0 ∨ t.dom ≤ j + k ;
g ( t, j, k ) =
t t ∈ L + j + k, t.lob + j , if 0 ≤ j + k <t.dom.

A=M×Z×Z
t max i
B=M
'
(t '
Q: t=t )
Σ
Q ∧ i ∈ [ -t.dom + 1 , t.dom - 1] ∧ max = g ( t, i, p ) ∧
p=0
R:
Σ
∀j ∈ [ -t.dom + 1 , t.dom - 1]: g ( t, j, p ) ≤ max
p=0
1. Reverse: maximum search
Condition: - Parameter: - Strengthening: -

328 SOLUTIONS 15

m ← -t.dom + 1 n ← t.dom - 1 max ← max


i←i ←kk ← a≤b a≤b
Σ
f(j)← g ( t, j, p )
p=0

Σ
max, i, k : = g ( t, -t.dom + 1 , p ) , -t.dom + 1 , -t.dom + 1
p=0

k = t.dom - 1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 279/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
max ≤ Σ g ( t, k + 1 , p )
p=0

Σ
max, i : = g ( t, k + 1 , p ) , k + 1 SKIP
p=0

k:=k+1
2. Replace a function with a variable ( z : = Σ t.dom- 1
p=0 g ( t, j, p ))
3. Reversal: summary
Felt: - Parameter: - Strengthening: t, k z : = Σ t.dom- 1
compliance: p=0 g ( t, j, p )
m←0 p, z : = - 1 , 0
n ← t.dom - 1
p = t.dom - 1
d ←z
i ←p 0 ≤ t.lob + k + 1 + p + 1 <t.dom
f ( j ) ← g ( t, k + 1 , j ) zz : = t t.lob + k +1+ p +1 , t.lob + k + 1 zz : = 0
z : = z + zz
p:=p+1
4. Replace a function with a variable
zz : = g ( t, k + 1 , p + 1)
5. Reverse: The substitution value of a function defined by a case-separated functionthe
Calculate ( zz : = g ( t, k + 1 , p + 1))

15:10. DRIVING BACK 329

62nd
g : Z → (N × Z × L)
0
g ( m - 1) = (0 , m - 1 , false )
(1 , i + 1 , true ) , if f ( i + 1) = 1 ∧ g ( i ) = 0;
1
) f )( ,i + 1) = 1 ∧ g ( i ) > 0;
g ( i + 1) = ( g ( i ) + 1 , g ( i ) , g ( i if
1 2 3 1
(0 , g ( i ) , g ( i ) ) , if f ( i + 1) = 0 .
2 3

A=Z×Z×L×Z
MnlI
B=Z×Z
' '
(m n ' '
)
Q : ( m = m ∧n = n ∧ m≤n )
Q ∧ l = ∃j ∈ [ m, n ]: f ( j ) = 1 ∧
R:
l → ( i ∈ [ m, n ] ∧ ∀j ∈ [ m, n ]: g ( j ), ≤ g ( i ) )
1 1
1. Reverse: maximum search
Condition: - Parameter: - String: Specify the length of the longest series
compliance:
m ← m- 1 ( max, i, l ) , j, k : = g ( m - 1) , m - 1 , m - 1
n ←n k=n
up ← ( max, i, l )
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 280/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
i ←j ( max, i, l ) ≤ g ( k + 1)
k ←k ( Max, i, l ) , j : = g ( 1k + 1) k + 1 1 SKIP
a≤b ←a ≤b k:=k+1
1 1
f(j) ←g(j)
2. Replace a recursive function with a variable
z : = g ( k + 1) z : = (0 , m - 1 , false )
( max, i, l ) , j, k : = z, m - 1 , m - 1
k=n
z: = g (k + 1)
max ≤ z
1
( max, i, l ) , j : = z, k + 1 SKIP
k:=k+1
3. Reverse: The substitution value of a function defined by the split-off function,
calculation

330 SOLUTIONS 15

z : = (0 , m - 1 , false )
z : = g ( i + 1)
( max, i, l ) , j, k : = z, m - 1 , m - 1
k=n
f ( k + 1) = 1 ∧ f ( k + 1) = 1 ∧
f ( k + 1) = 0
z =0 z >0
1 1
z : = (1 , k + 1 , true ) z : = z + 1 z :=0
1 1 1
max ≤ z
1
( max, i, l ) , j : = z, k + 1 SKIP
k:=k+1
63rd
g:Z→N
0
g ( m - 1) = 0
g ( i + 1) = g ( i ) + f ( i + 1)

A=Z×Z×L
mnl
B=Z×Z
' '
(m n )
Q : ( m = m ' ∧n = n ' ∧ m≤n )
R : Q ∧ l = ∃j ∈ [ m, n ]: g ( j ) < 0
1. Reverse: linear search 2.8.
Condition: - Parameter: - Stretch: Enter where is the first time negative
m←m ←nn ←ll i←i β(j)←g(j)<0
2. Replace a recursive function with a variable
z : = g ( i + 1)

64th
g:Z→N
0
g ( m - 1) = 0{
g ( i ) + 1 , if f ( i + 1) < 0;
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 281/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
g ( i + 1) = 0, is f ( i + 1) ≥ 0 .

A=Z×Z×N
0
MND
B=Z×Z
' '
(m n ' '
)
Q:
( m = m ∧n Σ= n ∧ m≤n )
R : Q ∧ d = χ ( g ( j ) = 1)
j=m
1. Reversal: counting
Condition: - Parameter: - Strengthening: -

15:10. DRIVING BACK 331

m←m ←nn i←i ←dd β(j)←g(j)=1


2. Replace a recursive function with a variable
z : = g ( i + 1)
3. Reversal: Defined by split-off
calculating the substitution value of a function z:=0
d, i : = 0 , m - 1
z : = g ( i + 1)
i=n
i, d : = m - 1 , 0
f ( i + 1) < 0
i=n
z:=z+1 z:=0
g ( i + 1) = 1 ⇒
z=1
d:=d+1 SKIP d : = d + 1 SKIP
i:=i+1 i:=i+1

65th
g : N → (N , N )
0 0 0
g (0) = (0 (, n ) )
1
1 , g ( i2) )2 - . if 2 ∤ g ( i ) 2 ;
g ( i + 1) = (
0 , g(i)2 . if 2 | g ( i ) .
2 2

A=N×N
nk
B=N
'
(n '
Q: (n=n ) )
R: Q∧g(k) =1
1
1. Retraction: Linear Search 2.
Condition: - Parameter: - Strengthening: -
m←1 ←ll ik← β(j)←g(j) =1
1
2. Replacing a recursive function with a variable ( z : = g ( k + 1))
3. Reverse: The substitution value of a function defined by the split-off function,
Calculation ( z : = g ( k + 1))

z : = (0 , n )
k, l : = 0 , false k, l : = 0 , false
¬l ¬l
l : = g ( k + 1) = 1 2∤ z
1 ⇒ z : = (0 , z22)
2
1
k:=k+1 z : = (1 , z 22- )
l:=z =1
2
k:=k+1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 282/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
66th

332 SOLUTIONS 15

P = ( a : Z , b : Z)
g : Z → (M × N × Z)
0 0
g ( m ) ={(1 , m, m )
( G ( i ) + 1 , g ( i ) , i + 1) , where f ( i ) <f ( i + 1);
g ( i + 1) = 1 2
(1 , i + 1 , i + 1) , if f ( i ) ≥ f ( i + 1) .

A=Z×Z×P
mni
B=Z×Z
' '
(m n ' '
)
Q : ( m = m ∧n = n ∧ m≤n )
R : ∧ Q ia, ib ∈ [ m, n ] ∧ y = g ( ib ) ∧ ∀k ∈ [ m, n ]: g ( k ) ≤ g, ( Ib )
2 1 1
1. Reverse: maximum search
Condition: - Parameter: - Stretching: Enter the length of the longest stretch
m ← m- 1 ← n n ← max ( max i i )
a b
i←i ←kk a≤b ← a ≤ b
1 1
f(j)←g(j)
2. Replacing a recursive function with a variable ( z : = g ( k + 1))
3. Reverse: The substitution value of a function defined by the split-off function,
Calculation ( z : = g ( k + 1))

67th
g : N → (N , N )
0 0 0
g (0) = (0 (, x ) )
1
. if 2 ∤ g ( i ) ;
g ( i + 1) = ( 1 , g ( i2) )2 - 2
0 , g(i)2 . if 2 | g ( i ) .
2 2

A=N×N
0
xD
B=N
'
(x '
Q: (x=x ) )
Σ
R : Q∧d = χ ( g ( j ) = 1)
j=1 1

1. Reversal: counting
Condition: - Parameter: - Strengthening: -
m ← 1 n ← ⌈log n⌉ i ← i ← d d β ( j ) ← g ( j ) = 1
2 1
2. Replace a recursive function with a variable ( z : = g ( i + 1))
3. Reverse: The substitution value of a function defined by the split-off function,
Calculate ( z : = g ( i + 1))
68th

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 283/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:10. DRIVING BACK 333

V = vector (Z , C )
g : Z → (N × Z)
0
g ( x.obl - 1) = (0
{ , x.lob )
(0 , i + 2) , if x and +1 = ',';
g ( i + 1) =
( g ( i ) + 1 , g ( i ) if) ,x and +1 = ',' .
1 2

A=V×Z
xi
B=V
'
(x '
Q: (x=x ) )
R : Q ∧ i ∈ [ x.lob, x.hib ] ∧ ∀j ∈ [ x.lob, x.hib ] g ( j ), ≤ g ( i )
1 1
1. Reverse: maximum search
Condition: - Parameter: x Stretch: Enter the length of the longest word
compliance:
m ← x.lob - 1 ( Max, i ) , j, k : = g ( x.lob - 1) , x.lob - 1 , x.lob - 1
n ← x.hib k = x.hib
up ← ( max, i )
( max, i ) ≤ g ( k + 1)
i ←j 1 1
k ←k ( Max, i ) , j : = g ( k + 1) k + 1 SKIP
a≤b ←a ≤b k:=k+1
1 1
f(j) ←g(j)
2. Replacing a recursive function with a variable ( z : = g ( k + 1))
3. Reverse: The substitution value of a function defined by the split-off function,
Calculation ( z : = g ( k + 1)) z : = (0 , x.lob )
z : = g ( x.lob - 1) ( max, i ) , j, k : = z, x.lob - 1 , x.lob - 1
( max, i ) , j, k : = z, x.lob - 1 , x.lob - 1 k = x.hib
' '
k = x.hib x and +1 = ,
z : = g ( k + 1) z : = (0 , i + 2) z :=z +1
1 1
max ≤ z max ≤ z
1 1
( max, i ) , j : = z, k + 1 SKIP ( max, i ) , j : = z, k + 1 SKIP
k:=k+1 k:=k+1
69th
g : Z → (N × Z) g ( to ) = (0 , in )
( F ( i + 1) <f ( i ) ∧ f ( i + 1) <f ( i + 2))
0

(0 , i + 1) , if
g ( i + 1) =
∧(i+1=b)
( f ( i + 1) ≥ f ( i ) ∨ f ( i + 1) ≥ f ( i + 2))
( g ( i ) + 1 , g ( i ) ) , ha
1 2 ∨(i+1=b)

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 284/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

334 SOLUTIONS 15

A=Z×Z×Z
abi
B=Z×Z
' '
(a b )
Q : ( a = a ' ∧b = b ' ∧a≤b +1 )
R : Q ∧ i ∈ [ a, b ] ∧ ∀j ∈ [ a, b ]: g ( j ), ≤ g ( i )
1 1
1. Reverse: maximum search
Condition: - Parameter: - Stretching: Specify the widest mountain
compliance:
m←a
n ←b ( max, i ) , i, k : = g ( a ) , a, a
up ← ( max, i ) k=b
i ←i
k ←k ( max, i ) ≤ g ( k + 1)
1 1
a≤b ←a ≤b ( max, i ) , i : =
1 1
f(j) ←g(j) g ( k + 1) , k + 1 SKIP
2. Replace a recursive function with a variable
k:=k+1
z : = g ( k + 1)
3. Reverse: The substitution value of a function defined by the split-off function,
Calculation ( z : = g ( k + 1))
z : = (0 , a )
( max, i ) , j, k : = z, a, a
k=b
f ( i + 1) <f ( i ) ∧ f ( i + 1) ≥ f ( i ) ∨
f ( i + 1) <f ( i + 2) ∧ f ( i + 1) ≥ f ( i + 2) ∨
i+1=b i+1=b
z : = (0 , k + 1) z :=z +1
1 1
max ≤ z
1
( max, i ) , j : = z, k + 1 SKIP
k:=k+1

15:10. DRIVING BACK 335

70th
V = vect (Z , Z)
g : Z → (N × Z × L)
0

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 285/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
g ( x.obl - 1) = (0
{ , x.lob - 1 , false )
( G ( i ) + 1 , g ( i ) , right ) , where x i + 1 < 0;
g ( i + 1) = 1 2
(0 , i + 2 , g ( i ) ) , if x and +1 ≥ 0 .
3

A=V×L×Z
xli
B=V
'
(x '
Q: (x=x ) )
Q ∧ l = ∃j ∈ [ x.lob, x.hib ]: x < 0 ∧
R:
l → ( i ∈ [ x.lob, x.hib ] ∧ ∀j ∈ [ x.lob, x.hib ] g ( j ), ≤ g ( i ) )
j
1 1
1. Reverse: maximum search
Condition: - Parameter: x Stretch: Enter the length of the longest series
m ← x.lob - 1 n ← x.hib max ← ( max, i, l )
i←j ←kk a≤b ← a ≤ b
1 1
f(j)←g(j)
2. Replacing a recursive function with a variable ( z : = g ( k + 1))
3. Reverse: The substitution value of a function defined by the split-off function,
Calculation ( z : = g ( k + 1))

71st
g:Z→N
g ( a - 1) = 0
g ( i + 1) = g ( i ) + x ( i ) - y ( i )

A=Z×Z×Z
abi
B=Z×Z
' '
(a b )
Q : ( a = a ' ∧b = b ' ∧a≤b +1 )
R : Q ∧ i ∈ [ a - 1 , b ] ∧ ∀j ∈ [ a - 1 , b ]: g ( j ) ≤ g ( i )
1. Reverse: maximum search
Condition: - Parameter: - Stretching: Enter the number of visitors
m ← a- 1 ← n b max ← max
i←i ← k k ← a≤b a≤b
f(j)←g(j)
2. Replacing a recursive function with a variable ( z : = g ( k + 1))

336 SOLUTIONS 15

72nd
V = vect (Z , Z)
g : Z → (Z × L × L)
g ( t.lob - 1) = (0 , false, false )
(0 , false, false ) , if ¬g ( i ) ∧ t and +1 = a ∧ t and +1 = b
2
( t i +1 , true, false ) , if ν ( i ) ∧ ( t i +1 = a ∨ t and +1 = b )
g ( i + 1) = 2
( g ( i ) 1 , true, false ) , ha π
1

( ( g ( i )(1 , true, true ) , (otherwise


π = g ( i ) ∧ t and +1 = g ( i ) ∨t and +1 = a ∧ t and +1 = b ))) ∧ ¬g ( i )
1 2 1 3

A=V×Z×Z×Z×L
t abkl
B=V×Z×Z

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 286/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
( ' '
'
'
' '
Q : (t a = aa b∧ b = b ∧ t = t ) )
Q ∧ l = ∃j ∈ [ t.lob, t.hib ]: g ( j ) ∧
R:
l → ( ∃j ∈ [ t.lob, t.hib ] ( g ( j ) ∧ k = g ( j ) ))
3

3 1
1. Reverse: linear search 2.8.
Condition: - Parameter: - Strengthening: -
m ← t.lob n ← t.hib ← l l i ← i β ( j ) ← g ( j )
3
2. Replace a recursive function with a variable ( z : = g ( i + 1))
3. Reverse: The substitution value of a function defined by the split-off function,
Calculate ( z : = g ( i + 1))
k, l , l : = 0 , false, false
1 2
i, l : = t.lob - 1 , false
¬l ∧ i = t.hib
¬l ∧ ( t i +1 = a ¬l ∧ ( t i +1 = a l ∧ ¬l ∧ t and +1 = k∨ l ∨ l ∧ t and +1 = k ∧
∧2 t and +1 = b ) ∨2 t and +1 = b ) ( t and +1 = a ∨ t and +1 = b( )t and +1 = a ∨ t and +1 = b )
2 3 3 2

k, l , l : = k, l , l : = k, l , l : = k, l , l : =
1 2 1 2 1 2 1 2
0 , false, false t i +1 , true, false k is true or false k, true, true
l:=l
2
i:=i+1

15:10. DRIVING BACK 337

73rd
ρ = true ( )
∀j ∈ [1 , i ]: ( x i∈ [1 , n ] ∧
0

ρ = ∃ ( x , ..., x ):
i 1 i ∀k ∈ [1 , j - 1]: x j = x k ∧ x j ± i - k = x k )
ρ=ρ
nn
i=1{ 1 ... n}
N=×
A=N×L×N
NLX
B=N
'
(n '
Q: (n=n ) )
R : Q ∧ L = ∃y ∈ N : ρ ( φ ( y )) ∧ → l ( ρ ( φ ( x )))
1. Retract: Backward search
Condition: - Parameter: approx
Stretching: Enter the first such value
compliance:
ν ←x δ ← n Id φ ←
i i and
2. Reverse: Linear Search 2.8.
Condition: - Parameter: x Strengthening: - l : = ρ m+1( x )
compliance:
m←1 i, l : = 0 , true
n ←m l∧ i = m
l ← ¬l l : = x m +1 = x and +1 ∧ x m +1 ±
i ←i | m + 1 - j | = x and +1
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 287/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
β ( j ) ← x mx +m1+1=±x | m
j
∨ +1-j|=x i:=i+1
j

74th
ρ = true ( )
0
∀j ∈ [1 , i ]: ( x i∈ [1 , n ] ∧
ρ = ∃ ( x , ..., x ):
i 1 i ∀k ∈ [1 , j - 1]: x j = x k ∧ x j ± i - k = x k )
ρ=ρ
nn
i=1{ 1 ... n}
N=×

A=N×L×N
0
nld
B=N
'
(
n '
)
Q : ( n = n ∧ x.dom = n ∧ x.lob =)1
Σ
R: Q∧ d = : ρ ( φ ( μ ))
μ < ( ν 0, ν )
1. Reverse: reverse count

338 SOLUTIONS 15

Condition: - Parameter: approx


Strengthening: -
compliance:
ν ← ν δ ← n Id φ ←
i i and
2. Reverse: Linear Search 2.8.
Condition: - Parameter: ν Stretch: Enter your location
m ← 1 ← n m l ← ¬l i ← i β ( j ) ← ν m +1 = ν
j
∨ ν m +1 ± | m + 1 -j|=ν
j

76th
ρ = true ( )
ρ = ∃ ( x , ..., x ): ∀j ∈ [1 , i ]: t
0
x
i 1 i j, x j ∧∀k∈ [1 , j- 1]: x j = k
ρ=ρ
nt.dom
N = × i = 1 { 1 ... n}
NNM = vector (Z , vector (Z , L))
I ( x ) = ∀i ∈ [ x.lob, x.hib ]: ( x .dom = x.dom ∧ x .lob = x.lob )
NNM i i
V = vect (Z , Z)

A = NNM × L × V
t l x
B = NNM
( t )
Q : ( t = t ' ∧ x.lob = t.lob = 1 ∧ x.dom = t.dom = n )
R : Q ∧ L = ∃y ∈ N : ρ ( φ ( y )) ∧ → l ( ρ ( φ ( x )))
1. Retract: Backward search
Condition: - Parameter: t Stretching: Enter the first such value
compliance:
ν ←x δ ← t.dom Id φ ←
i i and
2. Reverse: Linear Search 2.8.
Condition: - Parameter: x, t Stretch: Enter your location
m ← 1 ← n m l ← ¬l i ← i β ( j ) ← ¬t m +1 , x x
m + 1 ∨x m +1 = j

82nd

H = ( x : N , y : N)
T = ( h : H, e : N , t : N , faza : N , J : L)
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 288/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
F = file ( T )
A = Fx seq ( H ) × seq ( T )
x t z
B=F
'
x '
Q:(x=x ) ' '
R :( t = f ( x ) ∧z = f ( x ))
1 2

15:10. DRIVING BACK 339

where f and f processed per element and processed by one element


1 2 can be
tozataik:
e∈T
{
{eh}, ha ¬ej ;
f ( {e} ) =
1 ∅ anyway .
{
{e}, ha et> 20;
f ( {e} ) ∅ anyway .
2

So this is a one-variable duplex item processing.

z : = <>
t : = <>
sx, dx, x : read
sx = norm
¬dx.j
t : hiext ( dx.h ) SKIP
dx.t> 20
z : hiext ( dx ) SKIP
sx, dx, x : read

83rd
F = file ( N )
A=F×F×F
k v z
B=F×F
' '
k ' v ' ' '
Q : ( k = k ∧' v = ' v ∧ k increasing ∧ v increasing)
R : ( z = f ( k , v ))
where f can be processed per item and processed by an item:
f ( {e}, ∅ ) = {e}
f ( ∅, {e} ) = ∅
f ( {e}, {e} ) = ∅
So this is a bivalent one-valued item processing. However,
using the spell of data and overwriting files) is as follows:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 289/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

340 SOLUTIONS 15

z : = <>
sk, dk, k : read
sv, dv, v : read
sk = norm ∨ sv = norm

sv = norm ∨ sk = norm ∧ sk = norm ∨


( sk = norm ∧ sv = norm ∧ ( sk = norm ∧
sv = norm ∧ dk = dv sv = norm ∧
dk <dv ) dk> dv )
z : hiext ( dk ) sk, dk, k : read
sv, dv, v : read
sk, dk, k : read sv, dv, v : read

84th
Consider the following function: H = { 0 , 1 } × N × Z , f : Z → H
0
{
(1 , x, x ) , if x> 0;
f(x)=
(0 , -x, x ) , if x ≤ 0 .

F = file (Z))
A=F×H
x up
B=F
'
x ' '
Q : ( x = x ∧ x ' .dom ≥ 1) i )' = max ∧ ∈ [ 1..x ' .dom ]: f ( x j ) ≤max )
R : ( ∃i ∈ [ 1..x .dom ]: f ( x
where the sorting of the type H is ≤ , so that the first com-
take the least into consideration, the second being "less". The number of searches
mot max contains the third component. Seeing this postponement, we can try
to reconnect the task to the maximum search, for the first time write the maxi-
mum searching for series:

max : = f ( x.lov )
x.dom = 0
f ( x.lov ) ≥max

max : = f ( x.lov ) SKIP


x : lorem

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 290/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:10. DRIVING BACK 341

From here, it's easier to transcribe. We know that x is not empty, so


we can do two pre-readings. We also apply ≤ calculating method-
and substitute f ( dx ) with variable (then z is already a record also
considered):

sx, dx, x : read


max : = f ( dx )
sx, dx, x : read
sx = norm
f ( dx ) . 1 > max. 1 ∨ f ( dx ) . 1 = max. 1 ∧ f ( dx ) . 2 > max. 2
max : = f ( dx ) SKIP
sx, dx, x : read

sx, dx, x : read


dx> 0
z : = (1 , dx, dx ) z : = (0 , -dx, dx )
max : = z
sx, dx, x : read
sx = norm
dx> 0
z : = (1 , dx, dx ) z : = (0 , -dx, dx )
z. 1 > max. 1 ∨ z. 1 = max. 1 ∧ z. 2 > max. 2
max : = z SKIP
sx, dx, x : read

85th
K = ( n : N, o : O, v : V, m : M )
F = file ( K )
A=F×F×F
x y z
B=F
'
x

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 291/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

342 SOLUTIONS 15

'
Q:(x=x ) ' '
R : ( y = f ( x ) ∧ z = f ( x ))
1 2

One-variable divalent item processing, where two elements


variants of each element processing function:

{ {
f ( {e} ): =
∅, if eo = 'mexikó';
f ( e ): =
∅, has ev = 'red';
1 {E}, if eo = 'mexikó' . 2 {E}, has ev = 'red' .

The Solution Program:

y, z : = <>, <>
dx, x : fin
dx = extr
dx.o = ' mexikó '
y : hiext ( dx ) SKIP
dx.v = 'red'
z : hiext ( dx ) SKIP
dx, x : fin

87th

NEV = seq ( Ch )
F = file (( name : NEV, o : Z))
A = F × NEV ×L
x n l
B=F
'
x '
Q:(x=x )
R : ( l' = ( ∃i ∈ [ 1..x .dom ]: x and .o≥ 0) ∧l → ( ∃i∈ [ 1..x ' .dom ] :( x i .o≥ 0 ∧
' '

i .nev∧∀j∈ [ 1..x ' .dom ] :( x j .o≥ 0 → x i .o≤x j .o ))))


n=x
The task can be traced back to a conditional maximum search.

15:10. DRIVING BACK 343

l : = false
sx, dx, x : read
sx = norm

dx.o ≥ 0
dx.o < 0 dx.o ≥ 0 ∧ l
∧ ¬l

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 292/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
l, max : = dx.o ≥ max dx.o ≤ max
SKIP right, dx.o max : = dx.o
SKIP
n : = dx n : = dx
sx, dx, x : read

88th

F = file (Z)
V = vector (Z , N)
S = seq (Z)
A=V ×F×S
x y z
B:V ×F
' '
x '
y ' ' ' ' '
Q' : ( x = x '∧ y = y ∧ x increasing ∧ y increasing ∧ ∀j ∈ [ y .ob, y .bib - 1]:
j>
y 0 ∧ y .hiv
'
<' 0)
R = ( z = f ( k , v ))

where f can be processed per item and processed by an item:


f ( {e}, ∅ ) = {e}
f ( ∅, {e} ) = {e}
f ( {e}, {e} ) = {e}

So this is a bivalent one-valued item processing.

344 SOLUTIONS 15

z : = <>
two, y : finop
k : = x.lob - 1
two ≥ 0 ∨ k = x.hib

two < 0 ∨ k = x.ib ∨


two ≥ 0 ∧ k = x.hib
( ≥ 0 ∧ k = x.hib ( k = x. error ∧ dy ≥ 0
∧ x [ k + 1] <two ) ∧ x [ k + 1] = two ∧ x [ k + 1] > two )
z : hiext ( x [ k + 1])
z : hiext ( x [ k + 1]) z : hiext ( two )
k:=k+1
k:=k+1 two, y : finop
two, y : finop

Note: In the middle line z : hiext ( dy ) can be written.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 293/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:11. ABSTRACTION STRATEGY 345

15:11. Abstraction strategy


First
Be
V = vect (Z , Z)
S = seq (Z)
A=V ×S
x y
B=V
'
x '
Q:(x=x )'
R : ( y = f ( x ))
Let's consider the elements of the vector to be different. This can be done because min-
den element can be replaced by a (index, element) pair. Be
{
f(x)=

f ( {e} ) and f ( {e} ) =
∅, ha e ≤ 0;
{E}, has e> 0 .
e∈ {x}

According to item 12.1, f is a function that can be processed per element, such as a single variable
the element-by-processing vector and the function defined by the random separation
calculated using:

y : = <>
i : = x.dom
i=0
x x.lob + i- 1 > 0
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 294/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

y : hiext ( x x.ob + i- 1 ) SKIP


i:=i-1

Third
Let S be = seq ( D ) , T = seq ( AZON ) , D = ( on : AZON, no :
SZA, LC : LC, iv : IV, start : N , rank : INSERT, fiz : N) ,

A=S×T×N×S
x y year z

Transform the status space:

346 SOLUTIONS 15

'
A =S ×S×N×S
x u year z
'
B =S ×S×N
' ' '
x in ev
The relation between y and u is dom ( u ) = dom ( y ) and ∀i ∈ [1 ..dom ( u )]:
u .azon = y .azon . The u rest is the same as the xu Prior Art ID
and and i i
with the rest of its element, if there is such an element, anything may be anyway.
' ' ' ' '
Q : ( ev = ev ' ∧ x = x ∧' u = ' u ∧ growing ( x ) ∧ increasing ( u ))
R : ( ev = ev ∧ z = f ( x , u ))
' ' '
i Prior Art <x i +1 Prior Art .
( x ) = ∀i ∈ [ 1..dom ( x )]: x
The main definition of a function:

f ( x, u ) = f ( s ( e ) , s ( e )) , where
1 2
e∈ {x} ∪ {u}
{ {
{e}, if e ∈ {x} ; {e}, if e ∈ {u} ;
s (e)= s (e)= and
1 ∅, if e ∈ {x} 2 ∅, if e ∈ {u}
f ( {e}, ∅ ) = ∅,
f ( ∅, {e} ) = ∅,
{
{e}, if e.kezd <ev ;
f ( {e}, {e} ) =
∅ anyway .
For the sake of simplicity, dates are considered to be a year (ie a ter-
natural number), and the months and days are not stored.
So this is a bivalent one-valued item processing.

z : = <>
x.dom = 0 ∨ u.dom = 0

u.dom = 0 ∨ x.dom = 0 ∨
( u.dom = 0 ∧ x.dom = 0 ∧ ( x.dom = 0 ∧
x.dom = 0 ∧ u.dom = 0 ∧ u.dom = 0 ∧
x.lov.azon < x.lov.azon = x.lov.azon>
u.lov.azon ) u.lov.azon u.lov.azon )

x.lov.kezd <ev
z : hiext ( x.lov ) SKIP
x : lorem in : lorem
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 295/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
x : lorem
y : lorem

15:11. ABSTRACTION STRATEGY 347

Since only parts of the elements of u are included in the program, they are
while the elements of y are exactly the same as u.lov.azon ← y.lov substitution
program in the original state.

4th
First solution
Let X = seq ( Ch ) and state space
A=X×X.
x y

We translate the status space.


' ' +
Let U = seq ( S ), S = ( Ch ; H ) , Ch = Ch \ { "" } and H = seq ( { "" } )
that is, H spaces are not empty series, and U is the next invariant
property:
I ( u ) = ∀i ∈ [1 ..dom ( u ) - 1] u .h = u i + 1 .h , i.e. u non-space character would
U i
spaces and spaces series.
'
A =U ×X
u y

The relationship between x and u is seq ( x | Ch ) = seq ( u | Ch ).


Transform the status space further. Let T = f ile ( Ch ) .
''
A =T ×X
t y
''
B =T '
t
The relationship between t and u is dom ( t ) = dom ( u ) and
{ '
in
∀i ∈ [ 1..dom ( t )]: t i = i , if u .Ch ,
" ' , If u .h and
i

Then the task is:


'
Q:(t=t ')
R:(y=t )
If there is such a t file, then the task is a simple element
processing with the same mapping as an element
function. Let's look at the abstract copier program and the abstract t file
operations.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 296/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

348 SOLUTIONS 15

open ( t )
st, dt, t : read
y : = <>
st
y : hiext ( dt )
st, dt, t : read

st, dt, t : read

x.dom = 0
st : = norm
dt : = x.lov
dt = "" st : = abnorm
x.dom = 0 ∧ x.lov = ""
x : lorem
x : lorem

The open ( t ) program does not do anything in this case, that is, Skip .
Second solution
Let X = seq ( Ch ). Define the following function: f ∈ N × X →
0
X × L,
f (0) = ( <> , false )

( hiext ( f ( i ) 1 , x i + 1 ) is false ) , if x i +1 = "";


f ( i + 1) = ( hiext ( f ( i ) 1 , x i +1 ) , true ) , if x i +1 = "" and ¬f ( i ) ;
2
f(i), if x i +1 = "" and f ( i )
2

Then the job specification is:


A=X×X.
x y
B=X
'
x '
Q:(x=x ) '
R :( y = f ( dom ( x )) )
1

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 297/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:11. ABSTRACTION STRATEGY 349

The solving propagram is the substitution value of the function with the recursive formula
on the basis of:

y, l : = <> , false
x.dom = 0

\ x.lov = "" \ x.lov = "" ∧¬l \ x.lov = "" ∧l


y : hiext ( x.lov ) y : hiext ( x.lov ) Skip
l : = false l : = true
x : lorem

7th
First solution
Let F = f ile ( Ch ) and state space
A=F×N
0
x d
Transform the state space, introduce the words "word" and "partition"
' + ' +
Galm. Ch = Ch \ { "" }, SZO = seq ( Ch ) , ELV = seq ( { "" } ) . Be
S = ( SZO ; ELV ) and U = seq ( S ) with the known invariant property:
And ( u ) = ∀i ∈ [ 1..dom ( u ) - 1]: u .SZO = u and +1 .SZO.
U and

This is the new state of play


'
A =U ×N
0
u d
and the relationship between x and u is seq ( x | Ch ) = seq ( u | Ch ).
Since we do not need separating parts, new transfor-
by divesting them, that is
''
A =V × N where V = seq ( SZO ) and seq ( u | SZO ) = seq ( v | SZO ) .
0
v d
Finally, since we only need the length of words, let Y = f ile (N),
A
'' '
=Y × N and dom ( y ) = dom ( v ) and ∀i ∈ [1 ..dom ( y )]: y = dom ( v ) .
0 i i
y d
B=Y
'
y '
Q:(y=y )
Σ '
R:(d= χ ( yi > 5))
i=1
Solution program counts (abstract) sequential file.

350 SOLUTIONS 15

open ( y )

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 298/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
eye, two, y : read
d:=0
sy = norm
two < 5
d:=d+1 SKIP
eye, two, y : read

The actions of the abstract file:

open ( y )

sx, dx, x : read


sx = norm ∧ dx = ""
sx, dx, x : read

eye, two, y : read

sx = norm
sy : = norm
two : = 0
sx = norm ∧ dx = ""
two : = two + 1 sy : = abnorm
sx, dx, x : read
sx = norm ∧ dx = ""
sx, dx, x : read

Second solution
Functional abstraction is used with the last post element. Be y =
con ( x, < extr > ), ChE = Ch ∪ {extr} and F = f ( ChE ).
'
A =F ×N
0
y d

15:11. ABSTRACTION STRATEGY 351

B=F
'
y '
Q:(y=y ) '
R : ( d = f ( dom ( y )) ) , where
1

f (0) = (0 , 0) and
'
( f ( i ) 1 , f ( i ) 2 + 1) , where y i +1 ∈' Ch ;
f ( i +1) = ( f ( i ) 1 +1 , 0) , if y i +1 ∈ Ch ' and 0 <f ( i ) < 5;
f(i), if y i +1 ∈ Ch and f ( i ) = 02 or f ( i ) ≥ 5.
2 2

Apply the recursive function to an abstract sequential file:


file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 299/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

open ( y )
eye, two, y : read
d, h : = 0 , 0
sy = norm
' ' '
two ∈ Ch two ∈ Ch ∧ two ∈ Ch ∧
\ \ h> 0 ∧ h < 5 \ ( h = 0 ∨ h ≥ 5)
h:=h+1 d, h : = d + 1 , 0 Skip
eye, two, y : read

The actions of the y abstract file:

open ( y )

sx, dx, x : read


two : = ""

eye, two, y : read

two = extr
sy : = norm
sx = norm
sy : = abnorm
two : = dx
two : = extr
sx, dx, x : read

352 SOLUTIONS 15

8th
First, define the types in the task.
U = ( on : However, it does : Z)
T = ( type : { exception , insert }, partition : N)
Y=(u:U;t:T)
F = file ( Y )
'
F = file ( U )
'
A=F×F
x z
B:F
'
x ' ' '
Q : ( x = x ∧ ( x .lov.u ∨ x .dom = 0))
'
The prerequisite x .lov.u . since R is a merger, it states that a
first record of an input file must be a client record.
First solution
Before the postponement is written, we will transform the status space. Let V=be
( u : U, s : S ), where S = seq ( T ) and H = seq ( V ) .
' '
A =H ×F
h z
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 300/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
The relation between x and h is seq ( x | {U, T} ) = seq ( h | {U, T} ).
Further transforming the state space,
'' ' '
A =F ×F
t z
Connection between h and t :

dom ( t ) = Dom ( h ) and ∀i ∈ [1 ..dom ( t )]: t Prior Art = h Prior Art and
i i

Σ
t length = h .u. length + E ( h .s .tipus ) h .s .ossz, wherein
i. i i j i j
j=1
{
- 1 , where h .s .tipus = withdrawal;
e ( h .s .tipus ) = i j
i j 1, if h .s .tipus = napkin .
i j

In this state of affairs the task is very simple, with an identical univariate-
monovalent processing per item.
'' ' '
A =F ×F
t z
'' '
B =F '
t

15:11. ABSTRACTION STRATEGY 353

'' '
Q '' : ( t = t ' )
R :(z=t )

open ( t )
st, dt, t : read
z : = <>
st = norm
z : hiext ( dt )
st, dt, t : read

The t read abstract file on a substantially recursive function


(sum) substitution value.

st, dt, t : read

sx = norm
st : = norm
dt : = dx
sx, dx, x : read
sx = norm ∧ dx.t
st : = abnorm
dx.tipus = deposit

dt . length : = dt . length : =
dt.ossz + dx.ossz dt. length - dx. length

sx, dx, x : read

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 301/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

open ( t )

sx, dx, x : read

This program guarantees that dx = h .u because we are required to have a x client record-
1
song starts.
Second solution

354 SOLUTIONS 15

Functional abstraction is used with the last post element.


Let y = con ( x, < ( extr, 0) > ) .
' '
A =F ×F
y z
B=F
'
y ' '
Q : ( y = y ∧ y .lov.u
'
)
R : ( z = f ( dom ( y )) ) ,
where the function f is 1defined:

f (0) = ( <> , " empty " , 0) and

f ( i + 1) =

( Hiext ( f ( i ) , ( f ( i ) , f ( i ) ) , y i +1 Prior Art, y i +1 .ossz ) , if y i +1 .u


1 2 3
and f ( i ) = " empty ";
2
( F ( i ) , y i + 1 Prior Art, y i +1 .ossz ) , if y i +1 .u
1
and f ( i ) = " empty ";
2
( F ( i ) , f ( i ) , f ( i ) + e ( y i +1 .tipus ) y i + 1 .s ) , if y i +1 .t where
1 2 3

{
- 1 , if y i +1 .tipus = exclude ;
e ( y and +1 .tipus ) =
1, if y i +1 .typus = deposit .

Apply the recursive function to an abstract sequential file:

open ( y )
eye, two, y : read
z, a, s : = <> , " empty " , 0
sy = norm
\ dy.u∧a = " empty " \ dy.u∧a = " empty " \ dy.t
\ dy.tipus = exception /
z : hiext ( a, s ) a, s : = s:=s s:=s
a, s : = two, two -dy.ossz + dy.ossz
two, two
eye, two, y : read

The actions of the y abstract file:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 302/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:11. ABSTRACTION STRATEGY 355

open ( y )

sx, dx, x : read


two : = " empty "

eye, two, y : read

two = extr
sy : = norm
sx = norm
sy : = abnorm
two : = dx
two : = extr
sx, dx, x : read

9th
Specification:
F = file ( Ch )
A=F×N
0
x d
B=F
'
x '
Q:(x=x )
The solution to the problem is very similar to the solution to task 7.
First solution
The task is solved by data abstraction, the abstract file is natural
numbers that correspond to the word lengths of the specific file.
+ +
Let WORD = seq ( letters ) , ELV = seq ( BETU ) , E = ( WORD, BETU ) and
S = seq ( E ) .

open ( t )

sx, dx, x : read


sx = norm ∧ dx = ""
sx, dx, x : read

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 303/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

356 SOLUTIONS 15

st, dt, t : read

sx = norm
st : = norm
dt : = 1
sx, dx, x : read
sx = norm ∧ dx = ""
st : = abnorm
dt : = dt + 1
sx, dx, x : read
sx = norm ∧ dx = ""
sx, dx, x : read

With this abstract file, the task can easily be traced back to one
(where we sum up according to the function, which is only 12 na-
for the main argument 2, otherwise 1).
'
F ' = file' (N)
A =F ×N
0
t d
' '
B =F '

'
t '
Q :(t=t )
' Σ '
R :(d= '
f ( ti ))
i = t .lob
{
2 , if e> 12;
f(e)=
1 otherwise

d:=0
open ( t )
st, dt, t : read
st = norm
dt> 12
d:=d+2 d:=d+1
st, dt, t : read

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 304/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

15:11. ABSTRACTION STRATEGY 357

Second solution
F = file ( Ch ).
'
A =F ×N
0
y d
B=F
'
y '
Q:(y=y ) '
R : ( d = f ( dom ( y )) ) , where
1

f (0) = (0 , 0) and
( F ( i ) + 1 , f ( i ) + 1) , where y i +1 ∈ letters and
1 2
( f ( i ) = 0 or f ( i ) = 12);
f ( i + 1) = ( f ( i ) , 0) , where y i +1 2∈ letters ; 2
1
≠ ( f ( i ) , f ( i ) + 1) , where y i +1 ∈ letters and
1 2
f ( i ) = 0 and f ( i ) = 12 .
2 2

Apply the recursive function to a sequential file:

eye, two, y : read


d, h : = 0 , 0
sy = norm
two ∈ BETU ∧ two ∈ BETU ∨ two ∈ BETU

\ ( h = 0 ∨ h = 12) \ h = 0 ∧ h = 12 \
d, h : = d + 1 , h + 1 h:=h+1 h:=0
eye, two, y : read

10th
First solution
Specification:
F = file ( Ch )
A=F×N
0
x d

We translate the status space. Let Y = f ile (L) and


'
A =Y ×N
0
y d
The relationship x and y between: dom ( y ) = Dom ( X ) and

∀i ∈ [ 1..dom ( y )]: y i = ( x i = "R") .

358 SOLUTIONS 15

'
B =Y '
y
'
Σ '
Q:(y=y )R:(d= i=1
χ ( yi ))
Solution counting:
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 305/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

open ( y )
eye, two, y : read
d:=0
sy = norm
dy
d:=d+1 SKIP
eye, two, y : read

The actions of the y abstract file:

eye, two, y : read

sx = norm
sy : = norm
two : = false
sx = norm ∧ dx = ""
two : = two ∨ dx = " R " st : = abnorm
sx, dx, x : read
sx = norm ∧ dx = ""
sx, dx, x : read

open ( y )

sx, dx, x : read


sx = norm ∧ dx = ""
sx, dx, x : read

15:11. ABSTRACTION STRATEGY 359

Second solution
F = file ( Ch ).
A=F×N
0
y d
B=F
'
y '
Q:(y=y ) '
R : ( d = f ( dom ( y )) ) , where
1

f (0) = (0 , 0) and
( F ( i ) 1 + 1 , f ( i ) 2 + 1) , if y i +1 = " R " and f ( i ) 2 = 0;
f ( i + 1) = ( f ( i ) 1 , 0) , where y i +1 ∈ letters ;
f(i), where y i +1 ∈ letters and f ( i ) is 0 .
2

Apply the recursive function to a sequential file:

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 306/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

eye, two, y : read


d, h : = 0 , 0
sy = norm
two = " R " ∧ two ∈ BETU two ∈ BETU ∧
h=0 \ ( dy = " R " ∨h = 0
\ \
d, h : = d + 1 , h + 1 h:=0 Skip
eye, two, y : read

index

THE function 146


state space 27 bivalent monovalent 148
equivalent 62 prerequisite 43
assignment 88
B simple 88
identity 52 partial 88
simultaneous 88, 155
C value selection 88
cycle 68 partial 88
deduction rule 80 separation case 144
programfüggvénye 72
F
D function 13
direct product 12, 16 party extensions 53
subspace 17 task 28
equivalence 17 equivalent 104
supplemental area 17 Current 57
conditional maximum search 126
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 307/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
E conditions 131
unification 113, 115
depending on type 116; 119, 157
equivalent
state space 62 G
direct product 17 weak truths 16, 63
task 104
program 51 H
type specification 104 hatásreláció 31
branching 66
deduction rule 79 I
programfüggvénye 71 truth sets 16
can be processed per item weak 16
general version 150 inversion 165
univariate monovalent 147
univariate divalent 149 K
a sufficient condition 146 extension

INDEX 361

tASKS 49 variable parameters 41


solution 61 partial function 13
pROGRAMS 50 primitive programs 33, 90
extension items 51 primitive type 114
composition 14 program 29, 30
strict 14 program functions 31
calculate the composition 143 programming task 33
concatenation 12 Solving 33
projection 17
L
weakest prerequisite 37 R
narrowing 14 reduced 12
deduction 153 record 112 114, 117
sealed 15 calculating recursive function 144
condition 16 relation 12
limited 15 value stocks 12
linear search 127 interpretation range 12
2.8 127 deterministic 13
first version 131 134
third version 133 134 S
second version 132 134 series 113, 115, 118, 157-160
logarithmic search 137 specification of the specification 40
counting 124
M conditions 130
up search 125 sequential
conditions 130 file 118, 158, 160, 162
allowed programs 33 right 161
adequacy 103 sequence 66
generalization 104 deduction rule 77
solution 31 programfüggvénye 70
ρ for n 102 szelektorfüggvény 114 117, 119
generalized 62 tightening 32
renaming 62
extension 61 T
according to the report 63 type 102
abstract 104
HE equivalent 105
archetype 14 elementary 102

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 308/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html
summary 123 type set 27, 101, 102, 111-113,
conditions 129 161
elementary 102
P type specification 101, 103
parameter space 39 making 104

362 INDEX

transformation 153
state space 161, 162
program 154
type 157

U
postcondition 43

V
variable 17, 41
vector 119
screening times 53
backtracking
search 138
counting 142
recirculation 153
generality 171
älteres 170, 171
constant substitution 170
parametric 154, 171
tightening 154, 169-171
natural 168

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 309/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

References

[Dij 68] Dijkstra, EW: Go to statement considered as harmful.


Communications of ACM 11, 3 (1968) 147-148.
[Mills 72] Mills, HD: Mathematical functions for structured pro-
gram ming. SC 72-6012, IBM Gaithersburg 1972.
[Hoa 72] Hoare, CAR: Proof of correctness of data representa-
tions. Acta Informatica 1, 4 (1972) 271-281.
[Jac 75] Jackson, MA: Principles of Designing Design . Aca-
demic Press, 1975.

[Dij 76] Dijkstra, EW: A Discipline of Programming . Prentice


Hall, 1976.
[San 80] Sanderson, JG: A Relational Theory of Computing .
Springer-Verlag, 1980.
[Gri 81] Gries, D .: The Science of Programming . Springer-Verlag,
1981st
[Fót 83] Fóthi Á .: Introduction to programming . University note.
ELTE TTK, 1983.
[Mal 90] Malcolm, G .: Data structures and program transforma-
tions. Science of Computer Programming, 14, 2-3 (1990)
255-279.
[Bud 95] Budd, T .: Multi-Paradigm Programming in Lede .
Addison-Wesley, 1995.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 310/311
9/23/2018 4a1e6f44-bf35-11e8-b59b-0cc47a792c0a_id_4a1e6f44-bf35-11e8-b59b-0cc47a792c0a.html

364 REFERENCES

[GHJV 95] Gamma, E. - Helm, R. - Johnson, R. - Vlissides, J .:


Design Patterns - Elements of Reusable Object-Oriented
Software . Addison-Wesley, 1995.
[Hor 98] Horváth Z .: The formal specification of a problem solved
by a parallel program - a relational model. Annales Univ.
Sci. Budapest. but R. Eötvös Nom. Sectio Computatorica
17 (1998) 173-191.
[Abr 96] Abrial, J.-R .: B book . Cambridge University Press, 1996.
[Odi 98] Odifreddi, P .: Classical Recursion Theory . Elsevier Sci-
ence Publ. BV, 1989.
[Koz Var 03] Kozma L. - Varga L .: The software technology is theoretical
questions . ELTE Eötvös Publishing House, 2003.

file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 311/311

Das könnte Ihnen auch gefallen