
(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 4 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 -8e+119)
(if (>= b 0.0)
(/ (* 2.0 (- (* a (/ c b)) b)) (* 2.0 a))
(/ (* 2.0 c) (* (- b) (+ 2.0 (* -2.0 (* c (/ a (pow b 2.0))))))))
(if (<= b 2.7e+96)
(if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (- t_0 b)))
(if (>= b 0.0) (- (/ c b) (/ b a)) (/ (* 2.0 c) (- (- b) b)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -8e+119) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a);
} else {
tmp_2 = (2.0 * c) / (-b * (2.0 + (-2.0 * (c * (a / pow(b, 2.0))))));
}
tmp_1 = tmp_2;
} else if (b <= 2.7e+96) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (2.0 * a);
} else {
tmp_3 = (2.0 * c) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c / b) - (b / a);
} else {
tmp_1 = (2.0 * c) / (-b - b);
}
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) - (c * (a * 4.0d0))))
if (b <= (-8d+119)) then
if (b >= 0.0d0) then
tmp_2 = (2.0d0 * ((a * (c / b)) - b)) / (2.0d0 * a)
else
tmp_2 = (2.0d0 * c) / (-b * (2.0d0 + ((-2.0d0) * (c * (a / (b ** 2.0d0))))))
end if
tmp_1 = tmp_2
else if (b <= 2.7d+96) then
if (b >= 0.0d0) then
tmp_3 = (-b - t_0) / (2.0d0 * a)
else
tmp_3 = (2.0d0 * c) / (t_0 - b)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = (c / b) - (b / a)
else
tmp_1 = (2.0d0 * c) / (-b - b)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -8e+119) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a);
} else {
tmp_2 = (2.0 * c) / (-b * (2.0 + (-2.0 * (c * (a / Math.pow(b, 2.0))))));
}
tmp_1 = tmp_2;
} else if (b <= 2.7e+96) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (2.0 * a);
} else {
tmp_3 = (2.0 * c) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c / b) - (b / a);
} else {
tmp_1 = (2.0 * c) / (-b - b);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -8e+119: tmp_2 = 0 if b >= 0.0: tmp_2 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a) else: tmp_2 = (2.0 * c) / (-b * (2.0 + (-2.0 * (c * (a / math.pow(b, 2.0)))))) tmp_1 = tmp_2 elif b <= 2.7e+96: tmp_3 = 0 if b >= 0.0: tmp_3 = (-b - t_0) / (2.0 * a) else: tmp_3 = (2.0 * c) / (t_0 - b) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = (c / b) - (b / a) else: tmp_1 = (2.0 * c) / (-b - b) 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 <= -8e+119) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b)) / Float64(2.0 * a)); else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) * Float64(2.0 + Float64(-2.0 * Float64(c * Float64(a / (b ^ 2.0))))))); end tmp_1 = tmp_2; elseif (b <= 2.7e+96) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp_3 = Float64(Float64(2.0 * c) / Float64(t_0 - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c / b) - Float64(b / a)); else tmp_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - b)); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if (b <= -8e+119) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a); else tmp_3 = (2.0 * c) / (-b * (2.0 + (-2.0 * (c * (a / (b ^ 2.0)))))); end tmp_2 = tmp_3; elseif (b <= 2.7e+96) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (-b - t_0) / (2.0 * a); else tmp_4 = (2.0 * c) / (t_0 - b); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = (c / b) - (b / a); else tmp_2 = (2.0 * c) / (-b - b); end tmp_5 = tmp_2; 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, -8e+119], If[GreaterEqual[b, 0.0], N[(N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) * N[(2.0 + N[(-2.0 * N[(c * N[(a / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.7e+96], 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[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -8 \cdot 10^{+119}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) \cdot \left(2 + -2 \cdot \left(c \cdot \frac{a}{{b}^{2}}\right)\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{+96}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{t\_0 - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\end{array}
\end{array}
if b < -7.99999999999999955e119Initial program 34.9%
Taylor expanded in a around 0 34.9%
distribute-lft-out--34.9%
associate-/l*34.9%
Simplified34.9%
pow1/234.9%
pow234.9%
sub-neg34.9%
+-commutative34.9%
*-commutative34.9%
distribute-rgt-neg-in34.9%
distribute-lft-neg-in34.9%
metadata-eval34.9%
*-commutative34.9%
fma-undefine35.2%
metadata-eval35.2%
pow-pow35.2%
Applied egg-rr35.2%
Taylor expanded in b around -inf 81.2%
associate-*r*81.2%
mul-1-neg81.2%
*-commutative81.2%
associate-*r/93.4%
Simplified93.4%
if -7.99999999999999955e119 < b < 2.70000000000000022e96Initial program 85.8%
if 2.70000000000000022e96 < b Initial program 65.1%
Taylor expanded in a around 0 98.0%
distribute-lft-out--98.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in b around -inf 100.0%
Taylor expanded in a around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification89.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (or (<= b -2e+122) (not (<= b 4.9e+95)))
(if (>= b 0.0) (- (/ c b) (/ b a)) (/ (* 2.0 c) (- (- b) b)))
(if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (- t_0 b))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if ((b <= -2e+122) || !(b <= 4.9e+95)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c / b) - (b / a);
} else {
tmp_2 = (2.0 * c) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (-b - t_0) / (2.0 * a);
} else {
tmp_1 = (2.0 * c) / (t_0 - b);
}
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
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
if ((b <= (-2d+122)) .or. (.not. (b <= 4.9d+95))) then
if (b >= 0.0d0) then
tmp_2 = (c / b) - (b / a)
else
tmp_2 = (2.0d0 * c) / (-b - b)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (-b - t_0) / (2.0d0 * a)
else
tmp_1 = (2.0d0 * c) / (t_0 - b)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if ((b <= -2e+122) || !(b <= 4.9e+95)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c / b) - (b / a);
} else {
tmp_2 = (2.0 * c) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (-b - t_0) / (2.0 * a);
} else {
tmp_1 = (2.0 * c) / (t_0 - b);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if (b <= -2e+122) or not (b <= 4.9e+95): tmp_2 = 0 if b >= 0.0: tmp_2 = (c / b) - (b / a) else: tmp_2 = (2.0 * c) / (-b - b) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (-b - t_0) / (2.0 * a) else: tmp_1 = (2.0 * c) / (t_0 - b) 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 <= -2e+122) || !(b <= 4.9e+95)) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c / b) - Float64(b / a)); else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp_1 = Float64(Float64(2.0 * c) / Float64(t_0 - b)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if ((b <= -2e+122) || ~((b <= 4.9e+95))) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (c / b) - (b / a); else tmp_3 = (2.0 * c) / (-b - b); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (-b - t_0) / (2.0 * a); else tmp_2 = (2.0 * c) / (t_0 - b); end tmp_4 = tmp_2; 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[Or[LessEqual[b, -2e+122], N[Not[LessEqual[b, 4.9e+95]], $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $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[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+122} \lor \neg \left(b \leq 4.9 \cdot 10^{+95}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{t\_0 - b}\\
\end{array}
\end{array}
if b < -2.00000000000000003e122 or 4.8999999999999999e95 < b Initial program 51.2%
Taylor expanded in a around 0 68.9%
distribute-lft-out--68.9%
associate-/l*70.0%
Simplified70.0%
Taylor expanded in b around -inf 96.9%
Taylor expanded in a around inf 96.9%
+-commutative96.9%
mul-1-neg96.9%
unsub-neg96.9%
Simplified96.9%
if -2.00000000000000003e122 < b < 4.8999999999999999e95Initial program 85.8%
Final simplification89.8%
(FPCore (a b c)
:precision binary64
(if (<= b -2e+122)
(if (>= b 0.0) (- (/ c b) (/ b a)) (/ (* 2.0 c) (- (- b) b)))
(if (>= b 0.0)
(/ (* 2.0 (- (* a (/ c b)) b)) (* 2.0 a))
(/ (* 2.0 c) (- (sqrt (- (* b b) (* c (* a 4.0)))) b)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -2e+122) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c / b) - (b / a);
} else {
tmp_2 = (2.0 * c) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a);
} else {
tmp_1 = (2.0 * c) / (sqrt(((b * b) - (c * (a * 4.0)))) - b);
}
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 <= (-2d+122)) then
if (b >= 0.0d0) then
tmp_2 = (c / b) - (b / a)
else
tmp_2 = (2.0d0 * c) / (-b - b)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (2.0d0 * ((a * (c / b)) - b)) / (2.0d0 * a)
else
tmp_1 = (2.0d0 * c) / (sqrt(((b * b) - (c * (a * 4.0d0)))) - b)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double tmp_1;
if (b <= -2e+122) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c / b) - (b / a);
} else {
tmp_2 = (2.0 * c) / (-b - b);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a);
} else {
tmp_1 = (2.0 * c) / (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b);
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if b <= -2e+122: tmp_2 = 0 if b >= 0.0: tmp_2 = (c / b) - (b / a) else: tmp_2 = (2.0 * c) / (-b - b) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a) else: tmp_1 = (2.0 * c) / (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) return tmp_1
function code(a, b, c) tmp_1 = 0.0 if (b <= -2e+122) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c / b) - Float64(b / a)); else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b)) / Float64(2.0 * a)); else tmp_1 = Float64(Float64(2.0 * c) / Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b)); end return tmp_1 end
function tmp_4 = code(a, b, c) tmp_2 = 0.0; if (b <= -2e+122) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (c / b) - (b / a); else tmp_3 = (2.0 * c) / (-b - b); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (2.0 * ((a * (c / b)) - b)) / (2.0 * a); else tmp_2 = (2.0 * c) / (sqrt(((b * b) - (c * (a * 4.0)))) - b); end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[LessEqual[b, -2e+122], If[GreaterEqual[b, 0.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+122}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\
\end{array}
\end{array}
if b < -2.00000000000000003e122Initial program 34.9%
Taylor expanded in a around 0 34.9%
distribute-lft-out--34.9%
associate-/l*34.9%
Simplified34.9%
Taylor expanded in b around -inf 93.4%
Taylor expanded in a around inf 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -2.00000000000000003e122 < b Initial program 81.1%
Taylor expanded in a around 0 75.5%
distribute-lft-out--75.5%
associate-/l*76.1%
Simplified76.1%
Final simplification78.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (- (/ c b) (/ b a)) (/ (* 2.0 c) (- (- b) b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c / b) - (b / a);
} else {
tmp = (2.0 * c) / (-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 = (c / b) - (b / a)
else
tmp = (2.0d0 * c) / (-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 = (c / b) - (b / a);
} else {
tmp = (2.0 * c) / (-b - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c / b) - (b / a) else: tmp = (2.0 * c) / (-b - b) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (c / b) - (b / a); else tmp = (2.0 * c) / (-b - b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\end{array}
\end{array}
Initial program 73.5%
Taylor expanded in a around 0 68.9%
distribute-lft-out--68.9%
associate-/l*69.3%
Simplified69.3%
Taylor expanded in b around -inf 65.6%
Taylor expanded in a around inf 65.6%
+-commutative65.6%
mul-1-neg65.6%
unsub-neg65.6%
Simplified65.6%
Final simplification65.6%
herbie shell --seed 2024077
(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)))))))