/
is a theorem;  this is called refinement.  Since    is implied by   , is a theorem;  this is called refinement.  Since    is implied by   ,

is a theorem; this is called refinement. Since is implied by , - PDF document

lindy-dunigan
lindy-dunigan . @lindy-dunigan
Follow
392 views
Uploaded On 2016-07-12

is a theorem; this is called refinement. Since is implied by , - PPT Presentation

We cannot complete that refinement due to a little problem in order to get the new values and we need not only the values of and just produced by the recursive call which was not sav ID: 401348

cannot complete that refinement

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "is a theorem; this is called refinement..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

is a theorem; this is called refinement. Since is implied by , all computer also satisfies . We might refine in steps, finding specifications , , ... such that 2 Notation 0 1 2 ( )booleans, numbers, variables, bracketed expressions /multiplication, division4.+ – 5.,..from (including) to (excluding)6.= E.6; :comparisons, inclusion11.:= · · · ;quantifiers, sequential compositionExponentiation serves to bracket all operations within the exponent. The infix operators / – associate from left to right. The infix operators + ; are associative (they associate in both directions). On levels 6, 10, and 13 the operators are continuing; for neither associates to the left nor associates to the right, but means . On any one of these levels, a mixture of continuing operators can be used. means . The operators are identical to = except for precedence. and ) for the initial and ... specifies that is assigned the value and that all other ... for in ) (substitute for in , ... are the initial values, = , ... are the intermediate values, and = , ... are the final values of the variables. There are many laws that can be proven from these definitions; one of the most useful is the Substitution Law: (for substitute in is a specification not employing the assignment or sequential composition operators. To account for execution time, we use a time variable; we use for the time at for the time at which execution ends. In the case of 1Eric Hehner We cannot complete that refinement due to a little problem: in order to get the new values and , we need not only the values of and just produced by the recursive call, , which was not saved. So we revise: + + – 1; + + + – – – + 1) , the recursive call promises to leave it alone, and then we increase it back to its original value (which fulfills the promise). With time, + + – 1; + + + – – – + 1) else {n = n–1; P( ); n = n+1; y = y+n+n–1; x = x+y+y+y–n–n–n+1;}}Here is linear solution without general recursion. Let be a natural variable. Let = 3 + 3 + 1 = 6 + 6 = ( = 3 + 3 + 1 = 6 + 6 = (4 Exact Precondition is refined by specification if is a theorem. That . For any two specifications and , if we quantify over only , we obtain the exact precondition, or necessary and sufficient to be refined by . For +1One-Point Law� 4+1 will also satisfy �5 if and only if it �4 . (If instead we quantify over the input variables , we obtain the exact 3Eric Hehner 6 Probabilistic Specifications be an implementable deterministic specification. Let be the distribution . Then the distribution describing the final state iswhich is a generalization of the formula for average. Here is an example in two integer and . Suppose starts with value 7 one-third of the time, and starts with value 8 two-thirds of the time. Then the distribution of is 1/3 + ( 2/3 has value 7 is therefore 1/3 + (7=8) 2/3 1/3 + 2/3=1 1/3 + 0 2/3=1/3 has value 8 is 2/3 , and the probability that has value 9 is 0 . Let be the preceding distribution of . Suppose that also starts with value 7 one-third of the time, and starts with value 8 two-thirds of the time, . Then its distribution is given by = (=7) / 3 + ( 2/3 . Let be=7) / 3 + ( 2/3)=7) / 3 + ( 2/3) 5/9 + ( 4/9=0 five-ninths of the time, and =1 four-ninths of the time.A probability distribution such as ( 5/9 + ( 4/9 describes what to see. A boolean specification is just a special case of probabilistic specification. We now specifications as follows. If is a probability, and and are distributions of final + (1– for in ) (substitute for in are distributions of final states. For example, in one integer variable , suppose we start by assigning 0 with probability 1/3 or 1 with probability 2/3 ; that's 1/3 =0 then we add 2 with probability 1/2 or 3 with probability 1/2 , otherwise we add 4 with probability 1/4 or 5 with probability 3/4 ; that's 1/2 1/4 gives us conditional probability. Our calculation5Eric Hehner 3replace assignments: 0,..2)/2; (+3)/3sum: 0,..3)/3 + 1/2 =0) / 6 + (=2) / 3 + ( produces uniformly distributed natural numbers, it can be transformed into many different distributions. We just saw that 2 + 3 has value with distribution (=3) / 6 + (=2) / 3 . As another example, 8 with distribution = ( 5/8 is three-eighths of the time, and five-eighths of the time.8 BlackjackThis example is a simplified version of the card game known as blackjack. You are dealt a card from a deck; its value is in the range 1 through 13 inclusive. You may stop with just one card, or have a second card if you want. Your object is to get a total as near as possible to 14 , but not over 14 . Your strategy is to take a second card if the first is under 7 . Assuming each card value has equal probability (actually, the second card drawn has a 13) + 1; + ( 13) + 1 : 0,..13 for the two uses of , each with probability 1/13 . The program becomes = = has distribution = = 1/13 1/13 13) + 1; + ( 13) + 1 replace ; and (( if we use the “under 7 ” strategy. We can similarly find if we use the “under 8 ” strategy, or any other strategy. But which strategy is best? To compare two strategies, we play both of them at once. Player will ” and player will play “under 7Eric Hehner +1; ( (5/6) 1/6)) 1/6 1/6sum) + 30+1; ( (5/6) 1/6)) 1/6 1/6substitution) + 30 (5/6) 1/6) 1/6 1/6arithmetic 1/6 + ( (5/6) 1/6 (5/6) 1/6 and is as follows. Starting with the 6) + 1;replace +1; ( (5/6) 1/6)Substitution Law)/6; ( (5/6) / 6and simplify (5/6) / 6and replace (( (5/6) / 6)sum (6 ) + 30 (5/6) / 6)combine (5/6) 1/6 (5/6) 1/6 10 NondeterminismAccording to some authors, nondeterminism comes in several varieties: angelic, demonic, 2; . If is angelic nondeterminism, it chooses between its := 0 and := 1 in such a way that the desired result is always achieved. is demonic nondeterminism, it chooses between its operands in such a way that the desired result is never achieved. Both angelic and demonic nondeterminism require when choosing between assignments to . past) state. It achieves half the time. Now consider . If is angelically prescient, will be chosen to match the future , always achieving . If is demonically prescient, will be chosen to , never achieving . If is not prescient, then is In predicative programming, nondeterminism is disjunction. Angelic, demonic, , we can refine the nondeterminism angelically as , or , or obliviously as either := 0 or := 1 . In the example , we first have to replace 2 by boolean variable having probability 1/2 . Then we can refine the nondeterminism with angelic prescience as , 9Eric Hehner . All programming notations distribute over disjunction, so in any front. Before we prove that specification is refined by a program containing a nondeterministic choice, we make the following sequence of transformations. (The dots are ···········( ···········(· ( ···········(+1) . With =5 we get· ( because 1 With input distribution (=6)/2 we get· ( (( . These answers retain the nondeterminism in the form , which was not part of the question, and whose value is unknown.11 Monty Hall's Problemproblem, which was the subject of an internet discussion group; various probabilities were hypothesized and argued. We will not engage in any argument; we just calculate. The hypothesized and argued. We will not engage in any argument; we just calculate. The Monty Hall is a game show host, and in this game there are three doors. A prize is hidden behind one of the doors. The contestant chooses a door. Monty then opens one of chosen. Monty asks the contestant whether they (the contestant) would like to change their be the door where the prize is. Let be the contestant's choice. Let be the The first line (:= 2) says that the prize is placed behind one of the doors; the contestant knows nothing about the criteria used for placement of the prize, so from their point of view it is a nondeterministic choice. The second line 3 is the contestant's random choice of door. In the next line, is addition modulo 3 ; if the other two (nondeterministically); otherwise Monty must choose the one door that differs 11Eric Hehner Here is Mr.Bean's program (omitting the initialization). Variables and represent 2 (for hand), and we to express the nondeterministic choices. Due to the loop we index is easily proven. Now we need a hypothesis concerning the probability of execution times.drawer a sock of the same color as he throws away. This means that the nondeterministic just happens to have the same value as each time). that puts the wrong sock in his hand. But the mathematics says nothing about purpose or mechanism; it may be just a fantastic coincidence. In any case, we can prove that execution just happens to have the same value as mechanism or purpose, but the mathematics is silent about that. Now we can prove+1 which says that execution takes time 0 or 1 , but we cannot attach probabilities to those two possibilities. If we make no assumption at all about , leaving the nondeterministic Another way to refine the nondeterministic choice is with a probabilistic choice. If we attach probability 1/2 to each of the values of , then the distribution of execution times . To prove it, we start with the right side of the to 13Eric Hehner which does not satisfy the informally stated specification. The problem is known as convex closure, and it prevents us from formalizing the specification as a superdistribution. We partially known distribution. Let be the probability distribution of . Then what we = ((14 Conclusionprobability distributions expressed as functions. In that approach, if was a variable of , it becomes a variable of type such that 1 . All operators then need to be extended to distributions expressed as functions. Although this approach works, it was too low-level; a distribution expressed as a function tells us about the directly on programs and specifications. Without any new mechanism, we include probabilistic timing. From the distribution of execution times we can calculate the average execution time; this is often of more interest than the worst case execution time, which is notation (as is standard), and we have generalized booleans notation (as is standard), and we have generalized booleans )(if 1/3 ); there is no need to invent another. We have used the programming languages; we cope with it by replacing it with something that obeys the probability, is essential to forming a reasonable hypothesis. But probability problems are notorious for misleading even professional mathematicians; hypotheses are sometimes wrong. Sometimes the misunderstanding can be traced to a different understanding of the problem. Our first step, formalization as a program, makes one's understanding clear. After nondeterminacy. In [4], instead of calculating probabilities, they calculate a lower bound on probabilities: they find the precondition that ensures that the probability of outcome is 15Eric Hehner