0

I am trying to re-write the following pseudocode as the simplest if-else, but am struggling to understand the logic fully.

if (a <= b) then  // Here, a <= b.
  if (y > b) then P  // Here, (a <= b) & (y > b).  
  else if (x < a) then P  // Here, (a <= b) & !(y > b) & (x < a).
    else if ((y >= a) & (x <= b)) then Q else R  

My interpretations of the pseudocode so far are written in comments above. I think that I have correctly understood the logic of the first three lines of pseudocode.

However, I am not sure how to interpret the logic of the fourth and last line of the pseudocode. I would like help to understand the state(s) of the four variables at the fourth line, as well as how to re-write the pseudocode as the simplest if-else.

1 Answers1

1

How to get to the last line:

a <= b has to be true

y > b has to be false

x < a has to be false

so the last line would be:

(a <= b) & !(y > b) & !(x < a) & (y >= a) & (x <= b)

this leads to the following results:

a <= b & a <= x & a <= y -> a has to be the smallest value

b >= a & b >= y & b >= x -> b has to be the greatest value

y <= b & y >= a -> y has to be in between of a and b

x >= a & x <= b -> x has to be in between of a and b

which leads to:

if((x >= a & x <= b) & (y >= a & y <= b))

(but this only works if you just want to get to the last line)

Jibbow
  • 757
  • 1
  • 8
  • 17