# Using Wolfram Alpha-syntax for transpose, etc

Consider this expression:

{{0, 1}, {0, 2}, {0, 3}}*Transpose[{{0, 1}, {0, 2}, {0, 3}}]


It returns an error in Mathematica but works perfectly fine in Wolfram Alpha.

Is there a way I can get Mathematica to recognize this syntax? Why is there a difference between the ways that Mathematica and Alpha interpret this expression?

Short Version

You can get Mathematica to convert WolframAlpha-style free-form input into a valid expression using CTRL+= or by starting an input expression with =: Note how Mathematica made sense of two alternative free-form expressions of the same thing, and converted each into the same valid expression involving the Dot operator.

Longer Version: Why is there a difference?

WolframAlpha is primarily aimed at interpreting input from a human and delivering a response back to that human. As such, it uses inference heavily to try to make sense of what the user entered. In this case, WolframAlpha correctly inferred that the product operation in the expression is actually a matrix multiplication. This is a very reasonable assumption given that WWW users might not be familiar with the ins and outs of Mathematica syntax.

In contrast, the Mathematica system serves two goals. It shares the need to interact with a human just like WolframAlpha. But it also allows Mathematica users (i.e. programmers) to write code intended to be executed by machine as part of larger composite systems. In the first case, inferencing is welcomed as the user can immediately see whether the interpretation was correct. In the second case, inferencing is harmful since there is no human in the loop to spot any misinterpretation.

WolframAlpha is treating the exhibited expression as free-form input. The fact that it resembles an Mathematica expression is coincidental. One gets the same result by entering, for example:

((0, 1), (0, 2), (0, 3)) * Transpose ((0, 1), (0, 2), (0, 3))

This is not a valid Mathematica expression, yet WolframAlpha takes it in stride.

The good news is that Mathematica supports both use cases directly. By starting an input expression with =, we can tell Mathematica that we want it to infer our meaning from free-form input: Note how the product operator has been quietly re-interpreted as the matrix-multiplying Dot operator.

Alternatively, we can use the unambiguous formal Mathematica syntax that makes no assumptions, reporting errors instead: Here, Mathematica is not making any assumptions. We specified * (Times), so it will attempt to use *. It so happens that Times can be applied to matrices, meaning that the multiplication is to be threaded across matching numbers into the two matrices. But... the two matrices do not have the same dimensions to the number cannot be matched up. What is the error? Are the matrix arguments wrong, or is the operator wrong? Mathematica won't guess, so it reports an error to the user (programmer) to fix it.

• In the course of routine maintenance I was preparing to delete this old, closed question, but I feel your answer has lasting value. Would you consider improving the question to put this into the reopen queue? – Mr.Wizard Sep 2 '15 at 22:10
• @Mr.Wizard I gave it a try. – WReach Sep 2 '15 at 23:25

If you are looking for matrix multiplication, use . (or the Dot command).

Dot is a special case of Inner

list = {{0, 1}, {0, 2}, {0, 3}};

Inner[Times, list, Transpose[list], Plus] // MatrixForm list = {{1, 1}, {1, 2}, {1, 3}}

Inner[Power, list, Transpose[list], Plus] // MatrixForm Also possible:

Outer[Times, {1, 2, 3}, {1, 2, 3}] // MatrixForm 