Positive add and mul, LaTeX printing

View: New views
3 Messages — Rating Filter:   Alert me  

Positive add and mul, LaTeX printing

by Vladimir V. Kisil-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

                Dear All,

                I think it would be nice if GiNaC will learn that a sum or product of
  two positive expressions is again a positive expression. This will
  help, for example, to simply formulae like ((1+x)^{1/2})^2, where x
  is a positive symbol.

  It would be also a better LaTeX printing of complicated formulae if \mathrm
  will be used instead of \mbox (the later is not scaled in fractions, for
  example).

  I am attaching a patch which makes these two things.

  Best wishes,
  Vladimir
--
Vladimir V. Kisil     email: kisilv@...
--                      www: http://maths.leeds.ac.uk/~kisilv/

diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/add.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/add.cpp
--- ginac-1.5.3/ginac/add.cpp 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/add.cpp 2009-09-15 12:32:41.000000000 +0100
@@ -224,6 +224,16 @@
  case info_flags::integer_polynomial:
  case info_flags::cinteger_polynomial:
  case info_flags::rational_polynomial:
+ case info_flags::real:
+ case info_flags::rational:
+ case info_flags::integer:
+ case info_flags::crational:
+ case info_flags::cinteger:
+ case info_flags::positive:
+ case info_flags::nonnegative:
+ case info_flags::posint:
+ case info_flags::nonnegint:
+ case info_flags::even:
  case info_flags::crational_polynomial:
  case info_flags::rational_function: {
  epvector::const_iterator i = seq.begin(), end = seq.end();
@@ -232,6 +242,8 @@
  return false;
  ++i;
  }
+ if (overall_coeff.is_zero() && (inf == info_flags::positive || inf == info_flags::posint))
+ return true;
  return overall_coeff.info(inf);
  }
  case info_flags::algebraic: {
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/constant.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/constant.cpp
--- ginac-1.5.3/ginac/constant.cpp 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/constant.cpp 2009-09-15 12:55:54.000000000 +0100
@@ -60,7 +60,7 @@
   : name(initname), ef(efun), serial(next_serial++), domain(dm)
 {
  if (texname.empty())
- TeX_name = "\\mbox{" + name + "}";
+ TeX_name = "\\mathrm{" + name + "}";
  else
  TeX_name = texname;
  setflag(status_flags::evaluated | status_flags::expanded);
@@ -70,7 +70,7 @@
   : name(initname), ef(0), number(initnumber), serial(next_serial++), domain(dm)
 {
  if (texname.empty())
- TeX_name = "\\mbox{" + name + "}";
+ TeX_name = "\\mathrm{" + name + "}";
  else
  TeX_name = texname;
  setflag(status_flags::evaluated | status_flags::expanded);
@@ -131,7 +131,7 @@
 void constant::do_print_python_repr(const print_python_repr & c, unsigned level) const
 {
  c.s << class_name() << "('" << name << "'";
- if (TeX_name != "\\mbox{" + name + "}")
+ if (TeX_name != "\\mathrm{" + name + "}")
  c.s << ",TeX_name='" << TeX_name << "'";
  c.s << ')';
 }
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/flags.h /usr/local/distrib/math/ginac-1.5.3/ginac/flags.h
--- ginac-1.5.3/ginac/flags.h 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/flags.h 2009-09-15 12:30:05.000000000 +0100
@@ -204,7 +204,7 @@
 class info_flags {
 public:
  enum {
- // answered by class numeric and symbols/constants in particular domains
+ // answered by class numeric, add, mul and symbols/constants in particular domains
  numeric,
  real,
  rational,
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/function.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/function.cpp
--- ginac-1.5.3/ginac/function.cpp 2009-07-15 05:29:58.000000000 +0100
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/function.cpp 2009-09-15 12:57:52.000000000 +0100
@@ -76,7 +76,7 @@
 
 void function_options::initialize()
 {
- set_name("unnamed_function", "\\mbox{unnamed}");
+ set_name("unnamed_function", "\\mathrm{unnamed}");
  nparams = 0;
  eval_f = evalf_f = real_part_f = imag_part_f = conjugate_f = derivative_f
  = power_f = series_f = 0;
@@ -101,7 +101,7 @@
 {
  name = n;
  if (tn==std::string())
- TeX_name = "\\mbox{"+name+"}";
+ TeX_name = "\\mathrm{"+name+"}";
  else
  TeX_name = tn;
  return *this;
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/inifcns.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/inifcns.cpp
--- ginac-1.5.3/ginac/inifcns.cpp 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/inifcns.cpp 2009-09-15 12:56:38.000000000 +0100
@@ -647,7 +647,7 @@
                        evalf_func(Li2_evalf).
                        derivative_func(Li2_deriv).
                        series_func(Li2_series).
-                       latex_name("\\mbox{Li}_2"));
+                       latex_name("\\mathrm{Li}_2"));
 
 //////////
 // trilogarithm
@@ -661,7 +661,7 @@
 }
 
 REGISTER_FUNCTION(Li3, eval_func(Li3_eval).
-                       latex_name("\\mbox{Li}_3"));
+                       latex_name("\\mathrm{Li}_3"));
 
 //////////
 // Derivatives of Riemann's Zeta-function  zetaderiv(0,x)==zeta(x)
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/inifcns_gamma.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/inifcns_gamma.cpp
--- ginac-1.5.3/ginac/inifcns_gamma.cpp 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/inifcns_gamma.cpp 2009-09-15 12:57:15.000000000 +0100
@@ -328,7 +328,7 @@
                         evalf_func(beta_evalf).
                         derivative_func(beta_deriv).
                         series_func(beta_series).
-                        latex_name("\\mbox{B}").
+                        latex_name("\\mathrm{B}").
  set_symmetry(sy_symm(0, 1)));
 
 
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/inifcns_nstdsums.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/inifcns_nstdsums.cpp
--- ginac-1.5.3/ginac/inifcns_nstdsums.cpp 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/inifcns_nstdsums.cpp 2009-09-15 12:54:28.000000000 +0100
@@ -1683,7 +1683,7 @@
  } else {
  x = lst(x_);
  }
- c.s << "\\mbox{Li}_{";
+ c.s << "\\mathrm{Li}_{";
  lst::const_iterator itm = m.begin();
  (*itm).print(c);
  itm++;
@@ -2199,7 +2199,7 @@
 
 static void S_print_latex(const ex& n, const ex& p, const ex& x, const print_context& c)
 {
- c.s << "\\mbox{S}_{";
+ c.s << "\\mathrm{S}_{";
  n.print(c);
  c.s << ",";
  p.print(c);
@@ -3405,7 +3405,7 @@
  } else {
  m = lst(m_);
  }
- c.s << "\\mbox{H}_{";
+ c.s << "\\mathrm{H}_{";
  lst::const_iterator itm = m.begin();
  (*itm).print(c);
  itm++;
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/mul.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/mul.cpp
--- ginac-1.5.3/ginac/mul.cpp 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/mul.cpp 2009-09-15 12:36:24.000000000 +0100
@@ -278,6 +278,16 @@
  case info_flags::integer_polynomial:
  case info_flags::cinteger_polynomial:
  case info_flags::rational_polynomial:
+ case info_flags::real:
+ case info_flags::rational:
+ case info_flags::integer:
+ case info_flags::crational:
+ case info_flags::cinteger:
+ case info_flags::positive:
+ case info_flags::nonnegative:
+ case info_flags::posint:
+ case info_flags::nonnegint:
+ case info_flags::even:
  case info_flags::crational_polynomial:
  case info_flags::rational_function: {
  epvector::const_iterator i = seq.begin(), end = seq.end();
@@ -286,6 +296,8 @@
  return false;
  ++i;
  }
+ if (overall_coeff.is_equal(*_num1_p) && inf == info_flags::even)
+ return true;
  return overall_coeff.info(inf);
  }
  case info_flags::algebraic: {
diff -x '*.o' -x '*.lo' -u ginac-1.5.3/ginac/power.cpp /usr/local/distrib/math/ginac-1.5.3/ginac/power.cpp
--- ginac-1.5.3/ginac/power.cpp 2009-02-17 13:39:22.000000000 +0000
+++ /usr/local/distrib/math/ginac-1.5.3/ginac/power.cpp 2009-09-15 12:41:32.000000000 +0100
@@ -240,6 +240,8 @@
        basis.info(inf);
  case info_flags::expanded:
  return (flags & status_flags::expanded);
+ case info_flags::positive:
+ return basis.info(info_flags::positive) && exponent.info(info_flags::real);
  case info_flags::has_indices: {
  if (flags & status_flags::has_indices)
  return true;

_______________________________________________
GiNaC-devel mailing list
GiNaC-devel@...
https://www.cebix.net/mailman/listinfo/ginac-devel

Re: Positive add and mul, LaTeX printing

by Alexei Sheplyakov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

On Tue, Sep 15, 2009 at 02:22:45PM +0100, Vladimir V. Kisil wrote:
> I think it would be nice if GiNaC will learn that a sum or product of
>   two positive expressions is again a positive expression.

Sounds sensible.

> This will help, for example, to simply formulae like ((1+x)^{1/2})^2, where x
> is a positive symbol.

I hope no simplifications of this kind will be done automatically.

>   It would be also a better LaTeX printing of complicated formulae if \mathrm
>   will be used instead of \mbox (the later is not scaled in fractions, for
>   example).

I agree.
 
>   I am attaching a patch which makes these two things.

\begin{tip}

Your patch does two absolutely unrelated things. It's better to spilt such
patches into independent parts (this makes merging and identifying bugs
a bit simpler).

\end{tip}


Best regards,
        Alexei
 
_______________________________________________
GiNaC-devel mailing list
GiNaC-devel@...
https://www.cebix.net/mailman/listinfo/ginac-devel

Re: Positive add and mul, LaTeX printing

by Vladimir V. Kisil-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> On Tue, 15 Sep 2009 20:33:36 +0300, Alexei Sheplyakov <varg@...> said:
    ASh> \begin{tip}
    ASh> Your patch does two absolutely unrelated things. It's better to
    ASh> spilt such patches into independent parts (this makes merging
    ASh> and identifying bugs a bit simpler).
    ASh> \end{tip}

        Yes, I will do this the next time

        Best wishes,
        Vladimir
--
Vladimir V. Kisil     email: kisilv@...
--                      www: http://maths.leeds.ac.uk/~kisilv/
_______________________________________________
GiNaC-devel mailing list
GiNaC-devel@...
https://www.cebix.net/mailman/listinfo/ginac-devel