# Generic functions with irrationals that work with Symbolics / ModelingToolkit

**URL:** <https://discourse.julialang.org/t/generic-functions-with-irrationals-that-work-with-symbolics-modelingtoolkit/83205>\
**Category:** General Usage\
**Tags:** type, modelingtoolkit, symbolics\
**Created:** [June 22, 2022, 9:39pm UTC](https://discourse.julialang.org/t/generic-functions-with-irrationals-that-work-with-symbolics-modelingtoolkit/83205 "2022-06-22T21:39:44Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)\
**Post date:** [June 24, 2022, 9:12pm UTC](https://discourse.julialang.org/t/generic-functions-with-irrationals-that-work-with-symbolics-modelingtoolkit/83205/5 "2022-06-24T21:12:32Z")

</div>

The `oftype` code above works for me, but wouldn’t work for most cases, so I’m not sure what the PR should be. A slightly more general/useful version might be

```julia
Base.convert(::Type{Num}, y::Irrational) = Symbolics.Term(identity, y)

```

But I think that’s still not what most people would want. From the discussion [here](https://github.com/JuliaSymbolics/Symbolics.jl/issues/496) (and maybe [here](https://discourse.julialang.org/t/symbolic-sqrt-2-and-sin-pi/58633/6)), it looks like people want to be able to do something like `Num(π)` and get the sensible thing, but surely it would be too much to do `Num(y::Irrational) = Term(identity, y)`, since that wouldn’t actually result in a `Num`, right?

I’m happy to do a PR if it helps move in a positive direction, but I feel like this problem calls for more thought and more knowledge of the inner workings than I have.

[But if `Term(identity, y)` is actually used, it might be worth adding a special case to [`show_term`](https://github.com/JuliaSymbolics/SymbolicUtils.jl/blob/c109aa20ac81d408f58b29c05049114f85366379/src/types.jl#L832) to just show the argument if the operation is `identity`, because \mathrm{identity}(\pi) is pretty ugly and could be confusing.]

---

_[View the full topic](https://discourse.julialang.org/t/generic-functions-with-irrationals-that-work-with-symbolics-modelingtoolkit/83205)._
