
(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 -0.0018)
(/ c (- b))
(if (<= b 1.4e+46)
(/ (- (- 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 <= -0.0018) {
tmp = c / -b;
} else if (b <= 1.4e+46) {
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 <= (-0.0018d0)) then
tmp = c / -b
else if (b <= 1.4d+46) 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 <= -0.0018) {
tmp = c / -b;
} else if (b <= 1.4e+46) {
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 <= -0.0018: tmp = c / -b elif b <= 1.4e+46: 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 <= -0.0018) tmp = Float64(c / Float64(-b)); elseif (b <= 1.4e+46) 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 <= -0.0018) tmp = c / -b; elseif (b <= 1.4e+46) 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, -0.0018], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.4e+46], 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 -0.0018:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{+46}:\\
\;\;\;\;\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 < -0.0018Initial program 7.9%
div-sub6.5%
sub-neg6.5%
neg-mul-16.5%
*-commutative6.5%
associate-/l*6.7%
distribute-neg-frac6.7%
neg-mul-16.7%
*-commutative6.7%
associate-/l*6.6%
distribute-rgt-out7.9%
associate-/r*7.9%
metadata-eval7.9%
sub-neg7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around -inf 90.2%
mul-1-neg90.2%
distribute-neg-frac290.2%
Simplified90.2%
if -0.0018 < b < 1.40000000000000009e46Initial program 78.6%
if 1.40000000000000009e46 < b Initial program 70.6%
div-sub70.6%
sub-neg70.6%
neg-mul-170.6%
*-commutative70.6%
associate-/l*70.4%
distribute-neg-frac70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.4%
distribute-rgt-out70.4%
associate-/r*70.4%
metadata-eval70.4%
sub-neg70.4%
+-commutative70.4%
Simplified70.4%
Taylor expanded in c around 0 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -0.00038)
(/ c (- b))
(if (<= b 7.5e-36)
(/ (- (- b) (sqrt (* c (* a -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.00038) {
tmp = c / -b;
} else if (b <= 7.5e-36) {
tmp = (-b - sqrt((c * (a * -4.0)))) / (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 <= (-0.00038d0)) then
tmp = c / -b
else if (b <= 7.5d-36) then
tmp = (-b - sqrt((c * (a * (-4.0d0))))) / (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 <= -0.00038) {
tmp = c / -b;
} else if (b <= 7.5e-36) {
tmp = (-b - Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.00038: tmp = c / -b elif b <= 7.5e-36: tmp = (-b - math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.00038) tmp = Float64(c / Float64(-b)); elseif (b <= 7.5e-36) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0)))) / 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 <= -0.00038) tmp = c / -b; elseif (b <= 7.5e-36) tmp = (-b - sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.00038], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7.5e-36], N[(N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $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 -0.00038:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.8000000000000002e-4Initial program 7.9%
div-sub6.5%
sub-neg6.5%
neg-mul-16.5%
*-commutative6.5%
associate-/l*6.7%
distribute-neg-frac6.7%
neg-mul-16.7%
*-commutative6.7%
associate-/l*6.6%
distribute-rgt-out7.9%
associate-/r*7.9%
metadata-eval7.9%
sub-neg7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around -inf 90.2%
mul-1-neg90.2%
distribute-neg-frac290.2%
Simplified90.2%
if -3.8000000000000002e-4 < b < 7.49999999999999972e-36Initial program 74.4%
*-commutative74.4%
sqr-neg74.4%
*-commutative74.4%
sqr-neg74.4%
*-commutative74.4%
associate-*r*74.4%
*-commutative74.4%
Simplified74.4%
Taylor expanded in b around 0 66.7%
associate-*r*66.7%
*-commutative66.7%
Simplified66.7%
if 7.49999999999999972e-36 < b Initial program 76.9%
div-sub76.9%
sub-neg76.9%
neg-mul-176.9%
*-commutative76.9%
associate-/l*76.7%
distribute-neg-frac76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.6%
distribute-rgt-out76.6%
associate-/r*76.6%
metadata-eval76.6%
sub-neg76.6%
+-commutative76.6%
Simplified76.7%
Taylor expanded in c around 0 88.7%
+-commutative88.7%
mul-1-neg88.7%
unsub-neg88.7%
Simplified88.7%
Final simplification81.1%
(FPCore (a b c)
:precision binary64
(if (<= b -0.0003)
(/ c (- b))
(if (<= b 4.2e-36)
(* (+ b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.0003) {
tmp = c / -b;
} else if (b <= 4.2e-36) {
tmp = (b + sqrt((a * (c * -4.0)))) * (-0.5 / 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 <= (-0.0003d0)) then
tmp = c / -b
else if (b <= 4.2d-36) then
tmp = (b + sqrt((a * (c * (-4.0d0))))) * ((-0.5d0) / 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 <= -0.0003) {
tmp = c / -b;
} else if (b <= 4.2e-36) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.0003: tmp = c / -b elif b <= 4.2e-36: tmp = (b + math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.0003) tmp = Float64(c / Float64(-b)); elseif (b <= 4.2e-36) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) * Float64(-0.5 / 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 <= -0.0003) tmp = c / -b; elseif (b <= 4.2e-36) tmp = (b + sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.0003], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.2e-36], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0003:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-36}:\\
\;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.99999999999999974e-4Initial program 7.9%
div-sub6.5%
sub-neg6.5%
neg-mul-16.5%
*-commutative6.5%
associate-/l*6.7%
distribute-neg-frac6.7%
neg-mul-16.7%
*-commutative6.7%
associate-/l*6.6%
distribute-rgt-out7.9%
associate-/r*7.9%
metadata-eval7.9%
sub-neg7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around -inf 90.2%
mul-1-neg90.2%
distribute-neg-frac290.2%
Simplified90.2%
if -2.99999999999999974e-4 < b < 4.19999999999999982e-36Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.4%
distribute-neg-frac74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.3%
distribute-rgt-out74.3%
associate-/r*74.3%
metadata-eval74.3%
sub-neg74.3%
+-commutative74.3%
Simplified74.3%
associate-*l/74.4%
clear-num74.2%
*-commutative74.2%
pow274.2%
Applied egg-rr74.2%
pow1/274.2%
pow-to-exp69.6%
Applied egg-rr69.6%
Taylor expanded in c around inf 40.9%
mul-1-neg40.9%
unsub-neg40.9%
*-commutative40.9%
log-rec40.9%
Simplified40.9%
*-un-lft-identity40.9%
associate-/r/40.9%
Applied egg-rr66.6%
*-lft-identity66.6%
associate-*l/66.7%
*-lft-identity66.7%
associate-/l*66.6%
associate-*l*66.6%
*-commutative66.6%
Simplified66.6%
if 4.19999999999999982e-36 < b Initial program 76.9%
div-sub76.9%
sub-neg76.9%
neg-mul-176.9%
*-commutative76.9%
associate-/l*76.7%
distribute-neg-frac76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.6%
distribute-rgt-out76.6%
associate-/r*76.6%
metadata-eval76.6%
sub-neg76.6%
+-commutative76.6%
Simplified76.7%
Taylor expanded in c around 0 88.7%
+-commutative88.7%
mul-1-neg88.7%
unsub-neg88.7%
Simplified88.7%
Final simplification81.1%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 33.9%
div-sub33.1%
sub-neg33.1%
neg-mul-133.1%
*-commutative33.1%
associate-/l*33.1%
distribute-neg-frac33.1%
neg-mul-133.1%
*-commutative33.1%
associate-/l*33.0%
distribute-rgt-out33.8%
associate-/r*33.8%
metadata-eval33.8%
sub-neg33.8%
+-commutative33.8%
Simplified33.8%
Taylor expanded in b around -inf 61.6%
mul-1-neg61.6%
distribute-neg-frac261.6%
Simplified61.6%
if -3.999999999999988e-310 < b Initial program 77.2%
div-sub77.3%
sub-neg77.3%
neg-mul-177.3%
*-commutative77.3%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.0%
distribute-rgt-out77.0%
associate-/r*77.0%
metadata-eval77.0%
sub-neg77.0%
+-commutative77.0%
Simplified77.0%
Taylor expanded in c around 0 68.8%
+-commutative68.8%
mul-1-neg68.8%
unsub-neg68.8%
Simplified68.8%
Final simplification65.4%
(FPCore (a b c) :precision binary64 (if (<= b -4.5e-306) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-306) {
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 <= (-4.5d-306)) 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 <= -4.5e-306) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e-306: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-306) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.5e-306) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-306], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-306}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.50000000000000005e-306Initial program 33.6%
div-sub32.8%
sub-neg32.8%
neg-mul-132.8%
*-commutative32.8%
associate-/l*32.8%
distribute-neg-frac32.8%
neg-mul-132.8%
*-commutative32.8%
associate-/l*32.7%
distribute-rgt-out33.5%
associate-/r*33.5%
metadata-eval33.5%
sub-neg33.5%
+-commutative33.5%
Simplified33.5%
Taylor expanded in b around -inf 62.6%
mul-1-neg62.6%
distribute-neg-frac262.6%
Simplified62.6%
if -4.50000000000000005e-306 < b Initial program 76.9%
div-sub76.9%
sub-neg76.9%
neg-mul-176.9%
*-commutative76.9%
associate-/l*76.8%
distribute-neg-frac76.8%
neg-mul-176.8%
*-commutative76.8%
associate-/l*76.6%
distribute-rgt-out76.6%
associate-/r*76.6%
metadata-eval76.6%
sub-neg76.6%
+-commutative76.6%
Simplified76.7%
Taylor expanded in a around 0 67.2%
associate-*r/67.2%
mul-1-neg67.2%
Simplified67.2%
Final simplification65.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 56.6%
div-sub56.2%
sub-neg56.2%
neg-mul-156.2%
*-commutative56.2%
associate-/l*56.2%
distribute-neg-frac56.2%
neg-mul-156.2%
*-commutative56.2%
associate-/l*56.1%
distribute-rgt-out56.4%
associate-/r*56.4%
metadata-eval56.4%
sub-neg56.4%
+-commutative56.4%
Simplified56.4%
Taylor expanded in b around -inf 30.6%
mul-1-neg30.6%
distribute-neg-frac230.6%
Simplified30.6%
Final simplification30.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 56.6%
div-sub56.2%
sub-neg56.2%
neg-mul-156.2%
*-commutative56.2%
associate-/l*56.2%
distribute-neg-frac56.2%
neg-mul-156.2%
*-commutative56.2%
associate-/l*56.1%
distribute-rgt-out56.4%
associate-/r*56.4%
metadata-eval56.4%
sub-neg56.4%
+-commutative56.4%
Simplified56.4%
Taylor expanded in a around 0 35.8%
associate-/l*36.9%
Simplified36.9%
Taylor expanded in a around inf 10.2%
Final simplification10.2%
(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 2024089
(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)))