#!/usr/bin/perl use strict; use Math::Symbolic; use Math::Symbolic::Custom::LaTeXDumper; #undef $/; #$/=''; while(){ my $com ; s/#(.+?)#.*// and $com = $1; s/#(.*)// ; next unless /\w/; chomp; print $_ , "==>", Math::Symbolic->parse_from_string($_)->simplify()->to_latex(); print "\n"; print "\t##$com\n" if $com; } __DATA__ x+1 #unpleseant reorder# 3*x^2 + 2*x + 1 #unpleseant reorder# 3*x^2 -1 *x + 1 #unpleseant reorder# -3*x^2 - 1 * x + 1 #unpleseant reorder# a*x +x+x^2 - b #unpleseant reorder# cos(x^2) cos(x)^2 + sin(x)^2 --1 #ok# - - 1 #ok# (x^y)^2 #ok# x^(y^2) #ok# (-b+sqrt(b^2-4*a*c))/(2*a) +(-(12*x)) -(+(12*x)) x*2 #Problem# x*(-2) #Problem# x*(-x) #Problem# 20/21 sin(x)*(-x) sin(x)*((x)) sin(x)-(-1) 4*a*c #Problem# 4*a #ok# a*4*c #Problem# 4*x + 3*x #ok# x + 4*x^2 +4*x + 3*x #ok# 1 + x + x^2 + x^3#BUG# x^3 + x^2 + x^1 + 1#unpleseant reorder# 1+x#ok# 1 + x + x^2 #BUG# -1*x#not optimal# -1*x*y#BUG# -1*x*y*z #BUG + Unpleseant reorder# (x/y)/((2*x)/a) x/y/-1 x/-1 x/(1/6)