Opened 3 years ago

# Doctest fix: f.subs(I==...) does not work

Reported by: Owned by: zimmerma major sage-8.1 calculus N/A #24838

Minimal case:

```sage: (I*x).subs(I==0)
I*x
```

Originally:

the `substitute` command does not work with `I`:

```sage: f = sin(x*I)+I*x^2+cos(exp(I))
sage: f.subs(I=0)
I*x^2 + cos(e^I) + sin(I*x)
```

### comment:1 Changed 3 years ago by rws

The documentation: `Substitute with keyword arguments (works only with symbols):`. For you `I` is a symbol but for Pynac it's numeric. Just use dictionary or relational syntax:

```sage: f = sin(x*I)+I*x^2+cos(exp(I))
sage: f
I*x^2 + cos(e^I) + I*sinh(x)
sage: f.subs({I:0})
I*x^2 + cos(1) + I*sinh(x)
sage: f.subs(I==0)
I*x^2 + cos(1) + I*sinh(x)
```

As you can see the `I` inside `cos(e^I)` is now replaced. I agree that the other `I`s not being replaced is a bug. The bug is independent of which numeric is to be substituted:

```sage: f = sin(x*2)+2*x^2+cos(exp(2))
sage: f
2*x^2 + cos(e^2) + sin(2*x)
sage: f.subs({2:0})
cos(1) + sin(2*x) + 2
```

### comment:2 Changed 3 years ago by zimmerma

thank you. Should I open a new ticket for this bug? Or simply change the ticket description?

### comment:3 Changed 3 years ago by rws

• Summary changed from f.subs(I=...) does not work to f.subs(I==...) does not work

Done. I think I will restrict the numerics that can be replaced (not `0` nor `1`).

### comment:4 Changed 3 years ago by zimmerma

• Summary changed from f.subs(I==...) does not work to f.subs(I=...) does not work

btw it is strange that you get `I*sinh(x)` since with Sage 8.0 I get `sin(I*x)`, i.e., this term is unchanged.

### comment:5 Changed 3 years ago by zimmerma

• Summary changed from f.subs(I=...) does not work to f.subs(I==...) does not work

### comment:6 Changed 3 years ago by zimmerma

sorry we edited the ticket simultaneously and I discarded your edit in the title and maybe in the description. I've put the title back to `===` but I'm not sure about the description.

### comment:7 Changed 3 years ago by rws

• Description modified (diff)

Yeah that was an enhancement in a recent Pynac (#23820).

### comment:8 Changed 3 years ago by jdemeyer

Why should `(I*x).subs(I=0)` work? This `I` isn't a variable, it's a complex number. Would you expect `(2*x).subs({2:3})` to give `(3*x)`?

### comment:9 Changed 3 years ago by rws

Well, `subs` was always about termwise substitution. Maxima does it too:

```(%i3) subst(%i=y,%i*x);
(%o3)                                 x y
(%i4) subst(2=y,2*x);
(%o4)                                 x y
```
Last edited 3 years ago by rws (previous) (diff)

### comment:10 Changed 3 years ago by rws

This will be available with pynac-0.7.18 and should be doctested here.

### comment:11 Changed 3 years ago by rws

• Dependencies set to #24838
• Summary changed from f.subs(I==...) does not work to Doctest fix: f.subs(I==...) does not work

### comment:12 Changed 2 years ago by rws

The original case works now, the minimal case `I*x` not, so there is an inconsistency to resolve.

Note: See TracTickets for help on using tickets.