Evaluation Control

General discussion about Mathematica features and functionality...
Forum Rules
By using the Wolfram Faculty Program Forum, you agree not to post any abusive, obscene, vulgar, slanderous, hateful, threatening, or sexually oriented material. Wolfram Faculty Program Forum administrators have the right to remove, edit, move or close any topic at any time should we see fit.

Personal Information: Posts in this forum may be viewed by non-members; however, the forum prohibits non-members from viewing your profile. Although your email address is hidden from both non-members and members, your account is initially configured to allow members to contact you via email through the forum. If you wish to hide your profile, or prohibit others from contacting you directly, you may change these settings by updating your profile through the User Control Panel.

Attachments: Attachments are not currently enabled on this forum. To share a file with others on this site, simply upload your file to the online storage service of your choice and include a link to the file within your post. If your school does not offer an online file storage and sharing service, the following sites provide free basic online file storage and sharing: Mozy, FilesAnywhere, Adrive, and KeepandShare.

Evaluation Control

Postby sharper47 » Sat Oct 30, 2010 6:00 pm

I teach algebra at the local community college and I'm trying to use Mathematica to display a set of homework or quiz problems, with an associated button for each problem to expose the answer (maybe someday to become part of a Mathematica-based textbook). These are quite simple problems (well, some of my students wouldn't agree...) and the problem I have is that Mathematica evaluates the problem and shows the answer before I can display the problem in unevaluated form. I've read the documentation on the topic pretty carefully, and have experimented quite a bit with functions like Unevaluated, Hold, HoldForm, Defer, etc, but so far haven't been able to come up with a satisfactory solution. I have also looked at the Demonstrations Project for similar stuff and studied some code from there, but still no luck. All of those focus on slightly more complex problems which don't immediately simplify (so they display as nice expressions like you want), but then you use Expand or Solve, and the numeric or symbolic answer comes out nicely.

Here's a prototypical problem (the formatting would be nicer in Mathematica, but I'm sure you get the idea):

Simplify 4x^2/(-3xy^(-3)). Answer: -4xy^3/3

As soon as I assign the problem expression to a symbol (or as a list element for a set of similar problems), Mathematica evaluates everything and all I have is the answers, when I wanted the students to do the work first... I really need a way to save the original expression and display it (nice formatted TraditionalForm), and then later force evaluation to display the answer under a button, or FlipView, or whatever. I've even tried saving the original form as a string and then using ToExpression, but there are spacing and other formatting problems that crop up when I do that...

What's the best way to do this?

Thanks,
Steve
User avatar
sharper47
 
Posts: 3
Joined: Wed May 05, 2010 8:56 pm
Organization: Linn Benton Community College
Department: Mathematics, Engineering

Re: Evaluation Control

Postby Ginger_McKee » Thu Nov 04, 2010 9:05 pm

Below is a notebook that shows how to generate problems and an answer key. It shows problems with fractions and how to get them to display in original, not simplified, form. Let me know if you think this is helpful.
http://members.wolfram.com/mmorrison/Fa ... ogram.html
User avatar
Ginger_McKee
 
Posts: 1
Joined: Thu Oct 15, 2009 8:39 pm
Organization: Wolfram Research, Inc.
Department: Sales

Re: Evaluation Control

Postby sharper47 » Mon Nov 08, 2010 5:08 pm

Ginger,

Thanks for your response. The three code snippets in your link were all helpful and interesting to me, but unfortunately don't do anything to solve this particular problem. Indeed, the fraction quiz example in the last snippet actually suffers from the exact problem I've described, though in that particular case it's probably what the instructor prefers. That random integer approach will sometimes create fractions like 2/4, 2/6, 3/6, 2/8, 4/8, 6/8, 3/9, and 6/9 (and inverses of these) that are not in lowest terms. However, because the fraction is in the form of a math expression (rather than, say, a string expression), Mathematica evaluates it before it is displayed. This results in the fraction being reduced to lowest terms, whether you want the problem displayed that way or not. The only reason the sum or difference isn't evaluated also is that the "+" or "-" is displayed as a string, so the problem is really in separate pieces. To generate the answers, the StringTake expression then converts the "+" or "-" string to a "math" expression, and Mathematica does the evaluation of the entire expression for the answer. The only difference between this and my problem is that I'm dealing with symbolic expressions rather than numeric ones. Actually I've made some progress. After rereading the documentation several times, it looks like HoldForm is the right thing to do, though I'm still having difficulty extracting problems from a list.

Thanks Anyway,
Steve
User avatar
sharper47
 
Posts: 3
Joined: Wed May 05, 2010 8:56 pm
Organization: Linn Benton Community College
Department: Mathematics, Engineering

Re: Evaluation Control

Postby telefunkenvf14 » Tue Nov 09, 2010 3:59 am

sharper47 wrote:I teach algebra at the local community college and I'm trying to use Mathematica to display a set of homework or quiz problems, with an associated button for each problem to expose the answer (maybe someday to become part of a Mathematica-based textbook). These are quite simple problems (well, some of my students wouldn't agree...) and the problem I have is that Mathematica evaluates the problem and shows the answer before I can display the problem in unevaluated form. I've read the documentation on the topic pretty carefully, and have experimented quite a bit with functions like Unevaluated, Hold, HoldForm, Defer, etc, but so far haven't been able to come up with a satisfactory solution. I have also looked at the Demonstrations Project for similar stuff and studied some code from there, but still no luck. All of those focus on slightly more complex problems which don't immediately simplify (so they display as nice expressions like you want), but then you use Expand or Solve, and the numeric or symbolic answer comes out nicely.

Here's a prototypical problem (the formatting would be nicer in Mathematica, but I'm sure you get the idea):

Simplify 4x^2/(-3xy^(-3)). Answer: -4xy^3/3

As soon as I assign the problem expression to a symbol (or as a list element for a set of similar problems), Mathematica evaluates everything and all I have is the answers, when I wanted the students to do the work first... I really need a way to save the original expression and display it (nice formatted TraditionalForm), and then later force evaluation to display the answer under a button, or FlipView, or whatever. I've even tried saving the original form as a string and then using ToExpression, but there are spacing and other formatting problems that crop up when I do that...

What's the best way to do this?

Thanks,
Steve


Steve:

Here is something you should look at before putting too much work into your own approach. Go to http://home.comcast.net/~djmpark/Mathematica.html, then scroll down to the info on 'Two High School Tutorials' and 'Expression Manipulation' and grab the relevant notebooks and packages.

-RG
User avatar
telefunkenvf14
 
Posts: 46
Joined: Tue Apr 27, 2010 7:40 pm
Location: Lincoln, NE
Organization: University of Nebraska-Lincoln
Department: Economics

Re: Evaluation Control

Postby telefunkenvf14 » Tue Nov 09, 2010 4:23 am

Just playing around... don't know if this would be helpful or not.

Code: Select all
Labeled[TabView[{"Q:" -> HoldForm[ 4 x^2/(-3 xy^(-3))],
   "A:" -> 4 x^2/(-3 xy^(-3))},
  BaseStyle -> {48, FontFamily -> "Times", Italic},
  LabelStyle -> {24, FontFamily -> "Times", Italic},
  Alignment -> Center], "Simplifying Expressions", Top,
LabelStyle -> {24, FontFamily -> "Times", Bold}]


Preview:

Image

Image

-RG
User avatar
telefunkenvf14
 
Posts: 46
Joined: Tue Apr 27, 2010 7:40 pm
Location: Lincoln, NE
Organization: University of Nebraska-Lincoln
Department: Economics

Re: Evaluation Control

Postby sharper47 » Wed Nov 10, 2010 3:35 am

RG,

Thanks a bunch for your help. The code snippet you cooked up is a very pretty way of demonstrating what I've discovered about HoldForm. The link you provided in your previous post looks really interesting; I am going to spend some time studying that material. It looks like it should provide everything I need and then some.

Thanks,
Steve
User avatar
sharper47
 
Posts: 3
Joined: Wed May 05, 2010 8:56 pm
Organization: Linn Benton Community College
Department: Mathematics, Engineering

Re: Evaluation Control

Postby telefunkenvf14 » Thu Nov 11, 2010 11:39 pm

sharper47 wrote:RG,

Thanks a bunch for your help. The code snippet you cooked up is a very pretty way of demonstrating what I've discovered about HoldForm. The link you provided in your previous post looks really interesting; I am going to spend some time studying that material. It looks like it should provide everything I need and then some.

Thanks,
Steve


Just so you know, David Park is a frequent poster on MathGroup (the Mathematica newsgroup), and a real nice guy as well. You might be able to get some help on using his package via that forum. To participate in the newsgroup go to: http://groups.google.com/group/comp.soft-sys.math.mathematica/topics

-RG
User avatar
telefunkenvf14
 
Posts: 46
Joined: Tue Apr 27, 2010 7:40 pm
Location: Lincoln, NE
Organization: University of Nebraska-Lincoln
Department: Economics


Return to General Mathematica Discussion

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron