
(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 (* (* a 4.0) c)))
(if (<= b -4e+154)
(/ (- b) a)
(if (<= b 8.5e-119)
(/ (- (sqrt (- (* b b) t_0)) b) (* a 2.0))
(if (or (<= b 6.5e-61) (not (<= b 2.9e-34)))
(/ (- c) b)
(/
(-
(sqrt (+ (pow b 2.0) (fma a (* c -4.0) (fma a (* c -4.0) t_0))))
b)
(* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = (a * 4.0) * c;
double tmp;
if (b <= -4e+154) {
tmp = -b / a;
} else if (b <= 8.5e-119) {
tmp = (sqrt(((b * b) - t_0)) - b) / (a * 2.0);
} else if ((b <= 6.5e-61) || !(b <= 2.9e-34)) {
tmp = -c / b;
} else {
tmp = (sqrt((pow(b, 2.0) + fma(a, (c * -4.0), fma(a, (c * -4.0), t_0)))) - b) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(Float64(a * 4.0) * c) tmp = 0.0 if (b <= -4e+154) tmp = Float64(Float64(-b) / a); elseif (b <= 8.5e-119) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(a * 2.0)); elseif ((b <= 6.5e-61) || !(b <= 2.9e-34)) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(sqrt(Float64((b ^ 2.0) + fma(a, Float64(c * -4.0), fma(a, Float64(c * -4.0), t_0)))) - b) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]}, If[LessEqual[b, -4e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 8.5e-119], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 6.5e-61], N[Not[LessEqual[b, 2.9e-34]], $MachinePrecision]], N[((-c) / b), $MachinePrecision], N[(N[(N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(a \cdot 4\right) \cdot c\\
\mathbf{if}\;b \leq -4 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-119}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - t_0} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{-61} \lor \neg \left(b \leq 2.9 \cdot 10^{-34}\right):\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, t_0\right)\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4.00000000000000015e154Initial program 41.2%
*-commutative41.2%
Simplified41.2%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -4.00000000000000015e154 < b < 8.49999999999999977e-119Initial program 82.0%
if 8.49999999999999977e-119 < b < 6.4999999999999994e-61 or 2.9000000000000002e-34 < b Initial program 17.4%
*-commutative17.4%
Simplified17.4%
Taylor expanded in b around inf 86.6%
mul-1-neg86.6%
distribute-neg-frac86.6%
Simplified86.6%
if 6.4999999999999994e-61 < b < 2.9000000000000002e-34Initial program 86.2%
*-commutative86.2%
Simplified86.2%
prod-diff86.2%
*-commutative86.2%
fma-def86.2%
associate-+l+86.2%
pow286.2%
distribute-lft-neg-in86.2%
*-commutative86.2%
distribute-rgt-neg-in86.2%
metadata-eval86.2%
associate-*r*86.2%
*-commutative86.2%
*-commutative86.2%
fma-udef86.2%
Applied egg-rr86.2%
fma-def86.2%
fma-def86.4%
associate-*l*86.4%
Simplified86.4%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4e+152)
(/ (- b) a)
(if (or (<= b 8.5e-119) (and (not (<= b 5.5e-61)) (<= b 3.1e-34)))
(/ (- (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 <= -4e+152) {
tmp = -b / a;
} else if ((b <= 8.5e-119) || (!(b <= 5.5e-61) && (b <= 3.1e-34))) {
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 <= (-4d+152)) then
tmp = -b / a
else if ((b <= 8.5d-119) .or. (.not. (b <= 5.5d-61)) .and. (b <= 3.1d-34)) 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 <= -4e+152) {
tmp = -b / a;
} else if ((b <= 8.5e-119) || (!(b <= 5.5e-61) && (b <= 3.1e-34))) {
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 <= -4e+152: tmp = -b / a elif (b <= 8.5e-119) or (not (b <= 5.5e-61) and (b <= 3.1e-34)): 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 <= -4e+152) tmp = Float64(Float64(-b) / a); elseif ((b <= 8.5e-119) || (!(b <= 5.5e-61) && (b <= 3.1e-34))) 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 <= -4e+152) tmp = -b / a; elseif ((b <= 8.5e-119) || (~((b <= 5.5e-61)) && (b <= 3.1e-34))) 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, -4e+152], N[((-b) / a), $MachinePrecision], If[Or[LessEqual[b, 8.5e-119], And[N[Not[LessEqual[b, 5.5e-61]], $MachinePrecision], LessEqual[b, 3.1e-34]]], 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 -4 \cdot 10^{+152}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-119} \lor \neg \left(b \leq 5.5 \cdot 10^{-61}\right) \land b \leq 3.1 \cdot 10^{-34}:\\
\;\;\;\;\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 < -4.0000000000000002e152Initial program 41.2%
*-commutative41.2%
Simplified41.2%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -4.0000000000000002e152 < b < 8.49999999999999977e-119 or 5.4999999999999997e-61 < b < 3.0999999999999998e-34Initial program 82.3%
if 8.49999999999999977e-119 < b < 5.4999999999999997e-61 or 3.0999999999999998e-34 < b Initial program 17.4%
*-commutative17.4%
Simplified17.4%
Taylor expanded in b around inf 86.6%
mul-1-neg86.6%
distribute-neg-frac86.6%
Simplified86.6%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.15e-81)
(/ (- b) a)
(if (<= b 3.6e-119)
(* (/ -0.5 a) (- b (sqrt (* -4.0 (* a c)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-81) {
tmp = -b / a;
} else if (b <= 3.6e-119) {
tmp = (-0.5 / a) * (b - sqrt((-4.0 * (a * c))));
} 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.15d-81)) then
tmp = -b / a
else if (b <= 3.6d-119) then
tmp = ((-0.5d0) / a) * (b - sqrt(((-4.0d0) * (a * c))))
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.15e-81) {
tmp = -b / a;
} else if (b <= 3.6e-119) {
tmp = (-0.5 / a) * (b - Math.sqrt((-4.0 * (a * c))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.15e-81: tmp = -b / a elif b <= 3.6e-119: tmp = (-0.5 / a) * (b - math.sqrt((-4.0 * (a * c)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.15e-81) tmp = Float64(Float64(-b) / a); elseif (b <= 3.6e-119) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(-4.0 * Float64(a * c))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.15e-81) tmp = -b / a; elseif (b <= 3.6e-119) tmp = (-0.5 / a) * (b - sqrt((-4.0 * (a * c)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.15e-81], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.6e-119], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{-81}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-119}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{-4 \cdot \left(a \cdot c\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.14999999999999996e-81Initial program 67.6%
*-commutative67.6%
Simplified67.6%
Taylor expanded in b around -inf 87.4%
associate-*r/87.4%
mul-1-neg87.4%
Simplified87.4%
if -1.14999999999999996e-81 < b < 3.6e-119Initial program 73.9%
*-commutative73.9%
Simplified73.9%
Applied egg-rr73.7%
*-commutative73.7%
associate-/r*73.7%
metadata-eval73.7%
Simplified73.7%
pow1/273.7%
metadata-eval73.7%
pow-to-exp68.9%
metadata-eval68.9%
Applied egg-rr68.9%
Taylor expanded in a around -inf 46.9%
mul-1-neg46.9%
unsub-neg46.9%
*-commutative46.9%
Simplified46.9%
expm1-log1p-u23.8%
expm1-udef3.6%
Applied egg-rr21.6%
expm1-def45.3%
expm1-log1p70.9%
associate-/r/70.8%
/-rgt-identity70.8%
*-commutative70.8%
Simplified70.8%
if 3.6e-119 < b Initial program 22.1%
*-commutative22.1%
Simplified22.1%
Taylor expanded in b around inf 82.3%
mul-1-neg82.3%
distribute-neg-frac82.3%
Simplified82.3%
Final simplification81.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.2e-81) (/ (- b) a) (if (<= b 8e-121) (/ (- (sqrt (* -4.0 (* a c))) b) (* a 2.0)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-81) {
tmp = -b / a;
} else if (b <= 8e-121) {
tmp = (sqrt((-4.0 * (a * 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 <= (-1.2d-81)) then
tmp = -b / a
else if (b <= 8d-121) then
tmp = (sqrt(((-4.0d0) * (a * 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 <= -1.2e-81) {
tmp = -b / a;
} else if (b <= 8e-121) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-81: tmp = -b / a elif b <= 8e-121: tmp = (math.sqrt((-4.0 * (a * c))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e-81) tmp = Float64(Float64(-b) / a); elseif (b <= 8e-121) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * 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 <= -1.2e-81) tmp = -b / a; elseif (b <= 8e-121) tmp = (sqrt((-4.0 * (a * c))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e-81], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 8e-121], N[(N[(N[Sqrt[N[(-4.0 * N[(a * 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 -1.2 \cdot 10^{-81}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-121}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.2e-81Initial program 67.6%
*-commutative67.6%
Simplified67.6%
Taylor expanded in b around -inf 87.4%
associate-*r/87.4%
mul-1-neg87.4%
Simplified87.4%
if -1.2e-81 < b < 7.9999999999999998e-121Initial program 73.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in b around 0 71.0%
if 7.9999999999999998e-121 < b Initial program 22.1%
*-commutative22.1%
Simplified22.1%
Taylor expanded in b around inf 82.3%
mul-1-neg82.3%
distribute-neg-frac82.3%
Simplified82.3%
Final simplification81.2%
(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 71.2%
*-commutative71.2%
Simplified71.2%
Taylor expanded in b around -inf 65.6%
+-commutative65.6%
mul-1-neg65.6%
unsub-neg65.6%
Simplified65.6%
if -4.999999999999985e-310 < b Initial program 31.8%
*-commutative31.8%
Simplified31.8%
Taylor expanded in b around inf 67.1%
mul-1-neg67.1%
distribute-neg-frac67.1%
Simplified67.1%
Final simplification66.4%
(FPCore (a b c) :precision binary64 (if (<= b -3.6e-304) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-304) {
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 <= (-3.6d-304)) 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 <= -3.6e-304) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e-304: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e-304) 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 <= -3.6e-304) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e-304], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.6 \cdot 10^{-304}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -3.6000000000000001e-304Initial program 70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in b around -inf 65.9%
associate-*r/65.9%
mul-1-neg65.9%
Simplified65.9%
if -3.6000000000000001e-304 < b Initial program 32.3%
*-commutative32.3%
Simplified32.3%
Applied egg-rr32.2%
*-commutative32.2%
associate-/r*32.2%
metadata-eval32.2%
Simplified32.2%
*-commutative32.2%
sub-neg32.2%
distribute-lft-in31.9%
Applied egg-rr31.9%
Taylor expanded in c around 0 15.1%
distribute-rgt-out15.1%
metadata-eval15.1%
mul0-rgt18.7%
Simplified18.7%
Final simplification41.4%
(FPCore (a b c) :precision binary64 (if (<= b 6.5e-299) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.5e-299) {
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 <= 6.5d-299) 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 <= 6.5e-299) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6.5e-299: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6.5e-299) 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 <= 6.5e-299) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6.5e-299], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.5 \cdot 10^{-299}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 6.4999999999999997e-299Initial program 70.1%
*-commutative70.1%
Simplified70.1%
Taylor expanded in b around -inf 64.5%
associate-*r/64.5%
mul-1-neg64.5%
Simplified64.5%
if 6.4999999999999997e-299 < b Initial program 32.2%
*-commutative32.2%
Simplified32.2%
Taylor expanded in b around inf 68.1%
mul-1-neg68.1%
distribute-neg-frac68.1%
Simplified68.1%
Final simplification66.3%
(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 50.9%
*-commutative50.9%
Simplified50.9%
Applied egg-rr50.8%
*-commutative50.8%
associate-/r*50.8%
metadata-eval50.8%
Simplified50.8%
*-commutative50.8%
sub-neg50.8%
distribute-lft-in50.6%
Applied egg-rr50.6%
Taylor expanded in c around 0 9.0%
distribute-rgt-out9.0%
metadata-eval9.0%
mul0-rgt11.0%
Simplified11.0%
Final simplification11.0%
herbie shell --seed 2023332
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))