# Extending Symbolics.jl, How to dispatch all functions to the underlying Num

**URL:** https://discourse.julialang.org/t/extending-symbolics-jl-how-to-dispatch-all-functions-to-the-underlying-num/106845
**Category:** Modelling & Simulations
**Tags:** question, package, sciml, symbolics
**Created:** [November 28, 2023, 12:29pm UTC](https://discourse.julialang.org/t/extending-symbolics-jl-how-to-dispatch-all-functions-to-the-underlying-num/106845 "2023-11-28T12:29:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Qfl3x](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qfl3x/32/16227_2.png) [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)
#### Post date: [November 28, 2023, 12:29pm UTC](https://discourse.julialang.org/t/extending-symbolics-jl-how-to-dispatch-all-functions-to-the-underlying-num/106845/1 "2023-11-28T12:29:23Z")

</div>

Hello, I want to extend Symbolics.jl Variables to encode bounds and default value of parameters in the “variable”; Currently something like this:

```julia
using Symbolics: _parse_vars, Num, @variables

import SciMLBase: issymbollike

import Base: +, -, *, /

struct Parameter
    var::Num
    lower::Real
    upper::Real
    default::Real
end

# Extended Functions:
Base.:+(p::Parameter, x::Any) = Base.:+(p.var, x)
Base.:-(p::Parameter, x::Any) = Base.:-(p.var, x)
Base.:/(p::Parameter, x::Any) = Base.:/(p.var, x)
Base.:*(p::Parameter, x::Any) = Base.:*(p.var, x)

issymbollike(::Parameter) = true

macro parameter(x, lower, upper, default)
    var = (@variables $x)[1]
    esc(Parameter(var, lower, upper, default))
end

function bounds(p::Parameter)
    return (p.lower, p.upper)
end

```

I want all functions (except a few pre-determined ones like `bounds`) to act directly on `p.var` without having to extend everything by hand like the `Base.:` block.

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [November 28, 2023, 12:34pm UTC](https://discourse.julialang.org/t/extending-symbolics-jl-how-to-dispatch-all-functions-to-the-underlying-num/106845/2 "2023-11-28T12:34:17Z")

</div>

Maybe you could get some inspiration from here which already implemented bounds [Symbolic Metadata · ModelingToolkit.jl (sciml.ai)](https://docs.sciml.ai/ModelingToolkit/stable/basics/Variable_metadata/).

---

<div class="post-metadata">

### Author: ![Qfl3x](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qfl3x/32/16227_2.png) [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)
#### Post date: [November 28, 2023, 1:34pm UTC](https://discourse.julialang.org/t/extending-symbolics-jl-how-to-dispatch-all-functions-to-the-underlying-num/106845/3 "2023-11-28T13:34:13Z")

</div>

That should do!

Though I may need “mandatory” metadata for my case, will see how it goes.
