File: run06.pl

package info (click to toggle)
libmath-symbolic-perl 0.613-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,268 kB
  • sloc: perl: 12,638; makefile: 9
file content (39 lines) | stat: -rwxr-xr-x 995 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl
use strict;
use warnings;

use lib '../lib';
use Data::Dumper;

use Math::Symbolic qw/:all/;

my $var = Math::Symbolic::Variable->new();
my $a   = $var->new( 'x' => 2 );

print "Vars: x=" . $a->value() . " (Value is optional)\n\n";

my $op  = Math::Symbolic::Operator->new();
my $div = $op->new( '/', $a, $a );
my $mul = $op->new( '*', $a, $a );
my $sum = $op->new( '+', $a, $a );
my $dif = $op->new( '-', $a, $a );

print "Expressions: x/x, x*x, x+x, x-x\n\n";

print "prefix notation and evaluation:\n";
print $div->to_string('prefix') . "\n\n";
print $mul->to_string('prefix') . "\n\n";
print $sum->to_string('prefix') . "\n\n";
print $dif->to_string('prefix') . "\n\n";

print "Finally, we simplify the derived terms as much as possible:\n";

my $simplified = $div->simplify();
print "$simplified\n\n";
$simplified = $mul->simplify();
print "$simplified\n\n";
$simplified = $sum->simplify();
print "$simplified\n\n";
$simplified = $dif->simplify();
print "$simplified\n\n";