0

I basically have this boolean algebra expression:

((xDir === 1 || xDir === -1) &&
 (yDir === 1 || yDir === -1))

What is the "inverse" of this? I tried using DeMorgan's thereoms but I don't think I did it properly. I ended up with something like:

(!(xDir === 1 && xDir === -1) &&
 !(yDir === 1 && yDir === -1))

What is the inverse equation?

pizzae
  • 105

1 Answers1

0

Using the programmatic notation,

!((a || b) && (c || d)) -> !(a || b) || !(c || d) -> (!a && !b) || (!c && !d)

There is no real benefit of effecting this transform as the final expression is more complex to evaluate and less readable.

  • One could use the fact that xDir === 1 || xDir === -1 is equivalent to xDir^2 === 1, and similarly for yDir, to express the middle statement as !(xDir^2 === 1) || !(yDir^2 === 1). This is relatively compact. (But then, one could also express the initial statement as just (xDir^2-1)*(yDir^2-1)===0.) – Semiclassical Jul 21 '17 at 13:59
  • @Semiclassical: the question is not about efficient implementation (for which more information should be requested),it's about application of the De Morgran's laws. –  Jul 21 '17 at 14:02