
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))))
(if (<= b -1550000000000.0)
(/ c (- b))
(if (<= b -1.35e-45)
t_0
(if (<= b -1.35e-99)
(/ 1.0 (/ -1.0 (/ c b)))
(if (<= b 8.6e+32) t_0 (- (/ c b) (/ b a))))))))
double code(double a, double b, double c) {
double t_0 = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
double tmp;
if (b <= -1550000000000.0) {
tmp = c / -b;
} else if (b <= -1.35e-45) {
tmp = t_0;
} else if (b <= -1.35e-99) {
tmp = 1.0 / (-1.0 / (c / b));
} else if (b <= 8.6e+32) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
if (b <= (-1550000000000.0d0)) then
tmp = c / -b
else if (b <= (-1.35d-45)) then
tmp = t_0
else if (b <= (-1.35d-99)) then
tmp = 1.0d0 / ((-1.0d0) / (c / b))
else if (b <= 8.6d+32) then
tmp = t_0
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
double tmp;
if (b <= -1550000000000.0) {
tmp = c / -b;
} else if (b <= -1.35e-45) {
tmp = t_0;
} else if (b <= -1.35e-99) {
tmp = 1.0 / (-1.0 / (c / b));
} else if (b <= 8.6e+32) {
tmp = t_0;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): t_0 = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) tmp = 0 if b <= -1550000000000.0: tmp = c / -b elif b <= -1.35e-45: tmp = t_0 elif b <= -1.35e-99: tmp = 1.0 / (-1.0 / (c / b)) elif b <= 8.6e+32: tmp = t_0 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) t_0 = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)) tmp = 0.0 if (b <= -1550000000000.0) tmp = Float64(c / Float64(-b)); elseif (b <= -1.35e-45) tmp = t_0; elseif (b <= -1.35e-99) tmp = Float64(1.0 / Float64(-1.0 / Float64(c / b))); elseif (b <= 8.6e+32) tmp = t_0; else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); tmp = 0.0; if (b <= -1550000000000.0) tmp = c / -b; elseif (b <= -1.35e-45) tmp = t_0; elseif (b <= -1.35e-99) tmp = 1.0 / (-1.0 / (c / b)); elseif (b <= 8.6e+32) tmp = t_0; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1550000000000.0], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, -1.35e-45], t$95$0, If[LessEqual[b, -1.35e-99], N[(1.0 / N[(-1.0 / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8.6e+32], t$95$0, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{if}\;b \leq -1550000000000:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq -1.35 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq -1.35 \cdot 10^{-99}:\\
\;\;\;\;\frac{1}{\frac{-1}{\frac{c}{b}}}\\
\mathbf{elif}\;b \leq 8.6 \cdot 10^{+32}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.55e12Initial program 8.6%
div-sub7.1%
sub-neg7.1%
neg-mul-17.1%
*-commutative7.1%
associate-/l*6.9%
distribute-neg-frac6.9%
neg-mul-16.9%
*-commutative6.9%
associate-/l*7.1%
distribute-rgt-out8.7%
associate-/r*8.7%
metadata-eval8.7%
fma-neg8.7%
*-commutative8.7%
*-commutative8.7%
Simplified8.7%
Taylor expanded in b around -inf 92.6%
associate-*r/92.6%
neg-mul-192.6%
Simplified92.6%
if -1.55e12 < b < -1.34999999999999992e-45 or -1.35e-99 < b < 8.5999999999999994e32Initial program 83.2%
if -1.34999999999999992e-45 < b < -1.35e-99Initial program 27.3%
Taylor expanded in b around -inf 60.3%
clear-num60.6%
inv-pow60.6%
times-frac60.6%
metadata-eval60.6%
associate-/l*76.6%
Applied egg-rr76.6%
unpow-176.6%
associate-/r*76.7%
*-inverses76.7%
associate-*r/76.7%
metadata-eval76.7%
Simplified76.7%
if 8.5999999999999994e32 < b Initial program 62.1%
div-sub62.1%
sub-neg62.1%
neg-mul-162.1%
*-commutative62.1%
associate-/l*62.1%
distribute-neg-frac62.1%
neg-mul-162.1%
*-commutative62.1%
associate-/l*62.0%
distribute-rgt-out62.0%
associate-/r*62.0%
metadata-eval62.0%
fma-neg62.0%
*-commutative62.0%
*-commutative62.0%
Simplified62.0%
Taylor expanded in a around 0 97.1%
+-commutative97.1%
mul-1-neg97.1%
unsub-neg97.1%
Simplified97.1%
Final simplification89.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e-126)
(/ c (- b))
(if (<= b 1.35e-97)
(* (/ -0.5 a) (+ b (sqrt (* c (* a -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e-126) {
tmp = c / -b;
} else if (b <= 1.35e-97) {
tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.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 <= (-1.5d-126)) then
tmp = c / -b
else if (b <= 1.35d-97) then
tmp = ((-0.5d0) / a) * (b + sqrt((c * (a * (-4.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 <= -1.5e-126) {
tmp = c / -b;
} else if (b <= 1.35e-97) {
tmp = (-0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.5e-126: tmp = c / -b elif b <= 1.35e-97: tmp = (-0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.5e-126) tmp = Float64(c / Float64(-b)); elseif (b <= 1.35e-97) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.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 <= -1.5e-126) tmp = c / -b; elseif (b <= 1.35e-97) tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.5e-126], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.35e-97], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{-126}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-97}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.5000000000000001e-126Initial program 17.0%
div-sub15.8%
sub-neg15.8%
neg-mul-115.8%
*-commutative15.8%
associate-/l*15.6%
distribute-neg-frac15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*15.8%
distribute-rgt-out17.0%
associate-/r*17.0%
metadata-eval17.0%
fma-neg17.0%
*-commutative17.0%
*-commutative17.0%
Simplified17.0%
Taylor expanded in b around -inf 84.2%
associate-*r/84.2%
neg-mul-184.2%
Simplified84.2%
if -1.5000000000000001e-126 < b < 1.34999999999999993e-97Initial program 85.3%
div-sub85.3%
sub-neg85.3%
neg-mul-185.3%
*-commutative85.3%
associate-/l*85.3%
distribute-neg-frac85.3%
neg-mul-185.3%
*-commutative85.3%
associate-/l*85.2%
distribute-rgt-out85.2%
associate-/r*85.2%
metadata-eval85.2%
fma-neg85.2%
*-commutative85.2%
*-commutative85.2%
Simplified85.2%
Taylor expanded in b around 0 77.6%
associate-*r*77.6%
Simplified77.6%
if 1.34999999999999993e-97 < b Initial program 66.5%
div-sub66.5%
sub-neg66.5%
neg-mul-166.5%
*-commutative66.5%
associate-/l*66.4%
distribute-neg-frac66.4%
neg-mul-166.4%
*-commutative66.4%
associate-/l*66.4%
distribute-rgt-out66.4%
associate-/r*66.4%
metadata-eval66.4%
fma-neg66.4%
*-commutative66.4%
*-commutative66.4%
Simplified66.4%
Taylor expanded in a around 0 90.6%
+-commutative90.6%
mul-1-neg90.6%
unsub-neg90.6%
Simplified90.6%
Final simplification84.5%
(FPCore (a b c)
:precision binary64
(if (<= b -4e-124)
(/ c (- b))
(if (<= b 6e-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 <= -4e-124) {
tmp = c / -b;
} else if (b <= 6e-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 <= (-4d-124)) then
tmp = c / -b
else if (b <= 6d-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 <= -4e-124) {
tmp = c / -b;
} else if (b <= 6e-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 <= -4e-124: tmp = c / -b elif b <= 6e-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 <= -4e-124) tmp = Float64(c / Float64(-b)); elseif (b <= 6e-99) tmp = Float64(Float64(b + sqrt(Float64(Float64(c * 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 <= -4e-124) tmp = c / -b; elseif (b <= 6e-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, -4e-124], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6e-99], N[(N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $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 -4 \cdot 10^{-124}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-99}:\\
\;\;\;\;\frac{b + \sqrt{\left(c \cdot a\right) \cdot -4}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.99999999999999973e-124Initial program 17.0%
div-sub15.8%
sub-neg15.8%
neg-mul-115.8%
*-commutative15.8%
associate-/l*15.6%
distribute-neg-frac15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*15.8%
distribute-rgt-out17.0%
associate-/r*17.0%
metadata-eval17.0%
fma-neg17.0%
*-commutative17.0%
*-commutative17.0%
Simplified17.0%
Taylor expanded in b around -inf 84.2%
associate-*r/84.2%
neg-mul-184.2%
Simplified84.2%
if -3.99999999999999973e-124 < b < 6.00000000000000012e-99Initial program 85.3%
div-sub85.3%
sub-neg85.3%
neg-mul-185.3%
*-commutative85.3%
associate-/l*85.3%
distribute-neg-frac85.3%
neg-mul-185.3%
*-commutative85.3%
associate-/l*85.2%
distribute-rgt-out85.2%
associate-/r*85.2%
metadata-eval85.2%
fma-neg85.2%
*-commutative85.2%
*-commutative85.2%
Simplified85.2%
Taylor expanded in b around 0 77.6%
associate-*r*77.6%
Simplified77.6%
sqrt-prod42.2%
*-commutative42.2%
Applied egg-rr42.2%
add042.2%
associate-*l/42.1%
*-un-lft-identity42.1%
times-frac42.1%
metadata-eval42.1%
*-commutative42.1%
sqrt-unprod77.6%
Applied egg-rr77.6%
add077.6%
metadata-eval77.6%
times-frac77.6%
*-lft-identity77.6%
associate-*r*77.6%
Simplified77.6%
if 6.00000000000000012e-99 < b Initial program 66.5%
div-sub66.5%
sub-neg66.5%
neg-mul-166.5%
*-commutative66.5%
associate-/l*66.4%
distribute-neg-frac66.4%
neg-mul-166.4%
*-commutative66.4%
associate-/l*66.4%
distribute-rgt-out66.4%
associate-/r*66.4%
metadata-eval66.4%
fma-neg66.4%
*-commutative66.4%
*-commutative66.4%
Simplified66.4%
Taylor expanded in a around 0 90.6%
+-commutative90.6%
mul-1-neg90.6%
unsub-neg90.6%
Simplified90.6%
Final simplification84.5%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-310)) then
tmp = c / -b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 29.8%
div-sub28.9%
sub-neg28.9%
neg-mul-128.9%
*-commutative28.9%
associate-/l*28.7%
distribute-neg-frac28.7%
neg-mul-128.7%
*-commutative28.7%
associate-/l*28.8%
distribute-rgt-out29.8%
associate-/r*29.8%
metadata-eval29.8%
fma-neg29.8%
*-commutative29.8%
*-commutative29.8%
Simplified29.8%
Taylor expanded in b around -inf 70.5%
associate-*r/70.5%
neg-mul-170.5%
Simplified70.5%
if -4.999999999999985e-310 < b Initial program 71.9%
div-sub71.9%
sub-neg71.9%
neg-mul-171.9%
*-commutative71.9%
associate-/l*71.9%
distribute-neg-frac71.9%
neg-mul-171.9%
*-commutative71.9%
associate-/l*71.9%
distribute-rgt-out71.9%
associate-/r*71.9%
metadata-eval71.9%
fma-neg71.9%
*-commutative71.9%
*-commutative71.9%
Simplified71.9%
Taylor expanded in a around 0 66.0%
+-commutative66.0%
mul-1-neg66.0%
unsub-neg66.0%
Simplified66.0%
Final simplification68.3%
(FPCore (a b c) :precision binary64 (if (<= b -1.45e+33) (/ c b) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e+33) {
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.45d+33)) 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.45e+33) {
tmp = c / b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e+33: tmp = c / b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e+33) tmp = Float64(c / b); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.45e+33) tmp = c / b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e+33], N[(c / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{+33}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.45000000000000012e33Initial program 5.6%
div-sub3.8%
sub-neg3.8%
neg-mul-13.8%
*-commutative3.8%
associate-/l*3.6%
distribute-neg-frac3.6%
neg-mul-13.6%
*-commutative3.6%
associate-/l*3.8%
distribute-rgt-out5.6%
associate-/r*5.6%
metadata-eval5.6%
fma-neg5.6%
*-commutative5.6%
*-commutative5.6%
Simplified5.6%
Taylor expanded in b around inf 2.2%
Taylor expanded in a around inf 22.6%
if -1.45000000000000012e33 < b Initial program 69.9%
div-sub70.0%
sub-neg70.0%
neg-mul-170.0%
*-commutative70.0%
associate-/l*70.0%
distribute-neg-frac70.0%
neg-mul-170.0%
*-commutative70.0%
associate-/l*69.9%
distribute-rgt-out69.9%
associate-/r*69.9%
metadata-eval69.9%
fma-neg69.9%
*-commutative69.9%
*-commutative69.9%
Simplified69.9%
Taylor expanded in a around 0 46.6%
associate-*r/46.6%
mul-1-neg46.6%
Simplified46.6%
Final simplification39.2%
(FPCore (a b c) :precision binary64 (if (<= b -2.2e-231) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e-231) {
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 <= (-2.2d-231)) 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 <= -2.2e-231) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.2e-231: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.2e-231) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.2e-231) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.2e-231], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.2 \cdot 10^{-231}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -2.20000000000000009e-231Initial program 24.8%
div-sub23.7%
sub-neg23.7%
neg-mul-123.7%
*-commutative23.7%
associate-/l*23.6%
distribute-neg-frac23.6%
neg-mul-123.6%
*-commutative23.6%
associate-/l*23.7%
distribute-rgt-out24.8%
associate-/r*24.8%
metadata-eval24.8%
fma-neg24.8%
*-commutative24.8%
*-commutative24.8%
Simplified24.8%
Taylor expanded in b around -inf 75.4%
associate-*r/75.4%
neg-mul-175.4%
Simplified75.4%
if -2.20000000000000009e-231 < b Initial program 73.8%
div-sub73.8%
sub-neg73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.8%
distribute-rgt-out73.7%
associate-/r*73.7%
metadata-eval73.7%
fma-neg73.7%
*-commutative73.7%
*-commutative73.7%
Simplified73.7%
Taylor expanded in a around 0 61.5%
associate-*r/61.5%
mul-1-neg61.5%
Simplified61.5%
Final simplification68.2%
(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.0%
div-sub49.6%
sub-neg49.6%
neg-mul-149.6%
*-commutative49.6%
associate-/l*49.5%
distribute-neg-frac49.5%
neg-mul-149.5%
*-commutative49.5%
associate-/l*49.5%
distribute-rgt-out50.0%
associate-/r*50.0%
metadata-eval50.0%
fma-neg50.0%
*-commutative50.0%
*-commutative50.0%
Simplified50.0%
Taylor expanded in b around inf 32.3%
Taylor expanded in a around inf 9.0%
Final simplification9.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{t\_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t\_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024046
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(if (< b 0.0) (/ c (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0))) (/ (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))