Creating Random Student Worksheets using LaTeX and Sage

1,107 views
Skip to first unread message

M.Olson

unread,
Aug 1, 2009, 11:47:31 AM8/1/09
to sage-edu
I am a Sage Newbie and looking to create randomly generated exercise
worksheets (not a sage worksheet) using both LaTeX and Sage. I create
random arithmetic sheets using OpenOffice Calc, but they are not very
aesthetic. However, with the power to be able to incorporate the power
of Sage into LaTeX - I was hoping to be able create random worksheets
for my students that look good too.

Well, it is not just about looks. It would be great to generate
random

- polynomial expressions that need to simplified OR equations that
need to be solved. I am sure the possibilities are endless. Of
course, one might also be able to use Sage to create the answer sheet
as well. This is most likely possible as as one can do it in
Mathematica ... just need a little help. Really what I am looking to
be able to do is something similar to this:
http://www.wolfram.com/broadcast/screencasts/generateexerc/

Any help to steer me in the right direction would be greatly
appreciated.

//Mark

Rob Beezer

unread,
Aug 1, 2009, 12:58:59 PM8/1/09
to sage-edu
HI Mark,

Dan Drake's SageTeX will let you embed Sage commands into your LaTeX
source and as an extra step in compiling the LaTeX document the Sage
commands are executed and the output incorporated. Dan is an active
Sage developer so I'm sure he'd be interested in helping with the
finer points.

http://www.ctan.org/tex-archive/help/Catalogue/entries/sagetex.html
http://bitbucket.org/ddrake/sagetex/

Sage has lots of commands to generate random objects - for example I'm
most familiar with random_matrix(). And every object in Sage is
suppose to have a LaTeX representation, so it ought to look good as
well. I suspect it shouldn't be too hard to roll all this together to
get what you are after.

Sounds like a nice project. Maybe you can post a working example here
once you have one?

Rob

jason...@creativetrax.com

unread,
Aug 1, 2009, 1:47:44 PM8/1/09
to sage...@googlegroups.com


Rob had some good points. I personally do all of my class handouts in
latex, so Dan's sagetex package is what I would use here too.

We would be able to give you more specific help if you narrowed your
question down (e.g., how do I generate a random linear equation that a
student can solve, of the form ax+b=c). It would also be helpful to
post what you've tried.

Good luck! This sounds interesting.

Jason

Harald Schilly

unread,
Aug 2, 2009, 9:40:02 AM8/2/09
to sage-edu
On 1 Aug., 16:47, "M.Olson" <markhendryol...@gmail.com> wrote:
> I am a Sage Newbie and looking to create randomly generated exercise
> worksheets (not a sage worksheet) using both LaTeX and Sage.

Some months ago I had the same idea. It's pretty easy I think to code
some general framework in python for this and then design a random
test setup by coding the question/answers as python data structures.
There was also an R package for this, that might inspire you for this.

H

M.Olson

unread,
Aug 4, 2009, 10:58:51 AM8/4/09
to sage-edu
Thanks everyone for your comments of goodness.

I have been using Dan Drake's SageTeX for a couple weeks now ... and
it is nothing short of incredulous! I will be sure to share all my
working examples once I get them going.

I have made some progress this weekend after playing around a bit. I
am very confident that I can generate the randomly generated
worksheets, but I am having a problem creating the solution sheets. I
am sure my method of generating the sheets is not elegant nor
optimized.

I have a very SIMPLE example of generating random dyadic
operations ... let's use addition. I am using tables, so that the
layout looks consistent.

%Define the greatest term, t, to be used. In this example it will be
44

\begin{sagesilent}
t=44
\end{sagesilent}

\begin{tabular}{|c|c|c|c|c|}
\hline $\sage{ZZ.random_element(t)}$ & + & $\sage{ZZ.random_element(t)}
$ &$ =\\\hline
\hline $\sage{ZZ.random_element(t)}$ & + & $\sage{ZZ.random_element(t)}
$ &$ =\\\hline
\hline $\sage{ZZ.random_element(t)}$ & + & $\sage{ZZ.random_element(t)}
$ &$ =\\\hline
\hline $\sage{ZZ.random_element(t)}$ & + & $\sage{ZZ.random_element(t)}
$ &$ =\\\hline
\hline $\sage{ZZ.random_element(t)}$ & + & $\sage{ZZ.random_element(t)}
$ &$ =\\\hline
\hline $\sage{ZZ.random_element(t)}$ & + & $\sage{ZZ.random_element(t)}
$ &$ =\\\hline
.
.
.
\end{tabular}

This works brilliantly! Awesome ... I can now create awesome sheets
of goodness using this method. The problem is if I want to provide
answers and in more complicated problems ... solutions. They only way
that I have come up with is defining the operands in the sagesilent.
The reason is that I can manipulate my defined operands, in this case
sum them. More specifically, the problem is that I can only define
alpha constants, which are random numbers, a-z. If I define a
constant as "aa" or "a0", it does not compile? It would be a little
work to assign all the constants, but I am sure it would be worth it.
I can't figure out why this won't work. Is the following syntax
incorrect?

\begin{sagesilent}
t=43
a=ZZ.random_element(t) --- >this works
a0=ZZ.random_element(t) ---> this does not work
\end{sagesilent}

Any ideas on how to assign random numbers to constants?
Any ideas on how to simplify this procedure?


Here is an example that I could use to generate the worksheet and the
answer sheet by using defined constants:

\begin{sagesilent}
t=44
a=ZZ.random_element(t)
b=ZZ.random_element(t)
c=ZZ.random_element(t)
d=ZZ.random_element(t)
.
.
.
I run out of constants :(
\end{sagesilent}


\begin{tabular}{|c|c|c|c|c|}
\hline $\sage{a}$ & + & $\sage{b}$ &$ =$ & $\sage{a+b}$\\\hline
\hline $\sage{c}$ & + & $\sage{d}$ &$ =$ & $\sage{c+d}$\\\hline
.
.
.

\end{tabular}


Thank you everyone for your comments ... much appreciated :D

Mark

Harald Schilly

unread,
Aug 4, 2009, 2:10:46 PM8/4/09
to sage-edu
On Aug 4, 4:58 pm, "M.Olson" <markhendryol...@gmail.com> wrote:
> I have a very SIMPLE example of generating random dyadic
> operations ... let's use addition. ...

Hi, I would tackle this entirely different. I would code the randomness
+the solutions in python, part of sagetex, and just insert markers
into the latex code where the example should go (an example is
basically a map of "ID"s <-> problem-data-structure). coding the
random generation inside the latex document is bad, because you cannot
reuse the code and as you say you don't get the solutions.
In detail, you could parameterize each generated latex document with a
number (serving as a random seed). then, there is an option to print
the question, question+answer or just the answer. in the latex code is
something like "\insertProblem{ID_STRING}" and that calls a python
function that generates the latex code and does everything else. Of
course, I never thought this through but i think it might work very
well.

H

Rob Beezer

unread,
Aug 4, 2009, 5:39:56 PM8/4/09
to sage-edu
Hi Mark,

A couple of comments:

1. You can create a pille of Sage variables as illustrated. Not sure
how they will behave in SageTeX.

sage: for i in range(6):
var('a'+str(i))
a0
a1
a2
a3
a4
a5
sage: a1=6
sage: latex(a1)
6
sage: a2=5
sage: latex(a1+a2)
11

2. Harald's suggestion to set the random seed is a great idea, so
your exercise sheets are reproducible. LaTeX has an "ifthen"
package. Wrap your solutions in an \ifthenelse command so on your
first pass the solutions do not print. Then change the value of a
boolean (in LaTeX) so on the second pass the solutions to the same
"random" problems are included. I do this when I write an exam -
first pass is the questions, second pass is the questions with the
answers. But I don't use any randomness. ;-)

Rob

kilucas

unread,
Aug 21, 2009, 9:51:46 AM8/21/09
to sage-edu
I've linked to this thread from another Google group about some
learning software where question generation has arisen as an idea ...

Although I don't yet understand all of the technical ideas in this
thread and have yet to try SageTex, I thought I'd mention a thread
I've started in the Google group for Anki (Spaced repetition software)
about generation of mathematical questions within Anki. It's at
http://groups.google.com/group/ankisrs/browse_thread/thread/6f8769cf557ba85f/1f6dea718c0ba08a#1f6dea718c0ba08a.

Anki is designed to practice recollection of facts and thereby lodge
them in long term memory. It tracks student performance statistically
so it knows how frequently to ask a student to repeat their
recollection of a single fact based on how hard the student found the
question and whether they got it right or wrong.

Although Anki is designed to help memorise facts, I've asked if the
same style of intelligent repetition of posed questions and assessment
of the students' experience and answers could be used to help test
their learning of processes like the calculations that arise in maths.

A simple example could be to solve quadratic equations. A set of
quadratics could be posed (just as a text book might pose exercises)
but Anki would track answers and difficulty levels and would then
repeat specific questions that were posed earlier to reinforce the
learning process. I don't know whether this is better than work with a
text book but I suspect that, when a student gives an incorect answer
through a faulty process or careless application of a good one, they
may be shown what error they made, but they're not necessarily tested
on the same question later to ensure the lesson has been learned.

I also suspect that the repetition regime for learning of calculation
processes would differ from a memorisation regime for facts. And
there's a danger that too much repetition of a specific question would
teach the student to rely on the specifics of that one question rather
than reinforcing the calculation process of which it's an example.

I mention this here though because someone's posted a comment in the
Anki thread about whether maths questions could be randomly generated
so I've let people know of this thread about question generation. Anki
supports LaTex to some degree so I wondered if SageTex could be used.

If there is any merit in repeating calculation exercises, presumably
we'd want to generate a set of randomised question at first but then
ensure that any repeated questions were exact copies of the originals
and were not re-generated to produce a different question.

Kevin
> > > //Mark- Hide quoted text -
>
> - Show quoted text -

kcrisman

unread,
Aug 27, 2009, 9:17:29 AM8/27/09
to sage-edu

For those of us who have yet to take the leap into SageTex, some VERY
explicit examples posted somewhere (Wiki?) would be very helpful. I
would love the ability to create random questions for certain parts of
my exams using Sage, but don't feel comfortable with the programming
aspects of LaTex yet.

- kcrisman

jason...@creativetrax.com

unread,
Aug 27, 2009, 10:03:32 AM8/27/09
to sage...@googlegroups.com


Did you read the documentation and example files that come with
SageTex? I found that the most helpful for simple, explicit examples.

Jason


--
Jason Grout

Jason Grout

unread,
Feb 23, 2013, 5:23:12 PM2/23/13
to sage...@googlegroups.com
On 2/23/13 4:11 PM, Nathan Carter wrote:
>
> Harald's idea sounds like a great one, so I tried to implement it. I
> have no problem creating Python objects with arbitrary _latex_()
> methods, but then there's no way to insert them into the document. The
> only way to get Sage output into the document is with the \sage{...}
> command, which seems to be built only for inline and in math mode. You
> can't, for example, create an object whose LaTeX representation is
> several paragraphs long, with display math and so on in it, and then try
> to do \sage{thatObject}. You get a ton of errors of various kinds,
> including ones about paragraph breaks in places they shouldn't be.
>
> Doing it this way (creating Python objects to store the problems) was
> important to me, because I hoped to create a solution that didn't just
> generate random problems each time the document was compiled, but also
> (a) automatically generate several versions of the exam/worksheet in the
> same LaTeX document (concatenated), and (b) permute the problems
> differently in each version. Is this hopeless or does someone here know
> a relevant SageTeX trick that I don't?
>

One thing you might do is use \sagestr to just include the output
directly into the tex file, without running the _latex_ method. See
page 6 of the sagetex manual.

Jason

Nathan Carter

unread,
Feb 23, 2013, 7:06:27 PM2/23/13
to sage...@googlegroups.com

That's handy for outputting strings, but unfortunately because the .sout file puts everything in a \newlabel{} command, it still can't handle paragraph breaks.  So all my problems would need to be one paragraph. I could use \\ to split paragraphs primitively, and display math does work, so it's progress! :)  Not perfect yet, but usable---good tip, thanks, Jason!

Also, I had looked for something like \sagestr in the manual, but I was looking at this version:
Turns out that one's ancient, and the latest is here:
Now I see \sagestr, and lots of other cool new tools that weren't around in, uh, 2009. :)

Brad Burkman

unread,
Feb 24, 2013, 11:46:19 PM2/24/13
to sage...@googlegroups.com
I used to do this, make a hundred "different" but "similar" worksheets for my College Algebra students.  I used C++ to generate the exercises, then have C++ write a .tex file, then compile.  

I can help more with the questions of "why" and "what makes a good set of exercises," although I can also help with the technical aspects.  

I tried everything, including making all of the odd exercises the same across the set of worksheets, but all of the even exercises different.  I also worked on different schemes for giving the answers.  

The main reason I stopped doing it was that I found that "randomly" is not the best way to choose a set of exercises.  I would often see worksheets where adjacent exercises were too similar, and it felt like busywork.  

I spent the last five years working on what makes a good set, and how one would find it.  

Let me know if there is help I can give.  

Brad

Jurgis Pralgauskis

unread,
Feb 25, 2013, 6:34:05 PM2/25/13
to sage...@googlegroups.com
just stumbled upon some R package for exams...

http://cran.r-project.org/web/packages/exams/index.html

Nathan Carter

unread,
Feb 26, 2013, 7:52:30 AM2/26/13
to sage...@googlegroups.com

Now that I have gotten all the SageTeX tools I need set up, I'm planning to start working on this project in earnest.  I hit another wall, but it's a separate issue.  I started a new topic for it, rather than clutter this one, but I thought I'd link to it here.  You know, just to keep the saga going. :)
Reply all
Reply to author
Forward
0 new messages