
(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 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(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 -1.4e+154)
(/ (- b) a)
(if (<= b 7e-136)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ -1.0 (- (/ b c) (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e+154) {
tmp = -b / a;
} else if (b <= 7e-136) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -1.0 / ((b / c) - (a / 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.4d+154)) then
tmp = -b / a
else if (b <= 7d-136) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = (-1.0d0) / ((b / c) - (a / b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e+154) {
tmp = -b / a;
} else if (b <= 7e-136) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -1.0 / ((b / c) - (a / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e+154: tmp = -b / a elif b <= 7e-136: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = -1.0 / ((b / c) - (a / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e+154) tmp = Float64(Float64(-b) / a); elseif (b <= 7e-136) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.4e+154) tmp = -b / a; elseif (b <= 7e-136) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = -1.0 / ((b / c) - (a / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 7e-136], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-136}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b}{c} - \frac{a}{b}}\\
\end{array}
\end{array}
if b < -1.4e154Initial program 44.8%
*-commutative44.8%
Simplified44.8%
Taylor expanded in b around -inf 97.8%
associate-*r/97.8%
mul-1-neg97.8%
Simplified97.8%
if -1.4e154 < b < 7.00000000000000058e-136Initial program 91.0%
if 7.00000000000000058e-136 < b Initial program 26.3%
*-commutative26.3%
Simplified26.3%
Applied egg-rr30.0%
unpow-130.0%
Simplified30.0%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt77.0%
metadata-eval77.0%
Simplified77.0%
frac-2neg77.0%
metadata-eval77.0%
div-inv77.0%
distribute-neg-in77.0%
add-sqr-sqrt41.2%
sqrt-unprod40.3%
mul-1-neg40.3%
mul-1-neg40.3%
sqr-neg40.3%
sqrt-unprod12.0%
add-sqr-sqrt23.6%
mul-1-neg23.6%
sub-neg23.6%
Applied egg-rr77.0%
associate-*r/77.0%
metadata-eval77.0%
Simplified77.0%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -3.2e-146)
(/ (- b) a)
(if (<= b 6.6e-136)
(* (- (sqrt (* c (* a -4.0))) b) (/ 0.5 a))
(/ -1.0 (- (/ b c) (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-146) {
tmp = -b / a;
} else if (b <= 6.6e-136) {
tmp = (sqrt((c * (a * -4.0))) - b) * (0.5 / a);
} else {
tmp = -1.0 / ((b / c) - (a / 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 <= (-3.2d-146)) then
tmp = -b / a
else if (b <= 6.6d-136) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) * (0.5d0 / a)
else
tmp = (-1.0d0) / ((b / c) - (a / b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-146) {
tmp = -b / a;
} else if (b <= 6.6e-136) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) * (0.5 / a);
} else {
tmp = -1.0 / ((b / c) - (a / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-146: tmp = -b / a elif b <= 6.6e-136: tmp = (math.sqrt((c * (a * -4.0))) - b) * (0.5 / a) else: tmp = -1.0 / ((b / c) - (a / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-146) tmp = Float64(Float64(-b) / a); elseif (b <= 6.6e-136) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) * Float64(0.5 / a)); else tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.2e-146) tmp = -b / a; elseif (b <= 6.6e-136) tmp = (sqrt((c * (a * -4.0))) - b) * (0.5 / a); else tmp = -1.0 / ((b / c) - (a / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-146], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 6.6e-136], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-146}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 6.6 \cdot 10^{-136}:\\
\;\;\;\;\left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b}{c} - \frac{a}{b}}\\
\end{array}
\end{array}
if b < -3.1999999999999999e-146Initial program 76.0%
*-commutative76.0%
Simplified76.0%
Taylor expanded in b around -inf 84.7%
associate-*r/84.7%
mul-1-neg84.7%
Simplified84.7%
if -3.1999999999999999e-146 < b < 6.60000000000000035e-136Initial program 83.5%
*-commutative83.5%
Simplified83.5%
Taylor expanded in b around 0 83.5%
*-commutative83.5%
associate-*r*83.5%
Simplified83.5%
+-commutative83.5%
unsub-neg83.5%
Applied egg-rr83.5%
expm1-log1p-u58.2%
expm1-udef20.1%
*-un-lft-identity20.1%
*-commutative20.1%
times-frac20.1%
metadata-eval20.1%
Applied egg-rr20.1%
expm1-def58.2%
expm1-log1p83.5%
*-commutative83.5%
associate-*l/83.5%
*-lft-identity83.5%
times-frac83.4%
Simplified83.4%
if 6.60000000000000035e-136 < b Initial program 26.3%
*-commutative26.3%
Simplified26.3%
Applied egg-rr30.0%
unpow-130.0%
Simplified30.0%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt77.0%
metadata-eval77.0%
Simplified77.0%
frac-2neg77.0%
metadata-eval77.0%
div-inv77.0%
distribute-neg-in77.0%
add-sqr-sqrt41.2%
sqrt-unprod40.3%
mul-1-neg40.3%
mul-1-neg40.3%
sqr-neg40.3%
sqrt-unprod12.0%
add-sqr-sqrt23.6%
mul-1-neg23.6%
sub-neg23.6%
Applied egg-rr77.0%
associate-*r/77.0%
metadata-eval77.0%
Simplified77.0%
Final simplification81.2%
(FPCore (a b c)
:precision binary64
(if (<= b -3.2e-146)
(/ (- b) a)
(if (<= b 6.6e-136)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ -1.0 (- (/ b c) (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-146) {
tmp = -b / a;
} else if (b <= 6.6e-136) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -1.0 / ((b / c) - (a / 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 <= (-3.2d-146)) then
tmp = -b / a
else if (b <= 6.6d-136) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = (-1.0d0) / ((b / c) - (a / b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-146) {
tmp = -b / a;
} else if (b <= 6.6e-136) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -1.0 / ((b / c) - (a / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-146: tmp = -b / a elif b <= 6.6e-136: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -1.0 / ((b / c) - (a / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-146) tmp = Float64(Float64(-b) / a); elseif (b <= 6.6e-136) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.2e-146) tmp = -b / a; elseif (b <= 6.6e-136) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -1.0 / ((b / c) - (a / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-146], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 6.6e-136], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-146}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 6.6 \cdot 10^{-136}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b}{c} - \frac{a}{b}}\\
\end{array}
\end{array}
if b < -3.1999999999999999e-146Initial program 76.0%
*-commutative76.0%
Simplified76.0%
Taylor expanded in b around -inf 84.7%
associate-*r/84.7%
mul-1-neg84.7%
Simplified84.7%
if -3.1999999999999999e-146 < b < 6.60000000000000035e-136Initial program 83.5%
*-commutative83.5%
Simplified83.5%
Taylor expanded in b around 0 83.5%
*-commutative83.5%
associate-*r*83.5%
Simplified83.5%
+-commutative83.5%
unsub-neg83.5%
Applied egg-rr83.5%
if 6.60000000000000035e-136 < b Initial program 26.3%
*-commutative26.3%
Simplified26.3%
Applied egg-rr30.0%
unpow-130.0%
Simplified30.0%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt77.0%
metadata-eval77.0%
Simplified77.0%
frac-2neg77.0%
metadata-eval77.0%
div-inv77.0%
distribute-neg-in77.0%
add-sqr-sqrt41.2%
sqrt-unprod40.3%
mul-1-neg40.3%
mul-1-neg40.3%
sqr-neg40.3%
sqrt-unprod12.0%
add-sqr-sqrt23.6%
mul-1-neg23.6%
sub-neg23.6%
Applied egg-rr77.0%
associate-*r/77.0%
metadata-eval77.0%
Simplified77.0%
Final simplification81.3%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ -1.0 (- (/ b c) (/ a b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -1.0 / ((b / c) - (a / 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 <= (-2d-310)) then
tmp = (c / b) - (b / a)
else
tmp = (-1.0d0) / ((b / c) - (a / b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -1.0 / ((b / c) - (a / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -1.0 / ((b / c) - (a / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = (c / b) - (b / a); else tmp = -1.0 / ((b / c) - (a / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b}{c} - \frac{a}{b}}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 78.6%
*-commutative78.6%
Simplified78.6%
Taylor expanded in b around -inf 71.9%
+-commutative71.9%
mul-1-neg71.9%
unsub-neg71.9%
Simplified71.9%
if -1.999999999999994e-310 < b Initial program 36.4%
*-commutative36.4%
Simplified36.4%
Applied egg-rr39.3%
unpow-139.3%
Simplified39.3%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt64.1%
metadata-eval64.1%
Simplified64.1%
frac-2neg64.1%
metadata-eval64.1%
div-inv64.1%
distribute-neg-in64.1%
add-sqr-sqrt34.5%
sqrt-unprod34.0%
mul-1-neg34.0%
mul-1-neg34.0%
sqr-neg34.0%
sqrt-unprod10.1%
add-sqr-sqrt19.8%
mul-1-neg19.8%
sub-neg19.8%
Applied egg-rr64.1%
associate-*r/64.1%
metadata-eval64.1%
Simplified64.1%
Final simplification67.9%
(FPCore (a b c) :precision binary64 (if (<= b 4.6e+15) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.6e+15) {
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.6d+15) 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.6e+15) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.6e+15: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.6e+15) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 4.6e+15) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.6e+15], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.6 \cdot 10^{+15}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 4.6e15Initial program 71.9%
*-commutative71.9%
Simplified71.9%
Taylor expanded in b around -inf 50.2%
associate-*r/50.2%
mul-1-neg50.2%
Simplified50.2%
if 4.6e15 < b Initial program 20.6%
*-commutative20.6%
Simplified20.6%
Taylor expanded in b around inf 69.2%
associate-/l*74.8%
Simplified74.8%
add-log-exp32.1%
*-commutative32.1%
times-frac32.1%
metadata-eval32.1%
div-inv32.1%
clear-num32.1%
Applied egg-rr32.1%
rem-log-exp75.4%
add-sqr-sqrt55.2%
sqrt-unprod48.3%
mul-1-neg48.3%
mul-1-neg48.3%
sqr-neg48.3%
sqrt-unprod30.1%
add-sqr-sqrt30.8%
div-inv30.8%
clear-num30.8%
un-div-inv30.8%
Applied egg-rr30.8%
Taylor expanded in a around 0 30.5%
Final simplification44.5%
(FPCore (a b c) :precision binary64 (if (<= b 5e-304) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 5e-304) {
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 <= 5d-304) 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 <= 5e-304) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5e-304: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5e-304) 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 <= 5e-304) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5e-304], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5 \cdot 10^{-304}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 4.99999999999999965e-304Initial program 78.0%
*-commutative78.0%
Simplified78.0%
Taylor expanded in b around -inf 71.3%
associate-*r/71.3%
mul-1-neg71.3%
Simplified71.3%
if 4.99999999999999965e-304 < b Initial program 36.7%
*-commutative36.7%
Simplified36.7%
Taylor expanded in b around inf 64.4%
mul-1-neg64.4%
distribute-neg-frac64.4%
Simplified64.4%
Final simplification67.8%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 56.8%
*-commutative56.8%
Simplified56.8%
Applied egg-rr53.4%
unpow-153.4%
Simplified53.4%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt34.4%
metadata-eval34.4%
Simplified34.4%
Taylor expanded in b around 0 2.7%
Final simplification2.7%
(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 56.8%
*-commutative56.8%
Simplified56.8%
Taylor expanded in b around inf 26.3%
associate-/l*28.5%
Simplified28.5%
add-log-exp13.1%
*-commutative13.1%
times-frac13.1%
metadata-eval13.1%
div-inv13.1%
clear-num13.1%
Applied egg-rr13.1%
rem-log-exp28.7%
add-sqr-sqrt20.0%
sqrt-unprod17.9%
mul-1-neg17.9%
mul-1-neg17.9%
sqr-neg17.9%
sqrt-unprod9.8%
add-sqr-sqrt11.1%
div-inv11.1%
clear-num11.1%
un-div-inv11.1%
Applied egg-rr11.1%
Taylor expanded in a around 0 11.0%
Final simplification11.0%
herbie shell --seed 2023325
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))