# How to substitute realpart and imagpart after conversion to rectform?

Hello, I need to split some complicated expression into real and imaginary part, and I use function "rectform()" to do it. Then I want to plot just the imaginary part of the expression, and it seems obvious to substitute zero in place of real part. However, the substitution does not work.

Here is a minimal example, which reproduces this behavior. I want to substitute $\Re [A]$ with "$x$":

```
sage: var("A, x")
-> (A, x)
sage: assume(A, "complex")
sage: Ar = A.rectform()
sage: print Ar
-> realpart(A) + I*imagpart(A)
```

Then we try to substitute $\Re[x] \to x$:

```
sage: Ar.subs({real(A): x})
-> realpart(A) + I*imagpart(A) # No effect
sage: Ar.subs({real_part(A): x})
-> realpart(A) + I*imagpart(A) # No effect
sage: Ar.subs({A.real(): x})
-> realpart(A) + I*imagpart(A) # No effect
sage: Ar.subs({A.real_part(): x})
-> realpart(A) + I*imagpart(A) # No effect
sage: Ar.subs({realpart(A): x})
-> NameError: name 'realpart' is not defined
sage: Ar.subs({A.realpart(): x})
-> AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'realpart'
```

Then I try to use interface to *maxima*:

```
sage: maxima.subst(x, realpart(A), Ar)
-> NameError: name 'realpart' is not defined
sage: maxima.subst(x, real(A), Ar)
-> 'realpart(x)+%i*'imagpart(x) # Wrong substitution
sage: maxima.subst(x, A.realpart(), Ar)
-> AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'realpart'
sage: maxima.subst(x, A.real(), Ar)
-> 'realpart(x)+%i*'imagpart(x) # Wrong substitution
```

As you can see, *maxima* replaces $A$ with $x$ in the whole expression. E.g., if $x=0$, then after the substitution the whole expression is zero, not just the real part. How to do the substitution? Are there any workarounds?