
(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 10 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))) 1e+301) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+301) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (a * (c / d))) / 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))) <= 1e+301) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / 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], 1e+301], 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[(a * N[(c / d), $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 10^{+301}:\\
\;\;\;\;\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 + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.00000000000000005e301Initial program 77.1%
*-un-lft-identity77.1%
add-sqr-sqrt77.1%
times-frac77.2%
hypot-define77.2%
fma-define77.2%
hypot-define94.5%
Applied egg-rr94.5%
if 1.00000000000000005e301 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 13.6%
Taylor expanded in d around inf 47.1%
associate-/l*58.8%
Simplified58.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -2.6e-46)
(/ (+ b (/ c (/ d a))) d)
(if (<= d 9e-50)
(/ (+ a (/ (* b d) c)) c)
(/ (* d (/ b (hypot d c))) (hypot d c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.6e-46) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 9e-50) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (d * (b / hypot(d, c))) / hypot(d, c);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.6e-46) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 9e-50) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (d * (b / Math.hypot(d, c))) / Math.hypot(d, c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.6e-46: tmp = (b + (c / (d / a))) / d elif d <= 9e-50: tmp = (a + ((b * d) / c)) / c else: tmp = (d * (b / math.hypot(d, c))) / math.hypot(d, c) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.6e-46) tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); elseif (d <= 9e-50) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(Float64(d * Float64(b / hypot(d, c))) / hypot(d, c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2.6e-46) tmp = (b + (c / (d / a))) / d; elseif (d <= 9e-50) tmp = (a + ((b * d) / c)) / c; else tmp = (d * (b / hypot(d, c))) / hypot(d, c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.6e-46], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 9e-50], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(d * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.6 \cdot 10^{-46}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\mathbf{elif}\;d \leq 9 \cdot 10^{-50}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{d \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}
\end{array}
if d < -2.6000000000000002e-46Initial program 52.7%
Taylor expanded in d around inf 73.8%
associate-/l*78.7%
Simplified78.7%
clear-num78.6%
un-div-inv78.6%
Applied egg-rr78.6%
associate-/r/78.6%
Simplified78.6%
*-commutative78.6%
clear-num78.7%
un-div-inv78.7%
Applied egg-rr78.7%
if -2.6000000000000002e-46 < d < 8.99999999999999924e-50Initial program 73.8%
Taylor expanded in c around inf 87.7%
*-commutative87.7%
Simplified87.7%
if 8.99999999999999924e-50 < d Initial program 46.1%
Taylor expanded in a around 0 39.2%
*-commutative39.2%
Simplified39.2%
*-un-lft-identity39.2%
add-sqr-sqrt39.2%
hypot-undefine39.2%
hypot-undefine39.2%
times-frac54.2%
Applied egg-rr54.2%
associate-*l/54.4%
*-lft-identity54.4%
associate-/l*76.8%
associate-*l/76.8%
*-commutative76.8%
associate-*r/76.8%
hypot-undefine45.1%
unpow245.1%
unpow245.1%
+-commutative45.1%
unpow245.1%
unpow245.1%
hypot-define76.8%
hypot-undefine45.1%
unpow245.1%
unpow245.1%
+-commutative45.1%
unpow245.1%
unpow245.1%
hypot-define76.8%
Simplified76.8%
Final simplification82.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (/ (+ a (* d (/ b c))) c)))
(if (<= c -8.2e+77)
t_1
(if (<= c -4.5e-158)
t_0
(if (<= c 2.1e-130)
(/ (+ b (* c (/ a d))) d)
(if (<= c 3.5e+64) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -8.2e+77) {
tmp = t_1;
} else if (c <= -4.5e-158) {
tmp = t_0;
} else if (c <= 2.1e-130) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 3.5e+64) {
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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (a + (d * (b / c))) / c
if (c <= (-8.2d+77)) then
tmp = t_1
else if (c <= (-4.5d-158)) then
tmp = t_0
else if (c <= 2.1d-130) then
tmp = (b + (c * (a / d))) / d
else if (c <= 3.5d+64) 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 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -8.2e+77) {
tmp = t_1;
} else if (c <= -4.5e-158) {
tmp = t_0;
} else if (c <= 2.1e-130) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 3.5e+64) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (a + (d * (b / c))) / c tmp = 0 if c <= -8.2e+77: tmp = t_1 elif c <= -4.5e-158: tmp = t_0 elif c <= 2.1e-130: tmp = (b + (c * (a / d))) / d elif c <= 3.5e+64: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(a + Float64(d * Float64(b / c))) / c) tmp = 0.0 if (c <= -8.2e+77) tmp = t_1; elseif (c <= -4.5e-158) tmp = t_0; elseif (c <= 2.1e-130) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (c <= 3.5e+64) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (a + (d * (b / c))) / c; tmp = 0.0; if (c <= -8.2e+77) tmp = t_1; elseif (c <= -4.5e-158) tmp = t_0; elseif (c <= 2.1e-130) tmp = (b + (c * (a / d))) / d; elseif (c <= 3.5e+64) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -8.2e+77], t$95$1, If[LessEqual[c, -4.5e-158], t$95$0, If[LessEqual[c, 2.1e-130], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.5e+64], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -8.2 \cdot 10^{+77}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -4.5 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.1 \cdot 10^{-130}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;c \leq 3.5 \cdot 10^{+64}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -8.2000000000000002e77 or 3.4999999999999999e64 < c Initial program 38.3%
Taylor expanded in c around inf 75.6%
*-commutative75.6%
Simplified75.6%
associate-/l*83.8%
*-commutative83.8%
Applied egg-rr83.8%
if -8.2000000000000002e77 < c < -4.5e-158 or 2.10000000000000002e-130 < c < 3.4999999999999999e64Initial program 77.3%
if -4.5e-158 < c < 2.10000000000000002e-130Initial program 73.1%
Taylor expanded in d around inf 98.2%
associate-/l*99.2%
Simplified99.2%
clear-num99.2%
un-div-inv99.2%
Applied egg-rr99.2%
associate-/r/99.9%
Simplified99.9%
Final simplification84.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.5e-46) (not (<= d 1.7e+95))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.5e-46) || !(d <= 1.7e+95)) {
tmp = (b + (a * (c / d))) / 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.5d-46)) .or. (.not. (d <= 1.7d+95))) then
tmp = (b + (a * (c / d))) / 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.5e-46) || !(d <= 1.7e+95)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.5e-46) or not (d <= 1.7e+95): tmp = (b + (a * (c / d))) / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.5e-46) || !(d <= 1.7e+95)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.5e-46) || ~((d <= 1.7e+95))) tmp = (b + (a * (c / d))) / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.5e-46], N[Not[LessEqual[d, 1.7e+95]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.5 \cdot 10^{-46} \lor \neg \left(d \leq 1.7 \cdot 10^{+95}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.49999999999999996e-46 or 1.70000000000000011e95 < d Initial program 45.2%
Taylor expanded in d around inf 71.3%
associate-/l*76.9%
Simplified76.9%
if -2.49999999999999996e-46 < d < 1.70000000000000011e95Initial program 72.9%
Taylor expanded in c around inf 82.2%
*-commutative82.2%
Simplified82.2%
Final simplification79.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9e+77) (not (<= d 1.32e+166))) (/ b d) (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9e+77) || !(d <= 1.32e+166)) {
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 <= (-9d+77)) .or. (.not. (d <= 1.32d+166))) 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 <= -9e+77) || !(d <= 1.32e+166)) {
tmp = b / d;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9e+77) or not (d <= 1.32e+166): tmp = b / d else: tmp = (a + ((b * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9e+77) || !(d <= 1.32e+166)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -9e+77) || ~((d <= 1.32e+166))) tmp = b / d; else tmp = (a + ((b * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9e+77], N[Not[LessEqual[d, 1.32e+166]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{+77} \lor \neg \left(d \leq 1.32 \cdot 10^{+166}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -9.00000000000000049e77 or 1.3199999999999999e166 < d Initial program 36.6%
Taylor expanded in c around 0 75.0%
if -9.00000000000000049e77 < d < 1.3199999999999999e166Initial program 71.2%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
Simplified75.0%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.8e+77) (not (<= d 1.32e+166))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+77) || !(d <= 1.32e+166)) {
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.8d+77)) .or. (.not. (d <= 1.32d+166))) 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.8e+77) || !(d <= 1.32e+166)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.8e+77) or not (d <= 1.32e+166): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.8e+77) || !(d <= 1.32e+166)) 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.8e+77) || ~((d <= 1.32e+166))) 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.8e+77], N[Not[LessEqual[d, 1.32e+166]], $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.8 \cdot 10^{+77} \lor \neg \left(d \leq 1.32 \cdot 10^{+166}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.7999999999999999e77 or 1.3199999999999999e166 < d Initial program 36.6%
Taylor expanded in c around 0 75.0%
if -1.7999999999999999e77 < d < 1.3199999999999999e166Initial program 71.2%
*-un-lft-identity71.2%
add-sqr-sqrt71.2%
times-frac71.3%
hypot-define71.3%
fma-define71.3%
hypot-define82.5%
Applied egg-rr82.5%
Taylor expanded in c around inf 75.0%
associate-/l*74.8%
Simplified74.8%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (<= d -4e-47) (/ (+ b (/ c (/ d a))) d) (if (<= d 2.25e+95) (/ (+ a (/ (* b d) c)) c) (/ (+ b (* c (/ a d))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-47) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 2.25e+95) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (c * (a / 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 (d <= (-4d-47)) then
tmp = (b + (c / (d / a))) / d
else if (d <= 2.25d+95) then
tmp = (a + ((b * d) / c)) / c
else
tmp = (b + (c * (a / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-47) {
tmp = (b + (c / (d / a))) / d;
} else if (d <= 2.25e+95) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4e-47: tmp = (b + (c / (d / a))) / d elif d <= 2.25e+95: tmp = (a + ((b * d) / c)) / c else: tmp = (b + (c * (a / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4e-47) tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); elseif (d <= 2.25e+95) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4e-47) tmp = (b + (c / (d / a))) / d; elseif (d <= 2.25e+95) tmp = (a + ((b * d) / c)) / c; else tmp = (b + (c * (a / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e-47], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.25e+95], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{-47}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\mathbf{elif}\;d \leq 2.25 \cdot 10^{+95}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -3.9999999999999999e-47Initial program 52.7%
Taylor expanded in d around inf 73.8%
associate-/l*78.7%
Simplified78.7%
clear-num78.6%
un-div-inv78.6%
Applied egg-rr78.6%
associate-/r/78.6%
Simplified78.6%
*-commutative78.6%
clear-num78.7%
un-div-inv78.7%
Applied egg-rr78.7%
if -3.9999999999999999e-47 < d < 2.25000000000000008e95Initial program 72.9%
Taylor expanded in c around inf 82.2%
*-commutative82.2%
Simplified82.2%
if 2.25000000000000008e95 < d Initial program 36.7%
Taylor expanded in d around inf 68.4%
associate-/l*74.9%
Simplified74.9%
clear-num74.9%
un-div-inv74.9%
Applied egg-rr74.9%
associate-/r/77.5%
Simplified77.5%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (<= d -2.6e-46) (/ (+ b (* a (/ c d))) d) (if (<= d 1.8e+95) (/ (+ a (/ (* b d) c)) c) (/ (+ b (* c (/ a d))) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.6e-46) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.8e+95) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (c * (a / 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 (d <= (-2.6d-46)) then
tmp = (b + (a * (c / d))) / d
else if (d <= 1.8d+95) then
tmp = (a + ((b * d) / c)) / c
else
tmp = (b + (c * (a / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.6e-46) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= 1.8e+95) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = (b + (c * (a / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.6e-46: tmp = (b + (a * (c / d))) / d elif d <= 1.8e+95: tmp = (a + ((b * d) / c)) / c else: tmp = (b + (c * (a / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.6e-46) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= 1.8e+95) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2.6e-46) tmp = (b + (a * (c / d))) / d; elseif (d <= 1.8e+95) tmp = (a + ((b * d) / c)) / c; else tmp = (b + (c * (a / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.6e-46], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.8e+95], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.6 \cdot 10^{-46}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+95}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -2.6000000000000002e-46Initial program 52.7%
Taylor expanded in d around inf 73.8%
associate-/l*78.7%
Simplified78.7%
if -2.6000000000000002e-46 < d < 1.79999999999999989e95Initial program 72.9%
Taylor expanded in c around inf 82.2%
*-commutative82.2%
Simplified82.2%
if 1.79999999999999989e95 < d Initial program 36.7%
Taylor expanded in d around inf 68.4%
associate-/l*74.9%
Simplified74.9%
clear-num74.9%
un-div-inv74.9%
Applied egg-rr74.9%
associate-/r/77.5%
Simplified77.5%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.2e-69) (not (<= d 2.4e-77))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.2e-69) || !(d <= 2.4e-77)) {
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 <= (-9.2d-69)) .or. (.not. (d <= 2.4d-77))) 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 <= -9.2e-69) || !(d <= 2.4e-77)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.2e-69) or not (d <= 2.4e-77): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.2e-69) || !(d <= 2.4e-77)) 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 <= -9.2e-69) || ~((d <= 2.4e-77))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.2e-69], N[Not[LessEqual[d, 2.4e-77]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{-69} \lor \neg \left(d \leq 2.4 \cdot 10^{-77}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -9.2000000000000003e-69 or 2.3999999999999999e-77 < d Initial program 50.4%
Taylor expanded in c around 0 61.2%
if -9.2000000000000003e-69 < d < 2.3999999999999999e-77Initial program 73.8%
Taylor expanded in c around inf 71.3%
Final simplification65.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 60.3%
Taylor expanded in c around inf 44.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 2024185
(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))))