
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- c) b))
(t_1 (* c (* a 4.0)))
(t_2 (sqrt (- (* b b) t_1)))
(t_3 (sqrt (+ b (hypot b (sqrt (* a (* c -4.0))))))))
(if (<= b -2.2e+74)
t_0
(if (<= b -1.05e-27)
(* -0.5 (/ (/ t_1 (- b t_2)) a))
(if (<= b -1.55e-106)
t_0
(if (<= b 4.2e-182)
(* -0.5 (* t_3 (/ t_3 a)))
(if (<= b 1e+128) (* -0.5 (/ (+ b t_2) a)) (/ (- b) a))))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = c * (a * 4.0);
double t_2 = sqrt(((b * b) - t_1));
double t_3 = sqrt((b + hypot(b, sqrt((a * (c * -4.0))))));
double tmp;
if (b <= -2.2e+74) {
tmp = t_0;
} else if (b <= -1.05e-27) {
tmp = -0.5 * ((t_1 / (b - t_2)) / a);
} else if (b <= -1.55e-106) {
tmp = t_0;
} else if (b <= 4.2e-182) {
tmp = -0.5 * (t_3 * (t_3 / a));
} else if (b <= 1e+128) {
tmp = -0.5 * ((b + t_2) / a);
} else {
tmp = -b / a;
}
return tmp;
}
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = c * (a * 4.0);
double t_2 = Math.sqrt(((b * b) - t_1));
double t_3 = Math.sqrt((b + Math.hypot(b, Math.sqrt((a * (c * -4.0))))));
double tmp;
if (b <= -2.2e+74) {
tmp = t_0;
} else if (b <= -1.05e-27) {
tmp = -0.5 * ((t_1 / (b - t_2)) / a);
} else if (b <= -1.55e-106) {
tmp = t_0;
} else if (b <= 4.2e-182) {
tmp = -0.5 * (t_3 * (t_3 / a));
} else if (b <= 1e+128) {
tmp = -0.5 * ((b + t_2) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): t_0 = -c / b t_1 = c * (a * 4.0) t_2 = math.sqrt(((b * b) - t_1)) t_3 = math.sqrt((b + math.hypot(b, math.sqrt((a * (c * -4.0)))))) tmp = 0 if b <= -2.2e+74: tmp = t_0 elif b <= -1.05e-27: tmp = -0.5 * ((t_1 / (b - t_2)) / a) elif b <= -1.55e-106: tmp = t_0 elif b <= 4.2e-182: tmp = -0.5 * (t_3 * (t_3 / a)) elif b <= 1e+128: tmp = -0.5 * ((b + t_2) / a) else: tmp = -b / a return tmp
function code(a, b, c) t_0 = Float64(Float64(-c) / b) t_1 = Float64(c * Float64(a * 4.0)) t_2 = sqrt(Float64(Float64(b * b) - t_1)) t_3 = sqrt(Float64(b + hypot(b, sqrt(Float64(a * Float64(c * -4.0)))))) tmp = 0.0 if (b <= -2.2e+74) tmp = t_0; elseif (b <= -1.05e-27) tmp = Float64(-0.5 * Float64(Float64(t_1 / Float64(b - t_2)) / a)); elseif (b <= -1.55e-106) tmp = t_0; elseif (b <= 4.2e-182) tmp = Float64(-0.5 * Float64(t_3 * Float64(t_3 / a))); elseif (b <= 1e+128) tmp = Float64(-0.5 * Float64(Float64(b + t_2) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) t_0 = -c / b; t_1 = c * (a * 4.0); t_2 = sqrt(((b * b) - t_1)); t_3 = sqrt((b + hypot(b, sqrt((a * (c * -4.0)))))); tmp = 0.0; if (b <= -2.2e+74) tmp = t_0; elseif (b <= -1.05e-27) tmp = -0.5 * ((t_1 / (b - t_2)) / a); elseif (b <= -1.55e-106) tmp = t_0; elseif (b <= 4.2e-182) tmp = -0.5 * (t_3 * (t_3 / a)); elseif (b <= 1e+128) tmp = -0.5 * ((b + t_2) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2.2e+74], t$95$0, If[LessEqual[b, -1.05e-27], N[(-0.5 * N[(N[(t$95$1 / N[(b - t$95$2), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.55e-106], t$95$0, If[LessEqual[b, 4.2e-182], N[(-0.5 * N[(t$95$3 * N[(t$95$3 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+128], N[(-0.5 * N[(N[(b + t$95$2), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := c \cdot \left(a \cdot 4\right)\\
t_2 := \sqrt{b \cdot b - t_1}\\
t_3 := \sqrt{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\
\mathbf{if}\;b \leq -2.2 \cdot 10^{+74}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -1.05 \cdot 10^{-27}:\\
\;\;\;\;-0.5 \cdot \frac{\frac{t_1}{b - t_2}}{a}\\
\mathbf{elif}\;b \leq -1.55 \cdot 10^{-106}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-182}:\\
\;\;\;\;-0.5 \cdot \left(t_3 \cdot \frac{t_3}{a}\right)\\
\mathbf{elif}\;b \leq 10^{+128}:\\
\;\;\;\;-0.5 \cdot \frac{b + t_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.2000000000000001e74 or -1.05000000000000008e-27 < b < -1.54999999999999993e-106Initial program 8.4%
*-commutative8.4%
sqr-neg8.4%
*-commutative8.4%
sqr-neg8.4%
associate-*r*8.4%
*-commutative8.4%
Simplified8.4%
Taylor expanded in b around -inf 92.9%
mul-1-neg92.9%
distribute-neg-frac92.9%
Simplified92.9%
if -2.2000000000000001e74 < b < -1.05000000000000008e-27Initial program 43.2%
sub-neg43.2%
distribute-neg-out43.2%
neg-mul-143.2%
times-frac43.2%
metadata-eval43.2%
remove-double-neg43.2%
neg-sub043.2%
associate-+l-43.2%
Simplified43.2%
fma-udef43.2%
*-commutative43.2%
metadata-eval43.2%
cancel-sign-sub-inv43.2%
associate-*l*43.2%
prod-diff42.9%
*-commutative42.9%
fma-neg42.9%
associate-+l-42.9%
Applied egg-rr42.9%
associate--r+42.9%
+-inverses43.2%
neg-sub043.2%
associate-*r*43.2%
distribute-rgt-neg-in43.2%
metadata-eval43.2%
*-commutative43.2%
associate-*r*43.2%
Simplified43.2%
flip-+42.9%
add-sqr-sqrt42.8%
Applied egg-rr42.8%
associate-+l-83.9%
Simplified83.9%
Taylor expanded in b around 0 83.9%
if -1.54999999999999993e-106 < b < 4.2000000000000001e-182Initial program 73.6%
sub-neg73.6%
distribute-neg-out73.6%
neg-mul-173.6%
times-frac73.6%
metadata-eval73.6%
remove-double-neg73.6%
neg-sub073.6%
associate-+l-73.6%
Simplified73.6%
add-sqr-sqrt71.4%
*-un-lft-identity71.4%
times-frac71.5%
Applied egg-rr75.1%
if 4.2000000000000001e-182 < b < 1.0000000000000001e128Initial program 95.1%
sub-neg95.1%
distribute-neg-out95.1%
neg-mul-195.1%
times-frac95.1%
metadata-eval95.1%
remove-double-neg95.1%
neg-sub095.1%
associate-+l-95.1%
Simplified95.1%
fma-udef95.1%
*-commutative95.1%
metadata-eval95.1%
cancel-sign-sub-inv95.1%
associate-*l*95.1%
prod-diff95.0%
*-commutative95.0%
fma-neg95.0%
associate-+l-95.0%
Applied egg-rr95.0%
associate--r+95.0%
+-inverses95.1%
neg-sub095.1%
associate-*r*95.1%
distribute-rgt-neg-in95.1%
metadata-eval95.1%
*-commutative95.1%
associate-*r*95.1%
Simplified95.1%
if 1.0000000000000001e128 < b Initial program 60.3%
*-commutative60.3%
sqr-neg60.3%
*-commutative60.3%
sqr-neg60.3%
associate-*r*60.3%
*-commutative60.3%
Simplified60.3%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification90.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* a 4.0))) (t_1 (sqrt (- (* b b) t_0))))
(if (<= b -2.6e+74)
(/ (- c) b)
(if (<= b -1.1e-128)
(* -0.5 (/ (/ t_0 (- b t_1)) a))
(if (<= b 2.8e+128) (* -0.5 (/ (+ b t_1) a)) (/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double t_1 = sqrt(((b * b) - t_0));
double tmp;
if (b <= -2.6e+74) {
tmp = -c / b;
} else if (b <= -1.1e-128) {
tmp = -0.5 * ((t_0 / (b - t_1)) / a);
} else if (b <= 2.8e+128) {
tmp = -0.5 * ((b + t_1) / a);
} else {
tmp = -b / 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) :: t_1
real(8) :: tmp
t_0 = c * (a * 4.0d0)
t_1 = sqrt(((b * b) - t_0))
if (b <= (-2.6d+74)) then
tmp = -c / b
else if (b <= (-1.1d-128)) then
tmp = (-0.5d0) * ((t_0 / (b - t_1)) / a)
else if (b <= 2.8d+128) then
tmp = (-0.5d0) * ((b + t_1) / a)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double t_1 = Math.sqrt(((b * b) - t_0));
double tmp;
if (b <= -2.6e+74) {
tmp = -c / b;
} else if (b <= -1.1e-128) {
tmp = -0.5 * ((t_0 / (b - t_1)) / a);
} else if (b <= 2.8e+128) {
tmp = -0.5 * ((b + t_1) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): t_0 = c * (a * 4.0) t_1 = math.sqrt(((b * b) - t_0)) tmp = 0 if b <= -2.6e+74: tmp = -c / b elif b <= -1.1e-128: tmp = -0.5 * ((t_0 / (b - t_1)) / a) elif b <= 2.8e+128: tmp = -0.5 * ((b + t_1) / a) else: tmp = -b / a return tmp
function code(a, b, c) t_0 = Float64(c * Float64(a * 4.0)) t_1 = sqrt(Float64(Float64(b * b) - t_0)) tmp = 0.0 if (b <= -2.6e+74) tmp = Float64(Float64(-c) / b); elseif (b <= -1.1e-128) tmp = Float64(-0.5 * Float64(Float64(t_0 / Float64(b - t_1)) / a)); elseif (b <= 2.8e+128) tmp = Float64(-0.5 * Float64(Float64(b + t_1) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (a * 4.0); t_1 = sqrt(((b * b) - t_0)); tmp = 0.0; if (b <= -2.6e+74) tmp = -c / b; elseif (b <= -1.1e-128) tmp = -0.5 * ((t_0 / (b - t_1)) / a); elseif (b <= 2.8e+128) tmp = -0.5 * ((b + t_1) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2.6e+74], N[((-c) / b), $MachinePrecision], If[LessEqual[b, -1.1e-128], N[(-0.5 * N[(N[(t$95$0 / N[(b - t$95$1), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.8e+128], N[(-0.5 * N[(N[(b + t$95$1), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 4\right)\\
t_1 := \sqrt{b \cdot b - t_0}\\
\mathbf{if}\;b \leq -2.6 \cdot 10^{+74}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq -1.1 \cdot 10^{-128}:\\
\;\;\;\;-0.5 \cdot \frac{\frac{t_0}{b - t_1}}{a}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{+128}:\\
\;\;\;\;-0.5 \cdot \frac{b + t_1}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.6000000000000001e74Initial program 6.1%
*-commutative6.1%
sqr-neg6.1%
*-commutative6.1%
sqr-neg6.1%
associate-*r*6.1%
*-commutative6.1%
Simplified6.1%
Taylor expanded in b around -inf 94.2%
mul-1-neg94.2%
distribute-neg-frac94.2%
Simplified94.2%
if -2.6000000000000001e74 < b < -1.10000000000000005e-128Initial program 37.3%
sub-neg37.3%
distribute-neg-out37.3%
neg-mul-137.3%
times-frac37.3%
metadata-eval37.3%
remove-double-neg37.3%
neg-sub037.3%
associate-+l-37.3%
Simplified37.3%
fma-udef37.3%
*-commutative37.3%
metadata-eval37.3%
cancel-sign-sub-inv37.3%
associate-*l*37.3%
prod-diff37.1%
*-commutative37.1%
fma-neg37.1%
associate-+l-37.1%
Applied egg-rr37.1%
associate--r+37.1%
+-inverses37.3%
neg-sub037.3%
associate-*r*37.3%
distribute-rgt-neg-in37.3%
metadata-eval37.3%
*-commutative37.3%
associate-*r*37.3%
Simplified37.3%
flip-+37.1%
add-sqr-sqrt37.0%
Applied egg-rr37.0%
associate-+l-78.2%
Simplified78.2%
Taylor expanded in b around 0 78.2%
if -1.10000000000000005e-128 < b < 2.79999999999999983e128Initial program 86.3%
sub-neg86.3%
distribute-neg-out86.3%
neg-mul-186.3%
times-frac86.3%
metadata-eval86.3%
remove-double-neg86.3%
neg-sub086.3%
associate-+l-86.3%
Simplified86.3%
fma-udef86.3%
*-commutative86.3%
metadata-eval86.3%
cancel-sign-sub-inv86.3%
associate-*l*86.4%
prod-diff86.2%
*-commutative86.2%
fma-neg86.2%
associate-+l-86.2%
Applied egg-rr86.2%
associate--r+86.2%
+-inverses86.4%
neg-sub086.4%
associate-*r*86.3%
distribute-rgt-neg-in86.3%
metadata-eval86.3%
*-commutative86.3%
associate-*r*86.4%
Simplified86.4%
if 2.79999999999999983e128 < b Initial program 60.3%
*-commutative60.3%
sqr-neg60.3%
*-commutative60.3%
sqr-neg60.3%
associate-*r*60.3%
*-commutative60.3%
Simplified60.3%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e-107)
(/ (- c) b)
(if (<= b 1e+128)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* a 4.0))))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-107) {
tmp = -c / b;
} else if (b <= 1e+128) {
tmp = -0.5 * ((b + sqrt(((b * b) - (c * (a * 4.0))))) / a);
} else {
tmp = -b / 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) :: tmp
if (b <= (-7.2d-107)) then
tmp = -c / b
else if (b <= 1d+128) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - (c * (a * 4.0d0))))) / a)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-107) {
tmp = -c / b;
} else if (b <= 1e+128) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - (c * (a * 4.0))))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e-107: tmp = -c / b elif b <= 1e+128: tmp = -0.5 * ((b + math.sqrt(((b * b) - (c * (a * 4.0))))) / a) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-107) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+128) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0))))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.2e-107) tmp = -c / b; elseif (b <= 1e+128) tmp = -0.5 * ((b + sqrt(((b * b) - (c * (a * 4.0))))) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-107], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+128], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-107}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+128}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.19999999999999953e-107Initial program 19.0%
*-commutative19.0%
sqr-neg19.0%
*-commutative19.0%
sqr-neg19.0%
associate-*r*19.0%
*-commutative19.0%
Simplified19.0%
Taylor expanded in b around -inf 82.2%
mul-1-neg82.2%
distribute-neg-frac82.2%
Simplified82.2%
if -7.19999999999999953e-107 < b < 1.0000000000000001e128Initial program 86.0%
sub-neg86.0%
distribute-neg-out86.0%
neg-mul-186.0%
times-frac86.0%
metadata-eval86.0%
remove-double-neg86.0%
neg-sub086.0%
associate-+l-86.0%
Simplified86.0%
fma-udef86.0%
*-commutative86.0%
metadata-eval86.0%
cancel-sign-sub-inv86.0%
associate-*l*86.0%
prod-diff85.8%
*-commutative85.8%
fma-neg85.8%
associate-+l-85.8%
Applied egg-rr85.8%
associate--r+85.8%
+-inverses86.0%
neg-sub086.0%
associate-*r*86.0%
distribute-rgt-neg-in86.0%
metadata-eval86.0%
*-commutative86.0%
associate-*r*86.0%
Simplified86.0%
if 1.0000000000000001e128 < b Initial program 60.3%
*-commutative60.3%
sqr-neg60.3%
*-commutative60.3%
sqr-neg60.3%
associate-*r*60.3%
*-commutative60.3%
Simplified60.3%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.55e-106)
(/ (- c) b)
(if (<= b 1.6e-51)
(* -0.5 (/ (+ b (sqrt (* a (* c -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-106) {
tmp = -c / b;
} else if (b <= 1.6e-51) {
tmp = -0.5 * ((b + sqrt((a * (c * -4.0)))) / a);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-1.55d-106)) then
tmp = -c / b
else if (b <= 1.6d-51) then
tmp = (-0.5d0) * ((b + sqrt((a * (c * (-4.0d0))))) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-106) {
tmp = -c / b;
} else if (b <= 1.6e-51) {
tmp = -0.5 * ((b + Math.sqrt((a * (c * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.55e-106: tmp = -c / b elif b <= 1.6e-51: tmp = -0.5 * ((b + math.sqrt((a * (c * -4.0)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.55e-106) tmp = Float64(Float64(-c) / b); elseif (b <= 1.6e-51) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.55e-106) tmp = -c / b; elseif (b <= 1.6e-51) tmp = -0.5 * ((b + sqrt((a * (c * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.55e-106], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.6e-51], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.55 \cdot 10^{-106}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-51}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.54999999999999993e-106Initial program 19.0%
*-commutative19.0%
sqr-neg19.0%
*-commutative19.0%
sqr-neg19.0%
associate-*r*19.0%
*-commutative19.0%
Simplified19.0%
Taylor expanded in b around -inf 82.2%
mul-1-neg82.2%
distribute-neg-frac82.2%
Simplified82.2%
if -1.54999999999999993e-106 < b < 1.6e-51Initial program 80.6%
sub-neg80.6%
distribute-neg-out80.6%
neg-mul-180.6%
times-frac80.6%
metadata-eval80.6%
remove-double-neg80.6%
neg-sub080.6%
associate-+l-80.6%
Simplified80.6%
Taylor expanded in b around 0 67.8%
*-commutative67.8%
associate-*r*67.9%
Simplified67.9%
if 1.6e-51 < b Initial program 75.3%
*-commutative75.3%
sqr-neg75.3%
*-commutative75.3%
sqr-neg75.3%
associate-*r*75.3%
*-commutative75.3%
Simplified75.3%
Taylor expanded in b around inf 95.0%
+-commutative95.0%
mul-1-neg95.0%
unsub-neg95.0%
Simplified95.0%
Final simplification83.0%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-4d-310)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 31.9%
*-commutative31.9%
sqr-neg31.9%
*-commutative31.9%
sqr-neg31.9%
associate-*r*31.9%
*-commutative31.9%
Simplified31.9%
Taylor expanded in b around -inf 68.9%
mul-1-neg68.9%
distribute-neg-frac68.9%
Simplified68.9%
if -3.999999999999988e-310 < b Initial program 76.9%
*-commutative76.9%
sqr-neg76.9%
*-commutative76.9%
sqr-neg76.9%
associate-*r*76.9%
*-commutative76.9%
Simplified76.9%
Taylor expanded in b around inf 73.2%
+-commutative73.2%
mul-1-neg73.2%
unsub-neg73.2%
Simplified73.2%
Final simplification71.2%
(FPCore (a b c) :precision binary64 (if (<= b -2.45e+61) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.45e+61) {
tmp = c / b;
} else {
tmp = -b / 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) :: tmp
if (b <= (-2.45d+61)) then
tmp = c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.45e+61) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.45e+61: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.45e+61) tmp = Float64(c / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.45e+61) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.45e+61], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.45 \cdot 10^{+61}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.45000000000000013e61Initial program 13.0%
*-commutative13.0%
sqr-neg13.0%
*-commutative13.0%
sqr-neg13.0%
associate-*r*13.0%
*-commutative13.0%
Simplified13.0%
clear-num13.0%
associate-/r/13.0%
*-commutative13.0%
associate-/r*13.0%
metadata-eval13.0%
add-sqr-sqrt7.3%
cancel-sign-sub-inv7.3%
add-sqr-sqrt12.9%
sqrt-unprod6.2%
sqr-neg6.2%
sqrt-prod0.0%
add-sqr-sqrt5.5%
Applied egg-rr5.2%
flip--3.7%
hypot-udef3.7%
hypot-udef3.7%
add-sqr-sqrt3.7%
add-sqr-sqrt3.7%
fma-def3.7%
Applied egg-rr3.7%
associate-*r*3.7%
metadata-eval3.7%
distribute-rgt-neg-in3.7%
*-commutative3.7%
associate-*r*3.7%
fma-neg3.7%
associate-+l-3.8%
+-inverses4.4%
associate-*r*4.4%
*-commutative4.4%
associate-*l*4.4%
Simplified4.4%
Taylor expanded in a around 0 39.2%
if -2.45000000000000013e61 < b Initial program 67.3%
*-commutative67.3%
sqr-neg67.3%
*-commutative67.3%
sqr-neg67.3%
associate-*r*67.3%
*-commutative67.3%
Simplified67.3%
Taylor expanded in b around inf 50.0%
associate-*r/50.0%
mul-1-neg50.0%
Simplified50.0%
Final simplification47.7%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = -b / 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) :: tmp
if (b <= (-4d-310)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 31.9%
*-commutative31.9%
sqr-neg31.9%
*-commutative31.9%
sqr-neg31.9%
associate-*r*31.9%
*-commutative31.9%
Simplified31.9%
Taylor expanded in b around -inf 68.9%
mul-1-neg68.9%
distribute-neg-frac68.9%
Simplified68.9%
if -3.999999999999988e-310 < b Initial program 76.9%
*-commutative76.9%
sqr-neg76.9%
*-commutative76.9%
sqr-neg76.9%
associate-*r*76.9%
*-commutative76.9%
Simplified76.9%
Taylor expanded in b around inf 72.9%
associate-*r/72.9%
mul-1-neg72.9%
Simplified72.9%
Final simplification71.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 55.8%
*-commutative55.8%
sqr-neg55.8%
*-commutative55.8%
sqr-neg55.8%
associate-*r*55.8%
*-commutative55.8%
Simplified55.8%
clear-num55.7%
associate-/r/55.7%
*-commutative55.7%
associate-/r*55.7%
metadata-eval55.7%
add-sqr-sqrt54.4%
cancel-sign-sub-inv54.4%
add-sqr-sqrt14.9%
sqrt-unprod25.6%
sqr-neg25.6%
sqrt-prod20.5%
add-sqr-sqrt33.2%
Applied egg-rr24.4%
Taylor expanded in b around -inf 2.5%
Final simplification2.5%
(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 / 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 55.8%
*-commutative55.8%
sqr-neg55.8%
*-commutative55.8%
sqr-neg55.8%
associate-*r*55.8%
*-commutative55.8%
Simplified55.8%
clear-num55.7%
associate-/r/55.7%
*-commutative55.7%
associate-/r*55.7%
metadata-eval55.7%
add-sqr-sqrt54.4%
cancel-sign-sub-inv54.4%
add-sqr-sqrt14.9%
sqrt-unprod25.6%
sqr-neg25.6%
sqrt-prod20.5%
add-sqr-sqrt33.2%
Applied egg-rr24.4%
flip--23.3%
hypot-udef23.3%
hypot-udef23.3%
add-sqr-sqrt23.3%
add-sqr-sqrt23.3%
fma-def23.3%
Applied egg-rr23.3%
associate-*r*23.3%
metadata-eval23.3%
distribute-rgt-neg-in23.3%
*-commutative23.3%
associate-*r*23.3%
fma-neg23.3%
associate-+l-23.7%
+-inverses24.0%
associate-*r*24.0%
*-commutative24.0%
associate-*l*24.0%
Simplified24.0%
Taylor expanded in a around 0 10.5%
Final simplification10.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2023277
(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)))