1
$\begingroup$

I want to write a function say BaseExponent that will output the base and exponent of a number. In particular it should do the following:

BaseExponent[(1 + I Sqrt[3])^(1/72)] = {(1 + I Sqrt[3]), 1/72}
BaseExponent[72] = {72, 1}
BaseExponent[1/4] = {1/4, 1}
BaseExponent[Sqrt[-3]] = {-3, 1/2}
BaseExponent[I Sqrt[3]] = {-3, 1/2}
BaseExponent[(3/4)^(1/4)] = {3/4, 1/4}

I started by doing the following:

BaseExponent[a_] /; (! FreeQ[a, Power]) := {a[[1]], a[[2]]}
BaseExponent[a_Integer] := {a, 1}
BaseExponent[a_Rational] := {a, 1}

What I have supplied takes care of the first three examples but definitely not rest. Any ideas on how to extend this to cover all the cases I have provided in the example above?

$\endgroup$
  • 1
    $\begingroup$ You need to give a complete and consistent specification for what constitutes a base, what constitutes an exponent, and what constitutes an admissible expression. For example, if I Sqrt[3] is to give {-3, 1/2}, does it follow that 2 Sqrt[3] is to give {12, 1/2}? Further, what you to get from expressions such as Surd[12, 2] and CubeRoot[12]? $\endgroup$ – m_goldberg Nov 6 '15 at 21:35
2
$\begingroup$

This should get you closer

BaseExponent[
  a_. Power[b_, e_]] := ({a^(1/e) b, 
    e} /.
   {a2_. Power[b2_, e2_], e3_} :> {a2^(1/e2) b2, e3*e2})
BaseExponent[a_Integer] := {a, 1}
BaseExponent[a_Rational] := {a, 1}

BaseExponent[a_. Complex[r_, i_]] :=
 {a Complex[r, i], 1} (*  EDIT: added per evansdoe comment  *)


And @@ {
  BaseExponent[(1 + I Sqrt[3])^(1/72)] ===
   {(1 + I Sqrt[3]), 1/72},
  BaseExponent[72] === {72, 1},
  BaseExponent[1/4] === {1/4, 1},
  BaseExponent[Sqrt[-3]] === {-3, 1/2},
  BaseExponent[I Sqrt[3]] === {-3, 1/2},
  BaseExponent[(3/4)^(1/4)] === {3/4, 1/4},
  BaseExponent[Surd[12, 2]] === {12, 1/2},
  BaseExponent[CubeRoot[12]] === {12, 1/3},
  BaseExponent[a Complex[r, i]] === {a Complex[r, i], 1}}

(*  True  *)
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks but this case BaseExponent[(1 + I Sqrt[3])] that is complex numbers (a + I b) with exponents as 1 was not considered. I forgot to include this case in my question. I will figure it out and post the answer later. However anyone is also welcome to give it a try. $\endgroup$ – saintdoe Nov 8 '15 at 13:33
  • $\begingroup$ With BaseExponent[ a_.Complex[r_, i_]] := {Complex[r, i], 1} we have BaseExponent[(1 + I Sqrt[3])] = {1 + I Sqrt[3], 1} $\endgroup$ – saintdoe Nov 8 '15 at 14:53
  • $\begingroup$ @evansdoe - added additional case. Note your comment left out factor of a on RHS of definition. $\endgroup$ – Bob Hanlon Nov 8 '15 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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