
(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 (/ (+ (* a c) (* b d)) (fma c c (* d d))))
(t_1 (+ (/ a c) (* (/ d c) (/ b c)))))
(if (<= d -1.12e+156)
(+ (/ (* c (/ a d)) d) (/ b d))
(if (<= d -2.5e-136)
t_0
(if (<= d 2.65e-138)
t_1
(if (<= d 7.2e-79)
t_0
(if (<= d 2.05e+99) t_1 (+ (/ b d) (* (/ a d) (/ c d))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / fma(c, c, (d * d));
double t_1 = (a / c) + ((d / c) * (b / c));
double tmp;
if (d <= -1.12e+156) {
tmp = ((c * (a / d)) / d) + (b / d);
} else if (d <= -2.5e-136) {
tmp = t_0;
} else if (d <= 2.65e-138) {
tmp = t_1;
} else if (d <= 7.2e-79) {
tmp = t_0;
} else if (d <= 2.05e+99) {
tmp = t_1;
} else {
tmp = (b / d) + ((a / d) * (c / d));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / fma(c, c, Float64(d * d))) t_1 = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))) tmp = 0.0 if (d <= -1.12e+156) tmp = Float64(Float64(Float64(c * Float64(a / d)) / d) + Float64(b / d)); elseif (d <= -2.5e-136) tmp = t_0; elseif (d <= 2.65e-138) tmp = t_1; elseif (d <= 7.2e-79) tmp = t_0; elseif (d <= 2.05e+99) tmp = t_1; else tmp = Float64(Float64(b / d) + Float64(Float64(a / d) * Float64(c / d))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.12e+156], N[(N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.5e-136], t$95$0, If[LessEqual[d, 2.65e-138], t$95$1, If[LessEqual[d, 7.2e-79], t$95$0, If[LessEqual[d, 2.05e+99], t$95$1, N[(N[(b / d), $MachinePrecision] + N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
t_1 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{if}\;d \leq -1.12 \cdot 10^{+156}:\\
\;\;\;\;\frac{c \cdot \frac{a}{d}}{d} + \frac{b}{d}\\
\mathbf{elif}\;d \leq -2.5 \cdot 10^{-136}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.65 \cdot 10^{-138}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{-79}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{+99}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\end{array}
\end{array}
if d < -1.12000000000000007e156Initial program 19.7%
Taylor expanded in c around 0 77.4%
unpow277.4%
times-frac92.4%
Simplified92.4%
associate-*l/94.5%
Applied egg-rr94.5%
if -1.12000000000000007e156 < d < -2.5000000000000001e-136 or 2.65000000000000013e-138 < d < 7.2000000000000005e-79Initial program 87.4%
fma-def87.4%
fma-def87.5%
Simplified87.5%
fma-def87.5%
+-commutative87.5%
Applied egg-rr87.5%
if -2.5000000000000001e-136 < d < 2.65000000000000013e-138 or 7.2000000000000005e-79 < d < 2.0499999999999999e99Initial program 73.2%
Taylor expanded in c around inf 84.8%
unpow284.8%
times-frac91.6%
Simplified91.6%
if 2.0499999999999999e99 < d Initial program 39.5%
Taylor expanded in c around 0 73.5%
unpow273.5%
times-frac87.9%
Simplified87.9%
Final simplification90.0%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+214) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (fma b (/ 1.0 d) (/ (* c (/ a d)) d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+214) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = fma(b, (1.0 / d), ((c * (a / 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))) <= 5e+214) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = fma(b, Float64(1.0 / d), Float64(Float64(c * Float64(a / 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], 5e+214], 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[(b * N[(1.0 / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $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^{+214}:\\
\;\;\;\;\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}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, \frac{c \cdot \frac{a}{d}}{d}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.99999999999999953e214Initial program 82.9%
*-un-lft-identity82.9%
add-sqr-sqrt82.8%
times-frac82.8%
hypot-def82.8%
fma-def82.8%
hypot-def97.4%
Applied egg-rr97.4%
if 4.99999999999999953e214 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 11.7%
Taylor expanded in c around 0 46.4%
unpow246.4%
times-frac67.3%
Simplified67.3%
div-inv67.2%
fma-def70.0%
associate-*l/70.0%
Applied egg-rr70.0%
Final simplification89.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ (/ a c) (* (/ d c) (/ b c)))))
(if (<= d -1.12e+156)
(+ (/ (* c (/ a d)) d) (/ b d))
(if (<= d -4.6e-135)
t_0
(if (<= d 6.5e-138)
t_1
(if (<= d 8.5e-79)
t_0
(if (<= d 1.92e+99) t_1 (+ (/ b d) (* (/ a d) (/ c d))))))))))
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 / c) + ((d / c) * (b / c));
double tmp;
if (d <= -1.12e+156) {
tmp = ((c * (a / d)) / d) + (b / d);
} else if (d <= -4.6e-135) {
tmp = t_0;
} else if (d <= 6.5e-138) {
tmp = t_1;
} else if (d <= 8.5e-79) {
tmp = t_0;
} else if (d <= 1.92e+99) {
tmp = t_1;
} else {
tmp = (b / d) + ((a / d) * (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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (a / c) + ((d / c) * (b / c))
if (d <= (-1.12d+156)) then
tmp = ((c * (a / d)) / d) + (b / d)
else if (d <= (-4.6d-135)) then
tmp = t_0
else if (d <= 6.5d-138) then
tmp = t_1
else if (d <= 8.5d-79) then
tmp = t_0
else if (d <= 1.92d+99) then
tmp = t_1
else
tmp = (b / d) + ((a / d) * (c / d))
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 / c) + ((d / c) * (b / c));
double tmp;
if (d <= -1.12e+156) {
tmp = ((c * (a / d)) / d) + (b / d);
} else if (d <= -4.6e-135) {
tmp = t_0;
} else if (d <= 6.5e-138) {
tmp = t_1;
} else if (d <= 8.5e-79) {
tmp = t_0;
} else if (d <= 1.92e+99) {
tmp = t_1;
} else {
tmp = (b / d) + ((a / d) * (c / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (a / c) + ((d / c) * (b / c)) tmp = 0 if d <= -1.12e+156: tmp = ((c * (a / d)) / d) + (b / d) elif d <= -4.6e-135: tmp = t_0 elif d <= 6.5e-138: tmp = t_1 elif d <= 8.5e-79: tmp = t_0 elif d <= 1.92e+99: tmp = t_1 else: tmp = (b / d) + ((a / d) * (c / d)) 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 / c) + Float64(Float64(d / c) * Float64(b / c))) tmp = 0.0 if (d <= -1.12e+156) tmp = Float64(Float64(Float64(c * Float64(a / d)) / d) + Float64(b / d)); elseif (d <= -4.6e-135) tmp = t_0; elseif (d <= 6.5e-138) tmp = t_1; elseif (d <= 8.5e-79) tmp = t_0; elseif (d <= 1.92e+99) tmp = t_1; else tmp = Float64(Float64(b / d) + Float64(Float64(a / d) * Float64(c / d))); 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 / c) + ((d / c) * (b / c)); tmp = 0.0; if (d <= -1.12e+156) tmp = ((c * (a / d)) / d) + (b / d); elseif (d <= -4.6e-135) tmp = t_0; elseif (d <= 6.5e-138) tmp = t_1; elseif (d <= 8.5e-79) tmp = t_0; elseif (d <= 1.92e+99) tmp = t_1; else tmp = (b / d) + ((a / d) * (c / d)); 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 / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.12e+156], N[(N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -4.6e-135], t$95$0, If[LessEqual[d, 6.5e-138], t$95$1, If[LessEqual[d, 8.5e-79], t$95$0, If[LessEqual[d, 1.92e+99], t$95$1, N[(N[(b / d), $MachinePrecision] + N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\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}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{if}\;d \leq -1.12 \cdot 10^{+156}:\\
\;\;\;\;\frac{c \cdot \frac{a}{d}}{d} + \frac{b}{d}\\
\mathbf{elif}\;d \leq -4.6 \cdot 10^{-135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{-138}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq 8.5 \cdot 10^{-79}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.92 \cdot 10^{+99}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\end{array}
\end{array}
if d < -1.12000000000000007e156Initial program 19.7%
Taylor expanded in c around 0 77.4%
unpow277.4%
times-frac92.4%
Simplified92.4%
associate-*l/94.5%
Applied egg-rr94.5%
if -1.12000000000000007e156 < d < -4.5999999999999998e-135 or 6.4999999999999999e-138 < d < 8.50000000000000029e-79Initial program 87.4%
if -4.5999999999999998e-135 < d < 6.4999999999999999e-138 or 8.50000000000000029e-79 < d < 1.9199999999999999e99Initial program 73.2%
Taylor expanded in c around inf 84.8%
unpow284.8%
times-frac91.6%
Simplified91.6%
if 1.9199999999999999e99 < d Initial program 39.5%
Taylor expanded in c around 0 73.5%
unpow273.5%
times-frac87.9%
Simplified87.9%
Final simplification89.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.15e-27) (not (<= d 3.2e+99))) (/ b d) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-27) || !(d <= 3.2e+99)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / 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.15d-27)) .or. (.not. (d <= 3.2d+99))) then
tmp = b / d
else
tmp = (a / c) + ((d / c) * (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-27) || !(d <= 3.2e+99)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.15e-27) or not (d <= 3.2e+99): tmp = b / d else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.15e-27) || !(d <= 3.2e+99)) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.15e-27) || ~((d <= 3.2e+99))) tmp = b / d; else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.15e-27], N[Not[LessEqual[d, 3.2e+99]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.15 \cdot 10^{-27} \lor \neg \left(d \leq 3.2 \cdot 10^{+99}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if d < -1.15e-27 or 3.19999999999999999e99 < d Initial program 48.0%
Taylor expanded in c around 0 71.8%
if -1.15e-27 < d < 3.19999999999999999e99Initial program 77.4%
Taylor expanded in c around inf 79.4%
unpow279.4%
times-frac82.7%
Simplified82.7%
Final simplification77.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2e-29) (not (<= d 1.92e+99))) (+ (/ b d) (* (/ a d) (/ c d))) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2e-29) || !(d <= 1.92e+99)) {
tmp = (b / d) + ((a / d) * (c / d));
} else {
tmp = (a / c) + ((d / c) * (b / 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 <= (-2d-29)) .or. (.not. (d <= 1.92d+99))) then
tmp = (b / d) + ((a / d) * (c / d))
else
tmp = (a / c) + ((d / c) * (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2e-29) || !(d <= 1.92e+99)) {
tmp = (b / d) + ((a / d) * (c / d));
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2e-29) or not (d <= 1.92e+99): tmp = (b / d) + ((a / d) * (c / d)) else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2e-29) || !(d <= 1.92e+99)) tmp = Float64(Float64(b / d) + Float64(Float64(a / d) * Float64(c / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2e-29) || ~((d <= 1.92e+99))) tmp = (b / d) + ((a / d) * (c / d)); else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2e-29], N[Not[LessEqual[d, 1.92e+99]], $MachinePrecision]], N[(N[(b / d), $MachinePrecision] + N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{-29} \lor \neg \left(d \leq 1.92 \cdot 10^{+99}\right):\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if d < -1.99999999999999989e-29 or 1.9199999999999999e99 < d Initial program 48.0%
Taylor expanded in c around 0 76.5%
unpow276.5%
times-frac87.7%
Simplified87.7%
if -1.99999999999999989e-29 < d < 1.9199999999999999e99Initial program 77.4%
Taylor expanded in c around inf 79.4%
unpow279.4%
times-frac82.7%
Simplified82.7%
Final simplification85.2%
(FPCore (a b c d)
:precision binary64
(if (<= d -6.2e-31)
(+ (/ (* c (/ a d)) d) (/ b d))
(if (<= d 1.92e+99)
(+ (/ a c) (* (/ d c) (/ b c)))
(+ (/ b d) (* (/ a d) (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.2e-31) {
tmp = ((c * (a / d)) / d) + (b / d);
} else if (d <= 1.92e+99) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + ((a / d) * (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 (d <= (-6.2d-31)) then
tmp = ((c * (a / d)) / d) + (b / d)
else if (d <= 1.92d+99) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = (b / d) + ((a / d) * (c / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.2e-31) {
tmp = ((c * (a / d)) / d) + (b / d);
} else if (d <= 1.92e+99) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + ((a / d) * (c / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -6.2e-31: tmp = ((c * (a / d)) / d) + (b / d) elif d <= 1.92e+99: tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (b / d) + ((a / d) * (c / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -6.2e-31) tmp = Float64(Float64(Float64(c * Float64(a / d)) / d) + Float64(b / d)); elseif (d <= 1.92e+99) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(Float64(b / d) + Float64(Float64(a / d) * Float64(c / d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -6.2e-31) tmp = ((c * (a / d)) / d) + (b / d); elseif (d <= 1.92e+99) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (b / d) + ((a / d) * (c / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -6.2e-31], N[(N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.92e+99], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.2 \cdot 10^{-31}:\\
\;\;\;\;\frac{c \cdot \frac{a}{d}}{d} + \frac{b}{d}\\
\mathbf{elif}\;d \leq 1.92 \cdot 10^{+99}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\end{array}
\end{array}
if d < -6.19999999999999999e-31Initial program 54.7%
Taylor expanded in c around 0 78.9%
unpow278.9%
times-frac87.6%
Simplified87.6%
associate-*l/88.7%
Applied egg-rr88.7%
if -6.19999999999999999e-31 < d < 1.9199999999999999e99Initial program 77.4%
Taylor expanded in c around inf 79.4%
unpow279.4%
times-frac82.7%
Simplified82.7%
if 1.9199999999999999e99 < d Initial program 39.5%
Taylor expanded in c around 0 73.5%
unpow273.5%
times-frac87.9%
Simplified87.9%
Final simplification85.4%
(FPCore (a b c d) :precision binary64 (if (<= d -3.55e-87) (/ b d) (if (<= d 1.92e+99) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.55e-87) {
tmp = b / d;
} else if (d <= 1.92e+99) {
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 (d <= (-3.55d-87)) then
tmp = b / d
else if (d <= 1.92d+99) 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 (d <= -3.55e-87) {
tmp = b / d;
} else if (d <= 1.92e+99) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3.55e-87: tmp = b / d elif d <= 1.92e+99: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3.55e-87) tmp = Float64(b / d); elseif (d <= 1.92e+99) 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 (d <= -3.55e-87) tmp = b / d; elseif (d <= 1.92e+99) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.55e-87], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.92e+99], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.55 \cdot 10^{-87}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.92 \cdot 10^{+99}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -3.55000000000000002e-87 or 1.9199999999999999e99 < d Initial program 52.5%
Taylor expanded in c around 0 69.1%
if -3.55000000000000002e-87 < d < 1.9199999999999999e99Initial program 75.6%
Taylor expanded in c around inf 70.5%
Final simplification69.7%
(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 63.1%
Taylor expanded in c around inf 41.7%
Final simplification41.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 2023257
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(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))))