
(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 -2.9e-127)
(/ c (- b))
(if (<= b 5.2e+30)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-127) {
tmp = c / -b;
} else if (b <= 5.2e+30) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.9d-127)) then
tmp = c / -b
else if (b <= 5.2d+30) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * a)))) / (a * 2.0d0)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-127) {
tmp = c / -b;
} else if (b <= 5.2e+30) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-127: tmp = c / -b elif b <= 5.2e+30: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-127) tmp = Float64(c / Float64(-b)); elseif (b <= 5.2e+30) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e-127) tmp = c / -b; elseif (b <= 5.2e+30) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-127], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.2e+30], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-127}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{+30}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.9e-127Initial program 17.6%
div-sub16.8%
sub-neg16.8%
neg-mul-116.8%
*-commutative16.8%
associate-/l*16.9%
distribute-neg-frac16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*16.8%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 87.3%
mul-1-neg87.3%
distribute-neg-frac287.3%
Simplified87.3%
if -2.9e-127 < b < 5.19999999999999977e30Initial program 88.3%
*-commutative88.3%
*-commutative88.3%
sqr-neg88.3%
*-commutative88.3%
sqr-neg88.3%
*-commutative88.3%
associate-*r*88.3%
Simplified88.3%
if 5.19999999999999977e30 < b Initial program 58.1%
div-sub58.1%
sub-neg58.1%
neg-mul-158.1%
*-commutative58.1%
associate-/l*58.0%
distribute-neg-frac58.0%
neg-mul-158.0%
*-commutative58.0%
associate-/l*58.0%
distribute-rgt-out58.0%
associate-/r*58.0%
metadata-eval58.0%
sub-neg58.0%
+-commutative58.0%
Simplified58.1%
Taylor expanded in a around 0 97.3%
associate-*r/97.3%
mul-1-neg97.3%
Simplified97.3%
Final simplification90.4%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-127)
(/ c (- b))
(if (<= b 5.2e+30)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-127) {
tmp = c / -b;
} else if (b <= 5.2e+30) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.9d-127)) then
tmp = c / -b
else if (b <= 5.2d+30) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-127) {
tmp = c / -b;
} else if (b <= 5.2e+30) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-127: tmp = c / -b elif b <= 5.2e+30: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-127) tmp = Float64(c / Float64(-b)); elseif (b <= 5.2e+30) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e-127) tmp = c / -b; elseif (b <= 5.2e+30) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-127], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.2e+30], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-127}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{+30}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.9e-127Initial program 17.6%
div-sub16.8%
sub-neg16.8%
neg-mul-116.8%
*-commutative16.8%
associate-/l*16.9%
distribute-neg-frac16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*16.8%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 87.3%
mul-1-neg87.3%
distribute-neg-frac287.3%
Simplified87.3%
if -2.9e-127 < b < 5.19999999999999977e30Initial program 88.3%
if 5.19999999999999977e30 < b Initial program 58.1%
div-sub58.1%
sub-neg58.1%
neg-mul-158.1%
*-commutative58.1%
associate-/l*58.0%
distribute-neg-frac58.0%
neg-mul-158.0%
*-commutative58.0%
associate-/l*58.0%
distribute-rgt-out58.0%
associate-/r*58.0%
metadata-eval58.0%
sub-neg58.0%
+-commutative58.0%
Simplified58.1%
Taylor expanded in a around 0 97.3%
associate-*r/97.3%
mul-1-neg97.3%
Simplified97.3%
Final simplification90.4%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-127)
(/ c (- b))
(if (<= b 2.5e-41)
(* (/ -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-127) {
tmp = c / -b;
} else if (b <= 2.5e-41) {
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-127)) then
tmp = c / -b
else if (b <= 2.5d-41) 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-127) {
tmp = c / -b;
} else if (b <= 2.5e-41) {
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-127: tmp = c / -b elif b <= 2.5e-41: 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-127) tmp = Float64(c / Float64(-b)); elseif (b <= 2.5e-41) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e-127) tmp = c / -b; elseif (b <= 2.5e-41) 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-127], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.5e-41], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-127}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-41}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9e-127Initial program 17.6%
div-sub16.8%
sub-neg16.8%
neg-mul-116.8%
*-commutative16.8%
associate-/l*16.9%
distribute-neg-frac16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*16.8%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 87.3%
mul-1-neg87.3%
distribute-neg-frac287.3%
Simplified87.3%
if -2.9e-127 < b < 2.4999999999999998e-41Initial program 86.5%
div-sub86.5%
sub-neg86.5%
neg-mul-186.5%
*-commutative86.5%
associate-/l*86.5%
distribute-neg-frac86.5%
neg-mul-186.5%
*-commutative86.5%
associate-/l*86.4%
distribute-rgt-out86.4%
associate-/r*86.4%
metadata-eval86.4%
sub-neg86.4%
+-commutative86.4%
Simplified86.4%
Taylor expanded in a around inf 83.7%
associate-*r*83.7%
*-commutative83.7%
*-commutative83.7%
Simplified83.7%
if 2.4999999999999998e-41 < b Initial program 65.9%
div-sub65.9%
sub-neg65.9%
neg-mul-165.9%
*-commutative65.9%
associate-/l*65.7%
distribute-neg-frac65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.7%
distribute-rgt-out65.7%
associate-/r*65.7%
metadata-eval65.7%
sub-neg65.7%
+-commutative65.7%
Simplified65.7%
Taylor expanded in a around 0 90.4%
+-commutative90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
Final simplification87.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.8e-131)
(/ c (- b))
(if (<= b 2.3e-42)
(* -0.5 (/ (pow (* a (* c -4.0)) 0.5) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-131) {
tmp = c / -b;
} else if (b <= 2.3e-42) {
tmp = -0.5 * (pow((a * (c * -4.0)), 0.5) / 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 <= (-4.8d-131)) then
tmp = c / -b
else if (b <= 2.3d-42) then
tmp = (-0.5d0) * (((a * (c * (-4.0d0))) ** 0.5d0) / 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 <= -4.8e-131) {
tmp = c / -b;
} else if (b <= 2.3e-42) {
tmp = -0.5 * (Math.pow((a * (c * -4.0)), 0.5) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.8e-131: tmp = c / -b elif b <= 2.3e-42: tmp = -0.5 * (math.pow((a * (c * -4.0)), 0.5) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.8e-131) tmp = Float64(c / Float64(-b)); elseif (b <= 2.3e-42) tmp = Float64(-0.5 * Float64((Float64(a * Float64(c * -4.0)) ^ 0.5) / 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 <= -4.8e-131) tmp = c / -b; elseif (b <= 2.3e-42) tmp = -0.5 * (((a * (c * -4.0)) ^ 0.5) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.8e-131], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.3e-42], N[(-0.5 * N[(N[Power[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{-131}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-42}:\\
\;\;\;\;-0.5 \cdot \frac{{\left(a \cdot \left(c \cdot -4\right)\right)}^{0.5}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.7999999999999999e-131Initial program 17.6%
div-sub16.8%
sub-neg16.8%
neg-mul-116.8%
*-commutative16.8%
associate-/l*16.9%
distribute-neg-frac16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*16.8%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 87.3%
mul-1-neg87.3%
distribute-neg-frac287.3%
Simplified87.3%
if -4.7999999999999999e-131 < b < 2.30000000000000004e-42Initial program 86.5%
div-sub86.5%
sub-neg86.5%
neg-mul-186.5%
*-commutative86.5%
associate-/l*86.5%
distribute-neg-frac86.5%
neg-mul-186.5%
*-commutative86.5%
associate-/l*86.4%
distribute-rgt-out86.4%
associate-/r*86.4%
metadata-eval86.4%
sub-neg86.4%
+-commutative86.4%
Simplified86.4%
add-sqr-sqrt85.9%
pow285.9%
pow1/285.9%
sqrt-pow185.9%
pow285.9%
metadata-eval85.9%
Applied egg-rr85.9%
Taylor expanded in a around inf 45.7%
associate-*r/45.7%
Simplified44.1%
Taylor expanded in b around 0 45.5%
*-commutative45.5%
*-commutative45.5%
log-prod77.3%
exp-to-pow83.0%
Simplified83.0%
if 2.30000000000000004e-42 < b Initial program 65.9%
div-sub65.9%
sub-neg65.9%
neg-mul-165.9%
*-commutative65.9%
associate-/l*65.7%
distribute-neg-frac65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.7%
distribute-rgt-out65.7%
associate-/r*65.7%
metadata-eval65.7%
sub-neg65.7%
+-commutative65.7%
Simplified65.7%
Taylor expanded in a around 0 90.4%
+-commutative90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
Final simplification87.2%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 35.2%
div-sub34.6%
sub-neg34.6%
neg-mul-134.6%
*-commutative34.6%
associate-/l*34.6%
distribute-neg-frac34.6%
neg-mul-134.6%
*-commutative34.6%
associate-/l*34.6%
distribute-rgt-out35.2%
associate-/r*35.2%
metadata-eval35.2%
sub-neg35.2%
+-commutative35.2%
Simplified35.2%
Taylor expanded in b around -inf 67.8%
mul-1-neg67.8%
distribute-neg-frac267.8%
Simplified67.8%
if -9.999999999999969e-311 < b Initial program 70.8%
div-sub70.8%
sub-neg70.8%
neg-mul-170.8%
*-commutative70.8%
associate-/l*70.7%
distribute-neg-frac70.7%
neg-mul-170.7%
*-commutative70.7%
associate-/l*70.6%
distribute-rgt-out70.6%
associate-/r*70.6%
metadata-eval70.6%
sub-neg70.6%
+-commutative70.6%
Simplified70.7%
Taylor expanded in a around 0 69.4%
+-commutative69.4%
mul-1-neg69.4%
unsub-neg69.4%
Simplified69.4%
Final simplification68.6%
(FPCore (a b c) :precision binary64 (if (<= b -1.95e-294) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-294) {
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 <= (-1.95d-294)) 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 <= -1.95e-294) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.95e-294: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.95e-294) 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 <= -1.95e-294) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.95e-294], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.95 \cdot 10^{-294}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.9500000000000001e-294Initial program 34.7%
div-sub34.1%
sub-neg34.1%
neg-mul-134.1%
*-commutative34.1%
associate-/l*34.1%
distribute-neg-frac34.1%
neg-mul-134.1%
*-commutative34.1%
associate-/l*34.1%
distribute-rgt-out34.7%
associate-/r*34.7%
metadata-eval34.7%
sub-neg34.7%
+-commutative34.7%
Simplified34.7%
Taylor expanded in b around -inf 68.4%
mul-1-neg68.4%
distribute-neg-frac268.4%
Simplified68.4%
if -1.9500000000000001e-294 < b Initial program 71.0%
div-sub71.0%
sub-neg71.0%
neg-mul-171.0%
*-commutative71.0%
associate-/l*70.9%
distribute-neg-frac70.9%
neg-mul-170.9%
*-commutative70.9%
associate-/l*70.8%
distribute-rgt-out70.8%
associate-/r*70.8%
metadata-eval70.8%
sub-neg70.8%
+-commutative70.8%
Simplified70.9%
Taylor expanded in a around 0 68.5%
associate-*r/68.5%
mul-1-neg68.5%
Simplified68.5%
Final simplification68.4%
(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 52.9%
div-sub52.6%
sub-neg52.6%
neg-mul-152.6%
*-commutative52.6%
associate-/l*52.5%
distribute-neg-frac52.5%
neg-mul-152.5%
*-commutative52.5%
associate-/l*52.5%
distribute-rgt-out52.8%
associate-/r*52.8%
metadata-eval52.8%
sub-neg52.8%
+-commutative52.8%
Simplified52.8%
Taylor expanded in b around -inf 35.3%
mul-1-neg35.3%
distribute-neg-frac235.3%
Simplified35.3%
Final simplification35.3%
(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 52.9%
div-sub52.6%
sub-neg52.6%
neg-mul-152.6%
*-commutative52.6%
associate-/l*52.5%
distribute-neg-frac52.5%
neg-mul-152.5%
*-commutative52.5%
associate-/l*52.5%
distribute-rgt-out52.8%
associate-/r*52.8%
metadata-eval52.8%
sub-neg52.8%
+-commutative52.8%
Simplified52.8%
Applied egg-rr24.7%
*-commutative24.7%
distribute-lft-out--24.7%
*-commutative24.7%
Simplified24.7%
Taylor expanded in b around -inf 2.5%
Final simplification2.5%
(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 2024041
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))