]> www.ginac.de Git - ginac.git/commitdiff
Make it possible to override info() for functions.
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)
Signed-off-by: Vladimir V. Kisil <kisilv@maths.leeds.ac.uk>
check/exam_inifcns.cpp
ginac/flags.h
ginac/function.cppy
ginac/function.hppy
ginac/function.py

index 77a4b3b73d725c001b9e9a0d67eca2149502b995..30d5b2128bac37df222fa1c8716561818d4dea0c 100644 (file)
@@ -249,6 +249,15 @@ static unsigned inifcns_consist_abs()
        if (!abs(step(z)).eval().is_equal(step(z)))
                ++result;
 
+       if (!abs(p).info(info_flags::positive) || !abs(a).info(info_flags::real))
+               ++result;
+
+       if (abs(a).info(info_flags::positive) || !abs(a).info(info_flags::real))
+               ++result;
+
+       if (abs(z).info(info_flags::positive) || !abs(z).info(info_flags::real))
+               ++result;
+
        return result;
 }
 
index e38d9c58b0949703616e6b0e92eec9b7817062e4..3d398cf18619c6d0f5489c319ce48622b72591d3 100644 (file)
@@ -207,7 +207,7 @@ public:
 class info_flags {
 public:
        enum {
-               // answered by class numeric, add, mul and symbols/constants in particular domains
+               // answered by class numeric, add, mul, function and symbols/constants in particular domains
                numeric,
                real,
                rational,
index 2a9080cf698e43d519bce298bdc435833250125c..ce38045f96150add137a0de4d84ce41cf2373001 100644 (file)
@@ -80,6 +80,7 @@ void function_options::initialize()
        nparams = 0;
        eval_f = evalf_f = real_part_f = imag_part_f = conjugate_f = expand_f
                = derivative_f = power_f = series_f = 0;
+       info_f = 0;
        evalf_params_first = true;
        use_return_type = false;
        eval_use_exvector_args = false;
@@ -92,6 +93,7 @@ void function_options::initialize()
        power_use_exvector_args = false;
        series_use_exvector_args = false;
        print_use_exvector_args = false;
+       info_use_exvector_args = false;
        use_remember = false;
        functions_with_same_name = 1;
        symtree = 0;
@@ -594,6 +596,31 @@ ex function::imag_part() const
        throw(std::logic_error("function::imag_part(): invalid nparams"));
 }
 
+/** Implementation of ex::info for functions. */
+bool function::info(unsigned inf) const
+{
+       GINAC_ASSERT(serial<registered_functions().size());
+       const function_options & opt = registered_functions()[serial];
+
+       if (opt.info_f==0) {
+               return basic::info(inf);
+       }
+
+       if (opt.info_use_exvector_args) {
+               return ((info_funcp_exvector)(opt.info_f))(seq, inf);
+       }
+
+       switch (opt.nparams) {
+               // the following lines have been generated for max. @maxargs@ parameters
++++ for N in range(1, maxargs + 1):
+               case @N@:
+                       return ((info_funcp_@N@)(opt.info_f))(@seq('seq[%(n)d]', N, 0)@, inf);
+---
+               // end of generated lines
+       }
+       throw(std::logic_error("function::info(): invalid nparams"));
+}
+
 // protected
 
 /** Implementation of ex::diff() for functions. It applies the chain rule,
index fa178135451cb951d9c48bc958a67b7286260ed9..5d7ca098c9ece9fc7a241c95f664798191db961f 100644 (file)
@@ -62,6 +62,7 @@ typedef ex (* derivative_funcp)();
 typedef ex (* power_funcp)();
 typedef ex (* series_funcp)();
 typedef void (* print_funcp)();
+typedef bool (* info_funcp)();
 
 // the following lines have been generated for max. @maxargs@ parameters
 +++ for N, args in [ ( N, seq('const ex &', N) ) for N in range(1, maxargs + 1) ]:
@@ -75,6 +76,7 @@ typedef ex (* derivative_funcp_@N@)( @args@, unsigned );
 typedef ex (* power_funcp_@N@)( @args@, const ex & );
 typedef ex (* series_funcp_@N@)( @args@, const relational &, int, unsigned );
 typedef void (* print_funcp_@N@)( @args@, const print_context & );
+typedef bool (* info_funcp_@N@)( @args@, unsigned );
 ---
 // end of generated lines
 
@@ -88,6 +90,7 @@ typedef ex (* derivative_funcp_exvector)(const exvector &, unsigned);
 typedef ex (* power_funcp_exvector)(const exvector &, const ex &);
 typedef ex (* series_funcp_exvector)(const exvector &, const relational &, int, unsigned);
 typedef void (* print_funcp_exvector)(const exvector &, const print_context &);
+typedef bool (* info_funcp_exvector)(const exvector &, unsigned);
 
 
 class function_options
@@ -159,6 +162,7 @@ protected:
        power_funcp power_f;
        series_funcp series_f;
        std::vector<print_funcp> print_dispatch_table;
+       info_funcp info_f;
 
        bool evalf_params_first;
 
@@ -181,6 +185,7 @@ protected:
        bool power_use_exvector_args;
        bool series_use_exvector_args;
        bool print_use_exvector_args;
+       bool info_use_exvector_args;
 
        unsigned functions_with_same_name;
 
@@ -232,6 +237,7 @@ public:
        ex imag_part() const;
        void archive(archive_node& n) const;
        void read_archive(const archive_node& n, lst& syms);
+       bool info(unsigned inf) const;
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
index 0ecb918c2b4a07c4dafe01d789df9e910db1c294..3f5e54eb6028d95fef63e72c880c1cc6d17f2ab7 100755 (executable)
@@ -2,7 +2,7 @@
 # encoding: utf-8
 
 maxargs = 14
-methods = "eval evalf conjugate real_part imag_part expand derivative power series print".split()
+methods = "eval evalf conjugate real_part imag_part expand derivative power series info print".split()
 
 import sys, os, optparse
 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'scripts'))