
(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 9 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
(if (<= b -2.8e+158)
(/ (- b) a)
(if (<= b 4.3e-281)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(if (<= b 1.8e+74)
(/ (* -0.5 (/ c -0.25)) (- (- b) (sqrt (fma b b (* c (* a -4.0))))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+158) {
tmp = -b / a;
} else if (b <= 4.3e-281) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if (b <= 1.8e+74) {
tmp = (-0.5 * (c / -0.25)) / (-b - sqrt(fma(b, b, (c * (a * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2.8e+158) tmp = Float64(Float64(-b) / a); elseif (b <= 4.3e-281) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); elseif (b <= 1.8e+74) tmp = Float64(Float64(-0.5 * Float64(c / -0.25)) / Float64(Float64(-b) - sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2.8e+158], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.3e-281], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.8e+74], N[(N[(-0.5 * N[(c / -0.25), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+158}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.3 \cdot 10^{-281}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+74}:\\
\;\;\;\;\frac{-0.5 \cdot \frac{c}{-0.25}}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.80000000000000001e158Initial program 33.1%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -2.80000000000000001e158 < b < 4.30000000000000023e-281Initial program 90.1%
if 4.30000000000000023e-281 < b < 1.79999999999999994e74Initial program 61.0%
prod-diff60.7%
*-commutative60.7%
fma-def60.7%
associate-+l+60.7%
*-commutative60.7%
distribute-rgt-neg-in60.7%
fma-def60.6%
*-commutative60.6%
distribute-rgt-neg-in60.6%
metadata-eval60.6%
*-commutative60.6%
fma-udef60.7%
distribute-lft-neg-in60.7%
distribute-rgt-neg-in60.7%
fma-def60.6%
Applied egg-rr60.6%
flip-+60.6%
add-sqr-sqrt60.6%
fma-def60.5%
*-commutative60.5%
fma-def60.5%
Applied egg-rr60.5%
Simplified78.1%
div-inv77.9%
sub0-neg77.9%
*-commutative77.9%
Applied egg-rr77.9%
associate-*l/78.1%
associate-*r/78.2%
*-rgt-identity78.2%
neg-mul-178.2%
*-commutative78.2%
times-frac78.2%
metadata-eval78.2%
fma-udef78.2%
+-rgt-identity78.2%
*-commutative78.2%
fma-udef78.2%
+-rgt-identity78.2%
*-commutative78.2%
Simplified78.2%
expm1-log1p-u55.8%
expm1-udef21.4%
associate-/l*21.5%
Applied egg-rr21.5%
expm1-def65.2%
expm1-log1p87.7%
associate-/r*87.7%
*-inverses87.7%
metadata-eval87.7%
Simplified87.7%
if 1.79999999999999994e74 < b Initial program 3.8%
Taylor expanded in b around inf 95.8%
associate-*r/95.8%
neg-mul-195.8%
Simplified95.8%
Final simplification92.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e+158)
(/ (- b) a)
(if (<= b 4.2e-281)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(if (<= b 54.0)
(/ (/ c 0.5) (- (- b) (hypot b (sqrt (* a (* c -4.0))))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+158) {
tmp = -b / a;
} else if (b <= 4.2e-281) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if (b <= 54.0) {
tmp = (c / 0.5) / (-b - hypot(b, sqrt((a * (c * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+158) {
tmp = -b / a;
} else if (b <= 4.2e-281) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if (b <= 54.0) {
tmp = (c / 0.5) / (-b - Math.hypot(b, Math.sqrt((a * (c * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e+158: tmp = -b / a elif b <= 4.2e-281: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) elif b <= 54.0: tmp = (c / 0.5) / (-b - math.hypot(b, math.sqrt((a * (c * -4.0))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e+158) tmp = Float64(Float64(-b) / a); elseif (b <= 4.2e-281) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); elseif (b <= 54.0) tmp = Float64(Float64(c / 0.5) / Float64(Float64(-b) - hypot(b, sqrt(Float64(a * Float64(c * -4.0)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.8e+158) tmp = -b / a; elseif (b <= 4.2e-281) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); elseif (b <= 54.0) tmp = (c / 0.5) / (-b - hypot(b, sqrt((a * (c * -4.0))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e+158], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.2e-281], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 54.0], N[(N[(c / 0.5), $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]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+158}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-281}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 54:\\
\;\;\;\;\frac{\frac{c}{0.5}}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.80000000000000001e158Initial program 33.1%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -2.80000000000000001e158 < b < 4.1999999999999998e-281Initial program 90.1%
if 4.1999999999999998e-281 < b < 54Initial program 71.2%
prod-diff70.9%
*-commutative70.9%
fma-def70.9%
associate-+l+70.9%
*-commutative70.9%
distribute-rgt-neg-in70.9%
fma-def70.8%
*-commutative70.8%
distribute-rgt-neg-in70.8%
metadata-eval70.8%
*-commutative70.8%
fma-udef70.9%
distribute-lft-neg-in70.9%
distribute-rgt-neg-in70.9%
fma-def70.8%
Applied egg-rr70.8%
flip-+70.8%
add-sqr-sqrt70.8%
fma-def70.7%
*-commutative70.7%
fma-def70.7%
Applied egg-rr70.7%
Simplified78.4%
div-inv78.3%
sub0-neg78.3%
*-commutative78.3%
Applied egg-rr78.3%
associate-*l/78.4%
associate-*r/78.5%
*-rgt-identity78.5%
neg-mul-178.5%
*-commutative78.5%
times-frac78.5%
metadata-eval78.5%
fma-udef78.5%
+-rgt-identity78.5%
*-commutative78.5%
fma-udef78.5%
+-rgt-identity78.5%
*-commutative78.5%
Simplified78.5%
expm1-log1p-u62.6%
expm1-udef14.9%
Applied egg-rr15.0%
expm1-def71.2%
expm1-log1p87.1%
associate-/r/87.0%
associate-*l/87.1%
*-commutative87.1%
associate-*l/87.1%
associate-/l*87.1%
associate-/r*87.1%
*-inverses87.1%
metadata-eval87.1%
metadata-eval87.1%
associate-*r*87.1%
*-commutative87.1%
associate-*l*87.1%
Simplified87.1%
if 54 < b Initial program 8.5%
Taylor expanded in b around inf 94.3%
associate-*r/94.3%
neg-mul-194.3%
Simplified94.3%
Final simplification92.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e+158)
(/ (- b) a)
(if (<= b 220.0)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+158) {
tmp = -b / a;
} else if (b <= 220.0) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} 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 (b <= (-2.8d+158)) then
tmp = -b / a
else if (b <= 220.0d0) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+158) {
tmp = -b / a;
} else if (b <= 220.0) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e+158: tmp = -b / a elif b <= 220.0: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e+158) tmp = Float64(Float64(-b) / a); elseif (b <= 220.0) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.8e+158) tmp = -b / a; elseif (b <= 220.0) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e+158], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 220.0], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+158}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 220:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.80000000000000001e158Initial program 33.1%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -2.80000000000000001e158 < b < 220Initial program 84.1%
if 220 < b Initial program 8.5%
Taylor expanded in b around inf 94.3%
associate-*r/94.3%
neg-mul-194.3%
Simplified94.3%
Final simplification89.2%
(FPCore (a b c) :precision binary64 (if (<= b -5.4e-12) (- (/ c b) (/ b a)) (if (<= b 11.2) (/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.4e-12) {
tmp = (c / b) - (b / a);
} else if (b <= 11.2) {
tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} 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 (b <= (-5.4d-12)) then
tmp = (c / b) - (b / a)
else if (b <= 11.2d0) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.4e-12) {
tmp = (c / b) - (b / a);
} else if (b <= 11.2) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.4e-12: tmp = (c / b) - (b / a) elif b <= 11.2: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.4e-12) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 11.2) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.4e-12) tmp = (c / b) - (b / a); elseif (b <= 11.2) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.4e-12], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 11.2], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.4 \cdot 10^{-12}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 11.2:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.39999999999999961e-12Initial program 69.8%
Taylor expanded in b around -inf 94.9%
+-commutative94.9%
mul-1-neg94.9%
unsub-neg94.9%
Simplified94.9%
if -5.39999999999999961e-12 < b < 11.199999999999999Initial program 79.2%
prod-diff78.9%
*-commutative78.9%
fma-def78.9%
associate-+l+78.9%
*-commutative78.9%
distribute-rgt-neg-in78.9%
fma-def78.9%
*-commutative78.9%
distribute-rgt-neg-in78.9%
metadata-eval78.9%
*-commutative78.9%
fma-udef78.9%
distribute-lft-neg-in78.9%
distribute-rgt-neg-in78.9%
fma-def78.9%
Applied egg-rr78.9%
Taylor expanded in b around 0 69.7%
neg-mul-169.7%
unsub-neg69.7%
distribute-rgt-out70.0%
*-commutative70.0%
metadata-eval70.0%
associate-*l*70.0%
*-commutative70.0%
Simplified70.0%
if 11.199999999999999 < b Initial program 8.5%
Taylor expanded in b around inf 94.3%
associate-*r/94.3%
neg-mul-194.3%
Simplified94.3%
Final simplification84.9%
(FPCore (a b c) :precision binary64 (if (<= b -8.2e-91) (- (/ c b) (/ b a)) (if (<= b 36.0) (* 0.5 (/ (sqrt (* c (* a -4.0))) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-91) {
tmp = (c / b) - (b / a);
} else if (b <= 36.0) {
tmp = 0.5 * (sqrt((c * (a * -4.0))) / a);
} 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 (b <= (-8.2d-91)) then
tmp = (c / b) - (b / a)
else if (b <= 36.0d0) then
tmp = 0.5d0 * (sqrt((c * (a * (-4.0d0)))) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-91) {
tmp = (c / b) - (b / a);
} else if (b <= 36.0) {
tmp = 0.5 * (Math.sqrt((c * (a * -4.0))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.2e-91: tmp = (c / b) - (b / a) elif b <= 36.0: tmp = 0.5 * (math.sqrt((c * (a * -4.0))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.2e-91) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 36.0) tmp = Float64(0.5 * Float64(sqrt(Float64(c * Float64(a * -4.0))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.2e-91) tmp = (c / b) - (b / a); elseif (b <= 36.0) tmp = 0.5 * (sqrt((c * (a * -4.0))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.2e-91], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 36.0], N[(0.5 * N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-91}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 36:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.20000000000000048e-91Initial program 70.9%
Taylor expanded in b around -inf 86.9%
+-commutative86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
if -8.20000000000000048e-91 < b < 36Initial program 79.5%
prod-diff79.2%
*-commutative79.2%
fma-def79.2%
associate-+l+79.2%
*-commutative79.2%
distribute-rgt-neg-in79.2%
fma-def79.2%
*-commutative79.2%
distribute-rgt-neg-in79.2%
metadata-eval79.2%
*-commutative79.2%
fma-udef79.2%
distribute-lft-neg-in79.2%
distribute-rgt-neg-in79.2%
fma-def79.2%
Applied egg-rr79.2%
Taylor expanded in b around 0 73.2%
associate-*l/73.3%
*-lft-identity73.3%
distribute-rgt-out73.5%
*-commutative73.5%
metadata-eval73.5%
associate-*l*73.5%
*-commutative73.5%
Simplified73.5%
if 36 < b Initial program 8.5%
Taylor expanded in b around inf 94.3%
associate-*r/94.3%
neg-mul-194.3%
Simplified94.3%
Final simplification84.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} 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 (b <= (-5d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 75.4%
Taylor expanded in b around -inf 67.2%
+-commutative67.2%
mul-1-neg67.2%
unsub-neg67.2%
Simplified67.2%
if -4.999999999999985e-310 < b Initial program 34.6%
Taylor expanded in b around inf 65.7%
associate-*r/65.7%
neg-mul-165.7%
Simplified65.7%
Final simplification66.4%
(FPCore (a b c) :precision binary64 (if (<= b 2.85e-301) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.85e-301) {
tmp = -b / a;
} 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 (b <= 2.85d-301) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.85e-301) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.85e-301: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.85e-301) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.85e-301) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.85e-301], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.85 \cdot 10^{-301}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 2.85000000000000018e-301Initial program 75.6%
Taylor expanded in b around -inf 66.3%
associate-*r/66.3%
mul-1-neg66.3%
Simplified66.3%
if 2.85000000000000018e-301 < b Initial program 34.1%
Taylor expanded in b around inf 66.2%
associate-*r/66.2%
neg-mul-166.2%
Simplified66.2%
Final simplification66.2%
(FPCore (a b c) :precision binary64 (/ (- b) a))
double code(double a, double b, double c) {
return -b / 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 / a
end function
public static double code(double a, double b, double c) {
return -b / a;
}
def code(a, b, c): return -b / a
function code(a, b, c) return Float64(Float64(-b) / a) end
function tmp = code(a, b, c) tmp = -b / a; end
code[a_, b_, c_] := N[((-b) / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-b}{a}
\end{array}
Initial program 53.9%
Taylor expanded in b around -inf 33.0%
associate-*r/33.0%
mul-1-neg33.0%
Simplified33.0%
Final simplification33.0%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / 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 / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 53.9%
clear-num53.8%
associate-/r/53.8%
associate-/r*53.8%
metadata-eval53.8%
add-sqr-sqrt35.5%
sqrt-unprod51.6%
sqr-neg51.6%
sqrt-prod16.1%
add-sqr-sqrt34.1%
sub-neg34.1%
add-sqr-sqrt31.2%
hypot-def29.2%
*-commutative29.2%
distribute-rgt-neg-in29.2%
*-commutative29.2%
distribute-rgt-neg-in29.2%
metadata-eval29.2%
Applied egg-rr29.2%
Taylor expanded in a around 0 2.6%
Final simplification2.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- b) t_0) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * 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
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b < 0.0d0) then
tmp = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-b - t_0) / (2.0d0 * a)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b < 0.0: tmp = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b < 0.0) tmp = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-b - t_0) / (2.0 * a))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023293
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))