]> www.ginac.de Git - ginac.git/blobdiff - ginac/power.cpp
Update documentation of prerequisites.
[ginac.git] / ginac / power.cpp
index 1a4f57dbfe142741fc6117044f3c778673eb3389..2106b5113c6e26a5c60ebdb57c10991d661a4572 100644 (file)
@@ -139,7 +139,7 @@ void power::do_print_latex(const print_latex & c, unsigned level) const
 static void print_sym_pow(const print_context & c, const symbol &x, int exp)
 {
        // Optimal output of integer powers of symbols to aid compiler CSE.
-       // C.f. ISO/IEC 14882:1998, section 1.9 [intro execution], paragraph 15
+       // C.f. ISO/IEC 14882:2011, section 1.9 [intro execution], paragraph 15
        // to learn why such a parenthesation is really necessary.
        if (exp == 1) {
                x.print(c);
@@ -178,8 +178,8 @@ void power::do_print_csrc_cl_N(const print_csrc_cl_N& c, unsigned level) const
 void power::do_print_csrc(const print_csrc & c, unsigned level) const
 {
        // Integer powers of symbols are printed in a special, optimized way
-       if (exponent.info(info_flags::integer)
-        && (is_a<symbol>(basis) || is_a<constant>(basis))) {
+       if (exponent.info(info_flags::integer) &&
+           (is_a<symbol>(basis) || is_a<constant>(basis))) {
                int exp = ex_to<numeric>(exponent).to_int();
                if (exp > 0)
                        c.s << '(';
@@ -384,8 +384,8 @@ ex power::eval(int level) const
        const ex & ebasis    = level==1 ? basis    : basis.eval(level-1);
        const ex & eexponent = level==1 ? exponent : exponent.eval(level-1);
        
-       const numeric *num_basis = NULL;
-       const numeric *num_exponent = NULL;
+       const numeric *num_basis = nullptr;
+       const numeric *num_exponent = nullptr;
        
        if (is_exactly_a<numeric>(ebasis)) {
                num_basis = &ex_to<numeric>(ebasis);
@@ -495,8 +495,8 @@ ex power::eval(int level) const
                        if (is_exactly_a<numeric>(sub_exponent)) {
                                const numeric & num_sub_exponent = ex_to<numeric>(sub_exponent);
                                GINAC_ASSERT(num_sub_exponent!=numeric(1));
-                               if (num_exponent->is_integer() || (abs(num_sub_exponent) - (*_num1_p)).is_negative() 
-                                               || (num_sub_exponent == *_num_1_p && num_exponent->is_positive())) {
+                               if (num_exponent->is_integer() || (abs(num_sub_exponent) - (*_num1_p)).is_negative() ||
+                                   (num_sub_exponent == *_num_1_p && num_exponent->is_positive())) {
                                        return power(sub_basis,num_sub_exponent.mul(*num_exponent));
                                }
                        }
@@ -622,20 +622,18 @@ bool power::has(const ex & other, unsigned options) const
                return basic::has(other, options);
        if (!is_a<power>(other))
                return basic::has(other, options);
-       if (!exponent.info(info_flags::integer)
-                       || !other.op(1).info(info_flags::integer))
+       if (!exponent.info(info_flags::integer) ||
+           !other.op(1).info(info_flags::integer))
                return basic::has(other, options);
-       if (exponent.info(info_flags::posint)
-                       && other.op(1).info(info_flags::posint)
-                       && ex_to<numeric>(exponent).to_int()
-                                       > ex_to<numeric>(other.op(1)).to_int()
-                       && basis.match(other.op(0)))
+       if (exponent.info(info_flags::posint) &&
+           other.op(1).info(info_flags::posint) &&
+           ex_to<numeric>(exponent) > ex_to<numeric>(other.op(1)) &&
+           basis.match(other.op(0)))
                return true;
-       if (exponent.info(info_flags::negint)
-                       && other.op(1).info(info_flags::negint)
-                       && ex_to<numeric>(exponent).to_int()
-                                       < ex_to<numeric>(other.op(1)).to_int()
-                       && basis.match(other.op(0)))
+       if (exponent.info(info_flags::negint) &&
+           other.op(1).info(info_flags::negint) &&
+           ex_to<numeric>(exponent) < ex_to<numeric>(other.op(1)) &&
+           basis.match(other.op(0)))
                return true;
        return basic::has(other, options);
 }
@@ -1009,7 +1007,7 @@ private:
                // NB: Partition must be sorted in non-decreasing order.
                explicit coolmulti(const std::vector<int>& partition)
                {
-                       head = NULL;
+                       head = nullptr;
                        for (unsigned n = 0; n < partition.size(); ++n) {
                                head = new element(partition[n], head);
                                if (n <= 1)
@@ -1024,7 +1022,7 @@ private:
                void next_permutation()
                {
                        element *before_k;
-                       if (after_i->next != NULL && i->value >= after_i->next->value)
+                       if (after_i->next != nullptr && i->value >= after_i->next->value)
                                before_k = after_i;
                        else
                                before_k = i;
@@ -1038,7 +1036,7 @@ private:
                }
                bool finished() const
                {
-                       return after_i->next == NULL && after_i->value >= head->value;
+                       return after_i->next == nullptr && after_i->value >= head->value;
                }
        } cmgen;
        bool atend;  // needed for simplifying iteration over permutations
@@ -1055,7 +1053,7 @@ public:
        {
                coolmulti::element* it = cmgen.head;
                size_t i = 0;
-               while (it != NULL) {
+               while (it != nullptr) {
                        composition[i] = it->value;
                        it = it->next;
                        ++i;
@@ -1310,12 +1308,12 @@ ex power::expand_mul(const mul & m, const numeric & n, unsigned options, bool fr
        }
 
        // do not bother to rename indices if there are no any.
-       if ((!(options & expand_options::expand_rename_idx)) 
-                       && m.info(info_flags::has_indices))
+       if (!(options & expand_options::expand_rename_idx) &&
+           m.info(info_flags::has_indices))
                options |= expand_options::expand_rename_idx;
        // Leave it to multiplication since dummy indices have to be renamed
        if ((options & expand_options::expand_rename_idx) &&
-               (get_all_dummy_indices(m).size() > 0) && n.is_positive()) {
+           (get_all_dummy_indices(m).size() > 0) && n.is_positive()) {
                ex result = m;
                exvector va = get_all_dummy_indices(m);
                sort(va.begin(), va.end(), ex_is_less());