Math-Algebra-Symbols
view release on metacpan or search on metacpan
lib/Math/Algebra/Symbols/Sum.pm view on Meta::CPAN
}
=head3 st
Get the single term from a sum containing just one term
=cut
sub st($)
{my ($a) = @_;
return (values(%{$a->{t}}))[0] if scalar(keys(%{$a->{t}})) == 1;
undef;
}
=head3 negate
Multiply each term in a sum by -1
lib/Math/Algebra/Symbols/Sum.pm view on Meta::CPAN
}
=head3 re
Real part of a complex sum
=cut
sub re($)
{my ($A) = @_;
$A = newFromString("$A") unless ref($A) eq __PACKAGE__;
my @r;
for my $a($A->t)
{next if $a->i == 1;
push @r, $a;
}
sigma(@r);
}
=head3 im
Imaginary part of a complex sum
=cut
sub im($)
{my ($A) = @_;
$A = newFromString("$A") unless ref($A) eq __PACKAGE__;
my @r;
for my $a($A->t)
{next if $a->i == 0;
push @r, $a;
}
$mI->multiply(sigma(@r));
}
lib/Math/Algebra/Symbols/Sum.pm view on Meta::CPAN
}
=head3 id
Get Id of sum: each sum has a unique identifying number.
=cut
sub id($)
{my ($t) = @_;
$t->{id} or die "Sum $t not yet finalized";
$t->{id};
}
=head3 zz
Check sum finalized. See: L</z>.
=cut
sub zz($)
{my ($t) = @_;
$t->{z} or die "Sum $t not yet finalized";
print $t->{z}, "\n";
$t;
}
=head3 z
Finalize creation of the sum: Once a sum has been finalized it becomes
lib/Math/Algebra/Symbols/Term.pm view on Meta::CPAN
On get: returns the power of a variable, or zero if the variable is not
present in the term.
On set: Sets the power of a variable. If the power is zero, removes the
variable from the term. =cut
=cut
sub vp($$;$)
{my ($t, $v) = @_;
# $v =~ /^[a-z]+$/i or die "Bad variable name $v";
return exists($t->{v}{$v}) ? $t->{v}{$v} : 0 if @_ == 2;
my $p = ($_[2] == 1 ? $_[2] : intCheck($_[2], 'vp'));
$t->{v}{$v} = $p if $p;
delete $t->{v}{$v} unless $p;
$t;
}
lib/Math/Algebra/Symbols/Term.pm view on Meta::CPAN
}
=head3 id
Get Id of a term
=cut
sub id($)
{my ($t) = @_;
$t->{id} or die "Term $t not yet finalized";
$t->{id};
}
=head3 zz
# Check term finalized
=cut
sub zz($)
{my ($t) = @_;
$t->{z} or die "Term $t not yet finalized";
$t;
}
=head3 z
Finalize creation of the term. Once a term has been finalized, it
becomes readonly, which allows optimization to be performed.
( run in 2.150 seconds using v1.01-cache-2.11-cpan-524268b4103 )