Skip to content

Handling ssqrt and scbrt returned from symbolic_solve #1354

Open
@akirakyle

Description

@akirakyle

I was playing around with the exciting developments landed in #1192 and noticed some peculiarities.

First cosider this example:

using Symbolics, Groebner, Nemo, Latexify, LinearAlgebra

@variables A[1:2, 1:2], λ
char_poly = det(Num.(collect(A-λ*one(A))))
sol = symbolic_solve(char_poly, λ);
simplify(*((λ .- sol)...) - char_poly; expand=true)

which gives me

$$\frac{1}{4} \left( A_{1,1}^{2} + A_{2,2}^{2} \right) - \frac{1}{2} A_{1,1} A_{2,2} + A_{1,2} A_{2,1} - \frac{1}{4} \left( ssqrt\left( A_{1,1}^{2} - 2 A_{1,1} A_{2,2} + 4 A_{1,2} A_{2,1} + A_{2,2}^{2} \right) \right)^{2}$$

As I understand (although would be good to put somewhere in the docs), the ssqrt function was introduced to handle negative arguments without raising errors. Thus I would expect sqrt(x)^2 = x would be a valid rule to have applied by simplify? If I add a rule to rewrite ssqrt to be a power instead I get the expected simplification so the following gives zero as expected.

@variables A[1:2, 1:2], λ
char_poly = det(Num.(collect(A-λ*one(A))))
sol = symbolic_solve(char_poly, λ);
r = @rule Symbolics.ssqrt(~x) => (~x)^(1//2)
sol = simplify.(sol; rewriter=RuleSet([r]))
simplify(*((λ .- sol)...) - char_poly; expand=true)

I then went to try this strategy of checking symbolic_solve with a generic third order characteristic polynomial and it seemed to fail to simplify

@variables A[1:3, 1:3], λ
char_poly = det(Num.(collect(A-λ*one(A))))
sol = symbolic_solve(char_poly, λ);
r1 = @rule Symbolics.ssqrt(~x) => (~x)^(1//2)
r2 = @rule Symbolics.scbrt(~x) => (~x)^(1//3)
sol = simplify.(sol; rewriter=RuleSet([r1, r2]))
simplify(*((λ .- sol)...) - char_poly; expand=true)

The output is far to long to paste here, but it looks like there are floating point coefficients introduced at some point which might be why it fails to simplify to zero?

I was hoping to use the new symbolic_solve to find the eigenvalues of small symbolic matrices so this was my first test to make sure I was understanding how to work with the output of symbolic_solve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions