
(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 (+ (* c a) (* b d))))
(if (<= c -2.4e+103)
(/ 1.0 (/ c (fma b (/ d c) a)))
(if (<= c -1.55e+77)
(/ (+ b (* a (/ c d))) d)
(if (<= c -5.2)
(/ t_0 (+ (* c c) (* d d)))
(if (<= c 1e-120)
(/ (+ b (/ a (/ d c))) d)
(if (<= c 8.2e+92)
(/ t_0 (fma c c (* d d)))
(/ (+ a (* b (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * a) + (b * d);
double tmp;
if (c <= -2.4e+103) {
tmp = 1.0 / (c / fma(b, (d / c), a));
} else if (c <= -1.55e+77) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= -5.2) {
tmp = t_0 / ((c * c) + (d * d));
} else if (c <= 1e-120) {
tmp = (b + (a / (d / c))) / d;
} else if (c <= 8.2e+92) {
tmp = t_0 / fma(c, c, (d * d));
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * a) + Float64(b * d)) tmp = 0.0 if (c <= -2.4e+103) tmp = Float64(1.0 / Float64(c / fma(b, Float64(d / c), a))); elseif (c <= -1.55e+77) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= -5.2) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1e-120) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); elseif (c <= 8.2e+92) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.4e+103], N[(1.0 / N[(c / N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.55e+77], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -5.2], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1e-120], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.2e+92], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot a + b \cdot d\\
\mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\
\;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}\\
\mathbf{elif}\;c \leq -1.55 \cdot 10^{+77}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq -5.2:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 10^{-120}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -2.3999999999999998e103Initial program 35.6%
Taylor expanded in c around inf 81.7%
associate-/l*92.9%
Simplified92.9%
clear-num92.9%
un-div-inv92.9%
Applied egg-rr92.9%
clear-num92.9%
inv-pow92.9%
+-commutative92.9%
associate-/r/93.0%
fma-define93.0%
Applied egg-rr93.0%
unpow-193.0%
fma-undefine93.0%
associate-*l/81.8%
associate-*r/92.9%
fma-undefine92.9%
Simplified92.9%
if -2.3999999999999998e103 < c < -1.54999999999999999e77Initial program 30.8%
Taylor expanded in d around inf 86.2%
associate-/l*86.2%
Simplified86.2%
if -1.54999999999999999e77 < c < -5.20000000000000018Initial program 87.0%
if -5.20000000000000018 < c < 9.99999999999999979e-121Initial program 61.0%
Taylor expanded in d around inf 86.1%
associate-/l*87.0%
*-commutative87.0%
Applied egg-rr87.0%
*-commutative87.0%
clear-num87.0%
un-div-inv87.0%
Applied egg-rr87.0%
if 9.99999999999999979e-121 < c < 8.20000000000000047e92Initial program 82.6%
fma-define82.6%
fma-define82.6%
Simplified82.6%
fma-define82.6%
+-commutative82.6%
Applied egg-rr82.6%
if 8.20000000000000047e92 < c Initial program 30.6%
Taylor expanded in c around inf 84.4%
associate-/l*90.6%
Simplified90.6%
Final simplification87.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -2.4e+103)
(/ 1.0 (/ c (fma b (/ d c) a)))
(if (<= c -1.55e+77)
(/ (+ b (* a (/ c d))) d)
(if (<= c -7.8)
t_0
(if (<= c 1.2e-119)
(/ (+ b (/ a (/ d c))) d)
(if (<= c 8.5e+92) t_0 (/ (+ a (* b (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.4e+103) {
tmp = 1.0 / (c / fma(b, (d / c), a));
} else if (c <= -1.55e+77) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= -7.8) {
tmp = t_0;
} else if (c <= 1.2e-119) {
tmp = (b + (a / (d / c))) / d;
} else if (c <= 8.5e+92) {
tmp = t_0;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -2.4e+103) tmp = Float64(1.0 / Float64(c / fma(b, Float64(d / c), a))); elseif (c <= -1.55e+77) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= -7.8) tmp = t_0; elseif (c <= 1.2e-119) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); elseif (c <= 8.5e+92) tmp = t_0; else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.4e+103], N[(1.0 / N[(c / N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.55e+77], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -7.8], t$95$0, If[LessEqual[c, 1.2e-119], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.5e+92], t$95$0, N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\
\;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}\\
\mathbf{elif}\;c \leq -1.55 \cdot 10^{+77}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq -7.8:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{-119}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{elif}\;c \leq 8.5 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -2.3999999999999998e103Initial program 35.6%
Taylor expanded in c around inf 81.7%
associate-/l*92.9%
Simplified92.9%
clear-num92.9%
un-div-inv92.9%
Applied egg-rr92.9%
clear-num92.9%
inv-pow92.9%
+-commutative92.9%
associate-/r/93.0%
fma-define93.0%
Applied egg-rr93.0%
unpow-193.0%
fma-undefine93.0%
associate-*l/81.8%
associate-*r/92.9%
fma-undefine92.9%
Simplified92.9%
if -2.3999999999999998e103 < c < -1.54999999999999999e77Initial program 30.8%
Taylor expanded in d around inf 86.2%
associate-/l*86.2%
Simplified86.2%
if -1.54999999999999999e77 < c < -7.79999999999999982 or 1.20000000000000004e-119 < c < 8.5000000000000001e92Initial program 83.6%
if -7.79999999999999982 < c < 1.20000000000000004e-119Initial program 61.0%
Taylor expanded in d around inf 86.1%
associate-/l*87.0%
*-commutative87.0%
Applied egg-rr87.0%
*-commutative87.0%
clear-num87.0%
un-div-inv87.0%
Applied egg-rr87.0%
if 8.5000000000000001e92 < c Initial program 30.6%
Taylor expanded in c around inf 84.4%
associate-/l*90.6%
Simplified90.6%
Final simplification87.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* b (/ d c))) c))
(t_1 (/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -2.4e+103)
t_0
(if (<= c -1.12e+77)
(/ (+ b (* a (/ c d))) d)
(if (<= c -16.5)
t_1
(if (<= c 1.05e-119)
(/ (+ b (/ a (/ d c))) d)
(if (<= c 8.2e+92) t_1 t_0)))))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (b * (d / c))) / c;
double t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.4e+103) {
tmp = t_0;
} else if (c <= -1.12e+77) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= -16.5) {
tmp = t_1;
} else if (c <= 1.05e-119) {
tmp = (b + (a / (d / c))) / d;
} else if (c <= 8.2e+92) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = (a + (b * (d / c))) / c
t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d))
if (c <= (-2.4d+103)) then
tmp = t_0
else if (c <= (-1.12d+77)) then
tmp = (b + (a * (c / d))) / d
else if (c <= (-16.5d0)) then
tmp = t_1
else if (c <= 1.05d-119) then
tmp = (b + (a / (d / c))) / d
else if (c <= 8.2d+92) then
tmp = t_1
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 = (a + (b * (d / c))) / c;
double t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.4e+103) {
tmp = t_0;
} else if (c <= -1.12e+77) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= -16.5) {
tmp = t_1;
} else if (c <= 1.05e-119) {
tmp = (b + (a / (d / c))) / d;
} else if (c <= 8.2e+92) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (b * (d / c))) / c t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -2.4e+103: tmp = t_0 elif c <= -1.12e+77: tmp = (b + (a * (c / d))) / d elif c <= -16.5: tmp = t_1 elif c <= 1.05e-119: tmp = (b + (a / (d / c))) / d elif c <= 8.2e+92: tmp = t_1 else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) t_1 = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -2.4e+103) tmp = t_0; elseif (c <= -1.12e+77) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= -16.5) tmp = t_1; elseif (c <= 1.05e-119) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); elseif (c <= 8.2e+92) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (b * (d / c))) / c; t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -2.4e+103) tmp = t_0; elseif (c <= -1.12e+77) tmp = (b + (a * (c / d))) / d; elseif (c <= -16.5) tmp = t_1; elseif (c <= 1.05e-119) tmp = (b + (a / (d / c))) / d; elseif (c <= 8.2e+92) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.4e+103], t$95$0, If[LessEqual[c, -1.12e+77], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -16.5], t$95$1, If[LessEqual[c, 1.05e-119], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.2e+92], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + b \cdot \frac{d}{c}}{c}\\
t_1 := \frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.12 \cdot 10^{+77}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq -16.5:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-119}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.3999999999999998e103 or 8.20000000000000047e92 < c Initial program 32.7%
Taylor expanded in c around inf 83.3%
associate-/l*91.5%
Simplified91.5%
if -2.3999999999999998e103 < c < -1.1199999999999999e77Initial program 30.8%
Taylor expanded in d around inf 86.2%
associate-/l*86.2%
Simplified86.2%
if -1.1199999999999999e77 < c < -16.5 or 1.05e-119 < c < 8.20000000000000047e92Initial program 83.6%
if -16.5 < c < 1.05e-119Initial program 61.0%
Taylor expanded in d around inf 86.1%
associate-/l*87.0%
*-commutative87.0%
Applied egg-rr87.0%
*-commutative87.0%
clear-num87.0%
un-div-inv87.0%
Applied egg-rr87.0%
Final simplification87.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* a (/ c d))) d)))
(if (<= d -9.6e+83)
t_0
(if (<= d -1.9e-37)
(/ (+ a (/ b (/ c d))) c)
(if (or (<= d -1.75e-70) (not (<= d 1.9e-10)))
t_0
(/ (+ a (/ (* b d) c)) c))))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -9.6e+83) {
tmp = t_0;
} else if (d <= -1.9e-37) {
tmp = (a + (b / (c / d))) / c;
} else if ((d <= -1.75e-70) || !(d <= 1.9e-10)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (b + (a * (c / d))) / d
if (d <= (-9.6d+83)) then
tmp = t_0
else if (d <= (-1.9d-37)) then
tmp = (a + (b / (c / d))) / c
else if ((d <= (-1.75d-70)) .or. (.not. (d <= 1.9d-10))) then
tmp = t_0
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 t_0 = (b + (a * (c / d))) / d;
double tmp;
if (d <= -9.6e+83) {
tmp = t_0;
} else if (d <= -1.9e-37) {
tmp = (a + (b / (c / d))) / c;
} else if ((d <= -1.75e-70) || !(d <= 1.9e-10)) {
tmp = t_0;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (a * (c / d))) / d tmp = 0 if d <= -9.6e+83: tmp = t_0 elif d <= -1.9e-37: tmp = (a + (b / (c / d))) / c elif (d <= -1.75e-70) or not (d <= 1.9e-10): tmp = t_0 else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d) tmp = 0.0 if (d <= -9.6e+83) tmp = t_0; elseif (d <= -1.9e-37) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif ((d <= -1.75e-70) || !(d <= 1.9e-10)) tmp = t_0; else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (a * (c / d))) / d; tmp = 0.0; if (d <= -9.6e+83) tmp = t_0; elseif (d <= -1.9e-37) tmp = (a + (b / (c / d))) / c; elseif ((d <= -1.75e-70) || ~((d <= 1.9e-10))) tmp = t_0; else tmp = (a + ((b * d) / c)) / c; 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, -9.6e+83], t$95$0, If[LessEqual[d, -1.9e-37], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, -1.75e-70], N[Not[LessEqual[d, 1.9e-10]], $MachinePrecision]], t$95$0, N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{if}\;d \leq -9.6 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.9 \cdot 10^{-37}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;d \leq -1.75 \cdot 10^{-70} \lor \neg \left(d \leq 1.9 \cdot 10^{-10}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -9.59999999999999965e83 or -1.9000000000000002e-37 < d < -1.74999999999999987e-70 or 1.8999999999999999e-10 < d Initial program 43.1%
Taylor expanded in d around inf 78.4%
associate-/l*80.2%
Simplified80.2%
if -9.59999999999999965e83 < d < -1.9000000000000002e-37Initial program 63.6%
Taylor expanded in c around inf 59.8%
associate-/l*64.8%
Simplified64.8%
clear-num64.8%
un-div-inv64.9%
Applied egg-rr64.9%
if -1.74999999999999987e-70 < d < 1.8999999999999999e-10Initial program 69.8%
Taylor expanded in c around inf 90.3%
Final simplification83.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* a (/ c d))) d)))
(if (<= d -1.06e+85)
t_0
(if (<= d -1.8e-37)
(/ (+ a (/ b (/ c d))) c)
(if (<= d -5e-71)
(/ (+ b (/ a (/ d c))) d)
(if (<= d 1.85e-10) (/ (+ a (/ (* b d) 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 <= -1.06e+85) {
tmp = t_0;
} else if (d <= -1.8e-37) {
tmp = (a + (b / (c / d))) / c;
} else if (d <= -5e-71) {
tmp = (b + (a / (d / c))) / d;
} else if (d <= 1.85e-10) {
tmp = (a + ((b * d) / 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 <= (-1.06d+85)) then
tmp = t_0
else if (d <= (-1.8d-37)) then
tmp = (a + (b / (c / d))) / c
else if (d <= (-5d-71)) then
tmp = (b + (a / (d / c))) / d
else if (d <= 1.85d-10) then
tmp = (a + ((b * d) / 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 <= -1.06e+85) {
tmp = t_0;
} else if (d <= -1.8e-37) {
tmp = (a + (b / (c / d))) / c;
} else if (d <= -5e-71) {
tmp = (b + (a / (d / c))) / d;
} else if (d <= 1.85e-10) {
tmp = (a + ((b * d) / 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 <= -1.06e+85: tmp = t_0 elif d <= -1.8e-37: tmp = (a + (b / (c / d))) / c elif d <= -5e-71: tmp = (b + (a / (d / c))) / d elif d <= 1.85e-10: tmp = (a + ((b * d) / 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 <= -1.06e+85) tmp = t_0; elseif (d <= -1.8e-37) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (d <= -5e-71) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); elseif (d <= 1.85e-10) tmp = Float64(Float64(a + Float64(Float64(b * d) / 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 <= -1.06e+85) tmp = t_0; elseif (d <= -1.8e-37) tmp = (a + (b / (c / d))) / c; elseif (d <= -5e-71) tmp = (b + (a / (d / c))) / d; elseif (d <= 1.85e-10) tmp = (a + ((b * d) / 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, -1.06e+85], t$95$0, If[LessEqual[d, -1.8e-37], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, -5e-71], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.85e-10], N[(N[(a + N[(N[(b * d), $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 -1.06 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.8 \cdot 10^{-37}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;d \leq -5 \cdot 10^{-71}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{-10}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.0600000000000001e85 or 1.85000000000000007e-10 < d Initial program 39.1%
Taylor expanded in d around inf 77.7%
associate-/l*79.6%
Simplified79.6%
if -1.0600000000000001e85 < d < -1.80000000000000004e-37Initial program 63.6%
Taylor expanded in c around inf 59.8%
associate-/l*64.8%
Simplified64.8%
clear-num64.8%
un-div-inv64.9%
Applied egg-rr64.9%
if -1.80000000000000004e-37 < d < -4.99999999999999998e-71Initial program 99.4%
Taylor expanded in d around inf 88.3%
associate-/l*88.3%
*-commutative88.3%
Applied egg-rr88.3%
*-commutative88.3%
clear-num88.3%
un-div-inv88.3%
Applied egg-rr88.3%
if -4.99999999999999998e-71 < d < 1.85000000000000007e-10Initial program 69.8%
Taylor expanded in c around inf 90.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.6e+87) (not (<= d 5e+93))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.6e+87) || !(d <= 5e+93)) {
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 <= (-1.6d+87)) .or. (.not. (d <= 5d+93))) 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 <= -1.6e+87) || !(d <= 5e+93)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.6e+87) or not (d <= 5e+93): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.6e+87) || !(d <= 5e+93)) 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 <= -1.6e+87) || ~((d <= 5e+93))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.6e+87], N[Not[LessEqual[d, 5e+93]], $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 -1.6 \cdot 10^{+87} \lor \neg \left(d \leq 5 \cdot 10^{+93}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.6e87 or 5.0000000000000001e93 < d Initial program 32.7%
Taylor expanded in c around 0 80.7%
if -1.6e87 < d < 5.0000000000000001e93Initial program 68.6%
Taylor expanded in c around inf 77.0%
associate-/l*77.3%
Simplified77.3%
Final simplification78.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e+84) (not (<= d 1.76e-10))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e+84) || !(d <= 1.76e-10)) {
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 ((d <= (-4d+84)) .or. (.not. (d <= 1.76d-10))) 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 ((d <= -4e+84) || !(d <= 1.76e-10)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e+84) or not (d <= 1.76e-10): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e+84) || !(d <= 1.76e-10)) 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 ((d <= -4e+84) || ~((d <= 1.76e-10))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e+84], N[Not[LessEqual[d, 1.76e-10]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{+84} \lor \neg \left(d \leq 1.76 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000023e84 or 1.7600000000000001e-10 < d Initial program 39.1%
Taylor expanded in c around 0 71.9%
if -4.00000000000000023e84 < d < 1.7600000000000001e-10Initial program 70.7%
Taylor expanded in c around inf 67.4%
Final simplification69.4%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 56.8%
Taylor expanded in c around inf 45.7%
(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 2024084
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(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))))