
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- 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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0d0 * c) / (-b - t_0)
else
tmp = (-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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0 * c) / (-b - t_0) else: tmp = (-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(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = 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 = (2.0 * c) / (-b - t_0); else tmp = (-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[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $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{2 \cdot c}{\left(-b\right) - t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- 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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0d0 * c) / (-b - t_0)
else
tmp = (-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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0 * c) / (-b - t_0) else: tmp = (-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(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = 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 = (2.0 * c) / (-b - t_0); else tmp = (-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[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $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{2 \cdot c}{\left(-b\right) - t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- c) b)) (t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -5e+143)
(if (>= b 0.0) t_0 (* (+ (* -2.0 (/ c b)) (* 2.0 (/ b a))) -0.5))
(if (<= b 3.1e+43)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_1)) (/ (- t_1 b) (* 2.0 a)))
(if (>= b 0.0) t_0 (* (/ b a) -0.5))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -5e+143) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 3.1e+43) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_1);
} else {
tmp_3 = (t_1 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (b / a) * -0.5;
}
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) :: t_1
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
real(8) :: tmp_3
t_0 = -c / b
t_1 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-5d+143)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = (((-2.0d0) * (c / b)) + (2.0d0 * (b / a))) * (-0.5d0)
end if
tmp_1 = tmp_2
else if (b <= 3.1d+43) then
if (b >= 0.0d0) then
tmp_3 = (c * 2.0d0) / (-b - t_1)
else
tmp_3 = (t_1 - b) / (2.0d0 * a)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = (b / a) * (-0.5d0)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -5e+143) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 3.1e+43) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_1);
} else {
tmp_3 = (t_1 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (b / a) * -0.5;
}
return tmp_1;
}
def code(a, b, c): t_0 = -c / b t_1 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -5e+143: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5 tmp_1 = tmp_2 elif b <= 3.1e+43: tmp_3 = 0 if b >= 0.0: tmp_3 = (c * 2.0) / (-b - t_1) else: tmp_3 = (t_1 - b) / (2.0 * a) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = (b / a) * -0.5 return tmp_1
function code(a, b, c) t_0 = Float64(Float64(-c) / b) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -5e+143) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(Float64(-2.0 * Float64(c / b)) + Float64(2.0 * Float64(b / a))) * -0.5); end tmp_1 = tmp_2; elseif (b <= 3.1e+43) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - t_1)); else tmp_3 = Float64(Float64(t_1 - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(b / a) * -0.5); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = -c / b; t_1 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if (b <= -5e+143) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5; end tmp_2 = tmp_3; elseif (b <= 3.1e+43) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (c * 2.0) / (-b - t_1); else tmp_4 = (t_1 - b) / (2.0 * a); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = (b / a) * -0.5; end tmp_5 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5e+143], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]], If[LessEqual[b, 3.1e+43], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(b / a), $MachinePrecision] * -0.5), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+143}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{+43}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a} \cdot -0.5\\
\end{array}
\end{array}
if b < -5.00000000000000012e143Initial program 40.0%
Simplified40.0%
Taylor expanded in c around 0 40.0%
mul-1-neg40.0%
distribute-neg-frac40.0%
Simplified40.0%
Taylor expanded in b around -inf 98.0%
if -5.00000000000000012e143 < b < 3.1000000000000002e43Initial program 86.4%
if 3.1000000000000002e43 < b Initial program 69.3%
Simplified69.3%
Taylor expanded in c around 0 96.3%
mul-1-neg96.3%
distribute-neg-frac96.3%
Simplified96.3%
add-sqr-sqrt96.3%
pow296.3%
pow1/296.3%
sqrt-pow196.3%
pow296.3%
metadata-eval96.3%
Applied egg-rr96.3%
Taylor expanded in b around inf 96.3%
Final simplification91.4%
(FPCore (a b c)
:precision binary64
(if (<= b 6e+42)
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))))
(/ (* b -2.0) (* 2.0 a)))
(if (>= b 0.0) (/ (- c) b) (* (/ b a) -0.5))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= 6e+42) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt(((b * b) - (c * (a * 4.0)))));
} else {
tmp_2 = (b * -2.0) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (b / a) * -0.5;
}
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 <= 6d+42) then
if (b >= 0.0d0) then
tmp_2 = (c * 2.0d0) / (-b - sqrt(((b * b) - (c * (a * 4.0d0)))))
else
tmp_2 = (b * (-2.0d0)) / (2.0d0 * a)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = -c / b
else
tmp_1 = (b / a) * (-0.5d0)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double tmp_1;
if (b <= 6e+42) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - Math.sqrt(((b * b) - (c * (a * 4.0)))));
} else {
tmp_2 = (b * -2.0) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (b / a) * -0.5;
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if b <= 6e+42: tmp_2 = 0 if b >= 0.0: tmp_2 = (c * 2.0) / (-b - math.sqrt(((b * b) - (c * (a * 4.0))))) else: tmp_2 = (b * -2.0) / (2.0 * a) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = -c / b else: tmp_1 = (b / a) * -0.5 return tmp_1
function code(a, b, c) tmp_1 = 0.0 if (b <= 6e+42) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))))); else tmp_2 = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(-c) / b); else tmp_1 = Float64(Float64(b / a) * -0.5); end return tmp_1 end
function tmp_4 = code(a, b, c) tmp_2 = 0.0; if (b <= 6e+42) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (c * 2.0) / (-b - sqrt(((b * b) - (c * (a * 4.0))))); else tmp_3 = (b * -2.0) / (2.0 * a); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = -c / b; else tmp_2 = (b / a) * -0.5; end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[LessEqual[b, 6e+42], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(b / a), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6 \cdot 10^{+42}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a} \cdot -0.5\\
\end{array}
\end{array}
if b < 6.00000000000000058e42Initial program 74.6%
Taylor expanded in b around -inf 67.4%
*-commutative67.4%
Simplified67.4%
if 6.00000000000000058e42 < b Initial program 69.3%
Simplified69.3%
Taylor expanded in c around 0 96.3%
mul-1-neg96.3%
distribute-neg-frac96.3%
Simplified96.3%
add-sqr-sqrt96.3%
pow296.3%
pow1/296.3%
sqrt-pow196.3%
pow296.3%
metadata-eval96.3%
Applied egg-rr96.3%
Taylor expanded in b around inf 96.3%
Final simplification75.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (* (+ (* -2.0 (/ c b)) (* 2.0 (/ b a))) -0.5)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
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
else
tmp = (((-2.0d0) * (c / b)) + (2.0d0 * (b / a))) * (-0.5d0)
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;
} else {
tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5 return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(Float64(-2.0 * Float64(c / b)) + Float64(2.0 * Float64(b / a))) * -0.5); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.5\\
\end{array}
\end{array}
Initial program 73.1%
Simplified73.0%
Taylor expanded in c around 0 73.4%
mul-1-neg73.4%
distribute-neg-frac73.4%
Simplified73.4%
Taylor expanded in b around -inf 68.5%
Final simplification68.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.2e-253) (if (>= b 0.0) (/ b a) (/ (* b -2.0) (* 2.0 a))) (if (>= b 0.0) (/ (- c) b) (* (/ b a) -0.5))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= 1.2e-253) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b / a;
} else {
tmp_2 = (b * -2.0) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (b / a) * -0.5;
}
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 <= 1.2d-253) then
if (b >= 0.0d0) then
tmp_2 = b / a
else
tmp_2 = (b * (-2.0d0)) / (2.0d0 * a)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = -c / b
else
tmp_1 = (b / a) * (-0.5d0)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double tmp_1;
if (b <= 1.2e-253) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b / a;
} else {
tmp_2 = (b * -2.0) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (b / a) * -0.5;
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if b <= 1.2e-253: tmp_2 = 0 if b >= 0.0: tmp_2 = b / a else: tmp_2 = (b * -2.0) / (2.0 * a) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = -c / b else: tmp_1 = (b / a) * -0.5 return tmp_1
function code(a, b, c) tmp_1 = 0.0 if (b <= 1.2e-253) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(b / a); else tmp_2 = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(-c) / b); else tmp_1 = Float64(Float64(b / a) * -0.5); end return tmp_1 end
function tmp_4 = code(a, b, c) tmp_2 = 0.0; if (b <= 1.2e-253) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = b / a; else tmp_3 = (b * -2.0) / (2.0 * a); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = -c / b; else tmp_2 = (b / a) * -0.5; end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[LessEqual[b, 1.2e-253], If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(b / a), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.2 \cdot 10^{-253}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a} \cdot -0.5\\
\end{array}
\end{array}
if b < 1.20000000000000005e-253Initial program 71.7%
Taylor expanded in b around -inf 62.1%
*-commutative62.1%
Simplified62.1%
Taylor expanded in b around inf 58.6%
*-commutative58.6%
Simplified58.6%
associate--r+58.6%
cancel-sign-sub-inv58.6%
neg-mul-158.6%
*-un-lft-identity58.6%
distribute-rgt-out--58.6%
metadata-eval58.6%
metadata-eval58.6%
associate-/l*58.6%
Applied egg-rr58.6%
Taylor expanded in c around inf 58.6%
if 1.20000000000000005e-253 < b Initial program 74.6%
Simplified74.4%
Taylor expanded in c around 0 79.1%
mul-1-neg79.1%
distribute-neg-frac79.1%
Simplified79.1%
add-sqr-sqrt79.1%
pow279.1%
pow1/279.1%
sqrt-pow179.1%
pow279.1%
metadata-eval79.1%
Applied egg-rr79.1%
Taylor expanded in b around inf 79.1%
Final simplification68.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ (* b -2.0) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (b * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = (b * (-2.0d0)) / (2.0d0 * a)
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;
} else {
tmp = (b * -2.0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (b * -2.0) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = (b * -2.0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 73.1%
Taylor expanded in b around -inf 68.0%
*-commutative68.0%
Simplified68.0%
Taylor expanded in c around 0 68.3%
associate-*r/68.3%
mul-1-neg68.3%
Simplified68.3%
Final simplification68.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (* (/ b a) -0.5)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (b / a) * -0.5;
}
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
else
tmp = (b / a) * (-0.5d0)
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;
} else {
tmp = (b / a) * -0.5;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (b / a) * -0.5 return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(b / a) * -0.5); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = (b / a) * -0.5; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(b / a), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a} \cdot -0.5\\
\end{array}
\end{array}
Initial program 73.1%
Simplified73.0%
Taylor expanded in c around 0 73.4%
mul-1-neg73.4%
distribute-neg-frac73.4%
Simplified73.4%
add-sqr-sqrt73.3%
pow273.3%
pow1/273.3%
sqrt-pow173.3%
pow273.3%
metadata-eval73.3%
Applied egg-rr73.3%
Taylor expanded in b around inf 50.3%
Final simplification50.3%
herbie shell --seed 2024024
(FPCore (a b c)
:name "jeff quadratic root 2"
:precision binary64
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))