
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
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
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
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 tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); 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]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
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
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
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 tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); 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]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (pow (* a c) 4.0)))
(if (<= a 1.95e-25)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(if (<= a 0.0088)
(+ -1.0 (- 1.0 (/ c b)))
(+
(* -2.0 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(-
(-
(* -0.25 (/ (+ (* 16.0 t_0) (* 4.0 t_0)) (* a (pow b 7.0))))
(* (pow (/ c b) 2.0) (/ a b)))
(/ c b)))))))
double code(double a, double b, double c) {
double t_0 = pow((a * c), 4.0);
double tmp;
if (a <= 1.95e-25) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (a <= 0.0088) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = (-2.0 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + (((-0.25 * (((16.0 * t_0) + (4.0 * t_0)) / (a * pow(b, 7.0)))) - (pow((c / b), 2.0) * (a / b))) - (c / b));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(a * c) ^ 4.0 tmp = 0.0 if (a <= 1.95e-25) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif (a <= 0.0088) tmp = Float64(-1.0 + Float64(1.0 - Float64(c / b))); else tmp = Float64(Float64(-2.0 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(Float64(-0.25 * Float64(Float64(Float64(16.0 * t_0) + Float64(4.0 * t_0)) / Float64(a * (b ^ 7.0)))) - Float64((Float64(c / b) ^ 2.0) * Float64(a / b))) - Float64(c / b))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision]}, If[LessEqual[a, 1.95e-25], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.0088], N[(-1.0 + N[(1.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-0.25 * N[(N[(N[(16.0 * t$95$0), $MachinePrecision] + N[(4.0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision] * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(a \cdot c\right)}^{4}\\
\mathbf{if}\;a \leq 1.95 \cdot 10^{-25}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;a \leq 0.0088:\\
\;\;\;\;-1 + \left(1 - \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(\left(-0.25 \cdot \frac{16 \cdot t\_0 + 4 \cdot t\_0}{a \cdot {b}^{7}} - {\left(\frac{c}{b}\right)}^{2} \cdot \frac{a}{b}\right) - \frac{c}{b}\right)\\
\end{array}
\end{array}
if a < 1.95e-25Initial program 75.6%
*-commutative75.6%
+-commutative75.6%
sqr-neg75.6%
unsub-neg75.6%
sqr-neg75.6%
fma-neg75.6%
distribute-lft-neg-in75.6%
*-commutative75.6%
*-commutative75.6%
distribute-rgt-neg-in75.6%
metadata-eval75.6%
Simplified75.6%
if 1.95e-25 < a < 0.00880000000000000053Initial program 58.3%
*-commutative58.3%
Simplified58.3%
Taylor expanded in b around inf 48.1%
expm1-log1p-u38.1%
expm1-undefine59.5%
associate-*r/59.5%
*-commutative59.5%
times-frac59.5%
metadata-eval59.5%
Applied egg-rr59.5%
sub-neg59.5%
metadata-eval59.5%
+-commutative59.5%
log1p-undefine59.5%
rem-exp-log69.6%
mul-1-neg69.6%
unsub-neg69.6%
*-commutative69.6%
associate-/l*69.6%
*-inverses69.6%
*-rgt-identity69.6%
Simplified69.6%
if 0.00880000000000000053 < a Initial program 42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in b around inf 79.2%
*-commutative79.2%
unpow-prod-down79.2%
pow-prod-down79.2%
pow-pow79.2%
metadata-eval79.2%
metadata-eval79.2%
Applied egg-rr79.2%
pow-prod-down79.2%
metadata-eval79.2%
pow-pow79.2%
Applied egg-rr79.2%
unpow279.2%
pow-sqr79.2%
metadata-eval79.2%
Simplified79.2%
*-commutative79.2%
unpow379.2%
times-frac79.2%
unpow279.2%
frac-times79.2%
pow279.2%
Applied egg-rr79.2%
Final simplification75.1%
(FPCore (a b c)
:precision binary64
(if (<= a 1.85e-25)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(if (<= a 0.0072)
(+ -1.0 (- 1.0 (/ c b)))
(-
(* -2.0 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(+ (/ c b) (/ (* a (pow c 2.0)) (pow b 3.0)))))))
double code(double a, double b, double c) {
double tmp;
if (a <= 1.85e-25) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (a <= 0.0072) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = (-2.0 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) - ((c / b) + ((a * pow(c, 2.0)) / pow(b, 3.0)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (a <= 1.85e-25) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif (a <= 0.0072) tmp = Float64(-1.0 + Float64(1.0 - Float64(c / b))); else tmp = Float64(Float64(-2.0 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) - Float64(Float64(c / b) + Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[a, 1.85e-25], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.0072], N[(-1.0 + N[(1.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c / b), $MachinePrecision] + N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.85 \cdot 10^{-25}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;a \leq 0.0072:\\
\;\;\;\;-1 + \left(1 - \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} - \left(\frac{c}{b} + \frac{a \cdot {c}^{2}}{{b}^{3}}\right)\\
\end{array}
\end{array}
if a < 1.85000000000000004e-25Initial program 75.6%
*-commutative75.6%
+-commutative75.6%
sqr-neg75.6%
unsub-neg75.6%
sqr-neg75.6%
fma-neg75.6%
distribute-lft-neg-in75.6%
*-commutative75.6%
*-commutative75.6%
distribute-rgt-neg-in75.6%
metadata-eval75.6%
Simplified75.6%
if 1.85000000000000004e-25 < a < 0.0071999999999999998Initial program 58.3%
*-commutative58.3%
Simplified58.3%
Taylor expanded in b around inf 48.1%
expm1-log1p-u38.1%
expm1-undefine59.5%
associate-*r/59.5%
*-commutative59.5%
times-frac59.5%
metadata-eval59.5%
Applied egg-rr59.5%
sub-neg59.5%
metadata-eval59.5%
+-commutative59.5%
log1p-undefine59.5%
rem-exp-log69.6%
mul-1-neg69.6%
unsub-neg69.6%
*-commutative69.6%
associate-/l*69.6%
*-inverses69.6%
*-rgt-identity69.6%
Simplified69.6%
if 0.0071999999999999998 < a Initial program 42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in b around inf 78.2%
Final simplification74.6%
(FPCore (a b c)
:precision binary64
(if (<= a 1.45e-25)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(if (<= a 0.0136)
(+ -1.0 (- 1.0 (/ c b)))
(/
(fma
-4.0
(/ (pow (* a c) 3.0) (pow b 5.0))
(* -2.0 (+ (* a (/ c b)) (/ (* a c) (/ (pow b 3.0) (* a c))))))
(* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (a <= 1.45e-25) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (a <= 0.0136) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = fma(-4.0, (pow((a * c), 3.0) / pow(b, 5.0)), (-2.0 * ((a * (c / b)) + ((a * c) / (pow(b, 3.0) / (a * c)))))) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (a <= 1.45e-25) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif (a <= 0.0136) tmp = Float64(-1.0 + Float64(1.0 - Float64(c / b))); else tmp = Float64(fma(-4.0, Float64((Float64(a * c) ^ 3.0) / (b ^ 5.0)), Float64(-2.0 * Float64(Float64(a * Float64(c / b)) + Float64(Float64(a * c) / Float64((b ^ 3.0) / Float64(a * c)))))) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[a, 1.45e-25], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.0136], N[(-1.0 + N[(1.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-4.0 * N[(N[Power[N[(a * c), $MachinePrecision], 3.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.45 \cdot 10^{-25}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;a \leq 0.0136:\\
\;\;\;\;-1 + \left(1 - \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-4, \frac{{\left(a \cdot c\right)}^{3}}{{b}^{5}}, -2 \cdot \left(a \cdot \frac{c}{b} + \frac{a \cdot c}{\frac{{b}^{3}}{a \cdot c}}\right)\right)}{a \cdot 2}\\
\end{array}
\end{array}
if a < 1.45e-25Initial program 75.6%
*-commutative75.6%
+-commutative75.6%
sqr-neg75.6%
unsub-neg75.6%
sqr-neg75.6%
fma-neg75.6%
distribute-lft-neg-in75.6%
*-commutative75.6%
*-commutative75.6%
distribute-rgt-neg-in75.6%
metadata-eval75.6%
Simplified75.6%
if 1.45e-25 < a < 0.0135999999999999992Initial program 58.3%
*-commutative58.3%
Simplified58.3%
Taylor expanded in b around inf 48.1%
expm1-log1p-u38.1%
expm1-undefine59.5%
associate-*r/59.5%
*-commutative59.5%
times-frac59.5%
metadata-eval59.5%
Applied egg-rr59.5%
sub-neg59.5%
metadata-eval59.5%
+-commutative59.5%
log1p-undefine59.5%
rem-exp-log69.6%
mul-1-neg69.6%
unsub-neg69.6%
*-commutative69.6%
associate-/l*69.6%
*-inverses69.6%
*-rgt-identity69.6%
Simplified69.6%
if 0.0135999999999999992 < a Initial program 42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in b around inf 77.9%
fma-define77.9%
cube-prod77.9%
distribute-lft-out77.9%
associate-/l*78.1%
fma-define78.1%
Simplified78.1%
fma-undefine78.1%
div-inv78.1%
pow-prod-down78.1%
pow-flip78.1%
metadata-eval78.1%
Applied egg-rr78.1%
*-commutative78.1%
unpow278.1%
sqr-pow78.1%
unswap-sqr78.1%
metadata-eval78.1%
metadata-eval78.1%
pow-flip78.1%
associate-/r/78.1%
clear-num78.1%
metadata-eval78.1%
metadata-eval78.1%
pow-flip78.1%
associate-/r/78.1%
frac-times78.1%
*-commutative78.1%
*-un-lft-identity78.1%
Applied egg-rr78.1%
associate-*r/78.1%
pow-sqr78.1%
metadata-eval78.1%
Simplified78.1%
Final simplification74.6%
(FPCore (a b c)
:precision binary64
(if (<= a 3.9e-25)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(if (<= a 0.0065)
(+ -1.0 (- 1.0 (/ c b)))
(- (/ c (- b)) (* a (/ (pow c 2.0) (pow b 3.0)))))))
double code(double a, double b, double c) {
double tmp;
if (a <= 3.9e-25) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else if (a <= 0.0065) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = (c / -b) - (a * (pow(c, 2.0) / pow(b, 3.0)));
}
return tmp;
}
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 (a <= 3.9d-25) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else if (a <= 0.0065d0) then
tmp = (-1.0d0) + (1.0d0 - (c / b))
else
tmp = (c / -b) - (a * ((c ** 2.0d0) / (b ** 3.0d0)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (a <= 3.9e-25) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else if (a <= 0.0065) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = (c / -b) - (a * (Math.pow(c, 2.0) / Math.pow(b, 3.0)));
}
return tmp;
}
def code(a, b, c): tmp = 0 if a <= 3.9e-25: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) elif a <= 0.0065: tmp = -1.0 + (1.0 - (c / b)) else: tmp = (c / -b) - (a * (math.pow(c, 2.0) / math.pow(b, 3.0))) return tmp
function code(a, b, c) tmp = 0.0 if (a <= 3.9e-25) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); elseif (a <= 0.0065) tmp = Float64(-1.0 + Float64(1.0 - Float64(c / b))); else tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64((c ^ 2.0) / (b ^ 3.0)))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (a <= 3.9e-25) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); elseif (a <= 0.0065) tmp = -1.0 + (1.0 - (c / b)); else tmp = (c / -b) - (a * ((c ^ 2.0) / (b ^ 3.0))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[a, 3.9e-25], 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[a, 0.0065], N[(-1.0 + N[(1.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.9 \cdot 10^{-25}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;a \leq 0.0065:\\
\;\;\;\;-1 + \left(1 - \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \frac{{c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if a < 3.9e-25Initial program 75.6%
if 3.9e-25 < a < 0.0064999999999999997Initial program 58.3%
*-commutative58.3%
Simplified58.3%
Taylor expanded in b around inf 48.1%
expm1-log1p-u38.1%
expm1-undefine59.5%
associate-*r/59.5%
*-commutative59.5%
times-frac59.5%
metadata-eval59.5%
Applied egg-rr59.5%
sub-neg59.5%
metadata-eval59.5%
+-commutative59.5%
log1p-undefine59.5%
rem-exp-log69.6%
mul-1-neg69.6%
unsub-neg69.6%
*-commutative69.6%
associate-/l*69.6%
*-inverses69.6%
*-rgt-identity69.6%
Simplified69.6%
if 0.0064999999999999997 < a Initial program 42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in b around inf 75.5%
distribute-lft-out75.5%
associate-/l*75.8%
fma-define75.8%
Simplified75.8%
Taylor expanded in a around 0 75.9%
mul-1-neg75.9%
unsub-neg75.9%
mul-1-neg75.9%
distribute-neg-frac75.9%
associate-/l*75.9%
Simplified75.9%
Final simplification73.5%
(FPCore (a b c)
:precision binary64
(if (<= a 1.26e-25)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(if (<= a 0.0067)
(+ -1.0 (- 1.0 (/ c b)))
(- (/ c (- b)) (* a (/ (pow c 2.0) (pow b 3.0)))))))
double code(double a, double b, double c) {
double tmp;
if (a <= 1.26e-25) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else if (a <= 0.0067) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = (c / -b) - (a * (pow(c, 2.0) / pow(b, 3.0)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (a <= 1.26e-25) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif (a <= 0.0067) tmp = Float64(-1.0 + Float64(1.0 - Float64(c / b))); else tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64((c ^ 2.0) / (b ^ 3.0)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[a, 1.26e-25], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.0067], N[(-1.0 + N[(1.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.26 \cdot 10^{-25}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;a \leq 0.0067:\\
\;\;\;\;-1 + \left(1 - \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \frac{{c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if a < 1.26e-25Initial program 75.6%
*-commutative75.6%
+-commutative75.6%
sqr-neg75.6%
unsub-neg75.6%
sqr-neg75.6%
fma-neg75.6%
distribute-lft-neg-in75.6%
*-commutative75.6%
*-commutative75.6%
distribute-rgt-neg-in75.6%
metadata-eval75.6%
Simplified75.6%
if 1.26e-25 < a < 0.00670000000000000023Initial program 58.3%
*-commutative58.3%
Simplified58.3%
Taylor expanded in b around inf 48.1%
expm1-log1p-u38.1%
expm1-undefine59.5%
associate-*r/59.5%
*-commutative59.5%
times-frac59.5%
metadata-eval59.5%
Applied egg-rr59.5%
sub-neg59.5%
metadata-eval59.5%
+-commutative59.5%
log1p-undefine59.5%
rem-exp-log69.6%
mul-1-neg69.6%
unsub-neg69.6%
*-commutative69.6%
associate-/l*69.6%
*-inverses69.6%
*-rgt-identity69.6%
Simplified69.6%
if 0.00670000000000000023 < a Initial program 42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in b around inf 75.5%
distribute-lft-out75.5%
associate-/l*75.8%
fma-define75.8%
Simplified75.8%
Taylor expanded in a around 0 75.9%
mul-1-neg75.9%
unsub-neg75.9%
mul-1-neg75.9%
distribute-neg-frac75.9%
associate-/l*75.9%
Simplified75.9%
Final simplification73.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))))
(if (<= a 2.85e-25)
t_0
(if (<= a 0.038)
(+ -1.0 (- 1.0 (/ c b)))
(if (or (<= a 0.92) (not (<= a 1900000.0))) (/ c (- b)) t_0)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (a <= 2.85e-25) {
tmp = t_0;
} else if (a <= 0.038) {
tmp = -1.0 + (1.0 - (c / b));
} else if ((a <= 0.92) || !(a <= 1900000.0)) {
tmp = c / -b;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (a <= 2.85d-25) then
tmp = t_0
else if (a <= 0.038d0) then
tmp = (-1.0d0) + (1.0d0 - (c / b))
else if ((a <= 0.92d0) .or. (.not. (a <= 1900000.0d0))) then
tmp = c / -b
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (a <= 2.85e-25) {
tmp = t_0;
} else if (a <= 0.038) {
tmp = -1.0 + (1.0 - (c / b));
} else if ((a <= 0.92) || !(a <= 1900000.0)) {
tmp = c / -b;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp = 0 if a <= 2.85e-25: tmp = t_0 elif a <= 0.038: tmp = -1.0 + (1.0 - (c / b)) elif (a <= 0.92) or not (a <= 1900000.0): tmp = c / -b else: tmp = t_0 return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (a <= 2.85e-25) tmp = t_0; elseif (a <= 0.038) tmp = Float64(-1.0 + Float64(1.0 - Float64(c / b))); elseif ((a <= 0.92) || !(a <= 1900000.0)) tmp = Float64(c / Float64(-b)); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); tmp = 0.0; if (a <= 2.85e-25) tmp = t_0; elseif (a <= 0.038) tmp = -1.0 + (1.0 - (c / b)); elseif ((a <= 0.92) || ~((a <= 1900000.0))) tmp = c / -b; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = 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[a, 2.85e-25], t$95$0, If[LessEqual[a, 0.038], N[(-1.0 + N[(1.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[a, 0.92], N[Not[LessEqual[a, 1900000.0]], $MachinePrecision]], N[(c / (-b)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;a \leq 2.85 \cdot 10^{-25}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 0.038:\\
\;\;\;\;-1 + \left(1 - \frac{c}{b}\right)\\
\mathbf{elif}\;a \leq 0.92 \lor \neg \left(a \leq 1900000\right):\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < 2.8500000000000002e-25 or 0.92000000000000004 < a < 1.9e6Initial program 69.5%
if 2.8500000000000002e-25 < a < 0.0379999999999999991Initial program 59.0%
*-commutative59.0%
Simplified59.0%
Taylor expanded in b around inf 47.6%
expm1-log1p-u37.3%
expm1-undefine58.3%
associate-*r/58.3%
*-commutative58.3%
times-frac58.3%
metadata-eval58.3%
Applied egg-rr58.3%
sub-neg58.3%
metadata-eval58.3%
+-commutative58.3%
log1p-undefine58.3%
rem-exp-log68.7%
mul-1-neg68.7%
unsub-neg68.7%
*-commutative68.7%
associate-/l*68.7%
*-inverses68.7%
*-rgt-identity68.7%
Simplified68.7%
if 0.0379999999999999991 < a < 0.92000000000000004 or 1.9e6 < a Initial program 34.0%
*-commutative34.0%
Simplified34.0%
Taylor expanded in b around inf 76.8%
mul-1-neg76.8%
distribute-neg-frac76.8%
Simplified76.8%
Final simplification71.8%
(FPCore (a b c) :precision binary64 (if (or (<= a 0.035) (and (not (<= a 0.8)) (<= a 47000000.0))) (+ -1.0 (- 1.0 (/ c b))) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if ((a <= 0.035) || (!(a <= 0.8) && (a <= 47000000.0))) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = c / -b;
}
return tmp;
}
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 ((a <= 0.035d0) .or. (.not. (a <= 0.8d0)) .and. (a <= 47000000.0d0)) then
tmp = (-1.0d0) + (1.0d0 - (c / b))
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if ((a <= 0.035) || (!(a <= 0.8) && (a <= 47000000.0))) {
tmp = -1.0 + (1.0 - (c / b));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if (a <= 0.035) or (not (a <= 0.8) and (a <= 47000000.0)): tmp = -1.0 + (1.0 - (c / b)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if ((a <= 0.035) || (!(a <= 0.8) && (a <= 47000000.0))) tmp = Float64(-1.0 + Float64(1.0 - Float64(c / b))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if ((a <= 0.035) || (~((a <= 0.8)) && (a <= 47000000.0))) tmp = -1.0 + (1.0 - (c / b)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[Or[LessEqual[a, 0.035], And[N[Not[LessEqual[a, 0.8]], $MachinePrecision], LessEqual[a, 47000000.0]]], N[(-1.0 + N[(1.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 0.035 \lor \neg \left(a \leq 0.8\right) \land a \leq 47000000:\\
\;\;\;\;-1 + \left(1 - \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if a < 0.035000000000000003 or 0.80000000000000004 < a < 4.7e7Initial program 62.7%
*-commutative62.7%
Simplified62.7%
Taylor expanded in b around inf 44.4%
expm1-log1p-u34.6%
expm1-undefine55.9%
associate-*r/55.9%
*-commutative55.9%
times-frac55.9%
metadata-eval55.9%
Applied egg-rr55.9%
sub-neg55.9%
metadata-eval55.9%
+-commutative55.9%
log1p-undefine55.9%
rem-exp-log65.6%
mul-1-neg65.6%
unsub-neg65.6%
*-commutative65.6%
associate-/l*65.6%
*-inverses65.6%
*-rgt-identity65.6%
Simplified65.6%
if 0.035000000000000003 < a < 0.80000000000000004 or 4.7e7 < a Initial program 32.5%
*-commutative32.5%
Simplified32.5%
Taylor expanded in b around inf 78.3%
mul-1-neg78.3%
distribute-neg-frac78.3%
Simplified78.3%
Final simplification69.8%
(FPCore (a b c) :precision binary64 (/ c (- b)))
double code(double a, double b, double c) {
return c / -b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / -b
end function
public static double code(double a, double b, double c) {
return c / -b;
}
def code(a, b, c): return c / -b
function code(a, b, c) return Float64(c / Float64(-b)) end
function tmp = code(a, b, c) tmp = c / -b; end
code[a_, b_, c_] := N[(c / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{-b}
\end{array}
Initial program 52.8%
*-commutative52.8%
Simplified52.8%
Taylor expanded in b around inf 55.6%
mul-1-neg55.6%
distribute-neg-frac55.6%
Simplified55.6%
Final simplification55.6%
herbie shell --seed 2024046
(FPCore (a b c)
:name "Quadratic roots, wide range"
:precision binary64
:pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))