
(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 -2.6e-79)
(/ c (- b))
(if (<= b 3.35e+137)
(/ (- (- 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 <= -2.6e-79) {
tmp = c / -b;
} else if (b <= 3.35e+137) {
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 <= (-2.6d-79)) then
tmp = c / -b
else if (b <= 3.35d+137) 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 <= -2.6e-79) {
tmp = c / -b;
} else if (b <= 3.35e+137) {
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 <= -2.6e-79: tmp = c / -b elif b <= 3.35e+137: 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 <= -2.6e-79) tmp = Float64(c / Float64(-b)); elseif (b <= 3.35e+137) 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 <= -2.6e-79) tmp = c / -b; elseif (b <= 3.35e+137) 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, -2.6e-79], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.35e+137], 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 -2.6 \cdot 10^{-79}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.35 \cdot 10^{+137}:\\
\;\;\;\;\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 < -2.59999999999999994e-79Initial program 13.2%
div-sub12.8%
sub-neg12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*12.8%
distribute-neg-frac12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*12.8%
distribute-rgt-out13.2%
associate-/r*13.2%
metadata-eval13.2%
sub-neg13.2%
+-commutative13.2%
Simplified13.3%
Taylor expanded in b around -inf 86.3%
mul-1-neg86.3%
distribute-neg-frac286.3%
Simplified86.3%
if -2.59999999999999994e-79 < b < 3.3499999999999999e137Initial program 84.8%
if 3.3499999999999999e137 < b Initial program 48.8%
div-sub48.8%
sub-neg48.8%
neg-mul-148.8%
*-commutative48.8%
associate-/l*48.7%
distribute-neg-frac48.7%
neg-mul-148.7%
*-commutative48.7%
associate-/l*48.6%
distribute-rgt-out48.6%
associate-/r*48.6%
metadata-eval48.6%
sub-neg48.6%
+-commutative48.6%
Simplified48.7%
Taylor expanded in a around 0 98.3%
associate-*r/98.3%
mul-1-neg98.3%
Simplified98.3%
Final simplification88.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2e-78)
(/ c (- b))
(if (<= b 1.7e-102)
(/ (- (- 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 <= -2e-78) {
tmp = c / -b;
} else if (b <= 1.7e-102) {
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 <= (-2d-78)) then
tmp = c / -b
else if (b <= 1.7d-102) 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 <= -2e-78) {
tmp = c / -b;
} else if (b <= 1.7e-102) {
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 <= -2e-78: tmp = c / -b elif b <= 1.7e-102: 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 <= -2e-78) tmp = Float64(c / Float64(-b)); elseif (b <= 1.7e-102) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(c * 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 <= -2e-78) tmp = c / -b; elseif (b <= 1.7e-102) 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, -2e-78], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.7e-102], N[(N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $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 -2 \cdot 10^{-78}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-102}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2e-78Initial program 13.2%
div-sub12.8%
sub-neg12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*12.8%
distribute-neg-frac12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*12.8%
distribute-rgt-out13.2%
associate-/r*13.2%
metadata-eval13.2%
sub-neg13.2%
+-commutative13.2%
Simplified13.3%
Taylor expanded in b around -inf 86.3%
mul-1-neg86.3%
distribute-neg-frac286.3%
Simplified86.3%
if -2e-78 < b < 1.70000000000000006e-102Initial program 76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
associate-*r*76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in b around 0 75.6%
*-commutative75.6%
Simplified75.6%
if 1.70000000000000006e-102 < b Initial program 68.2%
div-sub68.2%
sub-neg68.2%
neg-mul-168.2%
*-commutative68.2%
associate-/l*68.1%
distribute-neg-frac68.1%
neg-mul-168.1%
*-commutative68.1%
associate-/l*68.0%
distribute-rgt-out68.0%
associate-/r*68.0%
metadata-eval68.0%
sub-neg68.0%
+-commutative68.0%
Simplified68.0%
Taylor expanded in c around 0 94.7%
+-commutative94.7%
mul-1-neg94.7%
unsub-neg94.7%
Simplified94.7%
Final simplification86.6%
(FPCore (a b c)
:precision binary64
(if (<= b -7.6e-78)
(/ c (- b))
(if (<= b 7.5e-103)
(* (/ -0.5 a) (+ b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-78) {
tmp = c / -b;
} else if (b <= 7.5e-103) {
tmp = (-0.5 / a) * (b + sqrt((a * (c * -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 <= (-7.6d-78)) then
tmp = c / -b
else if (b <= 7.5d-103) then
tmp = ((-0.5d0) / a) * (b + sqrt((a * (c * (-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 <= -7.6e-78) {
tmp = c / -b;
} else if (b <= 7.5e-103) {
tmp = (-0.5 / a) * (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.6e-78: tmp = c / -b elif b <= 7.5e-103: tmp = (-0.5 / a) * (b + math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.6e-78) tmp = Float64(c / Float64(-b)); elseif (b <= 7.5e-103) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(a * Float64(c * -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 <= -7.6e-78) tmp = c / -b; elseif (b <= 7.5e-103) tmp = (-0.5 / a) * (b + sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.6e-78], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7.5e-103], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.6 \cdot 10^{-78}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{-103}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -7.5999999999999998e-78Initial program 13.2%
div-sub12.8%
sub-neg12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*12.8%
distribute-neg-frac12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*12.8%
distribute-rgt-out13.2%
associate-/r*13.2%
metadata-eval13.2%
sub-neg13.2%
+-commutative13.2%
Simplified13.3%
Taylor expanded in b around -inf 86.3%
mul-1-neg86.3%
distribute-neg-frac286.3%
Simplified86.3%
if -7.5999999999999998e-78 < b < 7.5e-103Initial program 76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
associate-*r*76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in b around 0 75.6%
*-commutative75.6%
Simplified75.6%
*-un-lft-identity75.6%
*-commutative75.6%
times-frac75.6%
metadata-eval75.6%
add-sqr-sqrt55.5%
sqrt-unprod75.2%
sqr-neg75.2%
sqrt-prod19.5%
add-sqr-sqrt75.3%
associate-*l*75.3%
Applied egg-rr75.3%
metadata-eval75.3%
times-frac75.3%
*-lft-identity75.3%
*-commutative75.3%
Simplified75.3%
frac-2neg75.3%
div-inv75.1%
neg-sub075.1%
associate-+l-75.1%
neg-sub075.1%
add-sqr-sqrt55.6%
sqrt-unprod74.8%
sqr-neg74.8%
sqrt-prod20.1%
add-sqr-sqrt75.4%
associate-*r*75.4%
distribute-rgt-neg-in75.4%
metadata-eval75.4%
metadata-eval75.4%
div-inv75.4%
clear-num75.4%
Applied egg-rr75.4%
*-commutative75.4%
associate-*l*75.4%
Simplified75.4%
if 7.5e-103 < b Initial program 68.2%
div-sub68.2%
sub-neg68.2%
neg-mul-168.2%
*-commutative68.2%
associate-/l*68.1%
distribute-neg-frac68.1%
neg-mul-168.1%
*-commutative68.1%
associate-/l*68.0%
distribute-rgt-out68.0%
associate-/r*68.0%
metadata-eval68.0%
sub-neg68.0%
+-commutative68.0%
Simplified68.0%
Taylor expanded in c around 0 94.7%
+-commutative94.7%
mul-1-neg94.7%
unsub-neg94.7%
Simplified94.7%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 32.6%
div-sub32.3%
sub-neg32.3%
neg-mul-132.3%
*-commutative32.3%
associate-/l*32.3%
distribute-neg-frac32.3%
neg-mul-132.3%
*-commutative32.3%
associate-/l*32.2%
distribute-rgt-out32.5%
associate-/r*32.5%
metadata-eval32.5%
sub-neg32.5%
+-commutative32.5%
Simplified32.6%
Taylor expanded in b around -inf 64.5%
mul-1-neg64.5%
distribute-neg-frac264.5%
Simplified64.5%
if -1.999999999999994e-310 < b Initial program 68.4%
div-sub68.4%
sub-neg68.4%
neg-mul-168.4%
*-commutative68.4%
associate-/l*68.3%
distribute-neg-frac68.3%
neg-mul-168.3%
*-commutative68.3%
associate-/l*68.2%
distribute-rgt-out68.2%
associate-/r*68.2%
metadata-eval68.2%
sub-neg68.2%
+-commutative68.2%
Simplified68.2%
Taylor expanded in c around 0 81.1%
+-commutative81.1%
mul-1-neg81.1%
unsub-neg81.1%
Simplified81.1%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 32.6%
div-sub32.3%
sub-neg32.3%
neg-mul-132.3%
*-commutative32.3%
associate-/l*32.3%
distribute-neg-frac32.3%
neg-mul-132.3%
*-commutative32.3%
associate-/l*32.2%
distribute-rgt-out32.5%
associate-/r*32.5%
metadata-eval32.5%
sub-neg32.5%
+-commutative32.5%
Simplified32.6%
Taylor expanded in b around -inf 64.5%
mul-1-neg64.5%
distribute-neg-frac264.5%
Simplified64.5%
if -1.999999999999994e-310 < b Initial program 68.4%
div-sub68.4%
sub-neg68.4%
neg-mul-168.4%
*-commutative68.4%
associate-/l*68.3%
distribute-neg-frac68.3%
neg-mul-168.3%
*-commutative68.3%
associate-/l*68.2%
distribute-rgt-out68.2%
associate-/r*68.2%
metadata-eval68.2%
sub-neg68.2%
+-commutative68.2%
Simplified68.2%
Taylor expanded in a around 0 80.4%
associate-*r/80.4%
mul-1-neg80.4%
Simplified80.4%
Final simplification71.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 47.3%
div-sub47.1%
sub-neg47.1%
neg-mul-147.1%
*-commutative47.1%
associate-/l*47.1%
distribute-neg-frac47.1%
neg-mul-147.1%
*-commutative47.1%
associate-/l*47.0%
distribute-rgt-out47.2%
associate-/r*47.2%
metadata-eval47.2%
sub-neg47.2%
+-commutative47.2%
Simplified47.2%
Taylor expanded in b around -inf 39.0%
mul-1-neg39.0%
distribute-neg-frac239.0%
Simplified39.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 47.3%
div-sub47.1%
sub-neg47.1%
neg-mul-147.1%
*-commutative47.1%
associate-/l*47.1%
distribute-neg-frac47.1%
neg-mul-147.1%
*-commutative47.1%
associate-/l*47.0%
distribute-rgt-out47.2%
associate-/r*47.2%
metadata-eval47.2%
sub-neg47.2%
+-commutative47.2%
Simplified47.2%
Taylor expanded in a around 0 33.6%
+-commutative33.6%
mul-1-neg33.6%
sub-neg33.6%
associate-/l*34.4%
Simplified34.4%
Taylor expanded in a around inf 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 47.3%
div-sub47.1%
sub-neg47.1%
neg-mul-147.1%
*-commutative47.1%
associate-/l*47.1%
distribute-neg-frac47.1%
neg-mul-147.1%
*-commutative47.1%
associate-/l*47.0%
distribute-rgt-out47.2%
associate-/r*47.2%
metadata-eval47.2%
sub-neg47.2%
+-commutative47.2%
Simplified47.2%
Taylor expanded in a around 0 33.6%
+-commutative33.6%
mul-1-neg33.6%
sub-neg33.6%
associate-/l*34.4%
Simplified34.4%
*-commutative34.4%
fmm-def34.4%
add-sqr-sqrt1.2%
sqrt-unprod1.7%
sqr-neg1.7%
sqrt-prod0.6%
add-sqr-sqrt1.8%
Applied egg-rr1.8%
Taylor expanded in c around 0 2.5%
(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 2024191
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))