
(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 (<= c -6.6e+111)
(fma (/ d c) (/ b c) (/ a c))
(if (<= c -1.16e-102)
(/ (+ (* c a) (* d b)) (+ (* c c) (* d d)))
(if (<= c 6.8e+57) (/ (fma a (/ c d) b) d) (/ (fma b (/ d c) a) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.6e+111) {
tmp = fma((d / c), (b / c), (a / c));
} else if (c <= -1.16e-102) {
tmp = ((c * a) + (d * b)) / ((c * c) + (d * d));
} else if (c <= 6.8e+57) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = fma(b, (d / c), a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -6.6e+111) tmp = fma(Float64(d / c), Float64(b / c), Float64(a / c)); elseif (c <= -1.16e-102) tmp = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 6.8e+57) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = Float64(fma(b, Float64(d / c), a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.6e+111], N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.16e-102], N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.8e+57], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.6 \cdot 10^{+111}:\\
\;\;\;\;\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{c}\right)\\
\mathbf{elif}\;c \leq -1.16 \cdot 10^{-102}:\\
\;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{+57}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\end{array}
\end{array}
if c < -6.6000000000000002e111Initial program 38.0%
Taylor expanded in d around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6483.7
Simplified83.7%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
lift-*.f64N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6487.9
Applied egg-rr87.9%
if -6.6000000000000002e111 < c < -1.1599999999999999e-102Initial program 95.7%
if -1.1599999999999999e-102 < c < 6.79999999999999984e57Initial program 68.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6487.0
Simplified87.0%
if 6.79999999999999984e57 < c Initial program 54.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6490.3
Simplified90.3%
Final simplification89.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma b (/ d c) a) c)))
(if (<= c -6.6e+111)
t_0
(if (<= c -1.16e-102)
(/ (+ (* c a) (* d b)) (+ (* c c) (* d d)))
(if (<= c 6.8e+57) (/ (fma a (/ c d) b) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -6.6e+111) {
tmp = t_0;
} else if (c <= -1.16e-102) {
tmp = ((c * a) + (d * b)) / ((c * c) + (d * d));
} else if (c <= 6.8e+57) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -6.6e+111) tmp = t_0; elseif (c <= -1.16e-102) tmp = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 6.8e+57) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.6e+111], t$95$0, If[LessEqual[c, -1.16e-102], N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.8e+57], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -6.6 \cdot 10^{+111}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.16 \cdot 10^{-102}:\\
\;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{+57}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6.6000000000000002e111 or 6.79999999999999984e57 < c Initial program 45.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.0
Simplified89.0%
if -6.6000000000000002e111 < c < -1.1599999999999999e-102Initial program 95.7%
if -1.1599999999999999e-102 < c < 6.79999999999999984e57Initial program 68.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6487.0
Simplified87.0%
Final simplification89.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.1e+111)
(/ a c)
(if (<= c -9.6e-100)
(/ (* c a) (fma d d (* c c)))
(if (<= c 2e+93) (/ (fma a (/ c d) b) d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.1e+111) {
tmp = a / c;
} else if (c <= -9.6e-100) {
tmp = (c * a) / fma(d, d, (c * c));
} else if (c <= 2e+93) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -4.1e+111) tmp = Float64(a / c); elseif (c <= -9.6e-100) tmp = Float64(Float64(c * a) / fma(d, d, Float64(c * c))); elseif (c <= 2e+93) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.1e+111], N[(a / c), $MachinePrecision], If[LessEqual[c, -9.6e-100], N[(N[(c * a), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2e+93], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.1 \cdot 10^{+111}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -9.6 \cdot 10^{-100}:\\
\;\;\;\;\frac{c \cdot a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 2 \cdot 10^{+93}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.09999999999999986e111 or 2.00000000000000009e93 < c Initial program 43.4%
Taylor expanded in c around inf
lower-/.f6484.9
Simplified84.9%
if -4.09999999999999986e111 < c < -9.600000000000001e-100Initial program 95.7%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.8
Simplified64.8%
if -9.600000000000001e-100 < c < 2.00000000000000009e93Initial program 69.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6485.2
Simplified85.2%
Final simplification80.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.1e+111)
(/ a c)
(if (<= c -1.55e-146)
(/ (* c a) (fma d d (* c c)))
(if (<= c 2e+93) (/ b (fma c (/ c d) d)) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.1e+111) {
tmp = a / c;
} else if (c <= -1.55e-146) {
tmp = (c * a) / fma(d, d, (c * c));
} else if (c <= 2e+93) {
tmp = b / fma(c, (c / d), d);
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -4.1e+111) tmp = Float64(a / c); elseif (c <= -1.55e-146) tmp = Float64(Float64(c * a) / fma(d, d, Float64(c * c))); elseif (c <= 2e+93) tmp = Float64(b / fma(c, Float64(c / d), d)); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.1e+111], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.55e-146], N[(N[(c * a), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2e+93], N[(b / N[(c * N[(c / d), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.1 \cdot 10^{+111}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.55 \cdot 10^{-146}:\\
\;\;\;\;\frac{c \cdot a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 2 \cdot 10^{+93}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.09999999999999986e111 or 2.00000000000000009e93 < c Initial program 43.4%
Taylor expanded in c around inf
lower-/.f6484.9
Simplified84.9%
if -4.09999999999999986e111 < c < -1.5499999999999999e-146Initial program 92.8%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6463.6
Simplified63.6%
if -1.5499999999999999e-146 < c < 2.00000000000000009e93Initial program 69.3%
Taylor expanded in a around 0
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6448.3
Simplified48.3%
lift-*.f64N/A
lift-fma.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6455.5
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-fma.f6455.5
Applied egg-rr55.5%
Taylor expanded in c around 0
+-commutativeN/A
unpow2N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6472.2
Simplified72.2%
Final simplification74.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma a (/ c d) b) d))) (if (<= d -1.25e-21) t_0 (if (<= d 0.0068) (/ (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 <= -1.25e-21) {
tmp = t_0;
} else if (d <= 0.0068) {
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 <= -1.25e-21) tmp = t_0; elseif (d <= 0.0068) 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, -1.25e-21], t$95$0, If[LessEqual[d, 0.0068], 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 -1.25 \cdot 10^{-21}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 0.0068:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.24999999999999993e-21 or 0.00679999999999999962 < d Initial program 58.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.2
Simplified81.2%
if -1.24999999999999993e-21 < d < 0.00679999999999999962Initial program 75.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6485.8
Simplified85.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.1e+111)
(/ a c)
(if (<= c -1.55e-146)
(/ (* c a) (fma d d (* c c)))
(if (<= c 2e+93) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.1e+111) {
tmp = a / c;
} else if (c <= -1.55e-146) {
tmp = (c * a) / fma(d, d, (c * c));
} else if (c <= 2e+93) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -4.1e+111) tmp = Float64(a / c); elseif (c <= -1.55e-146) tmp = Float64(Float64(c * a) / fma(d, d, Float64(c * c))); elseif (c <= 2e+93) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.1e+111], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.55e-146], N[(N[(c * a), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2e+93], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.1 \cdot 10^{+111}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.55 \cdot 10^{-146}:\\
\;\;\;\;\frac{c \cdot a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 2 \cdot 10^{+93}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.09999999999999986e111 or 2.00000000000000009e93 < c Initial program 43.4%
Taylor expanded in c around inf
lower-/.f6484.9
Simplified84.9%
if -4.09999999999999986e111 < c < -1.5499999999999999e-146Initial program 92.8%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6463.6
Simplified63.6%
if -1.5499999999999999e-146 < c < 2.00000000000000009e93Initial program 69.3%
Taylor expanded in c around 0
lower-/.f6465.1
Simplified65.1%
Final simplification70.9%
(FPCore (a b c d) :precision binary64 (if (<= d -6e+74) (/ b d) (if (<= d 0.0068) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6e+74) {
tmp = b / d;
} else if (d <= 0.0068) {
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 <= (-6d+74)) then
tmp = b / d
else if (d <= 0.0068d0) 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 <= -6e+74) {
tmp = b / d;
} else if (d <= 0.0068) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -6e+74: tmp = b / d elif d <= 0.0068: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -6e+74) tmp = Float64(b / d); elseif (d <= 0.0068) 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 <= -6e+74) tmp = b / d; elseif (d <= 0.0068) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -6e+74], N[(b / d), $MachinePrecision], If[LessEqual[d, 0.0068], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6 \cdot 10^{+74}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 0.0068:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -6e74 or 0.00679999999999999962 < d Initial program 58.8%
Taylor expanded in c around 0
lower-/.f6472.3
Simplified72.3%
if -6e74 < d < 0.00679999999999999962Initial program 72.3%
Taylor expanded in c around inf
lower-/.f6463.1
Simplified63.1%
(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 66.6%
Taylor expanded in c around inf
lower-/.f6442.6
Simplified42.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024207
(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))))