# Catalyst: weird interaction between user defined functions, arrays and Num

**URL:** <https://discourse.julialang.org/t/catalyst-weird-interaction-between-user-defined-functions-arrays-and-num/61867>\
**Category:** General Usage\
**Tags:** package, symbolic, modelingtoolkit, symbolics\
**Created:** [May 26, 2021, 4:18pm UTC](https://discourse.julialang.org/t/catalyst-weird-interaction-between-user-defined-functions-arrays-and-num/61867 "2021-05-26T16:18:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex0](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex0/32/21169_2.png) [@Alex0](https://discourse.julialang.org/u/Alex0)\
**Post date:** [May 26, 2021, 4:18pm UTC](https://discourse.julialang.org/t/catalyst-weird-interaction-between-user-defined-functions-arrays-and-num/61867/1 "2021-05-26T16:18:19Z")

</div>

Hello everyone,

I am currently trying to create a chemical network in Catalyst.jl using my own functions as reaction rates. These functions are provided species of the network as input arguments and then need to use if statements and the `floor(x)` function on them. Here is a very simplified example, which causes no error:

```julia
using Catalyst

function f(A, dummy)
    
    @show typeof(A)
    if A > 10
        out = 0
    else
        out = 1
    end
    return out
end

@register f(A, dummy)
network = @reaction_network begin

    f(A, 1), A ⇒ B
    
end

```

The ouput is the usual Latexified presentation of the single reaction.  
The problem arises when I pass arrays or tuples to my function like this:

```julia
using Catalyst

function f(A, dummy)
    
    @show typeof(A)
    if A > 10
        out = 0
    else
        out = 1
    end
    return out
end

@register f(A, dummy)
network = @reaction_network begin

    f(A, [1]), A ⇒ B
   
end

```

Then I get this error:

```julia
typeof(A) = Num
TypeError: non-boolean (Num) used in boolean context

Stacktrace:
 [1] f(::Num, ::Array{Int64,1}) at .\In[5]:6
 [2] top-level scope at In[5]:15
 [3] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

```

For some reason, if I pass an array to my function it will turn my other arguments into this `Num` data type, which comes from Symbolics.jl I think, and cant be used in logical operations. I know about the IfElse.jl package but there is no alternative/solution for the `floor(x)` function (as far as I know), which cannot use `Num` aswell.

So what I want is to just pass the arguments as `Float64` so I can do whatever I want if them.

The easiest solution of course would be to just not use arrays but pass all the arguments/species individually. But for large numbers of arguments (11-15) it takes ages to `@register` the function. The code runs forever, I dont know exactly how long it would take to register a function with 15 arguments. This “registering problem” may be worth its own post.

Maybe its noteworthy that in the first example code `typeof(A)` is not being printed, only in the second example “`typeof(A) = Num`” is being printed. I dont know what that means or if it menas something.

I feel like this interaction between arrays and `Num` is not intended. Whether I pass an array or not shouldnt change the datatype of the other arguments.

I hope I included all you guys need to know, this is my first post. Thank you !
