GingerRobot Posted August 28, 2007 Author Share Posted August 28, 2007 Appears to work fine for positive bases Barand, but once we move into negatives, i think there are some problems. For instance, if you input (-1)^0.5 you get 1; though the root of -1 is i. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 28, 2007 Share Posted August 28, 2007 OK modified it output the "i" if neg and power < 1 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 28, 2007 Author Share Posted August 28, 2007 Unfortunately i dont think its quite that simple. For example, you should get answers with the following inputs of: (-1)^1/2 = i (-1)^1/3 = -1 (-1)^1/4 = 0.70711+0.7011i - the numerical values are actually sin(45 degrees) if you're interested At present, your code returns i for all of these inputs. I might take a look later and see if i can come up with a solution. I dont think it's going to be easy though. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 28, 2007 Share Posted August 28, 2007 so it's neg base number and even roots that get the "i" ? (It's 40 years since I studied maths so I'm a bit rusty) Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 28, 2007 Author Share Posted August 28, 2007 It seems so. When raising a negative number to a fractional power, if the denominator is even, you get a complex answer. If it is odd, you get a real answer. I can't seem to figure out how it all works to be honest though. Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 28, 2007 Share Posted August 28, 2007 as far as i know, the order of operations dictates that the numerator of a rational exponent is evaluated first (assuming one re-writes the expression as a power beneath a root sign). by that logic, the only case where a^(m/n) will produce a complex number is when a < 0, m is odd, n is even. regardless, whether a root is complex or not is rather a matter of definitions and semantics in the case of rational exponents, not actual programming. might as well save yourself a headache and take the absolute value of 'a'. as you yourself pointed out, one could simply multiply any given rational expression by 2/2 and obtain an identical exponent (based on group theory) which won't jar your script. you could always add an 'i' to the final output if you want to, but it would be a largely arguable point. Quote Link to comment Share on other sites More sharing options...
btherl Posted August 29, 2007 Share Posted August 29, 2007 However, im fairly sure there is nothing to say that you have to use the fractional power inside the bracket. As far as i know (x^(1/b))^a is identical to (x^b)^(1/a). Definitely one for my maths teacher i think. At your service Take the rule here: (x^m)^n = x^(mn) From this it follows that (x^(1/b))^a = x^(a/b) (x^a)^(1/b) = x^(a/b) I assume that's what you meant, not (x^b)^(1/a) These rules certainly don't work for b=0, and I would have doubts once things start getting negative.. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 29, 2007 Author Share Posted August 29, 2007 Sorry, yes you're right. I put the fraction with the wrong letter. However, you agreeing that (x^(1/b))^a is the same as (x^a)^(a/b) ? In which case, i think im back where i started. Also, whilst you say the rules don't hold for b=0, that is simply due to the fact that x/0 is undefined - however you manipulate the expression, at some point you must divide by b, making the calculation impossible. Quote Link to comment Share on other sites More sharing options...
btherl Posted August 29, 2007 Share Posted August 29, 2007 (x^(1/b))^a is the same as (x^a)^(a/b) (x^(1/b))^a is the same as (x^a)^(1/b), rather Also, whilst you say the rules don't hold for b=0, that is simply due to the fact that x/0 is undefined - however you manipulate the expression, at some point you must divide by b, making the calculation impossible. That's what I meant, sorry for not being clearer. Anyway, what is your current goal, when you say you are back where you started? Are you still thinking about the apparent paradox in your earlier post? I think the solution there is that you simply can't take the 3 and 6 inside, because that rule doesn't apply for x < 0. So you have to use other methods to solve, and those other methods will give you a correct result. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 29, 2007 Author Share Posted August 29, 2007 (x^(1/b))^a is the same as (x^a)^(1/b), rather Whoops. Though it was 7 in the morning -thats my excuse anyway As for current goal, i think i've satisfied my original motivation for posting, which was that i'd noticed that php couldn't deal with negative bases and fractional powers. I've largely just been trying to understand, from a mathematical point of view, how/why it works/doesn't work. I think ill mark this as solved now, although im sure im going to continue my searches on the internet. And thanks everyone, for all your help. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 29, 2007 Share Posted August 29, 2007 I think ill mark this as solved now, although im sure im going to continue my searches on the internet. Solved: I assume this is a real solution, not an imaginary one Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 29, 2007 Author Share Posted August 29, 2007 Haha. I think it probably is an imaginary solution! Im imagining that i understand it all perfectly Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 30, 2007 Share Posted August 30, 2007 The PEAR extension has an add on that can carry variables through a math function and return an answer and do complex numbers such as doing 4(x-2)^2 it would return 4x^2-8X+8 but it requires installation Quote Link to comment Share on other sites More sharing options...
Barand Posted August 30, 2007 Share Posted August 30, 2007 OK, I won't say anything about that returned result. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 30, 2007 Share Posted August 30, 2007 OK, I won't say anything about that returned result. New math rulez Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 30, 2007 Share Posted August 30, 2007 New Math? Math can't be "new" because its not like it didn't existed. Better term would be newly discovered math. Imaginary/complex numbers aren't actually new at all they have been around forever (in the sense of being known and used) Quote Link to comment Share on other sites More sharing options...
btherl Posted August 30, 2007 Share Posted August 30, 2007 I think Barand is talking about this: 4(x-2)^2 = 4(x-2)(x-2) = 4(x^2 - 2x -2x + 4) = 4(x^2 - 4x + 4) = 4x^2 - 16x + 16 No complex numbers involved there.. The lesson is, don't do maths in your head and drive! The same rule applies when not driving. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.