
(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
(let* ((t_0 (/ (+ b (* c (/ a d))) d)))
(if (<= d -4e+80)
t_0
(if (<= d -8.8e-112)
(/ (fma a c (* d b)) (fma c c (* d d)))
(if (<= d 3.5e-164)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 2.8e+25)
(/ (+ (* d b) (* c a)) (+ (* d d) (* c c)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (c * (a / d))) / d;
double tmp;
if (d <= -4e+80) {
tmp = t_0;
} else if (d <= -8.8e-112) {
tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
} else if (d <= 3.5e-164) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.8e+25) {
tmp = ((d * b) + (c * a)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(c * Float64(a / d))) / d) tmp = 0.0 if (d <= -4e+80) tmp = t_0; elseif (d <= -8.8e-112) tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d))); elseif (d <= 3.5e-164) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 2.8e+25) tmp = Float64(Float64(Float64(d * b) + Float64(c * a)) / 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[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -4e+80], t$95$0, If[LessEqual[d, -8.8e-112], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.5e-164], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.8e+25], N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -4 \cdot 10^{+80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -8.8 \cdot 10^{-112}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{-164}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{+25}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4e80 or 2.8000000000000002e25 < d Initial program 40.9%
fma-define40.9%
fma-define40.9%
Simplified40.9%
Taylor expanded in d around inf 80.7%
*-commutative80.7%
associate-/l*83.1%
Applied egg-rr83.1%
if -4e80 < d < -8.80000000000000085e-112Initial program 94.3%
fma-define94.3%
fma-define94.3%
Simplified94.3%
if -8.80000000000000085e-112 < d < 3.5e-164Initial program 59.4%
fma-define59.4%
fma-define59.4%
Simplified59.4%
Taylor expanded in c around inf 92.7%
*-commutative92.7%
Simplified92.7%
if 3.5e-164 < d < 2.8000000000000002e25Initial program 76.9%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* d d) (* c c))))
(t_1 (/ (+ b (* c (/ a d))) d)))
(if (<= d -1.8e+80)
t_1
(if (<= d -2.55e-112)
t_0
(if (<= d 3.5e-164)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 2.8e+25) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((d * b) + (c * a)) / ((d * d) + (c * c));
double t_1 = (b + (c * (a / d))) / d;
double tmp;
if (d <= -1.8e+80) {
tmp = t_1;
} else if (d <= -2.55e-112) {
tmp = t_0;
} else if (d <= 3.5e-164) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.8e+25) {
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 = ((d * b) + (c * a)) / ((d * d) + (c * c))
t_1 = (b + (c * (a / d))) / d
if (d <= (-1.8d+80)) then
tmp = t_1
else if (d <= (-2.55d-112)) then
tmp = t_0
else if (d <= 3.5d-164) then
tmp = (a + ((d * b) / c)) / c
else if (d <= 2.8d+25) 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 = ((d * b) + (c * a)) / ((d * d) + (c * c));
double t_1 = (b + (c * (a / d))) / d;
double tmp;
if (d <= -1.8e+80) {
tmp = t_1;
} else if (d <= -2.55e-112) {
tmp = t_0;
} else if (d <= 3.5e-164) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.8e+25) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((d * b) + (c * a)) / ((d * d) + (c * c)) t_1 = (b + (c * (a / d))) / d tmp = 0 if d <= -1.8e+80: tmp = t_1 elif d <= -2.55e-112: tmp = t_0 elif d <= 3.5e-164: tmp = (a + ((d * b) / c)) / c elif d <= 2.8e+25: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))) t_1 = Float64(Float64(b + Float64(c * Float64(a / d))) / d) tmp = 0.0 if (d <= -1.8e+80) tmp = t_1; elseif (d <= -2.55e-112) tmp = t_0; elseif (d <= 3.5e-164) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 2.8e+25) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((d * b) + (c * a)) / ((d * d) + (c * c)); t_1 = (b + (c * (a / d))) / d; tmp = 0.0; if (d <= -1.8e+80) tmp = t_1; elseif (d <= -2.55e-112) tmp = t_0; elseif (d <= 3.5e-164) tmp = (a + ((d * b) / c)) / c; elseif (d <= 2.8e+25) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.8e+80], t$95$1, If[LessEqual[d, -2.55e-112], t$95$0, If[LessEqual[d, 3.5e-164], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.8e+25], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
t_1 := \frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -1.8 \cdot 10^{+80}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.55 \cdot 10^{-112}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{-164}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{+25}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.79999999999999997e80 or 2.8000000000000002e25 < d Initial program 40.9%
fma-define40.9%
fma-define40.9%
Simplified40.9%
Taylor expanded in d around inf 80.7%
*-commutative80.7%
associate-/l*83.1%
Applied egg-rr83.1%
if -1.79999999999999997e80 < d < -2.55000000000000007e-112 or 3.5e-164 < d < 2.8000000000000002e25Initial program 84.1%
if -2.55000000000000007e-112 < d < 3.5e-164Initial program 59.4%
fma-define59.4%
fma-define59.4%
Simplified59.4%
Taylor expanded in c around inf 92.7%
*-commutative92.7%
Simplified92.7%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(if (<= c -7.5e+72)
(/ (+ a (/ d (/ c b))) c)
(if (<= c 4e+36)
(/ (+ b (* a (/ c d))) d)
(/ (+ a (* b (/ 1.0 (/ c d)))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e+72) {
tmp = (a + (d / (c / b))) / c;
} else if (c <= 4e+36) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (1.0 / (c / 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 <= (-7.5d+72)) then
tmp = (a + (d / (c / b))) / c
else if (c <= 4d+36) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b * (1.0d0 / (c / d)))) / 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+72) {
tmp = (a + (d / (c / b))) / c;
} else if (c <= 4e+36) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (1.0 / (c / d)))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -7.5e+72: tmp = (a + (d / (c / b))) / c elif c <= 4e+36: tmp = (b + (a * (c / d))) / d else: tmp = (a + (b * (1.0 / (c / d)))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e+72) tmp = Float64(Float64(a + Float64(d / Float64(c / b))) / c); elseif (c <= 4e+36) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(1.0 / Float64(c / d)))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -7.5e+72) tmp = (a + (d / (c / b))) / c; elseif (c <= 4e+36) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (1.0 / (c / d)))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e+72], N[(N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 4e+36], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{+72}:\\
\;\;\;\;\frac{a + \frac{d}{\frac{c}{b}}}{c}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{+36}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{1}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -7.50000000000000027e72Initial program 42.6%
fma-define42.6%
fma-define42.6%
Simplified42.6%
Taylor expanded in c around inf 76.0%
*-commutative76.0%
Simplified76.0%
associate-/l*83.4%
*-commutative83.4%
Applied egg-rr83.4%
*-commutative83.4%
clear-num84.6%
un-div-inv84.6%
Applied egg-rr84.6%
if -7.50000000000000027e72 < c < 4.00000000000000017e36Initial program 69.9%
fma-define69.9%
fma-define69.9%
Simplified69.9%
Taylor expanded in d around inf 78.9%
associate-/l*79.1%
Simplified79.1%
if 4.00000000000000017e36 < c Initial program 55.5%
fma-define55.5%
fma-define55.5%
Simplified55.5%
Taylor expanded in c around inf 78.7%
*-commutative78.7%
Simplified78.7%
associate-/l*82.5%
*-commutative82.5%
Applied egg-rr82.5%
*-commutative82.5%
associate-/l*78.7%
clear-num78.7%
associate-/r*82.6%
Applied egg-rr82.6%
associate-/r/82.6%
Simplified82.6%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.2e+72) (not (<= c 1e+31))) (/ (+ a (/ d (/ c b))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.2e+72) || !(c <= 1e+31)) {
tmp = (a + (d / (c / b))) / c;
} else {
tmp = (b + (a * (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) :: tmp
if ((c <= (-4.2d+72)) .or. (.not. (c <= 1d+31))) then
tmp = (a + (d / (c / b))) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.2e+72) || !(c <= 1e+31)) {
tmp = (a + (d / (c / b))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.2e+72) or not (c <= 1e+31): tmp = (a + (d / (c / b))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.2e+72) || !(c <= 1e+31)) tmp = Float64(Float64(a + Float64(d / Float64(c / b))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.2e+72) || ~((c <= 1e+31))) tmp = (a + (d / (c / b))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.2e+72], N[Not[LessEqual[c, 1e+31]], $MachinePrecision]], N[(N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.2 \cdot 10^{+72} \lor \neg \left(c \leq 10^{+31}\right):\\
\;\;\;\;\frac{a + \frac{d}{\frac{c}{b}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -4.2000000000000003e72 or 9.9999999999999996e30 < c Initial program 49.0%
fma-define49.0%
fma-define49.0%
Simplified49.0%
Taylor expanded in c around inf 77.4%
*-commutative77.4%
Simplified77.4%
associate-/l*83.0%
*-commutative83.0%
Applied egg-rr83.0%
*-commutative83.0%
clear-num83.6%
un-div-inv83.6%
Applied egg-rr83.6%
if -4.2000000000000003e72 < c < 9.9999999999999996e30Initial program 69.9%
fma-define69.9%
fma-define69.9%
Simplified69.9%
Taylor expanded in d around inf 78.9%
associate-/l*79.1%
Simplified79.1%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -14000000000000.0) (not (<= d 8.2e+82))) (/ b d) (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -14000000000000.0) || !(d <= 8.2e+82)) {
tmp = b / d;
} else {
tmp = (a + ((d * b) / c)) / 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 <= (-14000000000000.0d0)) .or. (.not. (d <= 8.2d+82))) then
tmp = b / d
else
tmp = (a + ((d * b) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -14000000000000.0) || !(d <= 8.2e+82)) {
tmp = b / d;
} else {
tmp = (a + ((d * b) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -14000000000000.0) or not (d <= 8.2e+82): tmp = b / d else: tmp = (a + ((d * b) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -14000000000000.0) || !(d <= 8.2e+82)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -14000000000000.0) || ~((d <= 8.2e+82))) tmp = b / d; else tmp = (a + ((d * b) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -14000000000000.0], N[Not[LessEqual[d, 8.2e+82]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -14000000000000 \lor \neg \left(d \leq 8.2 \cdot 10^{+82}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.4e13 or 8.1999999999999999e82 < d Initial program 50.2%
fma-define50.2%
fma-define50.2%
Simplified50.2%
Taylor expanded in c around 0 73.0%
if -1.4e13 < d < 8.1999999999999999e82Initial program 68.2%
fma-define68.2%
fma-define68.2%
Simplified68.2%
Taylor expanded in c around inf 74.7%
*-commutative74.7%
Simplified74.7%
Final simplification74.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.7e+14) (not (<= d 9.5e+84))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.7e+14) || !(d <= 9.5e+84)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / 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 <= (-2.7d+14)) .or. (.not. (d <= 9.5d+84))) then
tmp = b / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.7e+14) || !(d <= 9.5e+84)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.7e+14) or not (d <= 9.5e+84): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.7e+14) || !(d <= 9.5e+84)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.7e+14) || ~((d <= 9.5e+84))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.7e+14], N[Not[LessEqual[d, 9.5e+84]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{+14} \lor \neg \left(d \leq 9.5 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.7e14 or 9.49999999999999979e84 < d Initial program 50.2%
fma-define50.2%
fma-define50.2%
Simplified50.2%
Taylor expanded in c around 0 73.0%
if -2.7e14 < d < 9.49999999999999979e84Initial program 68.2%
fma-define68.2%
fma-define68.2%
Simplified68.2%
Taylor expanded in c around inf 74.7%
*-commutative74.7%
Simplified74.7%
Taylor expanded in d around 0 74.7%
associate-*r/74.2%
Simplified74.2%
Final simplification73.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.5e+73) (not (<= c 1.25e+31))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.5e+73) || !(c <= 1.25e+31)) {
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 <= (-4.5d+73)) .or. (.not. (c <= 1.25d+31))) 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 <= -4.5e+73) || !(c <= 1.25e+31)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.5e+73) or not (c <= 1.25e+31): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.5e+73) || !(c <= 1.25e+31)) 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 <= -4.5e+73) || ~((c <= 1.25e+31))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.5e+73], N[Not[LessEqual[c, 1.25e+31]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.5 \cdot 10^{+73} \lor \neg \left(c \leq 1.25 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -4.49999999999999985e73 or 1.25000000000000007e31 < c Initial program 49.0%
fma-define49.0%
fma-define49.0%
Simplified49.0%
Taylor expanded in c around inf 68.0%
if -4.49999999999999985e73 < c < 1.25000000000000007e31Initial program 69.9%
fma-define69.9%
fma-define69.9%
Simplified69.9%
Taylor expanded in c around 0 65.2%
Final simplification66.3%
(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 61.5%
fma-define61.5%
fma-define61.5%
Simplified61.5%
Taylor expanded in c around inf 40.2%
(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 2024139
(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))))