[LON-CAPA-cvs] cvs: doc /help codingmath.tex

riegler lon-capa-cvs-allow@mail.lon-capa.org
Wed, 10 Sep 2008 02:12:13 -0000


This is a MIME encoded message

--riegler1221012733
Content-Type: text/plain

riegler		Tue Sep  9 22:12:13 2008 EDT

  Added files:                 
    /doc/help	codingmath.tex 
  Log:
  very first draft of a tutorial on using maxima for authoring lc problems
  
--riegler1221012733
Content-Type: text/plain
Content-Disposition: attachment; filename="riegler-20080909221213.txt"


Index: doc/help/codingmath.tex
+++ doc/help/codingmath.tex
\documentclass{article}
\newcommand {\LC} {LON-CAPA~}
\title{Implementing Math Problems in \LC using CAS Support}
\author{Peter Riegler\\ and hopefully other contributers}
\begin{document}
\maketitle
\begin{abstract}
We describe the \LC interface to computer algebra systems (CAS) which conveniently allows to implement rather sophisticated math problems. 
\end{abstract}
\section{Introduction}
\section{\LC interfaces to CAS}
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. 
The second one {\tt <mathresponse>} is used for doing the complete grading of a problem exclusively be means of CAS functionality.

\begin{sloppypar}
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).
\end{sloppypar}
\subsection{{\tt \&cas}-interface}
\&cas(\$s,\$e,\$l) Evaluates the expression \$e inside the symbolic algebra system \$s. Currently, only the Maxima
symbolic math system is implemented. \$l is an optional comma-separated list of libraries. Example: \&cas('maxima','6*7')


\subsection{{\tt <mathresponse>}-interface}
\input{Math_Response_Problems.tex}

{\bf a simpler example might be more appriopriate here}
\section{Interface to maxima}
\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:
\begin{quote}
\begin{verbatim}
display2d:false;simp:true;kill(all);
\end{verbatim}
\end{quote}
Authors should be aware of this, because {\tt kill(all)} 
does {\em not} delete all previously defined 
stuff.\footnote{In fact, there seems to be no maxima command which 
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)}.

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}.)
\section{Primer on maxima}
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
\begin{quote}
http://maxima.sourceforge.net/
\end{quote}

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.

Let's start with some survival basics: exiting a maxima session and getting help. To quit maxima type {\tt quit();}
\begin{quote}
\begin{verbatim}
Maxima 5.9.2 http://maxima.sourceforge.net
Using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (aka GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(%i1) quit();
\end{verbatim}
\end{quote}
To search for help use {\tt ?} followed by blank and an appropriate keyword
and follow the instructions.
Note that the blank after {\tt ?} is essential.
\begin{quote}
\begin{verbatim}
(%i1) ? integrate

 0: integrate :(maxima.info)Definitions for Integration.
 1: integrate_use_rootsof :Definitions for Integration.
Enter space-separated numbers, `all' or `none': 
\end{verbatim}
\end{quote}
Entering 1 would give you all the details on how to integrate functions.

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.

Commands have to end either with {\tt ;} or {\tt \$}. The effect of {\tt \$} is that no output will be displayed:
\begin{quote}
\begin{verbatim}
(%i2) 1+1;

(%o2)                                  2
(%i3) 1+1$

(%i4) 
\end{verbatim}
\end{quote}
By now you might have noticed that inputs are precedented by 
{\tt (\%i<number>)} 
and the corresponding outputs by
{\tt (\%o<number>)}, 
where {\tt <number>} is a consecutive number. You can refer back to previous outputs via {\tt \%o<number>}:
\begin{quote}
\begin{verbatim}
(%i4) (2*%o2)^20;

(%o4)                            1099511627776
\end{verbatim}
\end{quote}
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 :}
\begin{quote}
\begin{verbatim}
(%i5) a: sin(%pi);

(%o5)                                  0

(%i6) b: cos(%pi);

(%o6)                                 - 1
\end{verbatim}
\end{quote}
Mathematical constants such as $\pi$ and Euler's number are precedented by {\tt \%}:
\begin{quote}
\begin{verbatim}
(%i7) log(%e);

(%o7)                                  1
\end{verbatim}
\end{quote}
The assignment operator for functions is {\tt :=}
\begin{quote}
\begin{verbatim}
(%i8) f(x):=b*x^2;

                                            2
(%o8)                            f(x) := b x
(%i9) f(2);

(%o9)                                 - 4
(%i10) integrate(f(x),x);

                                        3
                                       x
(%o10)                               - --
                                       3
\end{verbatim}
\end{quote}
Here we see maxima's two-dimensional rendering. Setting the flag {\tt display2d} to false will turn it off:
\begin{quote}
\begin{verbatim}
(%i11) display2d:false;

(%o11) false
(%i12) f(x);

(%o12) -x^2
\end{verbatim}
\end{quote}

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, 
\begin{quote}
\begin{verbatim}
(%i13) RESPONSE[1]: -x^3/3 + 5;

(%o13) 5-x^3/3
(%i14) is ( diff(RESPONSE[1],x) = f(x) );

(%o14) true
\end{verbatim}
\end{quote}
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:
\begin{quote}
\begin{verbatim}
(%i15) RESPONSE[1]: -x^3/3 + C;

(%o15) C-x^3/3
(%i12) is ( diff(RESPONSE[1],x) = f(x) );

(%o16) true
(%i16) RESPONSE[1]: -x^3/3 + C*x;

(%o17) x*C-x^3/3
(%i18) is ( diff(RESPONSE[1],x) = f(x) );

(%o18) false
\end{verbatim}
\end{quote}

more on delayed assignment, exact numbers, ...

\section{Simplify the following expression ...\label{SEC:simp}}
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.

more to be written by Zhoujing Wang (my student working on the issue)

\end{document}

--riegler1221012733--