
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -3.6e+124)
(- (/ c b) (/ b a))
(if (<= b 1.15e-46)
(/ (* (- b (sqrt (- (* b b) (* a (* c 4.0))))) -0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e+124) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-46) {
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
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.6d+124)) then
tmp = (c / b) - (b / a)
else if (b <= 1.15d-46) then
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0d0))))) * (-0.5d0)) / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e+124) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-46) {
tmp = ((b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e+124: tmp = (c / b) - (b / a) elif b <= 1.15e-46: tmp = ((b - math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e+124) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.15e-46) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * -0.5) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.6e+124) tmp = (c / b) - (b / a); elseif (b <= 1.15e-46) tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e+124], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-46], N[(N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.6 \cdot 10^{+124}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-46}:\\
\;\;\;\;\frac{\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot -0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.59999999999999986e124Initial program 37.2%
neg-sub037.2%
associate-+l-37.2%
sub0-neg37.2%
neg-mul-137.2%
associate-*l/37.2%
*-commutative37.2%
associate-/r*37.2%
/-rgt-identity37.2%
metadata-eval37.2%
Simplified37.3%
Taylor expanded in b around -inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
if -3.59999999999999986e124 < b < 1.15e-46Initial program 79.2%
neg-sub079.2%
associate-+l-79.2%
sub0-neg79.2%
neg-mul-179.2%
associate-*l/79.0%
*-commutative79.0%
associate-/r*79.0%
/-rgt-identity79.0%
metadata-eval79.0%
Simplified79.0%
fma-udef79.0%
*-commutative79.0%
associate-*r*79.0%
metadata-eval79.0%
distribute-rgt-neg-in79.0%
*-commutative79.0%
distribute-lft-neg-in79.0%
+-commutative79.0%
sub-neg79.0%
*-commutative79.0%
associate-*l*79.0%
Applied egg-rr79.0%
*-commutative79.0%
Simplified79.0%
associate-*r/79.2%
Applied egg-rr79.2%
if 1.15e-46 < b Initial program 14.8%
neg-sub014.8%
associate-+l-14.8%
sub0-neg14.8%
neg-mul-114.8%
associate-*l/14.8%
*-commutative14.8%
associate-/r*14.8%
/-rgt-identity14.8%
metadata-eval14.8%
Simplified14.8%
Taylor expanded in b around inf 86.2%
mul-1-neg86.2%
distribute-neg-frac86.2%
Simplified86.2%
Final simplification84.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e+74)
(- (/ c b) (/ b a))
(if (<= b 1.3e-46)
(* (- b (sqrt (- (* b b) (* a (* c 4.0))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e+74) {
tmp = (c / b) - (b / a);
} else if (b <= 1.3e-46) {
tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
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.25d+74)) then
tmp = (c / b) - (b / a)
else if (b <= 1.3d-46) then
tmp = (b - sqrt(((b * b) - (a * (c * 4.0d0))))) * ((-0.5d0) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e+74) {
tmp = (c / b) - (b / a);
} else if (b <= 1.3e-46) {
tmp = (b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.25e+74: tmp = (c / b) - (b / a) elif b <= 1.3e-46: tmp = (b - math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.25e+74) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.3e-46) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.25e+74) tmp = (c / b) - (b / a); elseif (b <= 1.3e-46) tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.25e+74], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.3e-46], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.25 \cdot 10^{+74}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.3 \cdot 10^{-46}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.24999999999999991e74Initial program 48.5%
neg-sub048.5%
associate-+l-48.5%
sub0-neg48.5%
neg-mul-148.5%
associate-*l/48.5%
*-commutative48.5%
associate-/r*48.5%
/-rgt-identity48.5%
metadata-eval48.5%
Simplified48.6%
Taylor expanded in b around -inf 96.9%
mul-1-neg96.9%
unsub-neg96.9%
Simplified96.9%
if -1.24999999999999991e74 < b < 1.3000000000000001e-46Initial program 77.2%
neg-sub077.2%
associate-+l-77.2%
sub0-neg77.2%
neg-mul-177.2%
associate-*l/77.1%
*-commutative77.1%
associate-/r*77.1%
/-rgt-identity77.1%
metadata-eval77.1%
Simplified77.1%
fma-udef77.1%
*-commutative77.1%
associate-*r*77.1%
metadata-eval77.1%
distribute-rgt-neg-in77.1%
*-commutative77.1%
distribute-lft-neg-in77.1%
+-commutative77.1%
sub-neg77.1%
*-commutative77.1%
associate-*l*77.1%
Applied egg-rr77.1%
*-commutative77.1%
Simplified77.1%
if 1.3000000000000001e-46 < b Initial program 14.8%
neg-sub014.8%
associate-+l-14.8%
sub0-neg14.8%
neg-mul-114.8%
associate-*l/14.8%
*-commutative14.8%
associate-/r*14.8%
/-rgt-identity14.8%
metadata-eval14.8%
Simplified14.8%
Taylor expanded in b around inf 86.2%
mul-1-neg86.2%
distribute-neg-frac86.2%
Simplified86.2%
Final simplification84.5%
(FPCore (a b c)
:precision binary64
(if (<= b -8.6e-116)
(- (/ c b) (/ b a))
(if (<= b 1.5e-46)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.6e-116) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-46) {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
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 <= (-8.6d-116)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d-46) then
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.0d0)))))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.6e-116) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-46) {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.6e-116: tmp = (c / b) - (b / a) elif b <= 1.5e-46: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.6e-116) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e-46) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.6e-116) tmp = (c / b) - (b / a); elseif (b <= 1.5e-46) tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.6e-116], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-46], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.6 \cdot 10^{-116}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-46}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.5999999999999994e-116Initial program 67.6%
neg-sub067.6%
associate-+l-67.6%
sub0-neg67.6%
neg-mul-167.6%
associate-*l/67.4%
*-commutative67.4%
associate-/r*67.4%
/-rgt-identity67.4%
metadata-eval67.4%
Simplified67.5%
Taylor expanded in b around -inf 86.3%
mul-1-neg86.3%
unsub-neg86.3%
Simplified86.3%
if -8.5999999999999994e-116 < b < 1.49999999999999994e-46Initial program 67.5%
neg-sub067.5%
associate-+l-67.5%
sub0-neg67.5%
neg-mul-167.5%
associate-*l/67.5%
*-commutative67.5%
associate-/r*67.5%
/-rgt-identity67.5%
metadata-eval67.5%
Simplified67.5%
Taylor expanded in a around inf 65.5%
*-commutative65.5%
*-commutative65.5%
associate-*r*65.5%
Simplified65.5%
if 1.49999999999999994e-46 < b Initial program 14.8%
neg-sub014.8%
associate-+l-14.8%
sub0-neg14.8%
neg-mul-114.8%
associate-*l/14.8%
*-commutative14.8%
associate-/r*14.8%
/-rgt-identity14.8%
metadata-eval14.8%
Simplified14.8%
Taylor expanded in b around inf 86.2%
mul-1-neg86.2%
distribute-neg-frac86.2%
Simplified86.2%
Final simplification80.2%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-123)
(- (/ c b) (/ b a))
(if (<= b 1.5e-46)
(/ (* c -2.0) (+ b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-123) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-46) {
tmp = (c * -2.0) / (b + sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
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 <= (-9d-123)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d-46) then
tmp = (c * (-2.0d0)) / (b + sqrt((a * (c * (-4.0d0)))))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e-123) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-46) {
tmp = (c * -2.0) / (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-123: tmp = (c / b) - (b / a) elif b <= 1.5e-46: tmp = (c * -2.0) / (b + math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-123) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e-46) tmp = Float64(Float64(c * -2.0) / Float64(b + sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-123) tmp = (c / b) - (b / a); elseif (b <= 1.5e-46) tmp = (c * -2.0) / (b + sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-123], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-46], N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-123}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-46}:\\
\;\;\;\;\frac{c \cdot -2}{b + \sqrt{a \cdot \left(c \cdot -4\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.99999999999999986e-123Initial program 67.6%
neg-sub067.6%
associate-+l-67.6%
sub0-neg67.6%
neg-mul-167.6%
associate-*l/67.4%
*-commutative67.4%
associate-/r*67.4%
/-rgt-identity67.4%
metadata-eval67.4%
Simplified67.5%
Taylor expanded in b around -inf 86.3%
mul-1-neg86.3%
unsub-neg86.3%
Simplified86.3%
if -8.99999999999999986e-123 < b < 1.49999999999999994e-46Initial program 67.5%
neg-sub067.5%
associate-+l-67.5%
sub0-neg67.5%
neg-mul-167.5%
associate-*l/67.5%
*-commutative67.5%
associate-/r*67.5%
/-rgt-identity67.5%
metadata-eval67.5%
Simplified67.5%
Taylor expanded in a around inf 65.5%
*-commutative65.5%
*-commutative65.5%
associate-*r*65.5%
Simplified65.5%
flip--64.7%
add-sqr-sqrt64.6%
Applied egg-rr64.6%
associate-*l/64.6%
Applied egg-rr64.6%
Taylor expanded in b around 0 66.9%
*-commutative66.9%
Simplified66.9%
if 1.49999999999999994e-46 < b Initial program 14.8%
neg-sub014.8%
associate-+l-14.8%
sub0-neg14.8%
neg-mul-114.8%
associate-*l/14.8%
*-commutative14.8%
associate-/r*14.8%
/-rgt-identity14.8%
metadata-eval14.8%
Simplified14.8%
Taylor expanded in b around inf 86.2%
mul-1-neg86.2%
distribute-neg-frac86.2%
Simplified86.2%
Final simplification80.6%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
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 <= (-1d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 69.4%
neg-sub069.4%
associate-+l-69.4%
sub0-neg69.4%
neg-mul-169.4%
associate-*l/69.3%
*-commutative69.3%
associate-/r*69.3%
/-rgt-identity69.3%
metadata-eval69.3%
Simplified69.3%
Taylor expanded in b around -inf 68.6%
mul-1-neg68.6%
unsub-neg68.6%
Simplified68.6%
if -9.999999999999969e-311 < b Initial program 32.2%
neg-sub032.2%
associate-+l-32.2%
sub0-neg32.2%
neg-mul-132.2%
associate-*l/32.2%
*-commutative32.2%
associate-/r*32.2%
/-rgt-identity32.2%
metadata-eval32.2%
Simplified32.2%
Taylor expanded in b around inf 62.5%
mul-1-neg62.5%
distribute-neg-frac62.5%
Simplified62.5%
Final simplification65.7%
(FPCore (a b c) :precision binary64 (if (<= b 2.25e-46) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.25e-46) {
tmp = -b / a;
} else {
tmp = c / b;
}
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-46) then
tmp = -b / a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.25e-46) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.25e-46: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.25e-46) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.25e-46) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.25e-46], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.25 \cdot 10^{-46}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.25e-46Initial program 67.6%
neg-sub067.6%
associate-+l-67.6%
sub0-neg67.6%
neg-mul-167.6%
associate-*l/67.5%
*-commutative67.5%
associate-/r*67.5%
/-rgt-identity67.5%
metadata-eval67.5%
Simplified67.5%
Taylor expanded in b around -inf 52.4%
associate-*r/52.4%
mul-1-neg52.4%
Simplified52.4%
if 2.25e-46 < b Initial program 14.8%
Taylor expanded in b around -inf 2.3%
Taylor expanded in c around inf 20.5%
Final simplification43.0%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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 <= (-1d-310)) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 69.4%
neg-sub069.4%
associate-+l-69.4%
sub0-neg69.4%
neg-mul-169.4%
associate-*l/69.3%
*-commutative69.3%
associate-/r*69.3%
/-rgt-identity69.3%
metadata-eval69.3%
Simplified69.3%
Taylor expanded in b around -inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
if -9.999999999999969e-311 < b Initial program 32.2%
neg-sub032.2%
associate-+l-32.2%
sub0-neg32.2%
neg-mul-132.2%
associate-*l/32.2%
*-commutative32.2%
associate-/r*32.2%
/-rgt-identity32.2%
metadata-eval32.2%
Simplified32.2%
Taylor expanded in b around inf 62.5%
mul-1-neg62.5%
distribute-neg-frac62.5%
Simplified62.5%
Final simplification65.5%
(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 52.1%
neg-sub052.1%
associate-+l-52.1%
sub0-neg52.1%
neg-mul-152.1%
associate-*l/52.0%
*-commutative52.0%
associate-/r*52.0%
/-rgt-identity52.0%
metadata-eval52.0%
Simplified52.0%
associate-*r/52.1%
clear-num52.0%
Applied egg-rr52.0%
Taylor expanded in a around 0 30.3%
mul-1-neg30.3%
unsub-neg30.3%
Simplified30.3%
Taylor expanded in a around inf 2.5%
Final simplification2.5%
(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 52.1%
Taylor expanded in b around -inf 35.7%
Taylor expanded in c around inf 8.1%
Final simplification8.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-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(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023171
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))