
(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 -2.4e+146)
(/ b (- a))
(if (<= b 1.1e-53)
(/ (- (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 <= -2.4e+146) {
tmp = b / -a;
} else if (b <= 1.1e-53) {
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 <= -2.4e+146) tmp = Float64(b / Float64(-a)); elseif (b <= 1.1e-53) 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, -2.4e+146], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.1e-53], 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 -2.4 \cdot 10^{+146}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{-53}:\\
\;\;\;\;\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 < -2.4000000000000002e146Initial program 32.1%
*-commutative32.1%
Simplified32.4%
Taylor expanded in b around -inf 88.8%
associate-*r/88.8%
mul-1-neg88.8%
Simplified88.8%
if -2.4000000000000002e146 < b < 1.10000000000000009e-53Initial program 83.3%
*-commutative83.3%
Simplified83.3%
if 1.10000000000000009e-53 < b Initial program 12.1%
*-commutative12.1%
Simplified12.1%
Taylor expanded in a around 0 88.1%
associate-*r/88.1%
mul-1-neg88.1%
Simplified88.1%
Final simplification85.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4e+146)
(/ b (- a))
(if (<= b 3.2e-53)
(/ (- (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 <= -4e+146) {
tmp = b / -a;
} else if (b <= 3.2e-53) {
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 <= (-4d+146)) then
tmp = b / -a
else if (b <= 3.2d-53) 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 <= -4e+146) {
tmp = b / -a;
} else if (b <= 3.2e-53) {
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 <= -4e+146: tmp = b / -a elif b <= 3.2e-53: 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 <= -4e+146) tmp = Float64(b / Float64(-a)); elseif (b <= 3.2e-53) 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 <= -4e+146) tmp = b / -a; elseif (b <= 3.2e-53) 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, -4e+146], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 3.2e-53], 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 \cdot 10^{+146}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{-53}:\\
\;\;\;\;\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 < -3.99999999999999973e146Initial program 32.1%
*-commutative32.1%
Simplified32.4%
Taylor expanded in b around -inf 88.8%
associate-*r/88.8%
mul-1-neg88.8%
Simplified88.8%
if -3.99999999999999973e146 < b < 3.2000000000000001e-53Initial program 83.3%
if 3.2000000000000001e-53 < b Initial program 12.1%
*-commutative12.1%
Simplified12.1%
Taylor expanded in a around 0 88.1%
associate-*r/88.1%
mul-1-neg88.1%
Simplified88.1%
Final simplification85.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e-69)
(/ b (- a))
(if (<= b 8.6e-56)
(/ (- (/ (sqrt (* a (* c -4.0))) a) (/ b a)) 2.0)
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-69) {
tmp = b / -a;
} else if (b <= 8.6e-56) {
tmp = ((sqrt((a * (c * -4.0))) / 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.2d-69)) then
tmp = b / -a
else if (b <= 8.6d-56) then
tmp = ((sqrt((a * (c * (-4.0d0)))) / 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.2e-69) {
tmp = b / -a;
} else if (b <= 8.6e-56) {
tmp = ((Math.sqrt((a * (c * -4.0))) / a) - (b / a)) / 2.0;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-69: tmp = b / -a elif b <= 8.6e-56: tmp = ((math.sqrt((a * (c * -4.0))) / a) - (b / a)) / 2.0 else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e-69) tmp = Float64(b / Float64(-a)); elseif (b <= 8.6e-56) tmp = Float64(Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) / a) - Float64(b / 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.2e-69) tmp = b / -a; elseif (b <= 8.6e-56) tmp = ((sqrt((a * (c * -4.0))) / a) - (b / a)) / 2.0; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e-69], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 8.6e-56], N[(N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{-69}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 8.6 \cdot 10^{-56}:\\
\;\;\;\;\frac{\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a} - \frac{b}{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.2000000000000001e-69Initial program 65.4%
*-commutative65.4%
Simplified65.5%
Taylor expanded in b around -inf 83.4%
associate-*r/83.4%
mul-1-neg83.4%
Simplified83.4%
if -1.2000000000000001e-69 < b < 8.6000000000000002e-56Initial program 76.4%
*-commutative76.4%
Simplified76.4%
Taylor expanded in a around inf 75.5%
associate-*r*75.5%
*-commutative75.5%
Simplified75.5%
div-sub75.5%
associate-*l*75.5%
*-commutative75.5%
Applied egg-rr75.5%
associate-/r*75.5%
associate-/r*75.5%
sub-div75.5%
Applied egg-rr75.5%
if 8.6000000000000002e-56 < b Initial program 12.1%
*-commutative12.1%
Simplified12.1%
Taylor expanded in a around 0 88.1%
associate-*r/88.1%
mul-1-neg88.1%
Simplified88.1%
Final simplification82.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-70)
(/ b (- a))
(if (<= b 4.4e-54)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-70) {
tmp = b / -a;
} else if (b <= 4.4e-54) {
tmp = (sqrt((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.6d-70)) then
tmp = b / -a
else if (b <= 4.4d-54) then
tmp = (sqrt((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.6e-70) {
tmp = b / -a;
} else if (b <= 4.4e-54) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-70: tmp = b / -a elif b <= 4.4e-54: tmp = (math.sqrt((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.6e-70) tmp = Float64(b / Float64(-a)); elseif (b <= 4.4e-54) tmp = Float64(Float64(sqrt(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.6e-70) tmp = b / -a; elseif (b <= 4.4e-54) tmp = (sqrt((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.6e-70], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 4.4e-54], N[(N[(N[Sqrt[N[(c * N[(a * -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 -4.6 \cdot 10^{-70}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 4.4 \cdot 10^{-54}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.60000000000000001e-70Initial program 65.4%
*-commutative65.4%
Simplified65.5%
Taylor expanded in b around -inf 83.4%
associate-*r/83.4%
mul-1-neg83.4%
Simplified83.4%
if -4.60000000000000001e-70 < b < 4.3999999999999999e-54Initial program 76.4%
*-commutative76.4%
Simplified76.4%
Taylor expanded in a around inf 75.5%
associate-*r*75.5%
*-commutative75.5%
Simplified75.5%
if 4.3999999999999999e-54 < b Initial program 12.1%
*-commutative12.1%
Simplified12.1%
Taylor expanded in a around 0 88.1%
associate-*r/88.1%
mul-1-neg88.1%
Simplified88.1%
Final simplification82.9%
(FPCore (a b c)
:precision binary64
(if (<= b -6.8e-69)
(/ b (- a))
(if (<= b 2.05e-53)
(* (/ 0.5 a) (- (sqrt (* a (* c -4.0))) b))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.8e-69) {
tmp = b / -a;
} else if (b <= 2.05e-53) {
tmp = (0.5 / a) * (sqrt((a * (c * -4.0))) - 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 <= (-6.8d-69)) then
tmp = b / -a
else if (b <= 2.05d-53) then
tmp = (0.5d0 / a) * (sqrt((a * (c * (-4.0d0)))) - 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 <= -6.8e-69) {
tmp = b / -a;
} else if (b <= 2.05e-53) {
tmp = (0.5 / a) * (Math.sqrt((a * (c * -4.0))) - b);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.8e-69: tmp = b / -a elif b <= 2.05e-53: tmp = (0.5 / a) * (math.sqrt((a * (c * -4.0))) - b) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.8e-69) tmp = Float64(b / Float64(-a)); elseif (b <= 2.05e-53) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(Float64(a * Float64(c * -4.0))) - b)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.8e-69) tmp = b / -a; elseif (b <= 2.05e-53) tmp = (0.5 / a) * (sqrt((a * (c * -4.0))) - b); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.8e-69], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2.05e-53], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.8 \cdot 10^{-69}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{-53}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{a \cdot \left(c \cdot -4\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -6.80000000000000016e-69Initial program 65.4%
*-commutative65.4%
Simplified65.5%
Taylor expanded in b around -inf 83.4%
associate-*r/83.4%
mul-1-neg83.4%
Simplified83.4%
if -6.80000000000000016e-69 < b < 2.05e-53Initial program 76.4%
*-commutative76.4%
Simplified76.4%
Taylor expanded in a around inf 75.5%
associate-*r*75.5%
*-commutative75.5%
Simplified75.5%
div-sub75.5%
associate-*l*75.5%
*-commutative75.5%
Applied egg-rr75.5%
div-inv75.4%
div-inv75.4%
distribute-rgt-out--75.4%
metadata-eval75.4%
div-inv75.4%
clear-num75.4%
Applied egg-rr75.4%
if 2.05e-53 < b Initial program 12.1%
*-commutative12.1%
Simplified12.1%
Taylor expanded in a around 0 88.1%
associate-*r/88.1%
mul-1-neg88.1%
Simplified88.1%
Final simplification82.8%
(FPCore (a b c) :precision binary64 (if (<= b 4.5e-267) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.5e-267) {
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.5d-267) 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.5e-267) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.5e-267: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.5e-267) 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 <= 4.5e-267) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.5e-267], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.5 \cdot 10^{-267}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 4.4999999999999999e-267Initial program 71.1%
*-commutative71.1%
Simplified71.2%
Taylor expanded in b around -inf 60.6%
associate-*r/60.6%
mul-1-neg60.6%
Simplified60.6%
if 4.4999999999999999e-267 < b Initial program 26.5%
*-commutative26.5%
Simplified26.5%
Taylor expanded in a around 0 70.3%
associate-*r/70.3%
mul-1-neg70.3%
Simplified70.3%
Final simplification65.4%
(FPCore (a b c) :precision binary64 (if (<= b 1.45e-49) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.45e-49) {
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.45d-49) 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.45e-49) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.45e-49: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.45e-49) 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.45e-49) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.45e-49], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.45 \cdot 10^{-49}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.45e-49Initial program 69.9%
*-commutative69.9%
Simplified70.0%
Taylor expanded in b around -inf 48.5%
associate-*r/48.5%
mul-1-neg48.5%
Simplified48.5%
if 1.45e-49 < b Initial program 12.2%
*-commutative12.2%
Simplified12.2%
Taylor expanded in a around 0 89.0%
associate-*r/89.0%
mul-1-neg89.0%
Simplified89.0%
add-sqr-sqrt38.9%
sqrt-unprod46.3%
sqr-neg46.3%
sqrt-unprod13.4%
add-sqr-sqrt29.4%
div-inv29.4%
Applied egg-rr29.4%
associate-*r/29.4%
*-rgt-identity29.4%
Simplified29.4%
Final simplification41.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 48.9%
*-commutative48.9%
Simplified49.0%
Taylor expanded in a around 0 36.0%
associate-*r/36.0%
mul-1-neg36.0%
Simplified36.0%
add-sqr-sqrt16.1%
sqrt-unprod19.2%
sqr-neg19.2%
sqrt-unprod6.1%
add-sqr-sqrt12.8%
div-inv12.8%
Applied egg-rr12.8%
associate-*r/12.8%
*-rgt-identity12.8%
Simplified12.8%
(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.9%
*-commutative48.9%
Simplified49.0%
Taylor expanded in b around -inf 31.7%
associate-*r/31.7%
mul-1-neg31.7%
Simplified31.7%
div-inv31.6%
add-sqr-sqrt30.2%
sqrt-unprod22.1%
sqr-neg22.1%
sqrt-prod1.8%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
Simplified2.5%
herbie shell --seed 2024163
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))