Is there a ternary operator in mathConsidering math or computer scienceWhat is a good language to develop in...
Equivalent to "source" in OpenBSD?
Avoiding unpacking an array when altering its dimension
Is there a German word for “analytics”?
Difference between 'stomach' and 'uterus'
What are these green text/line displays shown during the livestream of Crew Dragon's approach to dock with the ISS?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
Skis versus snow shoes - when to choose which for travelling the backcountry?
Why do members of Congress in committee hearings ask witnesses the same question multiple times?
Second-rate spelling
I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?
Has the Isbell–Freyd criterion ever been used to check that a category is concretisable?
What's the difference between a cart and a wagon?
How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?
How to avoid being sexist when trying to employ someone to function in a very sexist environment?
Series pass transistor, LM7812
What is better: yes / no radio, or simple checkbox?
How would one optimize conventional modern weapons for fighting robots
How can I handle a player who pre-plans arguments about my rulings on RAW?
I am on the US no-fly list. What can I do in order to be allowed on flights which go through US airspace?
Magento 2: Override XML file from vendor folder to app folder doesn't work/update
Are small insurances worth it
Is there any relevance to Thor getting his hair cut other than comedic value?
Is there a low-level alternative to Animate Objects?
What is a term for a function that when called repeatedly, has the same effect as calling once?
Is there a ternary operator in math
Considering math or computer scienceWhat is a good language to develop in for simple, yet customizable math programs?Translate Programming code to MathMath vocab: operator on $S$ and into $S =$?A set system generated by a closure operator?Evaluating math proofs by computeris all math beyond arithmetic just advanced arithmetic?Are there dictionaries in math?What is a good route for a math student to self study computer science systematically and efficiently?Multiplying two numbers using only the “left shift” operator
$begingroup$
Is there a math equivalent of the programming ternary operator?
a = b + c > 0 ? 1 : 2
The above meaning that if c is greater than 0 then a = b + 1 else a = b + 2.
computer-science
$endgroup$
add a comment |
$begingroup$
Is there a math equivalent of the programming ternary operator?
a = b + c > 0 ? 1 : 2
The above meaning that if c is greater than 0 then a = b + 1 else a = b + 2.
computer-science
$endgroup$
$begingroup$
It probably depends on the form of the conditions and the results, but the example you gave can be expressed with the unit step $u(x)$ (with an appropriate definition at $x=1$): $a = u(b+c) + 1$
$endgroup$
– Alex
2 hours ago
$begingroup$
@Alex $a = b + 2 - u(c)$
$endgroup$
– eyeballfrog
2 hours ago
add a comment |
$begingroup$
Is there a math equivalent of the programming ternary operator?
a = b + c > 0 ? 1 : 2
The above meaning that if c is greater than 0 then a = b + 1 else a = b + 2.
computer-science
$endgroup$
Is there a math equivalent of the programming ternary operator?
a = b + c > 0 ? 1 : 2
The above meaning that if c is greater than 0 then a = b + 1 else a = b + 2.
computer-science
computer-science
asked 2 hours ago
dataphiledataphile
415
415
$begingroup$
It probably depends on the form of the conditions and the results, but the example you gave can be expressed with the unit step $u(x)$ (with an appropriate definition at $x=1$): $a = u(b+c) + 1$
$endgroup$
– Alex
2 hours ago
$begingroup$
@Alex $a = b + 2 - u(c)$
$endgroup$
– eyeballfrog
2 hours ago
add a comment |
$begingroup$
It probably depends on the form of the conditions and the results, but the example you gave can be expressed with the unit step $u(x)$ (with an appropriate definition at $x=1$): $a = u(b+c) + 1$
$endgroup$
– Alex
2 hours ago
$begingroup$
@Alex $a = b + 2 - u(c)$
$endgroup$
– eyeballfrog
2 hours ago
$begingroup$
It probably depends on the form of the conditions and the results, but the example you gave can be expressed with the unit step $u(x)$ (with an appropriate definition at $x=1$): $a = u(b+c) + 1$
$endgroup$
– Alex
2 hours ago
$begingroup$
It probably depends on the form of the conditions and the results, but the example you gave can be expressed with the unit step $u(x)$ (with an appropriate definition at $x=1$): $a = u(b+c) + 1$
$endgroup$
– Alex
2 hours ago
$begingroup$
@Alex $a = b + 2 - u(c)$
$endgroup$
– eyeballfrog
2 hours ago
$begingroup$
@Alex $a = b + 2 - u(c)$
$endgroup$
– eyeballfrog
2 hours ago
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
Using the indicator function notation:$$a=b+1+1_{(-infty, 0]}(c)$$
$endgroup$
$begingroup$
Indicator is definitely the way to go, since the conditional can define an arbitrary set.
$endgroup$
– eyeballfrog
1 hour ago
$begingroup$
Thank you, that is very elegant. I will definitely try out all of the answers as I often use this in various scenarios.
$endgroup$
– dataphile
1 hour ago
add a comment |
$begingroup$
In math, equations are written in piecewise form by having a curly brace enclose multiple lines; each one with a condition excepting the last which has "otherwise".
There are a few custom operators that also occasionally make an appearance. E.g. the Heavyside function mentioned by Alex, the Dirac function, and the cyclical operator $delta_{ijk}$ - all of which can be used to emulate conditional behaviour.
$endgroup$
add a comment |
$begingroup$
This is not a ternary operator, it is a function of two variables. There is one operation that results in $a$. You can certainly define a function
$$f(b,c)=begin {cases} b+1&c gt 0\
b+2 & c le 0 end {cases}$$
You can also define functions with any number of inputs you want, so you can define $f(a,b,c)=a(b+c^2)$, for example. This is a ternary function.
$endgroup$
add a comment |
$begingroup$
In Concrete Mathematics by Graham, Knuth and Patashnik, the authors use the "Iverson bracket" notation: Square brackets around a statement represent $1$ if the statement is true and $0$ otherwise. Using this notation, you could write
$$
a = b + 2 - [c gt 0].
$$
$endgroup$
2
$begingroup$
aka en.wikipedia.org/wiki/Iverson_bracket
$endgroup$
– qwr
56 mins ago
$begingroup$
@qwr Thank you! I did not recall the name.
$endgroup$
– FredH
54 mins ago
$begingroup$
I would find it clearer to write $a = b + 1[c>0] + 2[cle0]$.
$endgroup$
– Rahul
46 mins ago
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%2f3135798%2fis-there-a-ternary-operator-in-math%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Using the indicator function notation:$$a=b+1+1_{(-infty, 0]}(c)$$
$endgroup$
$begingroup$
Indicator is definitely the way to go, since the conditional can define an arbitrary set.
$endgroup$
– eyeballfrog
1 hour ago
$begingroup$
Thank you, that is very elegant. I will definitely try out all of the answers as I often use this in various scenarios.
$endgroup$
– dataphile
1 hour ago
add a comment |
$begingroup$
Using the indicator function notation:$$a=b+1+1_{(-infty, 0]}(c)$$
$endgroup$
$begingroup$
Indicator is definitely the way to go, since the conditional can define an arbitrary set.
$endgroup$
– eyeballfrog
1 hour ago
$begingroup$
Thank you, that is very elegant. I will definitely try out all of the answers as I often use this in various scenarios.
$endgroup$
– dataphile
1 hour ago
add a comment |
$begingroup$
Using the indicator function notation:$$a=b+1+1_{(-infty, 0]}(c)$$
$endgroup$
Using the indicator function notation:$$a=b+1+1_{(-infty, 0]}(c)$$
answered 2 hours ago
Siong Thye GohSiong Thye Goh
102k1466118
102k1466118
$begingroup$
Indicator is definitely the way to go, since the conditional can define an arbitrary set.
$endgroup$
– eyeballfrog
1 hour ago
$begingroup$
Thank you, that is very elegant. I will definitely try out all of the answers as I often use this in various scenarios.
$endgroup$
– dataphile
1 hour ago
add a comment |
$begingroup$
Indicator is definitely the way to go, since the conditional can define an arbitrary set.
$endgroup$
– eyeballfrog
1 hour ago
$begingroup$
Thank you, that is very elegant. I will definitely try out all of the answers as I often use this in various scenarios.
$endgroup$
– dataphile
1 hour ago
$begingroup$
Indicator is definitely the way to go, since the conditional can define an arbitrary set.
$endgroup$
– eyeballfrog
1 hour ago
$begingroup$
Indicator is definitely the way to go, since the conditional can define an arbitrary set.
$endgroup$
– eyeballfrog
1 hour ago
$begingroup$
Thank you, that is very elegant. I will definitely try out all of the answers as I often use this in various scenarios.
$endgroup$
– dataphile
1 hour ago
$begingroup$
Thank you, that is very elegant. I will definitely try out all of the answers as I often use this in various scenarios.
$endgroup$
– dataphile
1 hour ago
add a comment |
$begingroup$
In math, equations are written in piecewise form by having a curly brace enclose multiple lines; each one with a condition excepting the last which has "otherwise".
There are a few custom operators that also occasionally make an appearance. E.g. the Heavyside function mentioned by Alex, the Dirac function, and the cyclical operator $delta_{ijk}$ - all of which can be used to emulate conditional behaviour.
$endgroup$
add a comment |
$begingroup$
In math, equations are written in piecewise form by having a curly brace enclose multiple lines; each one with a condition excepting the last which has "otherwise".
There are a few custom operators that also occasionally make an appearance. E.g. the Heavyside function mentioned by Alex, the Dirac function, and the cyclical operator $delta_{ijk}$ - all of which can be used to emulate conditional behaviour.
$endgroup$
add a comment |
$begingroup$
In math, equations are written in piecewise form by having a curly brace enclose multiple lines; each one with a condition excepting the last which has "otherwise".
There are a few custom operators that also occasionally make an appearance. E.g. the Heavyside function mentioned by Alex, the Dirac function, and the cyclical operator $delta_{ijk}$ - all of which can be used to emulate conditional behaviour.
$endgroup$
In math, equations are written in piecewise form by having a curly brace enclose multiple lines; each one with a condition excepting the last which has "otherwise".
There are a few custom operators that also occasionally make an appearance. E.g. the Heavyside function mentioned by Alex, the Dirac function, and the cyclical operator $delta_{ijk}$ - all of which can be used to emulate conditional behaviour.
answered 2 hours ago
Paul ChildsPaul Childs
3247
3247
add a comment |
add a comment |
$begingroup$
This is not a ternary operator, it is a function of two variables. There is one operation that results in $a$. You can certainly define a function
$$f(b,c)=begin {cases} b+1&c gt 0\
b+2 & c le 0 end {cases}$$
You can also define functions with any number of inputs you want, so you can define $f(a,b,c)=a(b+c^2)$, for example. This is a ternary function.
$endgroup$
add a comment |
$begingroup$
This is not a ternary operator, it is a function of two variables. There is one operation that results in $a$. You can certainly define a function
$$f(b,c)=begin {cases} b+1&c gt 0\
b+2 & c le 0 end {cases}$$
You can also define functions with any number of inputs you want, so you can define $f(a,b,c)=a(b+c^2)$, for example. This is a ternary function.
$endgroup$
add a comment |
$begingroup$
This is not a ternary operator, it is a function of two variables. There is one operation that results in $a$. You can certainly define a function
$$f(b,c)=begin {cases} b+1&c gt 0\
b+2 & c le 0 end {cases}$$
You can also define functions with any number of inputs you want, so you can define $f(a,b,c)=a(b+c^2)$, for example. This is a ternary function.
$endgroup$
This is not a ternary operator, it is a function of two variables. There is one operation that results in $a$. You can certainly define a function
$$f(b,c)=begin {cases} b+1&c gt 0\
b+2 & c le 0 end {cases}$$
You can also define functions with any number of inputs you want, so you can define $f(a,b,c)=a(b+c^2)$, for example. This is a ternary function.
answered 2 hours ago
Ross MillikanRoss Millikan
298k23198371
298k23198371
add a comment |
add a comment |
$begingroup$
In Concrete Mathematics by Graham, Knuth and Patashnik, the authors use the "Iverson bracket" notation: Square brackets around a statement represent $1$ if the statement is true and $0$ otherwise. Using this notation, you could write
$$
a = b + 2 - [c gt 0].
$$
$endgroup$
2
$begingroup$
aka en.wikipedia.org/wiki/Iverson_bracket
$endgroup$
– qwr
56 mins ago
$begingroup$
@qwr Thank you! I did not recall the name.
$endgroup$
– FredH
54 mins ago
$begingroup$
I would find it clearer to write $a = b + 1[c>0] + 2[cle0]$.
$endgroup$
– Rahul
46 mins ago
add a comment |
$begingroup$
In Concrete Mathematics by Graham, Knuth and Patashnik, the authors use the "Iverson bracket" notation: Square brackets around a statement represent $1$ if the statement is true and $0$ otherwise. Using this notation, you could write
$$
a = b + 2 - [c gt 0].
$$
$endgroup$
2
$begingroup$
aka en.wikipedia.org/wiki/Iverson_bracket
$endgroup$
– qwr
56 mins ago
$begingroup$
@qwr Thank you! I did not recall the name.
$endgroup$
– FredH
54 mins ago
$begingroup$
I would find it clearer to write $a = b + 1[c>0] + 2[cle0]$.
$endgroup$
– Rahul
46 mins ago
add a comment |
$begingroup$
In Concrete Mathematics by Graham, Knuth and Patashnik, the authors use the "Iverson bracket" notation: Square brackets around a statement represent $1$ if the statement is true and $0$ otherwise. Using this notation, you could write
$$
a = b + 2 - [c gt 0].
$$
$endgroup$
In Concrete Mathematics by Graham, Knuth and Patashnik, the authors use the "Iverson bracket" notation: Square brackets around a statement represent $1$ if the statement is true and $0$ otherwise. Using this notation, you could write
$$
a = b + 2 - [c gt 0].
$$
edited 51 mins ago
answered 1 hour ago
FredHFredH
50629
50629
2
$begingroup$
aka en.wikipedia.org/wiki/Iverson_bracket
$endgroup$
– qwr
56 mins ago
$begingroup$
@qwr Thank you! I did not recall the name.
$endgroup$
– FredH
54 mins ago
$begingroup$
I would find it clearer to write $a = b + 1[c>0] + 2[cle0]$.
$endgroup$
– Rahul
46 mins ago
add a comment |
2
$begingroup$
aka en.wikipedia.org/wiki/Iverson_bracket
$endgroup$
– qwr
56 mins ago
$begingroup$
@qwr Thank you! I did not recall the name.
$endgroup$
– FredH
54 mins ago
$begingroup$
I would find it clearer to write $a = b + 1[c>0] + 2[cle0]$.
$endgroup$
– Rahul
46 mins ago
2
2
$begingroup$
aka en.wikipedia.org/wiki/Iverson_bracket
$endgroup$
– qwr
56 mins ago
$begingroup$
aka en.wikipedia.org/wiki/Iverson_bracket
$endgroup$
– qwr
56 mins ago
$begingroup$
@qwr Thank you! I did not recall the name.
$endgroup$
– FredH
54 mins ago
$begingroup$
@qwr Thank you! I did not recall the name.
$endgroup$
– FredH
54 mins ago
$begingroup$
I would find it clearer to write $a = b + 1[c>0] + 2[cle0]$.
$endgroup$
– Rahul
46 mins ago
$begingroup$
I would find it clearer to write $a = b + 1[c>0] + 2[cle0]$.
$endgroup$
– Rahul
46 mins ago
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%2f3135798%2fis-there-a-ternary-operator-in-math%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$
It probably depends on the form of the conditions and the results, but the example you gave can be expressed with the unit step $u(x)$ (with an appropriate definition at $x=1$): $a = u(b+c) + 1$
$endgroup$
– Alex
2 hours ago
$begingroup$
@Alex $a = b + 2 - u(c)$
$endgroup$
– eyeballfrog
2 hours ago