I am looking for the simplest way to avoid applying Cross to a single argument.
PrimeFactorization[x_] := Cross @@ (Superscript @@@ FactorInteger[x]);
Table[{n, PrimeFactorization[n]}, {n, 200, 250}] // TableForm
I am looking for the simplest way to avoid applying Cross to a single argument.
PrimeFactorization[x_] := Cross @@ (Superscript @@@ FactorInteger[x]);
Table[{n, PrimeFactorization[n]}, {n, 200, 250}] // TableForm
If it is only for displaying purposes you can use Row:
PrimeFactorization[x_] := Row[#, "\[Cross]"] & @ (Superscript @@@ FactorInteger[x])
BoxForm`$UseTemplateSlotSequenceForRow = False; before using TeXForm on expressions involving Row.(See Incompatibility of Row and TeXForm)
– kglr
Aug 17 '18 at 08:12
Since you already use Cross in a way that it's not meant to be used, you can also redefine it and assign a meaning to it when it has only a single argument:
Unprotect[Cross];
Cross[x_] := x;
A bit less severe: Define your own function.
cross[x__] := Cross[x];
cross[x_] := x;
You might define your own function cross, that calls Cross when the number of arguments is larger than 1:
cross=If[Length[{##}]>1, Cross[##], #]&;
Length[{...}]?
– Friendly Ghost
Aug 16 '18 at 08:03
An alternative solution without defining new functions:
PrimeFactorization[x_] :=
Superscript @@@ FactorInteger[x] /. y_ /; Length@y < 0 -> Cross @@ y
For displaying purposes you can also use:
Times @@ Defer@*Power @@@ FactorInteger[10!]
CenterDot @@ Superscript @@@ FactorInteger[10!]
Inactive[Times] @@ Superscript @@@ FactorInteger[10!]
You can use Block in two ways:
Cross so that Cross[t_] := t:PrimeFactorization[x_] := Block[{Cross}, Cross[t_] := t;
Cross @@ Superscript @@@ FactorInteger @ x];
PrimeFactorization /@ {211, 222, 223} // TeXForm
$\left\{211^1,2^1\times 3^1\times 37^1,223^1\right\}$
Sequence as Cross:PrimeFactorization2[x_] := Block[{Sequence = Cross},
## & @@ Superscript @@@ FactorInteger @ x];
PrimeFactorization2 /@ {211, 222, 223} // TeXForm
$\left\{211^1,2^1\times 3^1\times 37^1,223^1\right\}$
If? – Kuba Aug 16 '18 at 08:00