<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>Forcing a sigma solution</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>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>

</BODY>
</HTML>