
(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 -5e+153)
(- (/ c b) (/ b a))
(if (<= b 2.8e-65)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(fma (- c) (/ 1.0 b) (/ (- c) (/ (/ (pow b 3.0) a) c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+153) {
tmp = (c / b) - (b / a);
} else if (b <= 2.8e-65) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = fma(-c, (1.0 / b), (-c / ((pow(b, 3.0) / a) / c)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e+153) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.8e-65) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = fma(Float64(-c), Float64(1.0 / b), Float64(Float64(-c) / Float64(Float64((b ^ 3.0) / a) / c))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e+153], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.8e-65], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) * N[(1.0 / b), $MachinePrecision] + N[((-c) / N[(N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-65}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-c, \frac{1}{b}, \frac{-c}{\frac{\frac{{b}^{3}}{a}}{c}}\right)\\
\end{array}
\end{array}
if b < -5.00000000000000018e153Initial program 26.4%
neg-sub026.4%
associate-+l-26.4%
sub0-neg26.4%
neg-mul-126.4%
*-commutative26.4%
associate-*r/26.4%
Simplified26.7%
Taylor expanded in b around -inf 97.7%
mul-1-neg97.7%
unsub-neg97.7%
Simplified97.7%
if -5.00000000000000018e153 < b < 2.8e-65Initial program 83.0%
if 2.8e-65 < b Initial program 13.8%
neg-sub013.8%
associate-+l-13.8%
sub0-neg13.8%
neg-mul-113.8%
*-commutative13.8%
associate-*r/13.8%
Simplified13.9%
Taylor expanded in b around inf 77.5%
+-commutative77.5%
mul-1-neg77.5%
unsub-neg77.5%
associate-*r/77.5%
neg-mul-177.5%
unpow277.5%
associate-*l*86.8%
Simplified86.8%
div-inv86.5%
fma-neg86.6%
associate-/l*91.0%
*-commutative91.0%
Applied egg-rr91.0%
distribute-neg-frac91.0%
associate-/r*93.1%
Simplified93.1%
Final simplification89.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.1e+84)
(- (/ c b) (/ b a))
(if (<= b 1.12e-92)
(* (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e+84) {
tmp = (c / b) - (b / a);
} else if (b <= 1.12e-92) {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (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.1d+84)) then
tmp = (c / b) - (b / a)
else if (b <= 1.12d-92) then
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) * (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.1e+84) {
tmp = (c / b) - (b / a);
} else if (b <= 1.12e-92) {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e+84: tmp = (c / b) - (b / a) elif b <= 1.12e-92: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e+84) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.12e-92) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) * 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.1e+84) tmp = (c / b) - (b / a); elseif (b <= 1.12e-92) tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e+84], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.12e-92], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{+84}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.12 \cdot 10^{-92}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.0999999999999999e84Initial program 45.5%
neg-sub045.5%
associate-+l-45.5%
sub0-neg45.5%
neg-mul-145.5%
*-commutative45.5%
associate-*r/45.4%
Simplified45.6%
Taylor expanded in b around -inf 98.3%
mul-1-neg98.3%
unsub-neg98.3%
Simplified98.3%
if -1.0999999999999999e84 < b < 1.11999999999999999e-92Initial program 81.9%
/-rgt-identity81.9%
metadata-eval81.9%
associate-/l*81.9%
associate-*r/81.7%
+-commutative81.7%
unsub-neg81.7%
fma-neg81.7%
*-commutative81.7%
distribute-rgt-neg-in81.7%
associate-*l*80.8%
metadata-eval80.8%
associate-/r*80.8%
metadata-eval80.8%
metadata-eval80.8%
Simplified80.8%
fma-udef80.8%
Applied egg-rr80.8%
if 1.11999999999999999e-92 < b Initial program 15.4%
neg-sub015.4%
associate-+l-15.4%
sub0-neg15.4%
neg-mul-115.4%
*-commutative15.4%
associate-*r/15.4%
Simplified15.4%
Taylor expanded in b around inf 91.3%
associate-*r/91.3%
neg-mul-191.3%
Simplified91.3%
Final simplification88.5%
(FPCore (a b c)
:precision binary64
(if (<= b -5e+153)
(- (/ c b) (/ b a))
(if (<= b 5.5e-72)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+153) {
tmp = (c / b) - (b / a);
} else if (b <= 5.5e-72) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.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 <= (-5d+153)) then
tmp = (c / b) - (b / a)
else if (b <= 5.5d-72) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - b) / (a * 2.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 <= -5e+153) {
tmp = (c / b) - (b / a);
} else if (b <= 5.5e-72) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e+153: tmp = (c / b) - (b / a) elif b <= 5.5e-72: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e+153) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.5e-72) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e+153) tmp = (c / b) - (b / a); elseif (b <= 5.5e-72) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e+153], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.5e-72], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{-72}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.00000000000000018e153Initial program 26.4%
neg-sub026.4%
associate-+l-26.4%
sub0-neg26.4%
neg-mul-126.4%
*-commutative26.4%
associate-*r/26.4%
Simplified26.7%
Taylor expanded in b around -inf 97.7%
mul-1-neg97.7%
unsub-neg97.7%
Simplified97.7%
if -5.00000000000000018e153 < b < 5.49999999999999994e-72Initial program 83.0%
if 5.49999999999999994e-72 < b Initial program 13.8%
neg-sub013.8%
associate-+l-13.8%
sub0-neg13.8%
neg-mul-113.8%
*-commutative13.8%
associate-*r/13.8%
Simplified13.9%
Taylor expanded in b around inf 93.0%
associate-*r/93.0%
neg-mul-193.0%
Simplified93.0%
Final simplification88.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e-54)
(/ (* 2.0 (- (/ c (/ b a)) b)) (* a 2.0))
(if (<= b 1.15e-92)
(* (- b (sqrt (* (* c a) -4.0))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e-54) {
tmp = (2.0 * ((c / (b / a)) - b)) / (a * 2.0);
} else if (b <= 1.15e-92) {
tmp = (b - sqrt(((c * a) * -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.5d-54)) then
tmp = (2.0d0 * ((c / (b / a)) - b)) / (a * 2.0d0)
else if (b <= 1.15d-92) then
tmp = (b - sqrt(((c * a) * (-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.5e-54) {
tmp = (2.0 * ((c / (b / a)) - b)) / (a * 2.0);
} else if (b <= 1.15e-92) {
tmp = (b - Math.sqrt(((c * a) * -4.0))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.5e-54: tmp = (2.0 * ((c / (b / a)) - b)) / (a * 2.0) elif b <= 1.15e-92: tmp = (b - math.sqrt(((c * a) * -4.0))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.5e-54) tmp = Float64(Float64(2.0 * Float64(Float64(c / Float64(b / a)) - b)) / Float64(a * 2.0)); elseif (b <= 1.15e-92) tmp = Float64(Float64(b - sqrt(Float64(Float64(c * a) * -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.5e-54) tmp = (2.0 * ((c / (b / a)) - b)) / (a * 2.0); elseif (b <= 1.15e-92) tmp = (b - sqrt(((c * a) * -4.0))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.5e-54], N[(N[(2.0 * N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-92], N[(N[(b - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{-54}:\\
\;\;\;\;\frac{2 \cdot \left(\frac{c}{\frac{b}{a}} - b\right)}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-92}:\\
\;\;\;\;\left(b - \sqrt{\left(c \cdot a\right) \cdot -4}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.50000000000000005e-54Initial program 64.2%
add-sqr-sqrt64.0%
pow264.0%
pow1/264.0%
sqrt-pow164.0%
cancel-sign-sub-inv64.0%
fma-def64.2%
metadata-eval64.2%
metadata-eval64.2%
Applied egg-rr64.2%
Taylor expanded in b around -inf 83.9%
mul-1-neg83.9%
distribute-lft-out83.9%
associate-*l/92.0%
*-commutative92.0%
unsub-neg92.0%
*-commutative92.0%
associate-/r/92.0%
Simplified92.0%
if -1.50000000000000005e-54 < b < 1.15000000000000008e-92Initial program 75.5%
neg-sub075.5%
associate-+l-75.5%
sub0-neg75.5%
neg-mul-175.5%
*-commutative75.5%
associate-*r/75.4%
Simplified74.1%
Taylor expanded in a around inf 73.8%
if 1.15000000000000008e-92 < b Initial program 15.4%
neg-sub015.4%
associate-+l-15.4%
sub0-neg15.4%
neg-mul-115.4%
*-commutative15.4%
associate-*r/15.4%
Simplified15.4%
Taylor expanded in b around inf 91.3%
associate-*r/91.3%
neg-mul-191.3%
Simplified91.3%
Final simplification86.6%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 68.1%
neg-sub068.1%
associate-+l-68.1%
sub0-neg68.1%
neg-mul-168.1%
*-commutative68.1%
associate-*r/67.9%
Simplified68.0%
Taylor expanded in b around -inf 65.5%
mul-1-neg65.5%
unsub-neg65.5%
Simplified65.5%
if -1.999999999999994e-310 < b Initial program 30.3%
neg-sub030.3%
associate-+l-30.3%
sub0-neg30.3%
neg-mul-130.3%
*-commutative30.3%
associate-*r/30.2%
Simplified29.5%
Taylor expanded in b around inf 73.1%
associate-*r/73.1%
neg-mul-173.1%
Simplified73.1%
Final simplification69.4%
(FPCore (a b c) :precision binary64 (if (<= b 0.095) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.095) {
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 <= 0.095d0) 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 <= 0.095) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 0.095: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 0.095) 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 <= 0.095) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 0.095], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.095:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 0.095000000000000001Initial program 65.3%
neg-sub065.3%
associate-+l-65.3%
sub0-neg65.3%
neg-mul-165.3%
*-commutative65.3%
associate-*r/65.1%
Simplified64.7%
Taylor expanded in b around -inf 47.2%
associate-*r/47.2%
mul-1-neg47.2%
Simplified47.2%
if 0.095000000000000001 < b Initial program 13.1%
/-rgt-identity13.1%
metadata-eval13.1%
associate-/l*13.1%
associate-*r/13.1%
+-commutative13.1%
unsub-neg13.1%
fma-neg13.1%
*-commutative13.1%
distribute-rgt-neg-in13.1%
associate-*l*13.1%
metadata-eval13.1%
associate-/r*13.1%
metadata-eval13.1%
metadata-eval13.1%
Simplified13.1%
Taylor expanded in b around -inf 2.9%
Taylor expanded in c around inf 32.5%
Final simplification42.5%
(FPCore (a b c) :precision binary64 (if (<= b 4.7e-284) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.7e-284) {
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 <= 4.7d-284) 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 <= 4.7e-284) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.7e-284: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.7e-284) 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 <= 4.7e-284) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.7e-284], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.7 \cdot 10^{-284}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 4.70000000000000022e-284Initial program 67.8%
neg-sub067.8%
associate-+l-67.8%
sub0-neg67.8%
neg-mul-167.8%
*-commutative67.8%
associate-*r/67.7%
Simplified67.8%
Taylor expanded in b around -inf 63.9%
associate-*r/63.9%
mul-1-neg63.9%
Simplified63.9%
if 4.70000000000000022e-284 < b Initial program 30.0%
neg-sub030.0%
associate-+l-30.0%
sub0-neg30.0%
neg-mul-130.0%
*-commutative30.0%
associate-*r/29.9%
Simplified29.2%
Taylor expanded in b around inf 74.1%
associate-*r/74.1%
neg-mul-174.1%
Simplified74.1%
Final simplification69.1%
(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 48.7%
/-rgt-identity48.7%
metadata-eval48.7%
associate-/l*48.7%
associate-*r/48.6%
+-commutative48.6%
unsub-neg48.6%
fma-neg48.6%
*-commutative48.6%
distribute-rgt-neg-in48.6%
associate-*l*48.3%
metadata-eval48.3%
associate-/r*48.3%
metadata-eval48.3%
metadata-eval48.3%
Simplified48.3%
Taylor expanded in b around -inf 30.4%
Taylor expanded in c around inf 12.3%
Final simplification12.3%
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023229
(FPCore (a b c)
:name "quadp (p42, positive)"
: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)))