

1  =head1 NAME 


2  


3  contextScientificNotation.pl  Allows entry of scientific notation. 


4  


5  =head1 DESCRIPTION 


6  


7  This file implements a context in which students can enter 


8  answers in scientific notation. It tries hard to report 


9  useful error messages when the student's answer is not 


10  in the proper format, and it also allows you to control 


11  how many decimal digits they are allowed/required to 


12  enter, and how many the system will display. 


13  


14  This probably should be called LimitedScientificNotation 


15  since it does not allow any operations other than the ones 


16  needed in Scientific notation. In the future it may be 


17  renamed if we produce a computational scientific notation 


18  context. 


19  


20  To use this context, add 


21  


22  loadMacros("contextScientificNotation.pl"); 


23  


24  to the top of your problem file, and then use 


25  


26  Context("ScientificNotation"); 


27  


28  to select the contxt and make it active. You can create 


29  values in scientific notation in two ways: 


30  


31  $n1 = Compute("1.23 x 10^3"); 


32  


33  or 


34  


35  $n2 = ScientificNotation(1.23 * 10**3); 


36  


37  (or even $n2 = ScientificNotation(1230), and it will be converted). 


38  


39  You can control how many digits are displayed by setting the 


40  snDigits flag in the context. For example, 


41  


42  Context()>flags>set(snDigits=>2); 


43  


44  sets the context to display at most 2 digits. The default is 6. 


45  By default, trailing zeros are removed, but you can ask that 


46  they be retained by issuing the command 


47  


48  Context()>flags>set(snTrimZeros=>0); 


49  


50  It is also possible to specify how many decimal digits the 


51  student must enter. For example, 


52  


53  Context()>flags>set(snMinDigits=>3); 


54  


55  would require the student to enter at least 3 digits past 


56  the decimal place (for a total of 4 significant digits, 


57  including the one to the left of the decimal). The default 


58  is 1 digit beyond the decimal. A value of 0 means that 


59  a decimal point and decimal values is optional. 


60  


61  Similarly, 


62  


63  Context()>flags>set(snMaxDigits=>6); 


64  


65  sets the maximum number to 6, so the student can't enter 


66  more than that. Setting this to 0 means no decimal places 


67  are allowed, effectively meaning students can only enter 


68  the numbers 0 through 9 (times a power of 10). Setting 


69  this to a negative number means that there is no upper 


70  limit on the number of digits the student may enter (this 


71  is the default). 


72  


73  As an example, in order to force a fixed precision of 


74  three digits of precision, use 


75  


76  Context()>flags>set( 


77  snDigits => 3, 


78  snTrimZeros => 0, 


79  snMinDigits => 3, 


80  snMaxDigits => 3, 


81  ); 


82  


83  Note that if you restrict the number of digits, you may 


84  need to adjust the tolerance values since the student 


85  may not be allowed to enter a more precise answer. In 


86  the example above, it would be appropriate to set the 


87  tolerance to .0001 and the tolType to "relative" in 


88  order to require the answers to be correct to the three 


89  digits that are shown. 


90  


91  =cut 


92  
1  loadMacros("MathObjects.pl"); 
93  loadMacros("MathObjects.pl"); 
2  
94  
3  sub _contextScientificNotation_init {ScientificNotation::Init()} 
95  sub _contextScientificNotation_init {ScientificNotation::Init()} 
4  


5  =head1 Context("ScientificNotation"); 


6  


7  ######################################################################### 


8  # 


9  # This file implements a context in which students can enter 


10  # answers in scientific notation. It tries hard to report 


11  # useful error messages when the student's answer is not 


12  # in the proper format, and it also allows you to control 


13  # how many decimal digits they are allowed/required to 


14  # enter, and how many the system will display. 


15  # 


16  # This probably should be called LimitedScientificNotation 


17  # since it does not allow any operations other than the ones 


18  # needed in Scientific notation. In the future it may be 


19  # renamed if we produce a computational scientific notation 


20  # context. 


21  # 


22  # To use this context, add 


23  # 


24  # loadMacros("contextScientificNotation.pl"); 


25  # 


26  # to the top of your problem file, and then use 


27  # 


28  # Context("ScientificNotation"); 


29  # 


30  # to select the contxt and make it active. You can create 


31  # values in scientific notation in two ways: 


32  # 


33  # $n1 = Compute("1.23 x 10^3"); 


34  # 


35  # or 


36  # 


37  # $n2 = ScientificNotation(1.23 * 10**3); 


38  # 


39  # (or even $n2 = ScientificNotation(1230), and it will be converted). 


40  # 


41  # You can control how many digits are displayed by setting the 


42  # snDigits flag in the context. For example, 


43  # 


44  # Context()>flags>set(snDigits=>2); 


45  # 


46  # sets the context to display at most 2 digits. The default is 6. 


47  # By default, trailing zeros are removed, but you can ask that 


48  # they be retained by issuing the command 


49  # 


50  # Context()>flags>set(snTrimZeros=>0); 


51  # 


52  # It is also possible to specify how many decimal digits the 


53  # student must enter. For example, 


54  # 


55  # Context()>flags>set(snMinDigits=>3); 


56  # 


57  # would require the student to enter at least 3 digits past 


58  # the decimal place (for a total of 4 significant digits, 


59  # including the one to the left of the decimal). The default 


60  # is 1 digit beyond the decimal. A value of 0 means that 


61  # a decimal point and decimal values is optional. 


62  # 


63  # Similarly, 


64  # 


65  # Context()>flags>set(snMaxDigits=>6); 


66  # 


67  # sets the maximum number to 6, so the student can't enter 


68  # more than that. Setting this to 0 means no decimal places 


69  # are allowed, effectively meaning students can only enter 


70  # the numbers 0 through 9 (times a power of 10). Setting 


71  # this to a negative number means that there is no upper 


72  # limit on the number of digits the student may enter (this 


73  # is the default). 


74  # 


75  # As an example, in order to force a fixed precision of 


76  # three digits of precision, use 


77  # 


78  # Context()>flags>set( 


79  # snDigits => 3, 


80  # snTrimZeros => 0, 


81  # snMinDigits => 3, 


82  # snMaxDigits => 3, 


83  # ); 


84  # 


85  # Note that if you restrict the number of digits, you may 


86  # need to adjust the tolerance values since the student 


87  # may not be allowed to enter a more precise answer. In 


88  # the example above, it would be appropriate to set the 


89  # tolerance to .0001 and the tolType to "relative" in 


90  # order to require the answers to be correct to the three 


91  # digits that are shown. 


92  # 


93  


94  =cut 


95  
96  
96  package ScientificNotation; 
97  package ScientificNotation; 
97  
98  
98  # 
99  # 
99  # Creates and initializes the ScientificNotation context 
100  # Creates and initializes the ScientificNotation context 