abs() and conjugate() provide some info() now.
authorVladimir V. Kisil <kisilv@maths.leeds.ac.uk>
Wed, 11 Sep 2013 08:26:30 +0000 (09:26 +0100)
committerAlexei Sheplyakov <Alexei.Sheplyakov@gmail.com>
Wed, 16 Oct 2013 05:20:30 +0000 (08:20 +0300)
ginac/inifcns.cpp

index e8aacab..1144ce1 100644 (file)
@@ -76,8 +76,46 @@ static ex conjugate_imag_part(const ex & arg)
        return -arg.imag_part();
 }
 
+static bool func_arg_info(const ex & arg, unsigned inf)
+{
+       // for some functions we can return the info() of its argument
+       // (think of conjugate())
+       switch (inf) {
+               case info_flags::polynomial:
+               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::even:
+               case info_flags::odd:
+               case info_flags::prime:
+               case info_flags::crational_polynomial:
+               case info_flags::rational_function:
+               case info_flags::algebraic:
+               case info_flags::positive:
+               case info_flags::negative:
+               case info_flags::nonnegative:
+               case info_flags::posint:
+               case info_flags::negint:
+               case info_flags::nonnegint:
+               case info_flags::has_indices:
+                       return arg.info(inf);
+       }
+       return false;
+}
+
+static bool conjugate_info(const ex & arg, unsigned inf)
+{
+       return func_arg_info(arg, inf);
+}
+
 REGISTER_FUNCTION(conjugate_function, eval_func(conjugate_eval).
                                       evalf_func(conjugate_evalf).
+                                      info_func(conjugate_info).
                                       print_func<print_latex>(conjugate_print_latex).
                                       conjugate_func(conjugate_conjugate).
                                       real_part_func(conjugate_real_part).
@@ -250,8 +288,36 @@ static ex abs_power(const ex & arg, const ex & exp)
                return power(abs(arg), exp).hold();
 }
 
+bool abs_info(const ex & arg, unsigned inf)
+{
+       switch (inf) {
+               case info_flags::integer:
+               case info_flags::even:
+               case info_flags::odd:
+               case info_flags::prime:
+                       return arg.info(inf);
+               case info_flags::nonnegint:
+                       return arg.info(info_flags::integer);
+               case info_flags::nonnegative:
+               case info_flags::real:
+                       return true;
+               case info_flags::negative:
+                       return false;
+               case info_flags::positive:
+                       return arg.info(info_flags::positive) || arg.info(info_flags::negative);
+               case info_flags::has_indices: {
+                       if (arg.info(info_flags::has_indices))
+                               return true;
+                       else
+                               return false;
+               }
+       }
+       return false;
+}
+
 REGISTER_FUNCTION(abs, eval_func(abs_eval).
                        evalf_func(abs_evalf).
+                       info_func(abs_info).
                        print_func<print_latex>(abs_print_latex).
                        print_func<print_csrc_float>(abs_print_csrc_float).
                        print_func<print_csrc_double>(abs_print_csrc_float).