
(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+255) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (+ (/ b d) (* (/ c d) (/ a d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+255) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
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+255) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); 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+255], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $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^{+255}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999998e255Initial program 79.9%
*-un-lft-identity79.9%
add-sqr-sqrt79.9%
times-frac79.9%
hypot-def79.9%
fma-def79.9%
hypot-def95.5%
Applied egg-rr95.5%
if 1.99999999999999998e255 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 9.4%
Taylor expanded in c around 0 50.3%
unpow250.3%
times-frac65.7%
Simplified65.7%
Final simplification88.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.45e+67)
(/ b d)
(if (<= d -5.5e-156)
t_0
(if (<= d 6.2e-145)
(+ (/ a c) (/ (* b (/ d c)) c))
(if (<= d 5.6e+112) t_0 (+ (/ b d) (* (/ c d) (/ a d)))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.45e+67) {
tmp = b / d;
} else if (d <= -5.5e-156) {
tmp = t_0;
} else if (d <= 6.2e-145) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (d <= 5.6e+112) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-1.45d+67)) then
tmp = b / d
else if (d <= (-5.5d-156)) then
tmp = t_0
else if (d <= 6.2d-145) then
tmp = (a / c) + ((b * (d / c)) / c)
else if (d <= 5.6d+112) then
tmp = t_0
else
tmp = (b / d) + ((c / d) * (a / d))
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 tmp;
if (d <= -1.45e+67) {
tmp = b / d;
} else if (d <= -5.5e-156) {
tmp = t_0;
} else if (d <= 6.2e-145) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (d <= 5.6e+112) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.45e+67: tmp = b / d elif d <= -5.5e-156: tmp = t_0 elif d <= 6.2e-145: tmp = (a / c) + ((b * (d / c)) / c) elif d <= 5.6e+112: tmp = t_0 else: tmp = (b / d) + ((c / d) * (a / d)) 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))) tmp = 0.0 if (d <= -1.45e+67) tmp = Float64(b / d); elseif (d <= -5.5e-156) tmp = t_0; elseif (d <= 6.2e-145) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); elseif (d <= 5.6e+112) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -1.45e+67) tmp = b / d; elseif (d <= -5.5e-156) tmp = t_0; elseif (d <= 6.2e-145) tmp = (a / c) + ((b * (d / c)) / c); elseif (d <= 5.6e+112) tmp = t_0; else tmp = (b / d) + ((c / d) * (a / d)); 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]}, If[LessEqual[d, -1.45e+67], N[(b / d), $MachinePrecision], If[LessEqual[d, -5.5e-156], t$95$0, If[LessEqual[d, 6.2e-145], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.6e+112], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.45 \cdot 10^{+67}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -5.5 \cdot 10^{-156}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{-145}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.6 \cdot 10^{+112}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if d < -1.45000000000000012e67Initial program 38.2%
Taylor expanded in c around 0 90.5%
if -1.45000000000000012e67 < d < -5.4999999999999998e-156 or 6.20000000000000001e-145 < d < 5.6000000000000003e112Initial program 83.5%
if -5.4999999999999998e-156 < d < 6.20000000000000001e-145Initial program 64.0%
Taylor expanded in c around inf 85.9%
unpow285.9%
times-frac91.4%
Simplified91.4%
associate-*r/92.6%
Applied egg-rr92.6%
if 5.6000000000000003e112 < d Initial program 40.6%
Taylor expanded in c around 0 77.2%
unpow277.2%
times-frac86.7%
Simplified86.7%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (<= d -4e+22) (/ b d) (if (<= d 8.3e+68) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e+22) {
tmp = b / d;
} else if (d <= 8.3e+68) {
tmp = (a / c) + ((d / c) * (b / 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 <= (-4d+22)) then
tmp = b / d
else if (d <= 8.3d+68) then
tmp = (a / c) + ((d / c) * (b / 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 <= -4e+22) {
tmp = b / d;
} else if (d <= 8.3e+68) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4e+22: tmp = b / d elif d <= 8.3e+68: tmp = (a / c) + ((d / c) * (b / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4e+22) tmp = Float64(b / d); elseif (d <= 8.3e+68) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4e+22) tmp = b / d; elseif (d <= 8.3e+68) tmp = (a / c) + ((d / c) * (b / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e+22], N[(b / d), $MachinePrecision], If[LessEqual[d, 8.3e+68], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{+22}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 8.3 \cdot 10^{+68}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -4e22 or 8.30000000000000041e68 < d Initial program 48.4%
Taylor expanded in c around 0 82.4%
if -4e22 < d < 8.30000000000000041e68Initial program 73.4%
Taylor expanded in c around inf 69.3%
unpow269.3%
times-frac74.5%
Simplified74.5%
Final simplification77.6%
(FPCore (a b c d) :precision binary64 (if (<= d -1.14e+24) (/ b d) (if (<= d 6.5e+68) (+ (/ a c) (/ (* b (/ d c)) c)) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.14e+24) {
tmp = b / d;
} else if (d <= 6.5e+68) {
tmp = (a / c) + ((b * (d / c)) / 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.14d+24)) then
tmp = b / d
else if (d <= 6.5d+68) then
tmp = (a / c) + ((b * (d / c)) / 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.14e+24) {
tmp = b / d;
} else if (d <= 6.5e+68) {
tmp = (a / c) + ((b * (d / c)) / c);
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.14e+24: tmp = b / d elif d <= 6.5e+68: tmp = (a / c) + ((b * (d / c)) / c) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.14e+24) tmp = Float64(b / d); elseif (d <= 6.5e+68) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.14e+24) tmp = b / d; elseif (d <= 6.5e+68) tmp = (a / c) + ((b * (d / c)) / c); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.14e+24], N[(b / d), $MachinePrecision], If[LessEqual[d, 6.5e+68], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.14 \cdot 10^{+24}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{+68}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.14e24 or 6.5000000000000005e68 < d Initial program 48.4%
Taylor expanded in c around 0 82.4%
if -1.14e24 < d < 6.5000000000000005e68Initial program 73.4%
Taylor expanded in c around inf 69.3%
unpow269.3%
times-frac74.5%
Simplified74.5%
associate-*r/75.1%
Applied egg-rr75.1%
Final simplification77.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -102000000000.0)
(+ (/ a c) (/ (* b (/ d c)) c))
(if (<= c 5.4e-68)
(+ (/ 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 (c <= -102000000000.0) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 5.4e-68) {
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 (c <= (-102000000000.0d0)) then
tmp = (a / c) + ((b * (d / c)) / c)
else if (c <= 5.4d-68) 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 (c <= -102000000000.0) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 5.4e-68) {
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 c <= -102000000000.0: tmp = (a / c) + ((b * (d / c)) / c) elif c <= 5.4e-68: 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 (c <= -102000000000.0) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); elseif (c <= 5.4e-68) 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 (c <= -102000000000.0) tmp = (a / c) + ((b * (d / c)) / c); elseif (c <= 5.4e-68) 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[LessEqual[c, -102000000000.0], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.4e-68], 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}\;c \leq -102000000000:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 5.4 \cdot 10^{-68}:\\
\;\;\;\;\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 c < -1.02e11Initial program 57.6%
Taylor expanded in c around inf 76.2%
unpow276.2%
times-frac85.0%
Simplified85.0%
associate-*r/85.0%
Applied egg-rr85.0%
if -1.02e11 < c < 5.4000000000000003e-68Initial program 66.9%
Taylor expanded in c around 0 77.5%
unpow277.5%
times-frac83.6%
Simplified83.6%
if 5.4000000000000003e-68 < c Initial program 62.9%
Taylor expanded in c around inf 74.4%
unpow274.4%
times-frac76.0%
Simplified76.0%
Final simplification81.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -5600000.0)
(+ (/ a c) (/ (* b (/ d c)) c))
(if (<= c 4.6e-68)
(+ (/ b d) (/ (* a (/ c d)) d))
(+ (/ a c) (* (/ d c) (/ b c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5600000.0) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 4.6e-68) {
tmp = (b / d) + ((a * (c / d)) / 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 (c <= (-5600000.0d0)) then
tmp = (a / c) + ((b * (d / c)) / c)
else if (c <= 4.6d-68) then
tmp = (b / d) + ((a * (c / d)) / 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 (c <= -5600000.0) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 4.6e-68) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5600000.0: tmp = (a / c) + ((b * (d / c)) / c) elif c <= 4.6e-68: tmp = (b / d) + ((a * (c / d)) / d) else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5600000.0) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); elseif (c <= 4.6e-68) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / 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 (c <= -5600000.0) tmp = (a / c) + ((b * (d / c)) / c); elseif (c <= 4.6e-68) tmp = (b / d) + ((a * (c / d)) / d); else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5600000.0], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.6e-68], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $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}\;c \leq -5600000:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 4.6 \cdot 10^{-68}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if c < -5.6e6Initial program 57.6%
Taylor expanded in c around inf 76.2%
unpow276.2%
times-frac85.0%
Simplified85.0%
associate-*r/85.0%
Applied egg-rr85.0%
if -5.6e6 < c < 4.59999999999999994e-68Initial program 66.9%
Taylor expanded in c around 0 77.5%
unpow277.5%
times-frac83.6%
Simplified83.6%
associate-*r/84.3%
Applied egg-rr84.3%
if 4.59999999999999994e-68 < c Initial program 62.9%
Taylor expanded in c around inf 74.4%
unpow274.4%
times-frac76.0%
Simplified76.0%
Final simplification81.9%
(FPCore (a b c d) :precision binary64 (if (<= c -2.75e-45) (/ a c) (if (<= c 4e-39) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.75e-45) {
tmp = a / c;
} else if (c <= 4e-39) {
tmp = b / d;
} else {
tmp = a / 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 (c <= (-2.75d-45)) then
tmp = a / c
else if (c <= 4d-39) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.75e-45) {
tmp = a / c;
} else if (c <= 4e-39) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.75e-45: tmp = a / c elif c <= 4e-39: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.75e-45) tmp = Float64(a / c); elseif (c <= 4e-39) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2.75e-45) tmp = a / c; elseif (c <= 4e-39) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.75e-45], N[(a / c), $MachinePrecision], If[LessEqual[c, 4e-39], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.75 \cdot 10^{-45}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-39}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2.75000000000000015e-45 or 3.99999999999999972e-39 < c Initial program 60.6%
Taylor expanded in c around inf 65.2%
if -2.75000000000000015e-45 < c < 3.99999999999999972e-39Initial program 67.2%
Taylor expanded in c around 0 72.9%
Final simplification68.7%
(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 63.7%
Taylor expanded in c around inf 42.0%
Final simplification42.0%
(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 2023178
(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))))