
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1.45e-85)
(/ (- c) b)
(if (<= b 4.5e+69)
(fma -0.5 (/ b a) (/ (sqrt (fma a (* c -4.0) (* b b))) (* a -2.0)))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-85) {
tmp = -c / b;
} else if (b <= 4.5e+69) {
tmp = fma(-0.5, (b / a), (sqrt(fma(a, (c * -4.0), (b * b))) / (a * -2.0)));
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-85) tmp = Float64(Float64(-c) / b); elseif (b <= 4.5e+69) tmp = fma(-0.5, Float64(b / a), Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) / Float64(a * -2.0))); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-85], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.5e+69], N[(-0.5 * N[(b / a), $MachinePrecision] + N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-85}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{+69}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \frac{b}{a}, \frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a \cdot -2}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.4500000000000001e-85Initial program 22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -1.4500000000000001e-85 < b < 4.4999999999999999e69Initial program 82.0%
div-sub82.0%
neg-mul-182.0%
times-frac82.0%
fma-neg82.0%
metadata-eval82.0%
frac-2neg82.0%
distribute-neg-frac82.0%
remove-double-neg82.0%
fma-neg81.9%
distribute-lft-neg-in81.9%
*-commutative81.9%
associate-*l*81.9%
metadata-eval81.9%
*-commutative81.9%
Applied egg-rr81.9%
fma-def82.0%
+-commutative82.0%
fma-def82.0%
Simplified82.0%
if 4.4999999999999999e69 < b Initial program 57.8%
Taylor expanded in b around inf 97.2%
associate-*r/97.2%
neg-mul-197.2%
Simplified97.2%
Final simplification88.0%
(FPCore (a b c)
:precision binary64
(if (<= b -7.6e-88)
(/ (- c) b)
(if (<= b 6e+69)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-88) {
tmp = -c / b;
} else if (b <= 6e+69) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-7.6d-88)) then
tmp = -c / b
else if (b <= 6d+69) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-88) {
tmp = -c / b;
} else if (b <= 6e+69) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.6e-88: tmp = -c / b elif b <= 6e+69: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.6e-88) tmp = Float64(Float64(-c) / b); elseif (b <= 6e+69) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.6e-88) tmp = -c / b; elseif (b <= 6e+69) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.6e-88], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 6e+69], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.6 \cdot 10^{-88}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{+69}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.60000000000000022e-88Initial program 22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -7.60000000000000022e-88 < b < 5.99999999999999967e69Initial program 82.0%
if 5.99999999999999967e69 < b Initial program 57.8%
Taylor expanded in b around inf 97.2%
associate-*r/97.2%
neg-mul-197.2%
Simplified97.2%
Final simplification88.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.8e-87)
(/ (- c) b)
(if (<= b 5.2e+67)
(* (/ -0.5 a) (+ b (sqrt (+ (* b b) (* a (* c -4.0))))))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-87) {
tmp = -c / b;
} else if (b <= 5.2e+67) {
tmp = (-0.5 / a) * (b + sqrt(((b * b) + (a * (c * -4.0)))));
} 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 <= (-3.8d-87)) then
tmp = -c / b
else if (b <= 5.2d+67) then
tmp = ((-0.5d0) / a) * (b + sqrt(((b * b) + (a * (c * (-4.0d0))))))
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-87) {
tmp = -c / b;
} else if (b <= 5.2e+67) {
tmp = (-0.5 / a) * (b + Math.sqrt(((b * b) + (a * (c * -4.0)))));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.8e-87: tmp = -c / b elif b <= 5.2e+67: tmp = (-0.5 / a) * (b + math.sqrt(((b * b) + (a * (c * -4.0))))) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.8e-87) tmp = Float64(Float64(-c) / b); elseif (b <= 5.2e+67) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))))); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.8e-87) tmp = -c / b; elseif (b <= 5.2e+67) tmp = (-0.5 / a) * (b + sqrt(((b * b) + (a * (c * -4.0))))); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.8e-87], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.2e+67], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.8 \cdot 10^{-87}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{+67}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.8e-87Initial program 22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -3.8e-87 < b < 5.2000000000000001e67Initial program 82.0%
frac-2neg82.0%
div-inv81.8%
*-commutative81.8%
distribute-lft-neg-in81.8%
associate-/r*81.8%
metadata-eval81.8%
metadata-eval81.8%
sub-neg81.8%
distribute-neg-out81.8%
remove-double-neg81.8%
fma-neg81.8%
distribute-lft-neg-in81.8%
*-commutative81.8%
associate-*l*81.8%
metadata-eval81.8%
Applied egg-rr81.8%
fma-udef81.8%
Applied egg-rr81.8%
if 5.2000000000000001e67 < b Initial program 57.8%
Taylor expanded in b around inf 97.2%
associate-*r/97.2%
neg-mul-197.2%
Simplified97.2%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -6e-86)
(/ (- c) b)
(if (<= b 2.25e-120)
(/ (- (- b) (sqrt (* a (* c -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e-86) {
tmp = -c / b;
} else if (b <= 2.25e-120) {
tmp = (-b - sqrt((a * (c * -4.0)))) / (a * 2.0);
} 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 <= (-6d-86)) then
tmp = -c / b
else if (b <= 2.25d-120) then
tmp = (-b - sqrt((a * (c * (-4.0d0))))) / (a * 2.0d0)
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 <= -6e-86) {
tmp = -c / b;
} else if (b <= 2.25e-120) {
tmp = (-b - Math.sqrt((a * (c * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e-86: tmp = -c / b elif b <= 2.25e-120: tmp = (-b - math.sqrt((a * (c * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e-86) tmp = Float64(Float64(-c) / b); elseif (b <= 2.25e-120) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(a * Float64(c * -4.0)))) / Float64(a * 2.0)); 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 <= -6e-86) tmp = -c / b; elseif (b <= 2.25e-120) tmp = (-b - sqrt((a * (c * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e-86], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.25e-120], N[(N[((-b) - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{-86}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{-120}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.0000000000000002e-86Initial program 22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -6.0000000000000002e-86 < b < 2.25e-120Initial program 79.4%
Taylor expanded in b around 0 74.6%
*-commutative74.6%
associate-*r*74.6%
Simplified74.6%
if 2.25e-120 < b Initial program 67.2%
Taylor expanded in b around inf 88.3%
+-commutative88.3%
mul-1-neg88.3%
unsub-neg88.3%
Simplified88.3%
Final simplification85.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.2e-88)
(/ (- c) b)
(if (<= b 2.8e-120)
(* (/ -0.5 a) (+ b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-88) {
tmp = -c / b;
} else if (b <= 2.8e-120) {
tmp = (-0.5 / a) * (b + sqrt((a * (c * -4.0))));
} 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 <= (-3.2d-88)) then
tmp = -c / b
else if (b <= 2.8d-120) then
tmp = ((-0.5d0) / a) * (b + sqrt((a * (c * (-4.0d0)))))
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 <= -3.2e-88) {
tmp = -c / b;
} else if (b <= 2.8e-120) {
tmp = (-0.5 / a) * (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-88: tmp = -c / b elif b <= 2.8e-120: tmp = (-0.5 / a) * (b + math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-88) tmp = Float64(Float64(-c) / b); elseif (b <= 2.8e-120) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(a * Float64(c * -4.0))))); 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 <= -3.2e-88) tmp = -c / b; elseif (b <= 2.8e-120) tmp = (-0.5 / a) * (b + sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-88], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.8e-120], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-88}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-120}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.20000000000000012e-88Initial program 22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -3.20000000000000012e-88 < b < 2.79999999999999994e-120Initial program 79.4%
frac-2neg79.4%
div-inv79.3%
*-commutative79.3%
distribute-lft-neg-in79.3%
associate-/r*79.3%
metadata-eval79.3%
metadata-eval79.3%
sub-neg79.3%
distribute-neg-out79.3%
remove-double-neg79.3%
fma-neg79.3%
distribute-lft-neg-in79.3%
*-commutative79.3%
associate-*l*79.3%
metadata-eval79.3%
Applied egg-rr79.3%
Taylor expanded in b around 0 74.5%
*-commutative74.5%
associate-*r*74.5%
Simplified74.5%
if 2.79999999999999994e-120 < b Initial program 67.2%
Taylor expanded in b around inf 88.3%
+-commutative88.3%
mul-1-neg88.3%
unsub-neg88.3%
Simplified88.3%
Final simplification85.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / 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 <= (-5d-310)) then
tmp = -c / 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 <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / 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 <= -5e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 35.8%
Taylor expanded in b around -inf 69.3%
associate-*r/69.3%
neg-mul-169.3%
Simplified69.3%
if -4.999999999999985e-310 < b Initial program 70.0%
Taylor expanded in b around inf 78.3%
+-commutative78.3%
mul-1-neg78.3%
unsub-neg78.3%
Simplified78.3%
Final simplification73.4%
(FPCore (a b c) :precision binary64 (if (<= b -1.4e-20) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-20) {
tmp = c / b;
} 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 <= (-1.4d-20)) then
tmp = c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-20) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e-20: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e-20) tmp = Float64(c / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.4e-20) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e-20], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{-20}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.4000000000000001e-20Initial program 18.6%
frac-2neg18.6%
div-inv18.6%
*-commutative18.6%
distribute-lft-neg-in18.6%
associate-/r*18.6%
metadata-eval18.6%
metadata-eval18.6%
sub-neg18.6%
distribute-neg-out18.6%
remove-double-neg18.6%
fma-neg18.6%
distribute-lft-neg-in18.6%
*-commutative18.6%
associate-*l*18.6%
metadata-eval18.6%
Applied egg-rr18.6%
Taylor expanded in b around inf 2.4%
associate-*r/2.4%
*-commutative2.4%
associate-*l*2.4%
*-commutative2.4%
Simplified2.4%
Taylor expanded in a around inf 34.6%
if -1.4000000000000001e-20 < b Initial program 68.9%
Taylor expanded in b around inf 55.2%
associate-*r/55.2%
neg-mul-155.2%
Simplified55.2%
Final simplification48.0%
(FPCore (a b c) :precision binary64 (if (<= b -2.6e-301) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-301) {
tmp = -c / b;
} 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 <= (-2.6d-301)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-301) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.6e-301: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.6e-301) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.6e-301) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.6e-301], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{-301}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.5999999999999998e-301Initial program 35.3%
Taylor expanded in b around -inf 69.8%
associate-*r/69.8%
neg-mul-169.8%
Simplified69.8%
if -2.5999999999999998e-301 < b Initial program 70.2%
Taylor expanded in b around inf 76.8%
associate-*r/76.8%
neg-mul-176.8%
Simplified76.8%
Final simplification73.0%
(FPCore (a b c) :precision binary64 (if (<= b -4.0) (/ c b) (/ -0.5 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.0) {
tmp = c / b;
} else {
tmp = -0.5 / 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 <= (-4.0d0)) then
tmp = c / b
else
tmp = (-0.5d0) / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.0) {
tmp = c / b;
} else {
tmp = -0.5 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.0: tmp = c / b else: tmp = -0.5 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.0) tmp = Float64(c / b); else tmp = Float64(-0.5 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.0) tmp = c / b; else tmp = -0.5 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.0], N[(c / b), $MachinePrecision], N[(-0.5 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{a}\\
\end{array}
\end{array}
if b < -4Initial program 18.2%
frac-2neg18.2%
div-inv18.2%
*-commutative18.2%
distribute-lft-neg-in18.2%
associate-/r*18.2%
metadata-eval18.2%
metadata-eval18.2%
sub-neg18.2%
distribute-neg-out18.2%
remove-double-neg18.2%
fma-neg18.2%
distribute-lft-neg-in18.2%
*-commutative18.2%
associate-*l*18.2%
metadata-eval18.2%
Applied egg-rr18.2%
Taylor expanded in b around inf 2.4%
associate-*r/2.5%
*-commutative2.5%
associate-*l*2.5%
*-commutative2.5%
Simplified2.5%
Taylor expanded in a around inf 36.1%
if -4 < b Initial program 67.9%
Applied egg-rr56.1%
*-lft-identity56.1%
*-commutative56.1%
Applied egg-rr61.0%
Simplified6.0%
Final simplification16.0%
(FPCore (a b c) :precision binary64 (/ -0.5 a))
double code(double a, double b, double c) {
return -0.5 / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-0.5d0) / a
end function
public static double code(double a, double b, double c) {
return -0.5 / a;
}
def code(a, b, c): return -0.5 / a
function code(a, b, c) return Float64(-0.5 / a) end
function tmp = code(a, b, c) tmp = -0.5 / a; end
code[a_, b_, c_] := N[(-0.5 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5}{a}
\end{array}
Initial program 51.4%
Applied egg-rr43.2%
*-lft-identity43.2%
*-commutative43.2%
Applied egg-rr50.9%
Simplified5.2%
Final simplification5.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t_0 - t_1} \cdot \sqrt{t_0 + t_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{t_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2023297
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:herbie-target
(if (< b 0.0) (/ c (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0))) (/ (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))