
(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 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(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 -1.3e+41)
(- (/ c b) (/ b a))
(if (<= b 1.1e-35)
(/ (- (sqrt (* c (- (/ (pow b 2.0) 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.3e+41) {
tmp = (c / b) - (b / a);
} else if (b <= 1.1e-35) {
tmp = (sqrt((c * ((pow(b, 2.0) / 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.3d+41)) then
tmp = (c / b) - (b / a)
else if (b <= 1.1d-35) then
tmp = (sqrt((c * (((b ** 2.0d0) / 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.3e+41) {
tmp = (c / b) - (b / a);
} else if (b <= 1.1e-35) {
tmp = (Math.sqrt((c * ((Math.pow(b, 2.0) / 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.3e+41: tmp = (c / b) - (b / a) elif b <= 1.1e-35: tmp = (math.sqrt((c * ((math.pow(b, 2.0) / 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.3e+41) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.1e-35) tmp = Float64(Float64(sqrt(Float64(c * Float64(Float64((b ^ 2.0) / c) - Float64(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.3e+41) tmp = (c / b) - (b / a); elseif (b <= 1.1e-35) tmp = (sqrt((c * (((b ^ 2.0) / 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.3e+41], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.1e-35], N[(N[(N[Sqrt[N[(c * N[(N[(N[Power[b, 2.0], $MachinePrecision] / c), $MachinePrecision] - N[(a * 4.0), $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 -1.3 \cdot 10^{+41}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{-35}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(\frac{{b}^{2}}{c} - a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -1.3e41Initial program 51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in b around -inf 93.4%
mul-1-neg93.4%
*-commutative93.4%
distribute-rgt-neg-in93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
Taylor expanded in a around inf 94.0%
+-commutative94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
if -1.3e41 < b < 1.09999999999999997e-35Initial program 76.0%
*-commutative76.0%
Simplified76.0%
Taylor expanded in c around inf 76.0%
if 1.09999999999999997e-35 < b Initial program 17.5%
*-commutative17.5%
Simplified17.5%
Applied egg-rr16.1%
distribute-rgt-out--17.5%
sub-neg17.5%
add-sqr-sqrt0.0%
sqrt-unprod7.5%
sqr-neg7.5%
sqrt-prod7.5%
add-sqr-sqrt7.5%
clear-num7.5%
div-inv7.5%
metadata-eval7.5%
+-commutative7.5%
associate-/r/7.5%
pow17.5%
associate-/l*7.5%
pow17.5%
Applied egg-rr17.5%
Taylor expanded in a around 0 88.0%
+-commutative88.0%
mul-1-neg88.0%
sub-neg88.0%
Simplified88.0%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3.7e+49)
(- (/ c b) (/ b a))
(if (<= b 2.6e-29)
(/ (- (sqrt (- (* b b) (* 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 <= -3.7e+49) {
tmp = (c / b) - (b / a);
} else if (b <= 2.6e-29) {
tmp = (sqrt(((b * b) - (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 <= (-3.7d+49)) then
tmp = (c / b) - (b / a)
else if (b <= 2.6d-29) then
tmp = (sqrt(((b * b) - (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 <= -3.7e+49) {
tmp = (c / b) - (b / a);
} else if (b <= 2.6e-29) {
tmp = (Math.sqrt(((b * b) - (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 <= -3.7e+49: tmp = (c / b) - (b / a) elif b <= 2.6e-29: tmp = (math.sqrt(((b * b) - (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 <= -3.7e+49) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.6e-29) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(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 <= -3.7e+49) tmp = (c / b) - (b / a); elseif (b <= 2.6e-29) tmp = (sqrt(((b * b) - (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, -3.7e+49], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.6e-29], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $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 -3.7 \cdot 10^{+49}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-29}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -3.70000000000000018e49Initial program 51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in b around -inf 93.4%
mul-1-neg93.4%
*-commutative93.4%
distribute-rgt-neg-in93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
Taylor expanded in a around inf 94.0%
+-commutative94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
if -3.70000000000000018e49 < b < 2.6000000000000002e-29Initial program 76.0%
if 2.6000000000000002e-29 < b Initial program 17.5%
*-commutative17.5%
Simplified17.5%
Applied egg-rr16.1%
distribute-rgt-out--17.5%
sub-neg17.5%
add-sqr-sqrt0.0%
sqrt-unprod7.5%
sqr-neg7.5%
sqrt-prod7.5%
add-sqr-sqrt7.5%
clear-num7.5%
div-inv7.5%
metadata-eval7.5%
+-commutative7.5%
associate-/r/7.5%
pow17.5%
associate-/l*7.5%
pow17.5%
Applied egg-rr17.5%
Taylor expanded in a around 0 88.0%
+-commutative88.0%
mul-1-neg88.0%
sub-neg88.0%
Simplified88.0%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(if (<= b -0.0003)
(- (/ c b) (/ b a))
(if (<= b 1.15e-35)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ 1.0 (- (/ a b) (/ b c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.0003) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-35) {
tmp = (sqrt((a * (c * -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 <= (-0.0003d0)) then
tmp = (c / b) - (b / a)
else if (b <= 1.15d-35) then
tmp = (sqrt((a * (c * (-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 <= -0.0003) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-35) {
tmp = (Math.sqrt((a * (c * -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 <= -0.0003: tmp = (c / b) - (b / a) elif b <= 1.15e-35: tmp = (math.sqrt((a * (c * -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 <= -0.0003) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.15e-35) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -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 <= -0.0003) tmp = (c / b) - (b / a); elseif (b <= 1.15e-35) tmp = (sqrt((a * (c * -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, -0.0003], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-35], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -0.0003:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-35}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -2.99999999999999974e-4Initial program 56.1%
*-commutative56.1%
Simplified56.1%
Taylor expanded in b around -inf 90.4%
mul-1-neg90.4%
*-commutative90.4%
distribute-rgt-neg-in90.4%
+-commutative90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
Taylor expanded in a around inf 90.9%
+-commutative90.9%
mul-1-neg90.9%
unsub-neg90.9%
Simplified90.9%
if -2.99999999999999974e-4 < b < 1.1499999999999999e-35Initial program 74.7%
*-commutative74.7%
Simplified74.7%
Taylor expanded in b around 0 66.6%
*-commutative66.6%
associate-*r*66.6%
Simplified66.6%
if 1.1499999999999999e-35 < b Initial program 17.5%
*-commutative17.5%
Simplified17.5%
Applied egg-rr16.1%
distribute-rgt-out--17.5%
sub-neg17.5%
add-sqr-sqrt0.0%
sqrt-unprod7.5%
sqr-neg7.5%
sqrt-prod7.5%
add-sqr-sqrt7.5%
clear-num7.5%
div-inv7.5%
metadata-eval7.5%
+-commutative7.5%
associate-/r/7.5%
pow17.5%
associate-/l*7.5%
pow17.5%
Applied egg-rr17.5%
Taylor expanded in a around 0 88.0%
+-commutative88.0%
mul-1-neg88.0%
sub-neg88.0%
Simplified88.0%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -4.5e-306) (- (/ c b) (/ b a)) (/ 1.0 (- (/ a b) (/ b c)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-306) {
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 <= (-4.5d-306)) 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 <= -4.5e-306) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e-306: 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 <= -4.5e-306) 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 <= -4.5e-306) 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, -4.5e-306], 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 -4.5 \cdot 10^{-306}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -4.50000000000000005e-306Initial program 68.8%
*-commutative68.8%
Simplified68.8%
Taylor expanded in b around -inf 62.5%
mul-1-neg62.5%
*-commutative62.5%
distribute-rgt-neg-in62.5%
+-commutative62.5%
mul-1-neg62.5%
unsub-neg62.5%
Simplified62.5%
Taylor expanded in a around inf 63.2%
+-commutative63.2%
mul-1-neg63.2%
unsub-neg63.2%
Simplified63.2%
if -4.50000000000000005e-306 < b Initial program 31.8%
*-commutative31.8%
Simplified31.8%
Applied egg-rr30.8%
distribute-rgt-out--31.7%
sub-neg31.7%
add-sqr-sqrt0.8%
sqrt-unprod24.2%
sqr-neg24.2%
sqrt-prod23.6%
add-sqr-sqrt24.3%
clear-num24.3%
div-inv24.3%
metadata-eval24.3%
+-commutative24.3%
associate-/r/24.3%
pow124.3%
associate-/l*24.3%
pow124.3%
Applied egg-rr31.7%
Taylor expanded in a around 0 67.4%
+-commutative67.4%
mul-1-neg67.4%
sub-neg67.4%
Simplified67.4%
Final simplification65.4%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = (c / b) - (b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = (c / b) - (b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 68.5%
*-commutative68.5%
Simplified68.5%
Taylor expanded in b around -inf 61.5%
mul-1-neg61.5%
*-commutative61.5%
distribute-rgt-neg-in61.5%
+-commutative61.5%
mul-1-neg61.5%
unsub-neg61.5%
Simplified61.5%
Taylor expanded in a around inf 62.2%
+-commutative62.2%
mul-1-neg62.2%
unsub-neg62.2%
Simplified62.2%
if -3.999999999999988e-310 < b Initial program 31.5%
*-commutative31.5%
Simplified31.5%
Taylor expanded in b around inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
Final simplification65.3%
(FPCore (a b c) :precision binary64 (if (<= b 9e-175) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= 9e-175) {
tmp = -b / a;
} else {
tmp = 0.0;
}
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-175) then
tmp = -b / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 9e-175) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 9e-175: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= 9e-175) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 9e-175) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 9e-175], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9 \cdot 10^{-175}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < 8.99999999999999996e-175Initial program 67.8%
*-commutative67.8%
Simplified67.8%
Taylor expanded in b around -inf 54.9%
mul-1-neg54.9%
Simplified54.9%
if 8.99999999999999996e-175 < b Initial program 27.4%
*-commutative27.4%
Simplified27.4%
Applied egg-rr26.3%
Taylor expanded in b around -inf 2.7%
mul-1-neg2.7%
Simplified2.7%
add-sqr-sqrt1.4%
sqrt-unprod8.3%
pow28.3%
add-sqr-sqrt0.0%
sqrt-unprod5.7%
sqr-neg5.7%
sqrt-prod6.5%
add-sqr-sqrt8.3%
Applied egg-rr8.3%
Taylor expanded in b around 0 24.4%
Final simplification40.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- b) a) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -b / a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -b / a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = -b / a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-b) / a), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 68.5%
*-commutative68.5%
Simplified68.5%
Taylor expanded in b around -inf 61.6%
mul-1-neg61.6%
Simplified61.6%
if -3.999999999999988e-310 < b Initial program 31.5%
*-commutative31.5%
Simplified31.5%
Taylor expanded in b around inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
Final simplification65.0%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 49.1%
*-commutative49.1%
Simplified49.1%
Applied egg-rr48.6%
Taylor expanded in b around -inf 30.8%
mul-1-neg30.8%
Simplified30.8%
add-sqr-sqrt16.9%
sqrt-unprod16.4%
pow216.4%
add-sqr-sqrt12.3%
sqrt-unprod10.8%
sqr-neg10.8%
sqrt-prod3.3%
add-sqr-sqrt16.4%
Applied egg-rr16.4%
Taylor expanded in b around 0 12.7%
Final simplification12.7%
(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 2024089
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(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)))