
(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 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(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 -1e+94)
(- (/ b a))
(if (<= b 2.8e-41)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+94) {
tmp = -(b / a);
} else if (b <= 2.8e-41) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1d+94)) then
tmp = -(b / a)
else if (b <= 2.8d-41) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e+94) {
tmp = -(b / a);
} else if (b <= 2.8e-41) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+94: tmp = -(b / a) elif b <= 2.8e-41: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+94) tmp = Float64(-Float64(b / a)); elseif (b <= 2.8e-41) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+94) tmp = -(b / a); elseif (b <= 2.8e-41) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+94], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 2.8e-41], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+94}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-41}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1e94Initial program 47.2%
*-commutative47.2%
Simplified47.3%
Taylor expanded in b around -inf 96.5%
associate-*r/96.5%
mul-1-neg96.5%
Simplified96.5%
if -1e94 < b < 2.8000000000000002e-41Initial program 79.9%
if 2.8000000000000002e-41 < b Initial program 14.4%
*-commutative14.4%
Simplified14.4%
Taylor expanded in a around 0 89.0%
associate-*r/89.0%
mul-1-neg89.0%
Simplified89.0%
Final simplification86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.4e-54)
(* b (- (/ c (pow b 2.0)) (/ 1.0 a)))
(if (<= b 7.8e-87)
(/ (- (sqrt (* -4.0 (* a c))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-54) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7.8e-87) {
tmp = (sqrt((-4.0 * (a * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.4d-54)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 7.8d-87) then
tmp = (sqrt(((-4.0d0) * (a * c))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-54) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7.8e-87) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e-54: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 7.8e-87: tmp = (math.sqrt((-4.0 * (a * c))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e-54) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 7.8e-87) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.4e-54) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 7.8e-87) tmp = (sqrt((-4.0 * (a * c))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-54], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.8e-87], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-54}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 7.8 \cdot 10^{-87}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.40000000000000013e-54Initial program 66.9%
*-commutative66.9%
Simplified67.0%
Taylor expanded in b around -inf 86.0%
mul-1-neg86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
+-commutative86.0%
mul-1-neg86.0%
unsub-neg86.0%
Simplified86.0%
if -2.40000000000000013e-54 < b < 7.7999999999999996e-87Initial program 78.0%
*-commutative78.0%
Simplified76.7%
Taylor expanded in a around inf 72.5%
if 7.7999999999999996e-87 < b Initial program 18.1%
*-commutative18.1%
Simplified18.2%
Taylor expanded in a around 0 83.3%
associate-*r/83.3%
mul-1-neg83.3%
Simplified83.3%
Final simplification81.2%
(FPCore (a b c) :precision binary64 (if (<= b -3.35e-59) (* b (- (/ c (pow b 2.0)) (/ 1.0 a))) (if (<= b 7e-87) (* (- (sqrt (* -4.0 (* a c))) b) (/ 0.5 a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.35e-59) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7e-87) {
tmp = (sqrt((-4.0 * (a * c))) - b) * (0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3.35d-59)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 7d-87) then
tmp = (sqrt(((-4.0d0) * (a * c))) - b) * (0.5d0 / a)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.35e-59) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7e-87) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) * (0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.35e-59: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 7e-87: tmp = (math.sqrt((-4.0 * (a * c))) - b) * (0.5 / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.35e-59) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 7e-87) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) * Float64(0.5 / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.35e-59) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 7e-87) tmp = (sqrt((-4.0 * (a * c))) - b) * (0.5 / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.35e-59], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7e-87], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.35 \cdot 10^{-59}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-87}:\\
\;\;\;\;\left(\sqrt{-4 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -3.35e-59Initial program 66.9%
*-commutative66.9%
Simplified67.0%
Taylor expanded in b around -inf 86.0%
mul-1-neg86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
+-commutative86.0%
mul-1-neg86.0%
unsub-neg86.0%
Simplified86.0%
if -3.35e-59 < b < 7.00000000000000023e-87Initial program 78.0%
*-commutative78.0%
Simplified76.7%
div-sub76.6%
sub-neg76.6%
div-inv76.6%
pow276.6%
*-commutative76.6%
associate-/r*76.6%
metadata-eval76.6%
div-inv76.6%
*-commutative76.6%
associate-/r*76.6%
metadata-eval76.6%
Applied egg-rr76.6%
sub-neg76.6%
distribute-rgt-out--76.6%
Simplified76.6%
Taylor expanded in a around inf 72.4%
if 7.00000000000000023e-87 < b Initial program 18.1%
*-commutative18.1%
Simplified18.2%
Taylor expanded in a around 0 83.3%
associate-*r/83.3%
mul-1-neg83.3%
Simplified83.3%
Final simplification81.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.55e-59) (* b (- (/ c (pow b 2.0)) (/ 1.0 a))) (if (<= b 8e-87) (/ (sqrt (* a (* c -4.0))) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-59) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 8e-87) {
tmp = sqrt((a * (c * -4.0))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.55d-59)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 8d-87) then
tmp = sqrt((a * (c * (-4.0d0)))) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-59) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 8e-87) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.55e-59: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 8e-87: tmp = math.sqrt((a * (c * -4.0))) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.55e-59) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 8e-87) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.55e-59) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 8e-87) tmp = sqrt((a * (c * -4.0))) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.55e-59], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8e-87], N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.55 \cdot 10^{-59}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-87}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.55e-59Initial program 66.9%
*-commutative66.9%
Simplified67.0%
Taylor expanded in b around -inf 86.0%
mul-1-neg86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
+-commutative86.0%
mul-1-neg86.0%
unsub-neg86.0%
Simplified86.0%
if -1.55e-59 < b < 8.00000000000000014e-87Initial program 78.0%
*-commutative78.0%
Simplified78.0%
add-cube-cbrt77.4%
pow377.4%
associate-*l*77.3%
Applied egg-rr77.3%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt69.7%
rem-cube-cbrt70.0%
associate-*r*71.3%
distribute-lft-neg-in71.3%
metadata-eval71.3%
*-lft-identity71.3%
associate-*r*70.0%
Simplified70.0%
if 8.00000000000000014e-87 < b Initial program 18.1%
*-commutative18.1%
Simplified18.2%
Taylor expanded in a around 0 83.3%
associate-*r/83.3%
mul-1-neg83.3%
Simplified83.3%
Final simplification80.5%
(FPCore (a b c) :precision binary64 (if (<= b -2.85e-56) (- (/ b a)) (if (<= b 7.3e-87) (/ (sqrt (* a (* c -4.0))) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.85e-56) {
tmp = -(b / a);
} else if (b <= 7.3e-87) {
tmp = sqrt((a * (c * -4.0))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.85d-56)) then
tmp = -(b / a)
else if (b <= 7.3d-87) then
tmp = sqrt((a * (c * (-4.0d0)))) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.85e-56) {
tmp = -(b / a);
} else if (b <= 7.3e-87) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.85e-56: tmp = -(b / a) elif b <= 7.3e-87: tmp = math.sqrt((a * (c * -4.0))) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.85e-56) tmp = Float64(-Float64(b / a)); elseif (b <= 7.3e-87) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.85e-56) tmp = -(b / a); elseif (b <= 7.3e-87) tmp = sqrt((a * (c * -4.0))) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.85e-56], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 7.3e-87], N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.85 \cdot 10^{-56}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 7.3 \cdot 10^{-87}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.8499999999999999e-56Initial program 66.9%
*-commutative66.9%
Simplified67.0%
Taylor expanded in b around -inf 85.8%
associate-*r/85.8%
mul-1-neg85.8%
Simplified85.8%
if -2.8499999999999999e-56 < b < 7.29999999999999967e-87Initial program 78.0%
*-commutative78.0%
Simplified78.0%
add-cube-cbrt77.4%
pow377.4%
associate-*l*77.3%
Applied egg-rr77.3%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt69.7%
rem-cube-cbrt70.0%
associate-*r*71.3%
distribute-lft-neg-in71.3%
metadata-eval71.3%
*-lft-identity71.3%
associate-*r*70.0%
Simplified70.0%
if 7.29999999999999967e-87 < b Initial program 18.1%
*-commutative18.1%
Simplified18.2%
Taylor expanded in a around 0 83.3%
associate-*r/83.3%
mul-1-neg83.3%
Simplified83.3%
Final simplification80.5%
(FPCore (a b c) :precision binary64 (if (<= b -7e-150) (- (/ b a)) (if (<= b 9.5e-107) (* (sqrt (* c (/ -4.0 a))) (- -0.5)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-150) {
tmp = -(b / a);
} else if (b <= 9.5e-107) {
tmp = sqrt((c * (-4.0 / a))) * -(-0.5);
} 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 <= (-7d-150)) then
tmp = -(b / a)
else if (b <= 9.5d-107) then
tmp = sqrt((c * ((-4.0d0) / a))) * -(-0.5d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7e-150) {
tmp = -(b / a);
} else if (b <= 9.5e-107) {
tmp = Math.sqrt((c * (-4.0 / a))) * -(-0.5);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-150: tmp = -(b / a) elif b <= 9.5e-107: tmp = math.sqrt((c * (-4.0 / a))) * -(-0.5) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-150) tmp = Float64(-Float64(b / a)); elseif (b <= 9.5e-107) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-(-0.5))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7e-150) tmp = -(b / a); elseif (b <= 9.5e-107) tmp = sqrt((c * (-4.0 / a))) * -(-0.5); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-150], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 9.5e-107], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (--0.5)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{-150}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-107}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(--0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -6.9999999999999996e-150Initial program 70.5%
*-commutative70.5%
Simplified70.6%
Taylor expanded in b around -inf 80.3%
associate-*r/80.3%
mul-1-neg80.3%
Simplified80.3%
if -6.9999999999999996e-150 < b < 9.4999999999999999e-107Initial program 74.1%
*-commutative74.1%
Simplified74.1%
add-cube-cbrt73.5%
pow373.4%
associate-*l*73.3%
Applied egg-rr73.3%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt37.5%
rem-cube-cbrt37.8%
associate-/l*37.7%
Simplified37.7%
if 9.4999999999999999e-107 < b Initial program 19.8%
*-commutative19.8%
Simplified19.8%
Taylor expanded in a around 0 81.7%
associate-*r/81.7%
mul-1-neg81.7%
Simplified81.7%
Final simplification71.2%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = -(b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -(b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = -(b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], (-N[(b / a), $MachinePrecision]), N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 70.9%
*-commutative70.9%
Simplified70.3%
Taylor expanded in b around -inf 67.0%
associate-*r/67.0%
mul-1-neg67.0%
Simplified67.0%
if -9.999999999999969e-311 < b Initial program 34.8%
*-commutative34.8%
Simplified34.8%
Taylor expanded in a around 0 64.2%
associate-*r/64.2%
mul-1-neg64.2%
Simplified64.2%
Final simplification65.7%
(FPCore (a b c) :precision binary64 (if (<= b 7e-15) (- (/ b a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7e-15) {
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 <= 7d-15) 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 <= 7e-15) {
tmp = -(b / a);
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7e-15: tmp = -(b / a) else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7e-15) 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 <= 7e-15) tmp = -(b / a); else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7e-15], (-N[(b / a), $MachinePrecision]), N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{-15}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.0000000000000001e-15Initial program 69.6%
*-commutative69.6%
Simplified69.1%
Taylor expanded in b around -inf 48.9%
associate-*r/48.9%
mul-1-neg48.9%
Simplified48.9%
if 7.0000000000000001e-15 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in a around 0 90.9%
associate-*r/90.9%
mul-1-neg90.9%
Simplified90.9%
add-sqr-sqrt49.2%
sqrt-unprod45.7%
sqr-neg45.7%
sqrt-unprod13.3%
add-sqr-sqrt24.1%
div-inv24.1%
Applied egg-rr24.1%
associate-*r/24.1%
*-rgt-identity24.1%
Simplified24.1%
Final simplification41.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 / 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 53.3%
*-commutative53.3%
Simplified53.0%
Taylor expanded in a around 0 32.4%
associate-*r/32.4%
mul-1-neg32.4%
Simplified32.4%
add-sqr-sqrt16.6%
sqrt-unprod17.3%
sqr-neg17.3%
sqrt-unprod4.9%
add-sqr-sqrt9.0%
div-inv9.0%
Applied egg-rr9.0%
associate-*r/9.0%
*-rgt-identity9.0%
Simplified9.0%
(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 2024150
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))