Skip to content

Commit f8deda6

Browse files
Merge pull request #1239 from SciML/ChrisRackauckas-patch-3
Document in FAQ the handling of ifelse, booleans, and registration
2 parents c3d6105 + 4b02343 commit f8deda6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/src/basics/FAQ.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ lowered array? You can use the internal function `varmap_to_vars`. For example:
2121
```julia
2222
pnew = varmap_to_vars([β=>3.0, c=>10.0, γ=>2.0],parameters(sys))
2323
```
24+
25+
## How do I handle `if` statements in my symbolic forms?
26+
27+
For statements that are in the `if then else` form, use `IfElse.ifelse` from the
28+
[IfElse.jl](https://github.com/SciML/IfElse.jl) package to represent the code in a
29+
functional form. For handling direct `if` statements, you can use equivalent boolean
30+
mathematical expressions. For example `if x > 0 ...` can be implementated as just
31+
`(x > 0) * `, where if `x <= 0` then the boolean will evaluate to `0` and thus the
32+
term will be excluded from the model.
33+
34+
## ERROR: TypeError: non-boolean (Num) used in boolean context?
35+
36+
If you see the error:
37+
38+
```julia
39+
ERROR: TypeError: non-boolean (Num) used in boolean context
40+
```
41+
42+
then it's likely you are trying to trace through a function which cannot be
43+
directly represented in Julia symbols. The techniques to handle this problem,
44+
such as `@register`, are described in detail
45+
[in the Symbolics.jl documentation](https://symbolics.juliasymbolics.org/dev/manual/faq/#Transforming-my-function-to-a-symbolic-equation-has-failed.-What-do-I-do?-1).

0 commit comments

Comments
 (0)