1

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?

wisedoe
  • 239
  • 1
  • 7
  • 1
    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]? – m_goldberg Nov 06 '15 at 21:35

1 Answers1

2

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  *)
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 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. – wisedoe Nov 08 '15 at 13:33
  • With BaseExponent[ a_.Complex[r_, i_]] := {Complex[r, i], 1} we have BaseExponent[(1 + I Sqrt[3])] = {1 + I Sqrt[3], 1} – wisedoe Nov 08 '15 at 14:53
  • @evansdoe - added additional case. Note your comment left out factor of a on RHS of definition. – Bob Hanlon Nov 08 '15 at 15:50