[GiNaC-list] a counterintuitive case with subs
Richard B. Kreckel
kreckel at in.terlu.de
Wed Mar 23 09:01:48 CET 2022
Dear Feng,
On 20.03.22 10:44, Feng Feng wrote:
> I got a problem with the function subs, and I am not sure it is a
> possible bug or not,
> but it seems counterintuitive.
>
> Here is the code to reproduce the case:
> //------------------------------------------------
> #include "ginac/ginac.h"
> using namespace std;
> using namespace GiNaC;
> int main() {
> symbol s("s");
> ex t = subs(1/s,s==1/s, subs_options::no_pattern);
> cout << t << endl;
> return 0;
> }
> //------------------------------------------------
> The output is 1/s instead of s.
>
> PS: if I remove the subs_options::no_pattern, the output is s as expected.
>
> and I have a look at the source code of basic::subs, it seems it comes
> from the following code:
> that is, the final substitutions on the new object as a whole,
> //------------------------------------------------
> // Perform substitutions on the new object as a whole
> return copy->subs_one_level(m, options);
> //------------------------------------------------
I don't see how that code is related to the problem.
Rather, power.cpp:622 seems to be the culprit. We subs s==1/s in the
basis of s^n, then, in the result, we subs s==1/s again. Isn't subs'ing
/again/ just wrong? It strikes me as weird but I run too low on coffee
to think clear.
Anyway, the attached patch seems to fix your problem and not cause
regressions. Please try.
All my best,
-richy.
--
Richard B. Kreckel
<https://in.terlu.de/~kreckel/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: feng-subs.patch
Type: text/x-patch
Size: 531 bytes
Desc: not available
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20220323/d03d27f0/attachment.bin>
More information about the GiNaC-list
mailing list