# JuMP: Register arbitary number of functions and use as constraints

**URL:** <https://discourse.julialang.org/t/jump-register-arbitary-number-of-functions-and-use-as-constraints/19692>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, loops\
**Created:** [January 16, 2019, 12:10pm UTC](https://discourse.julialang.org/t/jump-register-arbitary-number-of-functions-and-use-as-constraints/19692 "2019-01-16T12:10:35Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Marc.Cox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc.cox/32/7514_2.png) [@Marc.Cox](https://discourse.julialang.org/u/Marc.Cox)\
**Post date:** [November 11, 2020, 6:01pm UTC](https://discourse.julialang.org/t/jump-register-arbitary-number-of-functions-and-use-as-constraints/19692/4 "2020-11-11T18:01:27Z")

</div>

I was just dealing with a similar issue like “… _metaprogramming somehow. But **(NOT) using eval()**_ …”  
And the crux of the solution came from @ChrisRackauckas and @c42f who suggested **RuntimeGeneratedFunction.jl**.

A Simple MWE code for RuntimeGeneratedFunction.jl here \>\>

> [@Setting ApproxFun Space , tried several tricks but still receive \*\*ERROR: LoadError: Cannot infer spaces\*\* – specifically when using GeneralizedGenerated.jl for Generalized generated functions](https://discourse.julialang.org/t/setting-approxfun-space-tried-several-tricks-but-still-receive-error-loaderror-cannot-infer-spaces-specifically-when-using-generalizedgenerated-jl-for-generalized-generated-functions/48909/17):
>
> Thank you All for your input and insights ! You motivated me to push on until we found an answer together ! Ok so I’d like to take a swing at recapping what we’ve learned so far here … ### # Template solution motivated by @Chris\_Foster and @ChrisRackauckas Thanks Chrisss^2 slight_smile ! # .. Marc BEGIN WORKS NOW !! julia\> func\_f161 = @RuntimeGeneratedFunction(Meta.parse("f16(x) = x")) # Julia response @RuntimeGeneratedFunction( \>\> RuntimeGeneratedFunction(#=in Main=#, :((x,)-\>begin #= no…

More below :

```julia
# WORKS WAS -- f_symbolic_ans(x) = (x^3-x^2+1)
str_f_symbolic_BigD = "f_symbolic_ans(x) = (x^3-x^2+1)"
func_f_symbolic_BigD = @RuntimeGeneratedFunction(Meta.parse(str_f_symbolic_BigD))
#
f371 = ApproxFun.Fun(x->func_f_symbolic_BigD(x),Domain(r_left_x..r_right_x))

```

Also figured out my answer to "… quickly handling / **removing Inf from answers**"  
via

```julia
# Base.Generator{  
gen_iter_f2 = ( r_x for r_x in Iterators.filter( x -> ( isfinite(ApproxFun.extrapolate(f371,x)) & isfinite(ApproxFun.extrapolate(funjac_u1,x)) )
                ,range_x ) )

```

…

However @Torkel if you have “… _figured out a better approach for achieving what I wanted, without using Jump_. …”  
I’d love to know what it was, could you outline a sketch in pseudo-code or such ?

---

_[View the full topic](https://discourse.julialang.org/t/jump-register-arbitary-number-of-functions-and-use-as-constraints/19692)._
