
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+270) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (+ (/ (/ d (hypot d c)) (/ (hypot d c) b)) (* a (/ 1.0 c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+270) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = ((d / hypot(d, c)) / (hypot(d, c) / b)) + (a * (1.0 / c));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 2e+270) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(Float64(d / hypot(d, c)) / Float64(hypot(d, c) / b)) + Float64(a * Float64(1.0 / c))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+270], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(a * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+270}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{b}} + a \cdot \frac{1}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000001e270Initial program 81.1%
*-un-lft-identity81.1%
add-sqr-sqrt81.1%
times-frac81.1%
hypot-def81.1%
fma-def81.1%
hypot-def97.6%
Applied egg-rr97.6%
associate-*l/97.8%
*-un-lft-identity97.8%
Applied egg-rr97.8%
if 2.0000000000000001e270 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 14.9%
Taylor expanded in a around 0 8.3%
associate-/l*15.0%
associate-/r/17.7%
unpow217.7%
unpow217.7%
fma-udef17.7%
associate-/l*18.9%
associate-/r/20.4%
unpow220.4%
unpow220.4%
fma-udef20.4%
Simplified20.4%
*-un-lft-identity20.4%
add-sqr-sqrt20.4%
times-frac20.4%
fma-udef20.4%
hypot-def20.4%
fma-udef20.4%
hypot-def68.5%
Applied egg-rr68.5%
Taylor expanded in c around inf 69.3%
associate-*l*71.8%
associate-*l/71.9%
*-un-lft-identity71.9%
Applied egg-rr71.9%
associate-/l*71.9%
Simplified71.9%
Final simplification91.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))) (t_1 (+ (/ b d) (* (/ c d) (/ a d)))))
(if (<= d -1.1e+26)
t_1
(if (<= d 1.7e-158)
(+ (/ (/ d (hypot d c)) (/ (hypot d c) b)) (* a (/ 1.0 c)))
(if (<= d 1.4e+123) (+ (* b (/ d t_0)) (* a (/ c t_0))) t_1)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -1.1e+26) {
tmp = t_1;
} else if (d <= 1.7e-158) {
tmp = ((d / hypot(d, c)) / (hypot(d, c) / b)) + (a * (1.0 / c));
} else if (d <= 1.4e+123) {
tmp = (b * (d / t_0)) + (a * (c / t_0));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))) tmp = 0.0 if (d <= -1.1e+26) tmp = t_1; elseif (d <= 1.7e-158) tmp = Float64(Float64(Float64(d / hypot(d, c)) / Float64(hypot(d, c) / b)) + Float64(a * Float64(1.0 / c))); elseif (d <= 1.4e+123) tmp = Float64(Float64(b * Float64(d / t_0)) + Float64(a * Float64(c / t_0))); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.1e+26], t$95$1, If[LessEqual[d, 1.7e-158], N[(N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(a * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.4e+123], N[(N[(b * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision] + N[(a * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -1.1 \cdot 10^{+26}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{-158}:\\
\;\;\;\;\frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{b}} + a \cdot \frac{1}{c}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{+123}:\\
\;\;\;\;b \cdot \frac{d}{t_0} + a \cdot \frac{c}{t_0}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -1.10000000000000004e26 or 1.40000000000000006e123 < d Initial program 41.7%
Taylor expanded in c around 0 81.7%
unpow281.7%
times-frac87.0%
Simplified87.0%
if -1.10000000000000004e26 < d < 1.7e-158Initial program 77.3%
Taylor expanded in a around 0 70.0%
associate-/l*69.3%
associate-/r/71.1%
unpow271.1%
unpow271.1%
fma-udef71.1%
associate-/l*65.2%
associate-/r/73.2%
unpow273.2%
unpow273.2%
fma-udef73.2%
Simplified73.2%
*-un-lft-identity73.2%
add-sqr-sqrt73.2%
times-frac73.2%
fma-udef73.2%
hypot-def73.2%
fma-udef73.2%
hypot-def76.4%
Applied egg-rr76.4%
Taylor expanded in c around inf 87.3%
associate-*l*89.2%
associate-*l/89.2%
*-un-lft-identity89.2%
Applied egg-rr89.2%
associate-/l*89.1%
Simplified89.1%
if 1.7e-158 < d < 1.40000000000000006e123Initial program 79.5%
Taylor expanded in a around 0 79.5%
associate-/l*73.8%
associate-/r/84.1%
unpow284.1%
unpow284.1%
fma-udef84.1%
associate-/l*81.9%
associate-/r/84.5%
unpow284.5%
unpow284.5%
fma-udef84.5%
Simplified84.5%
Final simplification87.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ (/ d (hypot d c)) (/ (hypot d c) b)) (* a (/ 1.0 c))))
(t_1 (+ (/ b d) (* (/ c d) (/ a d)))))
(if (<= d -6.5e+23)
t_1
(if (<= d 1.5e-93)
t_0
(if (<= d 3.3e+65)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 2.6e+100) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((d / hypot(d, c)) / (hypot(d, c) / b)) + (a * (1.0 / c));
double t_1 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -6.5e+23) {
tmp = t_1;
} else if (d <= 1.5e-93) {
tmp = t_0;
} else if (d <= 3.3e+65) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.6e+100) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((d / Math.hypot(d, c)) / (Math.hypot(d, c) / b)) + (a * (1.0 / c));
double t_1 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -6.5e+23) {
tmp = t_1;
} else if (d <= 1.5e-93) {
tmp = t_0;
} else if (d <= 3.3e+65) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.6e+100) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((d / math.hypot(d, c)) / (math.hypot(d, c) / b)) + (a * (1.0 / c)) t_1 = (b / d) + ((c / d) * (a / d)) tmp = 0 if d <= -6.5e+23: tmp = t_1 elif d <= 1.5e-93: tmp = t_0 elif d <= 3.3e+65: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 2.6e+100: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(d / hypot(d, c)) / Float64(hypot(d, c) / b)) + Float64(a * Float64(1.0 / c))) t_1 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))) tmp = 0.0 if (d <= -6.5e+23) tmp = t_1; elseif (d <= 1.5e-93) tmp = t_0; elseif (d <= 3.3e+65) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2.6e+100) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((d / hypot(d, c)) / (hypot(d, c) / b)) + (a * (1.0 / c)); t_1 = (b / d) + ((c / d) * (a / d)); tmp = 0.0; if (d <= -6.5e+23) tmp = t_1; elseif (d <= 1.5e-93) tmp = t_0; elseif (d <= 3.3e+65) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 2.6e+100) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(a * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.5e+23], t$95$1, If[LessEqual[d, 1.5e-93], t$95$0, If[LessEqual[d, 3.3e+65], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.6e+100], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{b}} + a \cdot \frac{1}{c}\\
t_1 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -6.5 \cdot 10^{+23}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq 1.5 \cdot 10^{-93}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+65}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{+100}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -6.4999999999999996e23 or 2.6000000000000002e100 < d Initial program 43.1%
Taylor expanded in c around 0 81.4%
unpow281.4%
times-frac86.5%
Simplified86.5%
if -6.4999999999999996e23 < d < 1.5000000000000001e-93 or 3.30000000000000023e65 < d < 2.6000000000000002e100Initial program 76.3%
Taylor expanded in a around 0 70.0%
associate-/l*68.6%
associate-/r/72.6%
unpow272.6%
unpow272.6%
fma-udef72.6%
associate-/l*66.7%
associate-/r/74.5%
unpow274.5%
unpow274.5%
fma-udef74.5%
Simplified74.5%
*-un-lft-identity74.5%
add-sqr-sqrt74.5%
times-frac74.5%
fma-udef74.5%
hypot-def74.5%
fma-udef74.5%
hypot-def77.2%
Applied egg-rr77.2%
Taylor expanded in c around inf 87.3%
associate-*l*88.9%
associate-*l/89.0%
*-un-lft-identity89.0%
Applied egg-rr89.0%
associate-/l*89.0%
Simplified89.0%
if 1.5000000000000001e-93 < d < 3.30000000000000023e65Initial program 83.6%
Final simplification87.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ (/ b d) (* (/ c d) (/ a d)))))
(if (<= d -1.9e+94)
t_1
(if (<= d -2.15e-150)
t_0
(if (<= d 1e-154)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= d 1.7e+82) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -1.9e+94) {
tmp = t_1;
} else if (d <= -2.15e-150) {
tmp = t_0;
} else if (d <= 1e-154) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 1.7e+82) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (b / d) + ((c / d) * (a / d))
if (d <= (-1.9d+94)) then
tmp = t_1
else if (d <= (-2.15d-150)) then
tmp = t_0
else if (d <= 1d-154) then
tmp = (a / c) + (b / (c * (c / d)))
else if (d <= 1.7d+82) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -1.9e+94) {
tmp = t_1;
} else if (d <= -2.15e-150) {
tmp = t_0;
} else if (d <= 1e-154) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (d <= 1.7e+82) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (b / d) + ((c / d) * (a / d)) tmp = 0 if d <= -1.9e+94: tmp = t_1 elif d <= -2.15e-150: tmp = t_0 elif d <= 1e-154: tmp = (a / c) + (b / (c * (c / d))) elif d <= 1.7e+82: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))) tmp = 0.0 if (d <= -1.9e+94) tmp = t_1; elseif (d <= -2.15e-150) tmp = t_0; elseif (d <= 1e-154) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (d <= 1.7e+82) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (b / d) + ((c / d) * (a / d)); tmp = 0.0; if (d <= -1.9e+94) tmp = t_1; elseif (d <= -2.15e-150) tmp = t_0; elseif (d <= 1e-154) tmp = (a / c) + (b / (c * (c / d))); elseif (d <= 1.7e+82) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.9e+94], t$95$1, If[LessEqual[d, -2.15e-150], t$95$0, If[LessEqual[d, 1e-154], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.7e+82], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -1.9 \cdot 10^{+94}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq -2.15 \cdot 10^{-150}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 10^{-154}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;d \leq 1.7 \cdot 10^{+82}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -1.8999999999999998e94 or 1.69999999999999997e82 < d Initial program 40.0%
Taylor expanded in c around 0 80.0%
unpow280.0%
times-frac86.2%
Simplified86.2%
if -1.8999999999999998e94 < d < -2.15000000000000002e-150 or 9.9999999999999997e-155 < d < 1.69999999999999997e82Initial program 84.0%
if -2.15000000000000002e-150 < d < 9.9999999999999997e-155Initial program 73.4%
Taylor expanded in c around inf 78.6%
unpow278.6%
times-frac94.0%
Simplified94.0%
clear-num94.0%
frac-times94.1%
*-un-lft-identity94.1%
Applied egg-rr94.1%
Final simplification87.4%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -4.8e+22)
(and (not (<= d -1.05e-37))
(or (<= d -2e-67) (not (<= d 800000000.0)))))
(+ (/ b d) (* (/ c d) (/ a d)))
(+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e+22) || (!(d <= -1.05e-37) && ((d <= -2e-67) || !(d <= 800000000.0)))) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-4.8d+22)) .or. (.not. (d <= (-1.05d-37))) .and. (d <= (-2d-67)) .or. (.not. (d <= 800000000.0d0))) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (a / c) + ((d / c) * (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e+22) || (!(d <= -1.05e-37) && ((d <= -2e-67) || !(d <= 800000000.0)))) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.8e+22) or (not (d <= -1.05e-37) and ((d <= -2e-67) or not (d <= 800000000.0))): tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.8e+22) || (!(d <= -1.05e-37) && ((d <= -2e-67) || !(d <= 800000000.0)))) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.8e+22) || (~((d <= -1.05e-37)) && ((d <= -2e-67) || ~((d <= 800000000.0))))) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e+22], And[N[Not[LessEqual[d, -1.05e-37]], $MachinePrecision], Or[LessEqual[d, -2e-67], N[Not[LessEqual[d, 800000000.0]], $MachinePrecision]]]], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{+22} \lor \neg \left(d \leq -1.05 \cdot 10^{-37}\right) \land \left(d \leq -2 \cdot 10^{-67} \lor \neg \left(d \leq 800000000\right)\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if d < -4.8e22 or -1.05e-37 < d < -1.99999999999999989e-67 or 8e8 < d Initial program 50.4%
Taylor expanded in c around 0 79.4%
unpow279.4%
times-frac83.4%
Simplified83.4%
if -4.8e22 < d < -1.05e-37 or -1.99999999999999989e-67 < d < 8e8Initial program 78.7%
Taylor expanded in c around inf 73.9%
unpow273.9%
times-frac83.2%
Simplified83.2%
Final simplification83.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e+30) (not (<= d 41000000000000.0))) (/ b d) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e+30) || !(d <= 41000000000000.0)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-4d+30)) .or. (.not. (d <= 41000000000000.0d0))) then
tmp = b / d
else
tmp = (a / c) + ((d / c) * (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e+30) || !(d <= 41000000000000.0)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e+30) or not (d <= 41000000000000.0): tmp = b / d else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e+30) || !(d <= 41000000000000.0)) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4e+30) || ~((d <= 41000000000000.0))) tmp = b / d; else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e+30], N[Not[LessEqual[d, 41000000000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{+30} \lor \neg \left(d \leq 41000000000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if d < -4.0000000000000001e30 or 4.1e13 < d Initial program 47.6%
Taylor expanded in c around 0 72.0%
if -4.0000000000000001e30 < d < 4.1e13Initial program 79.8%
Taylor expanded in c around inf 71.0%
unpow271.0%
times-frac79.8%
Simplified79.8%
Final simplification76.2%
(FPCore (a b c d) :precision binary64 (if (<= d -1.8e+23) (/ b d) (if (<= d 3100.0) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.8e+23) {
tmp = b / d;
} else if (d <= 3100.0) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-1.8d+23)) then
tmp = b / d
else if (d <= 3100.0d0) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.8e+23) {
tmp = b / d;
} else if (d <= 3100.0) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.8e+23: tmp = b / d elif d <= 3100.0: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.8e+23) tmp = Float64(b / d); elseif (d <= 3100.0) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.8e+23) tmp = b / d; elseif (d <= 3100.0) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.8e+23], N[(b / d), $MachinePrecision], If[LessEqual[d, 3100.0], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{+23}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 3100:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.7999999999999999e23 or 3100 < d Initial program 48.4%
Taylor expanded in c around 0 70.8%
if -1.7999999999999999e23 < d < 3100Initial program 79.5%
Taylor expanded in c around inf 68.0%
Final simplification69.3%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 64.8%
Taylor expanded in c around inf 43.6%
Final simplification43.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2023208
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))