# Custom simplifying of ModelingToolkit ODESystem equations

**URL:** https://discourse.julialang.org/t/custom-simplifying-of-modelingtoolkit-odesystem-equations/80531
**Category:** Modelling & Simulations
**Tags:** modelingtoolkit, symbolics
**Created:** [May 5, 2022, 9:18am UTC](https://discourse.julialang.org/t/custom-simplifying-of-modelingtoolkit-odesystem-equations/80531 "2022-05-05T09:18:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jedforrest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jedforrest/32/37502_2.png) [@jedforrest](https://discourse.julialang.org/u/jedforrest)
#### Post date: [May 5, 2022, 9:18am UTC](https://discourse.julialang.org/t/custom-simplifying-of-modelingtoolkit-odesystem-equations/80531/1 "2022-05-05T09:18:16Z")

</div>

When converting my `ODESystem` into an `ODEProblem` to be solved, I find that the full equations are not simplified enough, leading to numerical errors. In particular, one part of the equations looks like this:

```julia
Differential(t)(X(t)) ~ exp(a * log(b * X(t)))

```

This `log(...)` is causing problems with negative values, when really this can be simplified to `(b * X(t))^a` so that there aren’t any domain issues.

I found I can simplify the symbolic equations further using a symbolic rewriter from [SymbolicUtils.jl](https://symbolicutils.juliasymbolics.org/rewrite/). However, I’m not sure what to do from here.

Can I structurally simplify the ODESystem with my own additional rules, or can I supply my own equations to the solver?

Thanks

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [May 5, 2022, 9:40am UTC](https://discourse.julialang.org/t/custom-simplifying-of-modelingtoolkit-odesystem-equations/80531/2 "2022-05-05T09:40:16Z")

</div>

The simplification you propose is only valid if you know that the argument of log is positive, hence it cannot be done automatically without this knowledge.

You could write your own simplification pass like you say that modifies the equations in the system. Simply run your pass on the equations and create a new ODESystem using the simplified equations
