| Alternative 1 | |
|---|---|
| Accuracy | 84.9% |
| Cost | 7688 |

(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e-83)
(/ (- c) b)
(if (<= b 5e+83)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))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) {
double tmp;
if (b <= -5.2e-83) {
tmp = -c / b;
} else if (b <= 5e+83) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
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
real(8) :: tmp
if (b <= (-5.2d-83)) then
tmp = -c / b
else if (b <= 5d+83) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = (c / b) - (b / a)
end if
code = tmp
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) {
double tmp;
if (b <= -5.2e-83) {
tmp = -c / b;
} else if (b <= 5e+83) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
def code(a, b, c): tmp = 0 if b <= -5.2e-83: tmp = -c / b elif b <= 5e+83: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-83) tmp = Float64(Float64(-c) / b); elseif (b <= 5e+83) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e-83) tmp = -c / b; elseif (b <= 5e+83) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -5.2e-83], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5e+83], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{-83}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+83}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 51.2% |
|---|---|
| Target | 70.4% |
| Herbie | 84.9% |
if b < -5.20000000000000018e-83Initial program 16.4%
Simplified16.5%
[Start]16.4% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]16.4% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]16.4% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
associate-/l* [=>]16.5% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2}{\frac{--1}{a}}}}
\] |
associate-/r/ [=>]16.5% | \[ \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2} \cdot \frac{--1}{a}}
\] |
*-commutative [<=]16.5% | \[ \color{blue}{\frac{--1}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}}
\] |
metadata-eval [=>]16.5% | \[ \frac{\color{blue}{1}}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
metadata-eval [<=]16.5% | \[ \frac{\color{blue}{-1 \cdot -1}}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
associate-*l/ [<=]16.5% | \[ \color{blue}{\left(\frac{-1}{a} \cdot -1\right)} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
associate-/r/ [<=]16.5% | \[ \color{blue}{\frac{-1}{\frac{a}{-1}}} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
times-frac [<=]16.4% | \[ \color{blue}{\frac{-1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{\frac{a}{-1} \cdot 2}}
\] |
*-commutative [<=]16.4% | \[ \frac{-1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{\color{blue}{2 \cdot \frac{a}{-1}}}
\] |
times-frac [=>]16.4% | \[ \color{blue}{\frac{-1}{2} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{a}{-1}}}
\] |
metadata-eval [=>]16.4% | \[ \color{blue}{-0.5} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{a}{-1}}
\] |
associate-/r/ [=>]16.4% | \[ -0.5 \cdot \color{blue}{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} \cdot -1\right)}
\] |
*-commutative [<=]16.4% | \[ -0.5 \cdot \color{blue}{\left(-1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}\right)}
\] |
div-sub [=>]14.0% | \[ -0.5 \cdot \left(-1 \cdot \color{blue}{\left(\frac{-b}{a} - \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}\right)}\right)
\] |
Taylor expanded in b around -inf 85.0%
Simplified85.0%
[Start]85.0% | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
associate-*r/ [=>]85.0% | \[ \color{blue}{\frac{-1 \cdot c}{b}}
\] |
neg-mul-1 [<=]85.0% | \[ \frac{\color{blue}{-c}}{b}
\] |
if -5.20000000000000018e-83 < b < 5.00000000000000029e83Initial program 80.8%
if 5.00000000000000029e83 < b Initial program 60.5%
Simplified60.5%
[Start]60.5% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]60.5% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]60.5% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
associate-/l* [=>]60.5% | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2}{\frac{--1}{a}}}}
\] |
associate-/r/ [=>]60.5% | \[ \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2} \cdot \frac{--1}{a}}
\] |
*-commutative [<=]60.5% | \[ \color{blue}{\frac{--1}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}}
\] |
metadata-eval [=>]60.5% | \[ \frac{\color{blue}{1}}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
metadata-eval [<=]60.5% | \[ \frac{\color{blue}{-1 \cdot -1}}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
associate-*l/ [<=]60.5% | \[ \color{blue}{\left(\frac{-1}{a} \cdot -1\right)} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
associate-/r/ [<=]60.5% | \[ \color{blue}{\frac{-1}{\frac{a}{-1}}} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
times-frac [<=]60.5% | \[ \color{blue}{\frac{-1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{\frac{a}{-1} \cdot 2}}
\] |
*-commutative [<=]60.5% | \[ \frac{-1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{\color{blue}{2 \cdot \frac{a}{-1}}}
\] |
times-frac [=>]60.5% | \[ \color{blue}{\frac{-1}{2} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{a}{-1}}}
\] |
metadata-eval [=>]60.5% | \[ \color{blue}{-0.5} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{a}{-1}}
\] |
associate-/r/ [=>]60.5% | \[ -0.5 \cdot \color{blue}{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} \cdot -1\right)}
\] |
*-commutative [<=]60.5% | \[ -0.5 \cdot \color{blue}{\left(-1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}\right)}
\] |
div-sub [=>]60.5% | \[ -0.5 \cdot \left(-1 \cdot \color{blue}{\left(\frac{-b}{a} - \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}\right)}\right)
\] |
Taylor expanded in b around inf 96.8%
Simplified96.8%
[Start]96.8% | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
mul-1-neg [=>]96.8% | \[ \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)}
\] |
unsub-neg [=>]96.8% | \[ \color{blue}{\frac{c}{b} - \frac{b}{a}}
\] |
Final simplification86.0%
| Alternative 1 | |
|---|---|
| Accuracy | 84.9% |
| Cost | 7688 |
| Alternative 2 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Accuracy | 68.4% |
| Cost | 580 |
| Alternative 4 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 388 |
| Alternative 5 | |
|---|---|
| Accuracy | 68.2% |
| Cost | 388 |
| Alternative 6 | |
|---|---|
| Accuracy | 2.5% |
| Cost | 192 |
| Alternative 7 | |
|---|---|
| Accuracy | 11.8% |
| Cost | 192 |
herbie shell --seed 2023167
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))