
(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 10 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 -8.4e+153)
(/ b (- a))
(if (<= b 6.6)
(/ (- (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 <= -8.4e+153) {
tmp = b / -a;
} else if (b <= 6.6) {
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 <= (-8.4d+153)) then
tmp = b / -a
else if (b <= 6.6d0) 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 <= -8.4e+153) {
tmp = b / -a;
} else if (b <= 6.6) {
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 <= -8.4e+153: tmp = b / -a elif b <= 6.6: 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 <= -8.4e+153) tmp = Float64(b / Float64(-a)); elseif (b <= 6.6) 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 <= -8.4e+153) tmp = b / -a; elseif (b <= 6.6) 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, -8.4e+153], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 6.6], 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 -8.4 \cdot 10^{+153}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 6.6:\\
\;\;\;\;\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 < -8.40000000000000067e153Initial program 41.7%
*-commutative41.7%
Simplified41.7%
Taylor expanded in b around -inf 94.8%
associate-*r/94.8%
mul-1-neg94.8%
Simplified94.8%
if -8.40000000000000067e153 < b < 6.5999999999999996Initial program 83.5%
if 6.5999999999999996 < b Initial program 8.5%
*-commutative8.5%
Simplified8.5%
Taylor expanded in b around inf 91.6%
associate-*r/91.6%
mul-1-neg91.6%
Simplified91.6%
Final simplification87.5%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e-89) (* b (- (/ c (pow b 2.0)) (/ 1.0 a))) (if (<= b 750.0) (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-89) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 750.0) {
tmp = (sqrt((a * (c * -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 <= (-2.4d-89)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 750.0d0) then
tmp = (sqrt((a * (c * (-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 <= -2.4e-89) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 750.0) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e-89: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 750.0: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e-89) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 750.0) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - 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-89) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 750.0) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-89], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 750.0], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $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^{-89}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 750:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.40000000000000016e-89Initial program 74.8%
*-commutative74.8%
Simplified74.8%
Taylor expanded in b around -inf 82.9%
mul-1-neg82.9%
distribute-rgt-neg-in82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
Simplified82.9%
if -2.40000000000000016e-89 < b < 750Initial program 75.4%
*-commutative75.4%
Simplified75.4%
Applied egg-rr75.3%
sub-neg75.3%
distribute-rgt-out--75.3%
Simplified75.3%
Taylor expanded in a around inf 70.0%
*-commutative70.0%
associate-*r*70.0%
Simplified70.0%
*-commutative70.0%
clear-num70.0%
un-div-inv70.1%
div-inv70.1%
metadata-eval70.1%
Applied egg-rr70.1%
if 750 < b Initial program 8.5%
*-commutative8.5%
Simplified8.5%
Taylor expanded in b around inf 91.6%
associate-*r/91.6%
mul-1-neg91.6%
Simplified91.6%
Final simplification81.7%
(FPCore (a b c) :precision binary64 (if (<= b -4.3e-85) (* b (- (/ c (pow b 2.0)) (/ 1.0 a))) (if (<= b 6.6) (* (- (sqrt (* a (* c -4.0))) b) (/ 0.5 a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-85) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 6.6) {
tmp = (sqrt((a * (c * -4.0))) - 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 <= (-4.3d-85)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 6.6d0) then
tmp = (sqrt((a * (c * (-4.0d0)))) - 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 <= -4.3e-85) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 6.6) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) * (0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.3e-85: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 6.6: tmp = (math.sqrt((a * (c * -4.0))) - b) * (0.5 / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.3e-85) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 6.6) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - 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 <= -4.3e-85) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 6.6) tmp = (sqrt((a * (c * -4.0))) - b) * (0.5 / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-85], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.6], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -4.3 \cdot 10^{-85}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 6.6:\\
\;\;\;\;\left(\sqrt{a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.29999999999999999e-85Initial program 74.8%
*-commutative74.8%
Simplified74.8%
Taylor expanded in b around -inf 82.9%
mul-1-neg82.9%
distribute-rgt-neg-in82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
Simplified82.9%
if -4.29999999999999999e-85 < b < 6.5999999999999996Initial program 75.4%
*-commutative75.4%
Simplified75.4%
Applied egg-rr75.3%
sub-neg75.3%
distribute-rgt-out--75.3%
Simplified75.3%
Taylor expanded in a around inf 70.0%
*-commutative70.0%
associate-*r*70.0%
Simplified70.0%
if 6.5999999999999996 < b Initial program 8.5%
*-commutative8.5%
Simplified8.5%
Taylor expanded in b around inf 91.6%
associate-*r/91.6%
mul-1-neg91.6%
Simplified91.6%
Final simplification81.7%
(FPCore (a b c) :precision binary64 (if (<= b -1.25e-158) (* b (- (/ c (pow b 2.0)) (/ 1.0 a))) (if (<= b 7.8e-80) (* 0.5 (sqrt (* c (/ -4.0 a)))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e-158) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7.8e-80) {
tmp = 0.5 * sqrt((c * (-4.0 / 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.25d-158)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 7.8d-80) then
tmp = 0.5d0 * sqrt((c * ((-4.0d0) / 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.25e-158) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7.8e-80) {
tmp = 0.5 * Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.25e-158: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 7.8e-80: tmp = 0.5 * math.sqrt((c * (-4.0 / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.25e-158) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 7.8e-80) tmp = Float64(0.5 * sqrt(Float64(c * Float64(-4.0 / a)))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.25e-158) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 7.8e-80) tmp = 0.5 * sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.25e-158], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.8e-80], N[(0.5 * N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.25 \cdot 10^{-158}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 7.8 \cdot 10^{-80}:\\
\;\;\;\;0.5 \cdot \sqrt{c \cdot \frac{-4}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.24999999999999993e-158Initial program 76.6%
*-commutative76.6%
Simplified76.6%
Taylor expanded in b around -inf 80.7%
mul-1-neg80.7%
distribute-rgt-neg-in80.7%
+-commutative80.7%
mul-1-neg80.7%
unsub-neg80.7%
Simplified80.7%
if -1.24999999999999993e-158 < b < 7.7999999999999995e-80Initial program 72.8%
*-commutative72.8%
Simplified72.8%
add-cube-cbrt72.3%
pow372.4%
Applied egg-rr72.4%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt38.7%
rem-cube-cbrt39.1%
associate-/l*39.1%
Simplified39.1%
pow139.1%
associate-*r*39.1%
metadata-eval39.1%
associate-*r/39.1%
*-commutative39.1%
*-un-lft-identity39.1%
times-frac39.0%
metadata-eval39.0%
Applied egg-rr39.0%
unpow139.0%
Simplified39.0%
*-un-lft-identity39.0%
*-commutative39.0%
associate-*r/39.1%
*-commutative39.1%
associate-/l*39.1%
Applied egg-rr39.1%
*-rgt-identity39.1%
Simplified39.1%
if 7.7999999999999995e-80 < b Initial program 20.0%
*-commutative20.0%
Simplified20.0%
Taylor expanded in b around inf 81.2%
associate-*r/81.2%
mul-1-neg81.2%
Simplified81.2%
Final simplification72.6%
(FPCore (a b c) :precision binary64 (if (<= b -1.45e-156) (/ b (- a)) (if (<= b 7e-99) (* 0.5 (sqrt (* c (/ -4.0 a)))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-156) {
tmp = b / -a;
} else if (b <= 7e-99) {
tmp = 0.5 * sqrt((c * (-4.0 / 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.45d-156)) then
tmp = b / -a
else if (b <= 7d-99) then
tmp = 0.5d0 * sqrt((c * ((-4.0d0) / 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.45e-156) {
tmp = b / -a;
} else if (b <= 7e-99) {
tmp = 0.5 * Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-156: tmp = b / -a elif b <= 7e-99: tmp = 0.5 * math.sqrt((c * (-4.0 / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-156) tmp = Float64(b / Float64(-a)); elseif (b <= 7e-99) tmp = Float64(0.5 * sqrt(Float64(c * Float64(-4.0 / a)))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.45e-156) tmp = b / -a; elseif (b <= 7e-99) tmp = 0.5 * sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-156], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 7e-99], N[(0.5 * N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-156}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-99}:\\
\;\;\;\;0.5 \cdot \sqrt{c \cdot \frac{-4}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.4500000000000001e-156Initial program 76.6%
*-commutative76.6%
Simplified76.6%
Taylor expanded in b around -inf 80.4%
associate-*r/80.4%
mul-1-neg80.4%
Simplified80.4%
if -1.4500000000000001e-156 < b < 6.9999999999999997e-99Initial program 72.8%
*-commutative72.8%
Simplified72.8%
add-cube-cbrt72.3%
pow372.4%
Applied egg-rr72.4%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt38.7%
rem-cube-cbrt39.1%
associate-/l*39.1%
Simplified39.1%
pow139.1%
associate-*r*39.1%
metadata-eval39.1%
associate-*r/39.1%
*-commutative39.1%
*-un-lft-identity39.1%
times-frac39.0%
metadata-eval39.0%
Applied egg-rr39.0%
unpow139.0%
Simplified39.0%
*-un-lft-identity39.0%
*-commutative39.0%
associate-*r/39.1%
*-commutative39.1%
associate-/l*39.1%
Applied egg-rr39.1%
*-rgt-identity39.1%
Simplified39.1%
if 6.9999999999999997e-99 < b Initial program 20.0%
*-commutative20.0%
Simplified20.0%
Taylor expanded in b around inf 81.2%
associate-*r/81.2%
mul-1-neg81.2%
Simplified81.2%
Final simplification72.5%
(FPCore (a b c) :precision binary64 (if (<= b -1.2e-155) (/ b (- a)) (if (<= b 1.02e-97) (* 0.5 (sqrt (* -4.0 (/ c a)))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-155) {
tmp = b / -a;
} else if (b <= 1.02e-97) {
tmp = 0.5 * sqrt((-4.0 * (c / 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.2d-155)) then
tmp = b / -a
else if (b <= 1.02d-97) then
tmp = 0.5d0 * sqrt(((-4.0d0) * (c / 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.2e-155) {
tmp = b / -a;
} else if (b <= 1.02e-97) {
tmp = 0.5 * Math.sqrt((-4.0 * (c / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-155: tmp = b / -a elif b <= 1.02e-97: tmp = 0.5 * math.sqrt((-4.0 * (c / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e-155) tmp = Float64(b / Float64(-a)); elseif (b <= 1.02e-97) tmp = Float64(0.5 * sqrt(Float64(-4.0 * Float64(c / a)))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.2e-155) tmp = b / -a; elseif (b <= 1.02e-97) tmp = 0.5 * sqrt((-4.0 * (c / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e-155], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.02e-97], N[(0.5 * N[Sqrt[N[(-4.0 * N[(c / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{-155}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-97}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot \frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.2e-155Initial program 76.6%
*-commutative76.6%
Simplified76.6%
Taylor expanded in b around -inf 80.4%
associate-*r/80.4%
mul-1-neg80.4%
Simplified80.4%
if -1.2e-155 < b < 1.02000000000000004e-97Initial program 72.8%
*-commutative72.8%
Simplified72.8%
add-cube-cbrt72.3%
pow372.4%
Applied egg-rr72.4%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt38.7%
rem-cube-cbrt39.1%
associate-/l*39.1%
Simplified39.1%
pow139.1%
associate-*r*39.1%
metadata-eval39.1%
associate-*r/39.1%
*-commutative39.1%
*-un-lft-identity39.1%
times-frac39.0%
metadata-eval39.0%
Applied egg-rr39.0%
unpow139.0%
Simplified39.0%
if 1.02000000000000004e-97 < b Initial program 20.0%
*-commutative20.0%
Simplified20.0%
Taylor expanded in b around inf 81.2%
associate-*r/81.2%
mul-1-neg81.2%
Simplified81.2%
Final simplification72.5%
(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(b / Float64(-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 78.4%
*-commutative78.4%
Simplified78.4%
Taylor expanded in b around -inf 69.3%
associate-*r/69.3%
mul-1-neg69.3%
Simplified69.3%
if -9.999999999999969e-311 < b Initial program 30.9%
*-commutative30.9%
Simplified30.9%
Taylor expanded in b around inf 65.6%
associate-*r/65.6%
mul-1-neg65.6%
Simplified65.6%
Final simplification67.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.3e+18) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.3e+18) {
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.3d+18) 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.3e+18) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.3e+18: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.3e+18) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.3e+18) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.3e+18], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.3 \cdot 10^{+18}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.3e18Initial program 74.7%
*-commutative74.7%
Simplified74.7%
Taylor expanded in b around -inf 50.8%
associate-*r/50.8%
mul-1-neg50.8%
Simplified50.8%
if 1.3e18 < b Initial program 8.6%
*-commutative8.6%
Simplified8.6%
Taylor expanded in b around inf 76.2%
associate-*r/76.2%
associate-*r*76.2%
*-commutative76.2%
associate-*l/66.8%
Simplified66.8%
associate-/l*58.0%
associate-/l*58.0%
frac-2neg58.0%
metadata-eval58.0%
add-sqr-sqrt0.0%
sqrt-unprod30.9%
sqr-neg30.9%
sqrt-prod30.6%
add-sqr-sqrt30.6%
Applied egg-rr30.6%
Taylor expanded in a around 0 30.6%
Final simplification44.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 55.1%
*-commutative55.1%
Simplified55.1%
Taylor expanded in b around inf 26.0%
associate-*r/26.0%
associate-*r*26.0%
*-commutative26.0%
associate-*l/25.1%
Simplified25.1%
associate-/l*22.8%
associate-/l*22.8%
frac-2neg22.8%
metadata-eval22.8%
add-sqr-sqrt1.0%
sqrt-unprod10.4%
sqr-neg10.4%
sqrt-prod9.4%
add-sqr-sqrt11.0%
Applied egg-rr11.0%
Taylor expanded in a around 0 11.2%
(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 55.1%
*-commutative55.1%
Simplified55.1%
*-un-lft-identity55.1%
*-un-lft-identity55.1%
prod-diff55.1%
*-commutative55.1%
*-un-lft-identity55.1%
fma-define55.1%
*-un-lft-identity55.1%
+-commutative55.1%
add-sqr-sqrt39.8%
sqrt-unprod53.4%
sqr-neg53.4%
sqrt-prod13.6%
add-sqr-sqrt32.4%
pow232.4%
add-sqr-sqrt19.8%
sqrt-unprod32.4%
sqr-neg32.4%
sqrt-prod13.6%
add-sqr-sqrt32.0%
*-commutative32.0%
*-un-lft-identity32.0%
Applied egg-rr32.0%
associate-+l+32.0%
fma-undefine32.0%
*-rgt-identity32.0%
Simplified32.0%
Taylor expanded in b around -inf 2.6%
(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 2024123
(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)))