
(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 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+224) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+224) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (b * (d / c))) / c;
}
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+224) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); 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+224], 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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+224}:\\
\;\;\;\;\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{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999997e223Initial program 74.4%
fma-define74.5%
fma-define74.5%
Simplified74.5%
*-un-lft-identity74.5%
fma-define74.4%
add-sqr-sqrt74.4%
times-frac74.4%
fma-define74.4%
hypot-define74.4%
fma-define74.4%
fma-define74.4%
hypot-define95.4%
Applied egg-rr95.4%
if 9.9999999999999997e223 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 11.5%
fma-define11.5%
fma-define11.5%
Simplified11.5%
*-un-lft-identity11.5%
fma-define11.5%
add-sqr-sqrt11.5%
times-frac11.5%
fma-define11.5%
hypot-define11.5%
fma-define11.5%
fma-define11.5%
hypot-define14.6%
Applied egg-rr14.6%
Taylor expanded in c around inf 51.1%
associate-/l*60.5%
Simplified60.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* b (/ d c))) c)))
(if (<= c -6.2e-8)
t_0
(if (<= c 4.5e-154)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.5e+68) (/ (fma d b (* a c)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -6.2e-8) {
tmp = t_0;
} else if (c <= 4.5e-154) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.5e+68) {
tmp = fma(d, b, (a * c)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) tmp = 0.0 if (c <= -6.2e-8) tmp = t_0; elseif (c <= 4.5e-154) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.5e+68) tmp = Float64(fma(d, b, Float64(a * c)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e-8], t$95$0, If[LessEqual[c, 4.5e-154], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.5e+68], N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{-154}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+68}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6.2e-8 or 1.5000000000000001e68 < c Initial program 40.2%
fma-define40.2%
fma-define40.2%
Simplified40.2%
*-un-lft-identity40.2%
fma-define40.2%
add-sqr-sqrt40.2%
times-frac40.2%
fma-define40.2%
hypot-define40.2%
fma-define40.2%
fma-define40.2%
hypot-define59.6%
Applied egg-rr59.6%
Taylor expanded in c around inf 74.6%
associate-/l*77.9%
Simplified77.9%
if -6.2e-8 < c < 4.4999999999999997e-154Initial program 65.5%
fma-define65.5%
fma-define65.5%
Simplified65.5%
Taylor expanded in d around inf 87.0%
associate-/l*88.3%
Simplified88.3%
if 4.4999999999999997e-154 < c < 1.5000000000000001e68Initial program 89.4%
+-commutative89.4%
*-commutative89.4%
fma-define89.5%
Applied egg-rr89.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* b (/ d c))) c)))
(if (<= c -6.2e-10)
t_0
(if (<= c 3.6e-152)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.6e+68) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (b * (d / c))) / c;
double tmp;
if (c <= -6.2e-10) {
tmp = t_0;
} else if (c <= 3.6e-152) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.6e+68) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} 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 = (a + (b * (d / c))) / c
if (c <= (-6.2d-10)) then
tmp = t_0
else if (c <= 3.6d-152) then
tmp = (b + (a * (c / d))) / d
else if (c <= 1.6d+68) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
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 tmp;
if (c <= -6.2e-10) {
tmp = t_0;
} else if (c <= 3.6e-152) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.6e+68) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (b * (d / c))) / c tmp = 0 if c <= -6.2e-10: tmp = t_0 elif c <= 3.6e-152: tmp = (b + (a * (c / d))) / d elif c <= 1.6e+68: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(b * Float64(d / c))) / c) tmp = 0.0 if (c <= -6.2e-10) tmp = t_0; elseif (c <= 3.6e-152) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.6e+68) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (b * (d / c))) / c; tmp = 0.0; if (c <= -6.2e-10) tmp = t_0; elseif (c <= 3.6e-152) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.6e+68) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); 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]}, If[LessEqual[c, -6.2e-10], t$95$0, If[LessEqual[c, 3.6e-152], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.6e+68], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{-152}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{+68}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6.2000000000000003e-10 or 1.59999999999999997e68 < c Initial program 40.2%
fma-define40.2%
fma-define40.2%
Simplified40.2%
*-un-lft-identity40.2%
fma-define40.2%
add-sqr-sqrt40.2%
times-frac40.2%
fma-define40.2%
hypot-define40.2%
fma-define40.2%
fma-define40.2%
hypot-define59.6%
Applied egg-rr59.6%
Taylor expanded in c around inf 74.6%
associate-/l*77.9%
Simplified77.9%
if -6.2000000000000003e-10 < c < 3.6e-152Initial program 65.5%
fma-define65.5%
fma-define65.5%
Simplified65.5%
Taylor expanded in d around inf 87.0%
associate-/l*88.3%
Simplified88.3%
if 3.6e-152 < c < 1.59999999999999997e68Initial program 89.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6e-8) (not (<= c 5.5e-30))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6e-8) || !(c <= 5.5e-30)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-6d-8)) .or. (.not. (c <= 5.5d-30))) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6e-8) || !(c <= 5.5e-30)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6e-8) or not (c <= 5.5e-30): tmp = (a + (b * (d / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6e-8) || !(c <= 5.5e-30)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6e-8) || ~((c <= 5.5e-30))) tmp = (a + (b * (d / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6e-8], N[Not[LessEqual[c, 5.5e-30]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6 \cdot 10^{-8} \lor \neg \left(c \leq 5.5 \cdot 10^{-30}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -5.99999999999999946e-8 or 5.49999999999999976e-30 < c Initial program 46.8%
fma-define46.8%
fma-define46.8%
Simplified46.8%
*-un-lft-identity46.8%
fma-define46.8%
add-sqr-sqrt46.8%
times-frac46.8%
fma-define46.8%
hypot-define46.8%
fma-define46.8%
fma-define46.8%
hypot-define63.9%
Applied egg-rr63.9%
Taylor expanded in c around inf 72.5%
associate-/l*75.4%
Simplified75.4%
if -5.99999999999999946e-8 < c < 5.49999999999999976e-30Initial program 69.3%
fma-define69.3%
fma-define69.3%
Simplified69.3%
Taylor expanded in d around inf 83.5%
associate-/l*84.6%
Simplified84.6%
Final simplification79.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.2e+131) (not (<= d 9.2e+109))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.2e+131) || !(d <= 9.2e+109)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2.2d+131)) .or. (.not. (d <= 9.2d+109))) then
tmp = b / d
else
tmp = (a + (b * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.2e+131) || !(d <= 9.2e+109)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.2e+131) or not (d <= 9.2e+109): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.2e+131) || !(d <= 9.2e+109)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.2e+131) || ~((d <= 9.2e+109))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.2e+131], N[Not[LessEqual[d, 9.2e+109]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.2 \cdot 10^{+131} \lor \neg \left(d \leq 9.2 \cdot 10^{+109}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.1999999999999999e131 or 9.20000000000000042e109 < d Initial program 39.9%
fma-define39.9%
fma-define39.9%
Simplified39.9%
Taylor expanded in c around 0 75.7%
if -2.1999999999999999e131 < d < 9.20000000000000042e109Initial program 64.9%
fma-define64.9%
fma-define64.9%
Simplified64.9%
*-un-lft-identity64.9%
fma-define64.9%
add-sqr-sqrt64.9%
times-frac64.9%
fma-define64.9%
hypot-define64.9%
fma-define64.9%
fma-define64.9%
hypot-define77.4%
Applied egg-rr77.4%
Taylor expanded in c around inf 72.5%
associate-/l*73.1%
Simplified73.1%
Final simplification74.0%
(FPCore (a b c d) :precision binary64 (if (<= c -7.2e-16) (/ a c) (if (<= c 1.1e-41) (/ b d) (/ 1.0 (/ c a)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.2e-16) {
tmp = a / c;
} else if (c <= 1.1e-41) {
tmp = b / d;
} else {
tmp = 1.0 / (c / a);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-7.2d-16)) then
tmp = a / c
else if (c <= 1.1d-41) then
tmp = b / d
else
tmp = 1.0d0 / (c / a)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.2e-16) {
tmp = a / c;
} else if (c <= 1.1e-41) {
tmp = b / d;
} else {
tmp = 1.0 / (c / a);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -7.2e-16: tmp = a / c elif c <= 1.1e-41: tmp = b / d else: tmp = 1.0 / (c / a) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -7.2e-16) tmp = Float64(a / c); elseif (c <= 1.1e-41) tmp = Float64(b / d); else tmp = Float64(1.0 / Float64(c / a)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -7.2e-16) tmp = a / c; elseif (c <= 1.1e-41) tmp = b / d; else tmp = 1.0 / (c / a); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.2e-16], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.1e-41], N[(b / d), $MachinePrecision], N[(1.0 / N[(c / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.2 \cdot 10^{-16}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.1 \cdot 10^{-41}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{c}{a}}\\
\end{array}
\end{array}
if c < -7.19999999999999965e-16Initial program 46.8%
fma-define46.8%
fma-define46.8%
Simplified46.8%
Taylor expanded in c around inf 63.4%
if -7.19999999999999965e-16 < c < 1.1e-41Initial program 68.8%
fma-define68.8%
fma-define68.8%
Simplified68.8%
Taylor expanded in c around 0 68.2%
if 1.1e-41 < c Initial program 48.9%
fma-define48.9%
fma-define48.9%
Simplified48.9%
Taylor expanded in c around inf 62.9%
clear-num63.4%
inv-pow63.4%
Applied egg-rr63.4%
unpow-163.4%
Simplified63.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.15e-15) (not (<= c 1.14e-41))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.15e-15) || !(c <= 1.14e-41)) {
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.15d-15)) .or. (.not. (c <= 1.14d-41))) 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.15e-15) || !(c <= 1.14e-41)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.15e-15) or not (c <= 1.14e-41): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.15e-15) || !(c <= 1.14e-41)) 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.15e-15) || ~((c <= 1.14e-41))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.15e-15], N[Not[LessEqual[c, 1.14e-41]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.15 \cdot 10^{-15} \lor \neg \left(c \leq 1.14 \cdot 10^{-41}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.14999999999999995e-15 or 1.14e-41 < c Initial program 48.0%
fma-define48.0%
fma-define48.0%
Simplified48.0%
Taylor expanded in c around inf 63.1%
if -1.14999999999999995e-15 < c < 1.14e-41Initial program 68.8%
fma-define68.8%
fma-define68.8%
Simplified68.8%
Taylor expanded in c around 0 68.2%
Final simplification65.2%
(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.5%
fma-define56.5%
fma-define56.5%
Simplified56.5%
Taylor expanded in c around inf 42.6%
(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 2024188
(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))))