##DESCRIPTION ## stuff here ##ENDDESCRIPTION ##KEYWORDS('tree', 'forest', 'word3') ## DBsubject('Graph theory') ## DBchapter('Trees') ## Level('2') ## Date('06/08/2023') ## Author('Cynthia Loten') ## Institution('University of the Fraser Valley') ## TitleText1('Discrete and Combinatorial Mathematics') ## EditionText1('5') ## AuthorText1('Grimaldi') ## Section1('12.2') ######################################################################## DOCUMENT(); loadMacros( "PGstandard.pl", # Standard macros for PG language "MathObjects.pl", "PGML.pl", "PGtikz.pl", # "niceTables.pl", "parserRadioButtons.pl", # "unionTables.pl", "PGnauGraphCatalog.pl", "PGnauGraphtheory.pl", "PGcourse.pl", # Customization file for the course ); #PGnauGraphtheory.pl loads PGnauGraphics.pl #PGnuaGraphpics.pl loads PGgraphmacros.pl and unionTables.pl and PGchoicemacros.pl #PGnuaGraphpics.pl contains checkbox_table and radio_table # 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("Numeric"); Context()->flags->set(tolerance => 0.01); $pick = random(0,3); #$pick = 0; # pick 5 letters from p to z @possible_vars = ('p' .. 'z'); @vars = map { splice(@possible_vars, random(0, $#possible_vars), 1) } 1..4; #### ((x + y) / u ) * v $exp[0] = "(($vars[0] + $vars[1]) / $vars[2] ) * $vars[3]"; $pn[0] = "* / + $vars[0] $vars[1] $vars[2] $vars[3]"; $tree[0]= createTikZImage(); $tree[0]->BEGIN_TIKZ [thick, every node/.style = {fill = green!20, circle, inner sep = 2pt}, level 1/.style = {sibling distance = 25mm}, level 2/.style = {sibling distance = 15mm}, level 3/.style = {sibling distance = 13mm}, ] \node {\(*\)} child {node {/} child {node{\(+\)} child {node{\($vars[0]\)}} child {node{\($vars[1]\)}} } child {node{\($vars[2]\)}} } child {node {\($vars[3]\)} }; END_TIKZ #using testing suggestion $image[0] = image($tree[0], width => 150, tex_size => 500); # width was 300, text size was 1000 #### (x + y) / (u * v ) $exp[1] = "($vars[0] + $vars[1]) / ($vars[2] * $vars[3])"; $pn[1] = "/ + $vars[0] $vars[1] * $vars[2] $vars[3]"; $tree[1]= createTikZImage(); $tree[1]->BEGIN_TIKZ [thick, every node/.style = {fill = green!20, circle, inner sep = 2pt}, level 1/.style = {sibling distance = 25mm}, level 2/.style = {sibling distance = 15mm}, level 3/.style = {sibling distance = 13mm}, ] \node {/} child {node {\(+\)} child {node {\($vars[0]\)}} child {node {\($vars[1]\)}} } child {node {\(*\)} child {node{\( $vars[2]\)}} child {node{\( $vars[3]\)}} }; END_TIKZ #using testing suggestion $image[1] = image($tree[1], width => 150, tex_size => 500); # width was 300, text size was 1000 #### x + ((y/u) * v) $exp[2] = "$vars[0] + (( $vars[1] / $vars[2] ) * $vars[3])"; $pn[2] = "+ $vars[0] * / $vars[1] $vars[2] $vars[3]"; $tree[2]= createTikZImage(); $tree[2]->BEGIN_TIKZ [thick, every node/.style = {fill = green!20, circle, inner sep = 2pt}, level 1/.style = {sibling distance = 25mm}, level 2/.style = {sibling distance = 15mm}, level 3/.style = {sibling distance = 13mm}, ] \node {\(+\)} child {node {\($vars[0]\)}} child {node {\(*\)} child {node{ / } child {node{\($vars[1]\) }} child {node{\( $vars[2]\)}} } child {node {\( $vars[3]\)}} }; END_TIKZ #using testing suggestion $image[2] = image($tree[2], width => 150, tex_size => 500); # width was 300, text size was 1000 #### x + (y / (u *v)) $exp[3] = "$vars[0] + ($vars[1] / ($vars[2] * $vars[3]))"; $pn[3] = "+ $vars[0] / $vars[1] * $vars[2] $vars[3]"; $tree[3]= createTikZImage(); $tree[3]->BEGIN_TIKZ [thick, every node/.style = {fill = green!20, circle, inner sep = 2pt}, level 1/.style = {sibling distance = 25mm}, level 2/.style = {sibling distance = 15mm}, level 3/.style = {sibling distance = 13mm}, ] \node {\(+\)} child {node {\($vars[0]\)}} child {node {/ } child {node { \($vars[1]\) } } child {node {\(*\)} child {node{\($vars[2]\) }} child {node{\( $vars[3]\)}} } }; END_TIKZ #using testing suggestion $image[3] = image($tree[3], width => 150, tex_size => 500); # width was 300, text size was 1000 ##### radio buttons $radio_tree =RadioButtons( [ "A","B","C","D" ], $pick, #index of correct answer separator => "$SPACE$SPACE$SPACE$SPACE", ); $radio_pn = RadioButtons( [ ["\($pn[0]\)", "\($pn[1]\)", "\($pn[2]\)", "\($pn[3]\)", ], ], $pick, #index of correct answer ); @indices = (0,0,0,0); $indices[$pick] = 1; #set index of correct tree to 1 ($table,$ans) = radio_table([ @image], [@indices], geometry => [2,2], border => 1); # ($table,$ans) = radio_table([@pics], [0,0,1], geometry => [1,3]); #got this command from #FindIsomorphism.pg #Graph Theory, Terminology ############################################################## # # Text # # BEGIN_PGML Consider the algebraic expression given below. [`[$exp[$pick]]`] (a) Select the binary tree that corresponds to the algebraic expression. [@ $table @]* END_PGML $ans; BEGIN_PGML (b) Now (using part (a)) convert the algebraic expression to Polish notation. [_]{$radio_pn} END_PGML ############################################################## # # Hints # # $showHint = 2; # default is 1 BEGIN_PGML If you don't get this in [$showHint] tries, you can get a hint. END_PGML BEGIN_PGML_HINT hints here if wanted END_PGML_HINT ############################################################## # # Solutions # # BEGIN_PGML_SOLUTION stuff END_PGML_SOLUTION COMMENT('MathObject version. Uses PGML.'); ENDDOCUMENT();