4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ What about If? $\endgroup$
    – Kuba
    Aug 16, 2018 at 8:00
  • $\begingroup$ Down vote detected. Thank you! $\endgroup$ Aug 17, 2018 at 12:55

6 Answers 6

8
$\begingroup$

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;
$\endgroup$
0
10
$\begingroup$

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

PrimeFactorization[x_] := Row[#, "\[Cross]"] & @ (Superscript @@@ FactorInteger[x])
$\endgroup$
3
  • $\begingroup$ This solution is not TeXForm friendly. Thank you! $\endgroup$ Aug 16, 2018 at 8:10
  • 9
    $\begingroup$ @FriendlyGhost there is nothing about TeXForm in your question. $\endgroup$
    – Kuba
    Aug 16, 2018 at 8:12
  • $\begingroup$ @FriendlyGhost, use BoxForm`$UseTemplateSlotSequenceForRow = False; before using TeXForm on expressions involving Row.(See Incompatibility of Row and TeXForm) $\endgroup$
    – kglr
    Aug 17, 2018 at 8:12
6
$\begingroup$

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

cross=If[Length[{##}]>1, Cross[##], #]&;
$\endgroup$
1
  • $\begingroup$ Thanks. Is there any method to check the number of arguments instead of using your trick with Length[{...}]? $\endgroup$ Aug 16, 2018 at 8:03
5
$\begingroup$

An alternative solution without defining new functions:

PrimeFactorization[x_] :=

 Superscript @@@ FactorInteger[x] /. y_ /; Length@y < 0 -> Cross @@ y
$\endgroup$
5
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ (+1) This does not resolve the issue with numbers that are a power if a prime though. $\endgroup$ Aug 16, 2018 at 16:59
2
$\begingroup$

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\}$

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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