
(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 -1.1e+71)
(/ (- (* c (* (/ (* a -4.0) b) -0.25)) b) a)
(if (<= b 2.9e-39)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e+71) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 2.9e-39) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - 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 <= (-1.1d+71)) then
tmp = ((c * (((a * (-4.0d0)) / b) * (-0.25d0))) - b) / a
else if (b <= 2.9d-39) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - 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 <= -1.1e+71) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 2.9e-39) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e+71: tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a elif b <= 2.9e-39: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e+71) tmp = Float64(Float64(Float64(c * Float64(Float64(Float64(a * -4.0) / b) * -0.25)) - b) / a); elseif (b <= 2.9e-39) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e+71) tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a; elseif (b <= 2.9e-39) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e+71], N[(N[(N[(c * N[(N[(N[(a * -4.0), $MachinePrecision] / b), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.9e-39], 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[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{+71}:\\
\;\;\;\;\frac{c \cdot \left(\frac{a \cdot -4}{b} \cdot -0.25\right) - b}{a}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{-39}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.09999999999999997e71Initial program 50.4%
*-commutative50.4%
Simplified50.4%
prod-diff50.1%
*-commutative50.1%
fma-def50.1%
associate-+l+50.1%
pow250.1%
distribute-lft-neg-in50.1%
*-commutative50.1%
distribute-rgt-neg-in50.1%
metadata-eval50.1%
associate-*r*50.1%
*-commutative50.1%
*-commutative50.1%
fma-udef50.1%
Applied egg-rr50.1%
fma-def50.1%
fma-def50.2%
associate-*l*50.2%
Simplified50.2%
Taylor expanded in b around -inf 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
*-commutative89.2%
associate-*r*89.2%
associate-*r*89.2%
distribute-rgt-in89.2%
times-frac79.5%
distribute-rgt-out79.5%
metadata-eval79.5%
Simplified79.5%
add-cube-cbrt78.1%
pow378.1%
associate-*l*78.1%
Applied egg-rr78.1%
rem-cube-cbrt79.5%
sub-neg79.5%
*-commutative79.5%
*-un-lft-identity79.5%
times-frac79.5%
metadata-eval79.5%
Applied egg-rr79.5%
sub-neg79.5%
associate-*l/97.7%
div-sub97.8%
associate-*r/97.8%
*-commutative97.8%
Simplified97.8%
if -1.09999999999999997e71 < b < 2.89999999999999988e-39Initial program 80.6%
if 2.89999999999999988e-39 < b Initial program 13.5%
*-commutative13.5%
Simplified13.5%
Taylor expanded in b around inf 88.5%
mul-1-neg88.5%
distribute-neg-frac88.5%
Simplified88.5%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(if (<= b -5e-48)
(/ (- (* c (* (/ (* a -4.0) b) -0.25)) b) a)
(if (<= b 4.2e-39)
(/ 1.0 (/ a (/ (- (sqrt (* -4.0 (* c a))) b) 2.0)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-48) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 4.2e-39) {
tmp = 1.0 / (a / ((sqrt((-4.0 * (c * a))) - b) / 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 <= (-5d-48)) then
tmp = ((c * (((a * (-4.0d0)) / b) * (-0.25d0))) - b) / a
else if (b <= 4.2d-39) then
tmp = 1.0d0 / (a / ((sqrt(((-4.0d0) * (c * a))) - b) / 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 <= -5e-48) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 4.2e-39) {
tmp = 1.0 / (a / ((Math.sqrt((-4.0 * (c * a))) - b) / 2.0));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-48: tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a elif b <= 4.2e-39: tmp = 1.0 / (a / ((math.sqrt((-4.0 * (c * a))) - b) / 2.0)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-48) tmp = Float64(Float64(Float64(c * Float64(Float64(Float64(a * -4.0) / b) * -0.25)) - b) / a); elseif (b <= 4.2e-39) tmp = Float64(1.0 / Float64(a / Float64(Float64(sqrt(Float64(-4.0 * Float64(c * a))) - b) / 2.0))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-48) tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a; elseif (b <= 4.2e-39) tmp = 1.0 / (a / ((sqrt((-4.0 * (c * a))) - b) / 2.0)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-48], N[(N[(N[(c * N[(N[(N[(a * -4.0), $MachinePrecision] / b), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 4.2e-39], N[(1.0 / N[(a / N[(N[(N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-48}:\\
\;\;\;\;\frac{c \cdot \left(\frac{a \cdot -4}{b} \cdot -0.25\right) - b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-39}:\\
\;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{-4 \cdot \left(c \cdot a\right)} - b}{2}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.9999999999999999e-48Initial program 65.0%
*-commutative65.0%
Simplified65.0%
prod-diff64.8%
*-commutative64.8%
fma-def64.8%
associate-+l+64.8%
pow264.8%
distribute-lft-neg-in64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
metadata-eval64.8%
associate-*r*64.8%
*-commutative64.8%
*-commutative64.8%
fma-udef64.8%
Applied egg-rr64.8%
fma-def64.8%
fma-def64.8%
associate-*l*64.8%
Simplified64.8%
Taylor expanded in b around -inf 82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
*-commutative82.9%
associate-*r*82.9%
associate-*r*82.9%
distribute-rgt-in82.9%
times-frac76.3%
distribute-rgt-out76.3%
metadata-eval76.3%
Simplified76.3%
add-cube-cbrt74.9%
pow375.0%
associate-*l*75.0%
Applied egg-rr75.0%
rem-cube-cbrt76.3%
sub-neg76.3%
*-commutative76.3%
*-un-lft-identity76.3%
times-frac76.3%
metadata-eval76.3%
Applied egg-rr76.3%
sub-neg76.3%
associate-*l/88.7%
div-sub88.8%
associate-*r/88.8%
*-commutative88.8%
Simplified88.8%
if -4.9999999999999999e-48 < b < 4.19999999999999987e-39Initial program 73.5%
*-commutative73.5%
Simplified73.5%
add-sqr-sqrt73.1%
pow273.1%
pow1/273.1%
sqrt-pow173.2%
sub-neg73.2%
+-commutative73.2%
distribute-lft-neg-in73.2%
*-commutative73.2%
distribute-rgt-neg-in73.2%
metadata-eval73.2%
associate-*r*71.8%
*-commutative71.8%
fma-udef71.8%
pow271.8%
metadata-eval71.8%
Applied egg-rr71.8%
Taylor expanded in c around -inf 48.1%
clear-num48.1%
inv-pow48.1%
Applied egg-rr71.8%
unpow-171.8%
associate-/l*71.8%
unpow271.8%
pow-sqr72.2%
metadata-eval72.2%
unpow1/272.2%
associate-*l*70.8%
associate-/r/70.8%
metadata-eval70.8%
associate-*r*70.8%
metadata-eval70.8%
*-commutative70.8%
associate-*r*72.1%
*-commutative72.1%
Simplified72.1%
if 4.19999999999999987e-39 < b Initial program 13.5%
*-commutative13.5%
Simplified13.5%
Taylor expanded in b around inf 88.5%
mul-1-neg88.5%
distribute-neg-frac88.5%
Simplified88.5%
Final simplification84.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.6e-48)
(/ (- (* c (* (/ (* a -4.0) b) -0.25)) b) a)
(if (<= b 4.2e-39)
(/ (- (sqrt (* -4.0 (* c a))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-48) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 4.2e-39) {
tmp = (sqrt((-4.0 * (c * a))) - 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 <= (-1.6d-48)) then
tmp = ((c * (((a * (-4.0d0)) / b) * (-0.25d0))) - b) / a
else if (b <= 4.2d-39) then
tmp = (sqrt(((-4.0d0) * (c * a))) - 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 <= -1.6e-48) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 4.2e-39) {
tmp = (Math.sqrt((-4.0 * (c * a))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.6e-48: tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a elif b <= 4.2e-39: tmp = (math.sqrt((-4.0 * (c * a))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.6e-48) tmp = Float64(Float64(Float64(c * Float64(Float64(Float64(a * -4.0) / b) * -0.25)) - b) / a); elseif (b <= 4.2e-39) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(c * a))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.6e-48) tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a; elseif (b <= 4.2e-39) tmp = (sqrt((-4.0 * (c * a))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.6e-48], N[(N[(N[(c * N[(N[(N[(a * -4.0), $MachinePrecision] / b), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 4.2e-39], N[(N[(N[Sqrt[N[(-4.0 * N[(c * a), $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.6 \cdot 10^{-48}:\\
\;\;\;\;\frac{c \cdot \left(\frac{a \cdot -4}{b} \cdot -0.25\right) - b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-39}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.5999999999999999e-48Initial program 65.0%
*-commutative65.0%
Simplified65.0%
prod-diff64.8%
*-commutative64.8%
fma-def64.8%
associate-+l+64.8%
pow264.8%
distribute-lft-neg-in64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
metadata-eval64.8%
associate-*r*64.8%
*-commutative64.8%
*-commutative64.8%
fma-udef64.8%
Applied egg-rr64.8%
fma-def64.8%
fma-def64.8%
associate-*l*64.8%
Simplified64.8%
Taylor expanded in b around -inf 82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
*-commutative82.9%
associate-*r*82.9%
associate-*r*82.9%
distribute-rgt-in82.9%
times-frac76.3%
distribute-rgt-out76.3%
metadata-eval76.3%
Simplified76.3%
add-cube-cbrt74.9%
pow375.0%
associate-*l*75.0%
Applied egg-rr75.0%
rem-cube-cbrt76.3%
sub-neg76.3%
*-commutative76.3%
*-un-lft-identity76.3%
times-frac76.3%
metadata-eval76.3%
Applied egg-rr76.3%
sub-neg76.3%
associate-*l/88.7%
div-sub88.8%
associate-*r/88.8%
*-commutative88.8%
Simplified88.8%
if -1.5999999999999999e-48 < b < 4.19999999999999987e-39Initial program 73.5%
*-commutative73.5%
Simplified73.5%
add-sqr-sqrt73.1%
pow273.1%
pow1/273.1%
sqrt-pow173.2%
sub-neg73.2%
+-commutative73.2%
distribute-lft-neg-in73.2%
*-commutative73.2%
distribute-rgt-neg-in73.2%
metadata-eval73.2%
associate-*r*71.8%
*-commutative71.8%
fma-udef71.8%
pow271.8%
metadata-eval71.8%
Applied egg-rr71.8%
Taylor expanded in c around -inf 48.1%
expm1-log1p-u48.2%
expm1-udef26.5%
Applied egg-rr38.1%
expm1-def69.0%
expm1-log1p71.6%
unpow271.6%
pow-sqr71.9%
metadata-eval71.9%
unpow1/271.9%
associate-*l*70.5%
associate-/r/70.5%
metadata-eval70.5%
associate-*r*70.5%
metadata-eval70.5%
*-commutative70.5%
associate-*r*71.8%
*-commutative71.8%
Simplified72.0%
if 4.19999999999999987e-39 < b Initial program 13.5%
*-commutative13.5%
Simplified13.5%
Taylor expanded in b around inf 88.5%
mul-1-neg88.5%
distribute-neg-frac88.5%
Simplified88.5%
Final simplification84.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.1e-47) (/ (- (* c (* (/ (* a -4.0) b) -0.25)) b) a) (if (<= b 2.9e-39) (* 0.5 (/ (sqrt (* -4.0 (* c a))) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-47) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 2.9e-39) {
tmp = 0.5 * (sqrt((-4.0 * (c * a))) / 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 <= (-1.1d-47)) then
tmp = ((c * (((a * (-4.0d0)) / b) * (-0.25d0))) - b) / a
else if (b <= 2.9d-39) then
tmp = 0.5d0 * (sqrt(((-4.0d0) * (c * a))) / 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 <= -1.1e-47) {
tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a;
} else if (b <= 2.9e-39) {
tmp = 0.5 * (Math.sqrt((-4.0 * (c * a))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e-47: tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a elif b <= 2.9e-39: tmp = 0.5 * (math.sqrt((-4.0 * (c * a))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e-47) tmp = Float64(Float64(Float64(c * Float64(Float64(Float64(a * -4.0) / b) * -0.25)) - b) / a); elseif (b <= 2.9e-39) tmp = Float64(0.5 * Float64(sqrt(Float64(-4.0 * Float64(c * a))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e-47) tmp = ((c * (((a * -4.0) / b) * -0.25)) - b) / a; elseif (b <= 2.9e-39) tmp = 0.5 * (sqrt((-4.0 * (c * a))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e-47], N[(N[(N[(c * N[(N[(N[(a * -4.0), $MachinePrecision] / b), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.9e-39], N[(0.5 * N[(N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{-47}:\\
\;\;\;\;\frac{c \cdot \left(\frac{a \cdot -4}{b} \cdot -0.25\right) - b}{a}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{-39}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.10000000000000009e-47Initial program 65.0%
*-commutative65.0%
Simplified65.0%
prod-diff64.8%
*-commutative64.8%
fma-def64.8%
associate-+l+64.8%
pow264.8%
distribute-lft-neg-in64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
metadata-eval64.8%
associate-*r*64.8%
*-commutative64.8%
*-commutative64.8%
fma-udef64.8%
Applied egg-rr64.8%
fma-def64.8%
fma-def64.8%
associate-*l*64.8%
Simplified64.8%
Taylor expanded in b around -inf 82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
*-commutative82.9%
associate-*r*82.9%
associate-*r*82.9%
distribute-rgt-in82.9%
times-frac76.3%
distribute-rgt-out76.3%
metadata-eval76.3%
Simplified76.3%
add-cube-cbrt74.9%
pow375.0%
associate-*l*75.0%
Applied egg-rr75.0%
rem-cube-cbrt76.3%
sub-neg76.3%
*-commutative76.3%
*-un-lft-identity76.3%
times-frac76.3%
metadata-eval76.3%
Applied egg-rr76.3%
sub-neg76.3%
associate-*l/88.7%
div-sub88.8%
associate-*r/88.8%
*-commutative88.8%
Simplified88.8%
if -1.10000000000000009e-47 < b < 2.89999999999999988e-39Initial program 73.5%
*-commutative73.5%
Simplified73.5%
add-sqr-sqrt73.1%
pow273.1%
pow1/273.1%
sqrt-pow173.2%
sub-neg73.2%
+-commutative73.2%
distribute-lft-neg-in73.2%
*-commutative73.2%
distribute-rgt-neg-in73.2%
metadata-eval73.2%
associate-*r*71.8%
*-commutative71.8%
fma-udef71.8%
pow271.8%
metadata-eval71.8%
Applied egg-rr71.8%
Taylor expanded in c around -inf 48.1%
Taylor expanded in b around 0 48.2%
expm1-log1p-u48.2%
expm1-udef26.5%
Applied egg-rr37.4%
expm1-def69.0%
expm1-log1p71.6%
unpow271.6%
pow-sqr71.9%
metadata-eval71.9%
unpow1/271.9%
associate-*l*70.5%
associate-/r/70.5%
metadata-eval70.5%
associate-*r*70.5%
metadata-eval70.5%
*-commutative70.5%
associate-*r*71.8%
*-commutative71.8%
Simplified71.8%
if 2.89999999999999988e-39 < b Initial program 13.5%
*-commutative13.5%
Simplified13.5%
Taylor expanded in b around inf 88.5%
mul-1-neg88.5%
distribute-neg-frac88.5%
Simplified88.5%
Final simplification84.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in b around -inf 69.7%
+-commutative69.7%
mul-1-neg69.7%
unsub-neg69.7%
Simplified69.7%
if -4.999999999999985e-310 < b Initial program 26.9%
*-commutative26.9%
Simplified26.9%
Taylor expanded in b around inf 70.6%
mul-1-neg70.6%
distribute-neg-frac70.6%
Simplified70.6%
Final simplification70.1%
(FPCore (a b c) :precision binary64 (if (<= b 1.9e+44) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.9e+44) {
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 <= 1.9d+44) 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 <= 1.9e+44) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.9e+44: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.9e+44) 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 <= 1.9e+44) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.9e+44], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{+44}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.9000000000000001e44Initial program 64.9%
*-commutative64.9%
Simplified64.9%
Taylor expanded in b around -inf 48.9%
associate-*r/48.9%
mul-1-neg48.9%
Simplified48.9%
if 1.9000000000000001e44 < b Initial program 8.3%
*-commutative8.3%
Simplified8.3%
Taylor expanded in b around -inf 2.7%
Taylor expanded in b around 0 28.7%
Final simplification43.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in b around -inf 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
if -4.999999999999985e-310 < b Initial program 26.9%
*-commutative26.9%
Simplified26.9%
Taylor expanded in b around inf 70.6%
mul-1-neg70.6%
distribute-neg-frac70.6%
Simplified70.6%
Final simplification70.0%
(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 48.5%
*-commutative48.5%
Simplified48.5%
Applied egg-rr29.5%
Taylor expanded in a around 0 2.5%
Final simplification2.5%
(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 48.5%
*-commutative48.5%
Simplified48.5%
Taylor expanded in b around -inf 33.4%
Taylor expanded in b around 0 10.5%
Final simplification10.5%
(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 2023322
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))