How to test for logic operator precedence
$begingroup$
While coding in Python, I realized I couldn't remember which is evaluated first:
and (the logical conjunctive operator),or (the logical disjunctive operator).
Of course, I could've used parentheses (or looked it up), but I wanted to try to find out for myself. I tried endless combinations of False, True, and, and or but could not figure it out.
Given a language with unknown operator precedence, where operators of equal precedence evaluate left-to-right, find a way to conclusively determine whether the logical conjunction or the logical disjunction is evaluated first.
You can only use False, True, and, and or in your answer.
Note: You may assume that or and and definitely have different precedence.
computer-puzzle computer-science
$endgroup$
|
show 2 more comments
$begingroup$
While coding in Python, I realized I couldn't remember which is evaluated first:
and (the logical conjunctive operator),or (the logical disjunctive operator).
Of course, I could've used parentheses (or looked it up), but I wanted to try to find out for myself. I tried endless combinations of False, True, and, and or but could not figure it out.
Given a language with unknown operator precedence, where operators of equal precedence evaluate left-to-right, find a way to conclusively determine whether the logical conjunction or the logical disjunction is evaluated first.
You can only use False, True, and, and or in your answer.
Note: You may assume that or and and definitely have different precedence.
computer-puzzle computer-science
$endgroup$
$begingroup$
Are we assuming operator precedence either (1) evaluates allandleft to right and then allorleft to right, or (2) evaluates allorleft to right and then allandleft to right?
$endgroup$
– noedne
Apr 30 '18 at 1:35
$begingroup$
@noedne Yes. Otherwise they'd have the same precedence
$endgroup$
– somebody
Apr 30 '18 at 1:37
1
$begingroup$
@noedne edited.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:34
1
$begingroup$
Nice edit. Do we also assume thatandandorhave different precedence?
$endgroup$
– noedne
Apr 30 '18 at 2:42
1
$begingroup$
Yes, as stated (slightly unclearly) in the question. Let me clarify that.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:51
|
show 2 more comments
$begingroup$
While coding in Python, I realized I couldn't remember which is evaluated first:
and (the logical conjunctive operator),or (the logical disjunctive operator).
Of course, I could've used parentheses (or looked it up), but I wanted to try to find out for myself. I tried endless combinations of False, True, and, and or but could not figure it out.
Given a language with unknown operator precedence, where operators of equal precedence evaluate left-to-right, find a way to conclusively determine whether the logical conjunction or the logical disjunction is evaluated first.
You can only use False, True, and, and or in your answer.
Note: You may assume that or and and definitely have different precedence.
computer-puzzle computer-science
$endgroup$
While coding in Python, I realized I couldn't remember which is evaluated first:
and (the logical conjunctive operator),or (the logical disjunctive operator).
Of course, I could've used parentheses (or looked it up), but I wanted to try to find out for myself. I tried endless combinations of False, True, and, and or but could not figure it out.
Given a language with unknown operator precedence, where operators of equal precedence evaluate left-to-right, find a way to conclusively determine whether the logical conjunction or the logical disjunction is evaluated first.
You can only use False, True, and, and or in your answer.
Note: You may assume that or and and definitely have different precedence.
computer-puzzle computer-science
computer-puzzle computer-science
edited 16 mins ago
Gareth McCaughan♦
67.3k3170261
67.3k3170261
asked Apr 30 '18 at 1:25
OldBunny2800OldBunny2800
356213
356213
$begingroup$
Are we assuming operator precedence either (1) evaluates allandleft to right and then allorleft to right, or (2) evaluates allorleft to right and then allandleft to right?
$endgroup$
– noedne
Apr 30 '18 at 1:35
$begingroup$
@noedne Yes. Otherwise they'd have the same precedence
$endgroup$
– somebody
Apr 30 '18 at 1:37
1
$begingroup$
@noedne edited.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:34
1
$begingroup$
Nice edit. Do we also assume thatandandorhave different precedence?
$endgroup$
– noedne
Apr 30 '18 at 2:42
1
$begingroup$
Yes, as stated (slightly unclearly) in the question. Let me clarify that.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:51
|
show 2 more comments
$begingroup$
Are we assuming operator precedence either (1) evaluates allandleft to right and then allorleft to right, or (2) evaluates allorleft to right and then allandleft to right?
$endgroup$
– noedne
Apr 30 '18 at 1:35
$begingroup$
@noedne Yes. Otherwise they'd have the same precedence
$endgroup$
– somebody
Apr 30 '18 at 1:37
1
$begingroup$
@noedne edited.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:34
1
$begingroup$
Nice edit. Do we also assume thatandandorhave different precedence?
$endgroup$
– noedne
Apr 30 '18 at 2:42
1
$begingroup$
Yes, as stated (slightly unclearly) in the question. Let me clarify that.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:51
$begingroup$
Are we assuming operator precedence either (1) evaluates all
and left to right and then all or left to right, or (2) evaluates all or left to right and then all and left to right?$endgroup$
– noedne
Apr 30 '18 at 1:35
$begingroup$
Are we assuming operator precedence either (1) evaluates all
and left to right and then all or left to right, or (2) evaluates all or left to right and then all and left to right?$endgroup$
– noedne
Apr 30 '18 at 1:35
$begingroup$
@noedne Yes. Otherwise they'd have the same precedence
$endgroup$
– somebody
Apr 30 '18 at 1:37
$begingroup$
@noedne Yes. Otherwise they'd have the same precedence
$endgroup$
– somebody
Apr 30 '18 at 1:37
1
1
$begingroup$
@noedne edited.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:34
$begingroup$
@noedne edited.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:34
1
1
$begingroup$
Nice edit. Do we also assume that
and and or have different precedence?$endgroup$
– noedne
Apr 30 '18 at 2:42
$begingroup$
Nice edit. Do we also assume that
and and or have different precedence?$endgroup$
– noedne
Apr 30 '18 at 2:42
1
1
$begingroup$
Yes, as stated (slightly unclearly) in the question. Let me clarify that.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:51
$begingroup$
Yes, as stated (slightly unclearly) in the question. Let me clarify that.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:51
|
show 2 more comments
1 Answer
1
active
oldest
votes
$begingroup$
True or True and False
GivingTruemeans 'and' then 'or'. GivingFalsemeans 'or' then 'and'.
Bonus:
False and True or True
Also use this to test if the precedence is same. If both tests are resulting different value (first test givesFalseand second test givesTrue) then the precedence is same.
$endgroup$
$begingroup$
Wow, how did I not think of that… facepalm Good job!
$endgroup$
– OldBunny2800
Apr 30 '18 at 1:42
3
$begingroup$
The middle value is actually irrelevant. It could be either true or false and the test would still work the same.
$endgroup$
– Kruga
Apr 30 '18 at 8:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "559"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f65127%2fhow-to-test-for-logic-operator-precedence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
True or True and False
GivingTruemeans 'and' then 'or'. GivingFalsemeans 'or' then 'and'.
Bonus:
False and True or True
Also use this to test if the precedence is same. If both tests are resulting different value (first test givesFalseand second test givesTrue) then the precedence is same.
$endgroup$
$begingroup$
Wow, how did I not think of that… facepalm Good job!
$endgroup$
– OldBunny2800
Apr 30 '18 at 1:42
3
$begingroup$
The middle value is actually irrelevant. It could be either true or false and the test would still work the same.
$endgroup$
– Kruga
Apr 30 '18 at 8:58
add a comment |
$begingroup$
True or True and False
GivingTruemeans 'and' then 'or'. GivingFalsemeans 'or' then 'and'.
Bonus:
False and True or True
Also use this to test if the precedence is same. If both tests are resulting different value (first test givesFalseand second test givesTrue) then the precedence is same.
$endgroup$
$begingroup$
Wow, how did I not think of that… facepalm Good job!
$endgroup$
– OldBunny2800
Apr 30 '18 at 1:42
3
$begingroup$
The middle value is actually irrelevant. It could be either true or false and the test would still work the same.
$endgroup$
– Kruga
Apr 30 '18 at 8:58
add a comment |
$begingroup$
True or True and False
GivingTruemeans 'and' then 'or'. GivingFalsemeans 'or' then 'and'.
Bonus:
False and True or True
Also use this to test if the precedence is same. If both tests are resulting different value (first test givesFalseand second test givesTrue) then the precedence is same.
$endgroup$
True or True and False
GivingTruemeans 'and' then 'or'. GivingFalsemeans 'or' then 'and'.
Bonus:
False and True or True
Also use this to test if the precedence is same. If both tests are resulting different value (first test givesFalseand second test givesTrue) then the precedence is same.
answered Apr 30 '18 at 1:37
athinathin
8,61222776
8,61222776
$begingroup$
Wow, how did I not think of that… facepalm Good job!
$endgroup$
– OldBunny2800
Apr 30 '18 at 1:42
3
$begingroup$
The middle value is actually irrelevant. It could be either true or false and the test would still work the same.
$endgroup$
– Kruga
Apr 30 '18 at 8:58
add a comment |
$begingroup$
Wow, how did I not think of that… facepalm Good job!
$endgroup$
– OldBunny2800
Apr 30 '18 at 1:42
3
$begingroup$
The middle value is actually irrelevant. It could be either true or false and the test would still work the same.
$endgroup$
– Kruga
Apr 30 '18 at 8:58
$begingroup$
Wow, how did I not think of that… facepalm Good job!
$endgroup$
– OldBunny2800
Apr 30 '18 at 1:42
$begingroup$
Wow, how did I not think of that… facepalm Good job!
$endgroup$
– OldBunny2800
Apr 30 '18 at 1:42
3
3
$begingroup$
The middle value is actually irrelevant. It could be either true or false and the test would still work the same.
$endgroup$
– Kruga
Apr 30 '18 at 8:58
$begingroup$
The middle value is actually irrelevant. It could be either true or false and the test would still work the same.
$endgroup$
– Kruga
Apr 30 '18 at 8:58
add a comment |
Thanks for contributing an answer to Puzzling Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f65127%2fhow-to-test-for-logic-operator-precedence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Are we assuming operator precedence either (1) evaluates all
andleft to right and then allorleft to right, or (2) evaluates allorleft to right and then allandleft to right?$endgroup$
– noedne
Apr 30 '18 at 1:35
$begingroup$
@noedne Yes. Otherwise they'd have the same precedence
$endgroup$
– somebody
Apr 30 '18 at 1:37
1
$begingroup$
@noedne edited.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:34
1
$begingroup$
Nice edit. Do we also assume that
andandorhave different precedence?$endgroup$
– noedne
Apr 30 '18 at 2:42
1
$begingroup$
Yes, as stated (slightly unclearly) in the question. Let me clarify that.
$endgroup$
– OldBunny2800
Apr 30 '18 at 2:51