Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

I watched this video: http://www.khanacademy.org/video/introduction-to-limits--hd?playlist=Calculus

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 khanacademy.org 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|improve this question
2  
What do you mean by "body"? Do you mean the graph of the function, or something else? –  NKS Jan 2 '12 at 22:38
4  
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
1  
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
2  
... 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
1  
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

1 Answer 1

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
    else:
        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|improve this answer

Your Answer

 
discard

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.