All in all, i wanted to know if if it's possible to mathematically simplify 'if expressions' in code, by replacing every condition by a set. Here's an example :
I have two 'if expressions', let's call them S1 & S2 respectively :
S1: ((x > 0) || ((x <= 0) && (y < 100))
S2: (x > 0) || (y < 100)
Now is it correct if i suppose that (x > 0) is basically some specific set A, generated by the actual rule x>0, and since x & y belong to the same domain (of natural numbers N), proving that the S1 and S2 are equal would also prove that the 'if expressions' are equivalent ?
If yes, would this be a valid proof :
Let A, B & C be the subsets generated by the following rules (x>0), (x<=0) & (y<100) respectively, using the domain of natural numbers N. I can then express S1 and S2 based on those sets, (using '+' for unions/ors and 'x' for intersections/ands) as such :
S1: A + (B x C)
S2: A + C
Hence, if S1 = S2 :
S1 = S2 <=> A + (B x C) = A x C
<=> (A + B) x (A + C) = A + C
So if i prove that (A or B) is equal to the whole domain, then our initial assumption that S1 = S2 is correct ?
In our case :
A or B = (x > 0) or (x <= 0) = N
And since: N or (A and C) = A and C
and that would mean our initial assumption S1 = S2 is true
Would that ultimately prove that S1 = S2 ?
A || ((!A) && B)is logically equivalent toA || B(where!Arefers to the negation ofA, like howx <= 0is the negation ofx > 0in your example). (Mathematically, we can write that $A\lor ((\sim A)\land B)$ is logically equivalent to $A\lor B$. You can prove this using rules of logic.) You can just use the latter in code. – Minus One-Twelfth Apr 03 '19 at 09:31