Forums

Search results: 133

inactiveTopicusing existing answer evaluators as filters topic started 8/27/2003; 3:32:38 PM
last post 8/28/2003; 9:20:00 AM
userGavin LaRose - using existing answer evaluators as filters  blueArrow
8/27/2003; 3:32:38 PM (reads: 1186, responses: 4)
Hi all,

It seems to me that it ought to be possible to use existing answer evaluators in new ones. However, my limited brain power is insufficient to accomplish this. I tried the simplest thing I could think of, which is the following.

sub newEvaluator {
my $cAns = shift();
my %opts = @_;
my $evaluator = new AnswerEvaluator();
$evaluator->install_evaluator(~~&fun_cmp, %opts);
return $evaluator;
}

And then called my new evaluator with ANS(newEvaluator($answer)). But when I do this, I get the error message

Error in /cgi-bin/webwork-cgi/cgi-scripts/processProblem8.pl
Can't locate object method "error_flag" via package AnswerEvaluator
at /opt/www/webwork/system/lib//PGtranslator.pm line 939.

Which seems to say that my simple-minded approach is, well, too simple-minded. If anyone could tell me how to do this correctly, I'd be appropriately grateful.

Thanks,
Gavin

<| Post or View Comments |>


userMichael Gage - Re: using existing answer evaluators as filters  blueArrow
8/27/2003; 5:39:34 PM (reads: 1421, responses: 0)
Hi Gavin,

It should work more or less this way, but it doesn't quite yet. Give me a few hours to give you an example of using one answer evaluator inside another and I'll post it here. See you later tonight (or tomorrow morning)

--Mike

<| Post or View Comments |>


userMichael Gage - Re: using existing answer evaluators as filters  blueArrow
8/27/2003; 9:54:48 PM (reads: 1408, responses: 0)
I've written some simple code that illustrates what has to be done:

Here's the source

##DESCRIPTION
## A very simple first problem
##ENDDESCRIPTION

##KEYWORDS('algebra')

DOCUMENT();
# This should be the first executable line in the problem.

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl"
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

$a = random(-10,-1,1);
$b = random(1,11,1);
$c = random(1,11,1);
$d = random(1,11,1);

BEGIN_TEXT
This problem demonstrates how you enter numerical answers into WeBWorK. $PAR
Evaluate the expression \(3($a )($b -$c -2($d ))\):
\{ ans_rule(10) \}
$BR

END_TEXT


$ans = 3*($a)*($b-$c-2*($d));

# Here are the important lines where we build a new
# answer evaluator using the old.
# The new answer evaluator doesn't do much. Just adds
# the message 'experimental'.

$old_ans_eval = num_cmp($ans);

# notice that num_cmp() is a function which PRODUCES an answer evaluator
# or technically a pointer to the answer evaluator object. I prefer to think
# of $old_ans_eval as actually containing the answer evaluator object.

$new_eval = new AnswerEvaluator;

# now we have a new, empty answer evaluator

$new_eval->install_evaluator(sub {my $rh_ans=shift;
$rh_ans = $old_ans_eval->evaluate($rh_ans->{student_ans});
$rh_ans->{ans_message}='experimental';
$rh_ans;}
);

# We have added a new filter to the new answer evaluator.
# The structure of a filter is that it is supposed to be a subroutine
# which accepts an answerHash object and returns an answerHash object.
# The first problem is that an AnswerEvaluator is not subroutine
# (it's more complicated) so one can't use
# &$old_ans_eval($answer_hash) to process an answer hash, you need to say
# $old_ans_eval->evaluate($answer_hash).
# For this routine we wrap a subroutine around the old answer evaluator
# so that it will behave correctly.
# [Note: The evaluate routine in AnswerEvaluator should (IMHO) be modified
# so it can accept filters which are answer evaluators as well as ones
# which are ordinary subroutines. This won't be too hard, only a few hours work. ]

# Secondly, even that might not work -- most answer evaluators, the ones built
# with all of the AnswerEvaluator tools accept either
# a string input, OR an AnswerHash input. Some of the older answer evalatuors,
# may not do this reliably
# -- there has not yet been a lot of reuse of answer evaluators so
# there has not been much testing in this area.
# That appears to be the case with num_cmp type evaluators, so
# instead of feeding it an answerHash
# we find the student answer inside the AnswerHash and feed it that. It will
# take some work, but
# eventually we should be able to refit all answer evaluators
# so that they will accept either a
# string or an AnswerHash and can therefore be used one inside the other.
# At the moment the evaluators produced by str_cmp aren't
# even AnswerEvaluator objects, they are subroutines!


# The final thing the filter does is to add the string 'experimental' to the
# answer message of the AnswerHash, just to prove that we've actually done
# something. You could do much more.

# Final note -- I often use $rh_ans, the $rh_ means it's a pointer (reference) to a
# hash value, this way I can remember that the scalar variable holds something
# more complicated than a single value. I also use $r_ for reference, and $ra for
# a reference to an array. Unfortunately I'm not consistent about this, but I use
# technique when I'm likely to get confused as to what is a value and what is a pointer.

ANS($new_eval);


ENDDOCUMENT();
# This should be the last executable line in the problem.


Here is what the problem looks like.

 


(1 pt) rochesterLibrary/setSampleAnswers/sample_compound_ans_eval.pg
This problem demonstrates how you enter numerical answers into WeBWorK.

Evaluate the expression 3(-4 )(2 -3 -2(3 )):

 

 


WARNINGS
µ¦å{h­

Reference AnswerHash.pm

<| Post or View Comments |>


userGavin LaRose - Re: using existing answer evaluators as filters  blueArrow
8/28/2003; 8:38:52 AM (reads: 1387, responses: 0)
Hi Mike,

Thanks, as usual, for your rapid and extremely useful help. The essence of your solution was my second attempt to get this to work, but it didn't quite get to where it needed to before I decided that I couldn't afford more time to play with it (I lost way more time than I intended on forgetting that backslashes in problem code are actually double tildes...).

The end result? What seems as if it ought to be a much simpler answer evaluator than I've arrived at to evaluate answers involving differentials. For example, in the problem "If the area of a rectangle is A(x,y) = xy, find the differential of this function: dA = [ ]." The correct answer is dA = y dx + x dy, and we want to evaluate the differentials (dx, dy) as single variables. To do this, I wrote an evaluator that first filters the dx, dy (actually, filters d[var] for all variables [var] specified in the answer evaluator options) into new variables P,R, etc. (I skipped Q because that's used for the function evaluator up to a constant), then uses fun_cmp to evaluate the resulting function, and then filters P,R, etc. back to the original variables. I'm pasting it in below. Comments for making it more streamlined or elegant are welcomed.

sub diffl_fun_cmp {
my $correctAns = shift();
my %opts = @_;



my @cAnsList =
((ref($correctAns) eq 'ARRAY')? @{$correctAns}:($correctAns));



# we rely on $opts{'var'} being defined as an array reference
if ( defined( $opts{'var'} ) ) {
$opts{'var'} =
( ref($opts{'var'}) ? $opts{'var'} : [$opts{'var'}] );
} else {
$opts{'var'} = [ 'x' ];
}



my @outEvaluators = ();
foreach my $cAns ( @cAnsList ) {
push(@outEvaluators, diffl_eval($cAns, %opts));
}
return (wantarray) ? @outEvaluators : $outEvaluators[0];
}
sub diffl_eval {
my $cAns = shift();
my %opts = @_;



my $evaluator = new AnswerEvaluator('correct_ans' => $cAns,
'type' => 'diffl_fun_cmp',
'original_correct_ans' =>
$cAns);
$evaluator->install_pre_filter( ~~&replace_differentials_filter,
%opts );
$evaluator->install_evaluator( ~~&diffl_fun_eval, %opts );
$evaluator->install_post_filter( ~~&restore_vars_filter, %opts );
return $evaluator;
}
sub diffl_fun_eval {
my $rh_ans=shift;
my %opts = @_;



my $cAns = $rh_ans->{'correct_ans'};



my @vars = ( @{$opts{'var'}}, @{$rh_ans->{'added_vars'}} );
$opts{'var'} = [ @vars ];



my $func_eval = fun_cmp($cAns, %opts);
$rh_ans = $func_eval->evaluate( $rh_ans->{'student_ans'} );



return $rh_ans;
}
sub replace_differentials_filter {
my $rh_ans = shift();
my %opts = @_;



my $student_input = $rh_ans->input();
my $correct_answer = $rh_ans->{'correct_ans'};



my @subs = ( 'P', 'R', 'S', 'M', 'N', 'O' );
my @addedVars = ();
for ( my $i=0; $i<@{$opts{'var'}}; $i++ ) {
$student_input =~ s/d$opts{'var'}->[$i]/$subs[$i]/g;
$correct_answer =~ s/d$opts{'var'}->[$i]/$subs[$i]/g;
push( @addedVars, $subs[$i] );
}
$rh_ans->input($student_input);
$rh_ans->{'correct_ans'} = $correct_answer;
$rh_ans->{'added_vars'} = [ @addedVars ];



return $rh_ans;
}
sub restore_vars_filter {
my $rh_ans = shift();
my %opts = @_;



my $student_input = $rh_ans->input();
my $correct_answer = $rh_ans->{'correct_ans'};
my $original_input = $rh_ans->{'original_student_ans'};
my $text_preview = $rh_ans->{'preview_text_string'};
my $latex_preview = $rh_ans->{'preview_latex_string'};



my @subs = ( 'P', 'R', 'S', 'M', 'N', 'O' );
for (my $i=0; $i<@{$opts{'var'}}; $i++) {
$student_input =~ s/$subs[$i]/d$opts{'var'}->[$i]/g;
$correct_answer =~ s/$subs[$i]/d$opts{'var'}->[$i]/g;
$original_input =~ s/$subs[$i]/d$opts{'var'}->[$i]/g;
$text_preview =~ s/$subs[$i]/d$opts{'var'}->[$i]/g;
$latex_preview =~ s/$subs[$i]/d$opts{'var'}->[$i]/g;
}



$rh_ans->input($student_input);
$rh_ans->{'correct_ans'} = $correct_answer;
$rh_ans->{'original_student_ans'} = $original_input;
$rh_ans->{'preview_text_string'} = $text_preview;
$rh_ans->{'preview_latex_string'} = $latex_preview;
delete( $rh_ans->{'added_vars'} );



return $rh_ans;
}

Thanks again, Mike
Gavin

<| Post or View Comments |>


userMichael Gage - Re: using existing answer evaluators as filters  blueArrow
8/28/2003; 9:20:00 AM (reads: 1399, responses: 0)
Hi Gavin,

Yeah, I've lost a lot of time over the years on the double tilde problem as well (and I wrote the interface!).  Unfortunately it seems still seems the best compromise between the requirements of using backslashes in tex and backslashes in perl. 

The possibility of reusing code to modify existing answer evaluators is one I'm very interested in and your
needs provide a good example of what facilities need to be made available.  The implementation of the
"filter" framework for answer evaluators is a good step in this direction -- but I'm afraid it stalled a  bit once I
had satisfied my immediate needs. 

What's most needed is documentation and tutorial examples. At the moment
there is only a little documentation in AnswerHash and the rest of the purpose and functionality has to be inferred from some of the better code examples, such as fun_cmp and reading the code in AnswerHash and AnswerEvaluator.

The other two needs I've been aware of  are to (1) modify the answer evaluator method so that filters can be either anonymous subroutines (for simple procedures) or answer evaluators (when more complicated processes are involved) and (2) to rewrite all of the current answer evaluators to correspond to the new scheme.

I know that John Jones has been pretty active in writing new answer evaluators using the "filter" framework.  Perhaps he, you and others have further suggestions for the answer evaluator framework.

I'm in the midst of setting up fall courses, so it will be a week or so before I can look more closely and what you have working above. I would like to call attention to two subroutines in PGanswermacros.pl  for handling options in a  uniform way:

assign_option_aliases

and

set_default_options

both in PGanswermacros.pl.

It's my current thinking that it is a good idea to  include these in  any but the most trivial of  filters or
answer evaluators.  They may not be important right away, but as people modify the filter, adding options
etc. , the presence of those subroutines will encourage the programmers to use them.  In the future these subroutines themselves might be modified to allow discovery of available options, better debugging features,
and other improvements, so it would be helpful if they were in widespread use so that new features are immediately available to old answer evaluators.

Glad you're playing with this feature.

--Mike

<| Post or View Comments |>

Forum archive 2000-2006 -> Arnold K. Pizer - dvipng and Solaris

by Arnold Pizer -
inactiveTopicdvipng and Solaris topic started 4/25/2003; 2:32:56 PM
last post 6/11/2003; 1:02:44 PM
userArnold K. Pizer - dvipng and Solaris  blueArrow
4/25/2003; 2:32:56 PM (reads: 1308, responses: 3)
Hi,

We would like to hear from people running WeBWorK 1.8 under Solaris. We are interested in how dvipng (i.e. typeset2 mode) was setup and how it is working. Jason Farmer at Radford reports problems with slow response times using dvipng. This is a problem that seemed to be corrected and then reappeared. See the discussion at http://webhost.math.rochester.edu/webworkdocs/discuss/msgReader$1398. Also Gavin LaRose at Michigan reports trouble compiling dvipng under Solaris. I believe that dvipng requires gnu make so that might account for Gavin's trouble.

If someone has dvipng working well under Solaris, we would appreciate their posting explicit instructions as to how they accomplished this.

Arnie

<| Post or View Comments |>


userGavin LaRose - Re: dvipng and Solaris  blueArrow
6/11/2003; 10:58:12 AM (reads: 1522, responses: 0)
Hi Arnie,

I've now worked through compiling dvipng for Solaris 8, with only marginal success. I had to tweak a few things to get it to compile cleanly, and even with a clean compile it's not creating correctly formatted png equation files. Examples of the output I'm getting:
testme2.png
and
testme3.png

If anyone has insight as to what's going on here, I'd appreciate it.

For the benefit of anyone who is interested in the nitty-gritty,the changes I had to make to get this to compile were: in dvipng/Makefile:

  1. CPPFLAGS : I changed this to reflect the paths to our non-system include files. I also took out -DDEBUG (c.f. below).
  2. LDFLAGS: I changed the paths in this similarly.

I can't easily put code into our TeX directory, so I put it in another place and set the TEXINPUTS environmental variable. I'm not sure if this actually works, though I don't think it should affect the compilation of dvipng. In addition, I'm compiling in 64 bit mode and had to set LD_LIBRARY_PATH to get the right libraries.

Finally, to get rid of two compile warnings,

font.c: In function `FontDef':
font.c:150: warning: int format, different type arg (arg 2)
pagelist.c: In function `SkipPage':
pagelist.c:31: warning: deprecated use of label at end of compound statement

I added the line " ;" at line 31 in pagelist.c and changed line 125 of font.c,

  if (Debug)
printf("DEF FONT%ld: %s\n",k,n);
to
#ifdef DEBUG
if (Debug)
printf("DEF FONT%ld: %s\n",k,n);
#endif

With these changes I get a clean compile with no warnings or errors, but the output indicated above.

Thoughts, comments or suggestions are welcomed.
Gavin

<| Post or View Comments |>


userGavin LaRose - Re: dvipng and Solaris  blueArrow
6/11/2003; 11:25:57 AM (reads: 1522, responses: 0)
Hi Arnie,

Ok, one more follow-up. I grabbed dvipng-0.2.tar.gz from sourceforge, and that seems to compile cleanly without changes--and produce correctly formatted images for me. Huzzah!

If anyone else is out there on (64bit) Solaris 8 or better, I'm happy to provide the binary.

Thanks,
Gavin

<| Post or View Comments |>


userJohn Jones - Re: dvipng and Solaris  blueArrow
6/11/2003; 1:02:44 PM (reads: 1543, responses: 0)
Hi everyone,

I am glad that dvipng-0.2 worked well for you. I was going to point people to the official distribution when the next version came out. This one has a bug (present in earlier versions too) which cause it to crop images a little too closely cutting off pixels at the right and bottom. I have contacted the maintainer about the bug and he replied that he would fix it.

I will post to the discussion board when the next version comes out.

John

<| Post or View Comments |>

Forum archive 2000-2006 -> Michael Gage - List of Units

by Arnold Pizer -
inactiveTopicList of Units topic started 5/3/2000; 10:47:39 PM
last post 5/3/2000; 10:47:39 PM
userMichael Gage - List of Units  blueArrow
5/3/2000; 10:47:39 PM (reads: 5806, responses: 0)
The answers you enter as the solutions to your WebWork problem sets must conform to the following conventions, in order to be interpreted and graded correctly.

 

Problems requiring a numerical answer

 

Most answers consist of a numerical value followed by an abbreviation for the appropriate units of the physical quantity. A space must separate the numerical value from the units, as in for example 1.234 m.

 

Numerical values

 

The numerical value may be written as a floating point decimal, for example 0.00314159, or in scientific notation as either 3.14159E-3 (as in FORTRAN) or 3.14159*10^-3 (with * signifying multiplication, and ^ signifying exponentiation; note in using the FORTRAN-like notation, you must use capital "E" and not small "e"). In place of a specific number for the numerical part of an answer, you may also use algebraic expressions. For example, (6+4)/2 is the same as writing 5. To see the syntax required for such expressions, as well as to see which special functions and numerical constants are recognized, see the section on Accepted math functions. Note that trigonometric functions assume the argument is expressed in radians and not degrees.

 

 

Units

 

The units may be any compound expression of the form:

[unit]1^n1*[unit]2^n2*...*[unit]3^n3/ [unit]4^n4*[unit]5^n5*...*[unit]6^n6

where [unit]i is any of the unit abbreviations listed below, and the ni are positive or negative integers. The string of units before the / denote the numerator of the compound expression, while those following the / denote the denominator of the compound expression. There may be only one / in a given compound unit expression and no spaces are allowed within the units expression.

The abbreviations for units that are recognized by WebWork are:

abbrev.unit name dimension equivalence in fundamental units
FUNDAMENTAL MKS UNITS
kgkilogramsmass 
mmeterslength 
ssecondstime 
OTHER BASIC UNITS
degdegreeangle1 deg = pi/180 rad
radradianangle1 rad = 180/pi deg
msmillisecondtime1 ms = 0.001 s
minminutetime1 min = 60 s
hrhourtime1 hr = 60 min = 3600 s
daydaytime1 day = 24 hr = 8.64E4 s
yryeartime1 yr = 365.25 day = 3.15576E7 s
kmkilometerlength1 km = 1000 m
cmcentimeterlength1 cm = 0.01 m
mmmillimeterlength1 mm = 0.001 m
micronmicrometerlength1 micron = 10^-6 m
ummicrometerlength1 um = 10^-6 m
nmnanometerlength1 nm = 10^-9 m
AAngstromlength1 A = 10^-10 m
ininchlength1 in = 0.0254 m
ftfeetlength1 ft = 12 in = 0.3048 m
mimilelength1 mi = 5280 ft = 1609.344 m
light-yearlight yearlength1 light-year = 9.46E15 m
Llitervolume1 L = 10^-3 m^3
mlmillilitervolume1 ml = 10^-3 L = cm^3
cccubic centimetervolume1 cc = 10^-3 L = cm^3
knotsnautical miles per hourvelocity1 knots = (1852/3600) m/s
ggrammass1 g = 10^-3 kg
slugslugmass1 slug = 14.6 kg
HzHertzfrequency1 Hz = 1 s^-1
kHzkilo-Hertzfrequency1 kHz = 1000 Hz = 10^3 s^-1
MHzmega-Hertzfrequency1 MHz = 10^6 Hz = 10^6 s^-1
revrevolutionsperiod1 rev = 2pi rad
cyclescyclesperiod1 cycles = 1 rev = 2pi rad
degKdegrees Kelvintemperature 
degCdegrees Centigradetemperature 
degFdegrees Fahrenheittemperature 
COMPOUND UNITS
NNewtonforce1 N = 1 kg*m/s^2
microNmicro-Newtonforce1 microN = 10^-6 N = 10^-6 kg*m/s^2
uNmicro-Newtonforce1 uN = 10^-6 N = 10^-6 kg*m/s^2
JJouleenergy1 J = 1 N*m = 1 kg*m^2/s^2
kJkilo-Jouleenergy1 kJ = 1000 J = 10^3 kg*m^2/s^2
lbffoot-poundenergy1 lbf = 1.355 N*m = 1.355 kg*m^2/s^2
WWattpower1 W = 1 J/s = 1 kg*m^2/s^3
kWkilo-Wattpower1 kW = 1000 W = 10^3 kg*m^2/s^3
dynedyneforce1 dyne = 10^-5 N = 10^-5 kg*m/s^2
ergergenergy1 erg= 10^-7 J = 10^-7 kg*m^2/s^2
lbpoundforce1 lb = 4.45 N = 4.45 kg*m/s^2
tontonforce1 ton = 2000 lb = 8900 kg*m/s^2
PaPascalpressure1 Pa = 1 N/m^2 = 1 kg/m*s^2
kPakilo-Pascalpressure1 kPa = 1000 Pa = 10^3 kg/m*s^2
atmatmospherepressure1 atm = 14.7 lb/in^2 = 1.01E5 Pa = 1.01E5 kg/m*s^2
calcalorieenergy1 cal = 4.19 J = 4.19 kg*m^2/s^2
kcalkilocalorieenergy1 kcal = 1000 cal = 4190 kg*m/s^2
eVelectron voltenergy1 eV = 1.60E-19 J = 1.60E-9 kg*m^2/s^2
kWhkilo-Watt hourenergy1 kWh = 3.6E6 J = 3.6E6 kg*m^2/s^2



Multiple choice problems

Some problems require you to enter all of several possible choices that are correct, for example ACEG. In this case, enter the letters corresponding to the choices in one string without any spaces separating the letters.

 

Problems requiring a symbolic functional expression for the answer

Follow the conventions explained in the WebWork section on Accepted math functions.

<| Post or View Comments |>