
(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 8 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 (fma b b (* a (* c -4.0))))))
(if (<= b -1.1e+61)
(if (>= b 0.0) (* -0.5 (/ 1.0 (* (/ 0.5 b) a))) (/ (* c 2.0) (- (- b) b)))
(if (<= b 4.6e+57)
(if (>= b 0.0) (* -0.5 (/ (+ b t_0) a)) (/ (* c 2.0) (- t_0 b)))
(if (>= b 0.0) (/ (- b) a) (/ b a))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(b, b, (a * (c * -4.0))));
double tmp_1;
if (b <= -1.1e+61) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (1.0 / ((0.5 / b) * a));
} else {
tmp_2 = (c * 2.0) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b <= 4.6e+57) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = -0.5 * ((b + t_0) / a);
} else {
tmp_3 = (c * 2.0) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -b / a;
} else {
tmp_1 = b / a;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(b, b, Float64(a * Float64(c * -4.0)))) tmp_1 = 0.0 if (b <= -1.1e+61) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-0.5 * Float64(1.0 / Float64(Float64(0.5 / b) * a))); else tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - b)); end tmp_1 = tmp_2; elseif (b <= 4.6e+57) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(-0.5 * Float64(Float64(b + t_0) / a)); else tmp_3 = Float64(Float64(c * 2.0) / Float64(t_0 - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(-b) / a); else tmp_1 = Float64(b / a); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1.1e+61], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(1.0 / N[(N[(0.5 / b), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 4.6e+57], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b + t$95$0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(b / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}\\
\mathbf{if}\;b \leq -1.1 \cdot 10^{+61}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{0.5}{b} \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \leq 4.6 \cdot 10^{+57}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + t\_0}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t\_0 - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a}\\
\end{array}
\end{array}
if b < -1.1e61Initial program 52.7%
Simplified52.7%
Taylor expanded in b around -inf 94.4%
clear-num94.4%
inv-pow94.4%
fma-udef94.4%
add-sqr-sqrt94.4%
hypot-def94.4%
Applied egg-rr94.4%
unpow-194.4%
Simplified94.4%
Taylor expanded in a around 0 94.4%
associate-*r/94.4%
*-rgt-identity94.4%
times-frac94.4%
rem-square-sqrt94.4%
associate-*r/94.4%
/-rgt-identity94.4%
rem-square-sqrt94.4%
Simplified94.4%
if -1.1e61 < b < 4.5999999999999998e57Initial program 85.9%
Simplified86.8%
if 4.5999999999999998e57 < b Initial program 66.2%
sqr-neg66.2%
sqr-neg66.2%
associate-*l*66.2%
*-commutative66.2%
associate-/l*66.2%
Simplified66.2%
Taylor expanded in b around inf 94.8%
associate-*r/94.8%
mul-1-neg94.8%
Simplified94.8%
Taylor expanded in b around inf 94.8%
associate-*r/94.8%
Simplified94.8%
frac-2neg94.8%
metadata-eval94.8%
div-inv94.8%
add-sqr-sqrt94.8%
sqrt-unprod94.8%
sqr-neg94.8%
sqrt-unprod94.8%
add-sqr-sqrt94.8%
distribute-frac-neg94.8%
frac-2neg94.8%
clear-num94.8%
*-un-lft-identity94.8%
times-frac94.8%
metadata-eval94.8%
Applied egg-rr94.8%
associate-*r*94.8%
metadata-eval94.8%
*-lft-identity94.8%
Simplified94.8%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (<= b -2.8e+35)
(if (>= b 0.0) (* -0.5 (/ 1.0 (* (/ 0.5 b) a))) (/ (* c 2.0) (- (- b) b)))
(if (<= b 4.6e+57)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ 2.0 (/ (- t_0 b) c)))
(if (>= b 0.0) (/ (- b) a) (/ b a))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp_1;
if (b <= -2.8e+35) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (1.0 / ((0.5 / b) * a));
} else {
tmp_2 = (c * 2.0) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b <= 4.6e+57) {
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 if (b >= 0.0) {
tmp_1 = -b / a;
} else {
tmp_1 = b / a;
}
return tmp_1;
}
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
real(8) :: tmp_1
real(8) :: tmp_2
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b <= (-2.8d+35)) then
if (b >= 0.0d0) then
tmp_2 = (-0.5d0) * (1.0d0 / ((0.5d0 / b) * a))
else
tmp_2 = (c * 2.0d0) / (-b - b)
end if
tmp_1 = tmp_2
else if (b <= 4.6d+57) then
if (b >= 0.0d0) then
tmp_3 = (-b - t_0) / (a * 2.0d0)
else
tmp_3 = 2.0d0 / ((t_0 - b) / c)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = -b / a
else
tmp_1 = b / a
end if
code = tmp_1
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_1;
if (b <= -2.8e+35) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (1.0 / ((0.5 / b) * a));
} else {
tmp_2 = (c * 2.0) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b <= 4.6e+57) {
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 if (b >= 0.0) {
tmp_1 = -b / a;
} else {
tmp_1 = b / a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp_1 = 0 if b <= -2.8e+35: tmp_2 = 0 if b >= 0.0: tmp_2 = -0.5 * (1.0 / ((0.5 / b) * a)) else: tmp_2 = (c * 2.0) / (-b - b) tmp_1 = tmp_2 elif b <= 4.6e+57: tmp_3 = 0 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 elif b >= 0.0: tmp_1 = -b / a else: tmp_1 = b / a return tmp_1
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp_1 = 0.0 if (b <= -2.8e+35) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-0.5 * Float64(1.0 / Float64(Float64(0.5 / b) * a))); else tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - b)); end tmp_1 = tmp_2; elseif (b <= 4.6e+57) 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; elseif (b >= 0.0) tmp_1 = Float64(Float64(-b) / a); else tmp_1 = Float64(b / a); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp_2 = 0.0; if (b <= -2.8e+35) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = -0.5 * (1.0 / ((0.5 / b) * a)); else tmp_3 = (c * 2.0) / (-b - b); end tmp_2 = tmp_3; elseif (b <= 4.6e+57) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (-b - t_0) / (a * 2.0); else tmp_4 = 2.0 / ((t_0 - b) / c); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = -b / a; else tmp_2 = b / a; end tmp_5 = tmp_2; 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[LessEqual[b, -2.8e+35], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(1.0 / N[(N[(0.5 / b), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 4.6e+57], 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]], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(b / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b \leq -2.8 \cdot 10^{+35}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{0.5}{b} \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \leq 4.6 \cdot 10^{+57}:\\
\;\;\;\;\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{elif}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a}\\
\end{array}
\end{array}
if b < -2.79999999999999999e35Initial program 55.4%
Simplified55.4%
Taylor expanded in b around -inf 94.7%
clear-num94.7%
inv-pow94.7%
fma-udef94.7%
add-sqr-sqrt94.7%
hypot-def94.7%
Applied egg-rr94.7%
unpow-194.7%
Simplified94.7%
Taylor expanded in a around 0 94.7%
associate-*r/94.7%
*-rgt-identity94.7%
times-frac94.7%
rem-square-sqrt94.7%
associate-*r/94.7%
/-rgt-identity94.7%
rem-square-sqrt94.7%
Simplified94.7%
if -2.79999999999999999e35 < b < 4.5999999999999998e57Initial program 85.4%
sqr-neg85.4%
sqr-neg85.4%
associate-*l*85.5%
*-commutative85.5%
associate-/l*85.5%
Simplified85.5%
if 4.5999999999999998e57 < b Initial program 66.2%
sqr-neg66.2%
sqr-neg66.2%
associate-*l*66.2%
*-commutative66.2%
associate-/l*66.2%
Simplified66.2%
Taylor expanded in b around inf 94.8%
associate-*r/94.8%
mul-1-neg94.8%
Simplified94.8%
Taylor expanded in b around inf 94.8%
associate-*r/94.8%
Simplified94.8%
frac-2neg94.8%
metadata-eval94.8%
div-inv94.8%
add-sqr-sqrt94.8%
sqrt-unprod94.8%
sqr-neg94.8%
sqrt-unprod94.8%
add-sqr-sqrt94.8%
distribute-frac-neg94.8%
frac-2neg94.8%
clear-num94.8%
*-un-lft-identity94.8%
times-frac94.8%
metadata-eval94.8%
Applied egg-rr94.8%
associate-*r*94.8%
metadata-eval94.8%
*-lft-identity94.8%
Simplified94.8%
Final simplification90.6%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e+35)
(if (>= b 0.0) (* -0.5 (/ 1.0 (* (/ 0.5 b) a))) (/ (* c 2.0) (- (- b) b)))
(if (>= b 0.0)
(/ (- b) a)
(/ 2.0 (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) c)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -2.8e+35) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (1.0 / ((0.5 / b) * a));
} else {
tmp_2 = (c * 2.0) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -b / a;
} else {
tmp_1 = 2.0 / ((sqrt(((b * b) - (4.0 * (a * c)))) - b) / c);
}
return tmp_1;
}
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
real(8) :: tmp_1
real(8) :: tmp_2
if (b <= (-2.8d+35)) then
if (b >= 0.0d0) then
tmp_2 = (-0.5d0) * (1.0d0 / ((0.5d0 / b) * a))
else
tmp_2 = (c * 2.0d0) / (-b - b)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = -b / a
else
tmp_1 = 2.0d0 / ((sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / c)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double tmp_1;
if (b <= -2.8e+35) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * (1.0 / ((0.5 / b) * a));
} else {
tmp_2 = (c * 2.0) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -b / a;
} else {
tmp_1 = 2.0 / ((Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / c);
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if b <= -2.8e+35: tmp_2 = 0 if b >= 0.0: tmp_2 = -0.5 * (1.0 / ((0.5 / b) * a)) else: tmp_2 = (c * 2.0) / (-b - b) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = -b / a else: tmp_1 = 2.0 / ((math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / c) return tmp_1
function code(a, b, c) tmp_1 = 0.0 if (b <= -2.8e+35) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-0.5 * Float64(1.0 / Float64(Float64(0.5 / b) * a))); else tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - b)); 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(4.0 * Float64(a * c)))) - b) / c)); end return tmp_1 end
function tmp_4 = code(a, b, c) tmp_2 = 0.0; if (b <= -2.8e+35) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = -0.5 * (1.0 / ((0.5 / b) * a)); else tmp_3 = (c * 2.0) / (-b - b); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = -b / a; else tmp_2 = 2.0 / ((sqrt(((b * b) - (4.0 * (a * c)))) - b) / c); end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e+35], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(1.0 / N[(N[(0.5 / b), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(2.0 / N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+35}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{0.5}{b} \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{c}}\\
\end{array}
\end{array}
if b < -2.79999999999999999e35Initial program 55.4%
Simplified55.4%
Taylor expanded in b around -inf 94.7%
clear-num94.7%
inv-pow94.7%
fma-udef94.7%
add-sqr-sqrt94.7%
hypot-def94.7%
Applied egg-rr94.7%
unpow-194.7%
Simplified94.7%
Taylor expanded in a around 0 94.7%
associate-*r/94.7%
*-rgt-identity94.7%
times-frac94.7%
rem-square-sqrt94.7%
associate-*r/94.7%
/-rgt-identity94.7%
rem-square-sqrt94.7%
Simplified94.7%
if -2.79999999999999999e35 < b Initial program 78.1%
sqr-neg78.1%
sqr-neg78.1%
associate-*l*78.1%
*-commutative78.1%
associate-/l*78.1%
Simplified78.1%
Taylor expanded in b around inf 75.6%
associate-*r/75.6%
mul-1-neg75.6%
Simplified75.6%
Final simplification80.8%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* -0.5 (+ (* -2.0 (/ c b)) (* 2.0 (/ b a)))) (/ (* c 2.0) (- (- b) b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * ((-2.0 * (c / b)) + (2.0 * (b / a)));
} 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) * (((-2.0d0) * (c / b)) + (2.0d0 * (b / a)))
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 * ((-2.0 * (c / b)) + (2.0 * (b / a)));
} else {
tmp = (c * 2.0) / (-b - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -0.5 * ((-2.0 * (c / b)) + (2.0 * (b / a))) 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(Float64(-2.0 * Float64(c / b)) + Float64(2.0 * Float64(b / a)))); else tmp = Float64(Float64(c * 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 * ((-2.0 * (c / b)) + (2.0 * (b / a))); 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[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \left(-2 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}
\end{array}
Initial program 71.9%
Simplified72.3%
Taylor expanded in b around -inf 72.3%
Taylor expanded in b around inf 70.1%
Final simplification70.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* -0.5 (/ 1.0 (* (/ 0.5 b) a))) (/ (* c 2.0) (- (- b) b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.5 * (1.0 / ((0.5 / b) * a));
} 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 / ((0.5d0 / b) * a))
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 / ((0.5 / b) * a));
} 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 / ((0.5 / b) * a)) 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(Float64(0.5 / b) * a))); else tmp = Float64(Float64(c * 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 / ((0.5 / b) * a)); 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[(N[(0.5 / b), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{0.5}{b} \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}
\end{array}
Initial program 71.9%
Simplified72.3%
Taylor expanded in b around -inf 72.3%
clear-num72.1%
inv-pow72.1%
fma-udef72.1%
add-sqr-sqrt61.3%
hypot-def62.8%
Applied egg-rr62.8%
unpow-162.8%
Simplified62.8%
Taylor expanded in a around 0 69.9%
associate-*r/69.9%
*-rgt-identity69.9%
times-frac69.8%
rem-square-sqrt49.3%
associate-*r/49.3%
/-rgt-identity49.3%
rem-square-sqrt69.8%
Simplified69.8%
Final simplification69.8%
(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(Float64(c * 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[(N[(c * 2.0), $MachinePrecision] / N[((-b) - b), $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}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}
\end{array}
Initial program 71.9%
Simplified72.3%
Taylor expanded in b around -inf 72.3%
clear-num72.1%
inv-pow72.1%
fma-udef72.1%
add-sqr-sqrt61.3%
hypot-def62.8%
Applied egg-rr62.8%
unpow-162.8%
Simplified62.8%
Taylor expanded in b around inf 69.9%
*-commutative69.9%
Simplified69.9%
Final simplification69.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ 2.0 (* -2.0 (/ b c)))))
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));
}
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))
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));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = 2.0 / (-2.0 * (b / 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(-2.0 * Float64(b / 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 / (-2.0 * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(2.0 / N[(-2.0 * N[(b / c), $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}}\\
\end{array}
\end{array}
Initial program 71.9%
sqr-neg71.9%
sqr-neg71.9%
associate-*l*71.9%
*-commutative71.9%
associate-/l*71.8%
Simplified71.8%
Taylor expanded in b around inf 69.9%
associate-*r/69.9%
mul-1-neg69.9%
Simplified69.9%
Taylor expanded in b around -inf 69.2%
*-commutative69.2%
Simplified69.2%
Final simplification69.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ b a)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = b / a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b >= 0.0d0) then
tmp = -b / a
else
tmp = b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = b / a return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(b / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -b / a; else tmp = b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(b / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a}\\
\end{array}
\end{array}
Initial program 71.9%
sqr-neg71.9%
sqr-neg71.9%
associate-*l*71.9%
*-commutative71.9%
associate-/l*71.8%
Simplified71.8%
Taylor expanded in b around inf 69.9%
associate-*r/69.9%
mul-1-neg69.9%
Simplified69.9%
Taylor expanded in b around inf 37.2%
associate-*r/37.2%
Simplified37.2%
frac-2neg37.2%
metadata-eval37.2%
div-inv37.2%
add-sqr-sqrt35.8%
sqrt-unprod37.5%
sqr-neg37.5%
sqrt-unprod37.6%
add-sqr-sqrt37.6%
distribute-frac-neg37.6%
frac-2neg37.6%
clear-num37.6%
*-un-lft-identity37.6%
times-frac37.6%
metadata-eval37.6%
Applied egg-rr37.6%
associate-*r*37.6%
metadata-eval37.6%
*-lft-identity37.6%
Simplified37.6%
Final simplification37.6%
herbie shell --seed 2024039
(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)))))))