### Using unicode characters in PopUp( ) answers version 10 webwork.

by tim Payer - Number of replies: 6Hello,

I am trying to use unicode characters to get the intersection and Union symbols to display in PopUp( ) answer displays.

I must have the syntax wrong or a macro that is not loaded?

Any guidance would be most appreciated.

Tim

##DESCRIPTION

## Applying the Rules of addition in probability given table data.

## Emphasis on notation as well as numeric calculation.

## Options for randomizing table data for algorithmic solutions.

##ENDDESCRIPTION

## DBsubject(Probability)

## DBchapter(Random variables)

## DBsection(Expectation)

## Institution(HSU)

## Beginning Statitstics(Tim Payer)

## KEYWORDS('probability','rules of addition','notation')

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

loadMacros(

"PG.pl",

"PGbasicmacros.pl",

"PGchoicemacros.pl",

"PGanswermacros.pl",

"PGauxiliaryFunctions.pl",

"PGasu.pl",

"PGML.pl",

"parserPopUp.pl"

);

TEXT(beginproblem());

## If you would rather not have algorithmic solutions with randomized table data:

## You can "switch" off the randomization by un-commenting the declarations below

## and then comment out the equivalent declarations that have randomization

## in their declarations.

# $r[4] = 15;

# $u[4] = 150;

# $m[4] = 200;

# $l[0] = 205;

# $p[0] = 40;

@x=( "89-95","86-88", "81-85", "77-80", "75-76");

$r[4]= random(12, 18,1);

$r[3]= $r[4]*4 -1;

$r[2]= $r[4]*10 +3;

$r[1]= $r[4]*15 -5;

$r[0]= $r[4]*20 -14;

$rsum = $r[4]+$r[3]+$r[2]+$r[1]+$r[0];

$u[4]= random(121, 131,1);

$u[3]= $u[4]*2 +25;

$u[2]= $u[4]*4 +3;

$u[1]= $u[4]*12 -15;

$u[0]= $u[4]*5 -14;

$usum = $u[4]+$u[3]+$u[2]+$u[1]+$u[0];

$m[4]= random(201, 231,1);

$m[3]= $m[4]*4 -14;

$m[2]= $m[4]*10 +13;

$m[1]= $m[4]*6 -15;

$m[0]= $m[4]*3 +14;

$msum = $m[4]+$m[3]+$m[2]+$m[1]+$m[0];

$l[0]= random(204, 224,1);

$l[1]= $l[0]*2 +52;

$l[2]= $l[0]*3 +33;

$l[3]= $l[0]*10 -5;

$l[4]= $l[0]*3 +14;

$lsum = $l[4]+$l[3]+$l[2]+$l[1]+$l[0];

$p[0]= random(31, 43,1);

$p[1]= $p[0]*2 -17;

$p[2]= $p[0]*3 +3;

$p[3]= $p[0]*6 -15;

$p[4]= $p[0]*7 +24;

$psum = $p[4]+$p[3]+$p[2]+$p[1]+$p[0];

$grand = $psum +$lsum +$msum +$usum +$rsum;

$col0sum = $r[0]+$u[0]+$m[0]+$l[0]+$p[0];

$col1sum = $r[1]+$u[1]+$m[1]+$l[1]+$p[1];

$col2sum = $r[2]+$u[2]+$m[2]+$l[2]+$p[2];

$col3sum = $r[3]+$u[3]+$m[3]+$l[3]+$p[3];

$col4sum = $r[4]+$u[4]+$m[4]+$l[4]+$p[4];

$popup1 = PopUp(

["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)");

$ans1 =$col1sum/$grand;

$popup2 = PopUp(

["probability notation", "P(B U F)", "P(BF)", "P(B ~~x{2229} F)", "P(B + F)", "P(B x F)"], "P(B ~~x{2229} F)");

$ans2 =$p[1]/$grand;

#Unicode errors due to non acceptance of: "P(B ~~x{2229} F)"

# Apparently the unicode wont work here? "~~x{2229}" wont render

# I will replace the "n" with intersection symbols once the proper code is found.

# And I still need to weight the responses with points.

$popup3 = PopUp(

["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R n L)");

$ans3 =0;

$popup4 = PopUp(

["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R U L)");

$ans4 =($rsum+$lsum)/$grand;

$popup5 = PopUp(

["probability notation", "P(P n E)", "P(PE)", "P(P U E)", "P(P + E)", "P(P x E)"], "P(P U E)");

$ans5 =($psum+$col4sum-$p[4])/$grand;

BEGIN_TEXT

$BR

4.2) Recent census data supports the case that life expectancy is correlated with one's income bracket. Given a small town with a population of \($grand\) individuals has a distribution of life expectancy loosely based on the recent census, determine the following probabilities with fourth decimal accuracy. $BR

$PAR

$BLEFT

\{begintable(6)\}

\{row("Expectancy in years", @x, "Row Sum")\}

\{row("Rich", $r[0], $r[1],$r[2],$r[3],$r[4],$rsum)\}

\{row("Upper Middle Class", $u[0], $u[1],$u[2],$u[3],$u[4],$usum)\}

\{row(" Middle Class", $m[0], $m[1],$m[2],$m[3],$m[4],$msum)\}

\{row("Lower Middle Class", $l[0], $l[1],$l[2],$l[3],$l[4],$lsum)\}

\{row("Poor", $p[0], $p[1],$p[2],$p[3],$p[4],$psum)\}

\{row("Column Sum", $col0sum, $col1sum,$col2sum,$col3sum,$col4sum,$grand)\}

\{endtable()\}

$ELEFT

$PAR

Use the the following event variable declarations within probability notation to find the associated probabilities with fourth decimal accuracy.

$PAR

END_TEXT

BEGIN_PGML

[`A`] = Event that an individual of the town has a life expectancy of 89-95 years.

[`B`] = Event that an individual of the town has a life expectancy of 86-88 years.

[`C`] = Event that an individual of the town has a life expectancy of 81-85 years.

[`D`] = Event that an individual of the town has a life expectancy of 77-80 years.

[`E`] = Event that an individual of the town has a life expectancy of 75-79 years.

[`R`] = Event that an individual of the town is rich.

[`S`] = Event that an individual of the town is of the upper middle class.

[`M`] = Event that an individual of the town is of the middle class.

[`L`] = Event that an individual of the town is of the lower middle class.

[`F`] = Event that an individual of the town is poor.

4.2a) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years:

[_____]{$popup1} = [______]{$ans1}

4.2b) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor:

[_____]{$popup2} = [______]{$ans2}

4.2c) Find the probability of drawing an individual from the town that is rich and is of the lower middle class:

[_____]{$popup3} = [______]{$ans3}

4.2d) Find the probability of drawing an individual from the town that is rich or is of the lower middle class:

[_____]{$popup4} = [______]{$ans4}

4.2e) Find the probability of drawing an individual from the town that is either poor or has a life expectancy of 75-76 years or both:

[_____]{$popup5} = [______]{$ans5}

END_PGML

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

In reply to tim Payer

### Re: Using unicode characters in PopUp( ) answers version 10 webwork.

by John Travis -
Try this. I separated the unicode usage from the popup call and all is well. I have only a part of your problem here...

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

loadMacros(

"PG.pl",

"PGbasicmacros.pl",

"PGchoicemacros.pl",

"PGanswermacros.pl",

"PGauxiliaryFunctions.pl",

"PGasu.pl",

"PGML.pl",

"parserPopUp.pl"

);

TEXT(beginproblem());

## If you would rather not have algorithmic solutions with randomized table data:

## You can "switch" off the randomization by un-commenting the declarations below

## and then comment out the equivalent declarations that have randomization

## in their declarations.

@x=( "89-95","86-88", "81-85", "77-80", "75-76");

$popup1 = PopUp(

["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)");

$ans1 =Compute("1");

$c1 = "P(B ~~x{2229} F)";

$c2 = "P(B ~~x{222A} F)";

$c3 = "P(B ~~x{2A2F} F)";

$popup2 = PopUp(

["probability notation",$c2, $c1, "P(B + F)", $c3], $c1);

$ans2 =Compute("2");

BEGIN_PGML

[`A`] = Event that an individual of the town has a life expectancy of 89-95 years.

[`B`] = Event that an individual of the town has a life expectancy of 86-88 years.

[`C`] = Event that an individual of the town has a life expectancy of 81-85 years.

[`D`] = Event that an individual of the town has a life expectancy of 77-80 years.

[`E`] = Event that an individual of the town has a life expectancy of 75-79 years.

[`R`] = Event that an individual of the town is rich.

[`S`] = Event that an individual of the town is of the upper middle class.

[`M`] = Event that an individual of the town is of the middle class.

[`L`] = Event that an individual of the town is of the lower middle class.

[`F`] = Event that an individual of the town is poor.

4.2a) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years:

[_____]{$popup1} = [______]{$ans1}

4.2b) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor:

[_____]{$popup2} = [______]{$ans2}

END_PGML

ENDDOCUMENT();

In reply to John Travis

### Re: Using unicode characters in PopUp( ) answers version 10 webwork.

by tim Payer -
Thanks John!

I will give that a try real soon.

I truly appreciate the feedback.

Best, Tim

In reply to tim Payer

### Re: Using unicode characters in PopUp( ) answers version 10 webwork.

by tim Payer -
Hello Again,

Unfortunately No, that last trick did not work for me. I am still getting errors when I try to unicode characters as you suggested.

Is it possible that There are limitations to Version 10?

Or is there something that i am missing here?

Please see if you can find the glitch in regard to the Unicode on lines 92-101

Thanks so much, Tim

##DESCRIPTION

## Applying the Rules of addition in probability given table data.

## Emphasis on notation as well as numeric calculation.

## Options for randomizing table data for algorithmic solutions.

##ENDDESCRIPTION

## DBsubject(Probability)

## DBchapter(Random variables)

## DBsection(Expectation)

## Institution(HSU)

## Beginning Statitstics(Tim Payer)

## KEYWORDS('probability','rules of addition','notation')

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

loadMacros(

"PG.pl",

"PGbasicmacros.pl",

"PGchoicemacros.pl",

"PGanswermacros.pl",

"PGauxiliaryFunctions.pl",

"PGasu.pl",

"PGML.pl",

"parserPopUp.pl"

);

TEXT(beginproblem());

## If you would rather not have algorithmic solutions with randomized table data:

## You can "switch" off the randomization by un-commenting the declarations below

## and then comment out the equivalent declarations that have randomization

## in their declarations.

# $r[4] = 15;

# $u[4] = 150;

# $m[4] = 200;

# $l[0] = 205;

# $p[0] = 40;

Context("Numeric");

Context()->flags->set(

tolerance => 0.0001,

tolType => "absolute",

);

@x=( "89-95","86-88", "81-85", "77-80", "75-76");

$r[4]= random(12, 18,1);

$r[3]= $r[4]*4 -1;

$r[2]= $r[4]*10 +3;

$r[1]= $r[4]*15 -5;

$r[0]= $r[4]*20 -14;

$rsum = $r[4]+$r[3]+$r[2]+$r[1]+$r[0];

$u[4]= random(121, 131,1);

$u[3]= $u[4]*2 +25;

$u[2]= $u[4]*4 +3;

$u[1]= $u[4]*12 -15;

$u[0]= $u[4]*5 -14;

$usum = $u[4]+$u[3]+$u[2]+$u[1]+$u[0];

$m[4]= random(201, 231,1);

$m[3]= $m[4]*4 -14;

$m[2]= $m[4]*10 +13;

$m[1]= $m[4]*6 -15;

$m[0]= $m[4]*3 +14;

$msum = $m[4]+$m[3]+$m[2]+$m[1]+$m[0];

$l[0]= random(204, 224,1);

$l[1]= $l[0]*2 +52;

$l[2]= $l[0]*3 +33;

$l[3]= $l[0]*10 -5;

$l[4]= $l[0]*3 +14;

$lsum = $l[4]+$l[3]+$l[2]+$l[1]+$l[0];

$p[0]= random(31, 43,1);

$p[1]= $p[0]*2 -17;

$p[2]= $p[0]*3 +3;

$p[3]= $p[0]*6 -15;

$p[4]= $p[0]*7 +24;

$psum = $p[4]+$p[3]+$p[2]+$p[1]+$p[0];

$grand = $psum +$lsum +$msum +$usum +$rsum;

$col0sum = $r[0]+$u[0]+$m[0]+$l[0]+$p[0];

$col1sum = $r[1]+$u[1]+$m[1]+$l[1]+$p[1];

$col2sum = $r[2]+$u[2]+$m[2]+$l[2]+$p[2];

$col3sum = $r[3]+$u[3]+$m[3]+$l[3]+$p[3];

$col4sum = $r[4]+$u[4]+$m[4]+$l[4]+$p[4];

$c1 = "P(B ~~x{2229} F)";

$c2 = "P(B ~~x{222A} F)";

$c3 = "P(B ~~x{2A2F} F)";

$popup1 = PopUp(

["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)");

$ans1 =$col1sum/$grand;

$popup2 = PopUp(

["probability notation", "P(B U F)", "P(BF)", $c1, "P(B + F)", $c3], $c1);

$ans2 =$p[1]/$grand;

#Unicode errors due to non acceptance of: "P(B ~~x{2229} F)"

# Apparently the unicode wont work here? "~~x{2229}" wont render

# I will replace the "n" with intersection symbols once the proper code is found.

# And I still need to weight the responses with points.

$popup3 = PopUp(

["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R n L)");

$ans3 =0;

$popup4 = PopUp(

["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R U L)");

$ans4 =($rsum+$lsum)/$grand;

$popup5 = PopUp(

["probability notation", "P(F n E)", "P(FE)", "P(F U E)", "P(F + E)", "P(F x E)"], "P(F U E)");

$ans5 =Compute("($psum+$col4sum-$p[4])/$grand");

BEGIN_TEXT

$BR

4.2) Recent census data supports the case that life expectancy is correlated with one's income bracket. Given a small town with a population of \($grand\) individuals has a distribution of life expectancy loosely based on the recent census, determine the following probabilities with fourth decimal accuracy. $BR

$PAR

$BLEFT

\{begintable(6)\}

\{row("Expectancy in years", @x, "Row Sum")\}

\{row("Rich", $r[0], $r[1],$r[2],$r[3],$r[4],$rsum)\}

\{row("Upper Middle Class", $u[0], $u[1],$u[2],$u[3],$u[4],$usum)\}

\{row(" Middle Class", $m[0], $m[1],$m[2],$m[3],$m[4],$msum)\}

\{row("Lower Middle Class", $l[0], $l[1],$l[2],$l[3],$l[4],$lsum)\}

\{row("Poor", $p[0], $p[1],$p[2],$p[3],$p[4],$psum)\}

\{row("Column Sum", $col0sum, $col1sum,$col2sum,$col3sum,$col4sum,$grand)\}

\{endtable()\}

$ELEFT

$PAR

Use the the following event variable declarations within probability notation to find the associated probabilities with fourth decimal accuracy.

$PAR

END_TEXT

BEGIN_PGML

[`A`] = Event that an individual of the town has a life expectancy of 89-95 years.

[`B`] = Event that an individual of the town has a life expectancy of 86-88 years.

[`C`] = Event that an individual of the town has a life expectancy of 81-85 years.

[`D`] = Event that an individual of the town has a life expectancy of 77-80 years.

[`E`] = Event that an individual of the town has a life expectancy of 75-79 years.

[`R`] = Event that an individual of the town is rich.

[`S`] = Event that an individual of the town is of the upper middle class.

[`M`] = Event that an individual of the town is of the middle class.

[`L`] = Event that an individual of the town is of the lower middle class.

[`F`] = Event that an individual of the town is poor.

4.2a) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years:

[_____]{$popup1} = [______]{$ans1}

4.2b) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor:

[_____]{$popup2} = [______]{$ans2}

4.2c) Find the probability of drawing an individual from the town that is rich and is of the lower middle class:

[_____]{$popup3} = [______]{$ans3}

4.2d) Find the probability of drawing an individual from the town that is rich or is of the lower middle class:

[_____]{$popup4} = [______]{$ans4}

4.2e) Find the probability of drawing an individual from the town that is either poor or has a life expectancy of 75-76 years or both:

[_____]{$popup5} = [______]{$ans5}

END_PGML

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

In reply to tim Payer

### Re: Using unicode characters in PopUp( ) answers version 10 webwork.

by Davide Cervone -
You say you are getting errors, but don't indicate what they are. Listing the actual errors might help us identify what is going on.

You ask "Is it possible that There are limitations to Version 10?" It is not likely that it has anything to do with PG itself, as this is just about the perl language. It is possible that the safe compartment might interact badly with it (e.g., it requires some package that hasn't been loaded in the safe compartment), but we can't tell without the error message.

It may also be an issue with the version of perl that you are using. I think these unicode features were added in perl 5.22, so if you have an earlier one, that might be the problem.

Finally, I have send on occasion an error message from perl about "wide characters", meaning unicode positions that require two bytes rather than just one in the UTF-8 encoding, being used in printed output that is not already in UTF-8. It might be that WeBWorK code needs something like "use utf8" or something in order to avoid that. But again, the actual error message should shed light on which (if any) of these is the issue you are facing.

You ask "Is it possible that There are limitations to Version 10?" It is not likely that it has anything to do with PG itself, as this is just about the perl language. It is possible that the safe compartment might interact badly with it (e.g., it requires some package that hasn't been loaded in the safe compartment), but we can't tell without the error message.

It may also be an issue with the version of perl that you are using. I think these unicode features were added in perl 5.22, so if you have an earlier one, that might be the problem.

Finally, I have send on occasion an error message from perl about "wide characters", meaning unicode positions that require two bytes rather than just one in the UTF-8 encoding, being used in printed output that is not already in UTF-8. It might be that WeBWorK code needs something like "use utf8" or something in order to avoid that. But again, the actual error message should shed light on which (if any) of these is the issue you are facing.

In reply to Davide Cervone

### Re: Using unicode characters in PopUp( ) answers version 10 webwork.

by tim Payer -
Thank you Davide,

Here is the error message for the code using unicode inserts:

Thanks so much for being willing to take a look at it.

Problem1 ERROR caught by Translator while processing problem file:Payer/S109/HW_4/income_longevity.pg **************** ERRORS from evaluating PG file:

'require' trapped by operation mask at [PG]/lib/Value/AnswerChecker.pm line 780 Died within Value::String::cmp called at line 942 of [PG]/macros/PGML.pl from within PGML::Format::Answer called at line 839 of [PG]/macros/PGML.pl from within PGML::Format::string called at line 993 of [PG]/macros/PGML.pl from within PGML::Format::html::Indent called at line 830 of [PG]/macros/PGML.pl from within PGML::Format::string called at line 819 of [PG]/macros/PGML.pl from within PGML::Format::format called at line 1252 of [PG]/macros/PGML.pl from within PGML::Format called at line 1261 of [PG]/macros/PGML.pl from within PGML::Format2 called at line 142 of (eval 10617)

****************

------Input Read 1 ##DESCRIPTION 2 ## Applying the Rules of addition in probability given table data. 3 ## Emphasis on notation as well as numeric calculation. 4 ## Options for randomizing table data for algorithmic solutions. 5 ##ENDDESCRIPTION 6 7 8 ## DBsubject(Probability) 9 ## DBchapter(Random variables) 10 ## DBsection(Expectation) 11 ## Institution(HSU) 12 ## Beginning Statitstics(Tim Payer) 13 ## KEYWORDS('probability','rules of addition','notation') 14 15 DOCUMENT(); # This should be the first executable line in the problem. 16 17 loadMacros( 18 "PG.pl", 19 "PGbasicmacros.pl", 20 "PGchoicemacros.pl", 21 "PGanswermacros.pl", 22 "PGauxiliaryFunctions.pl", 23 "PGasu.pl", 24 "PGML.pl", 25 "parserPopUp.pl" 26 ); 27 28 TEXT(beginproblem()); 29 30 ## If you would rather not have algorithmic solutions with randomized table data: 31 ## You can "switch" off the randomization by un-commenting the declarations below 32 ## and then comment out the equivalent declarations that have randomization 33 ## in their declarations. 34 35 # $r[4] = 15; 36 # $u[4] = 150; 37 # $m[4] = 200; 38 # $l[0] = 205; 39 # $p[0] = 40; 40 41 Context("Numeric"); 42 Context()->flags->set( 43 tolerance => 0.0001, 44 tolType => "absolute", 45 ); 46 47 48 @x=( "89-95","86-88", "81-85", "77-80", "75-76"); 49 $r[4]= random(12, 18,1); 50 $r[3]= $r[4]*4 -1; 51 $r[2]= $r[4]*10 +3; 52 $r[1]= $r[4]*15 -5; 53 $r[0]= $r[4]*20 -14; 54 $rsum = $r[4]+$r[3]+$r[2]+$r[1]+$r[0]; 55 56 $u[4]= random(121, 131,1); 57 $u[3]= $u[4]*2 +25; 58 $u[2]= $u[4]*4 +3; 59 $u[1]= $u[4]*12 -15; 60 $u[0]= $u[4]*5 -14; 61 $usum = $u[4]+$u[3]+$u[2]+$u[1]+$u[0]; 62 63 $m[4]= random(201, 231,1); 64 $m[3]= $m[4]*4 -14; 65 $m[2]= $m[4]*10 +13; 66 $m[1]= $m[4]*6 -15; 67 $m[0]= $m[4]*3 +14; 68 $msum = $m[4]+$m[3]+$m[2]+$m[1]+$m[0]; 69 70 $l[0]= random(204, 224,1); 71 $l[1]= $l[0]*2 +52; 72 $l[2]= $l[0]*3 +33; 73 $l[3]= $l[0]*10 -5; 74 $l[4]= $l[0]*3 +14; 75 $lsum = $l[4]+$l[3]+$l[2]+$l[1]+$l[0]; 76 77 $p[0]= random(31, 43,1); 78 $p[1]= $p[0]*2 -17; 79 $p[2]= $p[0]*3 +3; 80 $p[3]= $p[0]*6 -15; 81 $p[4]= $p[0]*7 +24; 82 $psum = $p[4]+$p[3]+$p[2]+$p[1]+$p[0]; 83 84 $grand = $psum +$lsum +$msum +$usum +$rsum; 85 86 $col0sum = $r[0]+$u[0]+$m[0]+$l[0]+$p[0]; 87 $col1sum = $r[1]+$u[1]+$m[1]+$l[1]+$p[1]; 88 $col2sum = $r[2]+$u[2]+$m[2]+$l[2]+$p[2]; 89 $col3sum = $r[3]+$u[3]+$m[3]+$l[3]+$p[3]; 90 $col4sum = $r[4]+$u[4]+$m[4]+$l[4]+$p[4]; 91 92 $c1 = "P(B ~~x{2229} F)"; 93 $c2 = "P(B ~~x{222A} F)"; 94 $c3 = "P(B ~~x{2A2F} F)"; 95 96 $popup1 = PopUp( 97 ["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)"); 98 $ans1 =$col1sum/$grand; 99 100 $popup2 = PopUp( 101 #["probability notation", "P(B U F)", "P(BF)", $c1, "P(B + F)", $c3], $c1); 102 ["probability notation", "P(B U F)", "P(BF)", "P(B ~~x{2229} F)", "P(B + F)", "P(B x F)"], "P(B ~~x{2229} F)"); 103 $ans2 =$p[1]/$grand; 104 105 #Unicode errors due to non acceptance of: "P(B ~~x{2229} F)" 106 # Apparently the unicode wont work here? "~~x{2229}" wont render 107 # I will replace the "n" with intersection symbols once the proper code is found. 108 # And I still need to weight the responses with points. 109 110 $popup3 = PopUp( 111 ["probability notation", "P(R U L)", "P(RL)", "P(R ~~x{2229} L)", "P(R + L)", "P(R x L)"], "P(R ~~x{2229} L)"); 112 $ans3 =0; 113 114 $popup4 = PopUp( 115 ["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R U L)"); 116 $ans4 =($rsum+$lsum)/$grand; 117 118 $popup5 = PopUp( 119 ["probability notation", "P(F n E)", "P(FE)", "P(F U E)", "P(F + E)", "P(F x E)"], "P(F U E)"); 120 $ans5 =Compute("($psum+$col4sum-$p[4])/$grand"); 121 122 123 124 BEGIN_TEXT 125 $BR 126 127 4.2) Recent census data supports the case that life expectancy is correlated with one's income bracket. Given a small town with a population of \($grand\) individuals has a distribution of life expectancy loosely based on the recent census, determine the following probabilities with fourth decimal accuracy. $BR 128 $PAR 129 $BLEFT 130 \{begintable(6)\} 131 \{row("Expectancy in years", @x, "Row Sum")\} 132 \{row("Rich", $r[0], $r[1],$r[2],$r[3],$r[4],$rsum)\} 133 \{row("Upper Middle Class", $u[0], $u[1],$u[2],$u[3],$u[4],$usum)\} 134 \{row(" Middle Class", $m[0], $m[1],$m[2],$m[3],$m[4],$msum)\} 135 \{row("Lower Middle Class", $l[0], $l[1],$l[2],$l[3],$l[4],$lsum)\} 136 \{row("Poor", $p[0], $p[1],$p[2],$p[3],$p[4],$psum)\} 137 \{row("Column Sum", $col0sum, $col1sum,$col2sum,$col3sum,$col4sum,$grand)\} 138 \{endtable()\} 139 $ELEFT 140 141 $PAR 142 Use the the following event variable declarations within probability notation to find the associated probabilities with fourth decimal accuracy. 143 $PAR 144 END_TEXT 145 146 BEGIN_PGML 147 148 [`A`] = Event that an individual of the town has a life expectancy of 89-95 years. 149 [`B`] = Event that an individual of the town has a life expectancy of 86-88 years. 150 [`C`] = Event that an individual of the town has a life expectancy of 81-85 years. 151 [`D`] = Event that an individual of the town has a life expectancy of 77-80 years. 152 [`E`] = Event that an individual of the town has a life expectancy of 75-79 years. 153 [`R`] = Event that an individual of the town is rich. 154 [`S`] = Event that an individual of the town is of the upper middle class. 155 [`M`] = Event that an individual of the town is of the middle class. 156 [`L`] = Event that an individual of the town is of the lower middle class. 157 [`F`] = Event that an individual of the town is poor. 158 159 160 4.2a) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years: 161 162 [_____]{$popup1} = [______]{$ans1} 163 164 4.2b) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor: 165 166 [_____]{$popup2} = [______]{$ans2} 167 168 4.2c) Find the probability of drawing an individual from the town that is rich and is of the lower middle class: 169 170 [_____]{$popup3} = [______]{$ans3} 171 172 4.2d) Find the probability of drawing an individual from the town that is rich or is of the lower middle class: 173 174 [_____]{$popup4} = [______]{$ans4} 175 176 4.2e) Find the probability of drawing an individual from the town that is either poor or has a life expectancy of 75-76 years or both: 177 178 [_____]{$popup5} = [______]{$ans5} 179 180 END_PGML 181 182 183 ENDDOCUMENT(); # This should be the last executable line in the problem. -----

## WeBWorK Error

### Error messages

### Error details

```
Problem1
ERROR caught by Translator while processing problem file:Payer/S109/HW_4/income_longevity.pg
****************
ERRORS from evaluating PG file:
```

'require' trapped by operation mask at [PG]/lib/Value/AnswerChecker.pm line 780
Died within Value::String::cmp called at line 942 of [PG]/macros/PGML.pl
from within PGML::Format::Answer called at line 839 of [PG]/macros/PGML.pl
from within PGML::Format::string called at line 993 of [PG]/macros/PGML.pl
from within PGML::Format::html::Indent called at line 830 of [PG]/macros/PGML.pl
from within PGML::Format::string called at line 819 of [PG]/macros/PGML.pl
from within PGML::Format::format called at line 1252 of [PG]/macros/PGML.pl
from within PGML::Format called at line 1261 of [PG]/macros/PGML.pl
from within PGML::Format2 called at line 142 of (eval 10617)

****************

------Input Read
1 ##DESCRIPTION
2 ## Applying the Rules of addition in probability given table data.
3 ## Emphasis on notation as well as numeric calculation.
4 ## Options for randomizing table data for algorithmic solutions.
5 ##ENDDESCRIPTION
6
7
8 ## DBsubject(Probability)
9 ## DBchapter(Random variables)
10 ## DBsection(Expectation)
11 ## Institution(HSU)
12 ## Beginning Statitstics(Tim Payer)
13 ## KEYWORDS('probability','rules of addition','notation')
14
15 DOCUMENT(); # This should be the first executable line in the problem.
16
17 loadMacros(
18 "PG.pl",
19 "PGbasicmacros.pl",
20 "PGchoicemacros.pl",
21 "PGanswermacros.pl",
22 "PGauxiliaryFunctions.pl",
23 "PGasu.pl",
24 "PGML.pl",
25 "parserPopUp.pl"
26 );
27
28 TEXT(beginproblem());
29
30 ## If you would rather not have algorithmic solutions with randomized table data:
31 ## You can "switch" off the randomization by un-commenting the declarations below
32 ## and then comment out the equivalent declarations that have randomization
33 ## in their declarations.
34
35 # $r[4] = 15;
36 # $u[4] = 150;
37 # $m[4] = 200;
38 # $l[0] = 205;
39 # $p[0] = 40;
40
41 Context("Numeric");
42 Context()->flags->set(
43 tolerance => 0.0001,
44 tolType => "absolute",
45 );
46
47
48 @x=( "89-95","86-88", "81-85", "77-80", "75-76");
49 $r[4]= random(12, 18,1);
50 $r[3]= $r[4]*4 -1;
51 $r[2]= $r[4]*10 +3;
52 $r[1]= $r[4]*15 -5;
53 $r[0]= $r[4]*20 -14;
54 $rsum = $r[4]+$r[3]+$r[2]+$r[1]+$r[0];
55
56 $u[4]= random(121, 131,1);
57 $u[3]= $u[4]*2 +25;
58 $u[2]= $u[4]*4 +3;
59 $u[1]= $u[4]*12 -15;
60 $u[0]= $u[4]*5 -14;
61 $usum = $u[4]+$u[3]+$u[2]+$u[1]+$u[0];
62
63 $m[4]= random(201, 231,1);
64 $m[3]= $m[4]*4 -14;
65 $m[2]= $m[4]*10 +13;
66 $m[1]= $m[4]*6 -15;
67 $m[0]= $m[4]*3 +14;
68 $msum = $m[4]+$m[3]+$m[2]+$m[1]+$m[0];
69
70 $l[0]= random(204, 224,1);
71 $l[1]= $l[0]*2 +52;
72 $l[2]= $l[0]*3 +33;
73 $l[3]= $l[0]*10 -5;
74 $l[4]= $l[0]*3 +14;
75 $lsum = $l[4]+$l[3]+$l[2]+$l[1]+$l[0];
76
77 $p[0]= random(31, 43,1);
78 $p[1]= $p[0]*2 -17;
79 $p[2]= $p[0]*3 +3;
80 $p[3]= $p[0]*6 -15;
81 $p[4]= $p[0]*7 +24;
82 $psum = $p[4]+$p[3]+$p[2]+$p[1]+$p[0];
83
84 $grand = $psum +$lsum +$msum +$usum +$rsum;
85
86 $col0sum = $r[0]+$u[0]+$m[0]+$l[0]+$p[0];
87 $col1sum = $r[1]+$u[1]+$m[1]+$l[1]+$p[1];
88 $col2sum = $r[2]+$u[2]+$m[2]+$l[2]+$p[2];
89 $col3sum = $r[3]+$u[3]+$m[3]+$l[3]+$p[3];
90 $col4sum = $r[4]+$u[4]+$m[4]+$l[4]+$p[4];
91
92 $c1 = "P(B ~~x{2229} F)";
93 $c2 = "P(B ~~x{222A} F)";
94 $c3 = "P(B ~~x{2A2F} F)";
95
96 $popup1 = PopUp(
97 ["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)");
98 $ans1 =$col1sum/$grand;
99
100 $popup2 = PopUp(
101 #["probability notation", "P(B U F)", "P(BF)", $c1, "P(B + F)", $c3], $c1);
102 ["probability notation", "P(B U F)", "P(BF)", "P(B ~~x{2229} F)", "P(B + F)", "P(B x F)"], "P(B ~~x{2229} F)");
103 $ans2 =$p[1]/$grand;
104
105 #Unicode errors due to non acceptance of: "P(B ~~x{2229} F)"
106 # Apparently the unicode wont work here? "~~x{2229}" wont render
107 # I will replace the "n" with intersection symbols once the proper code is found.
108 # And I still need to weight the responses with points.
109
110 $popup3 = PopUp(
111 ["probability notation", "P(R U L)", "P(RL)", "P(R ~~x{2229} L)", "P(R + L)", "P(R x L)"], "P(R ~~x{2229} L)");
112 $ans3 =0;
113
114 $popup4 = PopUp(
115 ["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R U L)");
116 $ans4 =($rsum+$lsum)/$grand;
117
118 $popup5 = PopUp(
119 ["probability notation", "P(F n E)", "P(FE)", "P(F U E)", "P(F + E)", "P(F x E)"], "P(F U E)");
120 $ans5 =Compute("($psum+$col4sum-$p[4])/$grand");
121
122
123
124 BEGIN_TEXT
125 $BR
126
127 4.2) Recent census data supports the case that life expectancy is correlated with one's income bracket. Given a small town with a population of \($grand\) individuals has a distribution of life expectancy loosely based on the recent census, determine the following probabilities with fourth decimal accuracy. $BR
128 $PAR
129 $BLEFT
130 \{begintable(6)\}
131 \{row("Expectancy in years", @x, "Row Sum")\}
132 \{row("Rich", $r[0], $r[1],$r[2],$r[3],$r[4],$rsum)\}
133 \{row("Upper Middle Class", $u[0], $u[1],$u[2],$u[3],$u[4],$usum)\}
134 \{row(" Middle Class", $m[0], $m[1],$m[2],$m[3],$m[4],$msum)\}
135 \{row("Lower Middle Class", $l[0], $l[1],$l[2],$l[3],$l[4],$lsum)\}
136 \{row("Poor", $p[0], $p[1],$p[2],$p[3],$p[4],$psum)\}
137 \{row("Column Sum", $col0sum, $col1sum,$col2sum,$col3sum,$col4sum,$grand)\}
138 \{endtable()\}
139 $ELEFT
140
141 $PAR
142 Use the the following event variable declarations within probability notation to find the associated probabilities with fourth decimal accuracy.
143 $PAR
144 END_TEXT
145
146 BEGIN_PGML
147
148 [`A`] = Event that an individual of the town has a life expectancy of 89-95 years.
149 [`B`] = Event that an individual of the town has a life expectancy of 86-88 years.
150 [`C`] = Event that an individual of the town has a life expectancy of 81-85 years.
151 [`D`] = Event that an individual of the town has a life expectancy of 77-80 years.
152 [`E`] = Event that an individual of the town has a life expectancy of 75-79 years.
153 [`R`] = Event that an individual of the town is rich.
154 [`S`] = Event that an individual of the town is of the upper middle class.
155 [`M`] = Event that an individual of the town is of the middle class.
156 [`L`] = Event that an individual of the town is of the lower middle class.
157 [`F`] = Event that an individual of the town is poor.
158
159
160 4.2a) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years:
161
162 [_____]{$popup1} = [______]{$ans1}
163
164 4.2b) Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor:
165
166 [_____]{$popup2} = [______]{$ans2}
167
168 4.2c) Find the probability of drawing an individual from the town that is rich and is of the lower middle class:
169
170 [_____]{$popup3} = [______]{$ans3}
171
172 4.2d) Find the probability of drawing an individual from the town that is rich or is of the lower middle class:
173
174 [_____]{$popup4} = [______]{$ans4}
175
176 4.2e) Find the probability of drawing an individual from the town that is either poor or has a life expectancy of 75-76 years or both:
177
178 [_____]{$popup5} = [______]{$ans5}
179
180 END_PGML
181
182
183 ENDDOCUMENT(); # This should be the last executable line in the problem.

In reply to tim Payer

### Re: Using unicode characters in PopUp( ) answers version 10 webwork.

by Davide Cervone -
Unfortunately, this message is from the Safe compartment. Apparently, something in the use of the Unicode characters is requiring perl to load some additional component, and that is being prevented by the Safe compartment. I don't know what package it is, but we ran into something like that once some time ago and added the utf8 package to the pg modules list. The line that is triggering the message is one where the correct answer is tested to see if it is non-blank using a regular expression. I suspect it is the regular expression code that is trying to load some information about unicode when it sees the intersection.

The only solution I can think of is to force the Safe compartment to load whatever it is that is needed prior to disabling the require command. That would take some experimenting, and the Safe compartment handling is pretty delicate, so it is not for the feint of heart.

An alternative would be to not use the unicode character but mark it in another way, and have some javascript go through the menus after they are in the browser to insert the unicode. To do that right would also require adjustments to the PopUp context so that the answers would show the proper character in the results table. It is a complete hack, but would be possible.

The only solution I can think of is to force the Safe compartment to load whatever it is that is needed prior to disabling the require command. That would take some experimenting, and the Safe compartment handling is pretty delicate, so it is not for the feint of heart.

An alternative would be to not use the unicode character but mark it in another way, and have some javascript go through the menus after they are in the browser to insert the unicode. To do that right would also require adjustments to the PopUp context so that the answers would show the proper character in the results table. It is a complete hack, but would be possible.