The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::Symbolic::Custom::ToShorterString - Shorter string representations of Math::Symbolic trees

VERSION

Version 0.01

SYNOPSIS

        use Math::Symbolic qw(:all);
        use Math::Symbolic::Custom::ToShorterString;

        my $f = parse_from_string("1*2+3*4+5*sqrt(x+y+z)");

        print "to_string():\t", $f->to_string(), "\n";
        # to_string():  ((1 * 2) + (3 * 4)) + (5 * (((x + y) + z) ^ 0.5))

        print "to_shorter_infix_string():\t", $f->to_shorter_infix_string(), "\n";
        # to_shorter_infix_string():    (1*2 + 3*4) + (5*sqrt(x + y + z))

DESCRIPTION

Provides "to_shorter_infix_string()" through the Math::Symbolic module extension class. "to_shorter_infix_string()" attempts to provide a string representation of a Math::Symbolic tree that is shorter and therefore more readable than the existing (infix) "to_string()" method.

The "to_string()" method wraps every branch in parentheses/brackets, which makes larger expressions difficult to read. "to_shorter_infix_string()" tries to determine whether parentheses are required and omits them. One of the goals of this module is that the output string should parse to a Math::Symbolic tree that is (at least numerically) equivalent to the original expression - even if the resulting Math::Symbolic tree might not be completely identical to the original (for that, use "to_string()"). Where appropriate, it produces strings containing the Math::Symbolic parser aliases "sqrt()" and "exp()".

The "to_shorter_infix_string()" does not replace the "to_string()" method, it has to be called explicitly.

SEE ALSO

Math::Symbolic

AUTHOR

Matt Johnson, <mjohnson at cpan.org>

BUGS

Please report any bugs or feature requests to bug-math-symbolic-custom-toshorterstring at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-Symbolic-Custom-ToShorterString. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Steffen Mueller, author of Math::Symbolic

LICENSE AND COPYRIGHT

This software is copyright (c) 2024 by Matt Johnson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.