| Alternative 1 | |
|---|---|
| Error | 2.6 |
| Cost | 7424 |
\[\frac{c \cdot -0.5}{b} + \left(c \cdot \left(c \cdot \frac{a}{{b}^{3}}\right)\right) \cdot -0.375
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c) :precision binary64 (* -0.3333333333333333 (/ (+ (* a (* 3.0 c)) (* 0.0 (* b b))) (* a (+ 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 -0.3333333333333333 * (((a * (3.0 * c)) + (0.0 * (b * b))) / (a * (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 = (-0.3333333333333333d0) * (((a * (3.0d0 * c)) + (0.0d0 * (b * b))) / (a * (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 -0.3333333333333333 * (((a * (3.0 * c)) + (0.0 * (b * b))) / (a * (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 -0.3333333333333333 * (((a * (3.0 * c)) + (0.0 * (b * b))) / (a * (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(-0.3333333333333333 * Float64(Float64(Float64(a * Float64(3.0 * c)) + Float64(0.0 * Float64(b * b))) / Float64(a * 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 = -0.3333333333333333 * (((a * (3.0 * c)) + (0.0 * (b * b))) / (a * (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[(-0.3333333333333333 * N[(N[(N[(a * N[(3.0 * c), $MachinePrecision]), $MachinePrecision] + N[(0.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
-0.3333333333333333 \cdot \frac{a \cdot \left(3 \cdot c\right) + 0 \cdot \left(b \cdot b\right)}{a \cdot \left(b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right)}
Results
Initial program 53.1
Simplified53.1
[Start]53.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]53.1 | \[ \frac{\left(-b\right) + \color{blue}{\left(-\left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)\right)}}{3 \cdot a}
\] |
sub-neg [<=]53.1 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]53.2 | \[ \color{blue}{\frac{-b}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
neg-mul-1 [=>]53.2 | \[ \frac{\color{blue}{-1 \cdot b}}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
associate-*l/ [<=]53.0 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot b} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
distribute-frac-neg [=>]53.0 | \[ \frac{-1}{3 \cdot a} \cdot b - \color{blue}{\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
fma-neg [=>]52.2 | \[ \color{blue}{\mathsf{fma}\left(\frac{-1}{3 \cdot a}, b, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)}
\] |
/-rgt-identity [<=]52.2 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b}{1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
metadata-eval [<=]52.2 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{b}{\color{blue}{\frac{-1}{-1}}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
associate-/l* [<=]52.2 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b \cdot -1}{-1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
*-commutative [<=]52.2 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-1 \cdot b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
neg-mul-1 [<=]52.2 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
fma-neg [<=]53.0 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
neg-mul-1 [=>]53.0 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{-1 \cdot \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
Applied egg-rr52.8
Applied egg-rr53.0
Simplified0.6
[Start]53.0 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{b}} + \frac{-0.3333333333333333}{a} \cdot \left(-\frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)
\] |
|---|---|
distribute-rgt-neg-out [=>]53.0 | \[ \frac{-0.3333333333333333}{a} \cdot \frac{b}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{b}} + \color{blue}{\left(-\frac{-0.3333333333333333}{a} \cdot \frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)}
\] |
sub-neg [<=]53.0 | \[ \color{blue}{\frac{-0.3333333333333333}{a} \cdot \frac{b}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{b}} - \frac{-0.3333333333333333}{a} \cdot \frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
*-commutative [=>]53.0 | \[ \color{blue}{\frac{b}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{b}} \cdot \frac{-0.3333333333333333}{a}} - \frac{-0.3333333333333333}{a} \cdot \frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-/r/ [=>]53.0 | \[ \color{blue}{\left(\frac{b}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot b\right)} \cdot \frac{-0.3333333333333333}{a} - \frac{-0.3333333333333333}{a} \cdot \frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*l/ [=>]53.0 | \[ \color{blue}{\frac{b \cdot b}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}} \cdot \frac{-0.3333333333333333}{a} - \frac{-0.3333333333333333}{a} \cdot \frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-/r/ [<=]52.7 | \[ \color{blue}{\frac{b \cdot b}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}} - \frac{-0.3333333333333333}{a} \cdot \frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
*-commutative [=>]52.7 | \[ \frac{b \cdot b}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}} - \color{blue}{\frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot \frac{-0.3333333333333333}{a}}
\] |
associate-/r/ [<=]52.9 | \[ \frac{b \cdot b}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}} - \color{blue}{\frac{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{-0.3333333333333333}{a}}}}
\] |
Applied egg-rr0.6
Final simplification0.6
| Alternative 1 | |
|---|---|
| Error | 2.6 |
| Cost | 7424 |
| Alternative 2 | |
|---|---|
| Error | 2.9 |
| Cost | 1216 |
| Alternative 3 | |
|---|---|
| Error | 58.4 |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Error | 5.9 |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Error | 5.7 |
| Cost | 320 |
herbie shell --seed 2023060
(FPCore (a b c)
:name "Cubic critical, wide range"
:precision binary64
:pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))