From: dpvc v. a. <we...@ma...> - 2005-08-11 14:24:08
|
Log Message: ----------- Changes needed for new Set object, and moving of string, TeX and perl methods to Value.pm Modified Files: -------------- pg/lib/Value: Formula.pm Point.pm Vector.pm List.pm Revision Data ------------- Index: Vector.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Vector.pm,v retrieving revision 1.18 retrieving revision 1.19 diff -Llib/Value/Vector.pm -Llib/Value/Vector.pm -u -r1.18 -r1.19 --- lib/Value/Vector.pm +++ lib/Value/Vector.pm @@ -179,7 +179,7 @@ return $pkg->make(@coords); } -sub abs {norm(@_)} +sub abs {my $self = shift; $self->norm(@_)} sub norm { my $p = promote(@_)->data; my $s = 0; @@ -249,37 +249,36 @@ sub stringify { my $self = shift; return $self->TeX if $$Value::context->flag('StringifyAsTeX'); - return $self->string(undef,$self->{open},$self->{close}); -}; + $self->string; +} sub string { my $self = shift; my $equation = shift; return $self->ijk($ijk_string) - if ($self->{ijk} || $equation->{ijk} || $$Value::context->flag("ijk")); - my $def = ($equation->{context} || $$Value::context)->lists->get('Vector'); - my $open = shift || $def->{open}; my $close = shift || $def->{close}; - my @coords = (); - foreach my $x (@{$self->data}) { - if (Value::isValue($x)) {push(@coords,$x->string($equation))} else {push(@coords,$x)} - } - return $open.join(',',@coords).$close; + if ($self->{ijk} || $equation->{ijk} || $$Value::context->flag("ijk")) && + !$self->{ColumnVector}; + return $self->SUPER::string($equation,@_); } sub TeX { my $self = shift; my $equation = shift; - return $self->ijk if ($self->{ijk} || $equation->{ijk} || $$Value::context->flag("ijk")); - my $def = ($equation->{context} || $$Value::context)->lists->get('Vector'); - my $open = shift || $self->{open} || $def->{open}; - my $close = shift || $self->{close} || $def->{close}; - my @coords = (); - foreach my $x (@{$self->data}) { - if (Value::isValue($x)) {push(@coords,$x->TeX($equation))} else {push(@coords,$x)} + if ($self->{ColumnVector}) { + my $def = ($equation->{context} || $$Value::context)->lists->get('Matrix'); + my $open = shift; my $close = shift; + $open = $self->{open} unless defined($open); + $open = $def->{open} unless defined($open); + $close = $self->{close} unless defined($close); + $close = $def->{close} unless defined($close); + $open =~ s/([{}])/\\$1/g; $close =~ s/([{}])/\\$1/g; + $open = '\left'.$open if $open; $close = '\right'.$close if $close; + my @coords = (); + foreach my $x (@{$self->data}) { + if (Value::isValue($x)) {push(@coords,$x->TeX($equation))} else {push(@coords,$x)} + } + return $open.'\begin{array}{c}'.join('\\\\',@coords).'\\\\\end{array}'.$close; } - return '\left'.$open.join(',',@coords).'\right'.$close unless $self->{ColumnVector}; - $def = ($equation->{context} || $$Value::context)->lists->get('Matrix'); - $open = shift || $self->{open} || $def->{open}; - $close = shift || $self->{close} || $def->{close}; - return '\left'.$open.'\begin{array}{c}'.join('\\\\',@coords).'\\\\\end{array}\right'.$close; + return $self->ijk if ($self->{ijk} || $equation->{ijk} || $$Value::context->flag("ijk")); + return $self->SUPER::TeX($equation,@_) unless $self->{ColumnVector}; } sub ijk { @@ -289,9 +288,9 @@ unless (scalar(@coords) <= 3); my $string = ''; my $n; my $term; foreach $n (0..scalar(@coords)-1) { - $term = $coords[$n]; - if ($term != 0) { - $term = '' if $term == 1; $term = '-' if $term == -1; + $term = $coords[$n]; $term = (Value::isValue($term))? $term->string : "$term"; + if ($term ne 0) { + $term = '' if $term eq '1'; $term = '-' if $term eq '-1'; $term = '('.$term.')' if $term =~ m/e/i; $term = '+' . $term unless $string eq '' or $term =~ m/^-/; $string .= $term . $ijk->[$n]; Index: List.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/List.pm,v retrieving revision 1.16 retrieving revision 1.17 diff -Llib/Value/List.pm -Llib/Value/List.pm -u -r1.16 -r1.17 --- lib/Value/List.pm +++ lib/Value/List.pm @@ -81,7 +81,7 @@ ($l,$r) = (promote($l)->data,promote($r)->data); return $pkg->new(@{$l},@{$r}); } -sub dot {add(@_)} +sub dot {my $self = shift; $self->add(@_)} # # Lexicographic compare @@ -99,51 +99,6 @@ return scalar(@{$l}) <=> scalar(@{$r}); } -############################################ -# -# Generate the various output formats. -# - -sub stringify { - my $self = shift; - return $self->TeX() if $$Value::context->flag('StringifyAsTeX'); - my $open = $self->{open}; my $close = $self->{close}; - $open = $$Value::context->lists->get('List')->{open} unless defined($open); - $close = $$Value::context->lists->get('List')->{close} unless defined($close); - $open.join(', ',@{$self->data}).$close; -} - -sub string { - my $self = shift; my $equation = shift; - my $def = ($equation->{context} || $$Value::context)->lists->get('List'); - my $open = shift; my $close = shift; - $open = $def->{open} unless defined($open); - $close = $def->{close} unless defined($close); - my @coords = (); - foreach my $x (@{$self->data}) { - if (Value::isValue($x)) - {push(@coords,$x->string($equation))} else {push(@coords,$x)} - } - return $open.join(', ',@coords).$close; -} -sub TeX { - my $self = shift; my $equation = shift; - my $context = $equation->{context} || $$Value::context; - my $def = $context->lists->get('List'); - my $open = shift; my $close = shift; - $open = $def->{open} unless defined($open); - $close = $def->{close} unless defined($close); - $open = '\{' if $open eq '{'; $close = '\}' if $close eq '}'; - $open = '\left'.$open if $open; $close = '\right'.$close if $close; - my @coords = (); my $str = $context->{strings}; - foreach my $x (@{$self->data}) { - if (Value::isValue($x)) {push(@coords,$x->TeX($equation))} - elsif (defined($str->{$x}) && $str->{$x}{TeX}) {push(@coords,$str->{$x}{TeX})} - else {push(@coords,$x)} - } - return $open.join(',',@coords).$close; -} - ########################################################################### 1; Index: Formula.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Formula.pm,v retrieving revision 1.31 retrieving revision 1.32 diff -Llib/Value/Formula.pm -Llib/Value/Formula.pm -u -r1.31 -r1.32 --- lib/Value/Formula.pm +++ lib/Value/Formula.pm @@ -94,7 +94,7 @@ $l = $parser->{Value}->new($formula,$l) unless ref($l) =~ m/^Parser::/; $r = $parser->{Value}->new($formula,$r) unless ref($r) =~ m/^Parser::/; $bop = 'U' if $bop eq '+' && - ($l->type =~ m/Interval|Union/ || $r->type =~ m/Interval|Union/); + ($l->type =~ m/Interval|Union|Set/ || $r->type =~ m/Interval|Union|Set/); $formula->{tree} = $parser->{BOP}->new($formula,$bop,$l,$r); $formula->{variables} = $formula->{tree}->getVariables; return $formula->eval if scalar(%{$formula->{variables}}) == 0; @@ -485,6 +485,16 @@ # sub isConstant {scalar(%{shift->{variables}}) == 0} +############################################ +# +# Provide output formats +# +sub stringify { + my $self = shift; + return $self->TeX if $$Value::context->flag('StringifyAsTeX'); + $self->string; +} + ########################################################################### 1; Index: Point.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Point.pm,v retrieving revision 1.16 retrieving revision 1.17 diff -Llib/Value/Point.pm -Llib/Value/Point.pm -u -r1.16 -r1.17 --- lib/Value/Point.pm +++ lib/Value/Point.pm @@ -168,42 +168,6 @@ return CORE::sqrt($s); } - -############################################ -# -# Generate the various output formats -# - -sub stringify { - my $self = shift; - return $self->TeX if $$Value::context->flag('StringifyAsTeX'); - return $self->string(undef,$self->{open},$self->{close}); -} - -sub string { - my $self = shift; my $equation = shift; - my $def = ($equation->{context} || $$Value::context)->lists->get('Point'); - my $open = shift || $def->{open}; my $close = shift || $def->{close}; - my @coords = (); - foreach my $x (@{$self->data}) { - if (Value::isValue($x)) {push(@coords,$x->string($equation))} else {push(@coords,$x)} - } - return $open.join(',',@coords).$close; -} - -sub TeX { - my $self = shift; my $equation = shift; - my $def = ($equation->{context} || $$Value::context)->lists->get('Point'); - my $open = shift || $self->{open} || $def->{open}; - my $close = shift || $self->{close} || $def->{close}; - my @coords = (); - foreach my $x (@{$self->data}) { - if (Value::isValue($x)) {push(@coords,$x->TeX($equation))} else {push(@coords,$x)} - } - return '\left'.$open.join(',',@coords).'\right'.$close; -} - ########################################################################### 1; - |