# Generate Julia expressions with Symbolics

**URL:** <https://discourse.julialang.org/t/generate-julia-expressions-with-symbolics/75528>\
**Category:** General Usage\
**Tags:** symbolics\
**Created:** [January 31, 2022, 6:43pm UTC](https://discourse.julialang.org/t/generate-julia-expressions-with-symbolics/75528 "2022-01-31T18:43:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [January 31, 2022, 6:43pm UTC](https://discourse.julialang.org/t/generate-julia-expressions-with-symbolics/75528/1 "2022-01-31T18:43:21Z")

</div>

Dear all,

I’m starting with Symbolics.jl, however I’m stuck with a basic functionality.  
I often use sympy to generate some text expressions that I then copy/paste in either C, MATLAB or Julia codes. I was wondering how one could do this with symbolics?

Here’s a sympy example that better illustrates what I mean:

```nohighlight
x, a, b, c = symbols('x, a, b, c')
F = a*x **3 + b*x** 2 + c*x
print('Julia_expr = ' + julia_code( F.diff(x) ) ) 
print('Octave_expr = ' + octave_code( F.diff(x) ) ) 
print('C_expr = ' + ccode( F.diff(x) ) ) 

```

Also, one issue here: the ‘Julia\_expr’ still needs to be edited before use within Julia (dots are missing 😃 )

thanks for your input!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 31, 2022, 7:12pm UTC](https://discourse.julialang.org/t/generate-julia-expressions-with-symbolics/75528/2 "2022-01-31T19:12:41Z")

</div>

`build_function`.

[https://symbolics.juliasymbolics.org/dev/manual/build\_function/](https://symbolics.juliasymbolics.org/dev/manual/build_function/)

---

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [February 2, 2022, 8:30am UTC](https://discourse.julialang.org/t/generate-julia-expressions-with-symbolics/75528/3 "2022-02-02T08:30:26Z")

</div>

Thanks for the link. As far as I understand the docs `build_function()` build functions in different languages and with different types of parallelism.  
I was wondering whether there was a also way to create a single line expression just as sympy’s `julia_code` does?  
I could not pick it up from the docs; I’ve searched for wrong key words.

```julia
using Symbolics
@variables x a b c
D = Differential(x)
F = a*x^3 + b*x^2 + c*x
dFdx = expand_derivatives(D(F))
build_function(dFdx, x, a, b, c, target=Symbolics.JuliaTarget())
build_function(dFdx, x, a, b, c, target=Symbolics.CTarget())
build_function(dFdx, x, a, b, c, target=Symbolics.MATLABTarget())

```
