
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+298) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (/ 1.0 (/ (/ d c) a))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+298) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (1.0 / ((d / c) / a))) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 5e+298) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(1.0 / Float64(Float64(d / c) / a))) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+298], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+298}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.0000000000000003e298Initial program 78.9%
fma-define78.9%
fma-define78.9%
Simplified78.9%
*-un-lft-identity78.9%
fma-define78.9%
add-sqr-sqrt78.9%
times-frac78.9%
fma-define78.9%
hypot-define78.9%
fma-define78.9%
fma-define78.9%
hypot-define97.4%
Applied egg-rr97.4%
if 5.0000000000000003e298 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 10.4%
fma-define10.4%
fma-define10.4%
Simplified10.4%
Taylor expanded in d around inf 44.2%
clear-num44.2%
inv-pow44.2%
*-commutative44.2%
Applied egg-rr44.2%
unpow-144.2%
associate-/r*57.9%
Simplified57.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.15e-33)
(/ (+ a (* b (/ d c))) c)
(if (<= c 6.5e-162)
(/ (+ b (/ 1.0 (/ (/ d c) a))) d)
(if (<= c 2.3e+104)
(/ (fma a c (* b d)) (fma c c (* d d)))
(+ (/ a c) (/ d (* c (/ c b))))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.15e-33) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 6.5e-162) {
tmp = (b + (1.0 / ((d / c) / a))) / d;
} else if (c <= 2.3e+104) {
tmp = fma(a, c, (b * d)) / fma(c, c, (d * d));
} else {
tmp = (a / c) + (d / (c * (c / b)));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.15e-33) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 6.5e-162) tmp = Float64(Float64(b + Float64(1.0 / Float64(Float64(d / c) / a))) / d); elseif (c <= 2.3e+104) tmp = Float64(fma(a, c, Float64(b * d)) / fma(c, c, Float64(d * d))); else tmp = Float64(Float64(a / c) + Float64(d / Float64(c * Float64(c / b)))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.15e-33], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 6.5e-162], N[(N[(b + N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.3e+104], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(d / N[(c * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.15 \cdot 10^{-33}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 6.5 \cdot 10^{-162}:\\
\;\;\;\;\frac{b + \frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{+104}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c \cdot \frac{c}{b}}\\
\end{array}
\end{array}
if c < -1.14999999999999993e-33Initial program 50.3%
fma-define50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in d around 0 74.6%
associate-*r/76.3%
Simplified76.3%
if -1.14999999999999993e-33 < c < 6.49999999999999989e-162Initial program 73.2%
fma-define73.2%
fma-define73.2%
Simplified73.2%
Taylor expanded in d around inf 88.7%
clear-num88.7%
inv-pow88.7%
*-commutative88.7%
Applied egg-rr88.7%
unpow-188.7%
associate-/r*91.6%
Simplified91.6%
if 6.49999999999999989e-162 < c < 2.29999999999999985e104Initial program 81.2%
fma-define81.2%
fma-define81.2%
Simplified81.2%
if 2.29999999999999985e104 < c Initial program 35.2%
fma-define35.2%
fma-define35.2%
Simplified35.2%
Taylor expanded in d around 0 65.5%
*-commutative65.5%
unpow265.5%
times-frac77.6%
Applied egg-rr77.6%
*-commutative77.6%
clear-num77.6%
frac-times80.9%
*-un-lft-identity80.9%
Applied egg-rr80.9%
Final simplification83.7%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.05e-32)
(/ (+ a (* b (/ d c))) c)
(if (<= c 2.9e-162)
(/ (+ b (/ 1.0 (/ (/ d c) a))) d)
(if (<= c 1.5e+104)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(+ (/ a c) (/ d (* c (/ c b))))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.05e-32) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 2.9e-162) {
tmp = (b + (1.0 / ((d / c) / a))) / d;
} else if (c <= 1.5e+104) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (a / c) + (d / (c * (c / b)));
}
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 <= (-1.05d-32)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 2.9d-162) then
tmp = (b + (1.0d0 / ((d / c) / a))) / d
else if (c <= 1.5d+104) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else
tmp = (a / c) + (d / (c * (c / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.05e-32) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 2.9e-162) {
tmp = (b + (1.0 / ((d / c) / a))) / d;
} else if (c <= 1.5e+104) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (a / c) + (d / (c * (c / b)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.05e-32: tmp = (a + (b * (d / c))) / c elif c <= 2.9e-162: tmp = (b + (1.0 / ((d / c) / a))) / d elif c <= 1.5e+104: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (a / c) + (d / (c * (c / b))) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.05e-32) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 2.9e-162) tmp = Float64(Float64(b + Float64(1.0 / Float64(Float64(d / c) / a))) / d); elseif (c <= 1.5e+104) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(a / c) + Float64(d / Float64(c * Float64(c / b)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.05e-32) tmp = (a + (b * (d / c))) / c; elseif (c <= 2.9e-162) tmp = (b + (1.0 / ((d / c) / a))) / d; elseif (c <= 1.5e+104) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (a / c) + (d / (c * (c / b))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.05e-32], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.9e-162], N[(N[(b + N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.5e+104], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(d / N[(c * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.05 \cdot 10^{-32}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 2.9 \cdot 10^{-162}:\\
\;\;\;\;\frac{b + \frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+104}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c \cdot \frac{c}{b}}\\
\end{array}
\end{array}
if c < -1.05e-32Initial program 50.3%
fma-define50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in d around 0 74.6%
associate-*r/76.3%
Simplified76.3%
if -1.05e-32 < c < 2.9000000000000001e-162Initial program 73.2%
fma-define73.2%
fma-define73.2%
Simplified73.2%
Taylor expanded in d around inf 88.7%
clear-num88.7%
inv-pow88.7%
*-commutative88.7%
Applied egg-rr88.7%
unpow-188.7%
associate-/r*91.6%
Simplified91.6%
if 2.9000000000000001e-162 < c < 1.49999999999999984e104Initial program 81.2%
if 1.49999999999999984e104 < c Initial program 35.2%
fma-define35.2%
fma-define35.2%
Simplified35.2%
Taylor expanded in d around 0 65.5%
*-commutative65.5%
unpow265.5%
times-frac77.6%
Applied egg-rr77.6%
*-commutative77.6%
clear-num77.6%
frac-times80.9%
*-un-lft-identity80.9%
Applied egg-rr80.9%
Final simplification83.7%
(FPCore (a b c d) :precision binary64 (if (<= c -1.2e-32) (/ (+ a (* b (/ d c))) c) (if (<= c 86.0) (/ (+ b (* a (/ c d))) d) (+ (/ a c) (/ d (* c (/ c b)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.2e-32) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 86.0) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a / c) + (d / (c * (c / b)));
}
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 <= (-1.2d-32)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 86.0d0) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a / c) + (d / (c * (c / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.2e-32) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 86.0) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a / c) + (d / (c * (c / b)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.2e-32: tmp = (a + (b * (d / c))) / c elif c <= 86.0: tmp = (b + (a * (c / d))) / d else: tmp = (a / c) + (d / (c * (c / b))) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.2e-32) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 86.0) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a / c) + Float64(d / Float64(c * Float64(c / b)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.2e-32) tmp = (a + (b * (d / c))) / c; elseif (c <= 86.0) tmp = (b + (a * (c / d))) / d; else tmp = (a / c) + (d / (c * (c / b))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.2e-32], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 86.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(d / N[(c * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.2 \cdot 10^{-32}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 86:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c \cdot \frac{c}{b}}\\
\end{array}
\end{array}
if c < -1.2000000000000001e-32Initial program 50.3%
fma-define50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in d around 0 74.6%
associate-*r/76.3%
Simplified76.3%
if -1.2000000000000001e-32 < c < 86Initial program 73.7%
fma-define73.8%
fma-define73.8%
Simplified73.8%
Taylor expanded in d around inf 84.9%
associate-/l*86.4%
Simplified86.4%
if 86 < c Initial program 52.2%
fma-define52.2%
fma-define52.2%
Simplified52.2%
Taylor expanded in d around 0 65.4%
*-commutative65.4%
unpow265.4%
times-frac73.5%
Applied egg-rr73.5%
*-commutative73.5%
clear-num73.5%
frac-times75.8%
*-un-lft-identity75.8%
Applied egg-rr75.8%
Final simplification80.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.4e-58) (not (<= c 7e-68))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.4e-58) || !(c <= 7e-68)) {
tmp = (a + (b * (d / 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 ((c <= (-5.4d-58)) .or. (.not. (c <= 7d-68))) then
tmp = (a + (b * (d / 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 ((c <= -5.4e-58) || !(c <= 7e-68)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.4e-58) or not (c <= 7e-68): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.4e-58) || !(c <= 7e-68)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.4e-58) || ~((c <= 7e-68))) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.4e-58], N[Not[LessEqual[c, 7e-68]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.4 \cdot 10^{-58} \lor \neg \left(c \leq 7 \cdot 10^{-68}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -5.3999999999999998e-58 or 7.00000000000000026e-68 < c Initial program 52.6%
fma-define52.6%
fma-define52.6%
Simplified52.6%
Taylor expanded in c around inf 69.3%
*-commutative69.3%
Simplified69.3%
Taylor expanded in d around 0 69.3%
associate-*r/72.9%
Simplified72.9%
if -5.3999999999999998e-58 < c < 7.00000000000000026e-68Initial program 74.5%
fma-define74.5%
fma-define74.5%
Simplified74.5%
Taylor expanded in c around 0 69.6%
Final simplification71.5%
(FPCore (a b c d) :precision binary64 (if (<= c -3e-33) (/ (+ a (* b (/ d c))) c) (if (<= c 125.0) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-33) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 125.0) {
tmp = (b + (a * (c / d))) / 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 (c <= (-3d-33)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 125.0d0) then
tmp = (b + (a * (c / d))) / 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 (c <= -3e-33) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 125.0) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3e-33: tmp = (a + (b * (d / c))) / c elif c <= 125.0: tmp = (b + (a * (c / d))) / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-33) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 125.0) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3e-33) tmp = (a + (b * (d / c))) / c; elseif (c <= 125.0) tmp = (b + (a * (c / d))) / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-33], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 125.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-33}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 125:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -3.0000000000000002e-33Initial program 50.3%
fma-define50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in d around 0 74.6%
associate-*r/76.3%
Simplified76.3%
if -3.0000000000000002e-33 < c < 125Initial program 73.7%
fma-define73.8%
fma-define73.8%
Simplified73.8%
Taylor expanded in d around inf 84.9%
associate-/l*86.4%
Simplified86.4%
if 125 < c Initial program 52.2%
fma-define52.2%
fma-define52.2%
Simplified52.2%
Taylor expanded in c around inf 67.8%
*-commutative67.8%
Simplified67.8%
associate-/l*74.4%
Applied egg-rr74.4%
(FPCore (a b c d) :precision binary64 (if (<= c -9.8e-51) (/ (+ a (* b (/ d c))) c) (if (<= c 1.65e-66) (/ b d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9.8e-51) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 1.65e-66) {
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 (c <= (-9.8d-51)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 1.65d-66) 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 (c <= -9.8e-51) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 1.65e-66) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -9.8e-51: tmp = (a + (b * (d / c))) / c elif c <= 1.65e-66: tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -9.8e-51) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 1.65e-66) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -9.8e-51) tmp = (a + (b * (d / c))) / c; elseif (c <= 1.65e-66) tmp = b / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -9.8e-51], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.65e-66], N[(b / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.8 \cdot 10^{-51}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 1.65 \cdot 10^{-66}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -9.79999999999999948e-51Initial program 50.4%
fma-define50.4%
fma-define50.4%
Simplified50.4%
Taylor expanded in c around inf 73.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in d around 0 73.9%
associate-*r/75.5%
Simplified75.5%
if -9.79999999999999948e-51 < c < 1.6499999999999999e-66Initial program 74.5%
fma-define74.5%
fma-define74.5%
Simplified74.5%
Taylor expanded in c around 0 69.6%
if 1.6499999999999999e-66 < c Initial program 54.3%
fma-define54.3%
fma-define54.3%
Simplified54.3%
Taylor expanded in c around inf 65.8%
*-commutative65.8%
Simplified65.8%
associate-/l*71.7%
Applied egg-rr71.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.5e-48) (not (<= c 1.9e-66))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.5e-48) || !(c <= 1.9e-66)) {
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 <= (-1.5d-48)) .or. (.not. (c <= 1.9d-66))) 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 <= -1.5e-48) || !(c <= 1.9e-66)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.5e-48) or not (c <= 1.9e-66): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.5e-48) || !(c <= 1.9e-66)) 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 <= -1.5e-48) || ~((c <= 1.9e-66))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.5e-48], N[Not[LessEqual[c, 1.9e-66]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.5 \cdot 10^{-48} \lor \neg \left(c \leq 1.9 \cdot 10^{-66}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.5e-48 or 1.8999999999999999e-66 < c Initial program 52.6%
fma-define52.6%
fma-define52.6%
Simplified52.6%
Taylor expanded in c around inf 62.6%
if -1.5e-48 < c < 1.8999999999999999e-66Initial program 74.5%
fma-define74.5%
fma-define74.5%
Simplified74.5%
Taylor expanded in c around 0 69.6%
Final simplification65.6%
(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.7%
fma-define61.8%
fma-define61.8%
Simplified61.8%
Taylor expanded in c around inf 43.0%
(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 2024160
(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))))