# Build\_function: stack overflow in type inference

**URL:** <https://discourse.julialang.org/t/build-function-stack-overflow-in-type-inference/109971>\
**Category:** Modelling & Simulations\
**Created:** [February 9, 2024, 8:46am UTC](https://discourse.julialang.org/t/build-function-stack-overflow-in-type-inference/109971 "2024-02-09T08:46:29Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Johan-Gronqvist](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johan-gronqvist/32/29895_2.png) [@Johan-Gronqvist](https://discourse.julialang.org/u/Johan-Gronqvist)\
**Post date:** [February 9, 2024, 12:43pm UTC](https://discourse.julialang.org/t/build-function-stack-overflow-in-type-inference/109971/4 "2024-02-09T12:43:01Z")

</div>

I have tried using symbolic arrays and symbolic array expressions, but I had problems [1] where `substitute` and `build_function` both failed to replace all occurences of the variables, and I therefore started to `scalarize` my expressions to obtain correct results.

I now sometimes define symbolic arrays, but I always scalarize them before using them in mathematical operations.

By the way, I never spent enough time debugging my issues with symbolic arrays, but I think some may have been related to `getindex` expressions like `(broadcast(-, K))[1, 2]` perhaps being considered non-composite expressions, due to [2].

[1] [Symbolics build\_function issues on complicated expressions](https://discourse.julialang.org/t/symbolics-build-function-issues-on-complicated-expressions/109727)

[2] In Symbolics.jl, in the file `utils.jl`, getindex operations are all treated the same, regardless of the complexity of the argument to `getindex`, in the following function.

```julia
function is_singleton(e)
    if istree(e)
        op = operation(e)
        op === getindex && return true
        istree(op) && return is_singleton(op) # recurse to reach getindex for array element variables
        return issym(op)
    else
        return issym(e)
    end
end

```

---

_[View the full topic](https://discourse.julialang.org/t/build-function-stack-overflow-in-type-inference/109971)._
