Vlamirs patch for automatically simplifying e.g., csgn(x)^3 -> csgn(x).
authorChris Dams <Chris.Dams@mi.infn.it>
Tue, 14 Mar 2006 18:54:55 +0000 (18:54 +0000)
committerChris Dams <Chris.Dams@mi.infn.it>
Tue, 14 Mar 2006 18:54:55 +0000 (18:54 +0000)
ginac/inifcns.cpp

index 47252a8f0d85724a4ccccd02d11382ccbadfd265..a8f82d8ea0413efaa02e63ea29d9a9919759f793 100644 (file)
@@ -252,10 +252,23 @@ static ex csgn_conjugate(const ex& arg)
        return csgn(arg);
 }
 
+static ex csgn_power(const ex & arg, const ex & exp)
+{
+       if (is_a<numeric>(exp) && exp.info(info_flags::positive) && ex_to<numeric>(exp).is_integer()) {
+               if (ex_to<numeric>(exp).is_odd())
+                       return csgn(arg);
+               else
+                       return power(csgn(arg), _ex2).hold();
+       } else
+               return power(csgn(arg), exp).hold();
+}
+
+
 REGISTER_FUNCTION(csgn, eval_func(csgn_eval).
                         evalf_func(csgn_evalf).
                         series_func(csgn_series).
-                        conjugate_func(csgn_conjugate));
+                        conjugate_func(csgn_conjugate).
+                        power_func(csgn_power));
 
 
 //////////