Math::Symbolic::Custom::Transformation::Group - Group of Transformations
use Math::Symbolic::Custom::Transformation qw/:all/; use Math::Symbolic qw/parse_from_string/; my $group = new_trafo_group( ',', new_trafo( 'TREE_x ^ 1' => 'TREE_x' ), new_trafo( 'TREE_x ^ CONST_a' => 'TREE_x * TREE_x^value{CONST_a-1}' ), ); my $function = parse_from_string( '(foo+1)^3 + bar^2' ); while(1) { my $result = $group->apply_recursive($function); last if not defined $result; $function = $result; } print $function."\n" # prints "((foo + 1) * ((foo + 1) * (foo + 1))) + (bar * bar)"
A Math::Symbolic::Custom::Transformation::Group object (Trafo Group for now) represents a conjunction of several transformations and is a transformation itself. An example is in order here:
Math::Symbolic::Custom::Transformation::Group
my $group = new_trafo_group( ',', $trafo1, $trafo2, ... );
Now, $group can be applied to Math::Symbolic trees as if it was an ordinary transformation object itself. In fact it is, because this is a subclass of Math::Symbolic::Custom::Transformation.
$group
The first argument to the constructor specifies the condition under which the grouped transformations are applied. ',' is the simplest form. It means that all grouped transformations are always applied. '&' means that the next transformation will only be applied if the previous one succeeded. Finally, '|' means that the first transformation to succeed is the last that is tried. '&' and '|' are and and or operators if you will.
','
'&'
'|'
and
or
None by default, but you may choose to import the new_trafo_group subroutine as an alternative constructor for Math::Symbolic::Custom::Transformation::Group objects.
new_trafo_group
This is a list of public methods.
This is the constructor for Math::Symbolic::Custom::Transformation::Group objects. First argument must be the type of the group as explained above. (',', '&', or '|'.) Following the group type may be any number of transformations (or groups thereof).
Applies the transformation (group) to a Math::Symbolic tree. First argument must be a Math::Symbolic tree to transform. The tree is not transformed in-place, but its matched subtrees are contained in the transformed tree, so if you plan to use the original tree as well as the transformed tree, take care to clone one of the trees.
Math::Symbolic
apply() returns the transformed tree if the transformation pattern matched and a false value otherwise.
apply()
On errors, it throws a fatal error.
Returns a string representation of the transformation. In presence of the simplify or value hooks, this may fail to return the correct represenation. It does not round-trip!
simplify
value
(Generally, it should work if only one hook is present, but fails if more than one hook is found.)
This method is inherited from Math::Symbolic::Custom::Transformation.
This is a list of public subroutines.
This subroutine is an alternative to the new() constructor for Math::Symbolic::Custom::Transformation::Group objects that uses a hard coded package name. (So if you want to subclass this module, you should be aware of that!)
new()
New versions of this module can be found on http://steffen-mueller.net or CPAN.
This module uses the Math::Symbolic framework for symbolic computations.
Math::Symbolic::Custom::Pattern implements the pattern matching routines.
Steffen Müller, <symbolic-module at steffen-mueller dot net>
Copyright (C) 2006, 2007, 2008, 2013 by Steffen Mueller
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.
To install Math::Symbolic::Custom::Transformation, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Symbolic::Custom::Transformation
CPAN shell
perl -MCPAN -e shell install Math::Symbolic::Custom::Transformation
For more information on module installation, please visit the detailed CPAN module installation guide.