
(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 7 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
(if (<= b -1e+153)
(/ (- b) a)
(if (<= b 2e-54)
(/ (* (- b (sqrt (- (* b b) (* a (* c 4.0))))) -0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = -b / a;
} else if (b <= 2e-54) {
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / 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 <= (-1d+153)) then
tmp = -b / a
else if (b <= 2d-54) then
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0d0))))) * (-0.5d0)) / 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 <= -1e+153) {
tmp = -b / a;
} else if (b <= 2e-54) {
tmp = ((b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+153: tmp = -b / a elif b <= 2e-54: tmp = ((b - math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+153) tmp = Float64(Float64(-b) / a); elseif (b <= 2e-54) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * -0.5) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+153) tmp = -b / a; elseif (b <= 2e-54) tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+153], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2e-54], N[(N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-54}:\\
\;\;\;\;\frac{\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot -0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1e153Initial program 38.9%
neg-sub038.9%
associate-+l-38.9%
sub0-neg38.9%
neg-mul-138.9%
*-commutative38.9%
associate-*r/38.9%
Simplified38.9%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1e153 < b < 2.0000000000000001e-54Initial program 84.4%
neg-sub084.4%
associate-+l-84.4%
sub0-neg84.4%
neg-mul-184.4%
*-commutative84.4%
associate-*r/84.3%
Simplified84.3%
fma-udef84.3%
associate-*r*84.3%
metadata-eval84.3%
distribute-rgt-neg-in84.3%
*-commutative84.3%
+-commutative84.3%
sub-neg84.3%
*-commutative84.3%
associate-*l*84.3%
Applied egg-rr84.3%
associate-*r/84.4%
Applied egg-rr84.4%
if 2.0000000000000001e-54 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
*-commutative15.9%
associate-*r/15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification89.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- b) a)) (t_1 (* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))))
(if (<= b -1.32e-43)
t_0
(if (<= b -6.2e-106)
t_1
(if (<= b -1.32e-129) t_0 (if (<= b 3.9e-55) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = -b / a;
double t_1 = (-0.5 / a) * (b - sqrt((a * (c * -4.0))));
double tmp;
if (b <= -1.32e-43) {
tmp = t_0;
} else if (b <= -6.2e-106) {
tmp = t_1;
} else if (b <= -1.32e-129) {
tmp = t_0;
} else if (b <= 3.9e-55) {
tmp = t_1;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = -b / a
t_1 = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.0d0)))))
if (b <= (-1.32d-43)) then
tmp = t_0
else if (b <= (-6.2d-106)) then
tmp = t_1
else if (b <= (-1.32d-129)) then
tmp = t_0
else if (b <= 3.9d-55) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = -b / a;
double t_1 = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
double tmp;
if (b <= -1.32e-43) {
tmp = t_0;
} else if (b <= -6.2e-106) {
tmp = t_1;
} else if (b <= -1.32e-129) {
tmp = t_0;
} else if (b <= 3.9e-55) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = -b / a t_1 = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) tmp = 0 if b <= -1.32e-43: tmp = t_0 elif b <= -6.2e-106: tmp = t_1 elif b <= -1.32e-129: tmp = t_0 elif b <= 3.9e-55: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(-b) / a) t_1 = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))) tmp = 0.0 if (b <= -1.32e-43) tmp = t_0; elseif (b <= -6.2e-106) tmp = t_1; elseif (b <= -1.32e-129) tmp = t_0; elseif (b <= 3.9e-55) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = -b / a; t_1 = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); tmp = 0.0; if (b <= -1.32e-43) tmp = t_0; elseif (b <= -6.2e-106) tmp = t_1; elseif (b <= -1.32e-129) tmp = t_0; elseif (b <= 3.9e-55) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-b) / a), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.32e-43], t$95$0, If[LessEqual[b, -6.2e-106], t$95$1, If[LessEqual[b, -1.32e-129], t$95$0, If[LessEqual[b, 3.9e-55], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-b}{a}\\
t_1 := \frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{if}\;b \leq -1.32 \cdot 10^{-43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -6.2 \cdot 10^{-106}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -1.32 \cdot 10^{-129}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 3.9 \cdot 10^{-55}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.32000000000000002e-43 or -6.19999999999999971e-106 < b < -1.31999999999999992e-129Initial program 66.3%
neg-sub066.3%
associate-+l-66.3%
sub0-neg66.3%
neg-mul-166.3%
*-commutative66.3%
associate-*r/66.1%
Simplified66.1%
Taylor expanded in b around -inf 86.3%
associate-*r/86.3%
mul-1-neg86.3%
Simplified86.3%
if -1.32000000000000002e-43 < b < -6.19999999999999971e-106 or -1.31999999999999992e-129 < b < 3.9e-55Initial program 80.6%
neg-sub080.6%
associate-+l-80.6%
sub0-neg80.6%
neg-mul-180.6%
*-commutative80.6%
associate-*r/80.6%
Simplified80.6%
Taylor expanded in a around inf 76.7%
*-commutative76.7%
*-commutative76.7%
associate-*r*76.7%
Simplified76.7%
if 3.9e-55 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
*-commutative15.9%
associate-*r/15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification85.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.22e+126)
(/ (- b) a)
(if (<= b 1.95e-51)
(* (- b (sqrt (- (* b b) (* a (* c 4.0))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e+126) {
tmp = -b / a;
} else if (b <= 1.95e-51) {
tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / 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 <= (-1.22d+126)) then
tmp = -b / a
else if (b <= 1.95d-51) then
tmp = (b - sqrt(((b * b) - (a * (c * 4.0d0))))) * ((-0.5d0) / 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 <= -1.22e+126) {
tmp = -b / a;
} else if (b <= 1.95e-51) {
tmp = (b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.22e+126: tmp = -b / a elif b <= 1.95e-51: tmp = (b - math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.22e+126) tmp = Float64(Float64(-b) / a); elseif (b <= 1.95e-51) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.22e+126) tmp = -b / a; elseif (b <= 1.95e-51) tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.22e+126], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.95e-51], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.22 \cdot 10^{+126}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.95 \cdot 10^{-51}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.21999999999999995e126Initial program 48.1%
neg-sub048.1%
associate-+l-48.1%
sub0-neg48.1%
neg-mul-148.1%
*-commutative48.1%
associate-*r/48.1%
Simplified48.1%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.21999999999999995e126 < b < 1.9499999999999999e-51Initial program 83.4%
neg-sub083.4%
associate-+l-83.4%
sub0-neg83.4%
neg-mul-183.4%
*-commutative83.4%
associate-*r/83.3%
Simplified83.3%
fma-udef83.3%
associate-*r*83.3%
metadata-eval83.3%
distribute-rgt-neg-in83.3%
*-commutative83.3%
+-commutative83.3%
sub-neg83.3%
*-commutative83.3%
associate-*l*83.3%
Applied egg-rr83.3%
if 1.9499999999999999e-51 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
*-commutative15.9%
associate-*r/15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification89.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.32e-129)
(/ (- b) a)
(if (<= b 7.4e-54)
(* -0.5 (/ (- (sqrt (* c (/ a -0.25)))) a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.32e-129) {
tmp = -b / a;
} else if (b <= 7.4e-54) {
tmp = -0.5 * (-sqrt((c * (a / -0.25))) / 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 <= (-1.32d-129)) then
tmp = -b / a
else if (b <= 7.4d-54) then
tmp = (-0.5d0) * (-sqrt((c * (a / (-0.25d0)))) / 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 <= -1.32e-129) {
tmp = -b / a;
} else if (b <= 7.4e-54) {
tmp = -0.5 * (-Math.sqrt((c * (a / -0.25))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.32e-129: tmp = -b / a elif b <= 7.4e-54: tmp = -0.5 * (-math.sqrt((c * (a / -0.25))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.32e-129) tmp = Float64(Float64(-b) / a); elseif (b <= 7.4e-54) tmp = Float64(-0.5 * Float64(Float64(-sqrt(Float64(c * Float64(a / -0.25)))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.32e-129) tmp = -b / a; elseif (b <= 7.4e-54) tmp = -0.5 * (-sqrt((c * (a / -0.25))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.32e-129], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 7.4e-54], N[(-0.5 * N[((-N[Sqrt[N[(c * N[(a / -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.32 \cdot 10^{-129}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 7.4 \cdot 10^{-54}:\\
\;\;\;\;-0.5 \cdot \frac{-\sqrt{c \cdot \frac{a}{-0.25}}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.31999999999999992e-129Initial program 68.5%
neg-sub068.5%
associate-+l-68.5%
sub0-neg68.5%
neg-mul-168.5%
*-commutative68.5%
associate-*r/68.3%
Simplified68.3%
Taylor expanded in b around -inf 79.3%
associate-*r/79.3%
mul-1-neg79.3%
Simplified79.3%
if -1.31999999999999992e-129 < b < 7.4000000000000006e-54Initial program 79.9%
neg-sub079.9%
associate-+l-79.9%
sub0-neg79.9%
neg-mul-179.9%
*-commutative79.9%
associate-*r/79.8%
Simplified79.8%
fma-udef79.8%
associate-*r*79.8%
metadata-eval79.8%
distribute-rgt-neg-in79.8%
*-commutative79.8%
+-commutative79.8%
sub-neg79.8%
add-sqr-sqrt79.4%
pow279.4%
Applied egg-rr79.5%
Taylor expanded in c around -inf 44.6%
unpow244.6%
exp-prod43.5%
exp-prod42.7%
pow-sqr42.7%
mul-1-neg42.7%
unsub-neg42.7%
*-commutative42.7%
Simplified42.7%
Taylor expanded in b around 0 44.0%
Simplified78.9%
if 7.4000000000000006e-54 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
*-commutative15.9%
associate-*r/15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification83.5%
(FPCore (a b c) :precision binary64 (if (<= b 2.05e-203) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.05e-203) {
tmp = -b / a;
} else {
tmp = 0.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 (b <= 2.05d-203) then
tmp = -b / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.05e-203) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.05e-203: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.05e-203) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.05e-203) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.05e-203], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.05 \cdot 10^{-203}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < 2.0499999999999999e-203Initial program 72.7%
neg-sub072.7%
associate-+l-72.7%
sub0-neg72.7%
neg-mul-172.7%
*-commutative72.7%
associate-*r/72.6%
Simplified72.6%
Taylor expanded in b around -inf 57.4%
associate-*r/57.4%
mul-1-neg57.4%
Simplified57.4%
if 2.0499999999999999e-203 < b Initial program 29.0%
neg-sub029.0%
associate-+l-29.0%
sub0-neg29.0%
neg-mul-129.0%
*-commutative29.0%
associate-*r/28.9%
Simplified28.9%
*-commutative28.9%
sub-neg28.9%
distribute-lft-in26.8%
Applied egg-rr26.8%
Taylor expanded in a around 0 19.2%
distribute-rgt-out19.2%
metadata-eval19.2%
metadata-eval19.2%
associate-*l/14.8%
metadata-eval14.8%
mul0-rgt19.2%
Simplified19.2%
Final simplification42.2%
(FPCore (a b c) :precision binary64 (if (<= b 7.6e-300) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.6e-300) {
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 <= 7.6d-300) 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 <= 7.6e-300) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.6e-300: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.6e-300) 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 <= 7.6e-300) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.6e-300], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.6 \cdot 10^{-300}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 7.60000000000000026e-300Initial program 72.5%
neg-sub072.5%
associate-+l-72.5%
sub0-neg72.5%
neg-mul-172.5%
*-commutative72.5%
associate-*r/72.3%
Simplified72.3%
Taylor expanded in b around -inf 65.0%
associate-*r/65.0%
mul-1-neg65.0%
Simplified65.0%
if 7.60000000000000026e-300 < b Initial program 36.1%
neg-sub036.1%
associate-+l-36.1%
sub0-neg36.1%
neg-mul-136.1%
*-commutative36.1%
associate-*r/36.1%
Simplified36.1%
Taylor expanded in b around inf 68.0%
associate-*r/68.0%
neg-mul-168.0%
Simplified68.0%
Final simplification66.4%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 55.3%
neg-sub055.3%
associate-+l-55.3%
sub0-neg55.3%
neg-mul-155.3%
*-commutative55.3%
associate-*r/55.2%
Simplified55.2%
*-commutative55.2%
sub-neg55.2%
distribute-lft-in54.4%
Applied egg-rr54.4%
Taylor expanded in a around 0 9.4%
distribute-rgt-out9.4%
metadata-eval9.4%
metadata-eval9.4%
associate-*l/7.5%
metadata-eval7.5%
mul0-rgt9.4%
Simplified9.4%
Final simplification9.4%
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023230
(FPCore (a b c)
:name "quadp (p42, positive)"
: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)))