
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -2e+155)
(- (/ c b) (/ b a))
(if (<= b 5.2e-70)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+155) {
tmp = (c / b) - (b / a);
} else if (b <= 5.2e-70) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2e+155) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.2e-70) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2e+155], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.2e-70], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+155}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-70}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.00000000000000001e155Initial program 33.5%
*-commutative33.5%
Simplified33.5%
Taylor expanded in b around -inf 95.5%
+-commutative95.5%
mul-1-neg95.5%
unsub-neg95.5%
Simplified95.5%
if -2.00000000000000001e155 < b < 5.20000000000000004e-70Initial program 85.4%
Simplified85.5%
if 5.20000000000000004e-70 < b Initial program 18.4%
*-commutative18.4%
Simplified18.4%
Taylor expanded in b around inf 88.9%
mul-1-neg88.9%
distribute-neg-frac88.9%
Simplified88.9%
Final simplification88.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1e+153)
(- (/ c b) (/ b a))
(if (<= b 1.1e-69)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = (c / b) - (b / a);
} else if (b <= 1.1e-69) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
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+153)) then
tmp = (c / b) - (b / a)
else if (b <= 1.1d-69) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = (c / b) - (b / a);
} else if (b <= 1.1e-69) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+153: tmp = (c / b) - (b / a) elif b <= 1.1e-69: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+153) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.1e-69) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+153) tmp = (c / b) - (b / a); elseif (b <= 1.1e-69) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+153], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.1e-69], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{-69}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1e153Initial program 33.5%
*-commutative33.5%
Simplified33.5%
Taylor expanded in b around -inf 95.5%
+-commutative95.5%
mul-1-neg95.5%
unsub-neg95.5%
Simplified95.5%
if -1e153 < b < 1.1e-69Initial program 85.4%
if 1.1e-69 < b Initial program 18.4%
*-commutative18.4%
Simplified18.4%
Taylor expanded in b around inf 88.9%
mul-1-neg88.9%
distribute-neg-frac88.9%
Simplified88.9%
Final simplification88.2%
(FPCore (a b c)
:precision binary64
(if (<= b -5.1e-76)
(- (/ c b) (/ b a))
(if (<= b 1.6e-70)
(/ 1.0 (/ (/ a 0.5) (- (sqrt (* a (* c -4.0))) b)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.1e-76) {
tmp = (c / b) - (b / a);
} else if (b <= 1.6e-70) {
tmp = 1.0 / ((a / 0.5) / (sqrt((a * (c * -4.0))) - b));
} else {
tmp = -c / b;
}
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.1d-76)) then
tmp = (c / b) - (b / a)
else if (b <= 1.6d-70) then
tmp = 1.0d0 / ((a / 0.5d0) / (sqrt((a * (c * (-4.0d0)))) - b))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.1e-76) {
tmp = (c / b) - (b / a);
} else if (b <= 1.6e-70) {
tmp = 1.0 / ((a / 0.5) / (Math.sqrt((a * (c * -4.0))) - b));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.1e-76: tmp = (c / b) - (b / a) elif b <= 1.6e-70: tmp = 1.0 / ((a / 0.5) / (math.sqrt((a * (c * -4.0))) - b)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.1e-76) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.6e-70) tmp = Float64(1.0 / Float64(Float64(a / 0.5) / Float64(sqrt(Float64(a * Float64(c * -4.0))) - b))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.1e-76) tmp = (c / b) - (b / a); elseif (b <= 1.6e-70) tmp = 1.0 / ((a / 0.5) / (sqrt((a * (c * -4.0))) - b)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.1e-76], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.6e-70], N[(1.0 / N[(N[(a / 0.5), $MachinePrecision] / N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.1 \cdot 10^{-76}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-70}:\\
\;\;\;\;\frac{1}{\frac{\frac{a}{0.5}}{\sqrt{a \cdot \left(c \cdot -4\right)} - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.09999999999999986e-76Initial program 70.3%
*-commutative70.3%
Simplified70.3%
Taylor expanded in b around -inf 86.2%
+-commutative86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
if -5.09999999999999986e-76 < b < 1.5999999999999999e-70Initial program 76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in b around 0 76.7%
associate-*r*76.7%
fma-def76.7%
*-commutative76.7%
Simplified76.7%
clear-num76.7%
inv-pow76.7%
neg-mul-176.7%
fma-def76.7%
Applied egg-rr76.7%
unpow-176.7%
associate-/l*76.7%
Simplified76.7%
*-un-lft-identity76.7%
div-inv76.7%
metadata-eval76.7%
times-frac76.4%
*-un-lft-identity76.4%
fma-udef76.4%
*-un-lft-identity76.4%
associate-*r*76.4%
fma-udef76.4%
Applied egg-rr76.4%
associate-*l/76.7%
*-lft-identity76.7%
fma-udef76.7%
neg-mul-176.7%
+-commutative76.7%
sub-neg76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in a around inf 70.2%
*-commutative70.1%
associate-*r*70.1%
Simplified70.2%
if 1.5999999999999999e-70 < b Initial program 18.4%
*-commutative18.4%
Simplified18.4%
Taylor expanded in b around inf 88.9%
mul-1-neg88.9%
distribute-neg-frac88.9%
Simplified88.9%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.45e-76)
(- (/ c b) (/ b a))
(if (<= b 3.7e-70)
(* (- (sqrt (* a (* c -4.0))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-76) {
tmp = (c / b) - (b / a);
} else if (b <= 3.7e-70) {
tmp = (sqrt((a * (c * -4.0))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
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.45d-76)) then
tmp = (c / b) - (b / a)
else if (b <= 3.7d-70) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) * (0.5d0 / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-76) {
tmp = (c / b) - (b / a);
} else if (b <= 3.7e-70) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-76: tmp = (c / b) - (b / a) elif b <= 3.7e-70: tmp = (math.sqrt((a * (c * -4.0))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-76) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.7e-70) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.45e-76) tmp = (c / b) - (b / a); elseif (b <= 3.7e-70) tmp = (sqrt((a * (c * -4.0))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-76], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.7e-70], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-76}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.7 \cdot 10^{-70}:\\
\;\;\;\;\left(\sqrt{a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.4500000000000001e-76Initial program 70.3%
*-commutative70.3%
Simplified70.3%
Taylor expanded in b around -inf 86.2%
+-commutative86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
if -1.4500000000000001e-76 < b < 3.7e-70Initial program 76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in b around 0 76.7%
associate-*r*76.7%
fma-def76.7%
*-commutative76.7%
Simplified76.7%
+-commutative76.7%
*-un-lft-identity76.7%
fma-def76.7%
Applied egg-rr76.7%
fma-udef76.7%
*-lft-identity76.7%
unsub-neg76.7%
fma-def76.7%
associate-*l*76.7%
fma-def76.7%
Simplified76.7%
div-sub76.6%
sub-neg76.6%
*-un-lft-identity76.6%
*-commutative76.6%
times-frac76.6%
metadata-eval76.6%
Applied egg-rr76.6%
sub-neg76.6%
*-commutative76.6%
metadata-eval76.6%
times-frac76.6%
*-rgt-identity76.6%
div-sub76.7%
*-lft-identity76.7%
*-lft-identity76.7%
sub-neg76.7%
+-commutative76.7%
neg-mul-176.7%
fma-udef76.7%
*-lft-identity76.7%
*-commutative76.7%
times-frac76.7%
Simplified76.6%
Taylor expanded in a around inf 70.1%
*-commutative70.1%
associate-*r*70.1%
Simplified70.1%
if 3.7e-70 < b Initial program 18.4%
*-commutative18.4%
Simplified18.4%
Taylor expanded in b around inf 88.9%
mul-1-neg88.9%
distribute-neg-frac88.9%
Simplified88.9%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -8e-76)
(- (/ c b) (/ b a))
(if (<= b 1.08e-69)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-76) {
tmp = (c / b) - (b / a);
} else if (b <= 1.08e-69) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
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-76)) then
tmp = (c / b) - (b / a)
else if (b <= 1.08d-69) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8e-76) {
tmp = (c / b) - (b / a);
} else if (b <= 1.08e-69) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-76: tmp = (c / b) - (b / a) elif b <= 1.08e-69: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e-76) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.08e-69) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8e-76) tmp = (c / b) - (b / a); elseif (b <= 1.08e-69) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-76], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.08e-69], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-76}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{-69}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.99999999999999942e-76Initial program 70.3%
*-commutative70.3%
Simplified70.3%
Taylor expanded in b around -inf 86.2%
+-commutative86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
if -7.99999999999999942e-76 < b < 1.0800000000000001e-69Initial program 76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in b around 0 76.7%
associate-*r*76.7%
fma-def76.7%
*-commutative76.7%
Simplified76.7%
+-commutative76.7%
*-un-lft-identity76.7%
fma-def76.7%
Applied egg-rr76.7%
fma-udef76.7%
*-lft-identity76.7%
unsub-neg76.7%
fma-def76.7%
associate-*l*76.7%
fma-def76.7%
Simplified76.7%
Taylor expanded in a around inf 70.2%
associate-*r*70.2%
*-commutative70.2%
associate-*l*70.2%
*-commutative70.2%
Simplified70.2%
if 1.0800000000000001e-69 < b Initial program 18.4%
*-commutative18.4%
Simplified18.4%
Taylor expanded in b around inf 88.9%
mul-1-neg88.9%
distribute-neg-frac88.9%
Simplified88.9%
Final simplification82.3%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
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) - (b / a)
else
tmp = -c / b
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) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in b around -inf 66.4%
+-commutative66.4%
mul-1-neg66.4%
unsub-neg66.4%
Simplified66.4%
if -4.999999999999985e-310 < b Initial program 35.3%
*-commutative35.3%
Simplified35.3%
Taylor expanded in b around inf 66.9%
mul-1-neg66.9%
distribute-neg-frac66.9%
Simplified66.9%
Final simplification66.7%
(FPCore (a b c) :precision binary64 (if (<= b -1.2e-303) (/ (- b) a) (/ 0.0 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-303) {
tmp = -b / a;
} else {
tmp = 0.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) :: tmp
if (b <= (-1.2d-303)) then
tmp = -b / a
else
tmp = 0.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-303) {
tmp = -b / a;
} else {
tmp = 0.0 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-303: tmp = -b / a else: tmp = 0.0 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e-303) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.2e-303) tmp = -b / a; else tmp = 0.0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e-303], N[((-b) / a), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{-303}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\
\end{array}
\end{array}
if b < -1.2e-303Initial program 73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in b around -inf 67.8%
associate-*r/67.8%
mul-1-neg67.8%
Simplified67.8%
if -1.2e-303 < b Initial program 36.6%
*-commutative36.6%
Simplified36.6%
Taylor expanded in b around 0 36.6%
associate-*r*36.6%
fma-def36.6%
*-commutative36.6%
Simplified36.6%
clear-num36.6%
inv-pow36.6%
neg-mul-136.6%
fma-def36.6%
Applied egg-rr36.6%
unpow-136.6%
associate-/l*36.6%
Simplified36.6%
Taylor expanded in a around 0 18.8%
associate-*r/18.8%
distribute-rgt1-in18.8%
metadata-eval18.8%
mul0-lft18.8%
metadata-eval18.8%
Simplified18.8%
Final simplification42.7%
(FPCore (a b c) :precision binary64 (if (<= b 4.2e-256) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.2e-256) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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.2d-256) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 4.2e-256) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.2e-256: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.2e-256) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 4.2e-256) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.2e-256], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.2 \cdot 10^{-256}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 4.20000000000000005e-256Initial program 73.3%
*-commutative73.3%
Simplified73.3%
Taylor expanded in b around -inf 62.7%
associate-*r/62.7%
mul-1-neg62.7%
Simplified62.7%
if 4.20000000000000005e-256 < b Initial program 33.2%
*-commutative33.2%
Simplified33.2%
Taylor expanded in b around inf 70.6%
mul-1-neg70.6%
distribute-neg-frac70.6%
Simplified70.6%
Final simplification66.4%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 54.5%
*-commutative54.5%
Simplified54.5%
Taylor expanded in b around 0 54.5%
associate-*r*54.5%
fma-def54.6%
*-commutative54.6%
Simplified54.6%
clear-num54.5%
inv-pow54.5%
neg-mul-154.5%
fma-def54.5%
Applied egg-rr54.5%
unpow-154.5%
associate-/l*54.5%
Simplified54.5%
Taylor expanded in a around 0 10.9%
associate-*r/10.9%
distribute-rgt1-in10.9%
metadata-eval10.9%
mul0-lft10.9%
metadata-eval10.9%
Simplified10.9%
Final simplification10.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023314
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))