
(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 9 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 (fma (/ c d) (/ a d) (/ b d))))
(if (<= d -1e-7)
t_0
(if (<= d 2.2e-112)
(/ (fma (/ d c) b a) c)
(if (<= d 2.3e+154) (/ (+ (* b d) (* a c)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((c / d), (a / d), (b / d));
double tmp;
if (d <= -1e-7) {
tmp = t_0;
} else if (d <= 2.2e-112) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 2.3e+154) {
tmp = ((b * d) + (a * c)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(c / d), Float64(a / d), Float64(b / d)) tmp = 0.0 if (d <= -1e-7) tmp = t_0; elseif (d <= 2.2e-112) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 2.3e+154) tmp = Float64(Float64(Float64(b * d) + Float64(a * c)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1e-7], t$95$0, If[LessEqual[d, 2.2e-112], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.3e+154], N[(N[(N[(b * d), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -1 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{-112}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{+154}:\\
\;\;\;\;\frac{b \cdot d + a \cdot c}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -9.9999999999999995e-8 or 2.3e154 < d Initial program 34.1%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6474.1
Applied rewrites74.1%
Applied rewrites81.2%
if -9.9999999999999995e-8 < d < 2.20000000000000021e-112Initial program 67.4%
Taylor expanded in c around inf
lower-/.f6468.8
Applied rewrites68.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.7
Applied rewrites90.7%
if 2.20000000000000021e-112 < d < 2.3e154Initial program 80.9%
Final simplification84.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -1e-7)
(/ (fma (/ a d) c b) d)
(if (<= d 2.2e-112)
(/ (fma (/ d c) b a) c)
(if (<= d 2.3e+154)
(/ (+ (* b d) (* a c)) (+ (* d d) (* c c)))
(/ (fma (/ c d) a b) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1e-7) {
tmp = fma((a / d), c, b) / d;
} else if (d <= 2.2e-112) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 2.3e+154) {
tmp = ((b * d) + (a * c)) / ((d * d) + (c * c));
} else {
tmp = fma((c / d), a, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1e-7) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (d <= 2.2e-112) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 2.3e+154) tmp = Float64(Float64(Float64(b * d) + Float64(a * c)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = Float64(fma(Float64(c / d), a, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1e-7], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.2e-112], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.3e+154], N[(N[(N[(b * d), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1 \cdot 10^{-7}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{-112}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{+154}:\\
\;\;\;\;\frac{b \cdot d + a \cdot c}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\end{array}
\end{array}
if d < -9.9999999999999995e-8Initial program 41.4%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.8
Applied rewrites80.8%
if -9.9999999999999995e-8 < d < 2.20000000000000021e-112Initial program 67.4%
Taylor expanded in c around inf
lower-/.f6468.8
Applied rewrites68.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.7
Applied rewrites90.7%
if 2.20000000000000021e-112 < d < 2.3e154Initial program 80.9%
if 2.3e154 < d Initial program 23.8%
Taylor expanded in c around inf
lower-/.f6424.7
Applied rewrites24.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.5
Applied rewrites81.5%
Final simplification84.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -7.5e+102)
(/ a c)
(if (<= c -3.1e-226)
(/ b d)
(if (<= c 1.18e-20) (/ (fma c a (* b d)) (* d d)) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e+102) {
tmp = a / c;
} else if (c <= -3.1e-226) {
tmp = b / d;
} else if (c <= 1.18e-20) {
tmp = fma(c, a, (b * d)) / (d * d);
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e+102) tmp = Float64(a / c); elseif (c <= -3.1e-226) tmp = Float64(b / d); elseif (c <= 1.18e-20) tmp = Float64(fma(c, a, Float64(b * d)) / Float64(d * d)); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e+102], N[(a / c), $MachinePrecision], If[LessEqual[c, -3.1e-226], N[(b / d), $MachinePrecision], If[LessEqual[c, 1.18e-20], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -3.1 \cdot 10^{-226}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.18 \cdot 10^{-20}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -7.5e102 or 1.1800000000000001e-20 < c Initial program 46.7%
Taylor expanded in c around inf
lower-/.f6473.4
Applied rewrites73.4%
if -7.5e102 < c < -3.09999999999999989e-226Initial program 61.3%
Taylor expanded in c around 0
lower-/.f6452.2
Applied rewrites52.2%
if -3.09999999999999989e-226 < c < 1.1800000000000001e-20Initial program 79.0%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6436.2
Applied rewrites36.2%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6432.3
Applied rewrites32.3%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6468.9
Applied rewrites68.9%
Final simplification66.6%
(FPCore (a b c d)
:precision binary64
(if (<= c -7.5e+102)
(/ a c)
(if (<= c 5e-140)
(/ b d)
(if (<= c 2e+49) (* (/ c (fma c c (* d d))) a) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e+102) {
tmp = a / c;
} else if (c <= 5e-140) {
tmp = b / d;
} else if (c <= 2e+49) {
tmp = (c / fma(c, c, (d * d))) * a;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e+102) tmp = Float64(a / c); elseif (c <= 5e-140) tmp = Float64(b / d); elseif (c <= 2e+49) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * a); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e+102], N[(a / c), $MachinePrecision], If[LessEqual[c, 5e-140], N[(b / d), $MachinePrecision], If[LessEqual[c, 2e+49], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{-140}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 2 \cdot 10^{+49}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot a\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -7.5e102 or 1.99999999999999989e49 < c Initial program 43.9%
Taylor expanded in c around inf
lower-/.f6476.3
Applied rewrites76.3%
if -7.5e102 < c < 5.00000000000000015e-140Initial program 68.5%
Taylor expanded in c around 0
lower-/.f6459.0
Applied rewrites59.0%
if 5.00000000000000015e-140 < c < 1.99999999999999989e49Initial program 79.4%
Taylor expanded in c around inf
lower-/.f6429.7
Applied rewrites29.7%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6456.6
Applied rewrites56.6%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma (/ b c) d a) c))) (if (<= c -4.4e+102) t_0 (if (<= c 8e+46) (/ (fma (/ c d) a b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / c), d, a) / c;
double tmp;
if (c <= -4.4e+102) {
tmp = t_0;
} else if (c <= 8e+46) {
tmp = fma((c / d), a, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -4.4e+102) tmp = t_0; elseif (c <= 8e+46) tmp = Float64(fma(Float64(c / d), a, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.4e+102], t$95$0, If[LessEqual[c, 8e+46], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -4.4 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+46}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.40000000000000015e102 or 7.9999999999999999e46 < c Initial program 43.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6485.5
Applied rewrites85.5%
if -4.40000000000000015e102 < c < 7.9999999999999999e46Initial program 70.9%
Taylor expanded in c around inf
lower-/.f6423.2
Applied rewrites23.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6476.5
Applied rewrites76.5%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma (/ b c) d a) c))) (if (<= c -4.4e+102) t_0 (if (<= c 8e+46) (/ (fma (/ a d) c b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / c), d, a) / c;
double tmp;
if (c <= -4.4e+102) {
tmp = t_0;
} else if (c <= 8e+46) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -4.4e+102) tmp = t_0; elseif (c <= 8e+46) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.4e+102], t$95$0, If[LessEqual[c, 8e+46], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -4.4 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+46}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.40000000000000015e102 or 7.9999999999999999e46 < c Initial program 43.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6485.5
Applied rewrites85.5%
if -4.40000000000000015e102 < c < 7.9999999999999999e46Initial program 70.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6473.5
Applied rewrites73.5%
(FPCore (a b c d) :precision binary64 (if (<= c -7.5e+102) (/ a c) (if (<= c 6.5e+132) (/ (fma (/ a d) c b) d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e+102) {
tmp = a / c;
} else if (c <= 6.5e+132) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e+102) tmp = Float64(a / c); elseif (c <= 6.5e+132) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e+102], N[(a / c), $MachinePrecision], If[LessEqual[c, 6.5e+132], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 6.5 \cdot 10^{+132}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -7.5e102 or 6.4999999999999994e132 < c Initial program 41.8%
Taylor expanded in c around inf
lower-/.f6481.0
Applied rewrites81.0%
if -7.5e102 < c < 6.4999999999999994e132Initial program 69.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
(FPCore (a b c d) :precision binary64 (if (<= c -7.5e+102) (/ a c) (if (<= c 7.8e-22) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e+102) {
tmp = a / c;
} else if (c <= 7.8e-22) {
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 <= (-7.5d+102)) then
tmp = a / c
else if (c <= 7.8d-22) 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 <= -7.5e+102) {
tmp = a / c;
} else if (c <= 7.8e-22) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -7.5e+102: tmp = a / c elif c <= 7.8e-22: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e+102) tmp = Float64(a / c); elseif (c <= 7.8e-22) 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 <= -7.5e+102) tmp = a / c; elseif (c <= 7.8e-22) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e+102], N[(a / c), $MachinePrecision], If[LessEqual[c, 7.8e-22], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{-22}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -7.5e102 or 7.79999999999999996e-22 < c Initial program 46.7%
Taylor expanded in c around inf
lower-/.f6473.4
Applied rewrites73.4%
if -7.5e102 < c < 7.79999999999999996e-22Initial program 70.7%
Taylor expanded in c around 0
lower-/.f6456.4
Applied rewrites56.4%
(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 59.8%
Taylor expanded in c around inf
lower-/.f6445.0
Applied rewrites45.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 2024271
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))