WeBWorK Problems

Table justification, and table cell justification.

Table justification, and table cell justification.

by tim Payer -
Number of replies: 0
Greetings,

1.)  I am trying to left justify the contents of a table holding several equations.
Sadly, my short term hack is to insert numerous "\quad" entries in an effort to allign the entries of each cell.

It is okay, but I am wondering if there is a better way than entering numerous "\quad" spacers?  Do you see a better way?

2.) I inserted one of the example tables from the "Using Tables" in a homework problem. But unfortunately bookending the table code block with $BELFT and $ELEFT does not bring the example table (the second table in this HW problem) to the left side of the page. 
   How can I have this type of table left justified?

Many Thanks for the help over this long Summer....

Tim

# DESCRIPTION 
# Probability
# WeBWorK problem written by Tim Payer, <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(Random Variables)
## DBsection(Expectation)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(probability, independence, notation)

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserFormulaUpToConstant.pl",
"niceTables.pl",
"PGunion.pl",
"parserPopUp.pl",
"weightedGrader.pl"
);

install_weighted_grader();

Context("Numeric");
Context()->flags->set(
  tolerance => 0.0001,
  tolType => "absolute",
);


# To switch off the algorithmic data un-comment the following 4 lines:
# and then Comment (#) the 4 random assignments that follow.
# $b = 12; # percentage of males with the condition
# $g = 21;  # percentage of females with the condition
# $f = 54;  # percentage of campus population that is female



$b = random(9, 17,1);  # condition incidence for males as a percentage
$g = random(19, 31,1); # condition incidence for females as a percentage
$f = random(51, 59,1); # incidence of females as a percentage

##  Note: Keep this code below for converting number to names:

#@NumberToName = ("zero","one","two","three","four","five");

#$rh = random(1,5,1);              # ratio count of 2 populations
#do { $rf = random(1,5,1); } until ($rf != $rh);   # ratio count of 1 pop.

#$rht = $NumberToName[$rh];
#$rft = $NumberToName[$rf];

#if($rf != 1) {
#$ins ="mosquitoes";
#} else {
#$ins ="mosquito";
#}


$popup1 = PopUp(
["probability notation:", "P(C)", "P(H)", "P(F)","P(C U F) + P(C U H)", "P(CF)*P(CH)", "P(CF) + P(CH)"], "P(C)");

$popup2 = PopUp(
["notation expansion:", "a", "b", "c","d", "e", "f","g", "h", "i","j", "k", "l","m", "n", "o","p", "q", "r","s", "t", "u","j", "w", "x","y", "z"], "s");
$ans1 = Compute("($b/100*(1-$f/100) +$g/100*($f/100))");

$popup3 = PopUp(
["probability notation:", "P(C | H)", "P(C | F)", "P(H | C)", "P(F | C)", "P(H)*P(C)", "P(HC)","P(F)*P(C)", "P(FC)"], "P(H | C)");

$popup4 = PopUp(
["notation expansion:", "a", "b", "c","d", "e", "f","g", "h", "i","j", "k", "l","m", "n", "o","p", "q", "r","s", "t", "u","j", "w", "x","y", "z"], "j");
$ans2 = Compute("$g*$f/(10000*$ans1) ");
## $ans2 = Compute("($b/100)*(1-$f/100)/$ans1");  ## for males

$popup5 = PopUp(
["Choose:", "union", "intersection", "cross product","composition", "inverse relationship", "reciprocal relationship"], "intersection");

$popup6 = PopUp(
["Choose:", "a", "b", "c","d", "e", "f","g", "h", "i","j", "k", "l"], "f");

$popup7 = PopUp(
["Choose:", "union", "intersection", "cross product","composition", "inverse relationship", "reciprocal relationship"], "intersection");

$popup8 = PopUp(
["Choose:", "a", "b", "c","d", "e", "f","g", "h", "i","j", "k", "l"], "k");

$popup9 = PopUp(
["first equation:", "a", "b", "c","d", "e", "f","g", "h", "i","j", "k", "l"], "f");
$ans3 = Compute("$ans1*$ans2 ");     ## Intersection always equals...

$popup10 = PopUp(
["second equation:", "a", "b", "c","d", "e", "f","g", "h", "i","j", "k", "l"], "k");
$ans4 = Compute("$ans1*(1-$f/100)");  ## independent events male
##$ans4 = Compute("$ans1*($f/100)");  ## independent events female

$popup11 = PopUp(
["choose:", "are", "are not"], "are not");

$popup12 = PopUp(
["choose:", " independent of", "dependent upon"], "dependent upon");
 

BEGIN_PGML

4B.2)  Red-green color blindness is due to mutations of two genes that produce red and green light sensitive proteins on the X chromosome. Men are much more likely to inherit  the condition as males have only one X chromosome. Women can inherit color blindness too, it is just that they must carry the recessive trait on both of their X chromosomes. Word wide about 8% of men are red-green color blind compared with 0.5% of women. Suppose that on  a particular rural college campus the incidence of color blindness is one out of every ($b) men and one out of every ($g) women. If the percentage of women on a college campus is (w%), and the rest are male,  find the probability of drawing a student that is red-green colorblind using the given declared event variables with correct probability notation.  
 
Use the the following event variable declarations within probability notation to find the associated probabilities with fourth decimal accuracy. 

[`C`] = Event that a randomly drawn student has the condition of (condition).  
[`M`] = Event that a randomly drawn student is male.  
[`F`] = Event that a randomly drawn student is female.


4B.2a)  Find the probability of randomly drawing a student that has the condition of red-green color blindness. Use the table below to determine the correct notation expansion and then find the numeric probability with fourth decimal accuracy.  
[$popup1->menu]*  = [$popup2->menu]*  = [______]  

END_PGML

BEGIN_TEXT

$PAR
Notation Expansions: a to z $BR
$BLEFT
\{begintable(3)\}
\{row("a.) \(\quad P(H | C) \cdot P(C)\quad \quad  \quad \quad \quad \quad\)", "\(\quad\)","n.) \(P(C | H)\cdot P(H) + P(H | C)\cdot P(C)\)")\}
\{row(" ", " "," ")\}
\{row("b.) \(\quad P(F) + P(H) - P(F \cap H) \quad\)","\(\quad\)","o.) \(P(F | H)\cdot P(H) + P(H | F)\cdot P(F)\)")\}
\{row(" ", " "," ")\}
\{row("c.) \(\quad P(F) + P(H) - P(F \cup H)\quad\)","\(\quad\)", "p.) \(P(C | H)\cdot P(H) + P(F | C)\cdot P(C)\)")\}
\{row(" ", " "," ")\}
\{row("d.) \(\quad P(C) + P(H) - P(C \cup H)\quad\)", "\(\quad\)","q.) \(P(F | C)\cdot P(C) + P(F | H)\cdot P(H)\)")\}
\{row(" ", " "," ")\}
\{row("e.) \(\quad P(C) + P(H) - P(C \cap H)\quad\)","\(\quad\)", "r.) \(P(C | F)\cdot P(F) + P(H | F)\cdot P(F)\)")\}
\{row(" ", " "," ")\}
\{row("f.) \(\quad P(F) + P(H) - P(F \cap H) \quad\)", "\(\quad\)","s.) \(P(C | H)\cdot P(H) + P(C | F)\cdot P(F)\)")\}
\{row(" ", " "," ")\}
\{row("g.) \(\quad  \frac{P(F | H)\cdot P(C)}{P(F)+P(H)} \quad \quad  \quad \quad\quad \quad \quad \quad \)", "\(\quad\)", "t.) \(P(H | C)\cdot P(C) + P(F | C)\cdot P(C)\)")\}
\{row(" ", " "," ")\}
\{row("h.) \(\quad  \frac{P(H | F)\cdot P(C)}{P(F)} \quad \quad  \quad \quad\quad \quad \quad \quad \)","\(\quad\)", "u.) \(P(C | H)\cdot P(H) + P(C | F)\cdot P(C)\)")\}
\{row(" ", " "," ")\}
\{row("i.) \(\quad  \frac{P(H | C)\cdot P(H)}{P(C)} \quad \quad  \quad \quad\quad \quad \quad \quad \)","\(\quad\)", "v.) \(P(H | C)\cdot P(C) + P(C | F)\cdot P(C)\)")\}
\{row(" ", " "," ")\}
\{row("j.) \(\quad  \frac{P(C | H)\cdot P(H)}{P(C)} \quad \quad  \quad \quad\quad \quad \quad \quad \)","\(\quad\)", "w.) \(P(H | C)\cdot P(C) + P(F | C)\cdot P(C)\)")\}
\{row(" ", " "," ")\}
\{row("k.) \(\quad  \frac{P(H | C)\cdot P(F)}{P(C)} \quad \quad  \quad \quad\quad \quad \quad \quad \)", "\(\quad\)","x.) \(P(C | F)\cdot P(H) + P(C | F)\cdot P(F)\)")\}
\{row(" ", " "," ")\}
\{row("l.) \(\quad  \frac{P(C | F)\cdot P(C)}{P(F)} \quad \quad  \quad \quad\quad \quad \quad \quad \)", "\(\quad\)","y.) \(P(C | H)\cdot P(H) - P(C | F)\cdot P(F)\)")\}
\{row(" ", " "," ")\}
\{row("m.) \(\quad  \frac{P(H | C)\cdot P(C)}{P(H)} \quad \quad  \quad \quad\quad \quad \quad \quad \)", "\(\quad\)","z.) \(P(C | F)\cdot P(F) - P(C | F)\cdot P(F)\)")\}
\{endtable()\}
$ELEFT

$PAR
A second table is offered here....
$PAR
$BLEFT
\{
BeginTable(border=>1, tex_border=>"1pt", spacing=>0, padding=>4).
AlignedRow(["\(x = \)","0","1","2"], align=>LEFT, separation=>0).
AlignedRow(["\(f(x)=\)","A","B","C"], separation=>0).
TableSpace(25,6).
AlignedRow(["\(g(x)=\)","E","F","G"], separation=>0).
EndTable()
\}
$ELEFT
$PAR

$PAR
END_TEXT

BEGIN_PGML
4B.2d)  Given that a college student has the condition of red green color blindness, find the probability that the student is male. Use the table above to choose the correct notation expansion. Answer with a probability accurate to four decimals.

[$popup3->menu]*  = [$popup4->menu]*  = [______]  

4B.1e)  Is the condition of color blindness independent of one's sex? Use the event of drawing a color blind man from this rural campus to support your answer with the correct probability notation and values.  

Complete the following statement regarding independent events. Select the correct letter next to the equation in the table below when referencing an equation.

END_PGML

BEGIN_TEXT

$PAR
Notation Expansions for Independent Event Questions: a to l $BR
$BLEFT
\{begintable(3)\}
\{row("a.) \(\quad P(H | C) = P(H \cap C)\cdot P(C) \quad \quad\quad \quad \quad\)", "\(\quad\)","g.) \(\quad P(C \cap H) = P(C | H)\cdot P(C)\quad\)")\}
\{row(" ", " "," ")\}
\{row("b.) \(\quad P(H \cap C) = P(H) + P(C) - P(C \cap H)\)","\(\quad\)","h.) \(\quad P(C | H) = P(H \cap C)\cdot P(C) \quad\)")\}
\{row(" ", " "," ")\}
\{row("c.) \(\quad P(C | H) = P(C) + P(H) - P(C \cap H)\quad\)","\(\quad\)", "i.) \(\quad P(C | H) = P(C)\cdot P(H) \quad\quad\quad\)")\}
\{row(" ", " "," ")\}
\{row("d.) \(\quad P(H | C) = P(C) + P(H) - P(C \cap H)\quad\)", "\(\quad\)","j.) \(\quad P(H | C) = P(C)\cdot P(H) \quad\quad\quad\)")\}
\{row(" ", " "," ")\}
\{row("e.) \(\quad P(H | C) = P(C) + P(H) - P(C \cup H)\quad\)","\(\quad\)", "k.) \(\quad P(H \cap C) = P(C)\cdot P(H) \quad\quad  \)")\}
\{row(" ", " "," ")\}
\{row("f.) \(\quad P(C \cap H) = P(C | H)\cdot P(H)\quad\quad\quad\quad\quad \)", "\(\quad\)","l.) \(\quad P(H \cap C) = P(H | C)\cdot P(H)\quad\)")\}
\{row(" ", " "," ")\}
\{endtable()\}
$ELEFT


$PAR
END_TEXT

BEGIN_PGML
To determine whether two events are independent we look at the calculation for the probability of the [$popup5->menu]* of the two events. The following equation [$popup6->menu]* is always true when calculating for the [$popup7->menu]* between events. However it is only this equation, [$popup8->menu]*, that is true when the two given events are independent of each other. Accordingly, we set these two equations equal to each other and if their numerical probabilities are equal we have verified that the two events are independent. 

Using fourth decimal accuracy, the calculation of both of these probability equations found that the first probability was [$popup9->menu]*  = [______] while the [$popup10->menu]*  = [______]. 

Since these probabilities [$popup11->menu]* equal then we know that the condition of red-green color blindness is [$popup12->menu]* whether a male or female student is drawn.
 
END_PGML


WEIGHTED_ANS( ($popup1)->cmp, 3 );
WEIGHTED_ANS( ($popup2)->cmp, 10 );
WEIGHTED_ANS( ($ans1)->cmp, 11 );
WEIGHTED_ANS( ($popup3)->cmp, 3 );
WEIGHTED_ANS( ($popup4)->cmp, 10 );
WEIGHTED_ANS( ($ans2)->cmp, 11 );
WEIGHTED_ANS( ($popup5)->cmp, 3 );
WEIGHTED_ANS( ($popup6)->cmp, 5 );
WEIGHTED_ANS( ($popup7)->cmp, 3 );
WEIGHTED_ANS( ($popup8)->cmp, 5 );
WEIGHTED_ANS( ($popup9)->cmp, 5 );
WEIGHTED_ANS( ($ans3)->cmp, 10 );
WEIGHTED_ANS( ($popup10)->cmp, 5 );
WEIGHTED_ANS( ($ans4)->cmp, 10 );
WEIGHTED_ANS( ($popup11)->cmp, 3 );
WEIGHTED_ANS( ($popup12)->cmp, 3 );


BEGIN_PGML_SOLUTION
*SOLUTION*
Solution to arrive in 2017....

 
[``\begin{aligned}&\\  
[$c]-\sqrt{\frac{[$am] x}{[$bm]}} &=[$c] -\sqrt{\frac{[$m]\cdot[$a] x}{[$m]\cdot[$b]}} = [$c]  -\frac{\sqrt{[$a] x}}{\sqrt{[$b]}}
&& \text{Cancel the common factor and then split the root.}\\    
&=\frac{[$c]\sqrt{[$b]}}{ \sqrt{[$b]}}-\frac{\sqrt{[$a] x}}{\sqrt{[$b]}} && \text{Create a common denominator.}\\  
&=\frac{[$c]\sqrt{[$b]} -\sqrt{[$a] x}}{\sqrt{[$b]}} && \text{Combine in to a single fraction.}\\    
&=\frac{\left([$c]\sqrt{[$b]} -\sqrt{[$a] x}\right)\sqrt{[$b]}}{\sqrt{[$b]}\cdot\sqrt{[$b]}} && \text{Multiply the numerator and denominator by the denominator.}\\  
&=\frac{\left([$c]\sqrt{[$b]\cdot [$b]}-\sqrt{[$a] \cdot [$b] x}\right)}{[$b]} && \text{Distribute through the numerator and reduce the denominator.}\\  
&=\frac{\left([$c] \cdot [$b] -\sqrt{[$ab] x}\right)}{[$b]} && \text{Reduce the square root factors.}\\  
&=\frac{[$cb] - \sqrt{[$ab] x}}{[$b]} && \text{Combine numerator factors.}  
\end{aligned}``]  


END_PGML_SOLUTION

ENDDOCUMENT();