# Zygote AutoDiff Works for Symboic Representation

## Check by Zygote for Composite Function


```julia
using Symbolics
using Zygote
```


```julia
f(x) = 3x^2
g(x) = 2x^2
h(x) = x^2
y(x) = f(g(h(x)))

@variables x
display(y(x))
```


\begin{equation}
12 x^{8}
\end{equation}




```julia
dy(x) = gradient(y,x)[1]
display(dy(x))
```


\begin{equation}
96 x^{7}
\end{equation}



## Check by Zygote for DiffProg-Type Code


```julia
function y(x, N)
    # N = 5
    y = 1
    for i=1:N
        y *= x
    end
    y
end

@variables x
display(y(x, 5))
```


\begin{equation}
x^{5}
\end{equation}




```julia
dy(x,N) = Zygote.gradient(y,x,N)[1]
dy(x,5)
```




\begin{equation}
5 x^{4}
\end{equation}




## Appendix


```julia
function y(x)
    N = 5
    y = 1
    for i=1:N
        y *= x
    end
    y
end

display(y(x))
dy(x) = Zygote.gradient(y,x)[1]
dy(x)
```


\begin{equation}
x^{5}
\end{equation}






\begin{equation}
5 x^{4}
\end{equation}




8f495cd4dc7404ff765956a68ceeccae1fbd0cf0
ipynb
Jupyter Notebook
diffprog/julia_dp/AD_zygote4symb.ipynb
jskDr/keraspp_2021
dc46ebb4f4dea48612135136c9837da7c246534a
MIT
2021-09-21T15:35:04.000Z
2021-12-14T12:14:44.000Z
diffprog/julia_dp/AD_zygote4symb.ipynb
jskDr/keraspp_2021
dc46ebb4f4dea48612135136c9837da7c246534a
MIT
diffprog/julia_dp/AD_zygote4symb.ipynb
jskDr/keraspp_2021
dc46ebb4f4dea48612135136c9837da7c246534a
MIT
Qwen/Qwen-72B
1. YES
2. YES