| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 7744 |
\[\frac{a}{a \cdot 3} \cdot \frac{-3 \cdot c}{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}}
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c) :precision binary64 (let* ((t_0 (* c (* a -3.0)))) (/ (/ t_0 (+ b (sqrt (+ (* b b) t_0)))) (* a 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) {
double t_0 = c * (a * -3.0);
return (t_0 / (b + sqrt(((b * b) + t_0)))) / (a * 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
real(8) :: t_0
t_0 = c * (a * (-3.0d0))
code = (t_0 / (b + sqrt(((b * b) + t_0)))) / (a * 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) {
double t_0 = c * (a * -3.0);
return (t_0 / (b + Math.sqrt(((b * b) + t_0)))) / (a * 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): t_0 = c * (a * -3.0) return (t_0 / (b + math.sqrt(((b * b) + t_0)))) / (a * 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) t_0 = Float64(c * Float64(a * -3.0)) return Float64(Float64(t_0 / Float64(b + sqrt(Float64(Float64(b * b) + t_0)))) / Float64(a * 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) t_0 = c * (a * -3.0); tmp = (t_0 / (b + sqrt(((b * b) + t_0)))) / (a * 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_] := Block[{t$95$0 = N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 / N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := c \cdot \left(a \cdot -3\right)\\
\frac{\frac{t_0}{b + \sqrt{b \cdot b + t_0}}}{a \cdot 3}
\end{array}
Results
Initial program 52.8
Applied egg-rr54.4
Simplified52.9
[Start]54.4 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(3 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)}}{\frac{1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
|---|---|
associate-/r* [<=]54.4 | \[ \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(3 \cdot a\right) \cdot c\right)}{\left(b \cdot b - \left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right) \cdot \frac{1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}}{3 \cdot a}
\] |
*-commutative [=>]54.4 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(3 \cdot a\right)}\right)}{\left(b \cdot b - \left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right) \cdot \frac{1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
*-commutative [=>]54.4 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \color{blue}{\left(a \cdot 3\right)}\right)}{\left(b \cdot b - \left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right) \cdot \frac{1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
associate-*r/ [=>]54.4 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 3\right)\right)}{\color{blue}{\frac{\left(b \cdot b - \left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right) \cdot 1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}}{3 \cdot a}
\] |
associate--r- [=>]52.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 3\right)\right)}{\frac{\color{blue}{\left(\left(b \cdot b - b \cdot b\right) + \left(3 \cdot a\right) \cdot c\right)} \cdot 1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
*-commutative [=>]52.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 3\right)\right)}{\frac{\left(\left(b \cdot b - b \cdot b\right) + \color{blue}{c \cdot \left(3 \cdot a\right)}\right) \cdot 1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
*-commutative [=>]52.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 3\right)\right)}{\frac{\left(\left(b \cdot b - b \cdot b\right) + c \cdot \color{blue}{\left(a \cdot 3\right)}\right) \cdot 1}{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
*-commutative [=>]52.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 3\right)\right)}{\frac{\left(\left(b \cdot b - b \cdot b\right) + c \cdot \left(a \cdot 3\right)\right) \cdot 1}{b - \sqrt{b \cdot b - \color{blue}{c \cdot \left(3 \cdot a\right)}}}}}{3 \cdot a}
\] |
*-commutative [=>]52.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 3\right)\right)}{\frac{\left(\left(b \cdot b - b \cdot b\right) + c \cdot \left(a \cdot 3\right)\right) \cdot 1}{b - \sqrt{b \cdot b - c \cdot \color{blue}{\left(a \cdot 3\right)}}}}}{3 \cdot a}
\] |
Applied egg-rr52.5
Applied egg-rr0.5
Applied egg-rr0.4
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 7744 |
| Alternative 2 | |
|---|---|
| Error | 3.0 |
| Cost | 7488 |
| Alternative 3 | |
|---|---|
| Error | 3.0 |
| Cost | 960 |
| Alternative 4 | |
|---|---|
| Error | 6.2 |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Error | 6.0 |
| Cost | 320 |
herbie shell --seed 2023011
(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)))