
(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 7 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.2e+108)
(- (/ c b) (/ b a))
(if (<= b 1.4e-48)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ 1.0 (- (/ a b) (/ b c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 1.4e-48) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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.2d+108)) then
tmp = (c / b) - (b / a)
else if (b <= 1.4d-48) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - b) / (a * 2.0d0)
else
tmp = 1.0d0 / ((a / b) - (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 1.4e-48) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.2e+108: tmp = (c / b) - (b / a) elif b <= 1.4e-48: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.2e+108) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.4e-48) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.2e+108) tmp = (c / b) - (b / a); elseif (b <= 1.4e-48) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.2e+108], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.4e-48], 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[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.2 \cdot 10^{+108}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{-48}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -6.2000000000000003e108Initial program 37.8%
Taylor expanded in b around -inf 93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -6.2000000000000003e108 < b < 1.40000000000000002e-48Initial program 81.2%
if 1.40000000000000002e-48 < b Initial program 14.9%
add-cbrt-cube11.8%
pow311.8%
pow1/38.6%
sqrt-pow28.6%
fma-neg8.6%
distribute-lft-neg-in8.6%
associate-*r*8.6%
metadata-eval8.6%
metadata-eval8.6%
Applied egg-rr8.6%
unpow1/311.8%
fma-def11.8%
+-commutative11.8%
*-commutative11.8%
fma-def11.8%
*-commutative11.8%
Simplified11.8%
clear-num11.8%
inv-pow11.8%
*-commutative11.8%
neg-mul-111.8%
fma-def11.8%
pow1/38.6%
pow-pow15.0%
metadata-eval15.0%
pow1/215.0%
fma-udef14.9%
add-sqr-sqrt12.1%
hypot-def23.1%
*-commutative23.1%
Applied egg-rr23.1%
unpow-123.1%
rem-log-exp15.5%
fma-udef15.5%
neg-mul-115.5%
prod-exp0.3%
*-commutative0.3%
prod-exp15.5%
rem-log-exp23.1%
unsub-neg23.1%
associate-*r*23.1%
*-commutative23.1%
associate-*r*23.1%
Simplified23.1%
Taylor expanded in b around inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt87.9%
metadata-eval87.9%
Simplified87.9%
Final simplification85.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.4e-29)
(- (/ c b) (/ b a))
(if (<= b 7.6e-48)
(/ (- (sqrt (* (* c a) -4.0)) b) (* a 2.0))
(/ 1.0 (- (/ a b) (/ b c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-29) {
tmp = (c / b) - (b / a);
} else if (b <= 7.6e-48) {
tmp = (sqrt(((c * a) * -4.0)) - b) / (a * 2.0);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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.4d-29)) then
tmp = (c / b) - (b / a)
else if (b <= 7.6d-48) then
tmp = (sqrt(((c * a) * (-4.0d0))) - b) / (a * 2.0d0)
else
tmp = 1.0d0 / ((a / b) - (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-29) {
tmp = (c / b) - (b / a);
} else if (b <= 7.6e-48) {
tmp = (Math.sqrt(((c * a) * -4.0)) - b) / (a * 2.0);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e-29: tmp = (c / b) - (b / a) elif b <= 7.6e-48: tmp = (math.sqrt(((c * a) * -4.0)) - b) / (a * 2.0) else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e-29) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 7.6e-48) tmp = Float64(Float64(sqrt(Float64(Float64(c * a) * -4.0)) - b) / Float64(a * 2.0)); else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.4e-29) tmp = (c / b) - (b / a); elseif (b <= 7.6e-48) tmp = (sqrt(((c * a) * -4.0)) - b) / (a * 2.0); else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e-29], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.6e-48], N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{-29}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7.6 \cdot 10^{-48}:\\
\;\;\;\;\frac{\sqrt{\left(c \cdot a\right) \cdot -4} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -1.4000000000000001e-29Initial program 57.3%
Taylor expanded in b around -inf 89.3%
mul-1-neg89.3%
unsub-neg89.3%
Simplified89.3%
if -1.4000000000000001e-29 < b < 7.60000000000000005e-48Initial program 77.7%
add-sqr-sqrt77.4%
pow277.4%
pow1/277.4%
sqrt-pow177.5%
fma-neg77.5%
distribute-lft-neg-in77.5%
associate-*r*77.5%
metadata-eval77.5%
metadata-eval77.5%
Applied egg-rr77.5%
Taylor expanded in a around inf 36.9%
Simplified66.9%
if 7.60000000000000005e-48 < b Initial program 14.9%
add-cbrt-cube11.8%
pow311.8%
pow1/38.6%
sqrt-pow28.6%
fma-neg8.6%
distribute-lft-neg-in8.6%
associate-*r*8.6%
metadata-eval8.6%
metadata-eval8.6%
Applied egg-rr8.6%
unpow1/311.8%
fma-def11.8%
+-commutative11.8%
*-commutative11.8%
fma-def11.8%
*-commutative11.8%
Simplified11.8%
clear-num11.8%
inv-pow11.8%
*-commutative11.8%
neg-mul-111.8%
fma-def11.8%
pow1/38.6%
pow-pow15.0%
metadata-eval15.0%
pow1/215.0%
fma-udef14.9%
add-sqr-sqrt12.1%
hypot-def23.1%
*-commutative23.1%
Applied egg-rr23.1%
unpow-123.1%
rem-log-exp15.5%
fma-udef15.5%
neg-mul-115.5%
prod-exp0.3%
*-commutative0.3%
prod-exp15.5%
rem-log-exp23.1%
unsub-neg23.1%
associate-*r*23.1%
*-commutative23.1%
associate-*r*23.1%
Simplified23.1%
Taylor expanded in b around inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt87.9%
metadata-eval87.9%
Simplified87.9%
Final simplification81.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.02e-305) (- (/ c b) (/ b a)) (/ 1.0 (- (/ a b) (/ b c)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.02e-305) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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.02d-305)) then
tmp = (c / b) - (b / a)
else
tmp = 1.0d0 / ((a / b) - (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.02e-305) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.02e-305: tmp = (c / b) - (b / a) else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.02e-305) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.02e-305) tmp = (c / b) - (b / a); else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.02e-305], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.02 \cdot 10^{-305}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -1.01999999999999994e-305Initial program 67.6%
Taylor expanded in b around -inf 66.6%
mul-1-neg66.6%
unsub-neg66.6%
Simplified66.6%
if -1.01999999999999994e-305 < b Initial program 32.1%
add-cbrt-cube25.0%
pow325.1%
pow1/321.8%
sqrt-pow221.8%
fma-neg21.8%
distribute-lft-neg-in21.8%
associate-*r*21.8%
metadata-eval21.8%
metadata-eval21.8%
Applied egg-rr21.8%
unpow1/325.1%
fma-def25.1%
+-commutative25.1%
*-commutative25.1%
fma-def25.1%
*-commutative25.1%
Simplified25.1%
clear-num25.1%
inv-pow25.1%
*-commutative25.1%
neg-mul-125.1%
fma-def25.1%
pow1/321.8%
pow-pow32.0%
metadata-eval32.0%
pow1/232.0%
fma-udef32.0%
add-sqr-sqrt30.1%
hypot-def37.5%
*-commutative37.5%
Applied egg-rr37.5%
unpow-137.5%
rem-log-exp12.6%
fma-udef12.6%
neg-mul-112.6%
prod-exp2.4%
*-commutative2.4%
prod-exp12.6%
rem-log-exp37.5%
unsub-neg37.5%
associate-*r*37.5%
*-commutative37.5%
associate-*r*37.5%
Simplified37.5%
Taylor expanded in b around inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt65.6%
metadata-eval65.6%
Simplified65.6%
Final simplification66.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 67.8%
Taylor expanded in b around -inf 66.2%
mul-1-neg66.2%
unsub-neg66.2%
Simplified66.2%
if -4.999999999999985e-310 < b Initial program 31.5%
Taylor expanded in b around inf 65.5%
associate-*r/65.5%
neg-mul-165.5%
Simplified65.5%
Final simplification65.8%
(FPCore (a b c) :precision binary64 (if (<= b 2.8e+26) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.8e+26) {
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.8d+26) 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.8e+26) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.8e+26: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.8e+26) 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.8e+26) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.8e+26], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.8 \cdot 10^{+26}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.8e26Initial program 66.2%
Taylor expanded in b around -inf 50.1%
associate-*r/50.1%
mul-1-neg50.1%
Simplified50.1%
if 2.8e26 < b Initial program 12.6%
add-sqr-sqrt11.1%
pow211.1%
pow1/211.1%
sqrt-pow111.1%
fma-neg11.1%
distribute-lft-neg-in11.1%
associate-*r*11.1%
metadata-eval11.1%
metadata-eval11.1%
Applied egg-rr11.1%
Taylor expanded in b around -inf 2.4%
neg-mul-12.4%
distribute-lft-out2.4%
unsub-neg2.4%
associate-/l*2.6%
Simplified2.6%
Taylor expanded in c around inf 28.2%
Final simplification43.8%
(FPCore (a b c) :precision binary64 (if (<= b 4.8e-274) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.8e-274) {
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.8d-274) 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.8e-274) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.8e-274: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.8e-274) 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.8e-274) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.8e-274], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.8 \cdot 10^{-274}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 4.8e-274Initial program 68.4%
Taylor expanded in b around -inf 63.2%
associate-*r/63.2%
mul-1-neg63.2%
Simplified63.2%
if 4.8e-274 < b Initial program 28.8%
Taylor expanded in b around inf 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
Final simplification65.7%
(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 50.9%
add-sqr-sqrt50.3%
pow250.3%
pow1/250.3%
sqrt-pow150.4%
fma-neg50.4%
distribute-lft-neg-in50.4%
associate-*r*50.4%
metadata-eval50.4%
metadata-eval50.4%
Applied egg-rr50.4%
Taylor expanded in b around -inf 33.9%
neg-mul-133.9%
distribute-lft-out33.9%
unsub-neg33.9%
associate-/l*36.4%
Simplified36.4%
Taylor expanded in c around inf 10.4%
Final simplification10.4%
(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 2023309
(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)))