Log Message:
-----------
Make vectors that are creates using ijk notation remain in ijk
notation when displayed. (This is easy now that objects produced by
combining others inherit the parent objects' flags.)
Added another context flag (ijkAnyDimension) that controls whether
vectors in ijk notation will conform to whatever dimension is used by
the vector they are being compared to. When set, i+2*j will equal
<1,2> even though i and j are vectors in 3-space. The value of
ijkAnyDimension is 1 by default.
This eliminates the need for the Vector2D context.
Modified Files:
--------------
pg/lib/Parser/Context:
Default.pm
pg/lib/Value:
Vector.pm
Revision Data
-------------
Index: Default.pm
===================================================================
RCS file: /webwork/cvs/system/pg/lib/Parser/Context/Default.pm,v
retrieving revision 1.41
retrieving revision 1.42
diff -Llib/Parser/Context/Default.pm -Llib/Parser/Context/Default.pm -u -r1.41 -r1.42
--- lib/Parser/Context/Default.pm
+++ lib/Parser/Context/Default.pm
@@ -131,8 +131,8 @@
'e' => exp(1),
'pi' => 4*atan2(1,1),
'i' => Value::Complex->new(0,1),
- 'j' => Value::Vector->new(0,1,0),
- 'k' => Value::Vector->new(0,0,1),
+ 'j' => Value::Vector->new(0,1,0)->with(ijk=>1),
+ 'k' => Value::Vector->new(0,0,1)->with(ijk=>1),
'_blank_' => {value => 0, hidden => 1, string => "", TeX => ""},
};
@@ -223,7 +223,8 @@
};
$flags = {
- ijk => 0, # 1 = show vectors in ijk form
+ ijk => 0, # 1 = show all vectors in ijk form
+ ijkAnyDimension => 1, # 1 = add/remove trailing zeros to match dimension in comparisons
reduceConstants => 1, # 1 = automatically combine constants
reduceConstantFunctions => 1, # 1 = compute function values of constants
showExtraParens => 1, # 1 = add useful parens, 2 = make things painfully unambiguous
@@ -316,14 +317,14 @@
$context = $context{Vector} = $context{Full}->copy;
$context->variables->are(x=>'Real',y=>'Real',z=>'Real');
$context->functions->undefine('arg','mod','Re','Im','conj');
-$context->constants->replace(i=>Value::Vector->new(1,0,0));
+$context->constants->replace(i=>Value::Vector->new(1,0,0)->with(ijk=>1));
$context->constants->set(i=>{TeX=>'\boldsymbol{i}', perl=>'i'});
$context->parens->set('(' => {formMatrix => 0});
$context = $context{Vector2D} = $context{Vector}->copy;
$context->constants->replace(
- i => Value::Vector->new(1,0),
- j => Value::Vector->new(0,1),
+ i => Value::Vector->new(1,0)->with(ijk=>1),
+ j => Value::Vector->new(0,1)->with(ijk=>1),
);
$context->constants->set(i => {TeX=>'\boldsymbol{i}', perl=>'i'});
$context->constants->remove("k");
Index: Vector.pm
===================================================================
RCS file: /webwork/cvs/system/pg/lib/Value/Vector.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -Llib/Value/Vector.pm -Llib/Value/Vector.pm -u -r1.34 -r1.35
--- lib/Value/Vector.pm
+++ lib/Value/Vector.pm
@@ -143,7 +143,13 @@
sub compare {
my ($self,$l,$r) = Value::checkOpOrderWithPromote(@_);
my @l = $l->value; my @r = $r->value;
- return scalar(@l) <=> scalar(@r) unless scalar(@l) == scalar(@r);
+ if (scalar(@l) != scalar(@r)) {
+ return scalar(@l) <=> scalar(@r) unless
+ ($l->getFlag("ijk") || $r->getFlag("ijk")) &&
+ ($l->getFlag("ijkAnyDimension") || $r->getFlag("ijkAnyDimension"));
+ if (scalar(@l) > scalar(@r)) {push(@l,0 x (scalar(@r)-scalar(@l)))}
+ else {push(@r,0 x (scalar(@l)-scalar(@r)))}
+ }
my $cmp = 0;
foreach my $i (0..scalar(@l)-1) {
$cmp = $l[$i] <=> $r[$i];
|