Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This has to be the stupidest question for the whole week but,

I watched this video:

and the guy defined a function

$$f(x) =\left\{ \begin{array}{ll} x^2, & \hbox{if }x\neq 2; \\ 1, & \hbox{if }x=2. \end{array} \right.$$

I believe that's the proper notation, please check the video at 5:52 if I messed it up.

My question is, is there a way to figure out the function's "body", just by making up rules like this?

For example, can I say that I have a function $f(x)$ that for

$$f(x) =\left\{ \begin{array}{ll} \sin(x), & \hbox{if }-1 < x < 1; \\ 0, & \hbox{if }x < -1\mbox{ or }x > 1. \end{array} \right.$$

How would I figure out the function's body just by using those preset rules?

Just pointing me in the right direction would be more than enough, please use the catalogue at and tell me what to watch. Thank you for your time!

P.S. This might not make a ton of sense at first, but it's interesting for me because I'm a front-end web developer and I'm doing lots of graphic or motion related programming, which involves math.

share|cite|improve this question
What do you mean by "body"? Do you mean the graph of the function, or something else? – NKS Jan 2 '12 at 22:38
The "$\cases{blah &\text{if this}\\ blah &\text{if that}}$" is the the definition of the function -- it's a perfectly good way to define a function and there no rule that says a function definition has to fit on one line. If you have a description that's unambiguous enough to allow you to figure out what the function value for each particular argument is, then by definition that description constitutes a function. It doesn't need to have any particular syntactic form. – Henning Makholm Jan 2 '12 at 23:31
It may be possible to twist the straightforward definition by cases into to something horrible involving improper integrals and whatnot that looks uniform at first sight -- but what if that twisted definition takes twenty times as long to compute than either of the plain cases in the straightforward definition? There'll be plenty of time left over for a conditional jump. – Henning Makholm Jan 3 '12 at 0:14
... Excluding horrible integrals and limits (neither of which are particularly cpu-friendly), the best you can hope for is to hide the conditional jump with prettier notation such as Iverson brackets or step functions, but all that will buy you is at best to add a function call to your expenses, relative to the straightforward definition. – Henning Makholm Jan 3 '12 at 0:16
What language are you using? A number of languages allow for a construction like the Iverson bracket; that is, a factor that is equal to 1 when a condition is true, and 0 if a condition is false... – J. M. Jan 3 '12 at 1:01

This is a piecewise-defined function. To write this in a programming language setting, you can take three routes:

If/Then: By far the simplest (here's pseudo-Python code)

def f(x):
    if (x > 1 || x < -1):
        return 0
        return math.sin(x)

Ternary Operator: Works in some languages, others it doesn't work. For Java:

public static double f(double x) {
    return (x > 1 || x < -1) ? 0 : Math.sin(x)

Cast Boolean to Numeric Also language dependent. In some languages, a false value is equivalent to $0$, and a true value is equivalent to $1$. This is true of Python:

def f(x):
    return (x > 1)*(x < -1)*math.sin(x)
share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.