1  loadMacros("Parser.pl"); 
1  loadMacros("Parser.pl"); 
2  
2  
3  sub _contextLimitedComplex_init {}; # don't load it again 
3  sub _contextLimitedComplex_init {}; # don't load it again 
4  
4  


5  =head3 Context("LimitedComplex") 


6  
5  ########################################################## 
7  ########################################################## 
6  # 
8  # 
7  # Implements a context in which complex numbers can be entered, 
9  # Implements a context in which complex numbers can be entered, 
8  # but no complex operations are permitted. So students will 
10  # but no complex operations are permitted. So students will 
9  # be able to perform operations within the real and imaginary 
11  # be able to perform operations within the real and imaginary 
10  # parts of the complex numbers, but not between complex numbers. 
12  # parts of the complex numbers, but not between complex numbers. 
11  # 
13  # 
12  # 
14  # 
13  # Complex Numbers can still be entered in a+bi or a*e^(bt) form. 
15  # Complex Numbers can still be entered in a+bi or a*e^(bt) form. 
14  # The e and i are allowed to be entered only once, so we have 
16  # The e and i are allowed to be entered only once, so we have 
15  # to keep track of that, and allow SOME complex operations, 
17  # to keep track of that, and allow SOME complex operations, 
16  # but only when one term is one of these constants (or an expression 
18  # but only when one term is one of these constants (or an expression 
17  # involving it that we've already OKed). 
19  # involving it that we've already OKed). 
18  # 
20  # 
19  # You control which format to use by setting the complex_format 
21  # You control which format to use by setting the complex_format 
20  # context flag to 'cartesian', 'polar' or 'either'. E.g., 
22  # context flag to 'cartesian', 'polar' or 'either'. E.g., 
21  # 
23  # 
22  # Context()>flags>set(complex_format => 'polar'); 
24  # Context()>flags>set(complex_format => 'polar'); 
23  # 
25  # 
24  # The default is 'either'. There are predefined contexts that 
26  # The default is 'either'. There are predefined contexts that 
25  # already have these values set: 
27  # already have these values set: 
26  # 
28  # 
27  # Context("LimitedComplexcartesian"); 
29  # Context("LimitedComplexcartesian"); 
28  # Context("LimitedComplexpolar"); 
30  # Context("LimitedComplexpolar"); 
29  # 
31  # 
30  # You can require that the a and b used in these forms be strictly 
32  # You can require that the a and b used in these forms be strictly 
31  # numbers (not expressions) by setting the strict_numeric flag and 
33  # numbers (not expressions) by setting the strict_numeric flag and 
32  # disabling all the functions: 
34  # disabling all the functions: 
33  # 
35  # 
34  # Context()>flags>set(strict_numeric=>1); 
36  # Context()>flags>set(strict_numeric=>1); 
35  # Context()>functions>disable('All'); 
37  # Context()>functions>disable('All'); 
36  # 
38  # 
37  # There are predefined contexts that already have these values 
39  # There are predefined contexts that already have these values 
38  # set: 
40  # set: 
39  # 
41  # 
40  # Context("LimitedComplexcartesianstrict"); 
42  # Context("LimitedComplexcartesianstrict"); 
41  # Context("LimitedComplexpolarstrict"); 
43  # Context("LimitedComplexpolarstrict"); 
42  # Context("LimitedComplexstrict"); 
44  # Context("LimitedComplexstrict"); 
43  # 
45  # 
44  
46  
45  # 
47  # 
46  # Handle common checking for BOPs 
48  # Handle common checking for BOPs 
47  # 
49  # 


50  


51  =cut 


52  
48  package LimitedComplex::BOP; 
53  package LimitedComplex::BOP; 
49  
54  
50  # 
55  # 
51  # Do original check and then if the operands are numbers, its OK. 
56  # Do original check and then if the operands are numbers, its OK. 
52  # Otherwise, do an operatorspecific check for if complex numbers are OK. 
57  # Otherwise, do an operatorspecific check for if complex numbers are OK. 