Annotation of doc/help/codingmath.tex, revision 1.2

1.1       riegler     1: \documentclass{article}
                      2: \newcommand {\LC} {LON-CAPA~}
                      3: \title{Implementing Math Problems in \LC using CAS Support}
                      4: \author{Peter Riegler\\ and hopefully other contributers}
                      5: \begin{document}
                      6: \maketitle
                      7: \begin{abstract}
                      8: We describe the \LC interface to computer algebra systems (CAS) which conveniently allows to implement rather sophisticated math problems. 
                      9: \end{abstract}
                     10: \section{Introduction}
                     11: \section{\LC interfaces to CAS}
                     12: There are two interfaces: The first one {\tt \&cas} can be called anywhere from a perl script. Its primary use is to give access to CAS functionality from within perl. 
                     13: The second one {\tt <mathresponse>} is used for doing the complete grading of a problem exclusively be means of CAS functionality.
                     14: 
                     15: \begin{sloppypar}
                     16: Both interfaces preprocess students input by the perl function {\tt \&implicit\_multiplication(\$f)}. It adds mathematical multiplication operators to the formula expression \$f where only implicit multiplication is used. Example: \&implicit\_multiplication('2(b+3c)') returns 2*(b+3*c).
                     17: \end{sloppypar}
                     18: \subsection{{\tt \&cas}-interface}
                     19: \&cas(\$s,\$e,\$l) Evaluates the expression \$e inside the symbolic algebra system \$s. Currently, only the Maxima
                     20: symbolic math system is implemented. \$l is an optional comma-separated list of libraries. Example: \&cas('maxima','6*7')
                     21: 
                     22: 
                     23: \subsection{{\tt <mathresponse>}-interface}
1.2     ! riegler    24: {\tt <mathresponse>} is a way to have a problem graded based on an algorithm that is executed inside of a computer algebra system. 
        !            25: The documentation of \LC points out that  use of this response type is
        !            26: generally discouraged, since the responses will not be analyzable by the LON-CAPA statistics tools. Yet, it can be useful.
        !            27: 
        !            28: Which computer algebra system is to be used is specified in the cas argument of the mathresponse tag; currently, only Maxima is available.
        !            29: LON-CAPA sets up two arrays inside the computer algebra system: RESPONSE and LONCAPALIST. RESPONSE contains the student input by component, for example, if "3,42,17" is entered, RESPONSE[2] would be 42. LONCAPALIST contains the arguments passed in the args of mathresponse.
        !            30: 
        !            31: The answerdisplay is what is displayed when the problem is in "Show Answer" mode.
        !            32: 
        !            33: The following example illustrates this. It is a simplified version of \begin{verbatim} /res/msu/kashy/physicsLib02/02_Math_2_Trig/LinethroughPt2.problem\end{verbatim}.
        !            34: 
        !            35: \begin{verbatim}
        !            36: <problem>
        !            37: <script type="loncapa/perl">
        !            38: $x = &random(-1,1,2) * &random(1,5,1);
        !            39: $y = &random(-1,1,2) * &random(1,4,1); 
        !            40: if(&abs($x)==&abs($y)){$x=$y+1;} 
        !            41: # avoids y=x and y=-x as possible solutions
        !            42: @args = ($x, $y); 
        !            43: # This is passed to the CAS, where it will be 
        !            44: # LONCAPALIST[1], LONCAPALIST[2]
        !            45: 
        !            46: # In the <answer> block below, RESPONSE[1] is the 
        !            47: # student's submission (a scalar, e.g., 3x + 2  ).
        !            48:  
        !            49: # The two lines below provide a varying sample function, 
        !            50: # y(x)=mx+b, to be displayed when a correct answer is entered.
        !            51: 
        !            52: $m=&random(2,5)*&random(-1,1,2);
        !            53: $b = $y-$m*$x;
        !            54: if($b > 0){$b = "+ " . $b;} 
        !            55: elsif ($b == 0) {$yb = "";}
        !            56: elsif ($b < 0) {$yb = "- " . $b;}
        !            57: $example = "$m x $b is an example of the many functions that 
        !            58:   meet the criteria above.";
        !            59: </script>
        !            60: 
        !            61: <startouttext />
        !            62: State a function y(x) which passes through the point ($x, $y) 
        !            63: and which has a constant slope with absolute value > 1.<br />
        !            64: <endouttext />
        !            65: <mathresponse answerdisplay="$example" cas="maxima" args="@args">
        !            66: 
        !            67: <answer>
        !            68: y(x):=RESPONSE[1]; 
        !            69: thrupoint:is(abs(y(LONCAPALIST[1]) - LONCAPALIST[2]) <= 0.000000001);
        !            70: islinear:is(diff(y(x),x,2) = 0);
        !            71: AbsSlopeGT1:is(abs(diff(y(x),x,1)) > 1);
        !            72: thrupoint and islinear and AbsSlopeGT1;
        !            73: </answer>
        !            74: 		
        !            75: <b>y(x)</b> = <textline readonly="no" size="20" />
        !            76: 
        !            77: </mathresponse>
        !            78: </problem>
        !            79: 
        !            80: \end{verbatim}
1.1       riegler    81: 
                     82: \section{Interface to maxima}
                     83: \LC servers run several maxima sessions in parallel. There is a queue which distributes CAS calls to these sessions. When processing a new CAS call one has to be sure that maxima is reset to some default state. In particular functions, variables etc.\ defined in previous calls should be removed. LON-CAPA automatically takes care of that by means of the following sequence of commands which is executed every time before a maxima code snippet supplied by an author will be executed:
                     84: \begin{quote}
                     85: \begin{verbatim}
                     86: display2d:false;simp:true;kill(all);
                     87: \end{verbatim}
                     88: \end{quote}
                     89: Authors should be aware of this, because {\tt kill(all)} 
                     90: does {\em not} delete all previously defined 
                     91: stuff.\footnote{In fact, there seems to be no maxima command which 
                     92: does the desired job. If the cherished reader finds out about one, any \LC developer will be more than happy to change the above sequence accordingly.} One known issue is, that previously loaded maxima packages will not be removed by {\tt kill(all)}.
                     93: 
                     94: The two commands in front of {\tt kill(all)} make sure that the maxima session renders output as expressions contained in a single line and that maxima's elementary simplification functionality is turned on. (More on the {\tt simp}-flag and its usefulnes in \ref{SEC:simp}.)
                     95: \section{Primer on maxima}
                     96: This sections serves as a short tutorial on maxima. It is intended for readers who either have not worked with maxima before or are not familiar with CAS at all. In the long run when authoring \LC problems you might wish to consult more advanced material provided e.g.\ on
                     97: \begin{quote}
                     98: http://maxima.sourceforge.net/
                     99: \end{quote}
                    100: 
                    101: To start with it is a good idea to have access to maxima either on a mainframe or on your personal computer. This will also be helpful if you author problems using maxima. Maxima runs on almost any platform and can be downloaded at the above mentioned URL. In the following we will use the terminal interface to maxima. The graphical user interfaces basically behave the same way, except for wxmaxima where you do not have a prompt but have to enter your expressions at the buttom.
                    102: 
                    103: Let's start with some survival basics: exiting a maxima session and getting help. To quit maxima type {\tt quit();}
                    104: \begin{quote}
                    105: \begin{verbatim}
                    106: Maxima 5.9.2 http://maxima.sourceforge.net
                    107: Using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (aka GCL)
                    108: Distributed under the GNU Public License. See the file COPYING.
                    109: Dedicated to the memory of William Schelter.
                    110: This is a development version of Maxima. The function bug_report()
                    111: provides bug reporting information.
                    112: (%i1) quit();
                    113: \end{verbatim}
                    114: \end{quote}
                    115: To search for help use {\tt ?} followed by blank and an appropriate keyword
                    116: and follow the instructions.
                    117: Note that the blank after {\tt ?} is essential.
                    118: \begin{quote}
                    119: \begin{verbatim}
                    120: (%i1) ? integrate
                    121: 
                    122:  0: integrate :(maxima.info)Definitions for Integration.
                    123:  1: integrate_use_rootsof :Definitions for Integration.
                    124: Enter space-separated numbers, `all' or `none': 
                    125: \end{verbatim}
                    126: \end{quote}
                    127: Entering 1 would give you all the details on how to integrate functions.
                    128: 
                    129: Obviously you won't use neither {\tt quit()} nor {\tt ?} when authoring LON-CAPA problems. To assure that you won't do that accidentily \LC will block these and a number of other commands.
                    130: 
                    131: Commands have to end either with {\tt ;} or {\tt \$}. The effect of {\tt \$} is that no output will be displayed:
                    132: \begin{quote}
                    133: \begin{verbatim}
                    134: (%i2) 1+1;
                    135: 
                    136: (%o2)                                  2
                    137: (%i3) 1+1$
                    138: 
                    139: (%i4) 
                    140: \end{verbatim}
                    141: \end{quote}
                    142: By now you might have noticed that inputs are precedented by 
                    143: {\tt (\%i<number>)} 
                    144: and the corresponding outputs by
                    145: {\tt (\%o<number>)}, 
                    146: where {\tt <number>} is a consecutive number. You can refer back to previous outputs via {\tt \%o<number>}:
                    147: \begin{quote}
                    148: \begin{verbatim}
                    149: (%i4) (2*%o2)^20;
                    150: 
                    151: (%o4)                            1099511627776
                    152: \end{verbatim}
                    153: \end{quote}
                    154: Note that refering back via {\tt \%o<number>} does not make sense when authoring problems, as you will not know {\tt <number>}. Instead you will use named variables of course. The assignment operator for variables is {\tt :}
                    155: \begin{quote}
                    156: \begin{verbatim}
                    157: (%i5) a: sin(%pi);
                    158: 
                    159: (%o5)                                  0
                    160: 
                    161: (%i6) b: cos(%pi);
                    162: 
                    163: (%o6)                                 - 1
                    164: \end{verbatim}
                    165: \end{quote}
                    166: Mathematical constants such as $\pi$ and Euler's number are precedented by {\tt \%}:
                    167: \begin{quote}
                    168: \begin{verbatim}
                    169: (%i7) log(%e);
                    170: 
                    171: (%o7)                                  1
                    172: \end{verbatim}
                    173: \end{quote}
                    174: The assignment operator for functions is {\tt :=}
                    175: \begin{quote}
                    176: \begin{verbatim}
                    177: (%i8) f(x):=b*x^2;
                    178: 
                    179:                                             2
                    180: (%o8)                            f(x) := b x
                    181: (%i9) f(2);
                    182: 
                    183: (%o9)                                 - 4
                    184: (%i10) integrate(f(x),x);
                    185: 
                    186:                                         3
                    187:                                        x
                    188: (%o10)                               - --
                    189:                                        3
                    190: \end{verbatim}
                    191: \end{quote}
                    192: Here we see maxima's two-dimensional rendering. Setting the flag {\tt display2d} to false will turn it off:
                    193: \begin{quote}
                    194: \begin{verbatim}
                    195: (%i11) display2d:false;
                    196: 
                    197: (%o11) false
                    198: (%i12) f(x);
                    199: 
                    200: (%o12) -x^2
                    201: \end{verbatim}
                    202: \end{quote}
                    203: 
                    204: When authoring {\tt <mathresponse>}-problems you will have to make sure that the last value your maxima code snippet will return is either true or false. Most often {\tt is} will do the job. For instance, 
                    205: \begin{quote}
                    206: \begin{verbatim}
                    207: (%i13) RESPONSE[1]: -x^3/3 + 5;
                    208: 
                    209: (%o13) 5-x^3/3
                    210: (%i14) is ( diff(RESPONSE[1],x) = f(x) );
                    211: 
                    212: (%o14) true
                    213: \end{verbatim}
                    214: \end{quote}
                    215: checks whether the students response {\tt RESPONSE[1]} is the antiderivative of $f(x)$. Note that by differentiating {\tt RESPONSE[1]} via the {\tt diff}-command we make sure that any integration constant will be accepted:
                    216: \begin{quote}
                    217: \begin{verbatim}
                    218: (%i15) RESPONSE[1]: -x^3/3 + C;
                    219: 
                    220: (%o15) C-x^3/3
                    221: (%i12) is ( diff(RESPONSE[1],x) = f(x) );
                    222: 
                    223: (%o16) true
                    224: (%i16) RESPONSE[1]: -x^3/3 + C*x;
                    225: 
                    226: (%o17) x*C-x^3/3
                    227: (%i18) is ( diff(RESPONSE[1],x) = f(x) );
                    228: 
                    229: (%o18) false
                    230: \end{verbatim}
                    231: \end{quote}
                    232: 
                    233: more on delayed assignment, exact numbers, ...
                    234: 
                    235: \section{Simplify the following expression ...\label{SEC:simp}}
                    236: Many text book examples start with this phrase. Giving it a moment of thought reveals that these are somewhat ill-posed problems. For what is simple depends to a large extent on what you {\em define} to be simple and on what you want to do next.
                    237: 
                    238: more to be written by Zhoujing Wang (my student working on the issue)
                    239: 
                    240: \end{document}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>