Content deleted Content added
m Dating maintenance tags: {{Split}} {{Cn}} |
→Measure of a closeness to being a structured program: there we go, out with the OR and misunderstandings and in with the referenced content. Please leave a note on talk if it's still not clear |
||
Line 12:
year=1996}}</ref>
== Measure of
'''Essential complexity''' is also
McCabe's reduction process is intended to simulate the conceptual replacement of control structures (and actual statements they contain) with subroutine calls, hence the requirement for the control structures to have a single entry and a single exit point.<ref name="mccabe76"/>{{rp|317}} (Nowadays a process like this would fall under the umbrella term of [[refactoring]].) All structured programs evidently have an essential complexity of 1 as defined by McCabe because they can all be iteratively reduced to a single call to a top-level subroutine.<ref name="mccabe76"/>{{rp|318}} As McCabe explains in his paper, his essential complexity metric was designed to provide a measure of how far off this ideal (of being completely structured) a given program was.<ref name="mccabe76"/>{{rp|317}} Thus higher essential complexity numbers, which can only be obtained for non-structured programs, indicate that they are further away from the structured programming ideal.<ref name="mccabe76"/>{{rp|317}}
To avoid confusion between various notions of reducibility to structured programs, it's important to note that McCabe's paper briefly discusses and then operates in the context of a 1973 paper by [[S. Rao Kosaraju]], which gave a refinement (or alternative view) of the [[structured program theorem]]. The seminal 1966 paper of Böhm and Jacopini showed that all programs can be [re]written using only structured programming constructs, (aka the D structures: sequence, if-then-else, and while-loop), however, in transforming a random program into a structured program additional variables may need to be introduced (and used in the tests) and some code may be duplicated.<ref name="WattFindlay2004">{{cite book|author1=David Anthony Watt|author2=William Findlay|title=Programming language design concepts|year=2004|publisher=John Wiley & Sons|isbn=978-0-470-85320-7|pages=228}}</ref>
For example, the following C program fragment has an essential complexity of 1, because the inner '''if''' statement and the '''for''' can be reduced:▼
In their paper, Böhm and Jacopini conjectured, but did not prove that it was necessary to introduce such additional variables for certain kinds of non-structured programs in order to transform them into structured programs.<Ref name="K">J. Computer and System Sciences, 9, 3 (December 1974), {{doi| 10.1016/S0022-0000(74)80043-7}}</ref>{{rp|236}} An example of program (that we now know) does require such additional variables is a loop with two conditional exits inside it. In order to address the conjecture of Böhm and Jacopini, Kosaraju defined a more restrictive notion of program reduction than the Turing equivalence used by Böhm and Jacopini. Essentially, Kosaraju's notion of reduction imposes, besides the obvious requirement that the two programs must compute the same value (or not finish) given the same inputs, that the two programs must use the same primitive actions and predicates, understood as expressions used in the conditionals. Because of these restrictions, Kosaraju's reduction does not allow the introduction of additional variables; assigning to these variables would create new primitive actions and testing their values would change the predicates used in the conditionals. Using this more restrictive notion of reduction, Kosaraju proved Böhm and Jacopini's conjecture, namely that a loop with two exists cannot be transformed into a structured program ''without introducing additional variables'', but went further and proved that programs containing multi-level breaks (from loops) form an hierarchy, such that one can always find a program with multi-level breaks of depth ''n'' that cannot be reduced to a program of multi-level depth less than ''n'', again without introducing additional variables.<Ref name="K"/><Ref>For more modern treatment of the same results see: Kozen, [http://www.cs.cornell.edu/~kozen/papers/bohmjacopini.pdf The Böhm–Jacopini Theorem is False, Propositionally]</ref>
McCabe notes in his paper that in view of Kosaraju's results, he intended to find a way to capture the essential properties of non-structured programs.<ref name="mccabe76"/>{{rp|315}} He proceeds by first identifying the control flow graphs corresponding to the smallest non-structured programs, which he uses to formulate a theorem analogous to [[Kuratowski's theorem]], and thereafter introduces his notion of essential complexity in order to give a scale answer ("measure of the
structureness of a program" in his words) rather than a yes/no answer to the question of whether a program's control flow graph is structured or not.<ref name="mccabe76"/>{{rp|315}} Finally, the notion of reduction used by McCabe to shrink the CFG is not the same as Kosaraju's notion of reducing flowcharts. The reduction defined on the CFG not know or care about the program's inputs, it is simply a [[graph transformation]].<ref>McCabe footnotes the two definitions of on pages 315 and 317.</ref>
▲For example, the following C program fragment has an essential complexity of 1, because the inner '''if''' statement and the '''for''' can be reduced
<source lang="C">
for(i=0;i<3;i++) {
if(a[i] == 0) b[i] += 2;
}
</source>
The following C program fragment has an essential complexity of
<source lang="C">
▲The following C program fragment has an essential complexity of more than one. It finds the first row of z which is all zero and puts that index in i; if there is none, it puts -1 in i.
}
i = -1;
found:
</source>
The notion of CFG reducibility introduced by McCabe for defining essential complexity finds applications in compiler optimization. The areas of the CFG that cannot be reduced are now called ''improper regions''.<ref name="Muchnick1997">{{cite book|author=Steven S. Muchnick|title=Advanced Compiler Design Implementation|year=1997|publisher=Morgan Kaufmann|isbn=978-1-55860-320-2|pages=196-197}}</ref>
▲ for(i=0;i<m;i++) {
▲ for(j=0;j<n;j++) {
▲ '''goto found''';
▲ non_zero:
▲ }
▲ i = -1;
▲ found:
==See also==
|