| Alternative 1 | |
|---|---|
| Accuracy | 87.2% |
| Cost | 13964 |
(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 -5e+108)
(- (/ c b) (/ b a))
(if (<= b -6.8e-221)
(/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0))
(if (<= b 1900000000000.0)
(/ (* c -2.0) (+ b (hypot b (sqrt (* a (* c -4.0))))))
(/ (- c) 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) {
double tmp;
if (b <= -5e+108) {
tmp = (c / b) - (b / a);
} else if (b <= -6.8e-221) {
tmp = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (b <= 1900000000000.0) {
tmp = (c * -2.0) / (b + hypot(b, sqrt((a * (c * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
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 <= -5e+108) {
tmp = (c / b) - (b / a);
} else if (b <= -6.8e-221) {
tmp = (Math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (b <= 1900000000000.0) {
tmp = (c * -2.0) / (b + Math.hypot(b, Math.sqrt((a * (c * -4.0)))));
} else {
tmp = -c / b;
}
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 <= -5e+108: tmp = (c / b) - (b / a) elif b <= -6.8e-221: tmp = (math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0) elif b <= 1900000000000.0: tmp = (c * -2.0) / (b + math.hypot(b, math.sqrt((a * (c * -4.0))))) else: tmp = -c / b return tmp
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) tmp = 0.0 if (b <= -5e+108) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -6.8e-221) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif (b <= 1900000000000.0) tmp = Float64(Float64(c * -2.0) / Float64(b + hypot(b, sqrt(Float64(a * Float64(c * -4.0)))))); else tmp = Float64(Float64(-c) / b); 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 <= -5e+108) tmp = (c / b) - (b / a); elseif (b <= -6.8e-221) tmp = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0); elseif (b <= 1900000000000.0) tmp = (c * -2.0) / (b + hypot(b, sqrt((a * (c * -4.0))))); else tmp = -c / b; end tmp_2 = tmp; 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_] := If[LessEqual[b, -5e+108], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -6.8e-221], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1900000000000.0], N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+108}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -6.8 \cdot 10^{-221}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1900000000000:\\
\;\;\;\;\frac{c \cdot -2}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
Results
if b < -4.99999999999999991e108Initial program 23.9%
Simplified23.9%
[Start]23.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]23.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Taylor expanded in b around -inf 94.4%
Simplified94.4%
[Start]94.4 | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
mul-1-neg [=>]94.4 | \[ \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)}
\] |
unsub-neg [=>]94.4 | \[ \color{blue}{\frac{c}{b} - \frac{b}{a}}
\] |
if -4.99999999999999991e108 < b < -6.8000000000000003e-221Initial program 88.0%
if -6.8000000000000003e-221 < b < 1.9e12Initial program 62.3%
Simplified62.3%
[Start]62.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]62.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]62.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]62.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]62.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]62.3 | \[ \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/ [<=]62.3 | \[ \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 [<=]62.3 | \[ \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 [<=]62.3 | \[ \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-rr61.3%
Taylor expanded in a around 0 77.1%
Simplified77.1%
[Start]77.1 | \[ \frac{-2 \cdot c}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}
\] |
|---|---|
*-commutative [=>]77.1 | \[ \frac{\color{blue}{c \cdot -2}}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}
\] |
if 1.9e12 < b Initial program 12.6%
Simplified12.6%
[Start]12.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]12.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]12.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]12.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]12.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]12.6 | \[ \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/ [<=]12.6 | \[ \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 [<=]12.6 | \[ \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 [<=]12.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Taylor expanded in b around inf 91.7%
Simplified91.7%
[Start]91.7 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
mul-1-neg [=>]91.7 | \[ \color{blue}{-\frac{c}{b}}
\] |
Final simplification87.2%
| Alternative 1 | |
|---|---|
| Accuracy | 87.2% |
| Cost | 13964 |
| Alternative 2 | |
|---|---|
| Accuracy | 87.2% |
| Cost | 13964 |
| Alternative 3 | |
|---|---|
| Accuracy | 83.6% |
| Cost | 7624 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 7624 |
| Alternative 5 | |
|---|---|
| Accuracy | 79.1% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Accuracy | 79.1% |
| Cost | 7368 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.1% |
| Cost | 388 |
| Alternative 8 | |
|---|---|
| Accuracy | 37.4% |
| Cost | 256 |
| Alternative 9 | |
|---|---|
| Accuracy | 11.2% |
| Cost | 192 |
herbie shell --seed 2023129
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))