• Keine Ergebnisse gefunden

6.3 Hoare-Kalkül Beweise 7 Punkte

N/A
N/A
Protected

Academic year: 2022

Aktie "6.3 Hoare-Kalkül Beweise 7 Punkte"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Serge Autexier Christoph Lüth Korrekte Software: Grundlagen und Methoden SoSe 2016

6. Übungsblatt

Ausgabe: 26.05.16 Abgabe: 06.06.16

6.1 Zustände 6 Punkte

Wir betrachten das Programm aus Abbildung 1. Geben Sie jeweils in der Notation aus der Vorlesung auf Folie 11 die Zustände an den Positionen 1,2, 3 und 5 an.

6.2 Operationale Semantik 7 Punkte

Geben Sie die operationale des Teilprogramms zwischen Position 3 und 4 unter Verwendung des folgenden Zustands

buch . c h a p t e r s [ 0 ] . s t a r t p a g e → 1 buch . c h a p t e r s [ 0 ] . endpage → 2 buch . c h a p t e r s [ 1 ] . s t a r t p a g e → 3 buch . c h a p t e r s [ 1 ] . endpage → 4

buch . c h a p t e r s [ 2 ] . s t a r t p a g e → 5 buch . c h a p t e r s [ 2 ] . endpage → 6 buch . c h a p t e r s [ 3 ] . s t a r t p a g e → 7 buch . c h a p t e r s [ 3 ] . endpage → 8

6.3 Hoare-Kalkül Beweise 7 Punkte

1. Beweisen Sie die partielle Korrektheit im Hoare-Kalkül von /∗∗ { buch . pages = 0 and

buch . c h a p t e r s [ 0 ] . s t a r t p a g e = 1 and buch . c h a p t e r s [ 0 ] . endpage = 5 and buch . c h a p t e r s [ 1 ] . s t a r t p a g e = 6 and buch . c h a p t e r s [ 1 ] . endpage =10 } ∗/

i n t l e n g t h = 0 ; i n t i = 1 ;

l e n g t h = l e n g t h + ( buch . c h a p t e r s [ i ] . endpage − buch . c h a p t e r s [ i ] . s t a r t p a g e ) + 1 ; i = 0 ;

l e n g t h = l e n g t h + ( buch . c h a p t e r s [ i ] . endpage − buch . c h a p t e r s [ i ] . s t a r t p a g e ) + 1 ; buch . pages = l e n g t h ;

/∗∗ { buch . c h a p t e r s [ 0 ] . s t a r t p a g e = 1 and buch . c h a p t e r s [ 0 ] . endpage = 5 and buch . c h a p t e r s [ 1 ] . s t a r t p a g e = 6 and buch . c h a p t e r s [ 1 ] . endpage =10 and buch . pages = 10 } ∗/

Verwenden Sie dabei die in der zweiten Vorlesung eingeführt Notation vollständig annotierter Program- me.

2. Wie sähe der Beweis aus für /∗∗ { buch . pages = 0 and

buch . c h a p t e r s [ 0 ] . s t a r t p a g e = n1 and buch . c h a p t e r s [ 0 ] . endpage = n2 and buch . c h a p t e r s [ 1 ] . s t a r t p a g e = n3 and buch . c h a p t e r s [ 1 ] . endpage = n4 } ∗/

i n t l e n g t h = 0 ; i n t i = 1 ;

l e n g t h = l e n g t h + ( buch . c h a p t e r s [ i ] . endpage − buch . c h a p t e r s [ i ] . s t a r t p a g e ) + 1 ; i = 0 ;

l e n g t h = l e n g t h + ( buch . c h a p t e r s [ i ] . endpage − buch . c h a p t e r s [ i ] . s t a r t p a g e ) + 1 ; buch . pages = l e n g t h ;

/∗∗ { buch . c h a p t e r s [ 0 ] . s t a r t p a g e = n1 and buch . c h a p t e r s [ 0 ] . endpage = n2 and buch . c h a p t e r s [ 1 ] . s t a r t p a g e = n3 and buch . c h a p t e r s [ 1 ] . endpage = n4 and buch . pages = ( n2−n1 + 1 ) + ( n4−n3 +1) } ∗/

1

(2)

09:49:19 2. Juni 2016 s t r u c t c h a p t e r {

char t i t l e [ 2 0 ] ; i n t s t a r t p a g e ; i n t endpage ; } ;

// Position 1

s t r u c t c h a p t e r c h a p t e r 1 = { {’A ’, ’ n ’, ’ f ’, ’ a ’, ’ n ’, ’ g ’, ’ \0 ’} , 1 , 9 } ; s t r u c t c h a p t e r c h a p t e r 2 = { {’ T ’, ’ e ’, ’ i ’, ’ l ’, ’ ’, ’ 1 ’, ’ \0 ’} , 1 0 , 1 9 } ; s t r u c t c h a p t e r c h a p t e r 3 = { {’ T ’, ’ e ’, ’ i ’, ’ l ’, ’ ’, ’ 2 ’, ’ \0 ’} , 2 0 , 2 9 } ; s t r u c t c h a p t e r c h a p t e r 4 = { {’ E ’, ’ n ’, ’ d ’, ’ e ’, ’ \0 ’} , 3 0 , 3 5 } ;

// Position 2

s t r u c t book { char t i t l e [ 2 0 ] ; i n t pages ;

s t r u c t c h a p t e r c h a p t e r s [ 4 ] ;

} buch = { {’D ’, ’ a ’, ’ s ’, ’ ’, ’ B ’, ’ u ’, ’ c ’, ’ h ’, ’ \0 ’} , 0 ,

{ chapter1 , chapter2 , chapter3 , c h a p t e r 4 } } ; // Position 3

i n t l e n g t h = 0 ; i n t i = 4 ; while ( i ) {

i = i − 1 ;

l e n g t h = l e n g t h + ( buch . c h a p t e r s [ i ] . endpage − buch . c h a p t e r s [ i ] . s t a r t p a g e ) + 1 ; } ;

// Position 4

buch . pages = l e n g t h ; // Position 5

Abbildung 1: Beispielprogramm

Änderungen:

• 26.05.16 Initiale Version.

• 26.05.16 Doppelte Deklaration von i in Aufgabe 6.3 (2.) entfernt.

• 30.05.16 Anpassung der Bedingungen an geänderte Repräsentation ohne expliziten Zustand.

2

Referenzen

ÄHNLICHE DOKUMENTE

Serge Autexier Christoph Lüth Korrekte Software: Grundlagen und Methoden SoSe

Korrekte Software: Grundlagen und Methoden Vorlesung 10 vom 12.06.18: Vorwärts mit Floyd und Hoare.. Serge Autexier,

Partial cor- rectness means that if the programs starts in a state where the precondition P holds, and it terminates, then it does so in a state which satisfies the postcondition

Serge Autexier Christoph Lüth Korrekte Software: Grundlagen und Methoden SoSe

Serge Autexier Christoph Lüth Korrekte Software: Grundlagen und Methoden SoSe

I Axiomatische Semantik beschreibt die Bedeutung eines Programmes durch Beweisregeln, mit welchem sich gültige Eigenschaften herleiten lassen.. Das prominenteste Beispiel hierzu ist

I Wenn wir eine gültige Zusicherung nicht herleiten können, liegt das nur daran, dass wir eine Beweisverpflichtung nicht beweisen können. I Logik erster Stufe ist unvollständig,

I Wir annotieren daher die Invarianten an Schleifen, und können dann die schwächste Vorbedingung und Verifikationsbedingungen.