| Alternative 1 | |
|---|---|
| Accuracy | 77.6% |
| Cost | 13896 |
(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 -3.3e-46)
(/ (- c) b)
(if (<= b -1.8e-251)
(*
-0.5
(/
(* c (/ 1.0 (* -0.25 (/ (- (hypot b (sqrt (* c (* a -4.0)))) b) a))))
a))
(if (<= b 1e+109)
(* -0.5 (/ (+ b (sqrt (fma a (* c -4.0) (* b b)))) a))
(- (/ 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 <= -3.3e-46) {
tmp = -c / b;
} else if (b <= -1.8e-251) {
tmp = -0.5 * ((c * (1.0 / (-0.25 * ((hypot(b, sqrt((c * (a * -4.0)))) - b) / a)))) / a);
} else if (b <= 1e+109) {
tmp = -0.5 * ((b + sqrt(fma(a, (c * -4.0), (b * b)))) / a);
} 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 <= -3.3e-46) tmp = Float64(Float64(-c) / b); elseif (b <= -1.8e-251) tmp = Float64(-0.5 * Float64(Float64(c * Float64(1.0 / Float64(-0.25 * Float64(Float64(hypot(b, sqrt(Float64(c * Float64(a * -4.0)))) - b) / a)))) / a)); elseif (b <= 1e+109) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return 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, -3.3e-46], N[((-c) / b), $MachinePrecision], If[LessEqual[b, -1.8e-251], N[(-0.5 * N[(N[(c * N[(1.0 / N[(-0.25 * N[(N[(N[Sqrt[b ^ 2 + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+109], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $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}
\mathbf{if}\;b \leq -3.3 \cdot 10^{-46}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq -1.8 \cdot 10^{-251}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot \frac{1}{-0.25 \cdot \frac{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b}{a}}}{a}\\
\mathbf{elif}\;b \leq 10^{+109}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
| Original | 42.9% |
|---|---|
| Target | 61.6% |
| Herbie | 79.1% |
if b < -3.30000000000000013e-46Initial program 15.1%
Taylor expanded in b around -inf 88.4%
Simplified88.4%
[Start]88.4 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
associate-*r/ [=>]88.4 | \[ \color{blue}{\frac{-1 \cdot c}{b}}
\] |
neg-mul-1 [<=]88.4 | \[ \frac{\color{blue}{-c}}{b}
\] |
if -3.30000000000000013e-46 < b < -1.8000000000000001e-251Initial program 62.2%
Simplified62.4%
[Start]62.2 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]62.2 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]62.2 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
associate-/l* [=>]62.1 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2}{\frac{--1}{a}}}}
\] |
associate-/r/ [=>]62.3 | \[ \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2} \cdot \frac{--1}{a}}
\] |
*-commutative [<=]62.3 | \[ \color{blue}{\frac{--1}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}}
\] |
metadata-eval [=>]62.3 | \[ \frac{\color{blue}{1}}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
metadata-eval [<=]62.3 | \[ \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/ [<=]62.3 | \[ \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/ [<=]62.3 | \[ \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 [<=]62.2 | \[ \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 [<=]62.2 | \[ \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 [=>]62.3 | \[ \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 [=>]62.3 | \[ \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/ [=>]62.3 | \[ -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 [<=]62.3 | \[ -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 [=>]62.3 | \[ -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)
\] |
Applied egg-rr61.7%
[Start]62.4 | \[ -0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}
\] |
|---|---|
flip-+ [=>]62.3 | \[ -0.5 \cdot \frac{\color{blue}{\frac{b \cdot b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}}{a}
\] |
add-sqr-sqrt [<=]62.3 | \[ -0.5 \cdot \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}{a}
\] |
div-sub [=>]62.3 | \[ -0.5 \cdot \frac{\color{blue}{\frac{b \cdot b}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}} - \frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}}{a}
\] |
fma-udef [=>]62.3 | \[ -0.5 \cdot \frac{\frac{b \cdot b}{b - \sqrt{\color{blue}{a \cdot \left(c \cdot -4\right) + b \cdot b}}} - \frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}{a}
\] |
+-commutative [=>]62.3 | \[ -0.5 \cdot \frac{\frac{b \cdot b}{b - \sqrt{\color{blue}{b \cdot b + a \cdot \left(c \cdot -4\right)}}} - \frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}{a}
\] |
add-sqr-sqrt [=>]61.7 | \[ -0.5 \cdot \frac{\frac{b \cdot b}{b - \sqrt{b \cdot b + \color{blue}{\sqrt{a \cdot \left(c \cdot -4\right)} \cdot \sqrt{a \cdot \left(c \cdot -4\right)}}}} - \frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}{a}
\] |
hypot-def [=>]61.7 | \[ -0.5 \cdot \frac{\frac{b \cdot b}{b - \color{blue}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}} - \frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}{a}
\] |
associate-*r* [=>]61.7 | \[ -0.5 \cdot \frac{\frac{b \cdot b}{b - \mathsf{hypot}\left(b, \sqrt{\color{blue}{\left(a \cdot c\right) \cdot -4}}\right)} - \frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}{a}
\] |
Simplified65.7%
[Start]61.7 | \[ -0.5 \cdot \frac{\frac{b \cdot b}{b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)} - \frac{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}{b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)}}{a}
\] |
|---|---|
div-sub [<=]61.7 | \[ -0.5 \cdot \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}{b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)}}}{a}
\] |
*-lft-identity [<=]61.7 | \[ -0.5 \cdot \frac{\color{blue}{1 \cdot \frac{b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}{b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)}}}{a}
\] |
metadata-eval [<=]61.7 | \[ -0.5 \cdot \frac{\color{blue}{\frac{-1}{-1}} \cdot \frac{b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}{b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)}}{a}
\] |
times-frac [<=]61.7 | \[ -0.5 \cdot \frac{\color{blue}{\frac{-1 \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)\right)}{-1 \cdot \left(b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)\right)}}}{a}
\] |
neg-mul-1 [<=]61.7 | \[ -0.5 \cdot \frac{\frac{-1 \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)\right)}{\color{blue}{-\left(b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)\right)}}}{a}
\] |
neg-mul-1 [<=]61.7 | \[ -0.5 \cdot \frac{\frac{\color{blue}{-\left(b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)\right)}}{-\left(b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)\right)}}{a}
\] |
Applied egg-rr75.4%
[Start]65.7 | \[ -0.5 \cdot \frac{\frac{c \cdot \left(a \cdot -4\right)}{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b}}{a}
\] |
|---|---|
associate-/l* [=>]75.5 | \[ -0.5 \cdot \frac{\color{blue}{\frac{c}{\frac{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b}{a \cdot -4}}}}{a}
\] |
div-inv [=>]75.4 | \[ -0.5 \cdot \frac{\color{blue}{c \cdot \frac{1}{\frac{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b}{a \cdot -4}}}}{a}
\] |
*-un-lft-identity [=>]75.4 | \[ -0.5 \cdot \frac{c \cdot \frac{1}{\frac{\color{blue}{1 \cdot \left(\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b\right)}}{a \cdot -4}}}{a}
\] |
*-commutative [=>]75.4 | \[ -0.5 \cdot \frac{c \cdot \frac{1}{\frac{1 \cdot \left(\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b\right)}{\color{blue}{-4 \cdot a}}}}{a}
\] |
times-frac [=>]75.4 | \[ -0.5 \cdot \frac{c \cdot \frac{1}{\color{blue}{\frac{1}{-4} \cdot \frac{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b}{a}}}}{a}
\] |
metadata-eval [=>]75.4 | \[ -0.5 \cdot \frac{c \cdot \frac{1}{\color{blue}{-0.25} \cdot \frac{\mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right) - b}{a}}}{a}
\] |
if -1.8000000000000001e-251 < b < 9.99999999999999982e108Initial program 81.7%
Simplified81.7%
[Start]81.7 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]81.7 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]81.7 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
associate-/l* [=>]81.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/ [=>]81.4 | \[ \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2} \cdot \frac{--1}{a}}
\] |
*-commutative [<=]81.4 | \[ \color{blue}{\frac{--1}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}}
\] |
metadata-eval [=>]81.4 | \[ \frac{\color{blue}{1}}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2}
\] |
metadata-eval [<=]81.4 | \[ \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/ [<=]81.4 | \[ \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/ [<=]81.4 | \[ \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 [<=]81.7 | \[ \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 [<=]81.7 | \[ \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 [=>]81.7 | \[ \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 [=>]81.7 | \[ \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/ [=>]81.7 | \[ -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 [<=]81.7 | \[ -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 [=>]81.7 | \[ -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)
\] |
if 9.99999999999999982e108 < b Initial program 15.8%
Taylor expanded in b around inf 62.5%
Simplified62.5%
[Start]62.5 | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
mul-1-neg [=>]62.5 | \[ \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)}
\] |
unsub-neg [=>]62.5 | \[ \color{blue}{\frac{c}{b} - \frac{b}{a}}
\] |
Final simplification79.1%
| Alternative 1 | |
|---|---|
| Accuracy | 77.6% |
| Cost | 13896 |
| Alternative 2 | |
|---|---|
| Accuracy | 77.6% |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Accuracy | 72.8% |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Accuracy | 59.4% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Accuracy | 35.0% |
| Cost | 388 |
| Alternative 6 | |
|---|---|
| Accuracy | 58.9% |
| Cost | 388 |
| Alternative 7 | |
|---|---|
| Accuracy | 10.6% |
| Cost | 192 |
herbie shell --seed 2023153
(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)))