Forums

Search results: 135

That sounds like a good idea for now. If it works well we can bake it into the moodle/webwork code so that it is easier to set up. I'm working on a rewrite of the basic underpinnings of webwork (originally written more than 10 years ago) which will take a while to finish -- but it should allow us to customize an output mode specifically for moodle. This should make the bridge2 more robust.

The current version of bridge2 was written under the constraint that nothing was changed on the webwork side so some compromises had to be made. By making some additions to the webwork side I think we can make this connection much stronger.

Dear Angel,

The issue probably is the WebWork and Moodle link. However, I'll point out one obvious caveat of compound problems and offer an alternative suggestion (conditional questions).

First the obvious caveat: For some reason, in order to advance from one part to the next in a webwork compound problem you need to submit the correct answer twice. The first time you submit it and get it correct, a new checkbox will appear near the bottom of the page that says "Go on to next part". Select that checkbox and click submit again.

Second, as an alternative to compound problems, you may also want to look into conditional questions. The following example of a conditional question comes from

/Library/Rochester/setMAAtutorial/conditionalquestionexample.pg



##DESCRIPTION
##KEYWORDS('sample')
## Tagged by jjh2b

## DBsubject('WeBWorK')
## DBchapter('WeBWorK Tutorial')
## DBsection('MAA Tutorial')
## Date('8/30/07')
## Author('')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')

DOCUMENT();
loadMacros(
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl"
);
TEXT(beginproblem(), $BR,$BBOLD, "Conditional questions example", $EBOLD, $BR,$BR);
$showPartialCorrectAnswers = 1;

$a1 = random(3,25,1);
$b1 = random(2,27,1);
$x1 = random(-11,11,1);
$a2 = $a1+5;

BEGIN_TEXT
If \( f(x) = $a1 x + $b1 \), find \( f'( $x1 ) \).
$BR $BR \{NAMED_ANS_RULE('first_answer',10) \}
$BR
END_TEXT



$ans_eval1 = num_cmp($a1);
NAMED_ANS(first_answer => $ans_eval1);

# Using named answers allows for more control. Any unique label can be
# used for an answer.
# (see http://webwork.math.rochester.edu/docs/docs/pglanguage/pgreference/managinganswers.html
# for more details on answer evaluator formats and on naming answers
# so that you can refer to them later. Look also at the pod documentation in
# PG.pl and PGbasicmacros.pl which you can also reach at
# http://webwork.math.rochester.edu/docs/techdescription/pglanguage/index.html)

# Check to see that the first answer was answered correctly. If it was then we
# will ask further questions.
$first_Answer = $inputs_ref->{first_answer}; # We need to know what the answer
# was named.
$rh_ans_hash = $ans_eval1->evaluate($first_Answer);

# warn pretty_print($rh_ans_hash); # this is useful technique for finding errors.
# When uncommented it prints out the contents of
# the ans_hash for debugging

# The output of each answer evaluator consists of a single %ans_hash with (at
# least) these entries:
# $ans_hash{score} -- a number between 0 and 1
# $ans_hash{correct_ans} -- The correct answer, as supplied by the instructor
# $ans_hash{student_ans} -- This is the student's answer
# $ans_hash{ans_message} -- Any error message, or hint provided by
# the answer evaluator.
# $ans_hash{type} -- A string indicating the type of answer evaluator.
# -- Some examples:
# 'number_with_units'
# 'function'
# 'frac_number'
# 'arith_number'
# For more details see
# http://webwork.math.rochester.edu/docs/docs/pglanguage/pgreference/answerhashdataype.html

# If they get the first answer right, then we'll ask a second part to the
# question ...
if (1 == $rh_ans_hash->{score} ) {

# WATCH OUT!!: BEGIN_TEXT and END_TEXT have to be on lines by
# themselves and left justified!!! This means you can't indent
# this section as you might want to. The placement of BEGIN_TEXT
# and END_TEXT is one of the very few formatting requirements in
# the PG language.

BEGIN_TEXT
$PAR Right! Now
try the second part of the problem: $PAR $HR
If \( f(x) = $a2 x + \{$b1+5\} \), find \( f'( x) \).
$BR $BR \{ NAMED_ANS_RULE('SecondAnSwEr',10) \}
$BR
END_TEXT

$ans_eval2 = num_cmp($a2);

NAMED_ANS(SecondAnSwEr => $ans_eval2);

}
ENDDOCUMENT();




Hi Angel,

The "bridge2" connection between moodle and webwork on a question by question basis is still somewhat incomplete so I'm not surprised that there are some features that aren't working The connection between moodle and webwork at the set level (bridge1) has now been used in production in a limited number of sites and is in pretty good shape (although it could still use more documentation) but bridge2 is still in beta testing at best.

My suggestion is that you try to implement the multipart aspect on the Moodle side (this is part of the reason for bridge2 exisiting -- is to take advantage of some of the features in the question type that are not mathematics specific so reproducing them in WeBWorK is extra work). This means that the moodle side would store the seed and just ask successive questions of WeBWorK using that same seed.

Let me know whether you think this would work. The bridge2 interface clearly needs work (and for that matter the Compound/Sequential problem capabilities in WeBWorK also needs work) and I'm interested in working on it, but it is a long term not short term project.

Hope this helps.

Take care,

Mike

Hi all,

I'm using Webwork as a question type within moodle.

I need to do a problem divided in different parts. The students can't read the next part if they have not answered the current one. All the parts are using some random numbers so is needed to keep those numbers in memory.

Reading the webwork documentation I have found out how to do it: using CompoundProblem. I've used it in the main webwork framework and it's working properly but when I use it with the moodle integration I can only see the first part, the submit button doesn't show the next part.

Somebody knows where is the problem or how to fix it in order to use it with Moodle?

Thanks a lot
Here's what webwork tells me

$5253.12 $5253.12 incorrect
$5798.47 incorrect

Yes, you're right it marks $5253.12 as incorrect, but it's also telling me this is the correct answer (which I believed). Is this what you see when you try this, or am I missing something?

## http://wwrk.maa.org/moodle/mod/forum/discuss.php?d=459
## seed 3515

########################################################################

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"contextCurrency.pl",
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;

##############################################################
#
# Setup
#
#

TEXT(&beginproblem);
Context("Currency");
$showPartialCorrectAnswers = 1;

@periods = ("annually","semiannually","quarterly","monthly","weekly","daily");
@ms = (1,2,4,12,52,365);

$mm = random(1,4);
$period = $periods[$mm];
$m = $ms[$mm];

$rate = random(5,10);
$r = $rate/100;

$t1 = random(1,6);
$t2 = $t1 + random(1,6);

$p = 5000*random(1,10);
$P = Currency($p);

$a1 = $p*(1+$r/$m)**($m*$t1);
$a2 = $p*(1+$r/$m)**($m*$t2);

$A1 = Currency($a1);
$A2 = Currency($a2);
BEGIN_TEXT;
If $P is invested at $rate$PERCENT compounded $period, what is the amount after
$HR
(A) $t1 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(B) $t2 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(Use dollar signs for monetary values)
END_TEXT
ANS($A1->cmp);
ANS($A2->cmp);
ENDDOCUMENT();
I gave the following problem on a homework set, and a student with seed 3515 gave the correct answer to part (A), but it was marked incorrect, despite displaying as the correct answer. As far as I can tell, she was the only student to have this problem. Can anyone help with this?

Nathan

TEXT(&beginproblem);
Context("Currency");
$showPartialCorrectAnswers = 1;

@periods = ("annually","semiannually","quarterly","monthly","weekly","daily");
@ms = (1,2,4,12,52,365);

$mm = random(1,4);
$period = $periods[$mm];
$m = $ms[$mm];

$rate = random(5,10);
$r = $rate/100;

$t1 = random(1,6);
$t2 = $t1 + random(1,6);

$p = 5000*random(1,10);
$P = Currency($p);

$a1 = $p*(1+$r/$m)**($m*$t1);
$a2 = $p*(1+$r/$m)**($m*$t2);

$A1 = Currency($a1);
$A2 = Currency($a2);
BEGIN_TEXT;
If $P is invested at $rate$PERCENT compounded $period, what is the amount after
$HR
(A) $t1 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(B) $t2 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(Use dollar signs for monetary values)
END_TEXT
ANS($A1->cmp);
ANS($A2->cmp);
ENDDOCUMENT();
I'm not talking about a macro, but an actual MathObject for reactions. Pattern matching for something like this is too fragile; you need the power of an actual formula parser, which is what MathObjects provides. The thing that is needed is the definitions required to make the parser understand chemical formulas, and that means a MathObject Context with the right definitions and support code.

I have put such a context together, and have added it to the pg/macros directory. You can get it from the HEAD version of the CVS repository. There are comments at the top of the file that explain how it works, which I also provide below.

I'm not a chemist, so I don't know if this is exactly what you need, but it looks like it should handle the problems that you illustrated in your initial question. Let me know if it needs adjusting.

Here is the documentation from the file:


contextReaction.pl - Implements a MathObject class for checmical reactions.

This file implements a Context in which checmical reactions can be specified and compared. Reactions can be composed of sums of integer multiples of elements (possibly with subscripts), separated by a right arrow (indicated by "-->"). Helpful error messages are given when a reaction is not of the correct form. Sums of compounds can be given in any order, but the elements within a compound must be in the order given by the correct answer; e.g., if the correct answer specifies CO_2, then O_2C would be marked incorrect.

To use the context include

    loadMacros("contextReaction.pl");
    Context("Reaction");
at the top of your PG file, then create Formula() objects for your reactions. For example:
    $R = Formula("4P + 5O_2 --> 2P_2O_5");
Reactions know how to create their own TeX versions (via $R->TeX), and know how to check student answers (via $R->cmp), just like any other MathObject.

The Reaction Context also allows you to create parts of reactions. E.g., you could create

    $products = Formula("4CO_2 + 6H_2O");
which you could use in a problem as follows:
    loadMacros("contextReaction.pl");
    Context("Reaction");

    $reactants = Formula("2C_2H_6 + 7O_2");
    $products  = Formula("4CO_2 + 6H_2O");

    Context()->texStrings;
    BEGIN_TEXT
    \($reactants \longrightarrow\) \{ans_rule(30)\}.
    END_TEXT
    Context()->normalStrings;

    ANS($products->cmp);

Note that sums and products are not simplified in any way, so that Formula("O + O") and Formula("2O") and Formula("O_2") are all different and unequal in this context.

All the elements of the periodic table are available within the Reaction Context. If you need additional terms, like "Heat" for example, you can add them as variables:

    Context()->variables->add(Heat => $context::Reaction::CONSTANT);
Then you can make formulas that include Heat as a term. These "constants" are not allowed to have coefficients or subscripts, and can not be combined with compounds except by addition. If you want a term that can be combined in those ways, use $context::Reaction::ELEMENT instead.


Hope that does what you need.

Davide

WeBWorK Problems -> Setting up a chemistry problem

by Eric Stroyan -
Sorry in advance for the length of this.
I am trying to set up a problem in which students are to predict the products of a chemical reaction.
The reactants and products are currently stored in a macro file with the following format
%reactions=(
1=>{equation=>"N_{2} + H_{2} \longrightarrow NH_{3}",
class=>"combination",
components=>[
{type=>"reactant", compound=>"N_{2}", coef=>1 },
{type=>"reactant", compound=>"H_{2}", coef=>3 },
{type=>"product", compound=>"NH_{3}", coef=>2 },]},
2=>{equation=>"P + O_{2} \longrightarrow P_{2}O_{5}",
class=>"combination",
components=>[
{type=>"reactant", compound=>"P", coef=>4 },
{type=>"reactant", compound=>"O_{2}", coef=>5 },
{type=>"product", compound=>"P_{2}O_{5}", coef=>2 },]},
3=>{equation=>"C_{2}H_{6} + O_{2} \longrightarrow CO_{2} + H_{2}O",
class=>"combustion",
components=>[
{type=>"reactant", compound=>"C_{2}H_{6}", coef=>2 },
{type=>"reactant", compound=>"O_{2}", coef=>7 },
{type=>"product", compound=>"CO_{2}", coef=>4 },
{type=>"product", compound=>"H_{2}O", coef=>6 },]},
4=>{equation=>"KClO_{3} \longrightarrow KCl + O_{2}",
class=>"decomposition",
components=>[
{type=>"reactant", compound=>"KClO_{3}", coef=>2 },
{type=>"product", compound=>"KCl", coef=>2 },
{type=>"product", compound=>"O_{2}", coef=>3 },]},

The problem that I have working asks the student to predict one of the two products (code attached). I would like to develop a problem with two (or more, as the reaction warrants) answer blanks that students would enter the products in LaTeX format. I have set one up that will check answers, the problem is the products must be in a specific order. I would like to be able to let students enter the products in any order. I'm pretty much shot as to how to do this.
Any suggestions/help would be appreciated.

WeBWorK Problems -> contextFraction.pl -> Re: contextFraction.pl

by Davide Cervone -
There are several problems here. First, the requireProperFractions flag requires the strictFractions flag, so it is really only effective in the LimitedFraction context, not in the plain Fraction context. Also, if you were to get this flag to work Fraction context (by setting strictFraction), then you would not be able to enter the improper fractions that you do in the Compute() calls below.

Second, the LimitedFraction context that you set at the bottom has no effect. This is because MathObjects retain the context in which they were created, so since $ans1, $ans2, and $ans3 where created in the Fraction context, they continue to be in that context even after you change the current context to LimitedFraction.

The proper way to do this is to create them in LimitedFraction context initially (without the requireReducedFractions flag set, so the correct answer can be entered as an improper fraction) and then set the requireReducedFractions flag after they are created.

Here is the code:


    #DESCRIPTION
    ##Type of
    #ENDDESCRIPTION

    DOCUMENT();
    loadMacros(
    "PGstandard.pl",
    #"PGchoicemacros.pl",
    #"PGgraphmacros.pl",
    "MathObjects.pl",
    # "compoundProblem.pl",
    #"contextCurrency.pl",
    #"contextInequalities.pl",
    #"unionTables.pl",
    # "unionLists.pl",
    #"unionMacros.pl",
    #"contextLeadingZero.pl",
    "contextFraction.pl",
    #"answerHints.pl",
    #"problemPanic.pl",
    );
    #for currency use Context("Currency") then Currency($A);
    #Then, in the text use $DOLLAR $a
    TEXT(beginproblem());
    $showPartialCorrectAnswers = 1;

    Context("LimitedFraction");

    $a1=random (3,7,2);
    $b1=random (4,8,4);
    $x=Compute("$a1/$b1");
    $a2=random (4,8,2);
    $b2=random (5,7,2);
    $y=Compute("$a2/$b2");
    $a3=random (3,9,3);
    $b3=random (5,10,5);
    $z=Compute("$a3/$b3");
    $ans1=$x-$y;
    $ans2=$x+2*$y;
    $ans3=$x+$y+$z;
    #warn "a1=$a1, b1=$b1, x=$x, a2=$a2, b2=$b2, y=$y, a3=$a3, b3=$b3, z=$z, a1=$ans1";

    Context()->flags->set(requireProperFractions => 1);


    BEGIN_TEXT
    Evaluate each expression if \(x =\frac{$a1}{$b1}\), \(y=\frac{$a2}{$b2}\), and
    \(z=\frac{$a3}{$b3}\).$BR
    Your answer should be a reduced fraction or a mixed number with the $BR
    faction part reduced (a mixed number can be entered in the form 2 3/4 to
    mean \(2\frac{3}{4}\)).$PAR
    $PAR
    a) \(x-y=\) \{ans_rule(6)\}
    $PAR
    b) \(x+2y=\) \{ans_rule(6)\}
    $PAR
    c) \(x+y+z=\) \{ans_rule(6)\}
    END_TEXT

    ANS($ans1->cmp);
    ANS($ans2->cmp);
    ANS($ans3->cmp);

    ENDDOCUMENT();

Hope that clears things up.

Davide