| Alternative 1 | |
|---|---|
| Accuracy | 90.9% |
| Cost | 832 |
\[\frac{c}{1.5 \cdot \frac{c \cdot a}{b} + b \cdot -2}
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c) :precision binary64 (/ c (- (- b) (sqrt (+ (* b b) (* a (* c -3.0)))))))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
return c / (-b - sqrt(((b * b) + (a * (c * -3.0)))));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / (-b - sqrt(((b * b) + (a * (c * (-3.0d0))))))
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
public static double code(double a, double b, double c) {
return c / (-b - Math.sqrt(((b * b) + (a * (c * -3.0)))));
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c): return c / (-b - math.sqrt(((b * b) + (a * (c * -3.0)))))
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function code(a, b, c) return Float64(c / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -3.0)))))) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
function tmp = code(a, b, c) tmp = c / (-b - sqrt(((b * b) + (a * (c * -3.0))))); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(c / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{c}{\left(-b\right) - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}}
Results
Initial program 31.5%
Simplified31.5%
[Start]31.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]31.5 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]31.5 | \[ \color{blue}{\frac{-1}{-1}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
times-frac [<=]31.5 | \[ \color{blue}{\frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{-1 \cdot \left(3 \cdot a\right)}}
\] |
neg-mul-1 [<=]31.5 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{-3 \cdot a}}
\] |
distribute-rgt-neg-in [=>]31.5 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{3 \cdot \left(-a\right)}}
\] |
times-frac [=>]31.5 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]31.5 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Applied egg-rr32.4%
Simplified32.4%
[Start]32.4 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot -0.3333333333333333}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
|---|---|
times-frac [=>]32.4 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{a} \cdot \frac{-0.3333333333333333}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
Taylor expanded in b around 0 99.1%
Applied egg-rr37.0%
Simplified99.7%
[Start]37.0 | \[ e^{\mathsf{log1p}\left(\frac{-1 \cdot \frac{c \cdot a}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)} - 1
\] |
|---|---|
expm1-def [=>]84.2 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1 \cdot \frac{c \cdot a}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)\right)}
\] |
expm1-log1p [=>]99.6 | \[ \color{blue}{\frac{-1 \cdot \frac{c \cdot a}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
associate-*r/ [=>]99.6 | \[ \frac{\color{blue}{\frac{-1 \cdot \left(c \cdot a\right)}{a}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
*-commutative [<=]99.6 | \[ \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot -1}}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-/r* [<=]99.4 | \[ \color{blue}{\frac{\left(c \cdot a\right) \cdot -1}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
*-commutative [=>]99.4 | \[ \frac{\color{blue}{-1 \cdot \left(c \cdot a\right)}}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
neg-mul-1 [<=]99.4 | \[ \frac{\color{blue}{-c \cdot a}}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
distribute-frac-neg [=>]99.4 | \[ \color{blue}{-\frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
mul-1-neg [<=]99.4 | \[ \color{blue}{-1 \cdot \frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
metadata-eval [<=]99.4 | \[ \color{blue}{\frac{1}{-1}} \cdot \frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
times-frac [<=]99.4 | \[ \color{blue}{\frac{1 \cdot \left(c \cdot a\right)}{-1 \cdot \left(a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}
\] |
*-commutative [=>]99.4 | \[ \frac{\color{blue}{\left(c \cdot a\right) \cdot 1}}{-1 \cdot \left(a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}
\] |
times-frac [=>]99.3 | \[ \color{blue}{\frac{c \cdot a}{-1} \cdot \frac{1}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
associate-/r* [=>]99.3 | \[ \frac{c \cdot a}{-1} \cdot \color{blue}{\frac{\frac{1}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
times-frac [<=]99.4 | \[ \color{blue}{\frac{\left(c \cdot a\right) \cdot \frac{1}{a}}{-1 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
Applied egg-rr99.7%
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 90.9% |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Accuracy | 80.9% |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Accuracy | 80.9% |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 320 |
herbie shell --seed 2023129
(FPCore (a b c)
:name "Cubic critical, medium range"
:precision binary64
:pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))