
(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 8 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 -1.9e-13)
(/ c (- b))
(if (<= b 4.5e+82)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-13) {
tmp = c / -b;
} else if (b <= 4.5e+82) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-1.9d-13)) then
tmp = c / -b
else if (b <= 4.5d+82) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-13) {
tmp = c / -b;
} else if (b <= 4.5e+82) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.9e-13: tmp = c / -b elif b <= 4.5e+82: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.9e-13) tmp = Float64(c / Float64(-b)); elseif (b <= 4.5e+82) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.9e-13) tmp = c / -b; elseif (b <= 4.5e+82) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.9e-13], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.5e+82], 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[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{-13}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{+82}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.9e-13Initial program 10.0%
div-sub9.6%
sub-neg9.6%
neg-mul-19.6%
*-commutative9.6%
associate-/l*7.1%
distribute-neg-frac7.1%
neg-mul-17.1%
*-commutative7.1%
associate-/l*9.6%
distribute-rgt-out10.0%
associate-/r*10.0%
metadata-eval10.0%
sub-neg10.0%
+-commutative10.0%
Simplified10.0%
Taylor expanded in b around -inf 93.2%
mul-1-neg93.2%
distribute-neg-frac293.2%
Simplified93.2%
if -1.9e-13 < b < 4.4999999999999997e82Initial program 81.4%
if 4.4999999999999997e82 < b Initial program 55.7%
div-sub55.7%
sub-neg55.7%
neg-mul-155.7%
*-commutative55.7%
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.7%
Taylor expanded in a around 0 98.4%
associate-*r/98.4%
mul-1-neg98.4%
Simplified98.4%
Final simplification89.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-19)
(/ c (- b))
(if (<= b 300.0)
(/ (* -0.5 (+ b (sqrt (* c (* a -4.0))))) a)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e-19) {
tmp = c / -b;
} else if (b <= 300.0) {
tmp = (-0.5 * (b + sqrt((c * (a * -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.25d-19)) then
tmp = c / -b
else if (b <= 300.0d0) then
tmp = ((-0.5d0) * (b + sqrt((c * (a * (-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.25e-19) {
tmp = c / -b;
} else if (b <= 300.0) {
tmp = (-0.5 * (b + Math.sqrt((c * (a * -4.0))))) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.25e-19: tmp = c / -b elif b <= 300.0: tmp = (-0.5 * (b + math.sqrt((c * (a * -4.0))))) / a else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.25e-19) tmp = Float64(c / Float64(-b)); elseif (b <= 300.0) tmp = Float64(Float64(-0.5 * Float64(b + sqrt(Float64(c * Float64(a * -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.25e-19) tmp = c / -b; elseif (b <= 300.0) tmp = (-0.5 * (b + sqrt((c * (a * -4.0))))) / a; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.25e-19], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 300.0], N[(N[(-0.5 * N[(b + N[Sqrt[N[(c * N[(a * -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.25 \cdot 10^{-19}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 300:\\
\;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.2500000000000001e-19Initial program 11.1%
div-sub10.6%
sub-neg10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*8.2%
distribute-neg-frac8.2%
neg-mul-18.2%
*-commutative8.2%
associate-/l*10.6%
distribute-rgt-out11.0%
associate-/r*11.0%
metadata-eval11.0%
sub-neg11.0%
+-commutative11.0%
Simplified11.0%
Taylor expanded in b around -inf 92.2%
mul-1-neg92.2%
distribute-neg-frac292.2%
Simplified92.2%
if -1.2500000000000001e-19 < b < 300Initial program 78.5%
div-sub78.5%
sub-neg78.5%
neg-mul-178.5%
*-commutative78.5%
associate-/l*78.5%
distribute-neg-frac78.5%
neg-mul-178.5%
*-commutative78.5%
associate-/l*78.3%
distribute-rgt-out78.3%
associate-/r*78.3%
metadata-eval78.3%
sub-neg78.3%
+-commutative78.3%
Simplified78.4%
add-sqr-sqrt78.2%
pow278.2%
pow1/278.2%
sqrt-pow178.2%
pow278.2%
metadata-eval78.2%
Applied egg-rr78.2%
Taylor expanded in b around 0 69.6%
associate-*r*69.6%
*-commutative69.6%
Simplified69.6%
associate-*l/69.7%
pow-pow69.9%
metadata-eval69.9%
pow1/269.9%
*-commutative69.9%
*-commutative69.9%
Applied egg-rr69.9%
if 300 < b Initial program 66.2%
div-sub66.2%
sub-neg66.2%
neg-mul-166.2%
*-commutative66.2%
associate-/l*66.1%
distribute-neg-frac66.1%
neg-mul-166.1%
*-commutative66.1%
associate-/l*66.0%
distribute-rgt-out66.0%
associate-/r*66.0%
metadata-eval66.0%
sub-neg66.0%
+-commutative66.0%
Simplified66.1%
Taylor expanded in c around 0 93.9%
+-commutative93.9%
mul-1-neg93.9%
unsub-neg93.9%
Simplified93.9%
Final simplification84.3%
(FPCore (a b c)
:precision binary64
(if (<= b -3.1e-20)
(/ c (- b))
(if (<= b 0.056)
(* (/ -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.1e-20) {
tmp = c / -b;
} else if (b <= 0.056) {
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.1d-20)) then
tmp = c / -b
else if (b <= 0.056d0) 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.1e-20) {
tmp = c / -b;
} else if (b <= 0.056) {
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.1e-20: tmp = c / -b elif b <= 0.056: 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.1e-20) tmp = Float64(c / Float64(-b)); elseif (b <= 0.056) 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.1e-20) tmp = c / -b; elseif (b <= 0.056) 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.1e-20], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 0.056], 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.1 \cdot 10^{-20}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 0.056:\\
\;\;\;\;\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.1e-20Initial program 11.1%
div-sub10.6%
sub-neg10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*8.2%
distribute-neg-frac8.2%
neg-mul-18.2%
*-commutative8.2%
associate-/l*10.6%
distribute-rgt-out11.0%
associate-/r*11.0%
metadata-eval11.0%
sub-neg11.0%
+-commutative11.0%
Simplified11.0%
Taylor expanded in b around -inf 92.2%
mul-1-neg92.2%
distribute-neg-frac292.2%
Simplified92.2%
if -3.1e-20 < b < 0.0560000000000000012Initial program 78.5%
div-sub78.5%
sub-neg78.5%
neg-mul-178.5%
*-commutative78.5%
associate-/l*78.5%
distribute-neg-frac78.5%
neg-mul-178.5%
*-commutative78.5%
associate-/l*78.3%
distribute-rgt-out78.3%
associate-/r*78.3%
metadata-eval78.3%
sub-neg78.3%
+-commutative78.3%
Simplified78.4%
Taylor expanded in a around inf 69.7%
*-commutative69.7%
Simplified69.7%
if 0.0560000000000000012 < b Initial program 66.2%
div-sub66.2%
sub-neg66.2%
neg-mul-166.2%
*-commutative66.2%
associate-/l*66.1%
distribute-neg-frac66.1%
neg-mul-166.1%
*-commutative66.1%
associate-/l*66.0%
distribute-rgt-out66.0%
associate-/r*66.0%
metadata-eval66.0%
sub-neg66.0%
+-commutative66.0%
Simplified66.1%
Taylor expanded in c around 0 93.9%
+-commutative93.9%
mul-1-neg93.9%
unsub-neg93.9%
Simplified93.9%
Final simplification84.3%
(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 30.7%
div-sub30.4%
sub-neg30.4%
neg-mul-130.4%
*-commutative30.4%
associate-/l*28.8%
distribute-neg-frac28.8%
neg-mul-128.8%
*-commutative28.8%
associate-/l*30.3%
distribute-rgt-out30.6%
associate-/r*30.6%
metadata-eval30.6%
sub-neg30.6%
+-commutative30.6%
Simplified30.6%
Taylor expanded in b around -inf 68.9%
mul-1-neg68.9%
distribute-neg-frac268.9%
Simplified68.9%
if -4.999999999999985e-310 < b Initial program 74.0%
div-sub74.0%
sub-neg74.0%
neg-mul-174.0%
*-commutative74.0%
associate-/l*73.9%
distribute-neg-frac73.9%
neg-mul-173.9%
*-commutative73.9%
associate-/l*73.9%
distribute-rgt-out73.9%
associate-/r*73.9%
metadata-eval73.9%
sub-neg73.9%
+-commutative73.9%
Simplified73.9%
Taylor expanded in c around 0 65.2%
+-commutative65.2%
mul-1-neg65.2%
unsub-neg65.2%
Simplified65.2%
(FPCore (a b c) :precision binary64 (if (<= b -7e-295) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-295) {
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 <= (-7d-295)) 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 <= -7e-295) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-295: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-295) 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 <= -7e-295) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-295], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{-295}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -6.99999999999999977e-295Initial program 29.6%
div-sub29.3%
sub-neg29.3%
neg-mul-129.3%
*-commutative29.3%
associate-/l*27.7%
distribute-neg-frac27.7%
neg-mul-127.7%
*-commutative27.7%
associate-/l*29.2%
distribute-rgt-out29.5%
associate-/r*29.5%
metadata-eval29.5%
sub-neg29.5%
+-commutative29.5%
Simplified29.5%
Taylor expanded in b around -inf 70.0%
mul-1-neg70.0%
distribute-neg-frac270.0%
Simplified70.0%
if -6.99999999999999977e-295 < b Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.3%
distribute-neg-frac74.3%
neg-mul-174.3%
*-commutative74.3%
associate-/l*74.2%
distribute-rgt-out74.2%
associate-/r*74.2%
metadata-eval74.2%
sub-neg74.2%
+-commutative74.2%
Simplified74.3%
Taylor expanded in a around 0 63.9%
associate-*r/63.9%
mul-1-neg63.9%
Simplified63.9%
Final simplification66.9%
(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 52.7%
div-sub52.6%
sub-neg52.6%
neg-mul-152.6%
*-commutative52.6%
associate-/l*51.7%
distribute-neg-frac51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*52.4%
distribute-rgt-out52.6%
associate-/r*52.6%
metadata-eval52.6%
sub-neg52.6%
+-commutative52.6%
Simplified52.6%
Taylor expanded in b around -inf 35.1%
mul-1-neg35.1%
distribute-neg-frac235.1%
Simplified35.1%
(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 52.7%
div-sub52.6%
sub-neg52.6%
neg-mul-152.6%
*-commutative52.6%
associate-/l*51.7%
distribute-neg-frac51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*52.4%
distribute-rgt-out52.6%
associate-/r*52.6%
metadata-eval52.6%
sub-neg52.6%
+-commutative52.6%
Simplified52.6%
Taylor expanded in b around inf 33.2%
Taylor expanded in b around 0 10.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 52.7%
div-sub52.6%
sub-neg52.6%
neg-mul-152.6%
*-commutative52.6%
associate-/l*51.7%
distribute-neg-frac51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*52.4%
distribute-rgt-out52.6%
associate-/r*52.6%
metadata-eval52.6%
sub-neg52.6%
+-commutative52.6%
Simplified52.6%
Applied egg-rr36.5%
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)
(/ 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 2024101
(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)))