From aed514f534cc6b4438822c1fcf80c203a828a94c Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Wed, 23 Mar 2022 21:21:48 +0100 Subject: [PATCH] Fix power::subs() in some special cases. In some cases, after subs'ing in basis and exponent, an extra substitution was performed. This could lead to messed-up final results because, e.g. substituting x==1/x in 1/x evaluated to x, but then another substitution x==1/x was performed. Reported by Feng Feng . --- check/exam_misc.cpp | 18 ++++++++++++++++++ ginac/power.cpp | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/check/exam_misc.cpp b/check/exam_misc.cpp index 3595c9a2..31dc1bad 100644 --- a/check/exam_misc.cpp +++ b/check/exam_misc.cpp @@ -192,6 +192,24 @@ static unsigned exam_subs() ++result; } + // This used to fail in GiNaC 1.8.2 with subs_options::no_pattern + e1 = 1/x; + e2 = e1.subs(x == 1/x); + if (!e2.is_equal(x)) { + clog << "(1/x).subs(x==1/x) erroneously returned " << e2 << " instead of x" << endl; + ++result; + } + e2 = e1.subs(x == 1/x, subs_options::no_pattern); + if (!e2.is_equal(x)) { + clog << "(1/x).subs(x==1/x, subs_options::no_pattern) erroneously returned " << e2 << " instead of x" << endl; + ++result; + } + e2 = e1.subs(x == 1/x, subs_options::algebraic); + if (!e2.is_equal(x)) { + clog << "(1/x).subs(x==1/x, subs_options::algebraic) erroneously returned " << e2 << " instead of x" << endl; + ++result; + } + return result; } diff --git a/ginac/power.cpp b/ginac/power.cpp index 97095b2a..9019b376 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -619,7 +619,7 @@ ex power::subs(const exmap & m, unsigned options) const if (!are_ex_trivially_equal(basis, subsed_basis) || !are_ex_trivially_equal(exponent, subsed_exponent)) - return power(subsed_basis, subsed_exponent).subs_one_level(m, options); + return dynallocate(subsed_basis, subsed_exponent); if (!(options & subs_options::algebraic)) return subs_one_level(m, options); -- 2.45.0