
(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 10 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
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -5.8e+89)
(/ (- (- a) (/ b (/ c d))) (hypot c d))
(if (<= c -2.4e-43)
t_0
(if (<= c 8e-141)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= c 1.75e+108) t_0 (/ (+ a (* d (/ b c))) (hypot c 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 (c <= -5.8e+89) {
tmp = (-a - (b / (c / d))) / hypot(c, d);
} else if (c <= -2.4e-43) {
tmp = t_0;
} else if (c <= 8e-141) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 1.75e+108) {
tmp = t_0;
} else {
tmp = (a + (d * (b / c))) / hypot(c, d);
}
return tmp;
}
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 (c <= -5.8e+89) {
tmp = (-a - (b / (c / d))) / Math.hypot(c, d);
} else if (c <= -2.4e-43) {
tmp = t_0;
} else if (c <= 8e-141) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 1.75e+108) {
tmp = t_0;
} else {
tmp = (a + (d * (b / c))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -5.8e+89: tmp = (-a - (b / (c / d))) / math.hypot(c, d) elif c <= -2.4e-43: tmp = t_0 elif c <= 8e-141: tmp = (1.0 / d) * (b + (a / (d / c))) elif c <= 1.75e+108: tmp = t_0 else: tmp = (a + (d * (b / c))) / math.hypot(c, 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 (c <= -5.8e+89) tmp = Float64(Float64(Float64(-a) - Float64(b / Float64(c / d))) / hypot(c, d)); elseif (c <= -2.4e-43) tmp = t_0; elseif (c <= 8e-141) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (c <= 1.75e+108) tmp = t_0; else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / hypot(c, 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 (c <= -5.8e+89) tmp = (-a - (b / (c / d))) / hypot(c, d); elseif (c <= -2.4e-43) tmp = t_0; elseif (c <= 8e-141) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (c <= 1.75e+108) tmp = t_0; else tmp = (a + (d * (b / c))) / hypot(c, 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[c, -5.8e+89], N[(N[((-a) - N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.4e-43], t$95$0, If[LessEqual[c, 8e-141], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.75e+108], t$95$0, N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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}\;c \leq -5.8 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -2.4 \cdot 10^{-43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 8 \cdot 10^{-141}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+108}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -5.80000000000000051e89Initial program 39.3%
*-un-lft-identity39.3%
add-sqr-sqrt39.3%
times-frac39.3%
hypot-def39.3%
fma-def39.3%
hypot-def58.9%
Applied egg-rr58.9%
associate-*l/58.9%
*-un-lft-identity58.9%
Applied egg-rr58.9%
Taylor expanded in c around -inf 94.0%
distribute-lft-out94.0%
associate-/l*96.7%
Simplified96.7%
if -5.80000000000000051e89 < c < -2.4000000000000002e-43 or 8.0000000000000003e-141 < c < 1.7500000000000001e108Initial program 87.1%
if -2.4000000000000002e-43 < c < 8.0000000000000003e-141Initial program 66.5%
*-un-lft-identity66.5%
add-sqr-sqrt66.5%
times-frac66.5%
hypot-def66.5%
fma-def66.5%
hypot-def77.7%
Applied egg-rr77.7%
Taylor expanded in c around 0 55.2%
associate-/l*56.4%
Simplified56.4%
Taylor expanded in c around 0 88.0%
if 1.7500000000000001e108 < c Initial program 41.5%
*-un-lft-identity41.5%
add-sqr-sqrt41.5%
times-frac41.5%
hypot-def41.5%
fma-def41.5%
hypot-def60.6%
Applied egg-rr60.6%
associate-*l/60.6%
*-un-lft-identity60.6%
Applied egg-rr60.6%
div-inv60.5%
*-commutative60.5%
fma-udef60.4%
*-commutative60.4%
distribute-lft-in60.4%
*-commutative60.4%
Applied egg-rr60.4%
distribute-lft-out60.4%
fma-def60.5%
associate-*l/60.6%
*-lft-identity60.6%
fma-def60.6%
+-commutative60.6%
fma-def60.6%
*-commutative60.6%
Simplified60.6%
Taylor expanded in d around 0 83.9%
*-commutative83.9%
associate-*r/88.2%
Simplified88.2%
Final simplification89.1%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (/ (/ (fma b d (* a c)) (hypot c d)) (hypot c d)) (* (/ c (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (fma(b, d, (a * c)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (c / hypot(c, d)) * (a / hypot(c, 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))) <= Inf) tmp = Float64(Float64(fma(b, d, Float64(a * c)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, 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], Infinity], N[(N[(N[(b * d + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $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 \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 79.0%
*-un-lft-identity79.0%
add-sqr-sqrt79.0%
times-frac79.0%
hypot-def79.0%
fma-def79.0%
hypot-def93.6%
Applied egg-rr93.6%
associate-*l/93.7%
*-un-lft-identity93.7%
Applied egg-rr93.7%
div-inv93.6%
*-commutative93.6%
fma-udef93.6%
*-commutative93.6%
distribute-lft-in93.6%
*-commutative93.6%
Applied egg-rr93.6%
distribute-lft-out93.6%
fma-def93.6%
associate-*l/93.7%
*-lft-identity93.7%
fma-def93.7%
+-commutative93.7%
fma-def93.7%
*-commutative93.7%
Simplified93.7%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in a around inf 1.3%
*-commutative1.3%
Simplified1.3%
add-sqr-sqrt1.3%
hypot-udef1.3%
hypot-udef1.3%
times-frac63.2%
Applied egg-rr63.2%
Final simplification88.1%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (* (/ c (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (c / hypot(c, d)) * (a / hypot(c, 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))) <= Inf) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, 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], Infinity], 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[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $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 \infty:\\
\;\;\;\;\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{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 79.0%
*-un-lft-identity79.0%
add-sqr-sqrt79.0%
times-frac79.0%
hypot-def79.0%
fma-def79.0%
hypot-def93.6%
Applied egg-rr93.6%
associate-*l/93.7%
*-un-lft-identity93.7%
Applied egg-rr93.7%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in a around inf 1.3%
*-commutative1.3%
Simplified1.3%
add-sqr-sqrt1.3%
hypot-udef1.3%
hypot-udef1.3%
times-frac63.2%
Applied egg-rr63.2%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -7.5e+99)
(* (/ 1.0 c) (+ a (/ (* b d) c)))
(if (<= c -1.12e-43)
t_0
(if (<= c 3.3e-145)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= c 3.6e+108) t_0 (/ (+ a (* d (/ b c))) (hypot c 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 (c <= -7.5e+99) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else if (c <= -1.12e-43) {
tmp = t_0;
} else if (c <= 3.3e-145) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 3.6e+108) {
tmp = t_0;
} else {
tmp = (a + (d * (b / c))) / hypot(c, d);
}
return tmp;
}
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 (c <= -7.5e+99) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else if (c <= -1.12e-43) {
tmp = t_0;
} else if (c <= 3.3e-145) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 3.6e+108) {
tmp = t_0;
} else {
tmp = (a + (d * (b / c))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -7.5e+99: tmp = (1.0 / c) * (a + ((b * d) / c)) elif c <= -1.12e-43: tmp = t_0 elif c <= 3.3e-145: tmp = (1.0 / d) * (b + (a / (d / c))) elif c <= 3.6e+108: tmp = t_0 else: tmp = (a + (d * (b / c))) / math.hypot(c, 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 (c <= -7.5e+99) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); elseif (c <= -1.12e-43) tmp = t_0; elseif (c <= 3.3e-145) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (c <= 3.6e+108) tmp = t_0; else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / hypot(c, 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 (c <= -7.5e+99) tmp = (1.0 / c) * (a + ((b * d) / c)); elseif (c <= -1.12e-43) tmp = t_0; elseif (c <= 3.3e-145) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (c <= 3.6e+108) tmp = t_0; else tmp = (a + (d * (b / c))) / hypot(c, 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[c, -7.5e+99], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.12e-43], t$95$0, If[LessEqual[c, 3.3e-145], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.6e+108], t$95$0, N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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}\;c \leq -7.5 \cdot 10^{+99}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;c \leq -1.12 \cdot 10^{-43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 3.3 \cdot 10^{-145}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{+108}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -7.49999999999999963e99Initial program 37.7%
*-un-lft-identity37.7%
add-sqr-sqrt37.7%
times-frac37.7%
hypot-def37.7%
fma-def37.7%
hypot-def57.8%
Applied egg-rr57.8%
Taylor expanded in c around inf 32.7%
Taylor expanded in c around inf 93.5%
if -7.49999999999999963e99 < c < -1.12e-43 or 3.29999999999999981e-145 < c < 3.6e108Initial program 87.2%
if -1.12e-43 < c < 3.29999999999999981e-145Initial program 66.5%
*-un-lft-identity66.5%
add-sqr-sqrt66.5%
times-frac66.5%
hypot-def66.5%
fma-def66.5%
hypot-def77.7%
Applied egg-rr77.7%
Taylor expanded in c around 0 55.2%
associate-/l*56.4%
Simplified56.4%
Taylor expanded in c around 0 88.0%
if 3.6e108 < c Initial program 41.5%
*-un-lft-identity41.5%
add-sqr-sqrt41.5%
times-frac41.5%
hypot-def41.5%
fma-def41.5%
hypot-def60.6%
Applied egg-rr60.6%
associate-*l/60.6%
*-un-lft-identity60.6%
Applied egg-rr60.6%
div-inv60.5%
*-commutative60.5%
fma-udef60.4%
*-commutative60.4%
distribute-lft-in60.4%
*-commutative60.4%
Applied egg-rr60.4%
distribute-lft-out60.4%
fma-def60.5%
associate-*l/60.6%
*-lft-identity60.6%
fma-def60.6%
+-commutative60.6%
fma-def60.6%
*-commutative60.6%
Simplified60.6%
Taylor expanded in d around 0 83.9%
*-commutative83.9%
associate-*r/88.2%
Simplified88.2%
Final simplification88.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))) (t_1 (* d (/ b c))))
(if (<= c -1.45e+89)
(/ (- (- a) t_1) (hypot c d))
(if (<= c -1.2e-43)
t_0
(if (<= c 2.95e-142)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= c 3.8e+106) t_0 (/ (+ a t_1) (hypot c d))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = d * (b / c);
double tmp;
if (c <= -1.45e+89) {
tmp = (-a - t_1) / hypot(c, d);
} else if (c <= -1.2e-43) {
tmp = t_0;
} else if (c <= 2.95e-142) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 3.8e+106) {
tmp = t_0;
} else {
tmp = (a + t_1) / hypot(c, d);
}
return tmp;
}
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 = d * (b / c);
double tmp;
if (c <= -1.45e+89) {
tmp = (-a - t_1) / Math.hypot(c, d);
} else if (c <= -1.2e-43) {
tmp = t_0;
} else if (c <= 2.95e-142) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 3.8e+106) {
tmp = t_0;
} else {
tmp = (a + t_1) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = d * (b / c) tmp = 0 if c <= -1.45e+89: tmp = (-a - t_1) / math.hypot(c, d) elif c <= -1.2e-43: tmp = t_0 elif c <= 2.95e-142: tmp = (1.0 / d) * (b + (a / (d / c))) elif c <= 3.8e+106: tmp = t_0 else: tmp = (a + t_1) / math.hypot(c, 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))) t_1 = Float64(d * Float64(b / c)) tmp = 0.0 if (c <= -1.45e+89) tmp = Float64(Float64(Float64(-a) - t_1) / hypot(c, d)); elseif (c <= -1.2e-43) tmp = t_0; elseif (c <= 2.95e-142) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (c <= 3.8e+106) tmp = t_0; else tmp = Float64(Float64(a + t_1) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = d * (b / c); tmp = 0.0; if (c <= -1.45e+89) tmp = (-a - t_1) / hypot(c, d); elseif (c <= -1.2e-43) tmp = t_0; elseif (c <= 2.95e-142) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (c <= 3.8e+106) tmp = t_0; else tmp = (a + t_1) / hypot(c, 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]}, Block[{t$95$1 = N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.45e+89], N[(N[((-a) - t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.2e-43], t$95$0, If[LessEqual[c, 2.95e-142], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.8e+106], t$95$0, N[(N[(a + t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := d \cdot \frac{b}{c}\\
\mathbf{if}\;c \leq -1.45 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-a\right) - t_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -1.2 \cdot 10^{-43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.95 \cdot 10^{-142}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;c \leq 3.8 \cdot 10^{+106}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + t_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if c < -1.45000000000000013e89Initial program 39.3%
*-un-lft-identity39.3%
add-sqr-sqrt39.3%
times-frac39.3%
hypot-def39.3%
fma-def39.3%
hypot-def58.9%
Applied egg-rr58.9%
associate-*l/58.9%
*-un-lft-identity58.9%
Applied egg-rr58.9%
div-inv58.9%
*-commutative58.9%
fma-udef58.9%
*-commutative58.9%
distribute-lft-in58.8%
*-commutative58.8%
Applied egg-rr58.8%
distribute-lft-out58.9%
fma-def58.9%
associate-*l/58.9%
*-lft-identity58.9%
fma-def58.9%
+-commutative58.9%
fma-def59.0%
*-commutative59.0%
Simplified59.0%
Taylor expanded in c around -inf 94.0%
associate-/l*96.7%
distribute-lft-in96.7%
mul-1-neg96.7%
neg-sub096.7%
associate--r+96.7%
neg-sub096.7%
associate-/r/96.6%
*-commutative96.6%
Simplified96.6%
if -1.45000000000000013e89 < c < -1.2000000000000001e-43 or 2.94999999999999983e-142 < c < 3.7999999999999998e106Initial program 87.1%
if -1.2000000000000001e-43 < c < 2.94999999999999983e-142Initial program 66.5%
*-un-lft-identity66.5%
add-sqr-sqrt66.5%
times-frac66.5%
hypot-def66.5%
fma-def66.5%
hypot-def77.7%
Applied egg-rr77.7%
Taylor expanded in c around 0 55.2%
associate-/l*56.4%
Simplified56.4%
Taylor expanded in c around 0 88.0%
if 3.7999999999999998e106 < c Initial program 41.5%
*-un-lft-identity41.5%
add-sqr-sqrt41.5%
times-frac41.5%
hypot-def41.5%
fma-def41.5%
hypot-def60.6%
Applied egg-rr60.6%
associate-*l/60.6%
*-un-lft-identity60.6%
Applied egg-rr60.6%
div-inv60.5%
*-commutative60.5%
fma-udef60.4%
*-commutative60.4%
distribute-lft-in60.4%
*-commutative60.4%
Applied egg-rr60.4%
distribute-lft-out60.4%
fma-def60.5%
associate-*l/60.6%
*-lft-identity60.6%
fma-def60.6%
+-commutative60.6%
fma-def60.6%
*-commutative60.6%
Simplified60.6%
Taylor expanded in d around 0 83.9%
*-commutative83.9%
associate-*r/88.2%
Simplified88.2%
Final simplification89.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (* (/ 1.0 c) (+ a (/ (* b d) c)))))
(if (<= c -1.15e+101)
t_1
(if (<= c -5e-43)
t_0
(if (<= c 5e-141)
(* (/ 1.0 d) (+ b (/ a (/ d c))))
(if (<= c 3.2e+118) 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 = (1.0 / c) * (a + ((b * d) / c));
double tmp;
if (c <= -1.15e+101) {
tmp = t_1;
} else if (c <= -5e-43) {
tmp = t_0;
} else if (c <= 5e-141) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 3.2e+118) {
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 = (1.0d0 / c) * (a + ((b * d) / c))
if (c <= (-1.15d+101)) then
tmp = t_1
else if (c <= (-5d-43)) then
tmp = t_0
else if (c <= 5d-141) then
tmp = (1.0d0 / d) * (b + (a / (d / c)))
else if (c <= 3.2d+118) 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 = (1.0 / c) * (a + ((b * d) / c));
double tmp;
if (c <= -1.15e+101) {
tmp = t_1;
} else if (c <= -5e-43) {
tmp = t_0;
} else if (c <= 5e-141) {
tmp = (1.0 / d) * (b + (a / (d / c)));
} else if (c <= 3.2e+118) {
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 = (1.0 / c) * (a + ((b * d) / c)) tmp = 0 if c <= -1.15e+101: tmp = t_1 elif c <= -5e-43: tmp = t_0 elif c <= 5e-141: tmp = (1.0 / d) * (b + (a / (d / c))) elif c <= 3.2e+118: 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(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))) tmp = 0.0 if (c <= -1.15e+101) tmp = t_1; elseif (c <= -5e-43) tmp = t_0; elseif (c <= 5e-141) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); elseif (c <= 3.2e+118) 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 = (1.0 / c) * (a + ((b * d) / c)); tmp = 0.0; if (c <= -1.15e+101) tmp = t_1; elseif (c <= -5e-43) tmp = t_0; elseif (c <= 5e-141) tmp = (1.0 / d) * (b + (a / (d / c))); elseif (c <= 3.2e+118) 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[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.15e+101], t$95$1, If[LessEqual[c, -5e-43], t$95$0, If[LessEqual[c, 5e-141], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.2e+118], 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{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{if}\;c \leq -1.15 \cdot 10^{+101}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -5 \cdot 10^{-43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 5 \cdot 10^{-141}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{+118}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -1.1500000000000001e101 or 3.20000000000000016e118 < c Initial program 38.8%
*-un-lft-identity38.8%
add-sqr-sqrt38.8%
times-frac38.8%
hypot-def38.8%
fma-def38.8%
hypot-def57.9%
Applied egg-rr57.9%
Taylor expanded in c around inf 61.0%
Taylor expanded in c around inf 88.7%
if -1.1500000000000001e101 < c < -5.00000000000000019e-43 or 4.9999999999999999e-141 < c < 3.20000000000000016e118Initial program 86.6%
if -5.00000000000000019e-43 < c < 4.9999999999999999e-141Initial program 66.5%
*-un-lft-identity66.5%
add-sqr-sqrt66.5%
times-frac66.5%
hypot-def66.5%
fma-def66.5%
hypot-def77.7%
Applied egg-rr77.7%
Taylor expanded in c around 0 55.2%
associate-/l*56.4%
Simplified56.4%
Taylor expanded in c around 0 88.0%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.42e+88) (not (<= d 9e+17))) (/ b d) (* (/ 1.0 c) (+ a (/ (* b d) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.42e+88) || !(d <= 9e+17)) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + ((b * d) / 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 <= (-1.42d+88)) .or. (.not. (d <= 9d+17))) then
tmp = b / d
else
tmp = (1.0d0 / c) * (a + ((b * d) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.42e+88) || !(d <= 9e+17)) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + ((b * d) / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.42e+88) or not (d <= 9e+17): tmp = b / d else: tmp = (1.0 / c) * (a + ((b * d) / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.42e+88) || !(d <= 9e+17)) tmp = Float64(b / d); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.42e+88) || ~((d <= 9e+17))) tmp = b / d; else tmp = (1.0 / c) * (a + ((b * d) / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.42e+88], N[Not[LessEqual[d, 9e+17]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.42 \cdot 10^{+88} \lor \neg \left(d \leq 9 \cdot 10^{+17}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\end{array}
\end{array}
if d < -1.41999999999999996e88 or 9e17 < d Initial program 45.6%
Taylor expanded in c around 0 66.0%
if -1.41999999999999996e88 < d < 9e17Initial program 75.6%
*-un-lft-identity75.6%
add-sqr-sqrt75.6%
times-frac75.6%
hypot-def75.6%
fma-def75.6%
hypot-def83.3%
Applied egg-rr83.3%
Taylor expanded in c around inf 46.3%
Taylor expanded in c around inf 78.6%
Final simplification73.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.45e-43) (not (<= c 1.36e+37))) (* (/ 1.0 c) (+ a (/ (* b d) c))) (* (/ 1.0 d) (+ b (/ a (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.45e-43) || !(c <= 1.36e+37)) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else {
tmp = (1.0 / d) * (b + (a / (d / 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.45d-43)) .or. (.not. (c <= 1.36d+37))) then
tmp = (1.0d0 / c) * (a + ((b * d) / c))
else
tmp = (1.0d0 / d) * (b + (a / (d / c)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.45e-43) || !(c <= 1.36e+37)) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else {
tmp = (1.0 / d) * (b + (a / (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.45e-43) or not (c <= 1.36e+37): tmp = (1.0 / c) * (a + ((b * d) / c)) else: tmp = (1.0 / d) * (b + (a / (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.45e-43) || !(c <= 1.36e+37)) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.45e-43) || ~((c <= 1.36e+37))) tmp = (1.0 / c) * (a + ((b * d) / c)); else tmp = (1.0 / d) * (b + (a / (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.45e-43], N[Not[LessEqual[c, 1.36e+37]], $MachinePrecision]], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{-43} \lor \neg \left(c \leq 1.36 \cdot 10^{+37}\right):\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\
\end{array}
\end{array}
if c < -2.44999999999999994e-43 or 1.3599999999999999e37 < c Initial program 55.1%
*-un-lft-identity55.1%
add-sqr-sqrt55.1%
times-frac55.1%
hypot-def55.1%
fma-def55.1%
hypot-def71.0%
Applied egg-rr71.0%
Taylor expanded in c around inf 48.5%
Taylor expanded in c around inf 81.9%
if -2.44999999999999994e-43 < c < 1.3599999999999999e37Initial program 73.5%
*-un-lft-identity73.5%
add-sqr-sqrt73.4%
times-frac73.4%
hypot-def73.4%
fma-def73.4%
hypot-def82.5%
Applied egg-rr82.5%
Taylor expanded in c around 0 51.8%
associate-/l*52.7%
Simplified52.7%
Taylor expanded in c around 0 81.9%
Final simplification81.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -600.0) (not (<= c 6.5e+36))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -600.0) || !(c <= 6.5e+36)) {
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 ((c <= (-600.0d0)) .or. (.not. (c <= 6.5d+36))) 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 ((c <= -600.0) || !(c <= 6.5e+36)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -600.0) or not (c <= 6.5e+36): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -600.0) || !(c <= 6.5e+36)) 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 ((c <= -600.0) || ~((c <= 6.5e+36))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -600.0], N[Not[LessEqual[c, 6.5e+36]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -600 \lor \neg \left(c \leq 6.5 \cdot 10^{+36}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -600 or 6.4999999999999998e36 < c Initial program 52.5%
Taylor expanded in c around inf 73.1%
if -600 < c < 6.4999999999999998e36Initial program 74.5%
Taylor expanded in c around 0 57.6%
Final simplification64.6%
(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.5%
Taylor expanded in c around inf 45.5%
Final simplification45.5%
(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 2023305
(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))))