Search code examples
formatoutputwolfram-mathematica

How do I get Mathematica not to multiply a vector by a scalar elementwise, but leave it as the scalar times the vector


In Mathematica I have the variable u defined as follows:

u = {1,2,3}

Now I want the product a*u to show as:

a {1,2,3}

but a*u returns this:

{a,2 a,3 a}

I have tried HoldForm and other things, but I cannot make it work. Any help?


Solution

  • u = {1, 2, 3};
    
    a u
    

    {a, 2 a, 3 a}

    s = Inactivate[a u]
    

    a {1, 2, 3}

    Activate[s]
    

    {a, 2 a, 3 a}

    InputForm[s]
    

    Inactive[Times][a, {1, 2, 3}]