
(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 -7e-39)
(/ (* c (- -1.0 (/ (* c a) (* b b)))) b)
(if (<= b 1e+129)
(/ (+ b (sqrt (- (* b b) (* a (* c 4.0))))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-39) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 1e+129) {
tmp = (b + sqrt(((b * b) - (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 <= (-7d-39)) then
tmp = (c * ((-1.0d0) - ((c * a) / (b * b)))) / b
else if (b <= 1d+129) then
tmp = (b + sqrt(((b * b) - (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 <= -7e-39) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 1e+129) {
tmp = (b + Math.sqrt(((b * b) - (a * (c * 4.0))))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-39: tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b elif b <= 1e+129: tmp = (b + math.sqrt(((b * b) - (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 <= -7e-39) tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / Float64(b * b)))) / b); elseif (b <= 1e+129) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / Float64(a * Float64(-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 <= -7e-39) tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b; elseif (b <= 1e+129) tmp = (b + sqrt(((b * b) - (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, -7e-39], N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[b, 1e+129], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $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 -7 \cdot 10^{-39}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{b \cdot b}\right)}{b}\\
\mathbf{elif}\;b \leq 10^{+129}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.99999999999999999e-39Initial program 18.5%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.3%
distribute-neg-frac14.3%
neg-mul-114.3%
*-commutative14.3%
associate-/l*16.9%
distribute-rgt-out18.4%
associate-/r*18.4%
metadata-eval18.4%
sub-neg18.4%
+-commutative18.4%
Simplified18.4%
Taylor expanded in b around -inf 69.3%
mul-1-neg69.3%
distribute-neg-frac269.3%
associate-/l*70.5%
Simplified70.5%
Taylor expanded in c around 0 87.8%
pow287.8%
Applied egg-rr87.8%
if -6.99999999999999999e-39 < b < 1e129Initial program 85.5%
*-commutative85.5%
sqr-neg85.5%
*-commutative85.5%
sqr-neg85.5%
*-commutative85.5%
associate-*r*85.6%
*-commutative85.6%
Simplified85.6%
if 1e129 < b Initial program 55.3%
div-sub55.3%
sub-neg55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.3%
distribute-rgt-out55.3%
associate-/r*55.3%
metadata-eval55.3%
sub-neg55.3%
+-commutative55.3%
Simplified55.4%
Taylor expanded in c around 0 97.2%
+-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
Simplified97.2%
Final simplification88.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.45e-39)
(/ (* c (- -1.0 (/ (* c a) (* b b)))) b)
(if (<= b 1e+126)
(/ (- (- b) (sqrt (- (* b b) (* (* c a) 4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-39) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 1e+126) {
tmp = (-b - sqrt(((b * b) - ((c * a) * 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 <= (-1.45d-39)) then
tmp = (c * ((-1.0d0) - ((c * a) / (b * b)))) / b
else if (b <= 1d+126) then
tmp = (-b - sqrt(((b * b) - ((c * a) * 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 <= -1.45e-39) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 1e+126) {
tmp = (-b - Math.sqrt(((b * b) - ((c * a) * 4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-39: tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b elif b <= 1e+126: tmp = (-b - math.sqrt(((b * b) - ((c * a) * 4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-39) tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / Float64(b * b)))) / b); elseif (b <= 1e+126) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * a) * 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 <= -1.45e-39) tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b; elseif (b <= 1e+126) tmp = (-b - sqrt(((b * b) - ((c * a) * 4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-39], N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[b, 1e+126], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * a), $MachinePrecision] * 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 -1.45 \cdot 10^{-39}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{b \cdot b}\right)}{b}\\
\mathbf{elif}\;b \leq 10^{+126}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.44999999999999994e-39Initial program 18.5%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.3%
distribute-neg-frac14.3%
neg-mul-114.3%
*-commutative14.3%
associate-/l*16.9%
distribute-rgt-out18.4%
associate-/r*18.4%
metadata-eval18.4%
sub-neg18.4%
+-commutative18.4%
Simplified18.4%
Taylor expanded in b around -inf 69.3%
mul-1-neg69.3%
distribute-neg-frac269.3%
associate-/l*70.5%
Simplified70.5%
Taylor expanded in c around 0 87.8%
pow287.8%
Applied egg-rr87.8%
if -1.44999999999999994e-39 < b < 9.99999999999999925e125Initial program 85.5%
if 9.99999999999999925e125 < b Initial program 55.3%
div-sub55.3%
sub-neg55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.3%
distribute-rgt-out55.3%
associate-/r*55.3%
metadata-eval55.3%
sub-neg55.3%
+-commutative55.3%
Simplified55.4%
Taylor expanded in c around 0 97.2%
+-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
Simplified97.2%
Final simplification88.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.92e-41)
(/ (* c (- -1.0 (/ (* c a) (* b b)))) b)
(if (<= b 8.4e-65)
(/ (- (- b) (sqrt (* c (* a -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.92e-41) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 8.4e-65) {
tmp = (-b - sqrt((c * (a * -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 <= (-1.92d-41)) then
tmp = (c * ((-1.0d0) - ((c * a) / (b * b)))) / b
else if (b <= 8.4d-65) then
tmp = (-b - sqrt((c * (a * (-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 <= -1.92e-41) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 8.4e-65) {
tmp = (-b - Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.92e-41: tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b elif b <= 8.4e-65: tmp = (-b - math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.92e-41) tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / Float64(b * b)))) / b); elseif (b <= 8.4e-65) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -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 <= -1.92e-41) tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b; elseif (b <= 8.4e-65) tmp = (-b - sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.92e-41], N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[b, 8.4e-65], N[(N[((-b) - N[Sqrt[N[(c * N[(a * -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 -1.92 \cdot 10^{-41}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{b \cdot b}\right)}{b}\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{-65}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.92000000000000002e-41Initial program 18.5%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.3%
distribute-neg-frac14.3%
neg-mul-114.3%
*-commutative14.3%
associate-/l*16.9%
distribute-rgt-out18.4%
associate-/r*18.4%
metadata-eval18.4%
sub-neg18.4%
+-commutative18.4%
Simplified18.4%
Taylor expanded in b around -inf 69.3%
mul-1-neg69.3%
distribute-neg-frac269.3%
associate-/l*70.5%
Simplified70.5%
Taylor expanded in c around 0 87.8%
pow287.8%
Applied egg-rr87.8%
if -1.92000000000000002e-41 < b < 8.40000000000000011e-65Initial program 81.7%
*-commutative81.7%
sqr-neg81.7%
*-commutative81.7%
sqr-neg81.7%
*-commutative81.7%
associate-*r*81.7%
*-commutative81.7%
Simplified81.7%
Taylor expanded in b around 0 77.3%
metadata-eval77.3%
distribute-lft-neg-in77.3%
associate-*r*77.4%
*-commutative77.4%
distribute-rgt-neg-in77.4%
distribute-lft-neg-in77.4%
metadata-eval77.4%
*-commutative77.4%
Simplified77.4%
if 8.40000000000000011e-65 < b Initial program 73.8%
div-sub73.8%
sub-neg73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.7%
distribute-rgt-out73.7%
associate-/r*73.7%
metadata-eval73.7%
sub-neg73.7%
+-commutative73.7%
Simplified73.8%
Taylor expanded in c around 0 85.8%
+-commutative85.8%
mul-1-neg85.8%
unsub-neg85.8%
Simplified85.8%
Final simplification83.6%
(FPCore (a b c)
:precision binary64
(if (<= b -6.1e-41)
(/ (* c (- -1.0 (/ (* c a) (* b b)))) b)
(if (<= b 6e-58)
(/ (sqrt (* a (* c -4.0))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.1e-41) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 6e-58) {
tmp = 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 <= (-6.1d-41)) then
tmp = (c * ((-1.0d0) - ((c * a) / (b * b)))) / b
else if (b <= 6d-58) then
tmp = 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 <= -6.1e-41) {
tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b;
} else if (b <= 6e-58) {
tmp = 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 <= -6.1e-41: tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b elif b <= 6e-58: tmp = 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 <= -6.1e-41) tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / Float64(b * b)))) / b); elseif (b <= 6e-58) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * Float64(-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 <= -6.1e-41) tmp = (c * (-1.0 - ((c * a) / (b * b)))) / b; elseif (b <= 6e-58) tmp = 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, -6.1e-41], N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[b, 6e-58], N[(N[Sqrt[N[(a * N[(c * -4.0), $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.1 \cdot 10^{-41}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{b \cdot b}\right)}{b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-58}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.0999999999999999e-41Initial program 18.5%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.3%
distribute-neg-frac14.3%
neg-mul-114.3%
*-commutative14.3%
associate-/l*16.9%
distribute-rgt-out18.4%
associate-/r*18.4%
metadata-eval18.4%
sub-neg18.4%
+-commutative18.4%
Simplified18.4%
Taylor expanded in b around -inf 69.3%
mul-1-neg69.3%
distribute-neg-frac269.3%
associate-/l*70.5%
Simplified70.5%
Taylor expanded in c around 0 87.8%
pow287.8%
Applied egg-rr87.8%
if -6.0999999999999999e-41 < b < 6.00000000000000015e-58Initial program 81.7%
*-commutative81.7%
sqr-neg81.7%
*-commutative81.7%
sqr-neg81.7%
*-commutative81.7%
associate-*r*81.7%
*-commutative81.7%
Simplified81.7%
add-cube-cbrt80.9%
pow380.9%
*-commutative80.9%
associate-*l*80.9%
Applied egg-rr80.9%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt76.1%
mul-1-neg76.1%
rem-cube-cbrt76.5%
Simplified76.5%
if 6.00000000000000015e-58 < b Initial program 73.8%
div-sub73.8%
sub-neg73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.7%
distribute-rgt-out73.7%
associate-/r*73.7%
metadata-eval73.7%
sub-neg73.7%
+-commutative73.7%
Simplified73.8%
Taylor expanded in c around 0 85.8%
+-commutative85.8%
mul-1-neg85.8%
unsub-neg85.8%
Simplified85.8%
Final simplification83.3%
(FPCore (a b c)
:precision binary64
(if (<= b -5e-167)
(/ c (- b))
(if (<= b 9.2e-151)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-167) {
tmp = c / -b;
} else if (b <= 9.2e-151) {
tmp = sqrt((c * (-4.0 / a))) * -0.5;
} 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-167)) then
tmp = c / -b
else if (b <= 9.2d-151) then
tmp = sqrt((c * ((-4.0d0) / a))) * -0.5d0
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-167) {
tmp = c / -b;
} else if (b <= 9.2e-151) {
tmp = Math.sqrt((c * (-4.0 / a))) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-167: tmp = c / -b elif b <= 9.2e-151: tmp = math.sqrt((c * (-4.0 / a))) * -0.5 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-167) tmp = Float64(c / Float64(-b)); elseif (b <= 9.2e-151) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-0.5)); 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-167) tmp = c / -b; elseif (b <= 9.2e-151) tmp = sqrt((c * (-4.0 / a))) * -0.5; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-167], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 9.2e-151], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-0.5)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-167}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-151}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.0000000000000002e-167Initial program 28.5%
div-sub27.2%
sub-neg27.2%
neg-mul-127.2%
*-commutative27.2%
associate-/l*25.2%
distribute-neg-frac25.2%
neg-mul-125.2%
*-commutative25.2%
associate-/l*27.2%
distribute-rgt-out28.4%
associate-/r*28.4%
metadata-eval28.4%
sub-neg28.4%
+-commutative28.4%
Simplified28.4%
Taylor expanded in b around -inf 76.5%
mul-1-neg76.5%
distribute-neg-frac276.5%
Simplified76.5%
if -5.0000000000000002e-167 < b < 9.19999999999999984e-151Initial program 87.1%
*-commutative87.1%
sqr-neg87.1%
*-commutative87.1%
sqr-neg87.1%
*-commutative87.1%
associate-*r*87.2%
*-commutative87.2%
Simplified87.2%
add-cube-cbrt86.3%
pow386.3%
*-commutative86.3%
associate-*l*86.3%
Applied egg-rr86.3%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt43.6%
neg-mul-143.6%
associate-/l*43.7%
rem-cube-cbrt43.9%
Simplified43.9%
if 9.19999999999999984e-151 < b Initial program 75.7%
div-sub75.7%
sub-neg75.7%
neg-mul-175.7%
*-commutative75.7%
associate-/l*75.7%
distribute-neg-frac75.7%
neg-mul-175.7%
*-commutative75.7%
associate-/l*75.6%
distribute-rgt-out75.6%
associate-/r*75.6%
metadata-eval75.6%
sub-neg75.6%
+-commutative75.6%
Simplified75.7%
Taylor expanded in c around 0 77.7%
+-commutative77.7%
mul-1-neg77.7%
unsub-neg77.7%
Simplified77.7%
Final simplification70.8%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(c / Float64(-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 <= -2e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 38.6%
div-sub37.5%
sub-neg37.5%
neg-mul-137.5%
*-commutative37.5%
associate-/l*35.9%
distribute-neg-frac35.9%
neg-mul-135.9%
*-commutative35.9%
associate-/l*37.5%
distribute-rgt-out38.5%
associate-/r*38.5%
metadata-eval38.5%
sub-neg38.5%
+-commutative38.5%
Simplified38.6%
Taylor expanded in b around -inf 64.2%
mul-1-neg64.2%
distribute-neg-frac264.2%
Simplified64.2%
if -1.999999999999994e-310 < b Initial program 78.6%
div-sub78.6%
sub-neg78.6%
neg-mul-178.6%
*-commutative78.6%
associate-/l*78.5%
distribute-neg-frac78.5%
neg-mul-178.5%
*-commutative78.5%
associate-/l*78.4%
distribute-rgt-out78.4%
associate-/r*78.4%
metadata-eval78.4%
sub-neg78.4%
+-commutative78.4%
Simplified78.5%
Taylor expanded in c around 0 64.4%
+-commutative64.4%
mul-1-neg64.4%
unsub-neg64.4%
Simplified64.4%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 38.6%
div-sub37.5%
sub-neg37.5%
neg-mul-137.5%
*-commutative37.5%
associate-/l*35.9%
distribute-neg-frac35.9%
neg-mul-135.9%
*-commutative35.9%
associate-/l*37.5%
distribute-rgt-out38.5%
associate-/r*38.5%
metadata-eval38.5%
sub-neg38.5%
+-commutative38.5%
Simplified38.6%
Taylor expanded in b around -inf 64.2%
mul-1-neg64.2%
distribute-neg-frac264.2%
Simplified64.2%
if -1.999999999999994e-310 < b Initial program 78.6%
div-sub78.6%
sub-neg78.6%
neg-mul-178.6%
*-commutative78.6%
associate-/l*78.5%
distribute-neg-frac78.5%
neg-mul-178.5%
*-commutative78.5%
associate-/l*78.4%
distribute-rgt-out78.4%
associate-/r*78.4%
metadata-eval78.4%
sub-neg78.4%
+-commutative78.4%
Simplified78.5%
Taylor expanded in a around 0 64.2%
associate-*r/64.2%
mul-1-neg64.2%
Simplified64.2%
Final simplification64.2%
(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 / Float64(-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 58.7%
div-sub58.2%
sub-neg58.2%
neg-mul-158.2%
*-commutative58.2%
associate-/l*57.4%
distribute-neg-frac57.4%
neg-mul-157.4%
*-commutative57.4%
associate-/l*58.1%
distribute-rgt-out58.6%
associate-/r*58.6%
metadata-eval58.6%
sub-neg58.6%
+-commutative58.6%
Simplified58.7%
Taylor expanded in b around -inf 33.0%
mul-1-neg33.0%
distribute-neg-frac233.0%
Simplified33.0%
(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 58.7%
div-sub58.2%
sub-neg58.2%
neg-mul-158.2%
*-commutative58.2%
associate-/l*57.4%
distribute-neg-frac57.4%
neg-mul-157.4%
*-commutative57.4%
associate-/l*58.1%
distribute-rgt-out58.6%
associate-/r*58.6%
metadata-eval58.6%
sub-neg58.6%
+-commutative58.6%
Simplified58.7%
Taylor expanded in b around -inf 33.0%
mul-1-neg33.0%
distribute-neg-frac233.0%
Simplified33.0%
add-sqr-sqrt31.7%
sqrt-unprod25.6%
sqr-neg25.6%
sqrt-prod1.7%
add-sqr-sqrt9.4%
div-inv9.4%
Applied egg-rr9.4%
associate-*r/9.4%
*-rgt-identity9.4%
Simplified9.4%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / 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 / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 58.7%
*-commutative58.7%
sqr-neg58.7%
*-commutative58.7%
sqr-neg58.7%
*-commutative58.7%
associate-*r*58.7%
*-commutative58.7%
Simplified58.7%
add-cube-cbrt58.4%
pow358.4%
*-commutative58.4%
associate-*l*58.4%
Applied egg-rr58.4%
clear-num58.3%
inv-pow58.3%
add-sqr-sqrt17.7%
sqrt-unprod34.8%
sqr-neg34.8%
sqrt-prod25.2%
add-sqr-sqrt39.9%
pow239.9%
unpow340.0%
add-cube-cbrt40.2%
Applied egg-rr40.2%
unpow-140.2%
*-commutative40.2%
*-lft-identity40.2%
times-frac40.2%
metadata-eval40.2%
unpow240.2%
fmm-def40.2%
associate-*r*40.2%
*-commutative40.2%
associate-*r*40.2%
distribute-rgt-neg-in40.2%
metadata-eval40.2%
rem-cube-cbrt40.1%
associate-*r*40.2%
rem-cube-cbrt40.2%
Simplified40.2%
Taylor expanded in b around -inf 2.6%
(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 2024177
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ c (- sqtD (/ b 2))) (/ (+ (/ b 2) sqtD) (- a)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))