Get the Mathematica code used to process a Wolfram Alpha query?

Hello

Let’s take a simple example:

WolframAlpha["get arclength of sin of x from 0 to 3Pi/2"]

I get back in a pod the symbolic result with its numeric value (5.73) and in another pod a nice graphic.

Without the help of WolframAlpha

ArcLength[{Sin[\[Theta]]}, {\[Theta], 0, 3 Pi/2 }] 

which returns 3 and I’m fairly sure this answer is correct

So the first pod has a different answer and I would like to know which Mathematica input code did WolframAlpha use in order to understand what is going on (and also how the symbolic integral was constituted in the output).

The graphics in the second pod would take me a long time to achieve with Mathematica only. Wouldn’t it be very pedagogic if the code built to produce it could be accessed ?

Thanks

Hi Jan,

most likely Wolfram|Alpha used this:

ArcLength[{\[Theta], Sin[\[Theta]]}, {\[Theta], 0, 3 Pi/2}] // N

which evaluates to 5.7303. That does actually make sense if you ask about the length of the curve, which should be larger than 3. Here is a simple example which substitutes the Sine curve by three straight lines (or two depending on your philosophical point of view):

Show[ParametricPlot[{\[Theta], Sin[\[Theta]]}, {\[Theta], 0, 3 Pi/2}],
  Graphics[Line[{{0, 0}, {Pi/2, 1}, {Pi, 0}, {3 Pi/2, -1}}]]]

Clearly, the black line is shorter than the sine curve. And the total length of the black lines is:

ArcLength[Line[{{0, 0}, {Pi/2, 1}, {Pi, 0}, {3 Pi/2, -1}}]] // N

which evaluates to 5.58629 and is a lower bound to the length of the sine curve. You are doing something quite different. You look at the vertical motion only. In a two dimensional plot this corresponds to three stretches of lines each of length 1. So you are doing this:

Total[ArcLength /@ (Line /@ Partition[Table[{0, Sin[\[Theta]]}, {\[Theta], 0, 3 Pi/2, Pi/2}], 2, 1])]

which gives 3.

Cheers,
M.

PS: In general if you want to know what Wolfram|Alpha does this is a useful approach: Type in an equal sign at the beginning of the input line in Mathematica and then use the same input you used for Wolfram|Alpha:

ScreenShot2016-04-22at16.14.19.png

This evaluates to

ScreenShot2016-04-22at16.14.27.png

which shows what Wolfram|Alpha does. Note that this function is equivalent to my ArcLength function.

Thanks Marco

My question was more general than for this example with the length of an arc (and my MMA code was for something else).

I don’t know how general your answer is as I notice that WolframAlpha does not use the ArcLength function which is rather new (and I suspect most new functions can be obtained using functions available in older MMA versions)

You left unanswered the second part of my question about the pod with the graphics. I’m not asking what the code is to generate it (I can do that, albeit not at the click of the fingers) but how do you get it from any WolframAlpha query (if that functionality is available, it would be very nice)

Regards

Hi,

You left unanswered the second part of my question about the pod with
the graphics. I’m not asking what the code is to generate it (I can do
that, albeit not at the click of the fingers) but how do you get it
from any WolframAlpha query (if that functionality is available, it
would be very nice)

Like this?

WolframAlpha["get arclength of sin of x from 0 to 3Pi/2", {{"Plot", 1}, "Content"}]

My question was more general than for this example with the length of
an arc (and my MMA code was for something else). I don’t know how
general your answer is as I notice that WolframAlpha does not use the
ArcLength function which is rather new (and I suspect most new
functions can be obtained using functions available in older MMA
versions)

I am not sure I understand. I think that the answer is quite general in the sense that it gives you what Wolfram|Alpha uses. The first solution (using ArcLength) was just what I intuitively used because it is less typing than the automatic solution that Wolfram|Alpha creates.

Cheers,

M.

Thanks Marco

We are nearly there:

 WolframAlpha["get arclength of sin of x from 0 to 3Pi/2", {{"Plot", 1}, "Content"}]

gets just the graphics and not the code that created it.

By toying a little, I saw that with

 WolframAlpha["get arclength of sin of x from 0 to 3Pi/2", {{"Plot",    1}, "Input"}]

I get at least the first part of what I’m looking for. But how can you ask WolframAlpha to return the code that created the whole graphics?

Regards

But how can you ask WolframAlpha to return the code that created the
whole graphics?

I don’t think that is possible.

Cheers,

M.