Главная » Просмотр файлов » 3. Verification of sequential and concurrent programs. Apt_ Olderog (3rd edition) (2010)

3. Verification of sequential and concurrent programs. Apt_ Olderog (3rd edition) (2010) (811405), страница 33

Файл №811405 3. Verification of sequential and concurrent programs. Apt_ Olderog (3rd edition) (2010) (3. Verification of sequential and concurrent programs. Apt_ Olderog (3rd edition) (2010).pdf) 33 страница3. Verification of sequential and concurrent programs. Apt_ Olderog (3rd edition) (2010) (811405) страница 332020-08-25СтудИзба
Просмтор этого файла доступен только зарегистрированным пользователям. Но у нас супер быстрая регистрация: достаточно только электронной почты!

Текст из файла (страница 33)

We remark that le ≤ n andm ≤ ri need not hold upon termination. Property P2 implies that the callP artition(n, k) permutes the array section a[m : n] and leaves other elementsof a intact, but actually is a stronger statement involving an interval [x′ : y ′ ]that includes [m : n], so that we can carry out the reasoning about therecursive calls of Quicksort.

Finally, property P3 captures the main effect ofthe call P artition(n, k): the elements of the section a[m : n] are rearrangedinto three parts, those smaller than pi (namely a[m : ri]), those equal topi (namely a[ri + 1 : le − 1]), and those larger than pi (namely a[le : n]).Property PT4 is needed in the termination proof of the Quicksort procedure:it implies that the subsections a[m : ri] and a[le : n] are strictly smaller thanthe section a[m : n].The correctness formulas P1–P3 and PT4 for the procedure callP artition(m, n) immediately follow from the properties P1–P4 and T ofthe while program P ART studied in Section 3.9 (see Exercise 5.8).Auxiliary Proof: Permutation PropertyIn the remainder of this section we use the following abbreviation:5.4 Case Study: Quicksort175J ≡ m = x ∧ n = y.We first extend the permutation property P2 to the procedure Quicksort:Q2{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ x ∧ y ≤ y ′ }Quicksort(x, y){perm(a, a0 , [x′ : y ′ ])}Until further notice the provability symbol ⊢ refers to the proof system PWaugmented with the the block rule, the instantiation rule and the auxiliaryrules A3–A7.The appropriate claim needed for the application of the recursion III ruleis:Claim 1.P1, P2, Q2 ⊢ {perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ x < y ≤ y ′ }begin local m, n := x, y; SQ end{perm(a, a0 , [x′ : y ′ ])}.Proof.

In Figure 5.3 a proof outline is given that uses as assumptions thecorrectness formulas P1, P2, and Q2. More specifically, the used correctnessformula about the call of P artition is derived from P1 and P2 by the conjunction rule. In turn, the correctness formulas about the recursive calls ofQuicksort are derived from Q2 by an application of the instantiation ruleand the invariance rule. This concludes the proof of Claim 1.⊓⊔We can now derive Q2 by the recursion rule.

In summary, we have provedP1, P2 ⊢ Q2.Auxiliary Proof: Sorting PropertyWe can now verify that the call Quicksort(x, y) sorts the array sectiona[x : y], soQ3{true} Quicksort(x, y) {sorted(a[x : y])}.The appropriate claim needed for the application of the recursion III rule is:1765 Recursive Programs with Parameters{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ x ∧ y ≤ y ′ }begin local{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ x ∧ y ≤ y ′ }m, n := x, y;{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ x ∧ y ≤ y ′ ∧ J}{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ m ∧ n ≤ y ′ }if m < n then{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ m ∧ n ≤ y ′ }P artition(m, n);{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ m ∧ n ≤ y ′ ∧ ri ≤ n ∧ m ≤ le}begin local{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ m ∧ n ≤ y ′ ∧ ri ≤ n ∧ m ≤ le}v, w := ri, le;{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ m ∧ n ≤ y ′ ∧ v ≤ n ∧ m ≤ w}{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ m ∧ v ≤ y ′ ∧ x′ ≤ w ∧ n ≤ y ′ }Quicksort(m, v);{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ w ∧ n ≤ y ′ }Quicksort(w, n){perm(a, a0 , [x′ : y ′ ])}end{perm(a, a0 , [x′ : y ′ ])}fi{perm(a, a0 , [x′ : y ′ ])}end{perm(a, a0 , [x′ : y ′ ])}Fig.

5.3 Proof outline showing permutation property Q2.Claim 2.P3, Q2, Q3 ⊢ {true}begin local m, n := x, y; SQ end{sorted(a[x : y])}.Proof. In Figure 5.4 a proof outline is given that uses as assumptions thecorrectness formulas P3, Q2, and Q3. In the following we justify the correctness formulas about P artition and the recursive calls of Quicksort usedin this proof outline. In the postcondition of P artition we use the followingabbreviation:K≡ v<w∧( ∀ i ∈ [m : v] : a[i] ≤ pi) ∧( ∀ i ∈ [v + 1 : w − 1] : a[i] = pi) ∧( ∀ i ∈ [w : n] : pi ≤ a[i]).5.4 Case Study: Quicksort177{true}begin local{true}m, n := x, y;{J}if m < n then{J ∧ m < n}P artition(m, n);{J ∧ K[v, w := ri, le]}begin local{J ∧ K[v, w := ri, le]}v, w := ri, le;{J ∧ K}Quicksort(m, v);{sorted(a[m : v]) ∧ J ∧ K}Quicksort(w, n){sorted(a[m : v] ∧ sorted(a[w : n] ∧ J ∧ K}{sorted(a[x : v] ∧ sorted(a[w : y] ∧ K[m, n := x, y]}{sorted(a[x : y])}end{sorted(a[x : y])}fi{sorted(a[x : y])}end{sorted(a[x : y])}Fig.

5.4 Proof outline showing sorting property Q3.Observe that the correctness formula{J} P artition(m, n) {J ∧ K[v, w := ri, le]}is derived from P3 by the invariance rule. Next we verify the correctnessformulas{J ∧ K} Quicksort(m, v) {sorted(a[m : v]) ∧ J ∧ K},and{sorted(a[m : v]) ∧ J ∧ K}Quicksort(w, n){sorted(a[m : v] ∧ sorted(a[w : n] ∧ J ∧ K}.about the recursive calls of Quicksort.Proof of (5.10). By applying the instantiation rule to Q3, we obtain(5.10)(5.11)178A15 Recursive Programs with Parameters{true} Quicksort(m, v) {sorted(a[m : v])}.Moreover, by the invariance axiom, we haveA2{J} Quicksort(m, v) {J}.By applying the instantiation rule to Q2, we then obtain{perm(a, a0 , [x′ : y ′ ]) ∧ x′ ≤ m ∧ v ≤ y ′ }Quicksort(m, v){perm(a, a0 , [x′ : y ′ ])}.Applying next the substitution rule with the substitution [x′ , y ′ := m, v]yields{perm(a, a0 , [m : v]) ∧ m ≤ m ∧ v ≤ v}Quicksort(m, v){perm(a, a0 , [m : v])}.So by a trivial application of the consequence rule, we obtain{a = a0 } Quicksort(m, v) {perm(a, a0 , [m : v])}.We then obtain by an application of the invariance rule{a = a0 ∧ K[a := a0 ]} Quicksort(m, v) {perm(a, a0 , [m : v]) ∧ K[a := a0 ]}.Note now the following implications:K → ∃a0 : (a = a0 ∧ K[a := a0 ]),perm(a, a0 , [m : v]) ∧ K[a := a0 ] → K.So we concludeA3{K} Quicksort(m, v) {K}by the ∃-introduction rule and the consequence rule.

Combining the correctness formulas A1–A3 by the conjunction rule we get (5.10).Proof of (5.11). In a similar way as above, we can prove the correctnessformula{a = a0 } Quicksort(w, n) {perm(a, a0 , [w : n])}.By an application of the invariance rule we obtain{a = a0 ∧ sorted(a0 [m : v]) ∧ v < w}Quicksort(w, n){perm(a, a0 , [w : n]) ∧ sorted(a0 [m : v]) ∧ v < w}.Note now the following implications:5.4 Case Study: Quicksort179v < w ∧ sorted(a[m : v]) → ∃a0 : (a = a0 ∧ sorted(a0 [m : v]) ∧ v < w),(perm(a, a0 , [w : n]) ∧ sorted(a0 [m : v]) ∧ v < w) → sorted(a[m : v]).So we concludeB0{v < w ∧ sorted(a[m : v])} Quicksort(w, n) {sorted(a[m : v])}by the ∃-introduction rule and the consequence rule.

Further, by applyingthe instantiation rule to Q3 we obtainB1{true} Quicksort(w, n) {sorted(a[w : n])}.Next, by the invariance axiom we obtainB2{J} Quicksort(w, m) {J}.Further, using the implicationsK → ∃a0 : (a = a0 ∧ K[a := a0 ]),perm(a, a0 , [w : n]) ∧ K[a := a0 ] → K,we can derive from Q2, in a similar manner as in the proof of A3,B3{K} Quicksort(w, n) {K}.Note that B1–B3 correspond to the properties A1–A3 of the procedure callQuicksort(m, v). Combining the correctness formulas B0–B3 by the conjunction rule and observing that K → v < w holds, we get (5.11).The final application of the consequence rule in the proof outline given inFigure 5.4 is justified by the following crucial implication:sorted(a[x : v]) ∧ sorted(a[w : y]) ∧ K[m, n := x, y] →sorted(a[x : y]).Also note that J ∧ m ≥ n → sorted(a[x : y]), so the implicit else branch isproperly taken care of.

This concludes the proof of Claim 2.⊓⊔We can now derive Q3 by the recursion rule. In summary, we have provedP3, Q2 ⊢ Q3.The proof of partial correctness of Quicksort is now immediate: it sufficesto combine Q2 and Q3 by the conjunction rule. Then after applying thesubstitution rule with the substitution [x′ , y ′ := x, y] and the consequencerule we obtain Q1, or more preciselyP1, P2, P3 ⊢ Q1.1805 Recursive Programs with ParametersTotal CorrectnessTo prove termination, by the decomposition rule discussed in Section 3.3 itsuffices to establishQ4{true} Quicksort(x, y) {true}in the sense of total correctness.

In the proof we rely on the property PT4of P artition:{m < n} P artition(m, n) {m < le ∧ ri < n}.The provability symbol ⊢ refers below to the proof system TW augmentedwith the block rule, the instantiation rule and the auxiliary rules A3–A7. Forthe termination proof of the recursive procedure call Quicksort(x, y) we uset ≡ max(y − x, 0)as the bound function. Since t ≥ 0 holds, the appropriate claim needed forthe application of the recursion IV rule is:Claim 3.PT4, {t < z} Quicksort(x, y) {true} ⊢{t = z} begin local m, n := x, y; SQ end {true}.Proof.In Figure 5.5 a proof outline for total correctness isgiven that uses as assumptions the correctness formulas PT4 and{t < z} Quicksort(x, y) {true}.

In the following we justify the correctnessformulas about P artition and the recursive calls of Quicksort used in thisproof outline. Since m, n, z 6∈ change(D), we deduce from PT4 using theinvariance rule the correctness formula{n − m = z ∧ m < n}P artition(m, n){n − m = z ∧ m < n ∧ ri − m < n − m ∧ n − le < n − m}.(5.12)Consider now the assumption{t < z} Quicksort(x, y) {true}.Since n, w, z 6∈ change(D), the instantiation rule and the invariance rule yield{max(v − m, 0) < z ∧ max(n − w, 0) < z}Quicksort(m, v){max(n − w, 0) < z}and{max(n − w, 0) < z} Quicksort(w, n) {true}.5.4 Case Study: Quicksort181{t = z}begin local{max(y − x, 0) = z}m, n := x, y;{max(n − m, 0) = z}if n < k then{max(n − m, 0) = z ∧ m < n}{n − m = z ∧ m < n}P artition(m, n);{n − m = z ∧ m < n ∧ ri − m < n − m ∧ n − le < n − m}begin local{n − m = z ∧ m < n ∧ ri − m < n − m ∧ n − le < n − m}v, w := ri, le;{n − m = z ∧ m < n ∧ v − m < n − m ∧ n − w < n − m}{max(v − m, 0) < z ∧ max(n − w, 0) < z}Quicksort(m, v);{max(n − w, 0) < z}Quicksort(w, n){true}end{true}fi{true}end{true}Fig.

Характеристики

Список файлов книги

Свежие статьи
Популярно сейчас
Почему делать на заказ в разы дороже, чем купить готовую учебную работу на СтудИзбе? Наши учебные работы продаются каждый год, тогда как большинство заказов выполняются с нуля. Найдите подходящий учебный материал на СтудИзбе!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
6417
Авторов
на СтудИзбе
307
Средний доход
с одного платного файла
Обучение Подробнее