
(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
(if (<= d -0.0001107)
(/ (fma a (/ c d) b) d)
(if (<= d 9.5e-64)
(/ (fma d (/ b c) a) c)
(if (<= d 1.85e+75)
(/ (+ (* a c) (* d b)) (+ (* c c) (* d d)))
(/ (fma (/ a d) c b) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0001107) {
tmp = fma(a, (c / d), b) / d;
} else if (d <= 9.5e-64) {
tmp = fma(d, (b / c), a) / c;
} else if (d <= 1.85e+75) {
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d));
} else {
tmp = fma((a / d), c, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (d <= 9.5e-64) tmp = Float64(fma(d, Float64(b / c), a) / c); elseif (d <= 1.85e+75) tmp = Float64(Float64(Float64(a * c) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(fma(Float64(a / d), c, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 9.5e-64], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.85e+75], N[(N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq 9.5 \cdot 10^{-64}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{+75}:\\
\;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4Initial program 57.4%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6483.3
Applied rewrites83.3%
if -1.10699999999999994e-4 < d < 9.50000000000000043e-64Initial program 70.1%
Taylor expanded in c around inf
lower-/.f6470.1
Applied rewrites70.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6490.9
Applied rewrites90.9%
if 9.50000000000000043e-64 < d < 1.85000000000000005e75Initial program 91.3%
if 1.85000000000000005e75 < d Initial program 52.3%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.0
Applied rewrites89.0%
Applied rewrites90.7%
Final simplification88.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -0.0001107)
(/ b d)
(if (<= d 8.8e-244)
(/ a c)
(if (<= d 2.15e-44)
(/ (fma b d (* a c)) (* c c))
(if (<= d 4.4e+155) (/ (fma c a (* d b)) (* d d)) (/ b d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0001107) {
tmp = b / d;
} else if (d <= 8.8e-244) {
tmp = a / c;
} else if (d <= 2.15e-44) {
tmp = fma(b, d, (a * c)) / (c * c);
} else if (d <= 4.4e+155) {
tmp = fma(c, a, (d * b)) / (d * d);
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(b / d); elseif (d <= 8.8e-244) tmp = Float64(a / c); elseif (d <= 2.15e-44) tmp = Float64(fma(b, d, Float64(a * c)) / Float64(c * c)); elseif (d <= 4.4e+155) tmp = Float64(fma(c, a, Float64(d * b)) / Float64(d * d)); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.15e-44], N[(N[(b * d + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.4e+155], N[(N[(c * a + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{c \cdot c}\\
\mathbf{elif}\;d \leq 4.4 \cdot 10^{+155}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 4.4000000000000005e155 < d Initial program 53.5%
Taylor expanded in c around 0
lower-/.f6478.6
Applied rewrites78.6%
if -1.10699999999999994e-4 < d < 8.79999999999999939e-244Initial program 64.8%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if 8.79999999999999939e-244 < d < 2.15000000000000007e-44Initial program 80.8%
Taylor expanded in c around inf
lower-/.f6464.2
Applied rewrites64.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.0
Applied rewrites89.0%
Taylor expanded in c around 0
Applied rewrites73.9%
if 2.15000000000000007e-44 < d < 4.4000000000000005e155Initial program 79.7%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6465.9
Applied rewrites65.9%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6465.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6465.9
Applied rewrites65.9%
Final simplification74.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma a (/ c d) b) d)))
(if (<= d -0.0001107)
t_0
(if (<= d 8.8e-244)
(/ a c)
(if (<= d 2.15e-44) (/ (fma b d (* a c)) (* c c)) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(a, (c / d), b) / d;
double tmp;
if (d <= -0.0001107) {
tmp = t_0;
} else if (d <= 8.8e-244) {
tmp = a / c;
} else if (d <= 2.15e-44) {
tmp = fma(b, d, (a * c)) / (c * c);
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(a, Float64(c / d), b) / d) tmp = 0.0 if (d <= -0.0001107) tmp = t_0; elseif (d <= 8.8e-244) tmp = Float64(a / c); elseif (d <= 2.15e-44) tmp = Float64(fma(b, d, Float64(a * c)) / Float64(c * c)); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -0.0001107], t$95$0, If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.15e-44], N[(N[(b * d + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 2.15000000000000007e-44 < d Initial program 59.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.9
Applied rewrites82.9%
if -1.10699999999999994e-4 < d < 8.79999999999999939e-244Initial program 64.8%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if 8.79999999999999939e-244 < d < 2.15000000000000007e-44Initial program 80.8%
Taylor expanded in c around inf
lower-/.f6464.2
Applied rewrites64.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.0
Applied rewrites89.0%
Taylor expanded in c around 0
Applied rewrites73.9%
Final simplification78.5%
(FPCore (a b c d)
:precision binary64
(if (<= d -0.0001107)
(/ b d)
(if (<= d 8.8e-244)
(/ a c)
(if (<= d 1.2e-42) (/ (fma b d (* a c)) (* c c)) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0001107) {
tmp = b / d;
} else if (d <= 8.8e-244) {
tmp = a / c;
} else if (d <= 1.2e-42) {
tmp = fma(b, d, (a * c)) / (c * c);
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(b / d); elseif (d <= 8.8e-244) tmp = Float64(a / c); elseif (d <= 1.2e-42) tmp = Float64(fma(b, d, Float64(a * c)) / Float64(c * c)); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.2e-42], N[(N[(b * d + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.20000000000000001e-42 < d Initial program 59.9%
Taylor expanded in c around 0
lower-/.f6469.3
Applied rewrites69.3%
if -1.10699999999999994e-4 < d < 8.79999999999999939e-244Initial program 64.8%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if 8.79999999999999939e-244 < d < 1.20000000000000001e-42Initial program 80.8%
Taylor expanded in c around inf
lower-/.f6464.2
Applied rewrites64.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.0
Applied rewrites89.0%
Taylor expanded in c around 0
Applied rewrites73.9%
Final simplification71.1%
(FPCore (a b c d) :precision binary64 (if (<= d -0.0001107) (/ (fma a (/ c d) b) d) (if (<= d 1.2e-42) (/ (fma d (/ b c) a) c) (/ (fma (/ a d) c b) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0001107) {
tmp = fma(a, (c / d), b) / d;
} else if (d <= 1.2e-42) {
tmp = fma(d, (b / c), a) / c;
} else {
tmp = fma((a / d), c, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (d <= 1.2e-42) tmp = Float64(fma(d, Float64(b / c), a) / c); else tmp = Float64(fma(Float64(a / d), c, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.2e-42], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4Initial program 57.4%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6483.3
Applied rewrites83.3%
if -1.10699999999999994e-4 < d < 1.20000000000000001e-42Initial program 71.1%
Taylor expanded in c around inf
lower-/.f6469.4
Applied rewrites69.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6490.0
Applied rewrites90.0%
if 1.20000000000000001e-42 < d Initial program 62.4%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
Applied rewrites83.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma a (/ c d) b) d))) (if (<= d -0.0001107) t_0 (if (<= d 1.2e-42) (/ (fma d (/ b c) a) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(a, (c / d), b) / d;
double tmp;
if (d <= -0.0001107) {
tmp = t_0;
} else if (d <= 1.2e-42) {
tmp = fma(d, (b / c), a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(a, Float64(c / d), b) / d) tmp = 0.0 if (d <= -0.0001107) tmp = t_0; elseif (d <= 1.2e-42) tmp = Float64(fma(d, Float64(b / c), a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -0.0001107], t$95$0, If[LessEqual[d, 1.2e-42], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.20000000000000001e-42 < d Initial program 59.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.9
Applied rewrites82.9%
if -1.10699999999999994e-4 < d < 1.20000000000000001e-42Initial program 71.1%
Taylor expanded in c around inf
lower-/.f6469.4
Applied rewrites69.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6490.0
Applied rewrites90.0%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma a (/ c d) b) d))) (if (<= d -0.0001107) t_0 (if (<= d 1.2e-42) (/ (fma b (/ d c) a) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(a, (c / d), b) / d;
double tmp;
if (d <= -0.0001107) {
tmp = t_0;
} else if (d <= 1.2e-42) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(a, Float64(c / d), b) / d) tmp = 0.0 if (d <= -0.0001107) tmp = t_0; elseif (d <= 1.2e-42) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -0.0001107], t$95$0, If[LessEqual[d, 1.2e-42], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.20000000000000001e-42 < d Initial program 59.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.9
Applied rewrites82.9%
if -1.10699999999999994e-4 < d < 1.20000000000000001e-42Initial program 71.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.2
Applied rewrites89.2%
(FPCore (a b c d) :precision binary64 (if (<= d -0.0001107) (/ b d) (if (<= d 1.15e-54) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.0001107) {
tmp = b / d;
} else if (d <= 1.15e-54) {
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 <= (-0.0001107d0)) then
tmp = b / d
else if (d <= 1.15d-54) 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 <= -0.0001107) {
tmp = b / d;
} else if (d <= 1.15e-54) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -0.0001107: tmp = b / d elif d <= 1.15e-54: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -0.0001107) tmp = Float64(b / d); elseif (d <= 1.15e-54) 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 <= -0.0001107) tmp = b / d; elseif (d <= 1.15e-54) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.15e-54], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0001107:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.15 \cdot 10^{-54}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.10699999999999994e-4 or 1.1499999999999999e-54 < d Initial program 60.2%
Taylor expanded in c around 0
lower-/.f6468.9
Applied rewrites68.9%
if -1.10699999999999994e-4 < d < 1.1499999999999999e-54Initial program 70.9%
Taylor expanded in c around inf
lower-/.f6470.0
Applied rewrites70.0%
(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 65.0%
Taylor expanded in c around inf
lower-/.f6442.5
Applied rewrites42.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 2024235
(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))))