# Wengert list -- possible graphs?

**URL:** <https://discourse.julialang.org/t/wengert-list-possible-graphs/59891>\
**Category:** New to Julia\
**Created:** [April 23, 2021, 6:49pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891 "2021-04-23T18:49:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 23, 2021, 6:49pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/1 "2021-04-23T18:49:21Z")

</div>

Hello everybody,

I wonder if there is a Julia package that, from a given equation, produces the calculation graph (Wenger’s list). As if:

```julia
f(x1,x2) = x1*x2 - sin(x2)

```

gives:  
 ![wenglert_1](https://global.discourse-cdn.com/julialang/original/3X/7/1/71060d4158837f1f612057aed04d7e8df0ab7364.png)  
A bit like [Catalyst.jl](https://catalyst.sciml.ai/dev/tutorials/using_catalyst/) allows the use of Graphiz…

See also the graph in [this video](https://youtu.be/wG_nF1awSSY) (~6:38) cited [in the present forum](https://discourse.julialang.org/t/learning-automatic-differentiation/56158/7)

Thanks for your advices,  
Thierry

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 23, 2021, 7:15pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/2 "2021-04-23T19:15:32Z")

</div>

[GitHub - JuliaTeX/TreeView.jl: Draw Julia syntax trees as a graph](https://github.com/JuliaTeX/TreeView.jl) does something similar.

Also [GitHub - JuliaPlots/GraphRecipes.jl: Graph-related recipes to be used with Plots.jl](https://github.com/JuliaPlots/GraphRecipes.jl).

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 23, 2021, 7:29pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/3 "2021-04-23T19:29:56Z")

</div>

Many thanks David!

I am looking at GraphRecipes but TreeView is already helpfull (I’ve just tried it without further investigation).  
Is there anything more aesthetically pleasing for didactic forms.

T.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 23, 2021, 7:37pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/4 "2021-04-23T19:37:46Z")

</div>

GraphRecipes.jl is more aesthetically pleasing I guess.

Or else you can modify TreeView, which uses TikzGraphs, according to your taste (and send a PR 😉 )

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 23, 2021, 7:46pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/5 "2021-04-23T19:46:41Z")

</div>

When installing GraphRecipes, I see that the package has links to ChainRules + ChainRulesCore, Zygote and… Flux. This is great.  
And probably the solution I am looking for. I am testing this!

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 23, 2021, 8:36pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/6 "2021-04-23T20:36:57Z")

</div>

OK… If I understand correctly, GraphRecipes cannot directly process a raw Wengert list like:

```julia
y1 = x ^ 2
y2 = 3 * y1
y3 = 2x
y4 = y3 + 1
y5 = y2 + y4

```

associated with:

```julia
y = :(3x^2 + (2x + 1))
w_y = Wengert(y)

```

It is necessary to provide it with the elements “by hand”. Is it right?

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 23, 2021, 8:46pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/7 "2021-04-23T20:46:44Z")

</div>

However, I find that TreeView (despite its apparent simplicity) renders the relationship with the parents very well, which allows a good link with automatic reverse differentiation for “simple” cases.  
Exple with @dag ou @dag\_cse

Many thanks for your rapid help. 😀

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 30, 2021, 6:14pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/8 "2021-04-30T18:14:50Z")

</div>

One last (?) questions: once a TreeView graph is produced, how to save it?

Then I saw how [it is possible to transform it into .svg](https://nbviewer.jupyter.org/github/sisl/TikzGraphs.jl/blob/master/doc/TikzGraphs.ipynb) for example. All the packages are installed (TikzGraphs, LightGraphs, TikzPictures, `pdf2svg). Of course LaTeX/Lyx is installed…

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 30, 2021, 7:06pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/9 "2021-04-30T19:06:40Z")

</div>

Good question. However you’re supposed to save Tikz pictures with those other packages I guess.

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 30, 2021, 10:10pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/10 "2021-04-30T22:10:51Z")

</div>

> [@dpsanders](#):
>
> However you’re supposed to save Tikz pictures with those other packages I guess

There is something that I don’t understand.  
In the REPL, I do:

julia\> @dag :(x1\*x2 - sin(x2))

Juno opens a Plots panel and displays the graph  
 ![treeview](https://global.discourse-cdn.com/julialang/original/3X/9/0/90880afe36ac8e41835e02da86ee5cd759cc9f92.png)

The type of graph is  
TreeView.DirectedAcyclicGraph

I wonder how to save this graph. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 1, 2021, 3:18am UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/11 "2021-05-01T03:18:21Z")

</div>

What do you mean by save? As in save a pdf to a file?

What I was suggesting is that since TreeView uses TikzGraphs.jl to draw the graph, you need to look at their docs to work out how to do that.

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [May 1, 2021, 5:50pm UTC](https://discourse.julialang.org/t/wengert-list-possible-graphs/59891/12 "2021-05-01T17:50:56Z")

</div>

Hello,

Finally I used these lines (inspired by [this notebook](https://nbviewer.jupyter.org/github/sisl/TikzGraphs.jl/blob/master/doc/TikzGraphs.ipynb)):

```julia
g = DiGraph(8)
add_edge!(g, 1,2)
add_edge!(g, 2,3)
add_edge!(g, 3,4)
add_edge!(g, 4,5)
add_edge!(g, 6,7)
add_edge!(g, 7,8)
add_edge!(g, 8,4)
add_edge!(g, 7,3)

```

Followed by:

```julia
t = TikzGraphs.plot(g, 
     [" ", L"v_1", L"v_3", L"v_5", " ", " ", L"v_2", L"v_4"], 
     node_style="draw, rounded corners, fill=blue!50", 
     edge_labels=Dict((1,2)=>L"x_1", (3,4)=>L"x_1x_2", (8,4)=>L"\sin(x_2)", 
                (4,5)=>L"x_1x_2 - \sin(x_2)", (6,7)=>L"x_2")
    )

```

And

```julia
TikzPictures.save(SVG("graph"), t)

```

So I obtained:  
 ![graph2](https://global.discourse-cdn.com/julialang/original/3X/9/1/9195d998b9bdbc9062a54f08b20a9b6f7f8ebef2.png)

Questions:

- Do you have any idea how to move the x1x2 term to the left of the arrow connecting v3 to v5?

- How to replace arrow by simple lines?

Thanks in advance,  
Thierry
