On Thu Aug 20 19:54:44 2009, MHASCH wrote:
Show quoted text> On Wed Aug 19 12:28:20 2009, WSDOOKADR wrote:
> > On Wed Aug 19 09:41:50 2009, MHASCH wrote:
> > > On Mon Aug 17 01:45:51 2009, WSDOOKADR wrote:
> > > > What kind of pretty printing did you have in mind ?
> > > Examples: Simplifying, rounding, formatting as code for
> > > a given language (such as your typesetting system).
> > Can you be more explicit about 'simplifying' and 'rounding' ?
> > I'm not sure what you mean.
>
> One form already mentioned was a Horner schema, which may be
> "simplified" by way of constant folding and redundant parentheses
> elimination.
From what I remember from school and from refreshing my memory from here
If you're refering to this
http://planetmath.org/encyclopedia/
HornersRule.html
and here
http://en.wikipedia.org/wiki/Horner_scheme
I think that after applying Horner's scheme the polynomial will
look like
a0+x(a1+x(a2+x(...+x(a_{n-1}+x*an)...)
So basically there will be lots of parenthesis.
If however some of the ais happen to be 0 , then then yes we can
fold some parenthesis , is that what you're reffering to ?
Show quoted text> "Rounding" meant rounding of coefficients for terse
> output.
Option1 sprintf("%.3f",3.141592);
Option2 Number::Format
Option3 Math::Round
Option4 Math::Round::Var
Which would be best ?
Show quoted text> None of these examples is terribly important, my point
> being that one should carefully consider what features to put
> into a specialized polynomial package and what elsewhere.
So this feature should lie elsewhere ? Where ?
(same namespace I presume)
Show quoted text> > > If you know of other modules Math::Polynomial should
> > > interface with in order to extend its formatting
> > > capabilities (or whatever), I am open for suggestions.
>
> > For example a more general way of doing these things would be:
> > First we use(or we extend so that we can use) Math::Symbolic on a
> > polynomial to create a parse tree from it ( parse_from_string
method
Show quoted text> > from Math::Symbolic ). [...]
>
> A symbolic calculator is definitely something useful to be
> compatible with. Nice suggestion.
>
> -Martin
With a small modification to the as_string routine of your module,
I had to add a "*" to the end of line 634 in Polynomial.pm
634 $result .= $config{'convert_coeff'}->($coeff)."*";
So that the output could be parsed by Math::Symbolic
1 use Math::Polynomial;
2 use Math::Symbolic::Custom::LaTeXDumper;
3 use Math::Symbolic qw/parse_from_string/;
4 use Data::Dumper;
5 use feature 'say';
6 $p = Math::Polynomial->new(0, -2, 3, 1);
7
8
9 my $tree = parse_from_string($p->as_string);
10 #print Dumper $tree;
11
12 say $tree->to_latex;
13 say $p;
OUTPUT:
x^3 + 3 x^2 + -2 x
(x^3 + 3* x^2 + -2* x)
P.S. : can I use html tags here ? how do I format some code ?
Actually , the initial output of your code was valid LaTeX(before I
modified it with the "*").