Annotation of doc/help/codingmath.tex, revision 1.1
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}
! 24: \input{Math_Response_Problems.tex}
! 25:
! 26: {\bf a simpler example might be more appriopriate here}
! 27: \section{Interface to maxima}
! 28: \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:
! 29: \begin{quote}
! 30: \begin{verbatim}
! 31: display2d:false;simp:true;kill(all);
! 32: \end{verbatim}
! 33: \end{quote}
! 34: Authors should be aware of this, because {\tt kill(all)}
! 35: does {\em not} delete all previously defined
! 36: stuff.\footnote{In fact, there seems to be no maxima command which
! 37: 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)}.
! 38:
! 39: 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}.)
! 40: \section{Primer on maxima}
! 41: 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
! 42: \begin{quote}
! 43: http://maxima.sourceforge.net/
! 44: \end{quote}
! 45:
! 46: 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.
! 47:
! 48: Let's start with some survival basics: exiting a maxima session and getting help. To quit maxima type {\tt quit();}
! 49: \begin{quote}
! 50: \begin{verbatim}
! 51: Maxima 5.9.2 http://maxima.sourceforge.net
! 52: Using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (aka GCL)
! 53: Distributed under the GNU Public License. See the file COPYING.
! 54: Dedicated to the memory of William Schelter.
! 55: This is a development version of Maxima. The function bug_report()
! 56: provides bug reporting information.
! 57: (%i1) quit();
! 58: \end{verbatim}
! 59: \end{quote}
! 60: To search for help use {\tt ?} followed by blank and an appropriate keyword
! 61: and follow the instructions.
! 62: Note that the blank after {\tt ?} is essential.
! 63: \begin{quote}
! 64: \begin{verbatim}
! 65: (%i1) ? integrate
! 66:
! 67: 0: integrate :(maxima.info)Definitions for Integration.
! 68: 1: integrate_use_rootsof :Definitions for Integration.
! 69: Enter space-separated numbers, `all' or `none':
! 70: \end{verbatim}
! 71: \end{quote}
! 72: Entering 1 would give you all the details on how to integrate functions.
! 73:
! 74: 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.
! 75:
! 76: Commands have to end either with {\tt ;} or {\tt \$}. The effect of {\tt \$} is that no output will be displayed:
! 77: \begin{quote}
! 78: \begin{verbatim}
! 79: (%i2) 1+1;
! 80:
! 81: (%o2) 2
! 82: (%i3) 1+1$
! 83:
! 84: (%i4)
! 85: \end{verbatim}
! 86: \end{quote}
! 87: By now you might have noticed that inputs are precedented by
! 88: {\tt (\%i<number>)}
! 89: and the corresponding outputs by
! 90: {\tt (\%o<number>)},
! 91: where {\tt <number>} is a consecutive number. You can refer back to previous outputs via {\tt \%o<number>}:
! 92: \begin{quote}
! 93: \begin{verbatim}
! 94: (%i4) (2*%o2)^20;
! 95:
! 96: (%o4) 1099511627776
! 97: \end{verbatim}
! 98: \end{quote}
! 99: 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 :}
! 100: \begin{quote}
! 101: \begin{verbatim}
! 102: (%i5) a: sin(%pi);
! 103:
! 104: (%o5) 0
! 105:
! 106: (%i6) b: cos(%pi);
! 107:
! 108: (%o6) - 1
! 109: \end{verbatim}
! 110: \end{quote}
! 111: Mathematical constants such as $\pi$ and Euler's number are precedented by {\tt \%}:
! 112: \begin{quote}
! 113: \begin{verbatim}
! 114: (%i7) log(%e);
! 115:
! 116: (%o7) 1
! 117: \end{verbatim}
! 118: \end{quote}
! 119: The assignment operator for functions is {\tt :=}
! 120: \begin{quote}
! 121: \begin{verbatim}
! 122: (%i8) f(x):=b*x^2;
! 123:
! 124: 2
! 125: (%o8) f(x) := b x
! 126: (%i9) f(2);
! 127:
! 128: (%o9) - 4
! 129: (%i10) integrate(f(x),x);
! 130:
! 131: 3
! 132: x
! 133: (%o10) - --
! 134: 3
! 135: \end{verbatim}
! 136: \end{quote}
! 137: Here we see maxima's two-dimensional rendering. Setting the flag {\tt display2d} to false will turn it off:
! 138: \begin{quote}
! 139: \begin{verbatim}
! 140: (%i11) display2d:false;
! 141:
! 142: (%o11) false
! 143: (%i12) f(x);
! 144:
! 145: (%o12) -x^2
! 146: \end{verbatim}
! 147: \end{quote}
! 148:
! 149: 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,
! 150: \begin{quote}
! 151: \begin{verbatim}
! 152: (%i13) RESPONSE[1]: -x^3/3 + 5;
! 153:
! 154: (%o13) 5-x^3/3
! 155: (%i14) is ( diff(RESPONSE[1],x) = f(x) );
! 156:
! 157: (%o14) true
! 158: \end{verbatim}
! 159: \end{quote}
! 160: 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:
! 161: \begin{quote}
! 162: \begin{verbatim}
! 163: (%i15) RESPONSE[1]: -x^3/3 + C;
! 164:
! 165: (%o15) C-x^3/3
! 166: (%i12) is ( diff(RESPONSE[1],x) = f(x) );
! 167:
! 168: (%o16) true
! 169: (%i16) RESPONSE[1]: -x^3/3 + C*x;
! 170:
! 171: (%o17) x*C-x^3/3
! 172: (%i18) is ( diff(RESPONSE[1],x) = f(x) );
! 173:
! 174: (%o18) false
! 175: \end{verbatim}
! 176: \end{quote}
! 177:
! 178: more on delayed assignment, exact numbers, ...
! 179:
! 180: \section{Simplify the following expression ...\label{SEC:simp}}
! 181: 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.
! 182:
! 183: more to be written by Zhoujing Wang (my student working on the issue)
! 184:
! 185: \end{document}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>