Problem 44374. Tautology
Check if the given expression is always true. For example, the sentence
'~(A & B) == (~A | ~B)'
is always true.
Characters in the input sequences may include ~ & | == ( ), whitespace, 0 for false, 1 for true and letters for variables.
Solution Stats
Problem Comments
-
25 Comments
Never mind. I see that MATLAB gives & precedence over |. This pretty much blows my solution out of the water. Guess it's back to the drawing board. Btw, why won't Cody let me delete my comments?
This question ignores operator precedence, and imho that's just evil. All compilers that I know of use operator precedence because if they don't that leads to contradictions. Test cases 49 & 51 demonstrates this: (1|A&0) is a tautology only if evaluated from right to left (1|0 -> 1, but 1&0 -> 0), and (A&~A|1) is a tautology only if evaluated from left to right (0|1 -> 1, but A & 1 -> 0). Assuming that & and I have the same precedence.
It would be a good measure to add operator precedence to the problem description since the author is requesting a parser. We cannot assume every language is the same. Imho, a tautology is true regardless of the order that we evaluate it such as A|~A or ~0. If there is a way to make it false, then it is not a tautology. And different languages may evaluate it differently.
Solution Comments
Show commentsProblem Recent Solvers42
Suggested Problems
-
104388 Solvers
-
1247 Solvers
-
Who knows the last digit of pi?
671 Solvers
-
859 Solvers
-
Rounding off numbers to n decimals
4772 Solvers
More from this Author40
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!