
(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 7 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) (* d b))) (t_1 (+ (* c c) (* d d))))
(if (<= d -6.2e+104)
(/ (+ b (* a (/ c d))) d)
(if (<= d -5.6e-117)
(/ t_0 t_1)
(if (<= d 3.3e-125)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 2.6e+134)
(/ 1.0 (/ t_1 t_0))
(/ (+ b (/ a (/ 1.0 (/ c d)))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (d * b);
double t_1 = (c * c) + (d * d);
double tmp;
if (d <= -6.2e+104) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -5.6e-117) {
tmp = t_0 / t_1;
} else if (d <= 3.3e-125) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.6e+134) {
tmp = 1.0 / (t_1 / t_0);
} else {
tmp = (b + (a / (1.0 / (c / d)))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (a * c) + (d * b)
t_1 = (c * c) + (d * d)
if (d <= (-6.2d+104)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-5.6d-117)) then
tmp = t_0 / t_1
else if (d <= 3.3d-125) then
tmp = (a + ((d * b) / c)) / c
else if (d <= 2.6d+134) then
tmp = 1.0d0 / (t_1 / t_0)
else
tmp = (b + (a / (1.0d0 / (c / d)))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (d * b);
double t_1 = (c * c) + (d * d);
double tmp;
if (d <= -6.2e+104) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -5.6e-117) {
tmp = t_0 / t_1;
} else if (d <= 3.3e-125) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.6e+134) {
tmp = 1.0 / (t_1 / t_0);
} else {
tmp = (b + (a / (1.0 / (c / d)))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a * c) + (d * b) t_1 = (c * c) + (d * d) tmp = 0 if d <= -6.2e+104: tmp = (b + (a * (c / d))) / d elif d <= -5.6e-117: tmp = t_0 / t_1 elif d <= 3.3e-125: tmp = (a + ((d * b) / c)) / c elif d <= 2.6e+134: tmp = 1.0 / (t_1 / t_0) else: tmp = (b + (a / (1.0 / (c / d)))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a * c) + Float64(d * b)) t_1 = Float64(Float64(c * c) + Float64(d * d)) tmp = 0.0 if (d <= -6.2e+104) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -5.6e-117) tmp = Float64(t_0 / t_1); elseif (d <= 3.3e-125) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 2.6e+134) tmp = Float64(1.0 / Float64(t_1 / t_0)); else tmp = Float64(Float64(b + Float64(a / Float64(1.0 / Float64(c / d)))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a * c) + (d * b); t_1 = (c * c) + (d * d); tmp = 0.0; if (d <= -6.2e+104) tmp = (b + (a * (c / d))) / d; elseif (d <= -5.6e-117) tmp = t_0 / t_1; elseif (d <= 3.3e-125) tmp = (a + ((d * b) / c)) / c; elseif (d <= 2.6e+134) tmp = 1.0 / (t_1 / t_0); else tmp = (b + (a / (1.0 / (c / d)))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.2e+104], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -5.6e-117], N[(t$95$0 / t$95$1), $MachinePrecision], If[LessEqual[d, 3.3e-125], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.6e+134], N[(1.0 / N[(t$95$1 / t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot c + d \cdot b\\
t_1 := c \cdot c + d \cdot d\\
\mathbf{if}\;d \leq -6.2 \cdot 10^{+104}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -5.6 \cdot 10^{-117}:\\
\;\;\;\;\frac{t\_0}{t\_1}\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{-125}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{+134}:\\
\;\;\;\;\frac{1}{\frac{t\_1}{t\_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\
\end{array}
\end{array}
if d < -6.20000000000000033e104Initial program 49.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6491.5%
Simplified91.5%
if -6.20000000000000033e104 < d < -5.6e-117Initial program 73.8%
if -5.6e-117 < d < 3.3000000000000001e-125Initial program 78.1%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6495.0%
Simplified95.0%
if 3.3000000000000001e-125 < d < 2.6000000000000002e134Initial program 83.7%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6483.8%
Applied egg-rr83.8%
if 2.6000000000000002e134 < d Initial program 34.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6492.0%
Simplified92.0%
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f6492.0%
Applied egg-rr92.0%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f6492.0%
Applied egg-rr92.0%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* d b)) (+ (* c c) (* d d)))))
(if (<= d -4e+104)
(/ (+ b (* a (/ c d))) d)
(if (<= d -5.6e-117)
t_0
(if (<= d 3.9e-125)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 1.45e+136) t_0 (/ (+ b (/ a (/ 1.0 (/ c d)))) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d));
double tmp;
if (d <= -4e+104) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -5.6e-117) {
tmp = t_0;
} else if (d <= 3.9e-125) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 1.45e+136) {
tmp = t_0;
} else {
tmp = (b + (a / (1.0 / (c / d)))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d))
if (d <= (-4d+104)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-5.6d-117)) then
tmp = t_0
else if (d <= 3.9d-125) then
tmp = (a + ((d * b) / c)) / c
else if (d <= 1.45d+136) then
tmp = t_0
else
tmp = (b + (a / (1.0d0 / (c / d)))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d));
double tmp;
if (d <= -4e+104) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -5.6e-117) {
tmp = t_0;
} else if (d <= 3.9e-125) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 1.45e+136) {
tmp = t_0;
} else {
tmp = (b + (a / (1.0 / (c / d)))) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d)) tmp = 0 if d <= -4e+104: tmp = (b + (a * (c / d))) / d elif d <= -5.6e-117: tmp = t_0 elif d <= 3.9e-125: tmp = (a + ((d * b) / c)) / c elif d <= 1.45e+136: tmp = t_0 else: tmp = (b + (a / (1.0 / (c / d)))) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -4e+104) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -5.6e-117) tmp = t_0; elseif (d <= 3.9e-125) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 1.45e+136) tmp = t_0; else tmp = Float64(Float64(b + Float64(a / Float64(1.0 / Float64(c / d)))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -4e+104) tmp = (b + (a * (c / d))) / d; elseif (d <= -5.6e-117) tmp = t_0; elseif (d <= 3.9e-125) tmp = (a + ((d * b) / c)) / c; elseif (d <= 1.45e+136) tmp = t_0; else tmp = (b + (a / (1.0 / (c / d)))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4e+104], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -5.6e-117], t$95$0, If[LessEqual[d, 3.9e-125], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.45e+136], t$95$0, N[(N[(b + N[(a / N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -4 \cdot 10^{+104}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -5.6 \cdot 10^{-117}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.9 \cdot 10^{-125}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+136}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\
\end{array}
\end{array}
if d < -4e104Initial program 49.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6491.5%
Simplified91.5%
if -4e104 < d < -5.6e-117 or 3.89999999999999982e-125 < d < 1.44999999999999987e136Initial program 78.1%
if -5.6e-117 < d < 3.89999999999999982e-125Initial program 78.1%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6495.0%
Simplified95.0%
if 1.44999999999999987e136 < d Initial program 34.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6492.0%
Simplified92.0%
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f6492.0%
Applied egg-rr92.0%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f6492.0%
Applied egg-rr92.0%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.25e-34)
(/ (+ b (* a (/ c d))) d)
(if (<= d 1.52e-5)
(/ (+ a (/ (* d b) c)) c)
(* (/ 1.0 d) (+ b (* c (/ a d)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.25e-34) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.52e-5) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = (1.0 / d) * (b + (c * (a / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-1.25d-34)) then
tmp = (b + (a * (c / d))) / d
else if (d <= 1.52d-5) then
tmp = (a + ((d * b) / c)) / c
else
tmp = (1.0d0 / d) * (b + (c * (a / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.25e-34) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.52e-5) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = (1.0 / d) * (b + (c * (a / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.25e-34: tmp = (b + (a * (c / d))) / d elif d <= 1.52e-5: tmp = (a + ((d * b) / c)) / c else: tmp = (1.0 / d) * (b + (c * (a / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.25e-34) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= 1.52e-5) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(c * Float64(a / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.25e-34) tmp = (b + (a * (c / d))) / d; elseif (d <= 1.52e-5) tmp = (a + ((d * b) / c)) / c; else tmp = (1.0 / d) * (b + (c * (a / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.25e-34], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.52e-5], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{-34}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 1.52 \cdot 10^{-5}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\
\end{array}
\end{array}
if d < -1.2500000000000001e-34Initial program 56.8%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6477.6%
Simplified77.6%
if -1.2500000000000001e-34 < d < 1.52e-5Initial program 81.1%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6485.7%
Simplified85.7%
if 1.52e-5 < d Initial program 52.5%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6479.6%
Simplified79.6%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6474.7%
Applied egg-rr74.7%
+-commutativeN/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6480.9%
Applied egg-rr80.9%
Final simplification82.0%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (+ b (* a (/ c d))) d))) (if (<= d -6.8e-36) t_0 (if (<= d 6.2e-7) (/ (+ a (/ (* d b) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -6.8e-36) {
tmp = t_0;
} else if (d <= 6.2e-7) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b + (a * (c / d))) / d
if (d <= (-6.8d-36)) then
tmp = t_0
else if (d <= 6.2d-7) then
tmp = (a + ((d * b) / c)) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -6.8e-36) {
tmp = t_0;
} else if (d <= 6.2e-7) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (a * (c / d))) / d tmp = 0 if d <= -6.8e-36: tmp = t_0 elif d <= 6.2e-7: tmp = (a + ((d * b) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -6.8e-36) tmp = t_0; elseif (d <= 6.2e-7) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -6.8e-36) tmp = t_0; elseif (d <= 6.2e-7) tmp = (a + ((d * b) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -6.8e-36], t$95$0, If[LessEqual[d, 6.2e-7], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -6.8 \cdot 10^{-36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{-7}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.8000000000000005e-36 or 6.1999999999999999e-7 < d Initial program 55.0%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6478.5%
Simplified78.5%
if -6.8000000000000005e-36 < d < 6.1999999999999999e-7Initial program 81.1%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6485.7%
Simplified85.7%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (<= d -5.8e-38) (/ b d) (if (<= d 1.22e-8) (/ (+ a (/ (* d b) c)) c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.8e-38) {
tmp = b / d;
} else if (d <= 1.22e-8) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-5.8d-38)) then
tmp = b / d
else if (d <= 1.22d-8) then
tmp = (a + ((d * b) / c)) / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.8e-38) {
tmp = b / d;
} else if (d <= 1.22e-8) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -5.8e-38: tmp = b / d elif d <= 1.22e-8: tmp = (a + ((d * b) / c)) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -5.8e-38) tmp = Float64(b / d); elseif (d <= 1.22e-8) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -5.8e-38) tmp = b / d; elseif (d <= 1.22e-8) tmp = (a + ((d * b) / c)) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.8e-38], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.22e-8], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.8 \cdot 10^{-38}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.22 \cdot 10^{-8}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -5.79999999999999988e-38 or 1.22e-8 < d Initial program 55.6%
Taylor expanded in c around 0
/-lowering-/.f6467.5%
Simplified67.5%
if -5.79999999999999988e-38 < d < 1.22e-8Initial program 80.7%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6486.3%
Simplified86.3%
Final simplification75.7%
(FPCore (a b c d) :precision binary64 (if (<= c -5.6e-14) (/ a c) (if (<= c 1.2e-76) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.6e-14) {
tmp = a / c;
} else if (c <= 1.2e-76) {
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 <= (-5.6d-14)) then
tmp = a / c
else if (c <= 1.2d-76) 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 <= -5.6e-14) {
tmp = a / c;
} else if (c <= 1.2e-76) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.6e-14: tmp = a / c elif c <= 1.2e-76: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.6e-14) tmp = Float64(a / c); elseif (c <= 1.2e-76) 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 <= -5.6e-14) tmp = a / c; elseif (c <= 1.2e-76) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.6e-14], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.2e-76], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.6 \cdot 10^{-14}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{-76}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -5.6000000000000001e-14 or 1.20000000000000007e-76 < c Initial program 57.4%
Taylor expanded in c around inf
/-lowering-/.f6465.4%
Simplified65.4%
if -5.6000000000000001e-14 < c < 1.20000000000000007e-76Initial program 78.1%
Taylor expanded in c around 0
/-lowering-/.f6471.5%
Simplified71.5%
(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
/-lowering-/.f6443.9%
Simplified43.9%
(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 2024161
(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))))