Have you implemented this? It seems like overflow would be a huge problem.
To be fair, I think he acknowledged that in the last paragraph.
Nope, still here. But the earlier replies are correct, this solution doesn’t work because we can only raise to positive integer powers.
Am I missing something? Isn’t it just (X*X)/X?
If X is negative, the result of that operation will be negative, and therefore not the absolute value (which is always positive). X*X is always positive, but if X is negative and you divide a positive number by a negative number, you get a negative number.
D’oh :smack:
It’s sort of amusing just how many mistaken posts in this thread would’ve easily been seen to be flawed by the most basic laws of expression simplification (things like division cancelling out multiplication (whenever the division is well-defined, that is)). For example, posts # 12, 21, 24, 31, 44.
I don’t mean to pick on anyone; I’m just amused is all. Something about this quest makes people throw out what would otherwise be mathematical commonsense. I suspect people subconsciously half-remember something like that sqrt(x^2) doesn’t always equal x (due to the branch cut involved in defining principal square roots), and then misrecall this into failure of cancellation rules in different contexts.
Guess I missed that detail in the OP; another one bites the dust…
I agree; the solution is not practical, but I spent on-and-off an afternoon thinking about it, and damn if I’m going to throw that away…
I was post #12. To be honest, I’m a friggen math major, but it’s been so long since I’ve even cracked a text book it didn’t dawn on me until someone pointed it out. At least I pointed out in my post that it was wrong, and other then getting the correct answer I followed the OP’s rules (namely I didn’t raise to a non integer power).
This nails it, almost. Let me extend the reasoning one step. Conceivably, you could have such a function that blows up at 0 and is absolute value everywhere else. So it suffices to eliminate this possibility. It is only necessary to observe that a rational function that blows up at a point is unbounded in every interval containing that point. Since absolute value is bounded in evey interval containing 0, this is not possible.
Indeed. Or, to do it perhaps most generally, an expression equal to abs(x) at infinitely many points is equal to x at infinitely many points or equal to -x at infinitely many points. If two rational functions agree at infinitely many points, then they are equal wherever they are both defined (since their difference will have infinitely many zeros, and thus must be essentially the constant zero). Therefore, any rational function which is equal to abs(x) at infinitely many points is either equal to x wherever it is defined or equal to -x wherever it is defined. [Please don’t mistake this for the trivial statement that it is equal to x or equal to -x wherever it is defined]. Thus, given any infinite set of inputs containing a positive and a negative, it will not be possible to craft an expression which gives the right answer for all of them.
(And, of course, for any finite set of inputs, it is easy to craft a (contrived, convoluted) polynomial giving the right answer for all of them, so this result is “tight”)
Ok then, since it’s easy, I will venture to ask, for my own education.
The set of my inputs is the set of intergers in the interval [-1000, 1000] What is the polynomial?
It’s the polynomial of degree 2000 that passes through (-1000, 1000), (-999, 999), …, (999, 999), (1000, 1000). With those points, you can generate a system of 2001 linear equations in 2001 variables, and just use Gauss-Jordan reduction to solve for the coefficients. You’ll need some kind of special arithmetic routines to prevent overflow, but those aren’t hard to come by.
Here’s an illustration for the interval [-1, 1]:
We want a polynomial P with P(-1) = 1, P(0) = 0, and P(1) = 1. To get through three points you need a quadratic polynomial, so it has to be of the form P(x) = ax[sup]2[/sup] + bx + c. Evaluate it at -1, 0 and 1 to get 1 = a - b + c, 0 = c and 1 = a + b + c. If you solve, you’ll get a = 1, b = 0 and c = 0, so the polynomial is P(x) = x[sup]2[/sup].
Alas, this margin is too small to contain the answer.
“Easy” and “tedious” are not necessarily mutually exclusive. Though perhaps Indistinguishable should have said “straightforward”.
To expand on this, remember that “trivial” means “someone, somewhere has solved it”.
Which leads trivially to Feynman’s Theorem, which states that mathematicians can only prove trivial theorems.
All right then, chop-chop! I haven’t got all day!
But seriously, thank you for the explanation.
To clarify, this is without the ^ operator. The previous proof involving it doesn’t automatically generalize to cover this case, though I’d be surprised if one could pull off an infinitely often, including a positive and a negative, correct abs(x) with just rational functions and the OP’s crippled exponentiation.