
(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 (* c (* a 4.0))))
(if (<= b -4e+117)
(- (/ c b) (/ b a))
(if (<= b 1.15e-116)
(/ (- (sqrt (- (* b b) t_0)) b) (* a 2.0))
(if (<= b 3.3e+38)
(* (/ t_0 (+ b (hypot b (sqrt (* (* c a) -4.0))))) (/ -0.5 a))
(/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double tmp;
if (b <= -4e+117) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-116) {
tmp = (sqrt(((b * b) - t_0)) - b) / (a * 2.0);
} else if (b <= 3.3e+38) {
tmp = (t_0 / (b + hypot(b, sqrt(((c * a) * -4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double tmp;
if (b <= -4e+117) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-116) {
tmp = (Math.sqrt(((b * b) - t_0)) - b) / (a * 2.0);
} else if (b <= 3.3e+38) {
tmp = (t_0 / (b + Math.hypot(b, Math.sqrt(((c * a) * -4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = c * (a * 4.0) tmp = 0 if b <= -4e+117: tmp = (c / b) - (b / a) elif b <= 1.15e-116: tmp = (math.sqrt(((b * b) - t_0)) - b) / (a * 2.0) elif b <= 3.3e+38: tmp = (t_0 / (b + math.hypot(b, math.sqrt(((c * a) * -4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(c * Float64(a * 4.0)) tmp = 0.0 if (b <= -4e+117) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.15e-116) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(a * 2.0)); elseif (b <= 3.3e+38) tmp = Float64(Float64(t_0 / Float64(b + hypot(b, sqrt(Float64(Float64(c * a) * -4.0))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (a * 4.0); tmp = 0.0; if (b <= -4e+117) tmp = (c / b) - (b / a); elseif (b <= 1.15e-116) tmp = (sqrt(((b * b) - t_0)) - b) / (a * 2.0); elseif (b <= 3.3e+38) tmp = (t_0 / (b + hypot(b, sqrt(((c * a) * -4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4e+117], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-116], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.3e+38], N[(N[(t$95$0 / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 4\right)\\
\mathbf{if}\;b \leq -4 \cdot 10^{+117}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-116}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - t_0} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{+38}:\\
\;\;\;\;\frac{t_0}{b + \mathsf{hypot}\left(b, \sqrt{\left(c \cdot a\right) \cdot -4}\right)} \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.0000000000000002e117Initial program 47.7%
Taylor expanded in b around -inf 96.8%
mul-1-neg96.8%
unsub-neg96.8%
Simplified96.8%
if -4.0000000000000002e117 < b < 1.15000000000000001e-116Initial program 86.5%
if 1.15000000000000001e-116 < b < 3.2999999999999999e38Initial program 49.1%
frac-2neg49.1%
div-inv49.1%
Applied egg-rr48.7%
*-commutative48.7%
associate-/r*48.7%
metadata-eval48.7%
Simplified48.7%
flip--48.2%
hypot-udef48.2%
hypot-udef48.2%
add-sqr-sqrt48.2%
add-sqr-sqrt48.3%
Applied egg-rr48.3%
associate--r+66.0%
+-inverses66.0%
rem-square-sqrt0.0%
unpow20.0%
neg-sub00.0%
distribute-lft-neg-in0.0%
neg-mul-10.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt66.0%
associate-*r*66.0%
neg-mul-166.0%
distribute-lft-neg-in66.0%
distribute-rgt-neg-in66.0%
metadata-eval66.0%
associate-*r*66.0%
*-commutative66.0%
associate-*r*66.0%
Simplified66.0%
if 3.2999999999999999e38 < b Initial program 12.2%
Taylor expanded in b around inf 90.5%
associate-*r/90.5%
neg-mul-190.5%
Simplified90.5%
Final simplification86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e+64)
(- (/ c b) (/ b a))
(if (or (<= b 4e-95) (and (not (<= b 3e-79)) (<= b 0.135)))
(* (/ -0.5 a) (- b (sqrt (+ (* b b) (* c (* a -4.0))))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+64) {
tmp = (c / b) - (b / a);
} else if ((b <= 4e-95) || (!(b <= 3e-79) && (b <= 0.135))) {
tmp = (-0.5 / a) * (b - sqrt(((b * b) + (c * (a * -4.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+64)) then
tmp = (c / b) - (b / a)
else if ((b <= 4d-95) .or. (.not. (b <= 3d-79)) .and. (b <= 0.135d0)) then
tmp = ((-0.5d0) / a) * (b - sqrt(((b * b) + (c * (a * (-4.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+64) {
tmp = (c / b) - (b / a);
} else if ((b <= 4e-95) || (!(b <= 3e-79) && (b <= 0.135))) {
tmp = (-0.5 / a) * (b - Math.sqrt(((b * b) + (c * (a * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e+64: tmp = (c / b) - (b / a) elif (b <= 4e-95) or (not (b <= 3e-79) and (b <= 0.135)): tmp = (-0.5 / a) * (b - math.sqrt(((b * b) + (c * (a * -4.0))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e+64) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif ((b <= 4e-95) || (!(b <= 3e-79) && (b <= 0.135))) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -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+64) tmp = (c / b) - (b / a); elseif ((b <= 4e-95) || (~((b <= 3e-79)) && (b <= 0.135))) tmp = (-0.5 / a) * (b - sqrt(((b * b) + (c * (a * -4.0))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e+64], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 4e-95], And[N[Not[LessEqual[b, 3e-79]], $MachinePrecision], LessEqual[b, 0.135]]], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] + 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^{+64}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-95} \lor \neg \left(b \leq 3 \cdot 10^{-79}\right) \land b \leq 0.135:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.80000000000000024e64Initial program 55.4%
Taylor expanded in b around -inf 97.3%
mul-1-neg97.3%
unsub-neg97.3%
Simplified97.3%
if -2.80000000000000024e64 < b < 3.99999999999999996e-95 or 3e-79 < b < 0.13500000000000001Initial program 81.4%
frac-2neg81.4%
div-inv81.2%
Applied egg-rr73.0%
*-commutative73.0%
associate-/r*73.0%
metadata-eval73.0%
Simplified73.0%
hypot-udef73.0%
add-sqr-sqrt81.2%
Applied egg-rr81.2%
if 3.99999999999999996e-95 < b < 3e-79 or 0.13500000000000001 < b Initial program 16.5%
Taylor expanded in b around inf 83.2%
associate-*r/83.2%
neg-mul-183.2%
Simplified83.2%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.06e+117)
(- (/ c b) (/ b a))
(if (or (<= b 1.7e-94) (and (not (<= b 6.3e-80)) (<= b 0.135)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.06e+117) {
tmp = (c / b) - (b / a);
} else if ((b <= 1.7e-94) || (!(b <= 6.3e-80) && (b <= 0.135))) {
tmp = (sqrt(((b * b) - (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 <= (-1.06d+117)) then
tmp = (c / b) - (b / a)
else if ((b <= 1.7d-94) .or. (.not. (b <= 6.3d-80)) .and. (b <= 0.135d0)) then
tmp = (sqrt(((b * b) - (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 <= -1.06e+117) {
tmp = (c / b) - (b / a);
} else if ((b <= 1.7e-94) || (!(b <= 6.3e-80) && (b <= 0.135))) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.06e+117: tmp = (c / b) - (b / a) elif (b <= 1.7e-94) or (not (b <= 6.3e-80) and (b <= 0.135)): tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.06e+117) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif ((b <= 1.7e-94) || (!(b <= 6.3e-80) && (b <= 0.135))) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - 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 <= -1.06e+117) tmp = (c / b) - (b / a); elseif ((b <= 1.7e-94) || (~((b <= 6.3e-80)) && (b <= 0.135))) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.06e+117], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 1.7e-94], And[N[Not[LessEqual[b, 6.3e-80]], $MachinePrecision], LessEqual[b, 0.135]]], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.06 \cdot 10^{+117}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-94} \lor \neg \left(b \leq 6.3 \cdot 10^{-80}\right) \land b \leq 0.135:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.06e117Initial program 47.7%
Taylor expanded in b around -inf 96.8%
mul-1-neg96.8%
unsub-neg96.8%
Simplified96.8%
if -1.06e117 < b < 1.6999999999999999e-94 or 6.29999999999999966e-80 < b < 0.13500000000000001Initial program 83.0%
if 1.6999999999999999e-94 < b < 6.29999999999999966e-80 or 0.13500000000000001 < b Initial program 16.5%
Taylor expanded in b around inf 83.2%
associate-*r/83.2%
neg-mul-183.2%
Simplified83.2%
Final simplification86.2%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e-78) (- (/ c b) (/ b a)) (if (<= b 2e-94) (/ (- (sqrt (* (* c a) -4.0)) b) (* a 2.0)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-78) {
tmp = (c / b) - (b / a);
} else if (b <= 2e-94) {
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 <= (-2.4d-78)) then
tmp = (c / b) - (b / a)
else if (b <= 2d-94) 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 <= -2.4e-78) {
tmp = (c / b) - (b / a);
} else if (b <= 2e-94) {
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 <= -2.4e-78: tmp = (c / b) - (b / a) elif b <= 2e-94: 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 <= -2.4e-78) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2e-94) tmp = Float64(Float64(sqrt(Float64(Float64(c * 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 <= -2.4e-78) tmp = (c / b) - (b / a); elseif (b <= 2e-94) 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, -2.4e-78], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2e-94], N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $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.4 \cdot 10^{-78}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-94}:\\
\;\;\;\;\frac{\sqrt{\left(c \cdot a\right) \cdot -4} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.4e-78Initial program 68.0%
Taylor expanded in b around -inf 93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -2.4e-78 < b < 1.9999999999999999e-94Initial program 80.2%
Taylor expanded in b around 0 71.7%
*-commutative71.7%
associate-*r*71.8%
Simplified71.8%
expm1-log1p-u51.4%
expm1-udef16.8%
neg-mul-116.8%
metadata-eval16.8%
fma-def16.8%
metadata-eval16.8%
*-commutative16.8%
Applied egg-rr16.8%
expm1-def51.4%
expm1-log1p71.8%
rem-log-exp5.8%
fma-udef5.8%
neg-mul-15.8%
prod-exp5.8%
*-commutative5.8%
prod-exp5.8%
rem-log-exp71.8%
unsub-neg71.8%
associate-*r*71.7%
*-commutative71.7%
Simplified71.7%
if 1.9999999999999999e-94 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -7.2e-71) (- (/ c b) (/ b a)) (if (<= b 7e-95) (/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-71) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-95) {
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 <= (-7.2d-71)) then
tmp = (c / b) - (b / a)
else if (b <= 7d-95) 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 <= -7.2e-71) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-95) {
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 <= -7.2e-71: tmp = (c / b) - (b / a) elif b <= 7e-95: 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 <= -7.2e-71) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 7e-95) 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 <= -7.2e-71) tmp = (c / b) - (b / a); elseif (b <= 7e-95) 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, -7.2e-71], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7e-95], 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 -7.2 \cdot 10^{-71}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-95}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.2e-71Initial program 68.0%
Taylor expanded in b around -inf 93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -7.2e-71 < b < 6.9999999999999994e-95Initial program 80.2%
Taylor expanded in b around 0 71.7%
*-commutative71.7%
associate-*r*71.8%
Simplified71.8%
pow1/271.8%
pow-to-exp67.2%
Applied egg-rr67.2%
*-un-lft-identity67.2%
+-commutative67.2%
exp-to-pow71.8%
*-commutative71.8%
Applied egg-rr71.8%
*-lft-identity71.8%
unsub-neg71.8%
unpow1/271.8%
Simplified71.8%
if 6.9999999999999994e-95 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 72.7%
Taylor expanded in b around -inf 76.4%
mul-1-neg76.4%
unsub-neg76.4%
Simplified76.4%
if -1.999999999999994e-310 < b Initial program 36.2%
Taylor expanded in b around inf 58.1%
associate-*r/58.1%
neg-mul-158.1%
Simplified58.1%
Final simplification67.2%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) 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 <= -2e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 72.7%
Taylor expanded in b around -inf 76.3%
associate-*r/76.3%
mul-1-neg76.3%
Simplified76.3%
if -1.999999999999994e-310 < b Initial program 36.2%
Taylor expanded in b around inf 58.1%
associate-*r/58.1%
neg-mul-158.1%
Simplified58.1%
Final simplification67.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 54.5%
Taylor expanded in b around -inf 39.6%
associate-*r/39.6%
mul-1-neg39.6%
Simplified39.6%
Final simplification39.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 2023279
(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)))