I may give the step-by-step technical explanation why eq.subs works this way:
- The subexpressions of x**2 + 5 are x**2, and 5, which is eq.args
- The subexpressions of x**2 are x and 2, which is (x**2).args
- There are no subexpressions of 5, because 5 is an atom.
- There are no subexpressions of 2, because 2 is an atom.
- There are no subexpressions of x, because x is an atom.
And the subs, (reasonably) works when the expression that is substituted, is equal to the expression, or its subexpressions.
x is recursively the subexpression of x**2 + 5, so eq.subs(x, 1) works,
however, x+1 is not the subexpression of
x**2 + 5, so eq.subs(x+1,2) works.
Although this is not 100% everything about how subs works, however, I think that it explains fairly most of the logic about the subs,
and I hope it can be useful for your programming experience with subs.
The reason that subs(x+1, 2) does not work, is debatable that it should be a bug, or it should be intended part of the design,
However, I'm weighted towards the opinion that it shouldn't be part of the design,
because it is much more complicated and opens up much more rooms for extension or incompleteness, if we adopt that as part of the design.
For example, if subs(x+1, 2) works, then we should also think of how subs(x**2 + 1, 2), or how subs(x**3 + 1, 2) works,
and I'm afraid that such discussions like this clearly gets into discussing very complicated mathematics that you or me are not familiar with.