1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
In the original code's prescreen handling the following condition is used:
if (Nscr > 0 && (naturalDeathAge < scr[0].age || (tumor.isTumor()
&& tumor.selfDetectAge() < scr[0].age)))
Following this a lot of code is provided to be executed when the condition is
true. It's more elegant to put this code in a function, returning when the
condition isn't true. So:
if (
not (Nscr > 0 && (naturalDeathAge < scr[0].age || (tumor.isTumor()
&& tumor.selfDetectAge() < scr[0].age)))
)
return;
But this isn't too readabile. However, the condition can be rewritten using De
Morgan's rules. First the condition is simplified by using symbols:
not (Nscr > 0 && (naturalDeathAge < scr[0].age || (tumor.isTumor()
--> not ( A and ( B or ( C
&& tumor.selfDetectAge() < scr[0].age)))
--> and D )))
And thus:
not ( A and ( B or ( C and D ) ) )
Now distribute the 'not' using De Morgan:
not A or not ( B or ( C and D ) )
The 2nd 'not' is next:
not A or not B and not( C and D )
And maybe also the 3rd 'not':
not A or not B and (not C or not D )
Now substitute the original expressions:
// if (not A) ->
if (Nscr == 0) // (Nscr is never negative)
return;
// if (not B and (not C or not D )) ->
if (
naturalDeathAge >= scr[0].age // not B
and
(not tumor.isTumor() or tumor.selfDetectAge() >= scr[0].age)
// not C or not D
)
return;
|