
(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 8 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 -6.5e-111)
(/ (- c) b)
(if (<= b 4.2e+56)
(/ (- (- b) (sqrt (- (* b b) (* c (* 4.0 a))))) (* a 2.0))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e-111) {
tmp = -c / b;
} else if (b <= 4.2e+56) {
tmp = (-b - sqrt(((b * b) - (c * (4.0 * 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 <= (-6.5d-111)) then
tmp = -c / b
else if (b <= 4.2d+56) then
tmp = (-b - sqrt(((b * b) - (c * (4.0d0 * 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 <= -6.5e-111) {
tmp = -c / b;
} else if (b <= 4.2e+56) {
tmp = (-b - Math.sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.5e-111: tmp = -c / b elif b <= 4.2e+56: tmp = (-b - math.sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.5e-111) tmp = Float64(Float64(-c) / b); elseif (b <= 4.2e+56) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * 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 <= -6.5e-111) tmp = -c / b; elseif (b <= 4.2e+56) tmp = (-b - sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.5e-111], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.2e+56], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * 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 -6.5 \cdot 10^{-111}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+56}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -6.49999999999999974e-111Initial program 16.5%
*-commutative16.5%
sqr-neg16.5%
*-commutative16.5%
sqr-neg16.5%
associate-*r*16.5%
*-commutative16.5%
Simplified16.5%
Taylor expanded in b around -inf 79.8%
associate-*r/79.8%
neg-mul-179.8%
Simplified79.8%
if -6.49999999999999974e-111 < b < 4.20000000000000034e56Initial program 84.3%
*-commutative84.3%
sqr-neg84.3%
*-commutative84.3%
sqr-neg84.3%
associate-*r*84.3%
*-commutative84.3%
Simplified84.3%
if 4.20000000000000034e56 < b Initial program 67.8%
*-commutative67.8%
sqr-neg67.8%
*-commutative67.8%
sqr-neg67.8%
associate-*r*67.8%
*-commutative67.8%
Simplified67.8%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -3.8e-111)
(/ (- c) b)
(if (<= b 4.2e+56)
(/ (- (- 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 <= -3.8e-111) {
tmp = -c / b;
} else if (b <= 4.2e+56) {
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 <= (-3.8d-111)) then
tmp = -c / b
else if (b <= 4.2d+56) 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 <= -3.8e-111) {
tmp = -c / b;
} else if (b <= 4.2e+56) {
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 <= -3.8e-111: tmp = -c / b elif b <= 4.2e+56: 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 <= -3.8e-111) tmp = Float64(Float64(-c) / b); elseif (b <= 4.2e+56) 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 <= -3.8e-111) tmp = -c / b; elseif (b <= 4.2e+56) 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, -3.8e-111], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.2e+56], 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 -3.8 \cdot 10^{-111}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+56}:\\
\;\;\;\;\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 < -3.80000000000000022e-111Initial program 16.5%
*-commutative16.5%
sqr-neg16.5%
*-commutative16.5%
sqr-neg16.5%
associate-*r*16.5%
*-commutative16.5%
Simplified16.5%
Taylor expanded in b around -inf 79.8%
associate-*r/79.8%
neg-mul-179.8%
Simplified79.8%
if -3.80000000000000022e-111 < b < 4.20000000000000034e56Initial program 84.3%
if 4.20000000000000034e56 < b Initial program 67.8%
*-commutative67.8%
sqr-neg67.8%
*-commutative67.8%
sqr-neg67.8%
associate-*r*67.8%
*-commutative67.8%
Simplified67.8%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e-110)
(/ (- c) b)
(if (<= b 5.8e-95)
(* (/ 0.5 a) (- b (sqrt (* c (* a -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e-110) {
tmp = -c / b;
} else if (b <= 5.8e-95) {
tmp = (0.5 / a) * (b - sqrt((c * (a * -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 <= (-1.5d-110)) then
tmp = -c / b
else if (b <= 5.8d-95) then
tmp = (0.5d0 / a) * (b - sqrt((c * (a * (-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 <= -1.5e-110) {
tmp = -c / b;
} else if (b <= 5.8e-95) {
tmp = (0.5 / a) * (b - Math.sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.5e-110: tmp = -c / b elif b <= 5.8e-95: tmp = (0.5 / a) * (b - math.sqrt((c * (a * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.5e-110) tmp = Float64(Float64(-c) / b); elseif (b <= 5.8e-95) tmp = Float64(Float64(0.5 / a) * Float64(b - sqrt(Float64(c * Float64(a * -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 <= -1.5e-110) tmp = -c / b; elseif (b <= 5.8e-95) tmp = (0.5 / a) * (b - sqrt((c * (a * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.5e-110], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.8e-95], N[(N[(0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(c * N[(a * -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 -1.5 \cdot 10^{-110}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-95}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.49999999999999993e-110Initial program 16.5%
*-commutative16.5%
sqr-neg16.5%
*-commutative16.5%
sqr-neg16.5%
associate-*r*16.5%
*-commutative16.5%
Simplified16.5%
Taylor expanded in b around -inf 79.8%
associate-*r/79.8%
neg-mul-179.8%
Simplified79.8%
if -1.49999999999999993e-110 < b < 5.80000000000000004e-95Initial program 77.4%
*-commutative77.4%
sqr-neg77.4%
*-commutative77.4%
sqr-neg77.4%
associate-*r*77.4%
*-commutative77.4%
Simplified77.4%
add-sqr-sqrt77.1%
pow277.1%
pow1/277.1%
sqrt-pow177.1%
fma-neg77.1%
*-commutative77.1%
distribute-rgt-neg-in77.1%
*-commutative77.1%
distribute-rgt-neg-in77.1%
metadata-eval77.1%
metadata-eval77.1%
Applied egg-rr77.1%
Taylor expanded in b around 0 75.8%
div-sub75.8%
add-sqr-sqrt35.3%
sqrt-unprod74.8%
sqr-neg74.8%
sqrt-unprod39.4%
add-sqr-sqrt74.8%
pow-pow75.0%
*-commutative75.0%
associate-*r*75.0%
metadata-eval75.0%
pow1/275.0%
Applied egg-rr75.0%
div-sub75.0%
*-lft-identity75.0%
associate-*l/75.0%
*-commutative75.0%
associate-/r*75.0%
metadata-eval75.0%
Simplified75.0%
if 5.80000000000000004e-95 < b Initial program 76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
sqr-neg76.8%
associate-*r*76.8%
*-commutative76.8%
Simplified76.8%
Taylor expanded in b around inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
Final simplification83.1%
(FPCore (a b c)
:precision binary64
(if (<= b -8e-111)
(/ (- c) b)
(if (<= b 1.6e-96)
(/ (* -0.5 (+ b (sqrt (* c (* a -4.0))))) a)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-111) {
tmp = -c / b;
} else if (b <= 1.6e-96) {
tmp = (-0.5 * (b + sqrt((c * (a * -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 <= (-8d-111)) then
tmp = -c / b
else if (b <= 1.6d-96) then
tmp = ((-0.5d0) * (b + sqrt((c * (a * (-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 <= -8e-111) {
tmp = -c / b;
} else if (b <= 1.6e-96) {
tmp = (-0.5 * (b + Math.sqrt((c * (a * -4.0))))) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-111: tmp = -c / b elif b <= 1.6e-96: tmp = (-0.5 * (b + math.sqrt((c * (a * -4.0))))) / a else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e-111) tmp = Float64(Float64(-c) / b); elseif (b <= 1.6e-96) tmp = Float64(Float64(-0.5 * Float64(b + sqrt(Float64(c * Float64(a * -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 <= -8e-111) tmp = -c / b; elseif (b <= 1.6e-96) tmp = (-0.5 * (b + sqrt((c * (a * -4.0))))) / a; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-111], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.6e-96], N[(N[(-0.5 * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-111}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-96}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.00000000000000071e-111Initial program 16.5%
*-commutative16.5%
sqr-neg16.5%
*-commutative16.5%
sqr-neg16.5%
associate-*r*16.5%
*-commutative16.5%
Simplified16.5%
Taylor expanded in b around -inf 79.8%
associate-*r/79.8%
neg-mul-179.8%
Simplified79.8%
if -8.00000000000000071e-111 < b < 1.60000000000000006e-96Initial program 77.4%
*-commutative77.4%
sqr-neg77.4%
*-commutative77.4%
sqr-neg77.4%
associate-*r*77.4%
*-commutative77.4%
Simplified77.4%
add-sqr-sqrt77.1%
pow277.1%
pow1/277.1%
sqrt-pow177.1%
fma-neg77.1%
*-commutative77.1%
distribute-rgt-neg-in77.1%
*-commutative77.1%
distribute-rgt-neg-in77.1%
metadata-eval77.1%
metadata-eval77.1%
Applied egg-rr77.1%
Taylor expanded in b around 0 75.8%
Taylor expanded in c around 0 36.6%
associate-*r/36.6%
Simplified76.0%
if 1.60000000000000006e-96 < b Initial program 76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
sqr-neg76.8%
associate-*r*76.8%
*-commutative76.8%
Simplified76.8%
Taylor expanded in b around inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
Final simplification83.4%
(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(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 <= -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 30.2%
*-commutative30.2%
sqr-neg30.2%
*-commutative30.2%
sqr-neg30.2%
associate-*r*30.2%
*-commutative30.2%
Simplified30.2%
Taylor expanded in b around -inf 64.6%
associate-*r/64.6%
neg-mul-164.6%
Simplified64.6%
if -1.999999999999994e-310 < b Initial program 78.3%
*-commutative78.3%
sqr-neg78.3%
*-commutative78.3%
sqr-neg78.3%
associate-*r*78.3%
*-commutative78.3%
Simplified78.3%
Taylor expanded in b around inf 73.4%
mul-1-neg73.4%
unsub-neg73.4%
Simplified73.4%
Final simplification69.3%
(FPCore (a b c) :precision binary64 (if (<= b -6e+43) (/ c b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e+43) {
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 <= (-6d+43)) 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 <= -6e+43) {
tmp = c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e+43: tmp = c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e+43) 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 <= -6e+43) tmp = c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e+43], N[(c / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{+43}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -6.00000000000000033e43Initial program 12.8%
*-commutative12.8%
sqr-neg12.8%
*-commutative12.8%
sqr-neg12.8%
associate-*r*12.8%
*-commutative12.8%
Simplified12.8%
Taylor expanded in b around inf 2.2%
Taylor expanded in c around inf 29.6%
if -6.00000000000000033e43 < b Initial program 68.6%
*-commutative68.6%
sqr-neg68.6%
*-commutative68.6%
sqr-neg68.6%
associate-*r*68.6%
*-commutative68.6%
Simplified68.6%
Taylor expanded in b around inf 51.7%
associate-*r/51.7%
mul-1-neg51.7%
Simplified51.7%
Final simplification46.7%
(FPCore (a b c) :precision binary64 (if (<= b -2.6e-287) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-287) {
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-287)) 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-287) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.6e-287: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.6e-287) 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-287) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.6e-287], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{-287}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -2.6e-287Initial program 27.8%
*-commutative27.8%
sqr-neg27.8%
*-commutative27.8%
sqr-neg27.8%
associate-*r*27.8%
*-commutative27.8%
Simplified27.8%
Taylor expanded in b around -inf 66.7%
associate-*r/66.7%
neg-mul-166.7%
Simplified66.7%
if -2.6e-287 < b Initial program 78.9%
*-commutative78.9%
sqr-neg78.9%
*-commutative78.9%
sqr-neg78.9%
associate-*r*78.9%
*-commutative78.9%
Simplified78.9%
Taylor expanded in b around inf 71.3%
associate-*r/71.3%
mul-1-neg71.3%
Simplified71.3%
Final simplification69.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 / 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 56.0%
*-commutative56.0%
sqr-neg56.0%
*-commutative56.0%
sqr-neg56.0%
associate-*r*56.0%
*-commutative56.0%
Simplified56.0%
Taylor expanded in b around inf 39.4%
Taylor expanded in c around inf 9.0%
Final simplification9.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2023263
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))