
(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 -3.6e-170)
(/ (- c) b)
(if (<= b 5.2e+103)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-170) {
tmp = -c / b;
} else if (b <= 5.2e+103) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * 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 <= (-3.6d-170)) then
tmp = -c / b
else if (b <= 5.2d+103) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * 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 <= -3.6e-170) {
tmp = -c / b;
} else if (b <= 5.2e+103) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e-170: tmp = -c / b elif b <= 5.2e+103: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e-170) tmp = Float64(Float64(-c) / b); elseif (b <= 5.2e+103) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * 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 <= -3.6e-170) tmp = -c / b; elseif (b <= 5.2e+103) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e-170], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.2e+103], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.6 \cdot 10^{-170}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{+103}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.6000000000000003e-170Initial program 22.5%
*-commutative22.5%
sqr-neg22.5%
*-commutative22.5%
sqr-neg22.5%
*-commutative22.5%
associate-*r*22.5%
*-commutative22.5%
Simplified22.5%
Taylor expanded in b around -inf 81.9%
mul-1-neg81.9%
distribute-neg-frac81.9%
Simplified81.9%
if -3.6000000000000003e-170 < b < 5.2000000000000003e103Initial program 86.2%
*-commutative86.2%
sqr-neg86.2%
*-commutative86.2%
sqr-neg86.2%
*-commutative86.2%
associate-*r*86.3%
*-commutative86.3%
Simplified86.3%
if 5.2000000000000003e103 < b Initial program 51.4%
*-commutative51.4%
sqr-neg51.4%
*-commutative51.4%
sqr-neg51.4%
*-commutative51.4%
associate-*r*51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in b around inf 96.9%
associate-*r/96.9%
mul-1-neg96.9%
Simplified96.9%
Final simplification87.1%
(FPCore (a b c)
:precision binary64
(if (<= b -3.6e-170)
(/ (- c) b)
(if (<= b 6e+103)
(/ (- (- 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 <= -3.6e-170) {
tmp = -c / b;
} else if (b <= 6e+103) {
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 <= (-3.6d-170)) then
tmp = -c / b
else if (b <= 6d+103) 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 <= -3.6e-170) {
tmp = -c / b;
} else if (b <= 6e+103) {
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 <= -3.6e-170: tmp = -c / b elif b <= 6e+103: 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 <= -3.6e-170) tmp = Float64(Float64(-c) / b); elseif (b <= 6e+103) 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 <= -3.6e-170) tmp = -c / b; elseif (b <= 6e+103) 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, -3.6e-170], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 6e+103], 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 -3.6 \cdot 10^{-170}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{+103}:\\
\;\;\;\;\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 < -3.6000000000000003e-170Initial program 22.5%
*-commutative22.5%
sqr-neg22.5%
*-commutative22.5%
sqr-neg22.5%
*-commutative22.5%
associate-*r*22.5%
*-commutative22.5%
Simplified22.5%
Taylor expanded in b around -inf 81.9%
mul-1-neg81.9%
distribute-neg-frac81.9%
Simplified81.9%
if -3.6000000000000003e-170 < b < 6e103Initial program 86.2%
if 6e103 < b Initial program 51.4%
*-commutative51.4%
sqr-neg51.4%
*-commutative51.4%
sqr-neg51.4%
*-commutative51.4%
associate-*r*51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in b around inf 96.9%
associate-*r/96.9%
mul-1-neg96.9%
Simplified96.9%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.6e-170)
(/ (- c) b)
(if (<= b 1.55e-142)
(/ (+ b (sqrt (* a (* c -4.0)))) (* a -2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-170) {
tmp = -c / b;
} else if (b <= 1.55e-142) {
tmp = (b + sqrt((a * (c * -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 <= (-3.6d-170)) then
tmp = -c / b
else if (b <= 1.55d-142) then
tmp = (b + sqrt((a * (c * (-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 <= -3.6e-170) {
tmp = -c / b;
} else if (b <= 1.55e-142) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e-170: tmp = -c / b elif b <= 1.55e-142: tmp = (b + math.sqrt((a * (c * -4.0)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e-170) tmp = Float64(Float64(-c) / b); elseif (b <= 1.55e-142) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -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 <= -3.6e-170) tmp = -c / b; elseif (b <= 1.55e-142) tmp = (b + sqrt((a * (c * -4.0)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e-170], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.55e-142], N[(N[(b + N[Sqrt[N[(a * N[(c * -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 -3.6 \cdot 10^{-170}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-142}:\\
\;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.6000000000000003e-170Initial program 22.5%
*-commutative22.5%
sqr-neg22.5%
*-commutative22.5%
sqr-neg22.5%
*-commutative22.5%
associate-*r*22.5%
*-commutative22.5%
Simplified22.5%
Taylor expanded in b around -inf 81.9%
mul-1-neg81.9%
distribute-neg-frac81.9%
Simplified81.9%
if -3.6000000000000003e-170 < b < 1.55e-142Initial program 75.5%
*-commutative75.5%
sqr-neg75.5%
*-commutative75.5%
sqr-neg75.5%
*-commutative75.5%
associate-*r*75.7%
*-commutative75.7%
Simplified75.7%
Taylor expanded in b around 0 74.8%
*-commutative74.8%
*-commutative74.8%
associate-*l*75.0%
Simplified75.0%
frac-2neg75.0%
div-inv74.5%
neg-sub074.5%
add-sqr-sqrt42.2%
sqrt-unprod74.0%
sqr-neg74.0%
sqrt-unprod31.6%
add-sqr-sqrt74.4%
associate-+l-74.4%
neg-sub074.4%
add-sqr-sqrt42.7%
sqrt-unprod74.4%
sqr-neg74.4%
sqrt-unprod32.3%
add-sqr-sqrt74.5%
associate-*r*74.4%
*-commutative74.4%
associate-*r*74.5%
distribute-rgt-neg-in74.5%
metadata-eval74.5%
Applied egg-rr74.5%
associate-*r/75.0%
*-rgt-identity75.0%
Simplified75.0%
if 1.55e-142 < b Initial program 72.3%
*-commutative72.3%
sqr-neg72.3%
*-commutative72.3%
sqr-neg72.3%
*-commutative72.3%
associate-*r*72.3%
*-commutative72.3%
Simplified72.3%
Taylor expanded in b around inf 85.6%
+-commutative85.6%
mul-1-neg85.6%
unsub-neg85.6%
Simplified85.6%
Final simplification82.0%
(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(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 <= -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 34.9%
*-commutative34.9%
sqr-neg34.9%
*-commutative34.9%
sqr-neg34.9%
*-commutative34.9%
associate-*r*35.0%
*-commutative35.0%
Simplified35.0%
Taylor expanded in b around -inf 65.0%
mul-1-neg65.0%
distribute-neg-frac65.0%
Simplified65.0%
if -4.999999999999985e-310 < b Initial program 73.0%
*-commutative73.0%
sqr-neg73.0%
*-commutative73.0%
sqr-neg73.0%
*-commutative73.0%
associate-*r*73.0%
*-commutative73.0%
Simplified73.0%
Taylor expanded in b around inf 72.8%
+-commutative72.8%
mul-1-neg72.8%
unsub-neg72.8%
Simplified72.8%
Final simplification69.0%
(FPCore (a b c) :precision binary64 (if (<= b -8e-89) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-89) {
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 <= (-8d-89)) 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 <= -8e-89) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-89: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e-89) 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 <= -8e-89) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-89], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-89}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.00000000000000031e-89Initial program 19.0%
*-commutative19.0%
sqr-neg19.0%
*-commutative19.0%
sqr-neg19.0%
*-commutative19.0%
associate-*r*19.0%
*-commutative19.0%
Simplified19.0%
Taylor expanded in b around -inf 67.0%
frac-2neg67.0%
distribute-rgt-neg-in67.0%
metadata-eval67.0%
distribute-frac-neg67.0%
add-sqr-sqrt37.4%
sqrt-unprod30.9%
swap-sqr30.9%
metadata-eval30.9%
metadata-eval30.9%
swap-sqr30.9%
sqrt-unprod13.2%
add-sqr-sqrt30.2%
*-commutative30.2%
times-frac30.2%
metadata-eval30.2%
associate-/l*30.4%
Applied egg-rr30.4%
mul-1-neg30.4%
remove-double-neg30.4%
associate-/l/30.3%
Simplified30.3%
Taylor expanded in a around 0 30.1%
if -8.00000000000000031e-89 < b Initial program 70.3%
*-commutative70.3%
sqr-neg70.3%
*-commutative70.3%
sqr-neg70.3%
*-commutative70.3%
associate-*r*70.3%
*-commutative70.3%
Simplified70.3%
Taylor expanded in b around inf 54.4%
associate-*r/54.4%
mul-1-neg54.4%
Simplified54.4%
Final simplification46.8%
(FPCore (a b c) :precision binary64 (if (<= b -4.5e-303) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-303) {
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-303)) 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-303) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e-303: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-303) 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 <= -4.5e-303) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-303], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-303}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.5000000000000001e-303Initial program 33.9%
*-commutative33.9%
sqr-neg33.9%
*-commutative33.9%
sqr-neg33.9%
*-commutative33.9%
associate-*r*33.9%
*-commutative33.9%
Simplified33.9%
Taylor expanded in b around -inf 66.0%
mul-1-neg66.0%
distribute-neg-frac66.0%
Simplified66.0%
if -4.5000000000000001e-303 < b Initial program 73.4%
*-commutative73.4%
sqr-neg73.4%
*-commutative73.4%
sqr-neg73.4%
*-commutative73.4%
associate-*r*73.5%
*-commutative73.5%
Simplified73.5%
Taylor expanded in b around inf 71.6%
associate-*r/71.6%
mul-1-neg71.6%
Simplified71.6%
Final simplification68.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 / 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 54.3%
*-commutative54.3%
sqr-neg54.3%
*-commutative54.3%
sqr-neg54.3%
*-commutative54.3%
associate-*r*54.3%
*-commutative54.3%
Simplified54.3%
Taylor expanded in b around -inf 23.7%
frac-2neg23.7%
distribute-rgt-neg-in23.7%
metadata-eval23.7%
distribute-frac-neg23.7%
add-sqr-sqrt13.0%
sqrt-unprod12.3%
swap-sqr12.3%
metadata-eval12.3%
metadata-eval12.3%
swap-sqr12.3%
sqrt-unprod5.0%
add-sqr-sqrt11.5%
*-commutative11.5%
times-frac11.5%
metadata-eval11.5%
associate-/l*11.5%
Applied egg-rr11.5%
mul-1-neg11.5%
remove-double-neg11.5%
associate-/l/11.4%
Simplified11.4%
Taylor expanded in a around 0 11.5%
Final simplification11.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 2023311
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(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)))