I suggest that you approach coding this problem as follows. Ask the student to input the limits of summation and the function that you are summing over as an ordered triple into a mathresponse problem. That is, tell the student to express the answer in the form  <m>$\sum_{n=a}^{b}f(n)$</m> but just ask them to input the ordered triple a,b,f(n). Then determine if sum(f(n),n,a,b) is equivalent to the desired sum in Maxima.
<div><br>Justin<br></div><div><br></div><div style="color:rgb(102,102,102)">Justin Gray | Senior Lecturer</div><span style="color:rgb(102,102,102)">Department of Mathematics | Simon Fraser University</span><br style="color:rgb(102,102,102)">

<span style="color:rgb(102,102,102)">8888 University Drive, Burnaby | V5A 1S6 | Canada</span><br style="color:rgb(102,102,102)"><span style="color:rgb(102,102,102)">Tel: +1 778.782.4237</span><div><div><br></div></div><br>


<br><br><div class="gmail_quote">On Tue, Mar 20, 2012 at 6:55 PM, Seema Ali <span dir="ltr"><<a href="mailto:sali@vsb.bc.ca">sali@vsb.bc.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<u></u>






<div>


<p><font>I'm working on creating a question that lists the terms of a finite sum and asking the students to enter a solution using sigma notation.  I know you can use the sum() function but I was wondering if it possible to make sure that the students enter a "valid" solution.<br>


<br>
<br>
Example: −5+10−15+20−25+30−35+40<br>
<br>
Some examples of valid solutions:<br>
sum(5*n*(-1)^n,n,1,8)<br>
sum(5*(n-1)*(-1)^(n-1),n,2,9)<br>
sum(5*(n+1)*(-1)^(n+1),n,0,7)<br>
5*sum(n*(-1)^n,n,1,8)<br>
sum(n*(-1)^n,n,1,8)*5<br>
plus other variations<br>
<br>
Some examples of not valid solutions:<br>
sum(0,n,1,8) + 20<br>
sum(1,n,1,20)<br>
20<br>
plus other variations<br>
<br>
Is it possible to have a question like this?  Below is the code that I have so far.  Keep in mind that it is still a work in progress.<br>
<br>
Thanks.<br>
<br>
<br>
<problem><br>
<script type="loncapa/perl">$base      = &random(2,6,1);<br>
$exponent  = &random(2,3,1);<br>
<br>
$firstterm = &random(-1,1,2)* $base;<br>
$numterms  = &random(5,9,1);<br>
$termstyle = &random(0,1,1); #determine if the term is base^n(-1)^m, or mn(-1)^p<br>
<br>
#$termstyle = 0;<br>
<br>
$term = $firstterm;<br>
$sumdisplay  = $term;<br>
$total = $firsterm;<br>
<br>
#calculate the answer<br>
$answer = &choose($termstyle+1, "sum((-$base)^n,n,1,$numterms)","sum($base*n*(-1)^n,n,1,$numterms)");<br>
<br>
<br>
if($firstterm>0)<br>
{<br>
  $answer = "-1*".$answer;<br>
}<br>
<br>
<br>
<br>
for($i=1; $i<$numterms-1; $i++)<br>
{<br>
  if($term>0)<br>
  {<br>
    $sumdisplay .= ' - ';<br>
  }<br>
  else<br>
  {<br>
    $sumdisplay .= ' + ';<br>
  }<br>
 <br>
  if($termstyle==0)<br>
  {<br>
    $term*= -1 * $base;         #term = base^n<br>
   <br>
  }<br>
  else<br>
  {<br>
    #$term = (-1)**($i) * $base *($i+1 ); #term = mn(-1)^n<br>
   if($firstterm>0)<br>
   {<br>
      $term =(-1)**($i) * $base *($i+1 ); #term = mn(-1)^n<br>
<br>
   }<br>
   else<br>
   {<br>
      $term =(-1)**($i+1) * $base *($i+1 ); #term = mn(-1)^n<br>
   }<br>
<br>
<br>
  }<br>
  $total += $term;<br>
  $sumdisplay .= abs($term);<br>
}<br>
<br>
  if($term>0)<br>
  {<br>
    $sumdisplay .= ' - ';<br>
  }<br>
  else<br>
  {<br>
    $sumdisplay .= ' + ';<br>
  }<br>
<br>
  if($termstyle==0)<br>
  {<br>
    #$term = (-1*$base)**($numterms);  #term = base^n<br>
    $term *= -1*$base;<br>
  }<br>
  else<br>
  {<br>
    $term = (-1)**($numterms) * $base*($numterms);  #term = mn(-1)^n<br>
  }<br>
<br>
  $sumdisplay .= abs($term);<br>
  $total += $term;</script><startouttext /><instructions></instructions><endouttext /><startouttext /><m eval='on'>\[ \Large $sumdisplay \]</m><br>
base=$base <br /><br>
numterm=$numterms <br /><br>
total = $total<br /><br>
style = $termstyle<br /><br>
answer = $answer<br /><endouttext /><br>
<mathresponse cas="maxima"><br>
    <answer></answer><br>
    <textline readonly="no" /><br>
   <br>
</mathresponse><br>
</problem><br>
</font>
</p>

</div>
<br>_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href="mailto:LON-CAPA-users@mail.lon-capa.org">LON-CAPA-users@mail.lon-capa.org</a><br>
<a href="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users" target="_blank">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</a><br>
<br></blockquote></div><br>