## WeBWorK Problems

### Math Object Formatting Question ### Math Object Formatting Question

by Cindy Loten -
Number of replies: 3

I am programming some combinatorics questions, and have run into the following situation:   My answer, $ans= Compute("C(60+6-1,60)") ; created in the IntegerFunctions context, is formatted correctly in the feedback table showing the correct answer, but I can't replicate this formatting in the PGML environment. All I get are the computed really big numbers, but I want the C(m,n) notation. This is causing issues for me as I want to refer to$ans (and other similarly constructed numbers)  in the PGML solution environment.  I have included a small working example and a screen shot below.

Thanks!

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

DOCUMENT();

"PGstandard.pl",     # Standard macros for PG language
"MathObjects.pl",
"PGML.pl",
"PGchoicemacros.pl",     # NchooseK defined here
"contextIntegerFunctions.pl",    #  need for P(n,k) and C(n,k);
#"source.pl",        # allows code to be displayed on certain sites.
"PGcourse.pl",      # Customization file for the course
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect, set to 0 for no information
$showPartialCorrectAnswers = 1; ############################################################## # # Setup # # Context("IntegerFunctions");$ans= Compute("C(60+6-1,60)") ;

BEGIN_PGML
Determine the number of integer solutions to the following equation.
>>[x_1+x_2+ \ldots +x_{6} = 60]<<
where [x_i \geq 0  ] for [i =1,2,3,\ldots, 6].

My answer is [_]{$ans}{10}. Testing formatting for [| [$ans], [$ans]*, [$ans]**, [$ans]***|] [$ans], [$ans]*, [$ans]**, [$ans]*** Testing formatting for [| [: [$ans], [$ans]*, [$ans]**, [$ans]*** :]|] [: [$ans], [$ans]*, [$ans]**, [$ans]*** :] I am looking for the command so that [|$ans |] produces the C(m,n) formatting, not the computed (large) number.
END_PGML

ENDDOCUMENT();

The result  ### Re: Math Object Formatting Question

by Jaimos Skriletz -

The issue here is that PGML runs either the ->string or ->TeX method on the $ans object which because it is a Real in the end, outputs the associated number. One way here is define your answer as a string to use in the PGML output. Something like: $ans_str = "C(60+6-1,60)";
$ans = Compute($ans_str);


Then when in PGML you can just use [$ans_str]. I've ran into this a few times, and use the above method. I haven't found a way to get the same output as Compute, without just using a second variable. In reply to Cindy Loten ### Re: Math Object Formatting Question by Andrew Parker - Try this: Context("IntegerFunctions")->flags->set( reduceConstants=>0, reduceConstantFunctions=>0);$ans= Formula("C(60+6-1,60)");

First, tell the context not to compute operations between constants nor constant-valued functions, then define the answer object explicitly as Formula (rather than using Compute). With these two context flags, $ans will be displayed "C(60+6-1,60)". If reduceConstants=>0 is removed, keeping only reduceConstantFunctions=>0, the arithmetic operations will be computed, but not the "C" function output.$ans will be displayed "C(65,60)" 