
(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)) (/ (* 2.0 c) (+ (- b) t_0)))))
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 = (2.0 * c) / (-b + t_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) :: 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 = (2.0d0 * c) / (-b + t_0)
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 = (2.0 * c) / (-b + t_0);
}
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 = (2.0 * c) / (-b + t_0) 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(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); 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 = (2.0 * c) / (-b + t_0); 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[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t_0}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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)) (/ (* 2.0 c) (+ (- b) t_0)))))
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 = (2.0 * c) / (-b + t_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) :: 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 = (2.0d0 * c) / (-b + t_0)
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 = (2.0 * c) / (-b + t_0);
}
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 = (2.0 * c) / (-b + t_0) 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(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); 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 = (2.0 * c) / (-b + t_0); 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[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t_0}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -5e+153)
(if (>= b 0.0)
(* -0.5 (/ (fma -2.0 (/ (* a c) b) (* b 2.0)) a))
(/ (* c 2.0) (fma -2.0 b (* (/ c b) (* a 2.0)))))
(if (<= b 9.5e+116)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ (* c 2.0) (- t_0 b)))
(/ (- b) a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -5e+153) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (fma(-2.0, ((a * c) / b), (b * 2.0)) / a);
} else {
tmp_2 = (c * 2.0) / fma(-2.0, b, ((c / b) * (a * 2.0)));
}
tmp_1 = tmp_2;
} else if (b <= 9.5e+116) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = (c * 2.0) / (t_0 - b);
}
tmp_1 = tmp_3;
} else {
tmp_1 = -b / a;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -5e+153) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-0.5 * Float64(fma(-2.0, Float64(Float64(a * c) / b), Float64(b * 2.0)) / a)); else tmp_2 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(Float64(c / b) * Float64(a * 2.0)))); end tmp_1 = tmp_2; elseif (b <= 9.5e+116) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp_3 = Float64(Float64(c * 2.0) / Float64(t_0 - b)); end tmp_1 = tmp_3; else tmp_1 = Float64(Float64(-b) / a); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5e+153], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(N[(c / b), $MachinePrecision] * N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 9.5e+116], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]], N[((-b) / a), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(-2, \frac{a \cdot c}{b}, b \cdot 2\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, \frac{c}{b} \cdot \left(a \cdot 2\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{+116}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_0 - b}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -5.00000000000000018e153Initial program 38.8%
Simplified38.8%
Taylor expanded in b around -inf 92.3%
fma-def92.3%
associate-/l*99.6%
Simplified99.6%
expm1-log1p-u97.3%
expm1-udef43.9%
associate-*r/43.9%
associate-*r/43.9%
div-inv43.9%
clear-num43.9%
Applied egg-rr43.9%
expm1-def97.6%
expm1-log1p99.9%
*-commutative99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in b around inf 99.9%
fma-def99.9%
*-commutative99.9%
Simplified99.9%
if -5.00000000000000018e153 < b < 9.5000000000000004e116Initial program 88.7%
if 9.5000000000000004e116 < b Initial program 42.5%
sqr-neg42.5%
sqr-neg42.5%
associate-*l*42.5%
*-commutative42.5%
associate-/l*42.5%
Simplified42.5%
Taylor expanded in b around inf 93.8%
associate-*r/93.8%
mul-1-neg93.8%
Simplified93.8%
Taylor expanded in b around inf 93.8%
Taylor expanded in a around 0 93.8%
associate-*r/93.8%
neg-mul-193.8%
Simplified93.8%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* a c) 4.0)))))
(if (<= b -5e+141)
(if (>= b 0.0)
(* -0.5 (/ (fma -2.0 (/ (* a c) b) (* b 2.0)) a))
(/ (* c 2.0) (fma -2.0 b (* (/ c b) (* a 2.0)))))
(if (<= b 4e+113)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ 2.0 (/ (- t_0 b) c)))
(/ (- b) a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((a * c) * 4.0)));
double tmp_1;
if (b <= -5e+141) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (fma(-2.0, ((a * c) / b), (b * 2.0)) / a);
} else {
tmp_2 = (c * 2.0) / fma(-2.0, b, ((c / b) * (a * 2.0)));
}
tmp_1 = tmp_2;
} else if (b <= 4e+113) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = 2.0 / ((t_0 - b) / c);
}
tmp_1 = tmp_3;
} else {
tmp_1 = -b / a;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(a * c) * 4.0))) tmp_1 = 0.0 if (b <= -5e+141) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-0.5 * Float64(fma(-2.0, Float64(Float64(a * c) / b), Float64(b * 2.0)) / a)); else tmp_2 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(Float64(c / b) * Float64(a * 2.0)))); end tmp_1 = tmp_2; elseif (b <= 4e+113) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp_3 = Float64(2.0 / Float64(Float64(t_0 - b) / c)); end tmp_1 = tmp_3; else tmp_1 = Float64(Float64(-b) / a); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * c), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5e+141], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(N[(c / b), $MachinePrecision] * N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 4e+113], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(N[(t$95$0 - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]], N[((-b) / a), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+141}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(-2, \frac{a \cdot c}{b}, b \cdot 2\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, \frac{c}{b} \cdot \left(a \cdot 2\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+113}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{t_0 - b}{c}}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -5.00000000000000025e141Initial program 41.1%
Simplified41.1%
Taylor expanded in b around -inf 92.6%
fma-def92.6%
associate-/l*99.6%
Simplified99.6%
expm1-log1p-u95.5%
expm1-udef42.3%
associate-*r/42.3%
associate-*r/42.3%
div-inv42.3%
clear-num42.3%
Applied egg-rr42.3%
expm1-def95.8%
expm1-log1p99.9%
*-commutative99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in b around inf 99.9%
fma-def99.9%
*-commutative99.9%
Simplified99.9%
if -5.00000000000000025e141 < b < 4e113Initial program 88.6%
sqr-neg88.6%
sqr-neg88.6%
associate-*l*88.6%
*-commutative88.6%
associate-/l*88.0%
Simplified87.9%
if 4e113 < b Initial program 42.5%
sqr-neg42.5%
sqr-neg42.5%
associate-*l*42.5%
*-commutative42.5%
associate-/l*42.5%
Simplified42.5%
Taylor expanded in b around inf 93.8%
associate-*r/93.8%
mul-1-neg93.8%
Simplified93.8%
Taylor expanded in b around inf 93.8%
Taylor expanded in a around 0 93.8%
associate-*r/93.8%
neg-mul-193.8%
Simplified93.8%
Final simplification91.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.9e+139)
(if (>= b 0.0)
(* -0.5 (/ (fma -2.0 (/ (* a c) b) (* b 2.0)) a))
(/ (* c 2.0) (fma -2.0 b (* (/ c b) (* a 2.0)))))
(if (>= b 0.0)
(/ (- b) a)
(/ 2.0 (/ (- (sqrt (- (* b b) (* (* a c) 4.0))) b) c)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -1.9e+139) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (fma(-2.0, ((a * c) / b), (b * 2.0)) / a);
} else {
tmp_2 = (c * 2.0) / fma(-2.0, b, ((c / b) * (a * 2.0)));
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -b / a;
} else {
tmp_1 = 2.0 / ((sqrt(((b * b) - ((a * c) * 4.0))) - b) / c);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -1.9e+139) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-0.5 * Float64(fma(-2.0, Float64(Float64(a * c) / b), Float64(b * 2.0)) / a)); else tmp_2 = Float64(Float64(c * 2.0) / fma(-2.0, b, Float64(Float64(c / b) * Float64(a * 2.0)))); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(-b) / a); else tmp_1 = Float64(2.0 / Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * c) * 4.0))) - b) / c)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -1.9e+139], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b + N[(N[(c / b), $MachinePrecision] * N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(2.0 / N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * c), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{+139}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(-2, \frac{a \cdot c}{b}, b \cdot 2\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(-2, b, \frac{c}{b} \cdot \left(a \cdot 2\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b}{c}}\\
\end{array}
\end{array}
if b < -1.9e139Initial program 41.1%
Simplified41.1%
Taylor expanded in b around -inf 92.6%
fma-def92.6%
associate-/l*99.6%
Simplified99.6%
expm1-log1p-u95.5%
expm1-udef42.3%
associate-*r/42.3%
associate-*r/42.3%
div-inv42.3%
clear-num42.3%
Applied egg-rr42.3%
expm1-def95.8%
expm1-log1p99.9%
*-commutative99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in b around inf 99.9%
fma-def99.9%
*-commutative99.9%
Simplified99.9%
if -1.9e139 < b Initial program 78.4%
sqr-neg78.4%
sqr-neg78.4%
associate-*l*78.4%
*-commutative78.4%
associate-/l*77.9%
Simplified77.8%
Taylor expanded in b around inf 73.9%
associate-*r/73.9%
mul-1-neg73.9%
Simplified73.9%
Final simplification79.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* -0.5 (/ (fma -2.0 (* a (/ c b)) (* b 2.0)) a)) (* c (/ 2.0 (fma -2.0 b (* 2.0 (/ a (/ b c))))))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * (fma(-2.0, (a * (c / b)), (b * 2.0)) / a);
} else {
tmp = c * (2.0 / fma(-2.0, b, (2.0 * (a / (b / c)))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(-0.5 * Float64(fma(-2.0, Float64(a * Float64(c / b)), Float64(b * 2.0)) / a)); else tmp = Float64(c * Float64(2.0 / fma(-2.0, b, Float64(2.0 * Float64(a / Float64(b / c)))))); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(c * N[(2.0 / N[(-2.0 * b + N[(2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(-2, a \cdot \frac{c}{b}, b \cdot 2\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{2}{\mathsf{fma}\left(-2, b, 2 \cdot \frac{a}{\frac{b}{c}}\right)}\\
\end{array}
\end{array}
Initial program 70.7%
Simplified70.2%
Taylor expanded in b around -inf 69.8%
fma-def69.8%
associate-/l*71.4%
Simplified71.4%
Taylor expanded in b around inf 66.7%
fma-def66.8%
*-commutative66.8%
Simplified66.7%
expm1-log1p-u64.4%
expm1-udef64.4%
*-commutative64.4%
*-un-lft-identity64.4%
times-frac65.6%
/-rgt-identity65.6%
Applied egg-rr65.6%
expm1-def65.6%
expm1-log1p68.2%
*-commutative68.2%
associate-*l/66.7%
associate-*r/68.2%
Simplified68.2%
Final simplification68.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ 2.0 (+ (* -2.0 (/ b c)) (* 2.0 (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / 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 >= 0.0d0) then
tmp = -b / a
else
tmp = 2.0d0 / (((-2.0d0) * (b / c)) + (2.0d0 * (a / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / b)));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / b))) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(2.0 / Float64(Float64(-2.0 * Float64(b / c)) + Float64(2.0 * Float64(a / b)))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -b / a; else tmp = 2.0 / ((-2.0 * (b / c)) + (2.0 * (a / b))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(2.0 / N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{-2 \cdot \frac{b}{c} + 2 \cdot \frac{a}{b}}\\
\end{array}
\end{array}
Initial program 70.7%
sqr-neg70.7%
sqr-neg70.7%
associate-*l*70.7%
*-commutative70.7%
associate-/l*70.3%
Simplified70.2%
Taylor expanded in b around inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
Taylor expanded in b around -inf 68.0%
Final simplification68.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* -0.5 (/ 1.0 (/ a (* b 2.0)))) (* c (/ 2.0 (- (+ b b))))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * (1.0 / (a / (b * 2.0)));
} else {
tmp = c * (2.0 / -(b + 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 >= 0.0d0) then
tmp = (-0.5d0) * (1.0d0 / (a / (b * 2.0d0)))
else
tmp = c * (2.0d0 / -(b + b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * (1.0 / (a / (b * 2.0)));
} else {
tmp = c * (2.0 / -(b + b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -0.5 * (1.0 / (a / (b * 2.0))) else: tmp = c * (2.0 / -(b + b)) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(-0.5 * Float64(1.0 / Float64(a / Float64(b * 2.0)))); else tmp = Float64(c * Float64(2.0 / Float64(-Float64(b + b)))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -0.5 * (1.0 / (a / (b * 2.0))); else tmp = c * (2.0 / -(b + b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(-0.5 * N[(1.0 / N[(a / N[(b * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c * N[(2.0 / (-N[(b + b), $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{2}{-\left(b + b\right)}\\
\end{array}
\end{array}
Initial program 70.7%
Simplified70.2%
clear-num70.1%
inv-pow70.1%
fma-udef70.1%
add-sqr-sqrt63.3%
hypot-def66.2%
Applied egg-rr66.2%
unpow-166.2%
Simplified66.2%
Taylor expanded in b around inf 66.9%
*-commutative66.9%
Simplified66.9%
Taylor expanded in b around -inf 67.7%
Final simplification67.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ 2.0 (/ (* b -2.0) c))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = 2.0 / ((b * -2.0) / c);
}
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 >= 0.0d0) then
tmp = -b / a
else
tmp = 2.0d0 / ((b * (-2.0d0)) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = 2.0 / ((b * -2.0) / c);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = 2.0 / ((b * -2.0) / c) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(2.0 / Float64(Float64(b * -2.0) / c)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -b / a; else tmp = 2.0 / ((b * -2.0) / c); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(2.0 / N[(N[(b * -2.0), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{b \cdot -2}{c}}\\
\end{array}
\end{array}
Initial program 70.7%
sqr-neg70.7%
sqr-neg70.7%
associate-*l*70.7%
*-commutative70.7%
associate-/l*70.3%
Simplified70.2%
Taylor expanded in b around inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
Taylor expanded in b around -inf 67.6%
associate-*r/67.6%
*-commutative67.6%
Simplified67.6%
Final simplification67.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ -1.0 (/ a b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = -1.0 / (a / 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 >= 0.0d0) then
tmp = -b / a
else
tmp = (-1.0d0) / (a / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = -1.0 / (a / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = -1.0 / (a / b) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(-1.0 / Float64(a / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -b / a; else tmp = -1.0 / (a / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(-1.0 / N[(a / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{a}{b}}\\
\end{array}
\end{array}
Initial program 70.7%
sqr-neg70.7%
sqr-neg70.7%
associate-*l*70.7%
*-commutative70.7%
associate-/l*70.3%
Simplified70.2%
Taylor expanded in b around inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
Taylor expanded in b around inf 31.4%
div-inv31.4%
associate-/r*31.4%
metadata-eval31.4%
Applied egg-rr31.4%
associate-*r/31.4%
metadata-eval31.4%
Simplified31.4%
Final simplification31.4%
(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 70.7%
sqr-neg70.7%
sqr-neg70.7%
associate-*l*70.7%
*-commutative70.7%
associate-/l*70.3%
Simplified70.2%
Taylor expanded in b around inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
Taylor expanded in b around inf 31.4%
Taylor expanded in a around 0 31.4%
associate-*r/31.4%
neg-mul-131.4%
Simplified31.4%
Final simplification31.4%
herbie shell --seed 2023305
(FPCore (a b c)
:name "jeff quadratic root 1"
:precision binary64
(if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))