2

Here is a simple session with maxima, in which im trying to make the simplification (r-r0)=h

(%i1) ax: G*M*m*(r-r0)/r0^2 - G*M*m/r0 ;
                            G M m (r - r0)   G M m
(%o1)                       -------------- - -----
                                   2          r0
                                 r0
(%i2) let(r-r0,h);
(%o2)                            r - r0 --> h
(%i3) expand(scanmap(letsimp,ax));
                               G M m r   2 G M m
(%o3)                          ------- - -------
                                   2       r0
                                 r0

I was expecting this in the last part:

                               G M m h   2 G M m
                              ------- - -------
                                   2       r0
                                 r0

Why did maxima replace (r-r0) with r rather than with h? Iv attempted letsimp and letrat as instructed in this other question: common subexpressions

user22866
  • 231
  • 4
  • 15

1 Answers1

2

r - r0 is not a form supported by let. From the documentation:

-- Function: let let (, , , , ..., ) let ([, , , , ..., ], )

 Defines a substitution rule for 'letsimp' such that <prod> is
 replaced by <repl>.  <prod> is a product of positive or negative
 powers of the following terms:

    * Atoms which 'letsimp' will search for literally unless
      previous to calling 'letsimp' the 'matchdeclare' function is
      used to associate a predicate with the atom.  In this case
      'letsimp' will match the atom to any term of a product
      satisfying the predicate.
    * Kernels such as 'sin(x)', 'n!', 'f(x,y)', etc.  As with atoms
      above 'letsimp' will look for a literal match unless
      'matchdeclare' is used to associate a predicate with the
      argument of the kernel.

In this case one can start with a syntactic substitution:

    (%i1) ax: G*M*m*(r-r0)/r0^2 - G*M*m/r0 $

    (%i2) subst(h, r - r0, ax);
                                    G M h m   G M m
    (%o2)                           ------- - -----
                                        2      r0
                                      r0
slitvinov
  • 5,693
  • 20
  • 31