| Alternative 1 | |
|---|---|
| Accuracy | 95.4% |
| Cost | 34752 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= (/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0)) -100.0)
(/ (/ (- (* b b) t_0) (- (- b) (sqrt t_0))) (* a 2.0))
(-
(- (/ (* (pow c 3.0) -2.0) (/ (pow b 5.0) (* a a))) (/ c b))
(* a (/ c (/ (pow b 3.0) c)))))))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 t_0 = fma(c, (a * -4.0), (b * b));
double tmp;
if (((sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0)) <= -100.0) {
tmp = (((b * b) - t_0) / (-b - sqrt(t_0))) / (a * 2.0);
} else {
tmp = (((pow(c, 3.0) * -2.0) / (pow(b, 5.0) / (a * a))) - (c / b)) - (a * (c / (pow(b, 3.0) / c)));
}
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) t_0 = fma(c, Float64(a * -4.0), Float64(b * b)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)) <= -100.0) tmp = Float64(Float64(Float64(Float64(b * b) - t_0) / Float64(Float64(-b) - sqrt(t_0))) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(Float64((c ^ 3.0) * -2.0) / Float64((b ^ 5.0) / Float64(a * a))) - Float64(c / b)) - Float64(a * Float64(c / Float64((b ^ 3.0) / c)))); end return 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_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[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], -100.0], N[(N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[((-b) - N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[Power[c, 3.0], $MachinePrecision] * -2.0), $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(a * N[(c / N[(N[Power[b, 3.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq -100:\\
\;\;\;\;\frac{\frac{b \cdot b - t_0}{\left(-b\right) - \sqrt{t_0}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{{c}^{3} \cdot -2}{\frac{{b}^{5}}{a \cdot a}} - \frac{c}{b}\right) - a \cdot \frac{c}{\frac{{b}^{3}}{c}}\\
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -100Initial program 71.0%
Simplified71.0%
[Start]71.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]71.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr72.1%
[Start]71.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}
\] |
|---|---|
flip-+ [=>]70.9 | \[ \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}
\] |
sub-neg [=>]70.9 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\left(-b\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]70.8 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b} \cdot \sqrt{b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqrt-prod [<=]70.9 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{b \cdot b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqr-neg [<=]70.9 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\sqrt{\color{blue}{\left(-b\right) \cdot \left(-b\right)}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
sqrt-unprod [<=]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\sqrt{-b} \cdot \sqrt{-b}}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
add-sqr-sqrt [<=]1.5 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{a \cdot 2}
\] |
distribute-neg-in [<=]1.5 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{-\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]0.0 | \[ \frac{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \left(-\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}}}{a \cdot 2}
\] |
Simplified72.5%
[Start]72.1 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
|---|---|
associate-/l/ [=>]72.1 | \[ \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}}{a \cdot 2}
\] |
/-rgt-identity [<=]72.1 | \[ \frac{\frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}{1}}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
/-rgt-identity [=>]72.1 | \[ \frac{\frac{\color{blue}{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
fma-def [<=]72.4 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + c \cdot \left(a \cdot -4\right)\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]72.4 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(c \cdot \left(a \cdot -4\right) + b \cdot b\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
fma-def [=>]72.5 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{\left(-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\right) \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2}
\] |
distribute-lft-neg-in [<=]72.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{\color{blue}{-\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}} \cdot \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}}{a \cdot 2}
\] |
rem-square-sqrt [=>]72.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}}}{a \cdot 2}
\] |
*-lft-identity [<=]72.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\color{blue}{1 \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}}}{a \cdot 2}
\] |
*-lft-identity [=>]72.5 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}{-\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}\right)}}}{a \cdot 2}
\] |
if -100 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 27.5%
Simplified27.5%
[Start]27.5 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]27.5 | \[ \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 95.3%
Simplified95.3%
[Start]95.3 | \[ -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)
\] |
|---|---|
+-commutative [=>]95.3 | \[ \color{blue}{\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}}
\] |
mul-1-neg [=>]95.3 | \[ \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + \color{blue}{\left(-\frac{{c}^{2} \cdot a}{{b}^{3}}\right)}
\] |
unsub-neg [=>]95.3 | \[ \color{blue}{\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) - \frac{{c}^{2} \cdot a}{{b}^{3}}}
\] |
+-commutative [=>]95.3 | \[ \color{blue}{\left(-2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + -1 \cdot \frac{c}{b}\right)} - \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
mul-1-neg [=>]95.3 | \[ \left(-2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \color{blue}{\left(-\frac{c}{b}\right)}\right) - \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
unsub-neg [=>]95.3 | \[ \color{blue}{\left(-2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} - \frac{c}{b}\right)} - \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
*-commutative [=>]95.3 | \[ \left(\color{blue}{\frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} \cdot -2} - \frac{c}{b}\right) - \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
associate-/l* [=>]95.3 | \[ \left(\color{blue}{\frac{{c}^{3}}{\frac{{b}^{5}}{{a}^{2}}}} \cdot -2 - \frac{c}{b}\right) - \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
associate-*l/ [=>]95.3 | \[ \left(\color{blue}{\frac{{c}^{3} \cdot -2}{\frac{{b}^{5}}{{a}^{2}}}} - \frac{c}{b}\right) - \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
unpow2 [=>]95.3 | \[ \left(\frac{{c}^{3} \cdot -2}{\frac{{b}^{5}}{\color{blue}{a \cdot a}}} - \frac{c}{b}\right) - \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
associate-/l* [=>]95.3 | \[ \left(\frac{{c}^{3} \cdot -2}{\frac{{b}^{5}}{a \cdot a}} - \frac{c}{b}\right) - \color{blue}{\frac{{c}^{2}}{\frac{{b}^{3}}{a}}}
\] |
associate-/r/ [=>]95.3 | \[ \left(\frac{{c}^{3} \cdot -2}{\frac{{b}^{5}}{a \cdot a}} - \frac{c}{b}\right) - \color{blue}{\frac{{c}^{2}}{{b}^{3}} \cdot a}
\] |
Final simplification93.1%
| Alternative 1 | |
|---|---|
| Accuracy | 95.4% |
| Cost | 34752 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.7% |
| Cost | 21060 |
| Alternative 3 | |
|---|---|
| Accuracy | 93.9% |
| Cost | 20736 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.7% |
| Cost | 14788 |
| Alternative 5 | |
|---|---|
| Accuracy | 90.8% |
| Cost | 1024 |
| Alternative 6 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 256 |
herbie shell --seed 2023137
(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)))