
(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 -4.5e-62)
(/ (- c) b)
(if (<= b 3.2e+94)
(/ (- (- 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 <= -4.5e-62) {
tmp = -c / b;
} else if (b <= 3.2e+94) {
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 <= (-4.5d-62)) then
tmp = -c / b
else if (b <= 3.2d+94) 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 <= -4.5e-62) {
tmp = -c / b;
} else if (b <= 3.2e+94) {
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 <= -4.5e-62: tmp = -c / b elif b <= 3.2e+94: 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 <= -4.5e-62) tmp = Float64(Float64(-c) / b); elseif (b <= 3.2e+94) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.5e-62) tmp = -c / b; elseif (b <= 3.2e+94) 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, -4.5e-62], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.2e+94], 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 -4.5 \cdot 10^{-62}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{+94}:\\
\;\;\;\;\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 < -4.50000000000000018e-62Initial program 16.5%
div-sub15.0%
sub-neg15.0%
neg-mul-115.0%
*-commutative15.0%
associate-/l*13.8%
distribute-neg-frac13.8%
neg-mul-113.8%
*-commutative13.8%
associate-/l*15.0%
distribute-rgt-out16.5%
associate-/r*16.5%
metadata-eval16.5%
sub-neg16.5%
+-commutative16.5%
Simplified16.5%
Taylor expanded in b around -inf 85.8%
associate-*r/85.8%
neg-mul-185.8%
Simplified85.8%
if -4.50000000000000018e-62 < b < 3.20000000000000014e94Initial program 81.0%
if 3.20000000000000014e94 < b Initial program 50.3%
div-sub50.3%
sub-neg50.3%
neg-mul-150.3%
*-commutative50.3%
associate-/l*50.3%
distribute-neg-frac50.3%
neg-mul-150.3%
*-commutative50.3%
associate-/l*50.2%
distribute-rgt-out50.2%
associate-/r*50.2%
metadata-eval50.2%
sub-neg50.2%
+-commutative50.2%
Simplified50.5%
Taylor expanded in a around 0 93.3%
associate-*r/93.3%
mul-1-neg93.3%
Simplified93.3%
Final simplification85.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-55)
(/ (- c) b)
(if (<= b 3.4e-50)
(* (/ -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 <= -1.25e-55) {
tmp = -c / b;
} else if (b <= 3.4e-50) {
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 <= (-1.25d-55)) then
tmp = -c / b
else if (b <= 3.4d-50) 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 <= -1.25e-55) {
tmp = -c / b;
} else if (b <= 3.4e-50) {
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 <= -1.25e-55: tmp = -c / b elif b <= 3.4e-50: 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 <= -1.25e-55) tmp = Float64(Float64(-c) / b); elseif (b <= 3.4e-50) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(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 <= -1.25e-55) tmp = -c / b; elseif (b <= 3.4e-50) 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, -1.25e-55], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.4e-50], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -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 -1.25 \cdot 10^{-55}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-50}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.25e-55Initial program 16.5%
div-sub15.0%
sub-neg15.0%
neg-mul-115.0%
*-commutative15.0%
associate-/l*13.8%
distribute-neg-frac13.8%
neg-mul-113.8%
*-commutative13.8%
associate-/l*15.0%
distribute-rgt-out16.5%
associate-/r*16.5%
metadata-eval16.5%
sub-neg16.5%
+-commutative16.5%
Simplified16.5%
Taylor expanded in b around -inf 85.8%
associate-*r/85.8%
neg-mul-185.8%
Simplified85.8%
if -1.25e-55 < b < 3.40000000000000014e-50Initial program 77.1%
div-sub77.1%
sub-neg77.1%
neg-mul-177.1%
*-commutative77.1%
associate-/l*77.1%
distribute-neg-frac77.1%
neg-mul-177.1%
*-commutative77.1%
associate-/l*77.0%
distribute-rgt-out77.0%
associate-/r*77.0%
metadata-eval77.0%
sub-neg77.0%
+-commutative77.0%
Simplified75.9%
Taylor expanded in a around inf 69.2%
metadata-eval69.2%
distribute-lft-neg-in69.2%
*-commutative69.2%
*-commutative69.2%
associate-*r*69.2%
distribute-rgt-neg-in69.2%
distribute-rgt-neg-in69.2%
metadata-eval69.2%
Simplified69.2%
if 3.40000000000000014e-50 < b Initial program 63.0%
div-sub63.0%
sub-neg63.0%
neg-mul-163.0%
*-commutative63.0%
associate-/l*63.0%
distribute-neg-frac63.0%
neg-mul-163.0%
*-commutative63.0%
associate-/l*62.9%
distribute-rgt-out62.9%
associate-/r*62.9%
metadata-eval62.9%
sub-neg62.9%
+-commutative62.9%
Simplified63.1%
Taylor expanded in c around 0 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
(FPCore (a b c) :precision binary64 (if (<= b -4.5e-143) (/ (- c) b) (if (<= b 2.3e-172) (* 0.5 (sqrt (* c (/ -4.0 a)))) (- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-143) {
tmp = -c / b;
} else if (b <= 2.3e-172) {
tmp = 0.5 * sqrt((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 <= (-4.5d-143)) then
tmp = -c / b
else if (b <= 2.3d-172) then
tmp = 0.5d0 * sqrt((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 <= -4.5e-143) {
tmp = -c / b;
} else if (b <= 2.3e-172) {
tmp = 0.5 * Math.sqrt((c * (-4.0 / a)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e-143: tmp = -c / b elif b <= 2.3e-172: tmp = 0.5 * math.sqrt((c * (-4.0 / a))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-143) tmp = Float64(Float64(-c) / b); elseif (b <= 2.3e-172) tmp = Float64(0.5 * sqrt(Float64(c * Float64(-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 <= -4.5e-143) tmp = -c / b; elseif (b <= 2.3e-172) tmp = 0.5 * sqrt((c * (-4.0 / a))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-143], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.3e-172], N[(0.5 * N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-143}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-172}:\\
\;\;\;\;0.5 \cdot \sqrt{c \cdot \frac{-4}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.5e-143Initial program 20.0%
div-sub18.6%
sub-neg18.6%
neg-mul-118.6%
*-commutative18.6%
associate-/l*17.5%
distribute-neg-frac17.5%
neg-mul-117.5%
*-commutative17.5%
associate-/l*18.6%
distribute-rgt-out20.0%
associate-/r*20.0%
metadata-eval20.0%
sub-neg20.0%
+-commutative20.0%
Simplified20.1%
Taylor expanded in b around -inf 82.5%
associate-*r/82.5%
neg-mul-182.5%
Simplified82.5%
if -4.5e-143 < b < 2.29999999999999995e-172Initial program 74.6%
add-cube-cbrt74.0%
pow373.9%
*-commutative73.9%
*-commutative73.9%
associate-*l*74.0%
Applied egg-rr74.0%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt36.2%
rem-cube-cbrt36.4%
Simplified36.4%
pow136.4%
add-sqr-sqrt0.6%
sqrt-unprod45.2%
mul-1-neg45.2%
mul-1-neg45.2%
sqr-neg45.2%
add-sqr-sqrt45.2%
associate-/l*45.2%
Applied egg-rr45.2%
unpow145.2%
Simplified45.2%
if 2.29999999999999995e-172 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.5%
distribute-neg-frac69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-rgt-out69.5%
associate-/r*69.5%
metadata-eval69.5%
sub-neg69.5%
+-commutative69.5%
Simplified69.6%
Taylor expanded in c around 0 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
Simplified74.9%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(Float64(-c) / 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 <= -1e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 31.2%
div-sub30.0%
sub-neg30.0%
neg-mul-130.0%
*-commutative30.0%
associate-/l*29.2%
distribute-neg-frac29.2%
neg-mul-129.2%
*-commutative29.2%
associate-/l*30.0%
distribute-rgt-out31.2%
associate-/r*31.2%
metadata-eval31.2%
sub-neg31.2%
+-commutative31.2%
Simplified30.5%
Taylor expanded in b around -inf 67.0%
associate-*r/67.0%
neg-mul-167.0%
Simplified67.0%
if -9.999999999999969e-311 < b Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-neg-frac70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/l*70.3%
distribute-rgt-out70.3%
associate-/r*70.3%
metadata-eval70.3%
sub-neg70.3%
+-commutative70.3%
Simplified70.5%
Taylor expanded in c around 0 65.1%
+-commutative65.1%
mul-1-neg65.1%
unsub-neg65.1%
Simplified65.1%
(FPCore (a b c) :precision binary64 (if (<= b -6e-289) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e-289) {
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 <= (-6d-289)) 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 <= -6e-289) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e-289: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e-289) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6e-289) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e-289], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{-289}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -5.9999999999999996e-289Initial program 30.3%
div-sub29.2%
sub-neg29.2%
neg-mul-129.2%
*-commutative29.2%
associate-/l*28.3%
distribute-neg-frac28.3%
neg-mul-128.3%
*-commutative28.3%
associate-/l*29.2%
distribute-rgt-out30.3%
associate-/r*30.3%
metadata-eval30.3%
sub-neg30.3%
+-commutative30.3%
Simplified29.6%
Taylor expanded in b around -inf 68.5%
associate-*r/68.5%
neg-mul-168.5%
Simplified68.5%
if -5.9999999999999996e-289 < b Initial program 70.3%
div-sub70.3%
sub-neg70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/l*70.3%
distribute-neg-frac70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/l*70.2%
distribute-rgt-out70.2%
associate-/r*70.2%
metadata-eval70.2%
sub-neg70.2%
+-commutative70.2%
Simplified70.4%
Taylor expanded in a around 0 62.8%
associate-*r/62.8%
mul-1-neg62.8%
Simplified62.8%
(FPCore (a b c) :precision binary64 (if (<= b -4.8e-28) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-28) {
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.8d-28)) 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.8e-28) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.8e-28: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.8e-28) tmp = Float64(c / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.8e-28) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.8e-28], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{-28}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.8000000000000004e-28Initial program 17.3%
add-cube-cbrt17.2%
pow317.2%
*-commutative17.2%
*-commutative17.2%
associate-*l*17.2%
Applied egg-rr17.2%
Taylor expanded in c around 0 2.3%
neg-mul-12.3%
distribute-frac-neg2.3%
+-commutative2.3%
distribute-frac-neg2.3%
unsub-neg2.3%
rem-cube-cbrt2.3%
associate-/l*2.3%
Simplified2.3%
Taylor expanded in c around inf 26.9%
if -4.8000000000000004e-28 < b Initial program 68.3%
div-sub68.3%
sub-neg68.3%
neg-mul-168.3%
*-commutative68.3%
associate-/l*68.2%
distribute-neg-frac68.2%
neg-mul-168.2%
*-commutative68.2%
associate-/l*68.2%
distribute-rgt-out68.2%
associate-/r*68.2%
metadata-eval68.2%
sub-neg68.2%
+-commutative68.2%
Simplified67.7%
Taylor expanded in a around 0 49.1%
associate-*r/49.1%
mul-1-neg49.1%
Simplified49.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 50.3%
add-cube-cbrt50.1%
pow350.1%
*-commutative50.1%
*-commutative50.1%
associate-*l*50.1%
Applied egg-rr50.1%
Taylor expanded in c around 0 32.8%
neg-mul-132.8%
distribute-frac-neg32.8%
+-commutative32.8%
distribute-frac-neg32.8%
unsub-neg32.8%
rem-cube-cbrt32.8%
associate-/l*32.8%
Simplified32.8%
Taylor expanded in c around inf 11.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 2024150
(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)))