4

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

enter image description here

Friendly Ghost
  • 337
  • 2
  • 7

6 Answers6

10

If it is only for displaying purposes you can use Row:

PrimeFactorization[x_] := Row[#, "\[Cross]"] & @ (Superscript @@@ FactorInteger[x])
Kuba
  • 136,707
  • 13
  • 279
  • 740
8

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;
Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
6

You might define your own function cross, that calls Cross when the number of arguments is larger than 1:

cross=If[Length[{##}]>1, Cross[##], #]&;
Fred Simons
  • 10,181
  • 18
  • 49
5

An alternative solution without defining new functions:

PrimeFactorization[x_] :=

 Superscript @@@ FactorInteger[x] /. y_ /; Length@y < 0 -> Cross @@ y
Fraccalo
  • 6,057
  • 13
  • 28
5

For displaying purposes you can also use:

Times @@ Defer@*Power @@@ FactorInteger[10!]

CenterDot @@ Superscript @@@ FactorInteger[10!]

Inactive[Times] @@ Superscript @@@ FactorInteger[10!]

enter image description here

chyanog
  • 15,542
  • 3
  • 40
  • 78
2

You can use Block in two ways:

  1. temporarily re-define 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\}$

  1. temporarily define 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\}$

kglr
  • 394,356
  • 18
  • 477
  • 896