Message Boards Message Boards

0
|
23643 Views
|
10 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Step By Step output with PHP API (for Wolfram|Alpha)

Posted 11 years ago
I am using php api to query my math expressions, however, I am not getting any step-by-step solution in my output. I tried something like even query?&format=plaintext&podstate=Result__Show+steps, from http://community.wolframalpha.com/viewtopic.php?f=31&t=141115. I checked the documentation, however I did not get any answer.
Is there any option available?

regards
venkatesan
10 Replies
Posted 11 years ago

plz get me full your code venkatesanr Iyengar

POSTED BY: lam huynh
Hi!

Thanks for your continued support. Finally I could get all the necessary things (except <infos>). Please check at
http://studyonline.co.in/resources/test.php?q=second%20derivative%20of%20Sin[Log[x]]
However, all the links are relative links and reads something iike pod.jsp?id=MSP33941fec5115c731f3d000004i99e6g09g6c5ie0&s=29&button=1. What are the absolute urls for these links. Can you please help me

regards
Hi!

Thanks for your support. I understood how to do get all informations. wolfram alpha documentation is slightly confusing and probably resulted in my stupid questions above. Thanks once again

regards
I'm not familiar at all with any PHP libraries for this. 

You posted this URL: http://api.wolframalpha.com/v2/query?appid=xxxx&input=second+differential+Sin%5BLog%5Bx%5D%5D

But If I'm not mistaken you'll have to make use of "&podstate=ndefiniteIntegral__Step-by-step+solution"  in the URL if that does work. This fact is independant of whatever programming language you are using. 
POSTED BY: Sean Clarke
This is what I have done to display the images steps and infos
 <?php
 
 $completeurl="http://api.wolframalpha.com/v2/query?format=html,image,plaintext&appid=XXX" . "&input=" . $_GET['q'];
 $xml = simplexml_load_file($completeurl);//simplexml_load_file($completeurl,'SimpleXMLElement', LIBXML_NOCDATA);
 function xml_attribute($object, $attribute)
 {
    if(isset($object[$attribute]))
         return (string) $object[$attribute];
 }
$numpods = xml_attribute($xml, 'numpods');
for ($i = 0; $i < $numpods; $i++) {
    echo "<h1>" . xml_attribute($xml->pod[$i], 'title')."</h1><br />";//echo $xml->pod[$i]->asXML();
    echo xml_attribute($xml->pod[$i]->img,'src');
    $numsubpods = xml_attribute($xml->pod[$i],'numsubpods');
        for ($j = 0; $j < $numsubpods; $j++) {
            echo "<img src=".xml_attribute($xml->pod[$i]->subpod[$j]->img,'src')."/><br />";
        }
    $states = xml_attribute($xml->pod[$i]->states,'count');
        for ($numstate = 0; $numstate < $states; $numstate++) {
            echo "<br /><button type=\"button\">". xml_attribute($xml->pod[$i]->states->state[$numstate],'name') . "</button>: " . xml_attribute($xml->pod[$i]->states->state[$numstate],'input') . "<br />";
        }
    $infos = xml_attribute($xml->pod[$i]->infos,'count');
        for ($numinfo = 0; $numinfo < $infos; $numinfo++) {
            echo "<br /><img src=" . xml_attribute($xml->pod[$i]->infos->info[$numinfo]->img,'src') . "/>|<a href=" . xml_attribute($xml->pod[$i]->infos->info[$numinfo]->link,'url') . ">" . xml_attribute($xml->pod[$i]->infos->info[$numinfo]->link,'text') . "</a><br />";
        }
    echo "<hr />";
}
?>
All I need is the correct format/url to dsiplay step-by-step calculation.
Also I tried to display the <![CDATA[ nodes in the xml output however, only the first CDDATA is displayed and other are ignored. Also the step-by-step url looks like a relative url like pod.jsp?id........ What is its absolute url?
Sorry for troubling you guys.
regards
Here is the api result of http://api.wolframalpha.com/v2/query?appid=xxxx&input=second+differential+Sin%5BLog%5Bx%5D%5D
  This XML file does not appear to have any style information associated with it. The document tree is shown below.
  
  <queryresult success="true" error="false" numpods="8" datatypes="D" timedout="InterestingDefiniteIntegrals,InterestingMultiDimensionalDefiniteIntegrals" timedoutpods="" timing="4.431" parsetiming="0.312" parsetimedout="false" recalculate="http://www4c.wolframalpha.com/api/v2/recalc.jsp?id=MSPa38811gd8h117263h7gb100001gegegicegc75ge1&s=40" id="MSPa38821gd8h117263h7gb100004288d84a48a6g110" host="http://www4c.wolframalpha.com" server="40" related="http://www4c.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa38831gd8h117263h7gb1000036597d9879hec6ai&s=40" version="2.6">
  
  <pod title="Derivative" scanner="Derivative" id="Input" position="100" error="false" numsubpods="1">
  
  <subpod title="">
  
  <plaintext>
 
 d^2/dx^2(sin(log(x))) = -(sin(log(x))+cos(log(x)))/x^2
 
 </plaintext>
 
 <img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38841gd8h117263h7gb1000042eg2b52978451ba?MSPStoreType=image/gif&s=40" alt="d^2/dx^2(sin(log(x))) = -(sin(log(x))+cos(log(x)))/x^2" title="d^2/dx^2(sin(log(x))) = -(sin(log(x))+cos(log(x)))/x^2" width="294" height="40"/>
 
 </subpod>
 
 <states count="1">
 
 <state name="Step-by-step solution" input="Input__Step-by-step solution"/>
 
 </states>
 
 <infos count="1">
 
 <info text="log(x) is the natural logarithm">
 
 <img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38851gd8h117263h7gb1000050cc69cafh15dc0e?MSPStoreType=image/gif&s=40" alt="log(x) is the natural logarithm" title="log(x) is the natural logarithm" width="192" height="16"/>
 
 <link url="http://reference.wolfram.com/mathematica/ref/Log.html" text="Documentation" title="Mathematica"/>
 
 <link url="http://functions.wolfram.com/ElementaryFunctions/Log" text="Properties" title="Wolfram Functions Site"/>
 
 <link url="http://mathworld.wolfram.com/NaturalLogarithm.html" text="Definition" title="MathWorld"/>
 
 </info>
 
 </infos>
 
 </pod>
 
 <pod title="Plots" scanner="Plotter" id="Plot" position="200" error="false" numsubpods="2">
 
 <subpod title="">
 
 <plaintext/>
 
 <img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38861gd8h117263h7gb10000371881f0hi7433db?MSPStoreType=image/gif&s=40" alt="" title="" width="314" height="97"/>
 
 <states count="1">
 
 <statelist count="2" value="Complex-valued plot" delimiters="">
 
 <state name="Complex-valued plot" input="Plot__1_Complex-valued plot"/>
 
 <state name="Real-valued plot" input="Plot__1_Real-valued plot"/>
 
 </statelist>
 
 </states>
 
 </subpod>
 
 <subpod title="">
 
 <plaintext/>
 
 <img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38871gd8h117263h7gb1000050ha92191ea4igh8?MSPStoreType=image/gif&s=40" alt="" title="" width="335" height="125"/>
 
 <states count="1">
 
 <statelist count="2" value="Complex-valued plot" delimiters="">
 
 <state name="Complex-valued plot" input="Plot__2_Complex-valued plot"/>
 
 <state name="Real-valued plot" input="Plot__2_Real-valued plot"/>
 
 </statelist>
 
 </states>
 
 </subpod>
 
 </pod>
 
 <pod title="Alternate forms" scanner="Simplification" id="AlternateForm" position="300" error="false" numsubpods="3">
 
 <subpod title="">
 
 <plaintext>(-sin(log(x))-cos(log(x)))/x^2</plaintext>
 
 <img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38881gd8h117263h7gb100005a748hf868346h50?MSPStoreType=image/gif&s=40" alt="(-sin(log(x))-cos(log(x)))/x^2" title="(-sin(log(x))-cos(log(x)))/x^2" width="168" height="38"/>
 
 </subpod>
 
 <subpod title="">
 
 <plaintext>-(sin(log(x)))/x^2-(cos(log(x)))/x^2</plaintext>

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38891gd8h117263h7gb100004c746f7175fcdc9g?MSPStoreType=image/gif&s=40" alt="-(sin(log(x)))/x^2-(cos(log(x)))/x^2" title="-(sin(log(x)))/x^2-(cos(log(x)))/x^2" width="172" height="38"/>

</subpod>

<subpod title="">

<plaintext>-(sqrt(2) sin(log(x)+pi/4))/x^2</plaintext>

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38901gd8h117263h7gb1000014f7h436ieef84i7?MSPStoreType=image/gif&s=40" alt="-(sqrt(2) sin(log(x)+pi/4))/x^2" title="-(sqrt(2) sin(log(x)+pi/4))/x^2" width="138" height="48"/>

</subpod>

<states count="1">

<state name="More" input="AlternateForm__More"/>

</states>

</pod>

<pod title="Root" scanner="Reduce" id="SymbolicSolution" position="400" error="false" numsubpods="1" primary="true">

<subpod title="">

<plaintext>

x = e^(pi n-pi/4), e^(pi n-pi/4) !=0, n element Z

</plaintext>

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38911gd8h117263h7gb10000472e73b4die5g22h?MSPStoreType=image/gif&s=40" alt="x = e^(pi n-pi/4), e^(pi n-pi/4) !=0, n element Z" title="x = e^(pi n-pi/4), e^(pi n-pi/4) !=0, n element Z" width="500" height="24"/>

</subpod>

<states count="2">

<state name="Approximate form" input="SymbolicSolution__Approximate form"/>

<state name="Step-by-step solution" input="SymbolicSolution__Step-by-step solution"/>

</states>

<infos count="1">

<info text="? is the set of integers">

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38921gd8h117263h7gb100005742dfb869ab5a9f?MSPStoreType=image/gif&s=40" alt="? is the set of integers" title="? is the set of integers" width="144" height="16"/>

<link url="http://reference.wolfram.com/mathematica/ref/Integers.html" text="Documentation" title="Documentation"/>

<link url="http://mathworld.wolfram.com/Z.html" text="Definition" title="MathWorld"/>

</info>

</infos>

</pod>

<pod title="Indefinite integral" scanner="Integral" id="IndefiniteIntegral" position="500" error="false" numsubpods="1" primary="true">

<subpod title="">

<plaintext>

integral -(cos(log(x))+sin(log(x)))/x^2 dx = (cos(log(x)))/x+constant

</plaintext>

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38931gd8h117263h7gb100003bf4gie47d3i50d0?MSPStoreType=image/gif&s=40" alt=" integral -(cos(log(x))+sin(log(x)))/x^2 dx = (cos(log(x)))/x+constant" title=" integral -(cos(log(x))+sin(log(x)))/x^2 dx = (cos(log(x)))/x+constant" width="372" height="38"/>

</subpod>

<states count="1">

<state name="Step-by-step solution" input="IndefiniteIntegral__Step-by-step solution"/>

</states>

</pod>

<pod title="Local maxima" scanner="GlobalExtrema" id="LocalMaximum" position="600" error="false" numsubpods="1">

<subpod title="">

<plaintext>

max{(d^2 sin(log(x)))/(dx^2)} = -e^(-4 (pi n+tan^(-1)(3+sqrt(10)))) (sin(2 tan^(-1)(3+sqrt(10)))+cos(2 tan^(-1)(3+sqrt(10)))) at x = e^(2 n pi+2 tan^(-1)(3+sqrt(10))) for integer n

</plaintext>

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38941gd8h117263h7gb100003i0c24dfi03815ib?MSPStoreType=image/gif&s=40" alt="max{(d^2 sin(log(x)))/(dx^2)} = -e^(-4 (pi n+tan^(-1)(3+sqrt(10)))) (sin(2 tan^(-1)(3+sqrt(10)))+cos(2 tan^(-1)(3+sqrt(10)))) at x = e^(2 n pi+2 tan^(-1)(3+sqrt(10))) for integer n" title="max{(d^2 sin(log(x)))/(dx^2)} = -e^(-4 (pi n+tan^(-1)(3+sqrt(10)))) (sin(2 tan^(-1)(3+sqrt(10)))+cos(2 tan^(-1)(3+sqrt(10)))) at x = e^(2 n pi+2 tan^(-1)(3+sqrt(10))) for integer n" width="466" height="106"/>

</subpod>

<states count="1">

<state name="Approximate form" input="LocalMaximum__Approximate form"/>

</states>

<infos count="1">

<info text="tan^(-1)(x) is the inverse tangent function">

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38951gd8h117263h7gb100005953e8gch8gfa66a?MSPStoreType=image/gif&s=40" alt="tan^(-1)(x) is the inverse tangent function" title="tan^(-1)(x) is the inverse tangent function" width="254" height="18"/>

<link url="http://reference.wolfram.com/mathematica/ref/ArcTan.html" text="Documentation" title="Mathematica"/>

<link url="http://functions.wolfram.com/ElementaryFunctions/ArcTan" text="Properties" title="Wolfram Functions Site"/>

<link url="http://mathworld.wolfram.com/InverseTangent.html" text="Definition" title="MathWorld"/>

</info>

</infos>

</pod>

<pod title="Local minima" scanner="GlobalExtrema" id="LocalMinimum" position="700" error="false" numsubpods="1">

<subpod title="">

<plaintext>

min{(d^2 sin(log(x)))/(dx^2)} = -e^(-4 (pi n+tan^(-1)(3-sqrt(10)))) (sin(2 tan^(-1)(3-sqrt(10)))+cos(2 tan^(-1)(3-sqrt(10)))) at x = e^(2 n pi+2 tan^(-1)(3-sqrt(10))) for integer n

</plaintext>

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38961gd8h117263h7gb1000023if7g666cc91baf?MSPStoreType=image/gif&s=40" alt="min{(d^2 sin(log(x)))/(dx^2)} = -e^(-4 (pi n+tan^(-1)(3-sqrt(10)))) (sin(2 tan^(-1)(3-sqrt(10)))+cos(2 tan^(-1)(3-sqrt(10)))) at x = e^(2 n pi+2 tan^(-1)(3-sqrt(10))) for integer n" title="min{(d^2 sin(log(x)))/(dx^2)} = -e^(-4 (pi n+tan^(-1)(3-sqrt(10)))) (sin(2 tan^(-1)(3-sqrt(10)))+cos(2 tan^(-1)(3-sqrt(10)))) at x = e^(2 n pi+2 tan^(-1)(3-sqrt(10))) for integer n" width="466" height="106"/>

</subpod>

<states count="1">

<state name="Approximate form" input="LocalMinimum__Approximate form"/>

</states>

</pod>

<pod title="Limit" scanner="GlobalExtrema" id="Limit" position="800" error="false" numsubpods="1">

<subpod title="">

<plaintext>

lim_(x->±infinity) -(cos(log(x))+sin(log(x)))/x^2 = 0

</plaintext>

<img src="http://www4c.wolframalpha.com/Calculate/MSP/MSP38971gd8h117263h7gb100005787bh47d75ae4ie?MSPStoreType=image/gif&s=40" alt="lim_(x->±infinity) -(cos(log(x))+sin(log(x)))/x^2 = 0" title="lim_(x->±infinity) -(cos(log(x))+sin(log(x)))/x^2 = 0" width="231" height="38"/>

</subpod>

</pod>

<assumptions count="1">

<assumption type="Function" word="Log" template="Assuming "${word}" is ${desc1}. Use ${desc2} instead" count="2">

<value name="Log" desc="the natural logarithm" input="*FunClash.Log-_*Log.Log10-"/>

<value name="Log10" desc="the base 10 logarithm" input="*FunClash.Log-_*Log10.Log-"/>

</assumption>

</assumptions>

</queryresult>
Can you please suggest the correct format to get the step-by-step output, additional calculations etc
regards
I think there's a misconception about what the API does. The API does exactly what you see in the API explorer. It produces XML. You can do whatever you want with the XML once you have it.

This is the XML for the pod we are interested in  from the example:
  <pod title='Indefinite integral'
      scanner='Integral'
      id='IndefiniteIntegral'
      position='100'
      error='false'
      numsubpods='1'
      primary='true'>
   <subpod title=''>
    <plaintext> integral sin(x) dx = -cos(x)+constant</plaintext>
   <img src='http://www1.wolframalpha.com/Calculate/MSP/MSP7131b1i7ic0iaic4ic200002ddhh8b9ccihi189?MSPStoreType=image/gif&amp;s=14'
       alt=' integral sin(x) dx = -cos(x)+constant'
       title=' integral sin(x) dx = -cos(x)+constant'
       width='218'
       height='34' />
  </subpod>
  <states count='1'>
   <state name='Step-by-step solution'
       input='IndefiniteIntegral__Step-by-step solution' />
  </states>
 </pod>
It has a state tag, much like the example in the documentation which works with the pod state. So according to the documentation, if you wanted to simulate having clicked the step-by-step solution button, it looks like you'd add "&podstate=ndefiniteIntegral__Step-by-step+solution" to the URL.

If you are having trouble still, what is the URL you are trying to use? What is XML that results from it? Of course, you probably shouldn't paste your API key. I'm not sure whether the API will give you the step by step results, but this how you'd try it out. 
POSTED BY: Sean Clarke
Hi Sean,

Thanks for the reply. I am trying to get it implemented with my appid in php my localhost in my department and the php front-end does not probably display all those things.
How to display all the subpods and states and infos?
Should I now write front-end html to display as it does in wolframalpha.com/input?i= .
Is it possible to get the html template that is being used in wolframalpha.com/input? so that I can just use them straight away.
I went through the documentation, however, it is not explicit about the functions used in api and implementation rules/protocols

regards
I think  that you'd probably have to work with pod-states to get that. This is because you have to click on a pod on the website to get that information. Consider this query:

http://www.wolframalpha.com/input/?i=integrate+Sin%5Bx%5D

You have to click on the button in the first pod to get the step by step instructions. When this is neccessary, you have to work with pod states. Please read through the API documentation:

http://products.wolframalpha.com/api/documentation.html

Especially the part about podstates.  You can see examples of what the API returns using the API Explorer:

http://products.wolframalpha.com/api/explorer.html
POSTED BY: Sean Clarke
I think there the sample php library provided at http://products.wolframalpha.com/api/libraries.html is incomplete. I was trying 'second derivative of Sin[Log]' . api xml output shows 8 pods and all 8 are displayed.  However, only the first subpod is diplayed, and states are not displayed at all. Is there any documentation for php api library.

thanks in advance
regards 
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract