Beruflich Dokumente
Kultur Dokumente
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
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
6th Programkonstrukciók 73
6.1. Permissible constructions 73
6.2. Program function of program constructions 79
6.3. Tasks 81
CONTENTS 5
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
6 CONTENTS
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
Acknowledgments
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
1.3. relations 13
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
• •1
b 2
• •
c• •3
d •4
•
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}.
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
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
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
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
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
(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
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.
×
A= A :: = {x ∈ X | ∀i ∈ I : x ( i ) ∈ A }
i∈ I i i
×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
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.6. EXAMPLES 19
⌈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⌉.
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) }.
20 1. BASIC PROVISIONS
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)
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
R ( - 1) ( { 4 , 5 } ) = { 1 , 3 , 4 }.
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 .
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
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) .
∀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
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
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.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.8. Create a non-empty relationship that is true for all its value sets
the true primordial subset of idols is an empty set!
G ◦ F =? G ⊙ F =?
F ( - 1) ◦ G ( - 1) =? F - 1 ( G - 1 ( Y )) =?
( G ◦ F ) - 1 ( Y ) =? ( G ◦ F ) ( - 1) =?
1.7. TASKS 25
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.
(F◦G)◦H =F◦(G◦H),
( F ⊙ G ) ⊙ H = F ⊙ ( G ⊙ H )?
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.
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.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.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
1.7. TASKS 27
1.31. R ⊆ N × N .
0 0
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 , 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
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
×
Countable, non-empty sets. Then A = Set is state-
i∈ I i
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
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
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
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.
D p(S) F(a)
the p(S)(a)
D
F
THE THE
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.
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:
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:
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
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
Solution:
a) Since the program assigns an infinite sequence to 1 and 3,
Function Interpretation Range:
D p ( S ) = { 2 , 4 , 5 }.
p ( S ) = { (2 , 1) , (2 , 4) , (4 , 4) , (4 , 1) , (4 , 2) , (5 , 4) }.
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
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
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
and ∀a ∈ D p 2( )S: P ( S ) ( in ) ⊆ P ( S ) ( in ).
2
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.
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.
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 ) ⌉ .
⌈Lf ( S, R ) ⌉ ⌈R⌉
⌈Q⌉
⌈Lf ( S, Q ) ⌉
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.
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
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
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.
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
F = { (( u , u , u ) , ( v , v , v )) ∈ A × A | v = u + u }.
1 2 3 1 2 3 3 1 2
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
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
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:
**
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
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
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.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
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
54 3. SPECIFICATION
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 .
A=N×N
kp
B=N
'
k
'
Q : ( k = k ∧ 0 <k )
R : ( Q ∧ prim ( p ) ∧ ∀i> 1: prim ( i ) → | k - i | ≥ | k - p | ) ,
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
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.
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
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.
'
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
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.
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
'
B THE
'
G the
''
the a
G
'
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
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.
'
B
THE
D
G
H B
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 ;
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
∀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.
then ∈ D p ( S ' ) .
B
F
''
a
'
b B
4.7. figure.
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
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.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:
'
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) }
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)
D A( p ( S )) = for ( D p ( S ) )?
pr A
' '
∃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
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 ?
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!
Chapter 5
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
×
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).
~ 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
1. D
F
⊆Dγ f ◦p ( S ) ◦γ ( - 1) ,
f
∀a ∈ D F : γ f ◦ p ( S ) ◦ γ (f - 1) ( the ) ⊆ M ( to ).
Second
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
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.
γ ( - 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
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 }.
γ ( 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 },
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.
χ ( α, β ) :: = red ( con ( α, β )) .
2
{α ∈ A | α ∈ S ( a ) } ∪
∞
S(a) =
∪ **
1 *
{χ ( α, β ) ∈ A | α ∈ S ( a ) ∩ A and β ∈ S ( τ ( α )) }.
2 1 2
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
S
1
S
2
( π : 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
{
{ < 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
•
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
76 6. PROGRAM STRUCTURES
IF
1 2 n
\π \π \. \π
S S S
1 2 n
• ∀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.
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
π
S
0
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
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 ∈ ⌈π⌉ . 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
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
P(S)=P(S )⊙P(S ).
2 1
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
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
• 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
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
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
D p ( IF ) = A and D p ( S ) = ∅ !
1 2 n k k
1 2 2 1
6:11. A = { 1 , 2 , 3 , 4 } .
IF
\ i=1 \ i≤ 2
i:=2i SKIP
6.3. TASKS 83
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
'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?
F k k 's 1 n
IF the F task?
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?
84 6. PROGRAM STRUCTURES
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
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.
Q , R pairs.
b 1
b b
86 7. RULES OF PROCESSING
⌈Q⌉ '
⌈R⌉
⌈Q ⌉
p(S ,S )
1 2
•
p(S ) •
2
• P(S ) •
1
'
(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:
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
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) .
ie q ∈ ⌈lf ( IF, R ) ⌉ .
• •
p(S )
3
⌈Π 3 ⌉ •
•
p(S )
4
⌈Π 4 •⌉ •
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.
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
• p ( S ) ( q ) ⊆ ⌈R⌉ . At
i
p ( S ) ( q ) ⊆ p ( IF ) ( q ) ⊆ ⌈R⌉,
i
so we got a contradiction.
(1) Q ⇒ P ,
(2) P ∧ ¬π ⇒ R ,
(3) P ∧ π ⇒ t> 0,
(4) P ∧ π ⇒-f ( S , P ),
0
⌈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⌉
then
Q ⇒ lf ( DO, R ) .
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:
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.
p ( DO ) ( q ) ⊆ ⌈¬π⌉.
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.
0
At
(1) Q ⇒ lf ( DO, R ) is trivially fulfilled.
92 7. RULES OF PROCESSING
a∈D =⇒R(a)⊆D ,
R R
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
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
i i 1 n
relation:
⋂ ×
D = D i and ∀a ∈ D : F ( a ) = F (a).
F i=1 F F i ∈ [1 ..n ] i
{
{red ( < a, b > ) | b ∈ F ( a ) } if a ∈ D ;
S(a)=
If a ∈ D .
F
{ < A, a, a,. . . > },
F
• 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 .
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 .
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.
98 8. ELEMENTAL PROGRAMS
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
x, l : = x, ( x> 0) .
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
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
A = A × ... × A
1 n
x x
1 n
B = B × ... × B
1 ' n 'n
x1 x
Q:(x =x
'
1 ∧··· ∧x = x )
'n
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
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
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
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.
• ∀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 ,
• ∀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 .
⋂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
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
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 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
z , ..., z : = f ( x , ..., x )
1 n 1 m
y , ..., y : = g ( z , ..., z )
1 k 1 n
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
y , ..., y 1 n 1 : = f ( x , ..., x )
11 1 1 m
y k 1 , ..., y k
: = f ( x , ..., x )
kn k 1 m
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
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
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.
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
'
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
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 ).
9.3. relations
Let us turn our attention now to relations. To make the relationships predictable
we must examine the concept of predictable relationship.
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:
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.
that ∃j ∈ [1 ..n ]: A j = T .
i i T
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
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
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
T H T F T H T
p (S)
E* H E
*
E
*
H E
*
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
⌈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).
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.
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
F= (e, e), (i, í), (í, i), (o, o), (a, a), (e,
(u, u), (u, u), (u, u), (u, u), (u, u) }.
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
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
γ = ),
m (ρ ⌈I⌉ ; ρ ⌈I⌉⌈;I⌉ ρ
γ = ),
u (ρ ⌈I⌉ ; ρ ⌈I⌉⌈;I⌉ ρ
γ = (ρ ⌈I⌉ ; id [0 .. 127] ; id ) .
L
e
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) .
D
F
⊆ D γ⊙p ( S 1) ⊙γ ( - 1)
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
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}
*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
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
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
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
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
1 2 n
T × T × ··· × T .
1 2 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
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
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
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
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
ρ = φ ◦ψ ,
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|
• If
( α, t ) , ( β, t ) ∈ φ ⇔ α ∈ perm ( β ) ,
I
• 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
T
t
φ
* I
T0 ρ
B < T , t , t , ..., t >
1 2 3 |t|
ψ
* ρ ρ ρ ρ I
0 0 0 0
E
∀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
| α |, 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 |α|
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
• The series that was left out of the first or last element of an empty series:
lorem ∈ T → T , hirem ∈ T → T ,
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
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 ,
• lorem, hirem ∈ F → F ,
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
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.
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.
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 .
dom ◦ f → f.dom
hunt ◦ f → f.lov
hiv ◦ f → f.hiv
lob ◦ f → f.lob
error ◦ f → f.hib
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.
A = Z × Z × ...
mn ...
B = Z × Z × ...
' '
m n ...
' ' *
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 .
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.
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
Σ
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
'
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
Σ
φ ( m, n, d ) = d= χ ( β ( j )) χ ,
j=m
Σ
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
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
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
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
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:
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
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
Note: this programming item is also called linear search version 2.8 .
α ( 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 ) ,
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 ).
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.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
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
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
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)
'
1) Q = ( Q ∧ i = m )
2) π = ¬β ( i )
4) P ∧ π ⇒ lf ( i : = i + 1 , P )
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 .
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
'
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
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.
*
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
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
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
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
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.
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
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
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
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
in : = i + 1 l:=↑ v:=i-1
R P ∧t <t
0
i
as follows:
1. ρ = true ;
0
∀i ∈ [0 .. N - 1]: ∀u ∈ U : ρ and +1 ( u ) → ρ ( u );
Second
i
4. ρ = ρ .
N
Σ
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
j i
¬ρ ( φ ( μ )).
i
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.
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:
ν, ν , m : = ε , 0 , 1
0 0
looking for ( ν, m, l )
¬l ∧ ν = 0
0
increase ( ν , ν, m )
0
\ ν =0 /
0
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.
ν, ν , m, d : = ε , 0 , 1 , 0
0 0
ν =0
0
looking for ( ν, m, l )
l
\ /
d:=d+1 SKIP
increase ( ν , ν, m )
0
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
g ( x ) , if π ( x ) .
n n
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)) .
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
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
i, y : = m, t
0
i=n
y:=F(i+1,y)
i:=i+1
X = X × ... × X ,
1 n
Y = Y × ... × Y ,
1 m
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
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
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
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.
f ~ ( h, e ) = h ∪ {e}, if e ∈ h.
∪
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.
≃
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 = ∅ ).
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} ) , 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.
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:
', '
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.
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
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
Q:(x =x
'
∧
··· ∧x = x )
1
'n
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
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.
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.5. Determine whether the natural number k divides the natural number x .
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: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: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!
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
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
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.
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.
'
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.
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
'
Then the S program equiv S strength loss & quot The -n.
S S
12 21
S S
1 2
S S
2 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.
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
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
function pile
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.
i:=m-1
i=n a.dom = 0
f ( i + 1) f ( a.lov )
i:=i+1 a : lorem
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
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.
The matching between the two types: the a and b series members list the x and y
sets of elements.
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
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
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
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.
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:
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
⋃
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 ,
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
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
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
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
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˝} ) .
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
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 = 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ó
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
S (c)
11
x : = <>
π
S ( c, e )
12
x : hiext ( e )
S (c)
13
'
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
S (a)
11
S (d)
31
π
S ( a, e )
12
ε : = f ( {e} )
2
S ( d, ε )
32
S (a)
13
S (d)
33
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.
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.
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
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)
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
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!
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)
′
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
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
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
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
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
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.
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
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)
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
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.
i, l : = 1 , true
l∧i = p- 1
l : = ¬ ( i + 1) | p ∧ ¬ ( i + 1) | ( p + 2)
i:=i+1
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.
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 ))
i, l : = a - 1 , false
¬l ∧ i = b
l : = ( g ( i + 1) = p )
i:=i+1
z:=0
i, l : = a - 1 , false
¬l ∧ i = b
z:=F(i+1,z)
l:=(z=p)
i:=i+1
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
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
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
13.7. Tasks
Functions in tasks (if not otherwise stipulated) are integers in an inter-
they are interpreted and are of value.
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.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.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!
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.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.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!
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: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:52. Calculate the number of lines in x matrix that are only one
contains zero elements!
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.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.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.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.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.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.78. How many ways can I pay n for m from different denominations?
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:
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:
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!
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
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
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
'
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.
\ 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.
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
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.
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
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.
{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 .
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′))
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}
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:
∪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
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 )
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:
\
∨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
{
" 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
Let f : X → T .
⋃
f(x)= f ( {e} ) and
e∈ {x}
The specification:
A=X×T
xt
B=X
'
x
'
Q:(x=x )
'
R : ( t = f ( x ))
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
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
S3
x=∅ ⇒ t0 = ∅ ∨ m = ∅
e :∈ x ⇒ q :∈ ({t0.k} ∪ {m.k})
e.d = ”üres” ∧ e.v = ”üres” ⇒ q ∈ {t0.k} ∧ q ∈ {m.k}
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
Υ ( {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))}
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
dx.s(p) = f (dx.v.dom),
ahol
f (0) = p;
f ( i + 1) = dx.s and +1 ( f ( i )) .
To perform the dx.v i +1 operation in the above definition, perform the following function values
'
We understood. Let d ∈ D , then:
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
Since the current value can be " empty, " instead of the hiext operation
program is used:
t : HIEXT ( ak, ad )
Let's go back to the original state of affairs. The main program then:
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
ad := T R(p, ak)
ad := p
sm = norm ∧ ak = dm.k
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.
1. g(u).dom = u.dom
3. ∀i ∈ [1..u.dom]:
g(u)i.k = ui.k és g(u)i.z = ui.z.
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
é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).
A=X×T
xt
B=X
x′
Q : (x = x′)
R : (t = f1(x′.dom))
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
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 :=
open(x)
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”
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
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′,
és HIEXT : T × (K × D′) → T ,
{
hiext(t, (k, d)), ha d = ”üres”;
HIEXT(t,k,d) =
t, ha d = ”üres”.
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
\
∧ 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)
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!
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.
Állítsuk elő azt a fájlt, ami az ügyfeleknek a bankban levő pillanatnyi összegeit
included in customer-type records!
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.
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.
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
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,
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(B \ Q) = {a ∈ DR | R(a) ⊆ B \ Q} =
= DR \ {a ∈ A | R(a) ∩ Q = ∅} = DR \ 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
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
Q ( - 1) ◦ R ( - 1) = ( R ◦ Q ) ( - 1) = ( R ⊙ Q ) ( - 1) .
( G ◦ F ) - 1 ( Y ) = {a ∈ D | G ( F ( a )) ⊆ Y} ⊇
⊇ {a ∈ D G◦F | G ( F ( a )) ⊆ Y} = ( G ⊙ F ) - 1 ( Y ).
GveroF
( G ◦ F ) - 1 ( Y ) ⊇ F - 1 ( G - 1 ( Y )).
( G ◦ F ) - 1 ( Y ) = ( G ⊙ F ) - 1 ( Y ) = F - 1 ( G - 1 ( Y )).
F ( - 1) ⊙ G ( - 1) ⊈ ( G ⊙ F ) ( - 1) .
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
( G ⊙ D ) ( - 1) ⊈ F ( - 1) ⊙ G ( - 1) .
A fordított irányú tartalmazás azonban ilyenkor sem áll fenn (ld. 15.2. ábra).
17. Nem igaz. Tekintsük például a 15.3. ábrát, és legyen H = {1, 2}. Ekkor ugya-
nis:
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:
-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=∅.
d) Definition is true.
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
232 SOLUTIONS 15
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.
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
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
F G G
26. R|π = {(1, 1), (2, 2)} ∪ {(2k , 2l) | k, l ∈ N és l < k},
R|π = R|π = idN\⌈π⌉.
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⌉.
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
Tehát DR|P q
= N \ ⌈Pq⌉.
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.
R
to specify a relationship, it always includes the direct form
subset.
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.
α = < (1 , 1) , (1 , 2) , (1 , 3) > .
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
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
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.
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
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
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
15.3. Specification
First =⇒
P ( S ) = { (2 , 1) , (2 , 4) , (4 , 1) , (4 , 2) , (4 , 4) , (5 , 4)F }( S, R ) ⌉ = ∅ .
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
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
240 SOLUTIONS 15
⋁ ⋁
i∈I lf ( S, Q i ) ⇒lf ( S, i∈I Q i ).
n
( ∃n ∈ N: lf ( S, Q )) ⇍ lf ( S, ( ∃ n ∈ N: Q )).
n n
= {a ∈ D p ( S ) ∩D P ( S ) | P ( S 1 ) ( in ) ∪p ( S 2 ) ( in ) ⊆⌈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
∀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
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
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
2 two 2 two 2
F (( the , b )) = { ( the , in ) , ( the , -a ) } ⊈ { ( the , in ) } = F (( the , b )),
1 2
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.)
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
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
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
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:
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)
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} )
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 ))
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 .
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 )))
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
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 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 ))
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}) .> )
'
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}). > )
** '
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
B
to order a finite sequence of k. and ( k + 1) . member is the same,
so it can not be reduced.
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
instead of ⊆ .
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.
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
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) }
p ( DO ) = { (3 , 6) , (5 , 5) , (6 , 6) } .
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. . . .
At that time:
254 SOLUTIONS 15
D p ( S ) = D p ( S2 ) ⊙ p ( S 1 ) = p ( S 1 ) - 1 ( D p2 )( )S = ⌈lf ( S 1 , P ( D p ( S 2 ) )) ⌉ .
= {a ∈ D p ( S ) ( p ( S 1 ) ( a ) ⊆ D p ( S ) and p ( S 2 ) ( p ( S 1 ) ( a )) ⊆⌈R ) ⌉} .
1 2
⌈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
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
⋃
⌈Π ⌉ ∩ D p k( )S) = { 1 , 2 } .
Then D p ( IF ) = { 2 } , on the other( hand
k
k=1
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
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
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 , ... > ) }
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
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
1
1• • •1
2• • •2
2
F =p(S ) F =p(S )
1 1 2 2
THE THE THE
15:10. figure. counterexample
(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
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
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
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
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
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
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
⋃
(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
⋃
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 ⌈π
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.
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
1 2
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
(1) D ⊆ D p ( S 0 ) ,
(2) ∀a ∈ D : p ( S ), ( the ) ⊆ M ( to ).
F
D 0
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
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
262 SOLUTIONS 15
p ( DO ) = ∅ ⊉ id = p ( S ).
A
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:
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 } = ∅ .
y≥ 1 y=0
x:=x-1
SKIP
y:=y-1
π
y≥ 1 y=0
x:=x-1
SKIP
y:=y-1
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
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.
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
15.8. Type
First
Let T = ( H, I , F) where
s s
H = [0 .. 99999],
I = Of course ,
s
F = {F , F } .
k e
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
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
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 .
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:
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
270 SOLUTIONS 15
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
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
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
( )
⋁
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
( )
⋁
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
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
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
• 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
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
k, r : = 1 , x
k=n
2 · k≤n
k, r : = 2 · k, r · r k, r : = k + 1 , r · x
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
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 ?
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
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
'
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.
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
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
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.
Σ
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 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
''
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 = 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
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
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
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
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
(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 ]
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
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
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
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 and +1 = x ∧ y = x and +1 .
h h
j j
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
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
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
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.
Σ Σ Σ
( 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 ∧
Σ Σ
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.
( 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
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.
g ( x ⊕ y, k + 1) = 10 k +1 · χ ( c ) + g ( z, k + 1) ∧ t = t )
0
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
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.
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:
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.
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
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:
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
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
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 )
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
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
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
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
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 )
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
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
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
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
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
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 )
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)
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
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
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
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
Σ
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))
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: -
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
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
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
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
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
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
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
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
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
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
{ {
f ( {e} ): =
∅, if eo = 'mexikó';
f ( e ): =
∅, has ev = 'red';
1 {E}, if eo = 'mexikó' . 2 {E}, has ev = 'red' .
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 ∧
' '
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 ))
344 SOLUTIONS 15
z : = <>
two, y : finop
k : = x.lob - 1
two ≥ 0 ∨ k = x.hib
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
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
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
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
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
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
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 )
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
The solving propagram is the substitution value of the function with the recursive formula
on the basis of:
y, l : = <> , false
x.dom = 0
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
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
open ( y )
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
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
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
open ( y )
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
'' '
Q '' : ( t = t ' )
R :(z=t )
open ( t )
st, dt, t : read
z : = <>
st = norm
z : hiext ( dt )
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
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 )
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
f ( i + 1) =
{
- 1 , if y i +1 .tipus = exclude ;
e ( y and +1 .tipus ) =
1, if y i +1 .typus = deposit .
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
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
open ( y )
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 )
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
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
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
\ ( 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
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
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 )
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
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
index
INDEX 361
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
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
file:///D:/Dropbox/PC/PollenaiF_PRO/IPCV/Semester%201%20PPCU/Programming%20Methodology/konyv/4a1e6f44-bf35-11e8-b59b-0cc47a79… 311/311