Automated Formal Static Analysis and Retrieval of Source Code - JKU
Automated Formal Static Analysis and Retrieval of Source Code - JKU
Automated Formal Static Analysis and Retrieval of Source Code - JKU
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
2.4. IMPLEMENTATION AND EXAMPLES 23<br />
(<br />
∀<br />
a,b<br />
a≥0,b≥0<br />
⎧<br />
∧<br />
⎪⎨<br />
⎪⎩<br />
a = 0 ⇒ π[a, b]<br />
(a ≠ 0 ∧ b ≠ 0 ∧ a > b ∧ π[a − b, b]) ⇒ π[a, b]<br />
(a ≠ 0 ∧ b ≠ 0 ∧ a ≠> b ∧ π[a, b − a]) ⇒ π[a, b]<br />
(a ≠ 0 ∧ b = 0) ⇒ π[a, b]<br />
)<br />
=⇒<br />
(<br />
∀<br />
a,b<br />
a≥0,b≥0<br />
)<br />
π[a, b]<br />
Description. The previously verification conditions were generated by analyzing each path <strong>of</strong><br />
the program <strong>and</strong> applying the notions <strong>of</strong> program syntax, semantics, partial correctness <strong>and</strong> termination<br />
introduced previously.<br />
Before the program starts to be analyzed, the substitution {a → a 0 , b → b 0 } <strong>and</strong> the formula<br />
representing the accumulated assumptions a 0 ≥ 0 ∧ b 0 ≥ 0 are created. After the program is<br />
completely analyzed, the input variables are universally quantified thus the reverting substitution<br />
is done.<br />
On the path 10, 1, 2, 3, 4, 11, the verification conditions were generated as follows: we add<br />
to the formula a 0 ≥ 0 ∧ b 0 ≥ 0 the conjunct a = 0, corresponding to the T rue evaluation <strong>of</strong> the<br />
If conditional. The Return statement determines the generation <strong>of</strong> the functional verification<br />
condition 2.2, where the value <strong>of</strong> y from the postcondition was replaced by the value returned by<br />
the program on this branch, namely b.<br />
On the path 10, 1, 2, 5, 6, 7, 9, 11, the assignment from the line 7 requires a term decomposition<br />
from the innermost to the outermost function symbol. The assumptions collected<br />
before the term analysis is the formula a ≥ 0 ∧ b ≥ 0 ∧ a ≠ 0 ∧ b ≠ 0. The specification<br />
<strong>of</strong> the functions composing the term GCD[a-b, b] has to be fulfilled. First the function<br />
,,-” is analyzed, generating the safety condition 2.3, insuring the respective precondition.<br />
The assumptions on this path are updated with the specification <strong>of</strong> the function ,,-”, namely<br />
a ≥ 0 ∧ b ≥ 0) ∧ a ≠ 0 ∧ b ≠ 0 ∧ a > b ∧ a ≥ b.<br />
The analysis <strong>of</strong> the function GCD is done similarly: the precondition has to hold for the<br />
arguments <strong>of</strong> the recursive call, the output value as well. The functional verification condition<br />
(2.5) is generated, where all the occurrences <strong>of</strong> the function GCD are replaced by the new constant<br />
y1.<br />
The path 10, 1, 2, 5, 8, 9, 11 is analyzed similar to the path 10, 1, 2, 5, 6, 7, 9, 11 <strong>and</strong> the path<br />
10, 1, 2, 9, 11, similar to the path 10, 1, 2, 3, 4, 11.<br />
The termination condition is obtained similarly to the verification conditions. It is an implication<br />
<strong>of</strong> two first order logical formulae (we consider that the predicate π is fixed), both universally<br />
quantified upon the input variables. The right h<strong>and</strong> side is always the predicate π with the input<br />
variables as arguments <strong>and</strong> the left h<strong>and</strong> side is a conjunction <strong>of</strong> formulae, each conjunct (having<br />
the shape <strong>of</strong> an implication) corresponding to the analysis <strong>of</strong> a single path. If on the path there<br />
exists a recursive call then the new introduced predicate symbol π occurs in the both sides <strong>of</strong> the<br />
implication within the conjunct (the second <strong>and</strong> the third conjunct corresponding to the second<br />
<strong>and</strong> the third path <strong>of</strong> the program). The π occurring on the left h<strong>and</strong> side has the arguments <strong>of</strong> the<br />
recursive call on the respective branch. If there is not a recursive call then the π occurs only on<br />
the right h<strong>and</strong> side (the first <strong>and</strong> the forth conjunct).