
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e-75)
(/ c (- b))
(if (<= b 3.4e+141)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-75) {
tmp = c / -b;
} else if (b <= 3.4e+141) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-5.2d-75)) then
tmp = c / -b
else if (b <= 3.4d+141) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-75) {
tmp = c / -b;
} else if (b <= 3.4e+141) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e-75: tmp = c / -b elif b <= 3.4e+141: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-75) tmp = Float64(c / Float64(-b)); elseif (b <= 3.4e+141) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e-75) tmp = c / -b; elseif (b <= 3.4e+141) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e-75], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.4e+141], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{-75}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{+141}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.2e-75Initial program 14.2%
div-sub11.6%
sub-neg11.6%
neg-mul-111.6%
*-commutative11.6%
associate-/l*10.9%
distribute-neg-frac10.9%
neg-mul-110.9%
*-commutative10.9%
associate-/l*11.6%
distribute-rgt-out14.2%
associate-/r*14.2%
metadata-eval14.2%
sub-neg14.2%
+-commutative14.2%
Simplified14.2%
Taylor expanded in b around -inf 91.1%
mul-1-neg91.1%
distribute-neg-frac291.1%
Simplified91.1%
if -5.2e-75 < b < 3.3999999999999998e141Initial program 88.8%
if 3.3999999999999998e141 < b Initial program 55.6%
div-sub55.6%
sub-neg55.6%
neg-mul-155.6%
*-commutative55.6%
associate-/l*55.6%
distribute-neg-frac55.6%
neg-mul-155.6%
*-commutative55.6%
associate-/l*55.6%
distribute-rgt-out55.6%
associate-/r*55.6%
metadata-eval55.6%
sub-neg55.6%
+-commutative55.6%
Simplified55.8%
Taylor expanded in c around 0 95.5%
+-commutative95.5%
mul-1-neg95.5%
unsub-neg95.5%
Simplified95.5%
Final simplification90.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3.45e-65)
(/ c (- b))
(if (<= b 6.6e-19)
(* (/ -0.5 a) (+ b (sqrt (* (* c a) -4.0))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.45e-65) {
tmp = c / -b;
} else if (b <= 6.6e-19) {
tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0)));
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-3.45d-65)) then
tmp = c / -b
else if (b <= 6.6d-19) then
tmp = ((-0.5d0) / a) * (b + sqrt(((c * a) * (-4.0d0))))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.45e-65) {
tmp = c / -b;
} else if (b <= 6.6e-19) {
tmp = (-0.5 / a) * (b + Math.sqrt(((c * a) * -4.0)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.45e-65: tmp = c / -b elif b <= 6.6e-19: tmp = (-0.5 / a) * (b + math.sqrt(((c * a) * -4.0))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.45e-65) tmp = Float64(c / Float64(-b)); elseif (b <= 6.6e-19) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * a) * -4.0)))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.45e-65) tmp = c / -b; elseif (b <= 6.6e-19) tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.45e-65], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.6e-19], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.45 \cdot 10^{-65}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.6 \cdot 10^{-19}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.44999999999999996e-65Initial program 14.2%
div-sub11.6%
sub-neg11.6%
neg-mul-111.6%
*-commutative11.6%
associate-/l*10.9%
distribute-neg-frac10.9%
neg-mul-110.9%
*-commutative10.9%
associate-/l*11.6%
distribute-rgt-out14.2%
associate-/r*14.2%
metadata-eval14.2%
sub-neg14.2%
+-commutative14.2%
Simplified14.2%
Taylor expanded in b around -inf 91.1%
mul-1-neg91.1%
distribute-neg-frac291.1%
Simplified91.1%
if -3.44999999999999996e-65 < b < 6.5999999999999995e-19Initial program 82.4%
div-sub82.4%
sub-neg82.4%
neg-mul-182.4%
*-commutative82.4%
associate-/l*82.4%
distribute-neg-frac82.4%
neg-mul-182.4%
*-commutative82.4%
associate-/l*82.1%
distribute-rgt-out82.1%
associate-/r*82.1%
metadata-eval82.1%
sub-neg82.1%
+-commutative82.1%
Simplified82.1%
Taylor expanded in a around inf 72.2%
*-commutative72.2%
Simplified72.2%
if 6.5999999999999995e-19 < b Initial program 78.6%
div-sub78.6%
sub-neg78.6%
neg-mul-178.6%
*-commutative78.6%
associate-/l*78.4%
distribute-neg-frac78.4%
neg-mul-178.4%
*-commutative78.4%
associate-/l*78.3%
distribute-rgt-out78.3%
associate-/r*78.3%
metadata-eval78.3%
sub-neg78.3%
+-commutative78.3%
Simplified78.3%
Taylor expanded in c around 0 90.2%
+-commutative90.2%
mul-1-neg90.2%
unsub-neg90.2%
Simplified90.2%
Final simplification85.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e-79)
(/ c (- b))
(if (<= b 6.6e-19)
(/ (* -0.5 (+ b (sqrt (* a (* c -4.0))))) a)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-79) {
tmp = c / -b;
} else if (b <= 6.6e-19) {
tmp = (-0.5 * (b + sqrt((a * (c * -4.0))))) / a;
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-1.2d-79)) then
tmp = c / -b
else if (b <= 6.6d-19) then
tmp = ((-0.5d0) * (b + sqrt((a * (c * (-4.0d0)))))) / a
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-79) {
tmp = c / -b;
} else if (b <= 6.6e-19) {
tmp = (-0.5 * (b + Math.sqrt((a * (c * -4.0))))) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-79: tmp = c / -b elif b <= 6.6e-19: tmp = (-0.5 * (b + math.sqrt((a * (c * -4.0))))) / a else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e-79) tmp = Float64(c / Float64(-b)); elseif (b <= 6.6e-19) tmp = Float64(Float64(-0.5 * Float64(b + sqrt(Float64(a * Float64(c * -4.0))))) / a); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.2e-79) tmp = c / -b; elseif (b <= 6.6e-19) tmp = (-0.5 * (b + sqrt((a * (c * -4.0))))) / a; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e-79], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.6e-19], N[(N[(-0.5 * N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{-79}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.6 \cdot 10^{-19}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.20000000000000003e-79Initial program 14.2%
div-sub11.6%
sub-neg11.6%
neg-mul-111.6%
*-commutative11.6%
associate-/l*10.9%
distribute-neg-frac10.9%
neg-mul-110.9%
*-commutative10.9%
associate-/l*11.6%
distribute-rgt-out14.2%
associate-/r*14.2%
metadata-eval14.2%
sub-neg14.2%
+-commutative14.2%
Simplified14.2%
Taylor expanded in b around -inf 91.1%
mul-1-neg91.1%
distribute-neg-frac291.1%
Simplified91.1%
if -1.20000000000000003e-79 < b < 6.5999999999999995e-19Initial program 82.4%
div-sub82.4%
sub-neg82.4%
neg-mul-182.4%
*-commutative82.4%
associate-/l*82.4%
distribute-neg-frac82.4%
neg-mul-182.4%
*-commutative82.4%
associate-/l*82.1%
distribute-rgt-out82.1%
associate-/r*82.1%
metadata-eval82.1%
sub-neg82.1%
+-commutative82.1%
Simplified82.1%
Taylor expanded in a around inf 72.2%
*-commutative72.2%
Simplified72.2%
associate-*l*72.2%
sqrt-prod54.9%
Applied egg-rr54.9%
associate-*l/55.0%
sqrt-prod72.4%
*-commutative72.4%
Applied egg-rr72.4%
if 6.5999999999999995e-19 < b Initial program 78.6%
div-sub78.6%
sub-neg78.6%
neg-mul-178.6%
*-commutative78.6%
associate-/l*78.4%
distribute-neg-frac78.4%
neg-mul-178.4%
*-commutative78.4%
associate-/l*78.3%
distribute-rgt-out78.3%
associate-/r*78.3%
metadata-eval78.3%
sub-neg78.3%
+-commutative78.3%
Simplified78.3%
Taylor expanded in c around 0 90.2%
+-commutative90.2%
mul-1-neg90.2%
unsub-neg90.2%
Simplified90.2%
Final simplification85.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-5d-310)) then
tmp = c / -b
else
tmp = (c / b) - (b / a)
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;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 32.5%
div-sub30.7%
sub-neg30.7%
neg-mul-130.7%
*-commutative30.7%
associate-/l*30.1%
distribute-neg-frac30.1%
neg-mul-130.1%
*-commutative30.1%
associate-/l*30.7%
distribute-rgt-out32.5%
associate-/r*32.5%
metadata-eval32.5%
sub-neg32.5%
+-commutative32.5%
Simplified32.5%
Taylor expanded in b around -inf 70.2%
mul-1-neg70.2%
distribute-neg-frac270.2%
Simplified70.2%
if -4.999999999999985e-310 < b Initial program 80.2%
div-sub80.2%
sub-neg80.2%
neg-mul-180.2%
*-commutative80.2%
associate-/l*80.1%
distribute-neg-frac80.1%
neg-mul-180.1%
*-commutative80.1%
associate-/l*79.9%
distribute-rgt-out79.9%
associate-/r*79.9%
metadata-eval79.9%
sub-neg79.9%
+-commutative79.9%
Simplified79.9%
Taylor expanded in c around 0 70.0%
+-commutative70.0%
mul-1-neg70.0%
unsub-neg70.0%
Simplified70.0%
Final simplification70.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = c / -b;
} else {
tmp = b / -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) :: tmp
if (b <= (-5d-310)) then
tmp = c / -b
else
tmp = b / -a
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;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 32.5%
div-sub30.7%
sub-neg30.7%
neg-mul-130.7%
*-commutative30.7%
associate-/l*30.1%
distribute-neg-frac30.1%
neg-mul-130.1%
*-commutative30.1%
associate-/l*30.7%
distribute-rgt-out32.5%
associate-/r*32.5%
metadata-eval32.5%
sub-neg32.5%
+-commutative32.5%
Simplified32.5%
Taylor expanded in b around -inf 70.2%
mul-1-neg70.2%
distribute-neg-frac270.2%
Simplified70.2%
if -4.999999999999985e-310 < b Initial program 80.2%
div-sub80.2%
sub-neg80.2%
neg-mul-180.2%
*-commutative80.2%
associate-/l*80.1%
distribute-neg-frac80.1%
neg-mul-180.1%
*-commutative80.1%
associate-/l*79.9%
distribute-rgt-out79.9%
associate-/r*79.9%
metadata-eval79.9%
sub-neg79.9%
+-commutative79.9%
Simplified79.9%
Taylor expanded in a around 0 69.7%
associate-*r/69.7%
mul-1-neg69.7%
Simplified69.7%
Final simplification70.0%
(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 / Float64(-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.8%
div-sub54.9%
sub-neg54.9%
neg-mul-154.9%
*-commutative54.9%
associate-/l*54.5%
distribute-neg-frac54.5%
neg-mul-154.5%
*-commutative54.5%
associate-/l*54.7%
distribute-rgt-out55.6%
associate-/r*55.6%
metadata-eval55.6%
sub-neg55.6%
+-commutative55.6%
Simplified55.7%
Taylor expanded in b around -inf 37.0%
mul-1-neg37.0%
distribute-neg-frac237.0%
Simplified37.0%
Final simplification37.0%
(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.8%
div-sub54.9%
sub-neg54.9%
neg-mul-154.9%
*-commutative54.9%
associate-/l*54.5%
distribute-neg-frac54.5%
neg-mul-154.5%
*-commutative54.5%
associate-/l*54.7%
distribute-rgt-out55.6%
associate-/r*55.6%
metadata-eval55.6%
sub-neg55.6%
+-commutative55.6%
Simplified55.7%
Taylor expanded in a around 0 34.4%
Taylor expanded in b around 0 11.6%
Final simplification11.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t\_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2024115
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))