Simplification of Non-Linear Systems

26 views
Skip to first unread message

jesse grabowski

unread,
Dec 30, 2022, 3:00:58 PM12/30/22
to sympy
Hello everyone!

I am (trying) to use Sympy to automatically derive first order conditions and a log-linear approximation to non-linear systems of equations from user provided problem descriptions. An example system might look something like this:

-C_t - I_t + K_t-1*r_t + L_t*w_t
I_t - K_t + K_t-1*(1 - delta)
-lambda_t + C_t**(-sigma_C)
-L_t**sigma_L + lambda_t*w_t
beta*(lambda_t+1*r_t+1 + lambda_t+1*(1 - delta)) - lambda_t
A_t*K_t-1**alpha*L_t**(1 - alpha) - Y_t
alpha*A_t*K_t-1**(alpha - 1)*L_t**(1 - alpha) - r_t
A_t*K_t-1**alpha*(1 - alpha)/L_t**alpha - w_t
rho_A*log(A_t-1) + epsilon_A_t - log(A_t)

A priori I know that this particular system can be written in reduced form in only two state variables, A_t and K_t. At the bare minimum, many equations can be eliminated via substitution. For example, we clearly see that lambda_t = C_t ** (-sigma_C), and we could make that substitutions everywhere to eliminate the equation. Less obviously, I can combine equations -4, -3 and -2 to get a single expression for w_t as a function of r_t, eliminating that variable.

If the system were linear, I could easily obtain the reduced form in Sympy with something like this:

A, b = sp.linear_eq_to_matrix(system)
sp.rref(sp.hstack(A, b))

But in the non-linear case I understand there is no "nice" way to do this.

I guess I am asking if anyone knows of tricks (or better yet algorithms) to attack a problem like this? I currently use a big stack of heuristics, for example looking for equations with only 2 non-parameter atoms in the form y = f(x), then recursively making substitutions. These heuristics are quite flaky though, because I'm quite out of my depth.

Thank you to everyone for such a marvelous open source tool!

Jesse

Oscar Benjamin

unread,
Jan 21, 2023, 9:46:04 AM1/21/23
to sy...@googlegroups.com
The generalisation of the RREF (reduced row echelon form) from linear
systems of equations to polynomial systems is known as a Groebner
basis. SymPy has a function groebner that can compute this. Note
though that computing Groebner bases can be an extremely expensive
operation depending on the exact structure of your equations and the
number of symbols. It can still be used on part of your system though
and potentially also an RREF can be used for a subset of equations and
variables appearing linearly.

It's not clear to me which of the symbols in your equations are
supposed to be unknowns and which are supposed to be parameters so I
won't demonstrate how to do any of this directly. If you show complete
code to make all the symbols and also say which are the unknowns then
it might be possible for someone to suggest something.

--
Oscar
Reply all
Reply to author
Forward
0 new messages