Opened 4 years ago

# f.subs(I==...) does not work — at Version 7

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

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 4 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 4 years ago by zimmerma

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

### comment:3 Changed 4 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 4 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 4 years ago by zimmerma

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

### comment:6 Changed 4 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 4 years ago by rws

• Description modified (diff)

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

Note: See TracTickets for help on using tickets.