Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve factoring for square roots #23

Open
fredrik-johansson opened this issue Apr 25, 2021 · 1 comment
Open

Improve factoring for square roots #23

fredrik-johansson opened this issue Apr 25, 2021 · 1 comment

Comments

@fredrik-johansson
Copy link
Collaborator

fredrik-johansson commented Apr 25, 2021

Composing matrix exponentials and logarithms is a good way to find expressions that don't simplify:

>>> ca_mat([[1,-1],[-1,-1]]).exp().log()
ca_mat of size 2 x 2
[1.00000 {(-b*d*f+b*e*f)/(2*c) where a = 1.41421 [Log(4.11325 {(c+d+e)/2})], b = -1.41421 [Log(0.243117 {(-c+d+e)/2})], c = 3.87013 [Sqrt(14.9779 {d^2+e^2-2})], d = 4.11325 [Exp(1.41421 {f})], e = 0.243117 [Exp(-1.41421 {-f})], f = 1.41421 [f^2-2=0]}, -1.00000 {(b*d^2+b*e^2-2*b)/(c*d*f-c*e*f) where a = 1.41421 [Log(4.11325 {(c+d+e)/2})], b = -1.41421 [Log(0.243117 {(-c+d+e)/2})], c = 3.87013 [Sqrt(14.9779 {d^2+e^2-2})], d = 4.11325 [Exp(1.41421 {f})], e = 0.243117 [Exp(-1.41421 {-f})], f = 1.41421 [f^2-2=0]}]
[-1.00000 {(b*d*f-b*e*f)/(2*c) where a = 1.41421 [Log(4.11325 {(c+d+e)/2})], b = -1.41421 [Log(0.243117 {(-c+d+e)/2})], c = 3.87013 [Sqrt(14.9779 {d^2+e^2-2})], d = 4.11325 [Exp(1.41421 {f})], e = 0.243117 [Exp(-1.41421 {-f})], f = 1.41421 [f^2-2=0]},             -1.00000 {(b*d*f-b*e*f)/(2*c) where a = 1.41421 [Log(4.11325 {(c+d+e)/2})], b = -1.41421 [Log(0.243117 {(-c+d+e)/2})], c = 3.87013 [Sqrt(14.9779 {d^2+e^2-2})], d = 4.11325 [Exp(1.41421 {f})], e = 0.243117 [Exp(-1.41421 {-f})], f = 1.41421 [f^2-2=0]}]

This is the problem:

>>> a = exp(2*sqrt(2))
>>> b = exp(-2*sqrt(2))
>>> sqrt(a+b-2); sqrt(a+1/a-2)
3.87013 {a where a = 3.87013 [Sqrt(14.9779 {b+c-2})], b = 16.9188 [Exp(2.82843 {2*d})], c = 0.0591057 [Exp(-2.82843 {-2*d})], d = 1.41421 [d^2-2=0]}
3.87013 {(a*b-a)/(b) where a = 4.11325 [Sqrt(16.9188 {b})], b = 16.9188 [Exp(2.82843 {2*c})], c = 1.41421 [c^2-2=0]}
>>> 
>>> sqrt(a+b-2) - (a-1)/sqrt(a)
0e-1125 {(a*b-c+1)/(b) where a = 3.87013 [Sqrt(14.9779 {c+d-2})], b = 4.11325 [Sqrt(16.9188 {c})], c = 16.9188 [Exp(2.82843 {2*e})], d = 0.0591057 [Exp(-2.82843 {-2*e})], e = 1.41421 [e^2-2=0]}
>>> 
>>> sqrt(a+1/a-2) - (a-1)/sqrt(a)
0

a+b-2 does not factor, though the equivalent rational function a+1/a-2 does.

The factoring algorithm for field elements somehow needs to be made aware of this. A possibility is to look specifically for exponentials to eliminate, but perhaps there's a more general approach.

@fredrik-johansson
Copy link
Collaborator Author

Another useful example of (lack of) rational function simplification:

>>> (pi-1) / (sqrt(pi) - 1); sqrt(pi) + 1
2.77245 {(b-1)/(a-1) where a = 1.77245 [Sqrt(3.14159 {b})], b = 3.14159 [Pi]}
2.77245 {a+1 where a = 1.77245 [Sqrt(3.14159 {b})], b = 3.14159 [Pi]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant