# How to substitute diff(y(x),x) with another expression in first and second order implicit differentiation?

I want to use implicit differentiation to find a dy/dx and d2y/dx2. Usually the solution on paper involves finding a replacement for y' that would eventually simplifies the final answer to some simple function of y.

so, for first and second derivative of x^2+y^2=1: there comes an issue where I got sequence instead of expression and I had to convert it to symbolic expression. which ended up with this :

```
y = function('y')(x);
f = x^2+y^2==1;
print('f is')
show(f)
df=diff(f,x,1);
show(df)
answer_1 = solve(diff(f,x,1),diff(y,x))
show(answer_1)
equation_1 = symbolic_expression(answer_1)
answer_2 = diff(equation_1 ,x)
show(answer_2)
equation_2 = symbolic_expression(answer_2[0])
show(equation_2.expand())
```

I couldn't find a way to substitute the "diff(y,x)" with another expression which only contains y which eventually goes to simplifies the expression to -1/y**3. my workaround this issue was converting the equation to strings and replace the strings with what I wanted.

```
show(symbolic_expression(str(equation_2.rhs()).replace(str(diff(y(x),x)),str(answer_1[0].rhs()))).substitute(solve(f,x**2)).simplify_full())
```

which is not the right way. please help :).

if you are looking for the source of the problem. it is from Thomas' calculus 11th edition. Exercise 3.6 no 37-42

Edit - here is a solved example from the book https://pasteboard.co/VXDe8HN0Vytn.png

here is the questions I was referring to: https://pasteboard.co/ecXwH8W1ZRjI.png

Second Edit: ok there my 9.2 sagemath is kinda old. I tried with SageMath 10 on cocalc, the problem is eventhough I'm giving the right code, it doesn't change the derivative with something else.

```
y = function('y')(x);
f = x^2+y^2==1;
dydx = solve(diff(f,x,1),diff(y,x,1))
show(dydx[0].rhs())
show(f)
df=diff(dydx[0].rhs(),x,1)
show(df)
df=diff(df,x,1)
df.substitute(diff(y,x,1)==dydx[0].rhs())
d2y = solve(df,diff(y,x,2))
show(d2y)
d2y[0].rhs().substitute(diff(y,x,1)==dydx[0].rhs())
d2y[0].rhs().substitute(x^2==1-y^2)
show(d2y)
```

Whene reffering to an external text, please

dothat your readers have your reference text available. Add a pointer to an available source or quote sufficiently (via pastebin if necessary).notassumeThank you !

BTW : is this homework ?

No, this is not a homework. This is not a hard problem. I just couldn't figure out the problem with type of the output. Sometimes it becomes a free form ring and and sometimes it is a generic sequence. other times something that won't be recognized as symbolic. what ever it is, it might be related to how I defined Y(x).

I am relearning calculus for myself. I just wanted to provide the context of the problem, and by the way I think that most of these problems might be in a course for Differential equations not Calculus I. Cause I remember solving for d2y/dx2 somewhere else.

what level of homework can make me do this :D show(symbolic_expression(str(equation_2.rhs()).replace(str(diff(y(x),x)),str(answer_1[0].rhs()))).substitute(solve(f,x**2)).simplify_full())