## Proposal for a generalized solver

Model inversion and deterministic conditional forecast solve the same mathematical problem: solving a (non-)linear system where the identity of the unknown variables change from period to period. I suggest to create a unique function that would solve such problems.

`general_solver`

would take at least the following arguments:

- y: endogenous variables (matrix)
- x: exogenous variables (matrix) [possible concatenation of exo_det variables to the right]
- model: model (function handle)
- i_endo_flip: flip variables indices in endogenous variables (vector)
- i_exo_flip: flip variables indices in exogenous variables (vector)

### Conventions

- there are as many endogenous flip variables as exogenenous or exo det variables
- the endogenous and exogenous flip variables are in the same order (not necessary to be contiguous but may help)
- given the indices vector of flip variablesm implicit pairs of endogenous/exogenous variables are formed
- If the observation of an endogenous variable is a NaN, the endogenous variables plays it usual role of endogenous variable
- If the observation of an endogenous variables is a valid number, the endogenous variable is treated as exogenous and the corresponding flip exogenous variables is treated as endogenous
- The presence of a NaN for an endogenous variable not declared as a flip variable is an error
- The corner case of unconditional forecast should be accepted for ease of use
- The solution is written back in
`y`

and`x`

irrespective of the actual role of a variable in a given period

### Operations

`general_solver`

dispatches la résolution du nouveau problème selon

- purely backward linear model
- purely backward nonlinear model
- purely forward linear model (if we have the algorithm...)
- purely forward nonlinear model
- general linear model
- general nonlinear model
- bytecode and or block model and according to the options selecting a particular algorithm