]> www.ginac.de Git - ginac.git/blobdiff - ginac/inifcns.cpp
Update copyright statements.
[ginac.git] / ginac / inifcns.cpp
index 1144ce1997e14eed7911a6b6004a18fcc008b1a4..02c909f313180456e7598794500cad82c4a0370f 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's initially known functions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2014 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -254,6 +254,27 @@ static ex abs_eval(const ex & arg)
        return abs(arg).hold();
 }
 
+static ex abs_expand(const ex & arg, unsigned options)
+{
+       if ((options & expand_options::expand_transcendental)
+               && is_exactly_a<mul>(arg)) {
+               exvector prodseq;
+               prodseq.reserve(arg.nops());
+               for (const_iterator i = arg.begin(); i != arg.end(); ++i) {
+                       if (options & expand_options::expand_function_args)
+                               prodseq.push_back(abs(i->expand(options)));
+                       else
+                               prodseq.push_back(abs(*i));
+               }
+               return (new mul(prodseq))->setflag(status_flags::dynallocated | status_flags::expanded);
+       }
+
+       if (options & expand_options::expand_function_args)
+               return abs(arg.expand(options)).hold();
+       else
+               return abs(arg).hold();
+}
+
 static void abs_print_latex(const ex & arg, const print_context & c)
 {
        c.s << "{|"; arg.print(c); c.s << "|}";
@@ -317,6 +338,7 @@ bool abs_info(const ex & arg, unsigned inf)
 
 REGISTER_FUNCTION(abs, eval_func(abs_eval).
                        evalf_func(abs_evalf).
+                       expand_func(abs_expand).
                        info_func(abs_info).
                        print_func<print_latex>(abs_print_latex).
                        print_func<print_csrc_float>(abs_print_csrc_float).