# trizen/Math-Bacovia2

Experimental symbolic math library for Perl.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
 Failed to load latest commit information. examples lib/Math t utils .gitignore Build.PL Changes LICENSE MANIFEST Makefile.PL README.md ignore.txt

# Math-Bacovia

Math::Bacovia is a symbolic math library, with support for numerical evaluation (including support for complex numbers).

# EXAMPLE

```use utf8;
use 5.014;

use Math::Bacovia qw(
Log
Exp
Power
Symbol
Product
Fraction
);

my \$x = Symbol('x');
my \$y = Symbol('y');

say \$x+\$y;               #=> Sum(Symbol("x"), Symbol("y"))
say \$x-\$y;               #=> Difference(Symbol("x"), Symbol("y"))
say \$x*\$y;               #=> Product(Symbol("x"), Symbol("y"))
say \$x/\$y;               #=> Fraction(Symbol("x"), Symbol("y"))

say \$x**\$y;              #=> Power(Symbol("x"), Symbol("y"))

say Log(\$x);             #=> Log(Symbol("x"))
say Log(\$x)+Log(\$y);     #=> Log(Product(Symbol("x"), Symbol("y")))

say Exp(\$x);             #=> Exp(Symbol("x"))
say Exp(\$x)*Exp(\$y);     #=> Exp(Sum(Symbol("x"), Symbol("y")))

say "\n=> Sum:";
my \$sum = Fraction(0, 1);

for my \$n (1..10) {
\$sum += Fraction(1, \$n);
}
say \$sum;                     #=> Fraction(10628640, 3628800)
say \$sum->numeric;            #=> 7381/2520

say "\n=> Product:";
my \$prod = Product();

for my \$n (1..3) {
\$prod *= Exp(Fraction(1, \$n));
}

say \$prod;                    #=> Product(Product(Product(Product(1, 1), Exp(Fraction(1, 1))), Exp(Fraction(1, 2))), Exp(Fraction(1, 3)))
say \$prod->simple->pretty;    #=> exp(11/6)
say \$prod->numeric;           #=> 6.25470095193632871640207...

say "\n=> Alternative representations:";
say join ', ', Power(3, 5)->alternatives;   #=> Exp(Product(Log(3), 5)), Power(3, 5)```

# DESCRIPTION

The types supported by this library are described bellow:

#### # `Symbol(name, value=undef)`

Represents a symbolic value. Optionally, it can have a numeric value.

#### # `Fraction(numerator, denominator)`

Represents a symbolic fraction.

#### # `Difference(minuend, subtrahend)`

Represents a symbolic subtraction.

#### # `Power(base, power)`

Represents a symbolic exponentiation in a symbolic base.

#### # `Log(x)`

Represents the natural logarithm of a symbolic value.

#### # `Exp(x)`

Represents the natural exponentiation of a symbolic value.

#### # `Sum(a, b)`

Represents a symbolic sum.

#### # `Product(a, b)`

Represents a symbolic product.

# SPECIAL METHODS

An interesting feature is the support for alternative representations (provided by the method `alternatives()`), which uses common mathematical identities to create symbolically equivalent expressions from the self-expression.

Bellow we describe the special methods provided by this library:

#### # `alternatives()`

Returns an array with alternative representations from the self-expression.

`say for Exp(Log(3) * 2)->alternatives;`

Output:

```Exp(Product(Log(3), 2))
Power(3, 2)
9```

#### # `simple()`

Returns a simplification of the self-expression.

`say Exp(Log(Log(Exp(Exp(Log(Symbol('x')))))))->simple;`

Output:

`Symbol("x")`

#### # `pretty()`

Returns a human-readable stringification of the self-expression.

`say Power(3, Log(Fraction(1, 2)))->pretty;`

Output:

`3^log(1/2)`

#### # `numeric()`

Evaluates the self-expression numerically and returns the result as a Number or a Complex object.

```my \$x = Symbol('x');
my \$expr = (\$x**2 - \$x + 41);

for my \$n (1..3) {
local \$x->{value} = \$n;
say \$expr->numeric;
}```

Output:

```41
43
47```

# DEPENDENCIES

Math::Bacovia requires the following modules:

# INSTALLATION

To install this module, run the following commands:

``````perl Build.PL
./Build
./Build test
./Build install
``````

# SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the perldoc command.

``````perldoc Math::Bacovia
``````

You can also look for information at:

``````AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/Math-Bacovia

CPAN Ratings
http://cpanratings.perl.org/d/Math-Bacovia

Search CPAN
http://search.cpan.org/dist/Math-Bacovia/
``````

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: