[system] / trunk / pg / macros / contextLimitedPowers.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/contextLimitedPowers.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5550 Revision 5551
1=head1 NAME
2
3contextLimitedPowers.pl - Restrict the base or power allowed in exponentials.
4
5=head1 DESCRIPTION
6
7Implements subclasses of the "^" operator that restrict
8the base or power that is allowed. There are four
9available restrictions:
10
11 No raising e to a power
12 Only allowing integer powers (positive or negative)
13 Only allowing positive interger powers
14 Only allowing positive interger powers (and 0)
15
16You install these via one of the commands:
17
18 LimitedPowers::NoBaseE();
19 LimitedPowers::OnlyIntegers();
20 LimitedPowers::OnlyPositiveIntegers();
21 LimitedPowers::OnlyNonNegativeIntegers();
22
23Only one of the three can be in effect at a time; setting
24a second one overrides the first.
25
26These function affect the current context, or you can pass
27a context reference, as in
28
29 $context = Context("Numeric")->copy;
30 LimitedPowers::OnlyIntegers($context);
31
32For the Interger power functions, you can pass additional
33parameters that control the range of values that are allowed
34for the powers. The oprtions include:
35
36=over
37
38=item S<C<< minPower => m >>>
39
40only integer powers bigger than or equal
41to m are allowed. (If m is undef, then
42there is no minimum power.)
43
44=item S<C<< maxPower => M >>>
45
46only integer powers less than or equal
47to M are allowed. (If M is undef, then
48there is no maximum power.)
49
50=item S<C<< message => "text" >>>
51
52a description of the type of power
53allowed (e.g., "positive integer constants");
54
55=item S<C<< checker => code >>>
56
57a reference to a subroutine that will be
58used to check if the powers are acceptable.
59It should accept a reference to the BOP::power
60structure and return 1 or 0 depending on
61whether the power is OK or not.
62
63=back
64
65For example:
66
67 LimitedPowers::OnlyIntegers(
68 minPower => -5, maxPower => 5,
69 message => "integer constants between -5 and 5",
70 );
71
72would accept only powers between -5 and 5, while
73
74 LimitedPowers::OnlyIntegers(
75 checker => sub {
76 return 0 unless LimitedPowers::isInteger(@_);
77 my $self = shift; my $p = shift; # the power as a constant
78 return $p != 0 && $p != 1;
79 },
80 message => "integer constants other than 0 or 1",
81 );
82
83would accept any integer power other than 0 and 1.
84
85=cut
86
1loadMacros("MathObjects.pl"); 87loadMacros("MathObjects.pl");
2 88
3sub _contextLimitedPowers_init {}; # don't load it again 89sub _contextLimitedPowers_init {}; # don't load it again
4
5=head3 LimitedPowers::NoBaseE();
6
7=head3 LimitedPowers::OnlyIntegers();
8
9=head3 LimitedPowers::OnlyNonNegativeIntegers();
10
11=head3 LimitedPowers::OnlyPositiveIntegers();
12
13=head3 LimitedPowers::OnlyNonTrivialPositiveIntegers();
14
15 ##########################################################
16 #
17 # Implements subclasses of the "^" operator that restrict
18 # the base or power that is allowed. There are four
19 # available restrictions:
20 #
21 # No raising e to a power
22 # Only allowing integer powers (positive or negative)
23 # Only allowing positive interger powers
24 # Only allowing positive interger powers (and 0)
25 #
26 # You install these via one of the commands:
27 #
28 # LimitedPowers::NoBaseE();
29 # LimitedPowers::OnlyIntegers();
30 # LimitedPowers::OnlyPositiveIntegers();
31 # LimitedPowers::OnlyNonNegativeIntegers();
32 #
33 # Only one of the three can be in effect at a time; setting
34 # a second one overrides the first.
35 #
36 # These function affect the current context, or you can pass
37 # a context reference, as in
38 #
39 # $context = Context("Numeric")->copy;
40 # LimitedPowers::OnlyIntegers($context);
41 #
42 # For the Interger power functions, you can pass additional
43 # parameters that control the range of values that are allowed
44 # for the powers. The oprtions include:
45 #
46 # minPower => m only integer powers bigger than or equal
47 # to m are allowed. (If m is undef, then
48 # there is no minimum power.)
49 #
50 # maxPower => M only integer powers less than or equal
51 # to M are allowed. (If M is undef, then
52 # there is no maximum power.)
53 #
54 # message => "text" a description of the type of power
55 # allowed (e.g., "positive integer constants");
56 #
57 # checker => code a reference to a subroutine that will be
58 # used to check if the powers are acceptable.
59 # It should accept a reference to the BOP::power
60 # structure and return 1 or 0 depending on
61 # whether the power is OK or not.
62 #
63 # For example:
64 #
65 # LimitedPowers::OnlyIntegers(
66 # minPower => -5, maxPower => 5,
67 # message => "integer constants between -5 and 5",
68 # );
69 #
70 # would accept only powers between -5 and 5, while
71 #
72 # LimitedPowers::OnlyIntegers(
73 # checker => sub {
74 # return 0 unless LimitedPowers::isInteger(@_);
75 # my $self = shift; my $p = shift; # the power as a constant
76 # return $p != 0 && $p != 1;
77 # },
78 # message => "integer constants other than 0 or 1",
79 # );
80 #
81 # would accept any integer power other than 0 and 1.
82 #
83 ##########################################################
84
85=cut
86 90
87package LimitedPowers; 91package LimitedPowers;
88 92
89sub NoBaseE { 93sub NoBaseE {
90 my $context = (Value::isContext($_[0]) ? shift : Value->context); 94 my $context = (Value::isContext($_[0]) ? shift : Value->context);

Legend:
Removed from v.5550  
changed lines
  Added in v.5551

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9