Does left-to-right evaluation not matter when only the right-most operation is non-commutative?
$begingroup$
So I've been working on a formula compiler and came across a bug in the order of operations that made
$2 - 2 + 2 = 4$
and have now learned to appreciate order of operations and that subtraction is not commutative.
I found that the same issue occurred with for division, where
$16 / 8 * 2 = 1$
So now I've fixed the issue, and am looking for more test cases.
while I can easily find them of the form
$a ÷ b * c$
where evaluation left-to-right differs from right-to-left, I cannot seem to find an example where
$a * b ÷ c$
is sensitive ltr vs rtl evaluation... likewise for subtraction!
So, I'm starting to suspect that if the operator have the same precedence, then
$a (commutativeop) b (noncommutativeop) c$
is not sensitive to ltr vs rtl, but that
$a (noncommutativeop) b (commutativeop) c$
is.
Have I encountered something fundamental going on here, or am I bad at looking for examples, or is this just a coincidence with division and subtraction?
PS please add appropriate tags
notation associativity
$endgroup$
|
show 1 more comment
$begingroup$
So I've been working on a formula compiler and came across a bug in the order of operations that made
$2 - 2 + 2 = 4$
and have now learned to appreciate order of operations and that subtraction is not commutative.
I found that the same issue occurred with for division, where
$16 / 8 * 2 = 1$
So now I've fixed the issue, and am looking for more test cases.
while I can easily find them of the form
$a ÷ b * c$
where evaluation left-to-right differs from right-to-left, I cannot seem to find an example where
$a * b ÷ c$
is sensitive ltr vs rtl evaluation... likewise for subtraction!
So, I'm starting to suspect that if the operator have the same precedence, then
$a (commutativeop) b (noncommutativeop) c$
is not sensitive to ltr vs rtl, but that
$a (noncommutativeop) b (commutativeop) c$
is.
Have I encountered something fundamental going on here, or am I bad at looking for examples, or is this just a coincidence with division and subtraction?
PS please add appropriate tags
notation associativity
$endgroup$
$begingroup$
The title seems to ask about the right-most operation being non-commutative, but your first two examples involve commutation operations on the right end of the expressions.
$endgroup$
– hardmath
Dec 5 '18 at 16:59
$begingroup$
Tweaked the title, but yes, it seems like it's only an issue when its on the left, since I can't find examples when it is on the right.
$endgroup$
– ArtB
Dec 5 '18 at 17:02
$begingroup$
If one of your operations was called difference defined as $x ? y = |x-y|$, then it would be commutative but not associative for example with $1 ? (2 ? 3) = 0$ while $(1 ? 2) ? 3 = 2$
$endgroup$
– Henry
Dec 5 '18 at 17:04
$begingroup$
Parentheses will help make clear what ordering the operations means. Of course one needs more than simply the commutative or noncommutative character of operations to show the order "doesn't make a difference". For example, $(a+b)÷ c$ is not generally equal to $a+(b÷ c)$.
$endgroup$
– hardmath
Dec 5 '18 at 17:06
$begingroup$
@hardmath + and ÷ have different precedence so that is more obvious that it matters (would violate BEDMAS etc), but I'm asking about ltr vs rtl within a precendence
$endgroup$
– ArtB
Dec 5 '18 at 17:08
|
show 1 more comment
$begingroup$
So I've been working on a formula compiler and came across a bug in the order of operations that made
$2 - 2 + 2 = 4$
and have now learned to appreciate order of operations and that subtraction is not commutative.
I found that the same issue occurred with for division, where
$16 / 8 * 2 = 1$
So now I've fixed the issue, and am looking for more test cases.
while I can easily find them of the form
$a ÷ b * c$
where evaluation left-to-right differs from right-to-left, I cannot seem to find an example where
$a * b ÷ c$
is sensitive ltr vs rtl evaluation... likewise for subtraction!
So, I'm starting to suspect that if the operator have the same precedence, then
$a (commutativeop) b (noncommutativeop) c$
is not sensitive to ltr vs rtl, but that
$a (noncommutativeop) b (commutativeop) c$
is.
Have I encountered something fundamental going on here, or am I bad at looking for examples, or is this just a coincidence with division and subtraction?
PS please add appropriate tags
notation associativity
$endgroup$
So I've been working on a formula compiler and came across a bug in the order of operations that made
$2 - 2 + 2 = 4$
and have now learned to appreciate order of operations and that subtraction is not commutative.
I found that the same issue occurred with for division, where
$16 / 8 * 2 = 1$
So now I've fixed the issue, and am looking for more test cases.
while I can easily find them of the form
$a ÷ b * c$
where evaluation left-to-right differs from right-to-left, I cannot seem to find an example where
$a * b ÷ c$
is sensitive ltr vs rtl evaluation... likewise for subtraction!
So, I'm starting to suspect that if the operator have the same precedence, then
$a (commutativeop) b (noncommutativeop) c$
is not sensitive to ltr vs rtl, but that
$a (noncommutativeop) b (commutativeop) c$
is.
Have I encountered something fundamental going on here, or am I bad at looking for examples, or is this just a coincidence with division and subtraction?
PS please add appropriate tags
notation associativity
notation associativity
edited Dec 5 '18 at 17:09
ArtB
asked Dec 5 '18 at 16:54
ArtBArtB
1059
1059
$begingroup$
The title seems to ask about the right-most operation being non-commutative, but your first two examples involve commutation operations on the right end of the expressions.
$endgroup$
– hardmath
Dec 5 '18 at 16:59
$begingroup$
Tweaked the title, but yes, it seems like it's only an issue when its on the left, since I can't find examples when it is on the right.
$endgroup$
– ArtB
Dec 5 '18 at 17:02
$begingroup$
If one of your operations was called difference defined as $x ? y = |x-y|$, then it would be commutative but not associative for example with $1 ? (2 ? 3) = 0$ while $(1 ? 2) ? 3 = 2$
$endgroup$
– Henry
Dec 5 '18 at 17:04
$begingroup$
Parentheses will help make clear what ordering the operations means. Of course one needs more than simply the commutative or noncommutative character of operations to show the order "doesn't make a difference". For example, $(a+b)÷ c$ is not generally equal to $a+(b÷ c)$.
$endgroup$
– hardmath
Dec 5 '18 at 17:06
$begingroup$
@hardmath + and ÷ have different precedence so that is more obvious that it matters (would violate BEDMAS etc), but I'm asking about ltr vs rtl within a precendence
$endgroup$
– ArtB
Dec 5 '18 at 17:08
|
show 1 more comment
$begingroup$
The title seems to ask about the right-most operation being non-commutative, but your first two examples involve commutation operations on the right end of the expressions.
$endgroup$
– hardmath
Dec 5 '18 at 16:59
$begingroup$
Tweaked the title, but yes, it seems like it's only an issue when its on the left, since I can't find examples when it is on the right.
$endgroup$
– ArtB
Dec 5 '18 at 17:02
$begingroup$
If one of your operations was called difference defined as $x ? y = |x-y|$, then it would be commutative but not associative for example with $1 ? (2 ? 3) = 0$ while $(1 ? 2) ? 3 = 2$
$endgroup$
– Henry
Dec 5 '18 at 17:04
$begingroup$
Parentheses will help make clear what ordering the operations means. Of course one needs more than simply the commutative or noncommutative character of operations to show the order "doesn't make a difference". For example, $(a+b)÷ c$ is not generally equal to $a+(b÷ c)$.
$endgroup$
– hardmath
Dec 5 '18 at 17:06
$begingroup$
@hardmath + and ÷ have different precedence so that is more obvious that it matters (would violate BEDMAS etc), but I'm asking about ltr vs rtl within a precendence
$endgroup$
– ArtB
Dec 5 '18 at 17:08
$begingroup$
The title seems to ask about the right-most operation being non-commutative, but your first two examples involve commutation operations on the right end of the expressions.
$endgroup$
– hardmath
Dec 5 '18 at 16:59
$begingroup$
The title seems to ask about the right-most operation being non-commutative, but your first two examples involve commutation operations on the right end of the expressions.
$endgroup$
– hardmath
Dec 5 '18 at 16:59
$begingroup$
Tweaked the title, but yes, it seems like it's only an issue when its on the left, since I can't find examples when it is on the right.
$endgroup$
– ArtB
Dec 5 '18 at 17:02
$begingroup$
Tweaked the title, but yes, it seems like it's only an issue when its on the left, since I can't find examples when it is on the right.
$endgroup$
– ArtB
Dec 5 '18 at 17:02
$begingroup$
If one of your operations was called difference defined as $x ? y = |x-y|$, then it would be commutative but not associative for example with $1 ? (2 ? 3) = 0$ while $(1 ? 2) ? 3 = 2$
$endgroup$
– Henry
Dec 5 '18 at 17:04
$begingroup$
If one of your operations was called difference defined as $x ? y = |x-y|$, then it would be commutative but not associative for example with $1 ? (2 ? 3) = 0$ while $(1 ? 2) ? 3 = 2$
$endgroup$
– Henry
Dec 5 '18 at 17:04
$begingroup$
Parentheses will help make clear what ordering the operations means. Of course one needs more than simply the commutative or noncommutative character of operations to show the order "doesn't make a difference". For example, $(a+b)÷ c$ is not generally equal to $a+(b÷ c)$.
$endgroup$
– hardmath
Dec 5 '18 at 17:06
$begingroup$
Parentheses will help make clear what ordering the operations means. Of course one needs more than simply the commutative or noncommutative character of operations to show the order "doesn't make a difference". For example, $(a+b)÷ c$ is not generally equal to $a+(b÷ c)$.
$endgroup$
– hardmath
Dec 5 '18 at 17:06
$begingroup$
@hardmath + and ÷ have different precedence so that is more obvious that it matters (would violate BEDMAS etc), but I'm asking about ltr vs rtl within a precendence
$endgroup$
– ArtB
Dec 5 '18 at 17:08
$begingroup$
@hardmath + and ÷ have different precedence so that is more obvious that it matters (would violate BEDMAS etc), but I'm asking about ltr vs rtl within a precendence
$endgroup$
– ArtB
Dec 5 '18 at 17:08
|
show 1 more comment
2 Answers
2
active
oldest
votes
$begingroup$
Edit in response to comment.
I misread the question. Original answer below. New discussion, not really an answer to your question. But it may help.
Operator precedence is subtle, and about associativity, not commutativity. The correct mathematical way to think about subtraction is in terms of the additive inverse - that would be the "unary $-$" operator in a computer language. Then
$$
a - b + c quad text{ is really } quad a + (-b) + c .
$$
Precedence binds the unary $-$ more tightly than $+$. After you've invoked it you have commutative and associative addition.
I think your problem is really about order of operations and hence associativity, not about which operations commute. For example
$$
"atimes b-c": (a times b) -c ne a times (b-c)
$$
and
$$
"a - b times c": (a - b) times c ne a - ( b times c)
$$
It doesn't matter whether the noncommutative subtraction is first or second.
$endgroup$
$begingroup$
multiplication and subtraction are different levels of precedence within BEDMAS/PEDMAS etc, I'm asking about when does ltr vs rtl evaluation matter between expression all of the same precedence
$endgroup$
– ArtB
Dec 5 '18 at 17:11
add a comment |
$begingroup$
No, this isn't fundamental. As an example, define operator $star$ as $a star b = frac b a$ and check your conjecture again.
$endgroup$
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: "69"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fmath.stackexchange.com%2fquestions%2f3027327%2fdoes-left-to-right-evaluation-not-matter-when-only-the-right-most-operation-is-n%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Edit in response to comment.
I misread the question. Original answer below. New discussion, not really an answer to your question. But it may help.
Operator precedence is subtle, and about associativity, not commutativity. The correct mathematical way to think about subtraction is in terms of the additive inverse - that would be the "unary $-$" operator in a computer language. Then
$$
a - b + c quad text{ is really } quad a + (-b) + c .
$$
Precedence binds the unary $-$ more tightly than $+$. After you've invoked it you have commutative and associative addition.
I think your problem is really about order of operations and hence associativity, not about which operations commute. For example
$$
"atimes b-c": (a times b) -c ne a times (b-c)
$$
and
$$
"a - b times c": (a - b) times c ne a - ( b times c)
$$
It doesn't matter whether the noncommutative subtraction is first or second.
$endgroup$
$begingroup$
multiplication and subtraction are different levels of precedence within BEDMAS/PEDMAS etc, I'm asking about when does ltr vs rtl evaluation matter between expression all of the same precedence
$endgroup$
– ArtB
Dec 5 '18 at 17:11
add a comment |
$begingroup$
Edit in response to comment.
I misread the question. Original answer below. New discussion, not really an answer to your question. But it may help.
Operator precedence is subtle, and about associativity, not commutativity. The correct mathematical way to think about subtraction is in terms of the additive inverse - that would be the "unary $-$" operator in a computer language. Then
$$
a - b + c quad text{ is really } quad a + (-b) + c .
$$
Precedence binds the unary $-$ more tightly than $+$. After you've invoked it you have commutative and associative addition.
I think your problem is really about order of operations and hence associativity, not about which operations commute. For example
$$
"atimes b-c": (a times b) -c ne a times (b-c)
$$
and
$$
"a - b times c": (a - b) times c ne a - ( b times c)
$$
It doesn't matter whether the noncommutative subtraction is first or second.
$endgroup$
$begingroup$
multiplication and subtraction are different levels of precedence within BEDMAS/PEDMAS etc, I'm asking about when does ltr vs rtl evaluation matter between expression all of the same precedence
$endgroup$
– ArtB
Dec 5 '18 at 17:11
add a comment |
$begingroup$
Edit in response to comment.
I misread the question. Original answer below. New discussion, not really an answer to your question. But it may help.
Operator precedence is subtle, and about associativity, not commutativity. The correct mathematical way to think about subtraction is in terms of the additive inverse - that would be the "unary $-$" operator in a computer language. Then
$$
a - b + c quad text{ is really } quad a + (-b) + c .
$$
Precedence binds the unary $-$ more tightly than $+$. After you've invoked it you have commutative and associative addition.
I think your problem is really about order of operations and hence associativity, not about which operations commute. For example
$$
"atimes b-c": (a times b) -c ne a times (b-c)
$$
and
$$
"a - b times c": (a - b) times c ne a - ( b times c)
$$
It doesn't matter whether the noncommutative subtraction is first or second.
$endgroup$
Edit in response to comment.
I misread the question. Original answer below. New discussion, not really an answer to your question. But it may help.
Operator precedence is subtle, and about associativity, not commutativity. The correct mathematical way to think about subtraction is in terms of the additive inverse - that would be the "unary $-$" operator in a computer language. Then
$$
a - b + c quad text{ is really } quad a + (-b) + c .
$$
Precedence binds the unary $-$ more tightly than $+$. After you've invoked it you have commutative and associative addition.
I think your problem is really about order of operations and hence associativity, not about which operations commute. For example
$$
"atimes b-c": (a times b) -c ne a times (b-c)
$$
and
$$
"a - b times c": (a - b) times c ne a - ( b times c)
$$
It doesn't matter whether the noncommutative subtraction is first or second.
edited Dec 5 '18 at 17:28
answered Dec 5 '18 at 17:05
Ethan BolkerEthan Bolker
42.6k549113
42.6k549113
$begingroup$
multiplication and subtraction are different levels of precedence within BEDMAS/PEDMAS etc, I'm asking about when does ltr vs rtl evaluation matter between expression all of the same precedence
$endgroup$
– ArtB
Dec 5 '18 at 17:11
add a comment |
$begingroup$
multiplication and subtraction are different levels of precedence within BEDMAS/PEDMAS etc, I'm asking about when does ltr vs rtl evaluation matter between expression all of the same precedence
$endgroup$
– ArtB
Dec 5 '18 at 17:11
$begingroup$
multiplication and subtraction are different levels of precedence within BEDMAS/PEDMAS etc, I'm asking about when does ltr vs rtl evaluation matter between expression all of the same precedence
$endgroup$
– ArtB
Dec 5 '18 at 17:11
$begingroup$
multiplication and subtraction are different levels of precedence within BEDMAS/PEDMAS etc, I'm asking about when does ltr vs rtl evaluation matter between expression all of the same precedence
$endgroup$
– ArtB
Dec 5 '18 at 17:11
add a comment |
$begingroup$
No, this isn't fundamental. As an example, define operator $star$ as $a star b = frac b a$ and check your conjecture again.
$endgroup$
add a comment |
$begingroup$
No, this isn't fundamental. As an example, define operator $star$ as $a star b = frac b a$ and check your conjecture again.
$endgroup$
add a comment |
$begingroup$
No, this isn't fundamental. As an example, define operator $star$ as $a star b = frac b a$ and check your conjecture again.
$endgroup$
No, this isn't fundamental. As an example, define operator $star$ as $a star b = frac b a$ and check your conjecture again.
answered Dec 5 '18 at 17:06
orlporlp
7,4341330
7,4341330
add a comment |
add a comment |
Thanks for contributing an answer to Mathematics 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%2fmath.stackexchange.com%2fquestions%2f3027327%2fdoes-left-to-right-evaluation-not-matter-when-only-the-right-most-operation-is-n%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$
The title seems to ask about the right-most operation being non-commutative, but your first two examples involve commutation operations on the right end of the expressions.
$endgroup$
– hardmath
Dec 5 '18 at 16:59
$begingroup$
Tweaked the title, but yes, it seems like it's only an issue when its on the left, since I can't find examples when it is on the right.
$endgroup$
– ArtB
Dec 5 '18 at 17:02
$begingroup$
If one of your operations was called difference defined as $x ? y = |x-y|$, then it would be commutative but not associative for example with $1 ? (2 ? 3) = 0$ while $(1 ? 2) ? 3 = 2$
$endgroup$
– Henry
Dec 5 '18 at 17:04
$begingroup$
Parentheses will help make clear what ordering the operations means. Of course one needs more than simply the commutative or noncommutative character of operations to show the order "doesn't make a difference". For example, $(a+b)÷ c$ is not generally equal to $a+(b÷ c)$.
$endgroup$
– hardmath
Dec 5 '18 at 17:06
$begingroup$
@hardmath + and ÷ have different precedence so that is more obvious that it matters (would violate BEDMAS etc), but I'm asking about ltr vs rtl within a precendence
$endgroup$
– ArtB
Dec 5 '18 at 17:08