| Alternative 1 | |
|---|---|
| Error | 5.8 |
| Cost | 1344 |
\[\frac{\frac{c \cdot \left(a \cdot -4\right)}{\frac{a}{0.5}}}{-2 \cdot \frac{c \cdot a}{b} + b \cdot 2}
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (/ (* c -2.0) (+ b (sqrt (+ (* c (* a -4.0)) (* b b))))))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
return (c * -2.0) / (b + sqrt(((c * (a * -4.0)) + (b * b))));
}
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) - ((4.0d0 * a) * c)))) / (2.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 * (-2.0d0)) / (b + sqrt(((c * (a * (-4.0d0))) + (b * b))))
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
return (c * -2.0) / (b + Math.sqrt(((c * (a * -4.0)) + (b * b))));
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
def code(a, b, c): return (c * -2.0) / (b + math.sqrt(((c * (a * -4.0)) + (b * b))))
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function code(a, b, c) return Float64(Float64(c * -2.0) / Float64(b + sqrt(Float64(Float64(c * Float64(a * -4.0)) + Float64(b * b))))) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
function tmp = code(a, b, c) tmp = (c * -2.0) / (b + sqrt(((c * (a * -4.0)) + (b * b)))); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[N[(N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\frac{c \cdot -2}{b + \sqrt{c \cdot \left(a \cdot -4\right) + b \cdot b}}
Results
Initial program 43.5
Simplified43.5
[Start]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]43.5 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{--1}{2}}{a}}
\] |
associate-*r/ [<=]43.5 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{--1}{2}}{a}}
\] |
/-rgt-identity [<=]43.5 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [<=]43.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Applied egg-rr43.0
Simplified42.9
[Start]43.0 | \[ \frac{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right) - \left(-b\right) \cdot \left(-b\right)}{\frac{a}{0.5} \cdot \left(\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right)\right)}
\] |
|---|---|
associate-/r* [=>]43.0 | \[ \color{blue}{\frac{\frac{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right) - \left(-b\right) \cdot \left(-b\right)}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right)}}
\] |
fma-def [<=]42.9 | \[ \frac{\frac{\color{blue}{\left(b \cdot b + \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right) \cdot \left(-b\right)}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right)}
\] |
+-commutative [=>]42.9 | \[ \frac{\frac{\color{blue}{\left(\left(a \cdot c\right) \cdot -4 + b \cdot b\right)} - \left(-b\right) \cdot \left(-b\right)}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right)}
\] |
*-commutative [=>]42.9 | \[ \frac{\frac{\left(\color{blue}{\left(c \cdot a\right)} \cdot -4 + b \cdot b\right) - \left(-b\right) \cdot \left(-b\right)}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right)}
\] |
fma-def [=>]42.9 | \[ \frac{\frac{\color{blue}{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - \left(-b\right) \cdot \left(-b\right)}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right)}
\] |
sqr-neg [=>]42.9 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - \color{blue}{b \cdot b}}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - \left(-b\right)}
\] |
fma-def [<=]42.9 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{\frac{a}{0.5}}}{\sqrt{\color{blue}{b \cdot b + \left(a \cdot c\right) \cdot -4}} - \left(-b\right)}
\] |
+-commutative [=>]42.9 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{\frac{a}{0.5}}}{\sqrt{\color{blue}{\left(a \cdot c\right) \cdot -4 + b \cdot b}} - \left(-b\right)}
\] |
*-commutative [=>]42.9 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{\frac{a}{0.5}}}{\sqrt{\color{blue}{\left(c \cdot a\right)} \cdot -4 + b \cdot b} - \left(-b\right)}
\] |
fma-def [=>]42.9 | \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right) - b \cdot b}{\frac{a}{0.5}}}{\sqrt{\color{blue}{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}} - \left(-b\right)}
\] |
Taylor expanded in c around 0 0.2
Simplified0.2
[Start]0.2 | \[ \frac{\frac{-4 \cdot \left(c \cdot a\right)}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - \left(-b\right)}
\] |
|---|---|
*-commutative [=>]0.2 | \[ \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot -4}}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - \left(-b\right)}
\] |
associate-*r* [<=]0.2 | \[ \frac{\frac{\color{blue}{c \cdot \left(a \cdot -4\right)}}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - \left(-b\right)}
\] |
*-commutative [=>]0.2 | \[ \frac{\frac{c \cdot \color{blue}{\left(-4 \cdot a\right)}}{\frac{a}{0.5}}}{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - \left(-b\right)}
\] |
Applied egg-rr0.2
Taylor expanded in c around 0 0.2
Simplified0.2
[Start]0.2 | \[ \frac{-2 \cdot c}{\sqrt{c \cdot \left(a \cdot -4\right) + b \cdot b} - \left(-b\right)}
\] |
|---|---|
*-commutative [=>]0.2 | \[ \frac{\color{blue}{c \cdot -2}}{\sqrt{c \cdot \left(a \cdot -4\right) + b \cdot b} - \left(-b\right)}
\] |
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 5.8 |
| Cost | 1344 |
| Alternative 2 | |
|---|---|
| Error | 5.9 |
| Cost | 832 |
| Alternative 3 | |
|---|---|
| Error | 12.2 |
| Cost | 256 |
| Alternative 4 | |
|---|---|
| Error | 63.0 |
| Cost | 192 |
herbie shell --seed 2023011
(FPCore (a b c)
:name "Quadratic roots, 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) (* (* 4.0 a) c)))) (* 2.0 a)))