M
mingze zhang
Hi all,
Sorry that this post may not be a correct place for C++ forum. I hope
someone can give me some idea on this.
We all know that logic expressions can be manipulated or simplified,
for example,
1. (x && y) || (x && z) is equivalent to x && (y || z)
2. x && (x || y) is equivalent to x
3. (x || y) && (x || z) is equivalent to x || (y && z)
4. (y && x) || (z && x) is equivalent to (y || z) && x
5. (x || y) && x is equivalent to x
6. (y || x) && (z || x) is equivalent to (y && z) || x
But this simplification is apparently not all valid if short-circuit
evaluation is considered. In the above examples, Cases 1-3 are valid,
but 4-6 are not (assume x, y, z may have side effects).
So here comes my question, is there a general guideline to simplify a
very complicated logic expressions (under short-circuit equivalence)
when some of the logic expressions have side effect and some do not.
I know some compilers may do this kind of simplification. I just want
to know whether there are some tutorial or general procedures so that
I can quickly catch up. I tried to search on Google but with no good
luck.
Thanks in advance.
Vincent
Sorry that this post may not be a correct place for C++ forum. I hope
someone can give me some idea on this.
We all know that logic expressions can be manipulated or simplified,
for example,
1. (x && y) || (x && z) is equivalent to x && (y || z)
2. x && (x || y) is equivalent to x
3. (x || y) && (x || z) is equivalent to x || (y && z)
4. (y && x) || (z && x) is equivalent to (y || z) && x
5. (x || y) && x is equivalent to x
6. (y || x) && (z || x) is equivalent to (y && z) || x
But this simplification is apparently not all valid if short-circuit
evaluation is considered. In the above examples, Cases 1-3 are valid,
but 4-6 are not (assume x, y, z may have side effects).
So here comes my question, is there a general guideline to simplify a
very complicated logic expressions (under short-circuit equivalence)
when some of the logic expressions have side effect and some do not.
I know some compilers may do this kind of simplification. I just want
to know whether there are some tutorial or general procedures so that
I can quickly catch up. I tried to search on Google but with no good
luck.
Thanks in advance.
Vincent