| Alternative 1 | |
|---|---|
| Error | 5.6 |
| Cost | 832 |
(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 43.9
Simplified43.9
[Start]43.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]43.9 | \[ \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 [<=]43.9 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]44.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 [=>]44.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/ [<=]44.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 [=>]44.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 [=>]43.1 | \[ \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 [<=]43.1 | \[ \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 [<=]43.1 | \[ \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* [<=]43.1 | \[ \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 [<=]43.1 | \[ \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 [<=]43.1 | \[ \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 [<=]44.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 [=>]44.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-rr43.3
Simplified43.3
[Start]43.3 | \[ \frac{-0.3333333333333333}{\frac{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
|---|---|
associate-/l* [<=]43.3 | \[ \color{blue}{\frac{-0.3333333333333333 \cdot \left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
*-commutative [=>]43.3 | \[ \frac{\color{blue}{\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)}
\] |
associate-*l/ [<=]43.3 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)} \cdot -0.3333333333333333}
\] |
*-commutative [=>]43.3 | \[ \color{blue}{-0.3333333333333333 \cdot \frac{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
associate-/r* [=>]43.3 | \[ -0.3333333333333333 \cdot \color{blue}{\frac{\frac{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
Taylor expanded in b around 0 0.5
Applied egg-rr40.0
Simplified0.2
[Start]40.0 | \[ e^{\mathsf{log1p}\left(-0.3333333333333333 \cdot \frac{3 \cdot c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)} - 1
\] |
|---|---|
expm1-def [=>]10.3 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-0.3333333333333333 \cdot \frac{3 \cdot c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)\right)}
\] |
expm1-log1p [=>]0.5 | \[ \color{blue}{-0.3333333333333333 \cdot \frac{3 \cdot c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
*-commutative [=>]0.5 | \[ \color{blue}{\frac{3 \cdot c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \cdot -0.3333333333333333}
\] |
associate-*r/ [<=]0.4 | \[ \color{blue}{\left(3 \cdot \frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right)} \cdot -0.3333333333333333
\] |
metadata-eval [<=]0.4 | \[ \left(\color{blue}{\frac{-3}{-1}} \cdot \frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right) \cdot -0.3333333333333333
\] |
times-frac [<=]0.5 | \[ \color{blue}{\frac{-3 \cdot c}{-1 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}} \cdot -0.3333333333333333
\] |
*-commutative [<=]0.5 | \[ \frac{\color{blue}{c \cdot -3}}{-1 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)} \cdot -0.3333333333333333
\] |
neg-mul-1 [<=]0.5 | \[ \frac{c \cdot -3}{\color{blue}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}} \cdot -0.3333333333333333
\] |
associate-/r/ [<=]0.5 | \[ \color{blue}{\frac{c \cdot -3}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{-0.3333333333333333}}}
\] |
associate-/l* [=>]0.4 | \[ \color{blue}{\frac{c}{\frac{\frac{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{-0.3333333333333333}}{-3}}}
\] |
associate-/l/ [=>]0.2 | \[ \frac{c}{\color{blue}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{-3 \cdot -0.3333333333333333}}}
\] |
metadata-eval [=>]0.2 | \[ \frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{\color{blue}{1}}}
\] |
/-rgt-identity [=>]0.2 | \[ \frac{c}{\color{blue}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
distribute-neg-in [=>]0.2 | \[ \frac{c}{\color{blue}{\left(-b\right) + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
unsub-neg [=>]0.2 | \[ \frac{c}{\color{blue}{\left(-b\right) - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
Applied egg-rr0.2
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 5.6 |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Error | 12.0 |
| Cost | 320 |
herbie shell --seed 2023187
(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)))