# Accessing arguments of a symbolic expression using SymbolicUtils.jl

**URL:** <https://discourse.julialang.org/t/accessing-arguments-of-a-symbolic-expression-using-symbolicutils-jl/85600>\
**Category:** General Usage\
**Tags:** symbolic-utils\
**Created:** [August 11, 2022, 1:58am UTC](https://discourse.julialang.org/t/accessing-arguments-of-a-symbolic-expression-using-symbolicutils-jl/85600 "2022-08-11T01:58:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpieper14](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpieper14/32/37510_2.png) [@hpieper14](https://discourse.julialang.org/u/hpieper14)\
**Post date:** [August 11, 2022, 1:58am UTC](https://discourse.julialang.org/t/accessing-arguments-of-a-symbolic-expression-using-symbolicutils-jl/85600/1 "2022-08-11T01:58:53Z")

</div>

Hi everyone, I have a question about the arguments of a symbolic expression in the case it is constructed from array variables.

Suppose I have an symbolic array and I use it to construct a symbolic expression:

```nohighlight
@parameters z[1:3]
expr = toexpr(z[1] + z[2])

```

I’d like to verify that `z[1]` is the arguments of `expr` and `z[3]` is not. I did this by looping over the arguments and calling `isequal`:

```nohighlight
for arg in expr.args 
     println("z[1] in expression: ", isequal(z[1], arg))
     println("z[3] in expression: ", isequal(z[1], arg))
end

```

but the output is always false. When I look at the arguments, I see

```nohighlight
In: expr.args
Out: 3-element Vector{Any}:
 + (generic function with 741 methods)
 :((getindex)(z, 1))
 :((getindex)(z, 2))

```

I understand that the arguments are of the form `:((get index)(z, i))` since I am working with variables from a symbolic array, but I’m not sure how to relate them to the form `z[i]`. Is there a different way I should initialize the symbolic expression? I read the docs [here](https://symbolicutils.juliasymbolics.org/codegen/) and it seemed like forwarding the state `st` could be promising, but I’m not sure how to use this functionality and I couldn’t find any examples. If there are examples or documentation I missed, it would be great if someone could point me in the right direction!

Thanks so much!

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [August 11, 2022, 2:29am UTC](https://discourse.julialang.org/t/accessing-arguments-of-a-symbolic-expression-using-symbolicutils-jl/85600/2 "2022-08-11T02:29:40Z")

</div>

With the latest package versions, the `@parameters` macro doesn’t seem to exist (any more). I can write this:

```julia
using Symbolics, SymbolicUtils.Code
@variables z[1:3]
expr = toexpr(z[1] + z[2])

println("z[1] in expression: ", in(toexpr(z[1]), expr.args))
println("z[3] in expression: ", in(toexpr(z[3]), expr.args))

```

The output is

```
z[1] in expression: true
z[3] in expression: false

```

---

<div class="post-metadata">

**Author:** ![hpieper14](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpieper14/32/37510_2.png) [@hpieper14](https://discourse.julialang.org/u/hpieper14)\
**Post date:** [August 11, 2022, 12:43pm UTC](https://discourse.julialang.org/t/accessing-arguments-of-a-symbolic-expression-using-symbolicutils-jl/85600/3 "2022-08-11T12:43:47Z")

</div>

Thanks so much! I really appreciate it.

---

<div class="post-metadata">

**Author:** ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)\
**Post date:** [August 11, 2022, 1:48pm UTC](https://discourse.julialang.org/t/accessing-arguments-of-a-symbolic-expression-using-symbolicutils-jl/85600/4 "2022-08-11T13:48:10Z")

</div>

May be of interest if you are unaware, but it is possible to call `arguments(z[1] + z[2])` to get `[z[1], z[2]]`.

Also of note is `operation(z[1] + z[2])`, which will return `(+)`
