2
$\begingroup$

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.

  • 2
    What do you mean by "body"? Do you mean the *graph* of the function, or something else?2012-01-02
  • 0
    @Nikolay: I used TeX to type your equations. Check if this is what you want to say.2012-01-02
  • 0
    No, by function body I didn't mean the graph. Sorry, english isn't my native lang. If the function was f(x)=5x^2, the body would be 5x^2. And my question is if I know the graph, or those sets of rules that define the graph, can I figure out the "body" (or maybe it's called definition) of the function?2012-01-02
  • 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.2012-01-02
  • 0
    I think "syntactic form" was the word that I was looking for. I'm looking for a function definition that I can write with code as an equation, so I can just plug in the variables and get the f's value. It's just much more efficient (CPU time-wise) to have a single equation, than a bunch of equations and 'if' statements and what not. That's why I wanted to know if you can get a working equation out of a definition by rules.2012-01-02
  • 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.2012-01-03
  • 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](http://en.wikipedia.org/wiki/Iverson_bracket) or [step functions](http://en.wikipedia.org/wiki/Heaviside_step_function), but all that will buy you is _at best_ to _add_ a function call to your expenses, relative to the straightforward definition.2012-01-03
  • 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...2012-01-03
  • 0
    In your programming lingo, the function $$f(x) =\left\{ \begin{array}{ll} x^2, & \hbox{if }x\neq 2; \\ 1, & \hbox{if }x=2. \end{array} \right.$$ is a function that takes one argument, $x.$ The "body" of $f$ is a conditional statement (or, if, switch-case, etc). When $x = 2,$ the function, returns (or, evaluates to): $1.$ When $x \ne 2,$ $f$ evaluates to $x^2.$2012-01-03
  • 0
    Thank you all for the comments, seems like conditionals are the way to go. @J.M. I'm using mainly JavaScript and that statement -> varName = (condition) ? value1 : value2; Which people suggested should be faster than going to the trouble of arriving at a one-line definition which includes integrals, limits, etc.2012-01-03
  • 0
    Just out of curiosity, how would you approach the problem that I started with (the second f(x) in the main question)? Henning Makholm's comment made me thing that while it's not worth doing, it's still possible.2012-01-03
  • 1
    @Nikolay: Yes, the "one-liner conditional" works, but `(-1 < x)*Math.sin(x)*(x < 1)` also seems to work nicely in JS... mathematically, you'd write that as $[-1 < x][x < 1]\sin\,x$; this works since $[p\text{ and }q]=[p][q]$.2012-01-03
  • 0
    Wow, I haven't seen that operator before. That's the syntax for an Inverson bracket, right?2012-01-03
  • 0
    Something like that. C-ish languages also allow for a construction like this.2012-01-03
  • 0
    http://jsperf.com/js-conditionals Interesting, turns out 'if' statements are much faster after all (87% faster in that case).2012-01-03

1 Answers 1