Inverting a matrix of symbolic equations

I’d like to invert a 4x4 matrix of symbolic equations.

I’m able to successfully invert a matrix of symbolic expressions like this:

using Symbolics
using LinearAlgebra
@variables x y[1:16] z
Symbolics.scalarize(y)

eq11 = x
eq12 = x^2
eq13 = x+15
eq14 = cos(x)
eq21 = log(x)
eq22 = sqrt(x)
eq23 = x^3
eq24 = -x
eq31 = 1/x
eq32 = (x+4)^3
eq33 = 69*x
eq34 = 42
eq41 = 14/x
eq42 = x^(3/5)
eq43 = sin(x)
eq44 = csc(x)

M = [eq11 eq12 eq13 eq14;
     eq21 eq22 eq23 eq24;
     eq31 eq32 eq33 eq34;
     eq41 eq42 eq43 eq44]

inv(M)

but if I change the expressions to equations

eq11 = y[1] ~ x
eq12 = y[2] ~ x^2
eq13 = y[3] ~ x+15
eq14 = y[4] ~ cos(x)
eq21 = y[5] ~ log(x)
eq22 = y[6] ~ sqrt(x)
eq23 = y[7] ~ x^3
eq24 = y[8] ~ -x
eq31 = y[9] ~ 1/x
eq32 = y[10] ~ (x+4)^3
eq33 = y[11] ~ 69*x
eq34 = y[12] ~ 42
eq41 = y[13] ~ 14/x
eq42 = y[14] ~ x^(3/5)
eq43 = y[15] ~ sin(x)
eq44 = y[16] ~ csc(x)

the inversion fails.

Is there a way around this?

What is the inverse of a single equation like a = b?

If =(a, b) is a function that maps two numbers to a boolean, then =^{-1}(c) should be a function that takes a boolean c and returns (the) two numbers for which =(a, b) = c. It will not in general be well-defined since the equality operator cannot be bijective by the pidgeonhole principle, but if we settle for an inverse then maybe

julia> ==⁻¹(c) = (1, Int(c))
==⁻¹ (generic function with 1 method)

julia> ==⁻¹(true)
(1, 1)

julia> ==⁻¹(false)
(1, 0)

could be an acceptable implementation.

Arguably, the inverse of an equation is the tuple (LHS, RHS):

julia> macro eqinv(ex)
    return esc(:(($(ex.args[2]), $(ex.args[3]))))
end;
julia> a = 2; b = 4;
julia> @eqinv a==b
(2, 4)
julia> ==(@eqinv(a==b)...)
false
julia> ==(@eqinv(a==a)...)
true

i.e. the inverted function (macro) “undoes” the original. Can’t imagine this is very useful though.

Sure, open an issue. But this is… really weird :sweat_smile: . I’m not sure of a use case where you wouldn’t just invert the matrix of expressions instead of equations, so I don’t think it would get prioritized without a clear idea of a use case.

Yeah I can almost guarantee my solutions are not what op wants.

Almost. I’ve seen odder requests.