I am trying to use CenterDot and Superscript, in conjunction with Apply to write out the prime factorization of any given integer. Everything works well UNLESS the prime factorization of the number contains only one prime (to some power). This is because CenterDot must have two arguments I guess.
So let's get going here...
primeFactorForm[n_] := CenterDot[Apply[Superscript, FactorInteger[n], {1}]]
primeFactorForm[9]
gives me
CenterDot[3^2]
and I don't want that obviously. So I created another function to avoid this problem, and put it before my primeFactorForm function that I created....
myCenterDot[{a_^b_}] := a^b
myCenterDot[x_] := Apply[CenterDot, x]
and then I changed my original function
primeFactorForm[n_] :=
myCenterDot[Apply[Superscript, FactorInteger[n], {1}]]
So now it SHOULD just return a^b IF the input is in the form {a^b}, but it still returns
CenterDot[3^2]
instead of just writing it out like i want it to. What have I done wrong? Just some minor syntax errors I hope! Thanks very much in advance!
EDIT: Sorry guys, I should have also mentioned this: when I suggested to my instructor that I add an If statement, he said that doing what I did (creating two myCenterDot functions) would create the same end result without the need of creating an If statement. So he basically said that I can avoid the use of an If statement by doing this that way....hmmm....
CenterDot
is getting tripped up over the fact that it needs two or more arguments. Adding anIf
statement to handle that case is one way to fix it. $\endgroup$If
statement or two definitions, only a simple replacement to handle the case of a "singleton" inCenterDot
. I also demonstrate how an actual formatting wrapper is created. $\endgroup$