
(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 -4.8e+31)
(/ b (- a))
(if (<= b 1.65e-96)
(/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e+31) {
tmp = b / -a;
} else if (b <= 1.65e-96) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4.8e+31) tmp = Float64(b / Float64(-a)); elseif (b <= 1.65e-96) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4.8e+31], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.65e-96], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $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 -4.8 \cdot 10^{+31}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{-96}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.79999999999999965e31Initial program 55.9%
*-commutative55.9%
Simplified56.2%
Taylor expanded in b around -inf 93.0%
associate-*r/93.0%
mul-1-neg93.0%
Simplified93.0%
if -4.79999999999999965e31 < b < 1.64999999999999995e-96Initial program 85.9%
*-commutative85.9%
Simplified85.9%
if 1.64999999999999995e-96 < b Initial program 16.9%
*-commutative16.9%
Simplified16.9%
Taylor expanded in a around 0 82.5%
associate-*r/82.5%
mul-1-neg82.5%
Simplified82.5%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4.8e+31)
(/ b (- a))
(if (<= b 9.8e-98)
(/ (- (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 <= -4.8e+31) {
tmp = b / -a;
} else if (b <= 9.8e-98) {
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 <= (-4.8d+31)) then
tmp = b / -a
else if (b <= 9.8d-98) 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 <= -4.8e+31) {
tmp = b / -a;
} else if (b <= 9.8e-98) {
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 <= -4.8e+31: tmp = b / -a elif b <= 9.8e-98: 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 <= -4.8e+31) tmp = Float64(b / Float64(-a)); elseif (b <= 9.8e-98) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 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 <= -4.8e+31) tmp = b / -a; elseif (b <= 9.8e-98) 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, -4.8e+31], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 9.8e-98], 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 -4.8 \cdot 10^{+31}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 9.8 \cdot 10^{-98}:\\
\;\;\;\;\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 < -4.79999999999999965e31Initial program 55.9%
*-commutative55.9%
Simplified56.2%
Taylor expanded in b around -inf 93.0%
associate-*r/93.0%
mul-1-neg93.0%
Simplified93.0%
if -4.79999999999999965e31 < b < 9.80000000000000028e-98Initial program 85.9%
if 9.80000000000000028e-98 < b Initial program 16.9%
*-commutative16.9%
Simplified16.9%
Taylor expanded in a around 0 82.5%
associate-*r/82.5%
mul-1-neg82.5%
Simplified82.5%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.9e-97)
(/ b (- a))
(if (<= b 4.2e-95)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-97) {
tmp = b / -a;
} else if (b <= 4.2e-95) {
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 <= (-1.9d-97)) then
tmp = b / -a
else if (b <= 4.2d-95) 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 <= -1.9e-97) {
tmp = b / -a;
} else if (b <= 4.2e-95) {
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 <= -1.9e-97: tmp = b / -a elif b <= 4.2e-95: 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 <= -1.9e-97) tmp = Float64(b / Float64(-a)); elseif (b <= 4.2e-95) 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 <= -1.9e-97) tmp = b / -a; elseif (b <= 4.2e-95) 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, -1.9e-97], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 4.2e-95], 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 -1.9 \cdot 10^{-97}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-95}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.9e-97Initial program 66.1%
*-commutative66.1%
Simplified66.2%
Taylor expanded in b around -inf 87.1%
associate-*r/87.1%
mul-1-neg87.1%
Simplified87.1%
if -1.9e-97 < b < 4.2e-95Initial program 81.7%
*-commutative81.7%
Simplified81.7%
Taylor expanded in a around inf 74.1%
*-commutative74.1%
associate-*r*74.1%
Simplified74.1%
if 4.2e-95 < b Initial program 16.9%
*-commutative16.9%
Simplified16.9%
Taylor expanded in a around 0 82.5%
associate-*r/82.5%
mul-1-neg82.5%
Simplified82.5%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.9e-97)
(/ b (- a))
(if (<= b 5.1e-96)
(* (/ 0.5 a) (- (sqrt (* -4.0 (* a c))) b))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-97) {
tmp = b / -a;
} else if (b <= 5.1e-96) {
tmp = (0.5 / a) * (sqrt((-4.0 * (a * c))) - b);
} 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-97)) then
tmp = b / -a
else if (b <= 5.1d-96) then
tmp = (0.5d0 / a) * (sqrt(((-4.0d0) * (a * c))) - b)
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-97) {
tmp = b / -a;
} else if (b <= 5.1e-96) {
tmp = (0.5 / a) * (Math.sqrt((-4.0 * (a * c))) - b);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.9e-97: tmp = b / -a elif b <= 5.1e-96: tmp = (0.5 / a) * (math.sqrt((-4.0 * (a * c))) - b) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.9e-97) tmp = Float64(b / Float64(-a)); elseif (b <= 5.1e-96) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.9e-97) tmp = b / -a; elseif (b <= 5.1e-96) tmp = (0.5 / a) * (sqrt((-4.0 * (a * c))) - b); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.9e-97], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 5.1e-96], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{-97}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 5.1 \cdot 10^{-96}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{-4 \cdot \left(a \cdot c\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.9e-97Initial program 66.1%
*-commutative66.1%
Simplified66.2%
Taylor expanded in b around -inf 87.1%
associate-*r/87.1%
mul-1-neg87.1%
Simplified87.1%
if -1.9e-97 < b < 5.09999999999999973e-96Initial program 81.7%
*-commutative81.7%
Simplified81.7%
div-sub81.7%
sub-neg81.7%
div-inv81.5%
pow281.5%
*-commutative81.5%
associate-/r*81.5%
metadata-eval81.5%
div-inv81.5%
*-commutative81.5%
associate-/r*81.5%
metadata-eval81.5%
Applied egg-rr81.5%
sub-neg81.5%
distribute-rgt-out--81.5%
Simplified81.5%
Taylor expanded in a around inf 74.0%
if 5.09999999999999973e-96 < b Initial program 16.9%
*-commutative16.9%
Simplified16.9%
Taylor expanded in a around 0 82.5%
associate-*r/82.5%
mul-1-neg82.5%
Simplified82.5%
Final simplification82.3%
(FPCore (a b c) :precision binary64 (if (<= b -2.6e-159) (/ b (- a)) (if (<= b 3.5e-177) (* -0.5 (- (sqrt (* c (/ -4.0 a))))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-159) {
tmp = b / -a;
} else if (b <= 3.5e-177) {
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 <= (-2.6d-159)) then
tmp = b / -a
else if (b <= 3.5d-177) 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 <= -2.6e-159) {
tmp = b / -a;
} else if (b <= 3.5e-177) {
tmp = -0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.6e-159: tmp = b / -a elif b <= 3.5e-177: 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 <= -2.6e-159) tmp = Float64(b / Float64(-a)); elseif (b <= 3.5e-177) tmp = Float64(-0.5 * Float64(-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 <= -2.6e-159) tmp = b / -a; elseif (b <= 3.5e-177) tmp = -0.5 * -sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.6e-159], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 3.5e-177], 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 -2.6 \cdot 10^{-159}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{-177}:\\
\;\;\;\;-0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.5999999999999998e-159Initial program 69.1%
*-commutative69.1%
Simplified69.3%
Taylor expanded in b around -inf 82.3%
associate-*r/82.3%
mul-1-neg82.3%
Simplified82.3%
if -2.5999999999999998e-159 < b < 3.5000000000000002e-177Initial program 76.5%
*-commutative76.5%
Simplified76.5%
add-cube-cbrt75.7%
pow375.7%
Applied egg-rr75.7%
Taylor expanded in a around -inf 0.0%
rem-cube-cbrt0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt46.3%
Simplified46.3%
if 3.5000000000000002e-177 < b Initial program 25.9%
*-commutative25.9%
Simplified25.9%
Taylor expanded in a around 0 74.3%
associate-*r/74.3%
mul-1-neg74.3%
Simplified74.3%
Final simplification74.1%
(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 70.4%
*-commutative70.4%
Simplified70.6%
Taylor expanded in b around -inf 72.9%
associate-*r/72.9%
mul-1-neg72.9%
Simplified72.9%
if -9.999999999999969e-311 < b Initial program 33.7%
*-commutative33.7%
Simplified33.7%
Taylor expanded in a around 0 62.9%
associate-*r/62.9%
mul-1-neg62.9%
Simplified62.9%
Final simplification68.4%
(FPCore (a b c) :precision binary64 (if (<= b 4.4e+86) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.4e+86) {
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 <= 4.4d+86) 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 <= 4.4e+86) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.4e+86: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.4e+86) 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 <= 4.4e+86) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.4e+86], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.4 \cdot 10^{+86}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 4.40000000000000006e86Initial program 65.2%
*-commutative65.2%
Simplified65.3%
Taylor expanded in b around -inf 50.3%
associate-*r/50.3%
mul-1-neg50.3%
Simplified50.3%
if 4.40000000000000006e86 < b Initial program 6.1%
*-commutative6.1%
Simplified6.1%
Taylor expanded in a around 0 96.3%
associate-*r/96.3%
mul-1-neg96.3%
Simplified96.3%
add-sqr-sqrt44.1%
sqrt-unprod56.5%
sqr-neg56.5%
sqrt-unprod22.1%
add-sqr-sqrt31.3%
div-inv31.3%
Applied egg-rr31.3%
associate-*r/31.3%
*-rgt-identity31.3%
Simplified31.3%
Final simplification46.6%
(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.6%
*-commutative53.6%
Simplified53.7%
Taylor expanded in a around 0 30.0%
associate-*r/30.0%
mul-1-neg30.0%
Simplified30.0%
add-sqr-sqrt13.1%
sqrt-unprod15.9%
sqr-neg15.9%
sqrt-unprod5.4%
add-sqr-sqrt8.4%
div-inv8.4%
Applied egg-rr8.4%
associate-*r/8.4%
*-rgt-identity8.4%
Simplified8.4%
(FPCore (a b c) :precision binary64 (/ a b))
double code(double a, double b, double c) {
return a / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = a / b
end function
public static double code(double a, double b, double c) {
return a / b;
}
def code(a, b, c): return a / b
function code(a, b, c) return Float64(a / b) end
function tmp = code(a, b, c) tmp = a / b; end
code[a_, b_, c_] := N[(a / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{b}
\end{array}
Initial program 53.6%
*-commutative53.6%
Simplified53.7%
Taylor expanded in b around -inf 40.9%
associate-*r/40.9%
mul-1-neg40.9%
Simplified40.9%
neg-sub040.9%
flip3--13.1%
metadata-eval13.1%
metadata-eval13.1%
pow213.1%
Applied egg-rr13.1%
sub0-neg13.1%
+-lft-identity13.1%
mul0-lft13.1%
+-rgt-identity13.1%
Simplified13.1%
div-inv13.1%
add-sqr-sqrt12.4%
sqrt-unprod13.1%
distribute-frac-neg13.1%
pow-div13.1%
metadata-eval13.1%
pow113.1%
distribute-frac-neg13.1%
pow-div29.1%
metadata-eval29.1%
pow129.1%
sqr-neg29.1%
unpow229.1%
sqrt-pow12.3%
metadata-eval2.3%
pow12.3%
Applied egg-rr2.3%
associate-*r/2.3%
*-rgt-identity2.3%
Simplified2.3%
Applied egg-rr2.2%
exp-diff2.2%
rem-exp-log4.2%
rem-exp-log5.0%
Simplified5.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}
\\
b \cdot a
\end{array}
Initial program 53.6%
*-commutative53.6%
Simplified53.7%
Taylor expanded in b around -inf 40.9%
associate-*r/40.9%
mul-1-neg40.9%
Simplified40.9%
neg-sub040.9%
flip3--13.1%
metadata-eval13.1%
metadata-eval13.1%
pow213.1%
Applied egg-rr13.1%
sub0-neg13.1%
+-lft-identity13.1%
mul0-lft13.1%
+-rgt-identity13.1%
Simplified13.1%
div-inv13.1%
add-sqr-sqrt12.4%
sqrt-unprod13.1%
distribute-frac-neg13.1%
pow-div13.1%
metadata-eval13.1%
pow113.1%
distribute-frac-neg13.1%
pow-div29.1%
metadata-eval29.1%
pow129.1%
sqr-neg29.1%
unpow229.1%
sqrt-pow12.3%
metadata-eval2.3%
pow12.3%
Applied egg-rr2.3%
associate-*r/2.3%
*-rgt-identity2.3%
Simplified2.3%
Applied egg-rr2.5%
*-commutative2.5%
Simplified2.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 2024152
(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)))