
(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 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) (/ (* 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 (if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (- (/ c b) (/ b a)))))
(if (<= b -1.1e+154)
t_0
(if (<= b 2.02e+102)
(if (>= b 0.0)
(/ (* (- c) 2.0) (+ (sqrt (- (* b b) (* (* a 4.0) c))) b))
(/ (- (sqrt (fma b b (* (* -4.0 c) a))) b) (* a 2.0)))
t_0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.0 * b);
} else {
tmp = (c / b) - (b / a);
}
double t_0 = tmp;
double tmp_1;
if (b <= -1.1e+154) {
tmp_1 = t_0;
} else if (b <= 2.02e+102) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-c * 2.0) / (sqrt(((b * b) - ((a * 4.0) * c))) + b);
} else {
tmp_2 = (sqrt(fma(b, b, ((-4.0 * c) * a))) - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end t_0 = tmp tmp_1 = 0.0 if (b <= -1.1e+154) tmp_1 = t_0; elseif (b <= 2.02e+102) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(Float64(-c) * 2.0) / Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) + b)); else tmp_2 = Float64(Float64(sqrt(fma(b, b, Float64(Float64(-4.0 * c) * a))) - b) / Float64(a * 2.0)); end tmp_1 = tmp_2; else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[b, -1.1e+154], t$95$0, If[LessEqual[b, 2.02e+102], If[GreaterEqual[b, 0.0], N[(N[((-c) * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(b * b + N[(N[(-4.0 * c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{if}\;b \leq -1.1 \cdot 10^{+154}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 2.02 \cdot 10^{+102}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-c\right) \cdot 2}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-4 \cdot c\right) \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1.1000000000000001e154 or 2.01999999999999997e102 < b Initial program 46.5%
Taylor expanded in c around 0
lower-*.f6466.6
Applied rewrites66.6%
Taylor expanded in b around -inf
lower-*.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.1
Applied rewrites95.1%
Taylor expanded in c around 0
Applied rewrites95.4%
if -1.1000000000000001e154 < b < 2.01999999999999997e102Initial program 90.2%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval90.2
Applied rewrites90.2%
Final simplification92.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (fma a (/ c b) (- b)) 2.0))
(t_1 (/ t_0 (* a 2.0)))
(t_2 (/ (* c 2.0) (* -2.0 b)))
(t_3 (sqrt (* (* a c) -4.0))))
(if (<= b -7.8e-81)
(if (>= b 0.0) t_2 (- (/ c b) (/ b a)))
(if (<= b -5e-311)
(if (>= b 0.0) t_2 (/ (- t_3 b) (* a 2.0)))
(if (<= b 2.6e-104)
(if (>= b 0.0) (/ (* (- c) 2.0) (+ t_3 b)) t_1)
(if (>= b 0.0) (/ (* c 2.0) t_0) t_1))))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c / b), -b) * 2.0;
double t_1 = t_0 / (a * 2.0);
double t_2 = (c * 2.0) / (-2.0 * b);
double t_3 = sqrt(((a * c) * -4.0));
double tmp_1;
if (b <= -7.8e-81) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_2;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b <= -5e-311) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_2;
} else {
tmp_3 = (t_3 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b <= 2.6e-104) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (-c * 2.0) / (t_3 + b);
} else {
tmp_4 = t_1;
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / t_0;
} else {
tmp_1 = t_1;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(fma(a, Float64(c / b), Float64(-b)) * 2.0) t_1 = Float64(t_0 / Float64(a * 2.0)) t_2 = Float64(Float64(c * 2.0) / Float64(-2.0 * b)) t_3 = sqrt(Float64(Float64(a * c) * -4.0)) tmp_1 = 0.0 if (b <= -7.8e-81) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_2; else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b <= -5e-311) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_2; else tmp_3 = Float64(Float64(t_3 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b <= 2.6e-104) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(Float64(-c) * 2.0) / Float64(t_3 + b)); else tmp_4 = t_1; end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / t_0); else tmp_1 = t_1; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision] * 2.0), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -7.8e-81], If[GreaterEqual[b, 0.0], t$95$2, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, -5e-311], If[GreaterEqual[b, 0.0], t$95$2, N[(N[(t$95$3 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.6e-104], If[GreaterEqual[b, 0.0], N[(N[((-c) * 2.0), $MachinePrecision] / N[(t$95$3 + b), $MachinePrecision]), $MachinePrecision], t$95$1], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / t$95$0), $MachinePrecision], t$95$1]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, \frac{c}{b}, -b\right) \cdot 2\\
t_1 := \frac{t\_0}{a \cdot 2}\\
t_2 := \frac{c \cdot 2}{-2 \cdot b}\\
t_3 := \sqrt{\left(a \cdot c\right) \cdot -4}\\
\mathbf{if}\;b \leq -7.8 \cdot 10^{-81}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_3 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-104}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-c\right) \cdot 2}{t\_3 + b}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if b < -7.7999999999999997e-81Initial program 72.3%
Taylor expanded in c around 0
lower-*.f6472.3
Applied rewrites72.3%
Taylor expanded in b around -inf
lower-*.f6487.0
Applied rewrites87.0%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6487.4
Applied rewrites87.4%
Taylor expanded in c around 0
Applied rewrites87.8%
if -7.7999999999999997e-81 < b < -5.00000000000023e-311Initial program 87.0%
Taylor expanded in c around 0
lower-*.f6487.0
Applied rewrites87.0%
Taylor expanded in c around inf
lower-*.f64N/A
lower-*.f6472.4
Applied rewrites72.4%
if -5.00000000000023e-311 < b < 2.60000000000000003e-104Initial program 81.5%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
associate-*r/N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6481.5
Applied rewrites81.5%
Taylor expanded in c around 0
Applied rewrites81.5%
Taylor expanded in c around inf
lower-*.f64N/A
lower-*.f6481.5
Applied rewrites81.5%
if 2.60000000000000003e-104 < b Initial program 69.9%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
associate-*r/N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6469.9
Applied rewrites69.9%
Taylor expanded in c around 0
Applied rewrites69.9%
Taylor expanded in c around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6486.5
Applied rewrites86.5%
Final simplification84.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (- (/ c b) (/ b a))))
(t_1 (sqrt (fma -4.0 (* a c) (* b b)))))
(if (<= b -1.1e+154)
t_0
(if (<= b 2.02e+102)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_1 b)) (* 0.5 (/ (- t_1 b) a)))
t_0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.0 * b);
} else {
tmp = (c / b) - (b / a);
}
double t_0 = tmp;
double t_1 = sqrt(fma(-4.0, (a * c), (b * b)));
double tmp_1;
if (b <= -1.1e+154) {
tmp_1 = t_0;
} else if (b <= 2.02e+102) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-2.0 * c) / (t_1 + b);
} else {
tmp_2 = 0.5 * ((t_1 - b) / a);
}
tmp_1 = tmp_2;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end t_0 = tmp t_1 = sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) tmp_1 = 0.0 if (b <= -1.1e+154) tmp_1 = t_0; elseif (b <= 2.02e+102) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-2.0 * c) / Float64(t_1 + b)); else tmp_2 = Float64(0.5 * Float64(Float64(t_1 - b) / a)); end tmp_1 = tmp_2; else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$1 = N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1.1e+154], t$95$0, If[LessEqual[b, 2.02e+102], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$1 + b), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(t$95$1 - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
t_1 := \sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)}\\
\mathbf{if}\;b \leq -1.1 \cdot 10^{+154}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 2.02 \cdot 10^{+102}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_1 + b}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{t\_1 - b}{a}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1.1000000000000001e154 or 2.01999999999999997e102 < b Initial program 46.5%
Taylor expanded in c around 0
lower-*.f6466.6
Applied rewrites66.6%
Taylor expanded in b around -inf
lower-*.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.1
Applied rewrites95.1%
Taylor expanded in c around 0
Applied rewrites95.4%
if -1.1000000000000001e154 < b < 2.01999999999999997e102Initial program 90.2%
Taylor expanded in c around 0
lower-*.f6474.1
Applied rewrites74.1%
Taylor expanded in c around 0
lower->=.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
Applied rewrites90.2%
Final simplification92.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* c 2.0) (* -2.0 b))))
(if (<= b -7.8e-81)
(if (>= b 0.0) t_0 (- (/ c b) (/ b a)))
(if (>= b 0.0) t_0 (/ (- (sqrt (* (* a c) -4.0)) b) (* a 2.0))))))
double code(double a, double b, double c) {
double t_0 = (c * 2.0) / (-2.0 * b);
double tmp_1;
if (b <= -7.8e-81) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (sqrt(((a * c) * -4.0)) - b) / (a * 2.0);
}
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 = (c * 2.0d0) / ((-2.0d0) * b)
if (b <= (-7.8d-81)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = (c / b) - (b / a)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = (sqrt(((a * c) * (-4.0d0))) - b) / (a * 2.0d0)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = (c * 2.0) / (-2.0 * b);
double tmp_1;
if (b <= -7.8e-81) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (Math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): t_0 = (c * 2.0) / (-2.0 * b) tmp_1 = 0 if b <= -7.8e-81: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = (c / b) - (b / a) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = (math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0) return tmp_1
function code(a, b, c) t_0 = Float64(Float64(c * 2.0) / Float64(-2.0 * b)) tmp_1 = 0.0 if (b <= -7.8e-81) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(sqrt(Float64(Float64(a * c) * -4.0)) - b) / Float64(a * 2.0)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (c * 2.0) / (-2.0 * b); tmp_2 = 0.0; if (b <= -7.8e-81) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = (c / b) - (b / a); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = (sqrt(((a * c) * -4.0)) - b) / (a * 2.0); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -7.8e-81], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{if}\;b \leq -7.8 \cdot 10^{-81}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\left(a \cdot c\right) \cdot -4} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -7.7999999999999997e-81Initial program 72.3%
Taylor expanded in c around 0
lower-*.f6472.3
Applied rewrites72.3%
Taylor expanded in b around -inf
lower-*.f6487.0
Applied rewrites87.0%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6487.4
Applied rewrites87.4%
Taylor expanded in c around 0
Applied rewrites87.8%
if -7.7999999999999997e-81 < b Initial program 76.4%
Taylor expanded in c around 0
lower-*.f6470.8
Applied rewrites70.8%
Taylor expanded in c around inf
lower-*.f64N/A
lower-*.f6467.3
Applied rewrites67.3%
Final simplification75.9%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* (fma a (/ c b) (- b)) 2.0))) (if (>= b 0.0) (/ (* c 2.0) t_0) (/ t_0 (* a 2.0)))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c / b), -b) * 2.0;
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / t_0;
} else {
tmp = t_0 / (a * 2.0);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(fma(a, Float64(c / b), Float64(-b)) * 2.0) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / t_0); else tmp = Float64(t_0 / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision] * 2.0), $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / t$95$0), $MachinePrecision], N[(t$95$0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, \frac{c}{b}, -b\right) \cdot 2\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 74.7%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
associate-*r/N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6472.2
Applied rewrites72.2%
Taylor expanded in c around 0
Applied rewrites72.2%
Taylor expanded in c around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6469.3
Applied rewrites69.3%
Final simplification69.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.0 * b);
} else {
tmp = (c / b) - (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 = (c * 2.0d0) / ((-2.0d0) * b)
else
tmp = (c / b) - (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 = (c * 2.0) / (-2.0 * b);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c * 2.0) / (-2.0 * b) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (c * 2.0) / (-2.0 * b); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
Initial program 74.7%
Taylor expanded in c around 0
lower-*.f6471.4
Applied rewrites71.4%
Taylor expanded in b around -inf
lower-*.f6468.6
Applied rewrites68.6%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6468.4
Applied rewrites68.4%
Taylor expanded in c around 0
Applied rewrites69.0%
Final simplification69.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (/ (* -2.0 b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.0 * b);
} else {
tmp = (-2.0 * b) / (a * 2.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) :: tmp
if (b >= 0.0d0) then
tmp = (c * 2.0d0) / ((-2.0d0) * b)
else
tmp = ((-2.0d0) * b) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.0 * b);
} else {
tmp = (-2.0 * b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c * 2.0) / (-2.0 * b) else: tmp = (-2.0 * b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp = Float64(Float64(-2.0 * b) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (c * 2.0) / (-2.0 * b); else tmp = (-2.0 * b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 74.7%
Taylor expanded in c around 0
lower-*.f6471.4
Applied rewrites71.4%
Taylor expanded in b around -inf
lower-*.f6468.6
Applied rewrites68.6%
Final simplification68.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* (/ 2.0 (* -2.0 b)) c) (/ (* -2.0 b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 / (-2.0 * b)) * c;
} else {
tmp = (-2.0 * b) / (a * 2.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) :: tmp
if (b >= 0.0d0) then
tmp = (2.0d0 / ((-2.0d0) * b)) * c
else
tmp = ((-2.0d0) * b) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 / (-2.0 * b)) * c;
} else {
tmp = (-2.0 * b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (2.0 / (-2.0 * b)) * c else: tmp = (-2.0 * b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 / Float64(-2.0 * b)) * c); else tmp = Float64(Float64(-2.0 * b) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (2.0 / (-2.0 * b)) * c; else tmp = (-2.0 * b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(N[(-2.0 * b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{-2 \cdot b} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 74.7%
Taylor expanded in c around 0
lower-*.f6471.4
Applied rewrites71.4%
Taylor expanded in b around -inf
lower-*.f6468.6
Applied rewrites68.6%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6468.5
Applied rewrites68.5%
Final simplification68.5%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- b) a))) (if (>= b 0.0) t_0 t_0)))
double code(double a, double b, double c) {
double t_0 = -b / a;
double tmp;
if (b >= 0.0) {
tmp = t_0;
} else {
tmp = 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 = -b / a
if (b >= 0.0d0) then
tmp = t_0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = -b / a;
double tmp;
if (b >= 0.0) {
tmp = t_0;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c): t_0 = -b / a tmp = 0 if b >= 0.0: tmp = t_0 else: tmp = t_0 return tmp
function code(a, b, c) t_0 = Float64(Float64(-b) / a) tmp = 0.0 if (b >= 0.0) tmp = t_0; else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c) t_0 = -b / a; tmp = 0.0; if (b >= 0.0) tmp = t_0; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-b) / a), $MachinePrecision]}, If[GreaterEqual[b, 0.0], t$95$0, t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-b}{a}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
Initial program 74.7%
Taylor expanded in c around 0
lower-*.f6471.4
Applied rewrites71.4%
Taylor expanded in b around -inf
lower-*.f6468.6
Applied rewrites68.6%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6440.9
Applied rewrites40.9%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6440.9
Applied rewrites40.9%
herbie shell --seed 2024273
(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))))