
(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 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(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 -2.9e-135)
(/ c (- b))
(if (<= b 7e+103)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-135) {
tmp = c / -b;
} else if (b <= 7e+103) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.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 <= (-2.9d-135)) then
tmp = c / -b
else if (b <= 7d+103) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.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 <= -2.9e-135) {
tmp = c / -b;
} else if (b <= 7e+103) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-135: tmp = c / -b elif b <= 7e+103: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-135) tmp = Float64(c / Float64(-b)); elseif (b <= 7e+103) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.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 <= -2.9e-135) tmp = c / -b; elseif (b <= 7e+103) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-135], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7e+103], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-135}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{+103}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9000000000000002e-135Initial program 29.2%
div-sub25.0%
sub-neg25.0%
neg-mul-125.0%
*-commutative25.0%
associate-/l*21.8%
distribute-neg-frac21.8%
neg-mul-121.8%
*-commutative21.8%
associate-/l*25.0%
distribute-rgt-out29.1%
associate-/r*29.1%
metadata-eval29.1%
sub-neg29.1%
+-commutative29.1%
Simplified29.1%
Taylor expanded in b around -inf 77.5%
mul-1-neg77.5%
distribute-neg-frac277.5%
Simplified77.5%
if -2.9000000000000002e-135 < b < 7e103Initial program 87.9%
if 7e103 < b Initial program 52.4%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.3%
distribute-neg-frac52.3%
neg-mul-152.3%
*-commutative52.3%
associate-/l*52.3%
distribute-rgt-out52.3%
associate-/r*52.3%
metadata-eval52.3%
sub-neg52.3%
+-commutative52.3%
Simplified52.5%
Taylor expanded in c around 0 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Final simplification86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -2.35e-135)
(/ c (- b))
(if (<= b 1.22e-82)
(/ (- (- b) (sqrt (* (* c a) -4.0))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-135) {
tmp = c / -b;
} else if (b <= 1.22e-82) {
tmp = (-b - sqrt(((c * a) * -4.0))) / (a * 2.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 <= (-2.35d-135)) then
tmp = c / -b
else if (b <= 1.22d-82) then
tmp = (-b - sqrt(((c * a) * (-4.0d0)))) / (a * 2.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 <= -2.35e-135) {
tmp = c / -b;
} else if (b <= 1.22e-82) {
tmp = (-b - Math.sqrt(((c * a) * -4.0))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.35e-135: tmp = c / -b elif b <= 1.22e-82: tmp = (-b - math.sqrt(((c * a) * -4.0))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.35e-135) tmp = Float64(c / Float64(-b)); elseif (b <= 1.22e-82) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(c * a) * -4.0))) / Float64(a * 2.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 <= -2.35e-135) tmp = c / -b; elseif (b <= 1.22e-82) tmp = (-b - sqrt(((c * a) * -4.0))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.35e-135], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.22e-82], N[(N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.35 \cdot 10^{-135}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-82}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.34999999999999988e-135Initial program 29.2%
div-sub25.0%
sub-neg25.0%
neg-mul-125.0%
*-commutative25.0%
associate-/l*21.8%
distribute-neg-frac21.8%
neg-mul-121.8%
*-commutative21.8%
associate-/l*25.0%
distribute-rgt-out29.1%
associate-/r*29.1%
metadata-eval29.1%
sub-neg29.1%
+-commutative29.1%
Simplified29.1%
Taylor expanded in b around -inf 77.5%
mul-1-neg77.5%
distribute-neg-frac277.5%
Simplified77.5%
if -2.34999999999999988e-135 < b < 1.22000000000000001e-82Initial program 87.7%
*-commutative87.7%
sqr-neg87.7%
*-commutative87.7%
sqr-neg87.7%
*-commutative87.7%
associate-*r*87.7%
*-commutative87.7%
Simplified87.7%
Taylor expanded in b around 0 85.9%
*-commutative85.9%
Simplified85.9%
if 1.22000000000000001e-82 < b Initial program 66.9%
div-sub66.9%
sub-neg66.9%
neg-mul-166.9%
*-commutative66.9%
associate-/l*66.8%
distribute-neg-frac66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.8%
distribute-rgt-out66.8%
associate-/r*66.8%
metadata-eval66.8%
sub-neg66.8%
+-commutative66.8%
Simplified66.9%
Taylor expanded in c around 0 90.3%
+-commutative90.3%
mul-1-neg90.3%
unsub-neg90.3%
Simplified90.3%
Final simplification84.6%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-135)
(/ c (- b))
(if (<= b 2.2e-89)
(* (/ -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 <= -2.9e-135) {
tmp = c / -b;
} else if (b <= 2.2e-89) {
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 <= (-2.9d-135)) then
tmp = c / -b
else if (b <= 2.2d-89) 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 <= -2.9e-135) {
tmp = c / -b;
} else if (b <= 2.2e-89) {
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 <= -2.9e-135: tmp = c / -b elif b <= 2.2e-89: 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 <= -2.9e-135) tmp = Float64(c / Float64(-b)); elseif (b <= 2.2e-89) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * 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 <= -2.9e-135) tmp = c / -b; elseif (b <= 2.2e-89) 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, -2.9e-135], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.2e-89], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-135}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-89}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9000000000000002e-135Initial program 29.2%
div-sub25.0%
sub-neg25.0%
neg-mul-125.0%
*-commutative25.0%
associate-/l*21.8%
distribute-neg-frac21.8%
neg-mul-121.8%
*-commutative21.8%
associate-/l*25.0%
distribute-rgt-out29.1%
associate-/r*29.1%
metadata-eval29.1%
sub-neg29.1%
+-commutative29.1%
Simplified29.1%
Taylor expanded in b around -inf 77.5%
mul-1-neg77.5%
distribute-neg-frac277.5%
Simplified77.5%
if -2.9000000000000002e-135 < b < 2.20000000000000012e-89Initial program 87.7%
*-commutative87.7%
sqr-neg87.7%
*-commutative87.7%
sqr-neg87.7%
*-commutative87.7%
associate-*r*87.7%
*-commutative87.7%
Simplified87.7%
Taylor expanded in b around 0 85.9%
*-commutative85.9%
Simplified85.9%
div-inv85.8%
add-sqr-sqrt38.6%
sqrt-unprod85.3%
sqr-neg85.3%
sqrt-prod46.6%
add-sqr-sqrt85.4%
associate-*l*85.4%
Applied egg-rr85.4%
Applied egg-rr85.8%
unpow185.8%
*-commutative85.8%
Simplified85.8%
if 2.20000000000000012e-89 < b Initial program 66.9%
div-sub66.9%
sub-neg66.9%
neg-mul-166.9%
*-commutative66.9%
associate-/l*66.8%
distribute-neg-frac66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.8%
distribute-rgt-out66.8%
associate-/r*66.8%
metadata-eval66.8%
sub-neg66.8%
+-commutative66.8%
Simplified66.9%
Taylor expanded in c around 0 90.3%
+-commutative90.3%
mul-1-neg90.3%
unsub-neg90.3%
Simplified90.3%
Final simplification84.6%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-187)
(/ c (- b))
(if (<= b 1.2e-147)
(* 0.5 (- (sqrt (* c (/ -4.0 a)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-187) {
tmp = c / -b;
} else if (b <= 1.2e-147) {
tmp = 0.5 * -sqrt((c * (-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 <= (-9d-187)) then
tmp = c / -b
else if (b <= 1.2d-147) then
tmp = 0.5d0 * -sqrt((c * ((-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 <= -9e-187) {
tmp = c / -b;
} else if (b <= 1.2e-147) {
tmp = 0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-187: tmp = c / -b elif b <= 1.2e-147: tmp = 0.5 * -math.sqrt((c * (-4.0 / a))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-187) tmp = Float64(c / Float64(-b)); elseif (b <= 1.2e-147) tmp = Float64(0.5 * Float64(-sqrt(Float64(c * Float64(-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 <= -9e-187) tmp = c / -b; elseif (b <= 1.2e-147) tmp = 0.5 * -sqrt((c * (-4.0 / a))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-187], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.2e-147], N[(0.5 * (-N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-187}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{-147}:\\
\;\;\;\;0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.9999999999999996e-187Initial program 30.5%
div-sub26.6%
sub-neg26.6%
neg-mul-126.6%
*-commutative26.6%
associate-/l*23.6%
distribute-neg-frac23.6%
neg-mul-123.6%
*-commutative23.6%
associate-/l*26.6%
distribute-rgt-out30.5%
associate-/r*30.5%
metadata-eval30.5%
sub-neg30.5%
+-commutative30.5%
Simplified30.5%
Taylor expanded in b around -inf 73.0%
mul-1-neg73.0%
distribute-neg-frac273.0%
Simplified73.0%
if -8.9999999999999996e-187 < b < 1.19999999999999999e-147Initial program 90.3%
*-commutative90.3%
sqr-neg90.3%
*-commutative90.3%
sqr-neg90.3%
*-commutative90.3%
associate-*r*90.3%
*-commutative90.3%
Simplified90.3%
add-cube-cbrt89.2%
pow389.2%
*-commutative89.2%
associate-*l*89.2%
Applied egg-rr89.2%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt33.4%
rem-cube-cbrt33.6%
associate-/l*33.6%
Simplified33.6%
if 1.19999999999999999e-147 < b Initial program 69.3%
div-sub69.3%
sub-neg69.3%
neg-mul-169.3%
*-commutative69.3%
associate-/l*69.2%
distribute-neg-frac69.2%
neg-mul-169.2%
*-commutative69.2%
associate-/l*69.2%
distribute-rgt-out69.2%
associate-/r*69.2%
metadata-eval69.2%
sub-neg69.2%
+-commutative69.2%
Simplified69.3%
Taylor expanded in c around 0 84.9%
+-commutative84.9%
mul-1-neg84.9%
unsub-neg84.9%
Simplified84.9%
Final simplification70.4%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(c / Float64(-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 <= -5e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 42.4%
div-sub39.2%
sub-neg39.2%
neg-mul-139.2%
*-commutative39.2%
associate-/l*36.8%
distribute-neg-frac36.8%
neg-mul-136.8%
*-commutative36.8%
associate-/l*39.2%
distribute-rgt-out42.3%
associate-/r*42.3%
metadata-eval42.3%
sub-neg42.3%
+-commutative42.3%
Simplified42.3%
Taylor expanded in b around -inf 59.4%
mul-1-neg59.4%
distribute-neg-frac259.4%
Simplified59.4%
if -4.999999999999985e-310 < b Initial program 73.4%
div-sub73.4%
sub-neg73.4%
neg-mul-173.4%
*-commutative73.4%
associate-/l*73.3%
distribute-neg-frac73.3%
neg-mul-173.3%
*-commutative73.3%
associate-/l*73.3%
distribute-rgt-out73.3%
associate-/r*73.3%
metadata-eval73.3%
sub-neg73.3%
+-commutative73.3%
Simplified73.3%
Taylor expanded in c around 0 70.2%
+-commutative70.2%
mul-1-neg70.2%
unsub-neg70.2%
Simplified70.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 42.4%
div-sub39.2%
sub-neg39.2%
neg-mul-139.2%
*-commutative39.2%
associate-/l*36.8%
distribute-neg-frac36.8%
neg-mul-136.8%
*-commutative36.8%
associate-/l*39.2%
distribute-rgt-out42.3%
associate-/r*42.3%
metadata-eval42.3%
sub-neg42.3%
+-commutative42.3%
Simplified42.3%
Taylor expanded in b around -inf 59.4%
mul-1-neg59.4%
distribute-neg-frac259.4%
Simplified59.4%
if -4.999999999999985e-310 < b Initial program 73.4%
div-sub73.4%
sub-neg73.4%
neg-mul-173.4%
*-commutative73.4%
associate-/l*73.3%
distribute-neg-frac73.3%
neg-mul-173.3%
*-commutative73.3%
associate-/l*73.3%
distribute-rgt-out73.3%
associate-/r*73.3%
metadata-eval73.3%
sub-neg73.3%
+-commutative73.3%
Simplified73.3%
Taylor expanded in a around 0 69.8%
associate-*r/69.8%
mul-1-neg69.8%
Simplified69.8%
(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 / Float64(-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 58.7%
div-sub57.2%
sub-neg57.2%
neg-mul-157.2%
*-commutative57.2%
associate-/l*56.0%
distribute-neg-frac56.0%
neg-mul-156.0%
*-commutative56.0%
associate-/l*57.2%
distribute-rgt-out58.6%
associate-/r*58.6%
metadata-eval58.6%
sub-neg58.6%
+-commutative58.6%
Simplified58.7%
Taylor expanded in b around -inf 29.2%
mul-1-neg29.2%
distribute-neg-frac229.2%
Simplified29.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 58.7%
div-sub57.2%
sub-neg57.2%
neg-mul-157.2%
*-commutative57.2%
associate-/l*56.0%
distribute-neg-frac56.0%
neg-mul-156.0%
*-commutative56.0%
associate-/l*57.2%
distribute-rgt-out58.6%
associate-/r*58.6%
metadata-eval58.6%
sub-neg58.6%
+-commutative58.6%
Simplified58.7%
Taylor expanded in b around -inf 29.2%
mul-1-neg29.2%
distribute-neg-frac229.2%
Simplified29.2%
*-un-lft-identity29.2%
add-sqr-sqrt28.0%
sqrt-unprod23.1%
sqr-neg23.1%
sqrt-prod1.9%
add-sqr-sqrt10.4%
Applied egg-rr10.4%
*-lft-identity10.4%
Simplified10.4%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 58.7%
div-sub57.2%
sub-neg57.2%
neg-mul-157.2%
*-commutative57.2%
associate-/l*56.0%
distribute-neg-frac56.0%
neg-mul-156.0%
*-commutative56.0%
associate-/l*57.2%
distribute-rgt-out58.6%
associate-/r*58.6%
metadata-eval58.6%
sub-neg58.6%
+-commutative58.6%
Simplified58.7%
add-sqr-sqrt32.9%
sqrt-unprod25.2%
frac-times25.2%
metadata-eval25.2%
pow225.2%
Applied egg-rr25.2%
Taylor expanded in a around 0 2.6%
(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 2024182
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))