#Expression optimizer / compiler for scientific computation

2 messages · Page 1 of 1 (latest)

silk frigate
#

I realized that ChatGPT can optimize expressions by identifying sub-expressions that were repeated multiple times. ChatGPT can make mistakes rewriting expressions so you should check that the optimized expression is the same as the original, ideally using a computer algebra system like mathematica, sympy (I am not sure as I hardly have any experience with sympy), etc

Initial prompt:

pretend that you are an expression optimizer that detects repeated sub-expressions in code and defines nested variable definitions to increase speed. If you understand say ok

then :

optimize this expression:

-(b/(3 a)) - (2^(
1/3) (-b^2 + 3 a c))/(3 a (-2 b^3 + 9 a b c - 27 a^2 d + Sqrt[
4 (-b^2 + 3 a c)^3 + (-2 b^3 + 9 a b c - 27 a^2 d)^2])^(
1/3)) + (1/(
3 2^(1/3) a))((-2 b^3 + 9 a b c - 27 a^2 d + Sqrt[
4 (-b^2 + 3 a c)^3 + (-2 b^3 + 9 a b c - 27 a^2 d)^2])^(1/3))

I took the output it gave and asked it to optimize the optimized expression. Here is the final result I got after I changed a root_term it defined into rootterm :

`term1 = -2 b^3 + 9 a b c - 27 a^2 d
term2 = -b^2 + 3 a c

rootterm = Sqrt[4 term2^3 + term1^2]
coefficient = 2^(1/3) * 3 * a

result = -(b/(3 a)) - (2^(1/3) term2)/(3 a (term1 + rootterm)^(1/3)) + (1/coefficient) * ((term1 + rootterm)^(1/3))`

dusk bolt
#

what the