
(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 -8.5e+154)
(/ (- b) a)
(if (<= b -5.2e-250)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(if (<= b 6.5e-42)
(* (* a (/ -2.0 a)) (/ c (+ b (hypot b (sqrt (* a (* c -4.0)))))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e+154) {
tmp = -b / a;
} else if (b <= -5.2e-250) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else if (b <= 6.5e-42) {
tmp = (a * (-2.0 / a)) * (c / (b + hypot(b, sqrt((a * (c * -4.0))))));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e+154) {
tmp = -b / a;
} else if (b <= -5.2e-250) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else if (b <= 6.5e-42) {
tmp = (a * (-2.0 / a)) * (c / (b + Math.hypot(b, Math.sqrt((a * (c * -4.0))))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e+154: tmp = -b / a elif b <= -5.2e-250: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) elif b <= 6.5e-42: tmp = (a * (-2.0 / a)) * (c / (b + math.hypot(b, math.sqrt((a * (c * -4.0)))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e+154) tmp = Float64(Float64(-b) / a); elseif (b <= -5.2e-250) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); elseif (b <= 6.5e-42) tmp = Float64(Float64(a * Float64(-2.0 / a)) * Float64(c / Float64(b + hypot(b, sqrt(Float64(a * Float64(c * -4.0))))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.5e+154) tmp = -b / a; elseif (b <= -5.2e-250) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); elseif (b <= 6.5e-42) tmp = (a * (-2.0 / a)) * (c / (b + hypot(b, sqrt((a * (c * -4.0)))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, -5.2e-250], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.5e-42], N[(N[(a * N[(-2.0 / a), $MachinePrecision]), $MachinePrecision] * N[(c / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.5 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq -5.2 \cdot 10^{-250}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{-42}:\\
\;\;\;\;\left(a \cdot \frac{-2}{a}\right) \cdot \frac{c}{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.5000000000000002e154Initial program 31.1%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -8.5000000000000002e154 < b < -5.20000000000000016e-250Initial program 86.4%
if -5.20000000000000016e-250 < b < 6.4999999999999998e-42Initial program 71.8%
+-commutative71.8%
flip-+71.5%
add-sqr-sqrt71.5%
fma-neg71.5%
distribute-lft-neg-in71.5%
associate-*r*71.5%
metadata-eval71.5%
sqr-neg71.5%
add-sqr-sqrt22.2%
sqrt-unprod67.6%
sqr-neg67.6%
sqrt-prod45.7%
add-sqr-sqrt67.9%
unsub-neg67.9%
+-commutative67.9%
Applied egg-rr71.5%
fma-def71.5%
+-commutative71.5%
associate-*r*71.5%
*-commutative71.5%
fma-udef71.5%
*-commutative71.5%
*-commutative71.5%
Simplified71.5%
Taylor expanded in a around 0 75.9%
div-inv75.9%
associate-/l*75.8%
*-commutative75.8%
*-commutative75.8%
associate-*r*75.8%
*-commutative75.8%
Applied egg-rr75.8%
*-commutative75.8%
associate-/r/75.8%
associate-*l/75.9%
times-frac62.3%
*-lft-identity62.3%
times-frac75.9%
*-commutative75.9%
associate-/r*75.9%
metadata-eval75.9%
*-commutative75.9%
associate-*l*75.9%
Simplified75.9%
frac-times62.3%
Applied egg-rr62.3%
associate-*r*62.3%
times-frac85.0%
associate-*l/84.7%
Simplified84.7%
if 6.4999999999999998e-42 < b Initial program 11.4%
Taylor expanded in b around inf 89.8%
associate-*r/89.8%
neg-mul-189.8%
Simplified89.8%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(if (<= b -8.5e+154)
(/ (- b) a)
(if (<= b 4.7e-99)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e+154) {
tmp = -b / a;
} else if (b <= 4.7e-99) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - 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 <= (-8.5d+154)) then
tmp = -b / a
else if (b <= 4.7d-99) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - 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 <= -8.5e+154) {
tmp = -b / a;
} else if (b <= 4.7e-99) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e+154: tmp = -b / a elif b <= 4.7e-99: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e+154) tmp = Float64(Float64(-b) / a); elseif (b <= 4.7e-99) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - 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 <= -8.5e+154) tmp = -b / a; elseif (b <= 4.7e-99) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.7e-99], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -8.5 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.7 \cdot 10^{-99}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.5000000000000002e154Initial program 31.1%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -8.5000000000000002e154 < b < 4.69999999999999989e-99Initial program 82.8%
if 4.69999999999999989e-99 < b Initial program 15.2%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
Final simplification86.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1e-89)
(- (/ c b) (/ b a))
(if (<= b 1.18e-99)
(/ (- (sqrt (* c (/ a -0.25))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-89) {
tmp = (c / b) - (b / a);
} else if (b <= 1.18e-99) {
tmp = (sqrt((c * (a / -0.25))) - 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-89)) then
tmp = (c / b) - (b / a)
else if (b <= 1.18d-99) then
tmp = (sqrt((c * (a / (-0.25d0)))) - 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-89) {
tmp = (c / b) - (b / a);
} else if (b <= 1.18e-99) {
tmp = (Math.sqrt((c * (a / -0.25))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-89: tmp = (c / b) - (b / a) elif b <= 1.18e-99: tmp = (math.sqrt((c * (a / -0.25))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-89) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.18e-99) tmp = Float64(Float64(sqrt(Float64(c * Float64(a / -0.25))) - 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-89) tmp = (c / b) - (b / a); elseif (b <= 1.18e-99) tmp = (sqrt((c * (a / -0.25))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-89], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.18e-99], N[(N[(N[Sqrt[N[(c * N[(a / -0.25), $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^{-89}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.18 \cdot 10^{-99}:\\
\;\;\;\;\frac{\sqrt{c \cdot \frac{a}{-0.25}} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.00000000000000004e-89Initial program 64.7%
Taylor expanded in b around -inf 83.5%
+-commutative83.5%
mul-1-neg83.5%
unsub-neg83.5%
Simplified83.5%
if -1.00000000000000004e-89 < b < 1.1800000000000001e-99Initial program 77.2%
add-sqr-sqrt76.9%
pow276.9%
pow1/276.9%
sqrt-pow176.9%
fma-neg76.9%
distribute-lft-neg-in76.9%
associate-*r*76.9%
metadata-eval76.9%
metadata-eval76.9%
Applied egg-rr76.9%
Taylor expanded in c around -inf 46.4%
unpow246.4%
exp-prod45.3%
exp-prod44.6%
pow-sqr44.6%
mul-1-neg44.6%
unsub-neg44.6%
*-commutative44.6%
Simplified44.6%
Taylor expanded in a around 0 46.3%
*-commutative46.3%
+-commutative46.3%
log-prod46.4%
log-div68.4%
exp-to-pow72.6%
unpow1/272.6%
associate-/r/72.6%
*-commutative72.6%
associate-/l*72.6%
metadata-eval72.6%
Simplified72.6%
if 1.1800000000000001e-99 < b Initial program 15.2%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
Final simplification81.5%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e-87) (- (/ c b) (/ b a)) (if (<= b 4.2e-99) (* 0.5 (/ (sqrt (* c (/ a -0.25))) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 4.2e-99) {
tmp = 0.5 * (sqrt((c * (a / -0.25))) / 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 <= (-2.4d-87)) then
tmp = (c / b) - (b / a)
else if (b <= 4.2d-99) then
tmp = 0.5d0 * (sqrt((c * (a / (-0.25d0)))) / 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 <= -2.4e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 4.2e-99) {
tmp = 0.5 * (Math.sqrt((c * (a / -0.25))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e-87: tmp = (c / b) - (b / a) elif b <= 4.2e-99: tmp = 0.5 * (math.sqrt((c * (a / -0.25))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e-87) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.2e-99) tmp = Float64(0.5 * Float64(sqrt(Float64(c * Float64(a / -0.25))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.4e-87) tmp = (c / b) - (b / a); elseif (b <= 4.2e-99) tmp = 0.5 * (sqrt((c * (a / -0.25))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-87], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e-99], N[(0.5 * N[(N[Sqrt[N[(c * N[(a / -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-87}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-99}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{c \cdot \frac{a}{-0.25}}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.4e-87Initial program 64.7%
Taylor expanded in b around -inf 83.5%
+-commutative83.5%
mul-1-neg83.5%
unsub-neg83.5%
Simplified83.5%
if -2.4e-87 < b < 4.19999999999999968e-99Initial program 77.2%
add-sqr-sqrt76.9%
pow276.9%
pow1/276.9%
sqrt-pow176.9%
fma-neg76.9%
distribute-lft-neg-in76.9%
associate-*r*76.9%
metadata-eval76.9%
metadata-eval76.9%
Applied egg-rr76.9%
Taylor expanded in c around -inf 46.4%
unpow246.4%
exp-prod45.3%
exp-prod44.6%
pow-sqr44.6%
mul-1-neg44.6%
unsub-neg44.6%
*-commutative44.6%
Simplified44.6%
Taylor expanded in b around 0 46.3%
log-prod46.2%
+-commutative46.2%
log-prod46.3%
log-div67.7%
*-commutative67.7%
exp-to-pow71.8%
unpow1/271.8%
associate-/r/71.8%
*-commutative71.8%
associate-/l*71.8%
metadata-eval71.8%
Simplified71.8%
if 4.19999999999999968e-99 < b Initial program 15.2%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
Final simplification81.3%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 70.0%
Taylor expanded in b around -inf 64.1%
+-commutative64.1%
mul-1-neg64.1%
unsub-neg64.1%
Simplified64.1%
if -9.999999999999969e-311 < b Initial program 30.3%
Taylor expanded in b around inf 66.4%
associate-*r/66.4%
neg-mul-166.4%
Simplified66.4%
Final simplification65.2%
(FPCore (a b c) :precision binary64 (if (<= b 3.65e-22) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.65e-22) {
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 <= 3.65d-22) 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 <= 3.65e-22) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.65e-22: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.65e-22) 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 <= 3.65e-22) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.65e-22], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.65 \cdot 10^{-22}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 3.65000000000000014e-22Initial program 67.4%
Taylor expanded in b around -inf 47.2%
associate-*r/47.2%
mul-1-neg47.2%
Simplified47.2%
if 3.65000000000000014e-22 < b Initial program 11.8%
Taylor expanded in b around -inf 2.2%
Taylor expanded in b around 0 28.6%
Final simplification41.5%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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 <= -1e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 70.0%
Taylor expanded in b around -inf 63.6%
associate-*r/63.6%
mul-1-neg63.6%
Simplified63.6%
if -9.999999999999969e-311 < b Initial program 30.3%
Taylor expanded in b around inf 66.4%
associate-*r/66.4%
neg-mul-166.4%
Simplified66.4%
Final simplification65.0%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 50.4%
Taylor expanded in b around -inf 31.2%
Taylor expanded in b around 0 11.0%
Final simplification11.0%
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023271
(FPCore (a b c)
:name "quadp (p42, positive)"
: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)))