# How to obtain val.argument of KeySet of OrderCollection?

**URL:** https://discourse.julialang.org/t/how-to-obtain-val-argument-of-keyset-of-ordercollection/123547
**Category:** General Usage
**Tags:** question
**Created:** [December 6, 2024, 4:58pm UTC](https://discourse.julialang.org/t/how-to-obtain-val-argument-of-keyset-of-ordercollection/123547 "2024-12-06T16:58:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)
#### Post date: [December 6, 2024, 4:58pm UTC](https://discourse.julialang.org/t/how-to-obtain-val-argument-of-keyset-of-ordercollection/123547/1 "2024-12-06T16:58:16Z")

</div>

Assume given

```julia
flatten(a) = collect(Iterators.flatten(a))

```

Assume furthermore given

```julia
julia> diff_eom.equations 
OrderedCollections.OrderedDict{Symbolics.Num, Symbolics.Equation} with 1 entry:
  x(t) => Differential(t)(Differential(t)(x(t))) - F*cos(t*ω) + x(t)*(ω0^2) ~ 0

```

Then the following two functions work beautifully and as a charm (stolen from HarmonicBalance.jl)

```julia
julia> keys(diff_eom.equations)
KeySet for a OrderedCollections.OrderedDict{Symbolics.Num, Symbolics.Equation} with 1 entry. Keys:
  x(t)

```

and

```julia
julia> flatten(unique([x.val.arguments for x in keys(diff_eom.equations)]))
1-element Vector{Any}:
 t

```

Assume wishing to extend this to (and later to N \>\> 1 ODEs)

```julia
julia> diff_eq
System of 2 differential equations
Variables: (x(t))[1], (x(t))[2]
Harmonic ansatz: (x(t))[1] => ; (x(t))[2] => ;   

Differential(t)(Differential(t)((x(t))[1])) - k*(x(t))[2] + (x(t))[1]*(ω0^2) ~ F*cos(t*ω)
Differential(t)(Differential(t)((x(t))[2])) - k*(x(t))[1] + (x(t))[2]*(ω0^2) ~ 0

```

Then the keys become

```julia
julia> keys(diff_eq.equations)
KeySet for a OrderedCollections.OrderedDict{Symbolics.Num, Symbolics.Equation} with 2 entries. Keys:
  (x(t))[1]
  (x(t))[2]

```

How do I get the t out in this case?

Merely repeating above is insufficient as shown below (Vector{Any} is no good sign)

```julia
julia> flatten(unique([x.val.arguments for x in keys(diff_eq.equations)]))
4-element Vector{Any}:
  x(t)
 1
  x(t)
 2

```

What is an appropriate syntax here? Thanks.

---

<div class="post-metadata">

### Author: ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)
#### Post date: [December 6, 2024, 10:05pm UTC](https://discourse.julialang.org/t/how-to-obtain-val-argument-of-keyset-of-ordercollection/123547/2 "2024-12-06T22:05:11Z")

</div>

Part of the issue is a syntax issues.

For the scalar case, this works

```julia
julia> @variables t, s(t)
2-element Vector{Symbolics.Num}:
    t
 s(t)

julia> s.val.arguments
1-element Vector{Any}:
 t

```

How do I make this work for the vector-valued case? How do I extract t from

```julia
julia> @variables t, (v(t))[1:2]
2-element Vector{Any}:
 t
  (v(t))[1:2]

```

Below does not work yet.

```julia
julia> v[1].val.arguments
2-element Vector{Any}:
  v(t)
 1

```

Thanks.

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [December 7, 2024, 6:15am UTC](https://discourse.julialang.org/t/how-to-obtain-val-argument-of-keyset-of-ordercollection/123547/3 "2024-12-07T06:15:37Z")

</div>

Try (using your last example):  
`v[1].val.arguments[1].val.arguments`

---

<div class="post-metadata">

### Author: ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)
#### Post date: [December 7, 2024, 6:40am UTC](https://discourse.julialang.org/t/how-to-obtain-val-argument-of-keyset-of-ordercollection/123547/4 "2024-12-07T06:40:36Z")

</div>

```julia
julia> v 
(v(t))[1:2]

julia> v[1].val.arguments[1].val.arguments
ERROR: type Term has no field val.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] throw_no_field(::Val{:Term}, s::Symbol)
   @ Unityper ~/.julia/packages/Unityper/BiodR/src/compactify.jl:505
 [3] getproperty(x::SymbolicUtils.BasicSymbolic{Vector{Real}}, s::Symbol)
   @ SymbolicUtils ~/.julia/packages/Unityper/BiodR/src/compactify.jl:310
 [4] top-level scope
   @ REPL[82]:1

```

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [December 7, 2024, 7:03am UTC](https://discourse.julialang.org/t/how-to-obtain-val-argument-of-keyset-of-ordercollection/123547/5 "2024-12-07T07:03:17Z")

</div>

```julia
julia> v
(v(t))[1:2]

julia> Symbolics.value(v)
v(t)

julia> arguments(Symbolics.value(v))
1-element Vector{Any}:
 t

julia> only(arguments(Symbolics.value(v)))
t

```

```julia
julia> zt
3-element Vector{Num}:
 (z(t))[1]
 (z(t))[2]
 (z(t))[3]

julia> only(arguments(arguments(Symbolics.value(zt[1]))[1]))
t

```

I don’t use Symbolics.jl but there’s probably a better way than this, but it works. You could define a function `get_farg` (or whatever) and use multiple dispatch to give convenient methods for the different forms of your symbolic variables
