Let's see:

```
x,z, xm, xs, zs, z2, d1, d2, em, es =var('x z xm xs zs z2 d1 d2 em es')
equations = [d1 == sqrt(xm*xm + zs*zs),
d2 == sqrt(z2*z2 + xs*xs),
xm + xs == x,
zs + z2 == z,
(xm/zs)/(xs/z2) == (em/es)]
E1=[u.subs(equations[2].solve(xm)).simplify_full() for u in equations]
E2=[u.subs(E1[3].solve(z2)).simplify_full() for u in E1]
E3=[u.subs(E2[4].solve(xs)).simplify_full() for u in E2]
E3
[d1 == sqrt((2*(em*es - es^2)*z*zs^3 + (em^2 - 2*em*es + es^2)*zs^4 + (em^2*x^2 + es^2*z^2)*zs^2)/(es^2*z^2 + 2*(em*es - es^2)*z*zs + (em^2 - 2*em*es + es^2)*zs^2)),
d2 == sqrt((es^2*x^2*z^2 + es^2*z^4 - 2*(em^2 - 3*em*es + 2*es^2)*z*zs^3 + (em^2 - 2*em*es + es^2)*zs^4 + (es^2*x^2 + (em^2 - 6*em*es + 6*es^2)*z^2)*zs^2 - 2*(es^2*x^2*z - (em*es - 2*es^2)*z^3)*zs)/(es^2*z^2 + 2*(em*es - es^2)*z*zs + (em^2 - 2*em*es + es^2)*zs^2)),
x == x,
z == z,
em/es == em/es]
```

Note that `maxima.eliminate`

is supposed to do that (but fails lamentably...).

**Note, two hours later :** (that's what called in french *"l'esprit de l'escalier"...*):

Of course, you can get the desired result trivially by solving for the variables to eliminate as well as for the desired variables :

```
solve(equations,[d1, d2, xm, xs, z2])
[[d1 == sqrt((2*(em*es - es^2)*z*zs^3 + (em^2 - 2*em*es + es^2)*zs^4 + (em^2*x^2 + es^2*z^2)*zs^2)/(es^2*z^2 + 2*(em*es - es^2)*z*zs + (em^2 - 2*em*es + es^2)*zs^2)),
d2 == sqrt(z^2 - 2*z*zs + zs^2 + (es*x*z - es*x*zs)^2/(es*z + (em - es)*zs)^2),
xm == em*x*zs/(es*z + (em - es)*zs),
xs == (es*x*z - es*x*zs)/(es*z + (em - es)*zs),
z2 == z - zs]]
```

The variables to be eliminated do not figure indeed in the solutions for the desired variables...

I should sleep more...

**"L'esprit de l'escalier" strikes again :**

You can get "cleaner" solutionns with :

```
solve(equations,[d1, d2, xm, xs, z2], algorithm="sympy", solution_dict=False)
[{xm: em*x*zs/(es*z + em*zs - es*zs),
d2: sqrt(es^2*x^2*(z - zs)^2/(es*z + em*zs - es*zs)^2 + (z - zs)^2),
d1: sqrt(em^2*x^2*zs^2/(es*z + em*zs - es*zs)^2 + zs^2),
z2: z - zs,
xs: es*x*(z - zs)/(es*z + em*zs - es*zs)}]
```