
(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 -6.2e-89)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 3e+61)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e-89) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 3e+61) {
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (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 <= (-6.2d-89)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 3d+61) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (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 <= -6.2e-89) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 3e+61) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.2e-89: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 3e+61: tmp = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.2e-89) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 3e+61) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / 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 <= -6.2e-89) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 3e+61) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.2e-89], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3e+61], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -6.2 \cdot 10^{-89}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{+61}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.19999999999999993e-89Initial program 17.9%
*-commutative17.9%
sqr-neg17.9%
*-commutative17.9%
sqr-neg17.9%
associate-*r*17.9%
*-commutative17.9%
Simplified17.9%
add-cbrt-cube13.0%
pow313.0%
Applied egg-rr22.3%
rem-cbrt-cube27.3%
clear-num27.2%
associate-*r*27.2%
*-commutative27.2%
associate-*r*27.2%
Applied egg-rr27.2%
Taylor expanded in b around -inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt82.8%
times-frac82.8%
metadata-eval82.8%
Simplified82.8%
if -6.19999999999999993e-89 < b < 3e61Initial program 82.1%
if 3e61 < b Initial program 54.7%
*-commutative54.7%
sqr-neg54.7%
*-commutative54.7%
sqr-neg54.7%
associate-*r*54.7%
*-commutative54.7%
Simplified54.7%
Taylor expanded in b around inf 92.4%
+-commutative92.4%
mul-1-neg92.4%
unsub-neg92.4%
Simplified92.4%
Final simplification84.8%
(FPCore (a b c)
:precision binary64
(if (<= b -7e-88)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 4.8e-99)
(/ (- (- 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 <= -7e-88) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 4.8e-99) {
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 <= (-7d-88)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 4.8d-99) 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 <= -7e-88) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 4.8e-99) {
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 <= -7e-88: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 4.8e-99: 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 <= -7e-88) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 4.8e-99) 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 <= -7e-88) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 4.8e-99) 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, -7e-88], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.8e-99], 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 -7 \cdot 10^{-88}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-99}:\\
\;\;\;\;\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 < -7.0000000000000002e-88Initial program 17.9%
*-commutative17.9%
sqr-neg17.9%
*-commutative17.9%
sqr-neg17.9%
associate-*r*17.9%
*-commutative17.9%
Simplified17.9%
add-cbrt-cube13.0%
pow313.0%
Applied egg-rr22.3%
rem-cbrt-cube27.3%
clear-num27.2%
associate-*r*27.2%
*-commutative27.2%
associate-*r*27.2%
Applied egg-rr27.2%
Taylor expanded in b around -inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt82.8%
times-frac82.8%
metadata-eval82.8%
Simplified82.8%
if -7.0000000000000002e-88 < b < 4.8000000000000001e-99Initial program 75.8%
*-commutative75.8%
sqr-neg75.8%
*-commutative75.8%
sqr-neg75.8%
associate-*r*75.8%
*-commutative75.8%
Simplified75.8%
Taylor expanded in b around 0 72.6%
*-commutative72.6%
*-commutative72.6%
associate-*r*72.6%
Simplified72.6%
if 4.8000000000000001e-99 < b Initial program 68.8%
*-commutative68.8%
sqr-neg68.8%
*-commutative68.8%
sqr-neg68.8%
associate-*r*68.8%
*-commutative68.8%
Simplified68.8%
Taylor expanded in b around inf 86.8%
+-commutative86.8%
mul-1-neg86.8%
unsub-neg86.8%
Simplified86.8%
Final simplification81.4%
(FPCore (a b c)
:precision binary64
(if (<= b -5.5e-88)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 4.7e-99)
(* -0.5 (/ (sqrt (* c (* a -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.5e-88) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 4.7e-99) {
tmp = -0.5 * (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 <= (-5.5d-88)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 4.7d-99) then
tmp = (-0.5d0) * (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 <= -5.5e-88) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 4.7e-99) {
tmp = -0.5 * (Math.sqrt((c * (a * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.5e-88: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 4.7e-99: tmp = -0.5 * (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 <= -5.5e-88) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 4.7e-99) tmp = Float64(-0.5 * Float64(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 <= -5.5e-88) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 4.7e-99) tmp = -0.5 * (sqrt((c * (a * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.5e-88], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.7e-99], N[(-0.5 * N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.5 \cdot 10^{-88}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 4.7 \cdot 10^{-99}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.49999999999999971e-88Initial program 17.9%
*-commutative17.9%
sqr-neg17.9%
*-commutative17.9%
sqr-neg17.9%
associate-*r*17.9%
*-commutative17.9%
Simplified17.9%
add-cbrt-cube13.0%
pow313.0%
Applied egg-rr22.3%
rem-cbrt-cube27.3%
clear-num27.2%
associate-*r*27.2%
*-commutative27.2%
associate-*r*27.2%
Applied egg-rr27.2%
Taylor expanded in b around -inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt82.8%
times-frac82.8%
metadata-eval82.8%
Simplified82.8%
if -5.49999999999999971e-88 < b < 4.69999999999999989e-99Initial program 75.8%
*-commutative75.8%
sqr-neg75.8%
*-commutative75.8%
sqr-neg75.8%
associate-*r*75.8%
*-commutative75.8%
Simplified75.8%
prod-diff75.5%
*-commutative75.5%
fma-def75.5%
associate-+l+75.5%
*-commutative75.5%
distribute-rgt-neg-in75.5%
fma-def75.5%
*-commutative75.5%
distribute-rgt-neg-in75.5%
metadata-eval75.5%
*-commutative75.5%
fma-udef75.5%
distribute-lft-neg-in75.5%
distribute-rgt-neg-in75.5%
fma-def75.5%
Applied egg-rr75.5%
Taylor expanded in b around 0 71.5%
associate-*l/71.5%
*-lft-identity71.5%
distribute-rgt-out71.8%
*-commutative71.8%
metadata-eval71.8%
associate-*r*71.8%
*-commutative71.8%
Simplified71.8%
if 4.69999999999999989e-99 < b Initial program 68.8%
*-commutative68.8%
sqr-neg68.8%
*-commutative68.8%
sqr-neg68.8%
associate-*r*68.8%
*-commutative68.8%
Simplified68.8%
Taylor expanded in b around inf 86.8%
+-commutative86.8%
mul-1-neg86.8%
unsub-neg86.8%
Simplified86.8%
Final simplification81.1%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ 1.0 (- (/ a b) (/ b c))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = 1.0 / ((a / b) - (b / c));
} 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 = 1.0d0 / ((a / b) - (b / c))
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 = 1.0 / ((a / b) - (b / c));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = 1.0 / ((a / b) - (b / c)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); 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 = 1.0 / ((a / b) - (b / c)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $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{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 35.1%
*-commutative35.1%
sqr-neg35.1%
*-commutative35.1%
sqr-neg35.1%
associate-*r*35.1%
*-commutative35.1%
Simplified35.1%
add-cbrt-cube15.6%
pow315.6%
Applied egg-rr22.2%
rem-cbrt-cube41.6%
clear-num41.7%
associate-*r*41.7%
*-commutative41.7%
associate-*r*41.7%
Applied egg-rr41.7%
Taylor expanded in b around -inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt63.6%
times-frac63.6%
metadata-eval63.6%
Simplified63.6%
if -9.999999999999969e-311 < b Initial program 70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
sqr-neg70.5%
associate-*r*70.5%
*-commutative70.5%
Simplified70.5%
Taylor expanded in b around inf 66.7%
+-commutative66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
Final simplification65.1%
(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 35.1%
*-commutative35.1%
sqr-neg35.1%
*-commutative35.1%
sqr-neg35.1%
associate-*r*35.1%
*-commutative35.1%
Simplified35.1%
Taylor expanded in b around -inf 63.5%
associate-*r/63.5%
neg-mul-163.5%
Simplified63.5%
if -9.999999999999969e-311 < b Initial program 70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
sqr-neg70.5%
associate-*r*70.5%
*-commutative70.5%
Simplified70.5%
Taylor expanded in b around inf 66.7%
+-commutative66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
Final simplification65.1%
(FPCore (a b c) :precision binary64 (if (<= b -5.2e+30) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e+30) {
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 <= (-5.2d+30)) 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 <= -5.2e+30) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e+30: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e+30) 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 <= -5.2e+30) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e+30], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{+30}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -5.19999999999999977e30Initial program 11.0%
*-commutative11.0%
sqr-neg11.0%
*-commutative11.0%
sqr-neg11.0%
associate-*r*11.0%
*-commutative11.0%
Simplified11.0%
Taylor expanded in b around inf 2.2%
Taylor expanded in b around 0 24.1%
if -5.19999999999999977e30 < b Initial program 68.4%
*-commutative68.4%
sqr-neg68.4%
*-commutative68.4%
sqr-neg68.4%
associate-*r*68.4%
*-commutative68.4%
Simplified68.4%
Taylor expanded in b around inf 46.2%
associate-*r/46.2%
mul-1-neg46.2%
Simplified46.2%
Final simplification40.1%
(FPCore (a b c) :precision binary64 (if (<= b -1.4e-302) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-302) {
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 <= (-1.4d-302)) 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 <= -1.4e-302) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e-302: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e-302) 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 <= -1.4e-302) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e-302], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{-302}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.4e-302Initial program 34.6%
*-commutative34.6%
sqr-neg34.6%
*-commutative34.6%
sqr-neg34.6%
associate-*r*34.6%
*-commutative34.6%
Simplified34.6%
Taylor expanded in b around -inf 64.0%
associate-*r/64.0%
neg-mul-164.0%
Simplified64.0%
if -1.4e-302 < b Initial program 70.7%
*-commutative70.7%
sqr-neg70.7%
*-commutative70.7%
sqr-neg70.7%
associate-*r*70.7%
*-commutative70.7%
Simplified70.7%
Taylor expanded in b around inf 65.9%
associate-*r/65.9%
mul-1-neg65.9%
Simplified65.9%
Final simplification64.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 52.5%
*-commutative52.5%
sqr-neg52.5%
*-commutative52.5%
sqr-neg52.5%
associate-*r*52.5%
*-commutative52.5%
Simplified52.5%
Taylor expanded in b around inf 32.7%
Taylor expanded in b around 0 8.9%
Final simplification8.9%
(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 2023271
(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)))