
(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 9 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.35e-63)
(/ 0.5 (+ (* -0.5 (/ b c)) (* 0.5 (/ a b))))
(if (<= b 1.8e+130)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e-63) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 1.8e+130) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (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 <= (-1.35d-63)) then
tmp = 0.5d0 / (((-0.5d0) * (b / c)) + (0.5d0 * (a / b)))
else if (b <= 1.8d+130) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (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 <= -1.35e-63) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 1.8e+130) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e-63: tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))) elif b <= 1.8e+130: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e-63) tmp = Float64(0.5 / Float64(Float64(-0.5 * Float64(b / c)) + Float64(0.5 * Float64(a / b)))); elseif (b <= 1.8e+130) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / 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 <= -1.35e-63) tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))); elseif (b <= 1.8e+130) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e-63], N[(0.5 / N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.8e+130], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{-63}:\\
\;\;\;\;\frac{0.5}{-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+130}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.3500000000000001e-63Initial program 17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/r*17.3%
metadata-eval17.3%
Simplified17.3%
frac-2neg17.3%
associate-*r/17.3%
metadata-eval17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/l*17.3%
Simplified17.3%
Taylor expanded in b around -inf 88.2%
if -1.3500000000000001e-63 < b < 1.8000000000000001e130Initial program 89.7%
if 1.8000000000000001e130 < b Initial program 49.6%
Taylor expanded in b around inf 97.1%
+-commutative97.1%
mul-1-neg97.1%
unsub-neg97.1%
Simplified97.1%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-68)
(/ 0.5 (+ (* -0.5 (/ b c)) (* 0.5 (/ a b))))
(if (<= b 1.55e-66)
(- (* b (/ -0.5 a)) (* 0.5 (/ (sqrt (* a (* c -4.0))) a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-68) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 1.55e-66) {
tmp = (b * (-0.5 / a)) - (0.5 * (sqrt((a * (c * -4.0))) / a));
} 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 <= (-4.6d-68)) then
tmp = 0.5d0 / (((-0.5d0) * (b / c)) + (0.5d0 * (a / b)))
else if (b <= 1.55d-66) then
tmp = (b * ((-0.5d0) / a)) - (0.5d0 * (sqrt((a * (c * (-4.0d0)))) / a))
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 <= -4.6e-68) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 1.55e-66) {
tmp = (b * (-0.5 / a)) - (0.5 * (Math.sqrt((a * (c * -4.0))) / a));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-68: tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))) elif b <= 1.55e-66: tmp = (b * (-0.5 / a)) - (0.5 * (math.sqrt((a * (c * -4.0))) / a)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-68) tmp = Float64(0.5 / Float64(Float64(-0.5 * Float64(b / c)) + Float64(0.5 * Float64(a / b)))); elseif (b <= 1.55e-66) tmp = Float64(Float64(b * Float64(-0.5 / a)) - Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a))); 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 <= -4.6e-68) tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))); elseif (b <= 1.55e-66) tmp = (b * (-0.5 / a)) - (0.5 * (sqrt((a * (c * -4.0))) / a)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-68], N[(0.5 / N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.55e-66], N[(N[(b * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{-68}:\\
\;\;\;\;\frac{0.5}{-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-66}:\\
\;\;\;\;b \cdot \frac{-0.5}{a} - 0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.59999999999999994e-68Initial program 17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/r*17.3%
metadata-eval17.3%
Simplified17.3%
frac-2neg17.3%
associate-*r/17.3%
metadata-eval17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/l*17.3%
Simplified17.3%
Taylor expanded in b around -inf 88.2%
if -4.59999999999999994e-68 < b < 1.5499999999999999e-66Initial program 86.2%
Taylor expanded in b around 0 81.4%
*-commutative81.4%
associate-*r*81.4%
Simplified81.4%
div-sub81.4%
sub-neg81.4%
div-inv81.4%
add-sqr-sqrt40.4%
sqrt-unprod79.3%
sqr-neg79.3%
unpow279.3%
unpow279.3%
sqrt-prod39.1%
add-sqr-sqrt79.4%
metadata-eval79.4%
associate-/r*79.4%
metadata-eval79.4%
metadata-eval79.4%
div-inv79.2%
metadata-eval79.2%
associate-/r*79.2%
metadata-eval79.2%
metadata-eval79.2%
Applied egg-rr79.2%
sub-neg79.2%
distribute-rgt-out--79.2%
Simplified79.2%
Applied egg-rr81.4%
if 1.5499999999999999e-66 < b Initial program 68.5%
Taylor expanded in b around inf 88.4%
+-commutative88.4%
mul-1-neg88.4%
unsub-neg88.4%
Simplified88.4%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -3.3e-65)
(/ 0.5 (+ (* -0.5 (/ b c)) (* 0.5 (/ a b))))
(if (<= b 5.4e-66)
(/ (- (- 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 <= -3.3e-65) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 5.4e-66) {
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 <= (-3.3d-65)) then
tmp = 0.5d0 / (((-0.5d0) * (b / c)) + (0.5d0 * (a / b)))
else if (b <= 5.4d-66) 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 <= -3.3e-65) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 5.4e-66) {
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 <= -3.3e-65: tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))) elif b <= 5.4e-66: 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 <= -3.3e-65) tmp = Float64(0.5 / Float64(Float64(-0.5 * Float64(b / c)) + Float64(0.5 * Float64(a / b)))); elseif (b <= 5.4e-66) 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 <= -3.3e-65) tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))); elseif (b <= 5.4e-66) 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, -3.3e-65], N[(0.5 / N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.4e-66], 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 -3.3 \cdot 10^{-65}:\\
\;\;\;\;\frac{0.5}{-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}}\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{-66}:\\
\;\;\;\;\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 < -3.3000000000000001e-65Initial program 17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/r*17.3%
metadata-eval17.3%
Simplified17.3%
frac-2neg17.3%
associate-*r/17.3%
metadata-eval17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/l*17.3%
Simplified17.3%
Taylor expanded in b around -inf 88.2%
if -3.3000000000000001e-65 < b < 5.39999999999999992e-66Initial program 86.2%
Taylor expanded in b around 0 81.4%
*-commutative81.4%
associate-*r*81.4%
Simplified81.4%
if 5.39999999999999992e-66 < b Initial program 68.5%
Taylor expanded in b around inf 88.4%
+-commutative88.4%
mul-1-neg88.4%
unsub-neg88.4%
Simplified88.4%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -2.25e-67)
(/ 0.5 (+ (* -0.5 (/ b c)) (* 0.5 (/ a b))))
(if (<= b 3.5e-69)
(* (/ -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 <= -2.25e-67) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 3.5e-69) {
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 <= (-2.25d-67)) then
tmp = 0.5d0 / (((-0.5d0) * (b / c)) + (0.5d0 * (a / b)))
else if (b <= 3.5d-69) 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 <= -2.25e-67) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else if (b <= 3.5e-69) {
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 <= -2.25e-67: tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))) elif b <= 3.5e-69: 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 <= -2.25e-67) tmp = Float64(0.5 / Float64(Float64(-0.5 * Float64(b / c)) + Float64(0.5 * Float64(a / b)))); elseif (b <= 3.5e-69) 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 <= -2.25e-67) tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))); elseif (b <= 3.5e-69) 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, -2.25e-67], N[(0.5 / N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.5e-69], 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 -2.25 \cdot 10^{-67}:\\
\;\;\;\;\frac{0.5}{-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{-69}:\\
\;\;\;\;\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 < -2.25000000000000008e-67Initial program 17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/r*17.3%
metadata-eval17.3%
Simplified17.3%
frac-2neg17.3%
associate-*r/17.3%
metadata-eval17.3%
Applied egg-rr17.3%
*-commutative17.3%
associate-/l*17.3%
Simplified17.3%
Taylor expanded in b around -inf 88.2%
if -2.25000000000000008e-67 < b < 3.5000000000000001e-69Initial program 86.2%
Taylor expanded in b around 0 81.4%
*-commutative81.4%
associate-*r*81.4%
Simplified81.4%
div-sub81.4%
sub-neg81.4%
div-inv81.4%
add-sqr-sqrt40.4%
sqrt-unprod79.3%
sqr-neg79.3%
unpow279.3%
unpow279.3%
sqrt-prod39.1%
add-sqr-sqrt79.4%
metadata-eval79.4%
associate-/r*79.4%
metadata-eval79.4%
metadata-eval79.4%
div-inv79.2%
metadata-eval79.2%
associate-/r*79.2%
metadata-eval79.2%
metadata-eval79.2%
Applied egg-rr79.2%
sub-neg79.2%
distribute-rgt-out--79.2%
Simplified79.2%
Applied egg-rr81.4%
*-commutative81.4%
distribute-lft-neg-in81.4%
metadata-eval81.4%
associate-*r/81.4%
associate-*l/81.3%
distribute-lft-in81.2%
Simplified81.2%
if 3.5000000000000001e-69 < b Initial program 68.5%
Taylor expanded in b around inf 88.4%
+-commutative88.4%
mul-1-neg88.4%
unsub-neg88.4%
Simplified88.4%
Final simplification86.4%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ 0.5 (+ (* -0.5 (/ b c)) (* 0.5 (/ a b)))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / 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 <= (-4d-310)) then
tmp = 0.5d0 / (((-0.5d0) * (b / c)) + (0.5d0 * (a / 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 <= -4e-310) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(0.5 / Float64(Float64(-0.5 * Float64(b / c)) + Float64(0.5 * Float64(a / 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 <= -4e-310) tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 * (a / b))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[(0.5 / N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{0.5}{-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 36.7%
Applied egg-rr36.7%
*-commutative36.7%
associate-/r*36.7%
metadata-eval36.7%
Simplified36.7%
frac-2neg36.7%
associate-*r/36.7%
metadata-eval36.7%
Applied egg-rr36.7%
*-commutative36.7%
associate-/l*36.7%
Simplified36.7%
Taylor expanded in b around -inf 63.7%
if -3.999999999999988e-310 < b Initial program 75.0%
Taylor expanded in b around inf 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
Simplified70.1%
Final simplification67.2%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 36.7%
Taylor expanded in b around -inf 63.5%
associate-*r/63.5%
neg-mul-163.5%
Simplified63.5%
if -3.999999999999988e-310 < b Initial program 75.0%
Taylor expanded in b around inf 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
Simplified70.1%
Final simplification67.1%
(FPCore (a b c) :precision binary64 (if (<= b -2.45e+69) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.45e+69) {
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.45d+69)) 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.45e+69) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.45e+69: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.45e+69) 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 <= -2.45e+69) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.45e+69], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.45 \cdot 10^{+69}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.45e69Initial program 15.5%
Taylor expanded in b around -inf 82.0%
associate-/l*88.3%
Simplified88.3%
div-inv88.2%
associate-*l*88.2%
associate-/r/76.6%
*-commutative76.6%
metadata-eval76.6%
associate-/r*76.6%
metadata-eval76.6%
metadata-eval76.6%
Applied egg-rr76.6%
associate-*r*76.6%
associate-*r/82.0%
*-commutative82.0%
*-commutative82.0%
*-commutative82.0%
associate-*r/76.6%
associate-*r*76.6%
associate-*r/82.0%
*-commutative82.0%
associate-*r/88.4%
associate-*r/88.4%
metadata-eval88.4%
Simplified88.4%
*-commutative88.4%
associate-*r/82.0%
associate-*r/86.7%
Applied egg-rr86.7%
*-commutative86.7%
associate-*r/86.8%
*-commutative86.8%
mul-1-neg86.8%
distribute-rgt-neg-in86.8%
Simplified86.8%
expm1-log1p-u68.9%
expm1-udef52.8%
associate-/l*43.0%
add-sqr-sqrt26.3%
sqrt-unprod41.8%
sqr-neg41.8%
sqrt-unprod17.2%
add-sqr-sqrt32.7%
Applied egg-rr32.7%
expm1-def32.5%
expm1-log1p32.9%
associate-/l*32.8%
*-commutative32.8%
associate-/l*32.9%
*-inverses32.9%
/-rgt-identity32.9%
Simplified32.9%
if -2.45e69 < b Initial program 70.9%
Taylor expanded in b around inf 50.6%
associate-*r/50.6%
mul-1-neg50.6%
Simplified50.6%
Final simplification46.3%
(FPCore (a b c) :precision binary64 (if (<= b -6.4e-300) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.4e-300) {
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 <= (-6.4d-300)) 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 <= -6.4e-300) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.4e-300: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.4e-300) 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 <= -6.4e-300) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.4e-300], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.4 \cdot 10^{-300}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.40000000000000043e-300Initial program 36.1%
Taylor expanded in b around -inf 64.0%
associate-*r/64.0%
neg-mul-164.0%
Simplified64.0%
if -6.40000000000000043e-300 < b Initial program 75.2%
Taylor expanded in b around inf 68.8%
associate-*r/68.8%
mul-1-neg68.8%
Simplified68.8%
Final simplification66.6%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 57.5%
Taylor expanded in b around -inf 24.3%
associate-/l*26.7%
Simplified26.7%
div-inv26.7%
associate-*l*26.7%
associate-/r/23.8%
*-commutative23.8%
metadata-eval23.8%
associate-/r*23.8%
metadata-eval23.8%
metadata-eval23.8%
Applied egg-rr23.8%
associate-*r*23.8%
associate-*r/24.2%
*-commutative24.2%
*-commutative24.2%
*-commutative24.2%
associate-*r/23.8%
associate-*r*23.8%
associate-*r/24.2%
*-commutative24.2%
associate-*r/26.7%
associate-*r/26.7%
metadata-eval26.7%
Simplified26.7%
*-commutative26.7%
associate-*r/24.2%
associate-*r/25.8%
Applied egg-rr25.8%
*-commutative25.8%
associate-*r/25.8%
*-commutative25.8%
mul-1-neg25.8%
distribute-rgt-neg-in25.8%
Simplified25.8%
expm1-log1p-u21.0%
expm1-udef15.7%
associate-/l*13.8%
add-sqr-sqrt9.0%
sqrt-unprod14.3%
sqr-neg14.3%
sqrt-unprod5.4%
add-sqr-sqrt9.9%
Applied egg-rr9.9%
expm1-def9.8%
expm1-log1p11.5%
associate-/l*10.3%
*-commutative10.3%
associate-/l*10.4%
*-inverses10.4%
/-rgt-identity10.4%
Simplified10.4%
Final simplification10.4%
(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 2023336
(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)))