
(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)) (+ (* c c) (* d d)))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 2e+307)))
(* (/ (fma b (/ d a) c) (hypot c d)) (/ a (hypot c d)))
(* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 2e+307)) {
tmp = (fma(b, (d / a), c) / hypot(c, d)) * (a / hypot(c, d));
} else {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(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))) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 2e+307)) tmp = Float64(Float64(fma(b, Float64(d / a), c) / hypot(c, d)) * Float64(a / hypot(c, d))); else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(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[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 2e+307]], $MachinePrecision]], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{+307}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\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)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0 or 1.99999999999999997e307 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 20.5%
Taylor expanded in a around inf 20.6%
associate-/l*20.6%
Simplified20.6%
*-commutative20.6%
add-sqr-sqrt20.6%
hypot-undefine20.6%
hypot-undefine20.6%
times-frac76.6%
+-commutative76.6%
fma-define76.6%
Applied egg-rr76.6%
if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999997e307Initial program 83.2%
*-un-lft-identity83.2%
associate-*r/83.2%
fma-define83.2%
add-sqr-sqrt83.2%
times-frac83.2%
fma-define83.2%
hypot-define83.2%
fma-define83.2%
fma-define83.2%
hypot-define98.9%
Applied egg-rr98.9%
Final simplification90.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= t_0 (- INFINITY))
(/ (+ b (* a (/ c d))) d)
(if (<= t_0 2e+307)
(* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
(/ (+ b (* c (/ a d))) d)))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = (b + (a * (c / d))) / d;
} else if (t_0 <= 2e+307) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b + (c * (a / d))) / 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))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (t_0 <= 2e+307) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / 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[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[t$95$0, 2e+307], 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[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+307}:\\
\;\;\;\;\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 + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0Initial program 44.2%
Taylor expanded in d around inf 77.7%
associate-/l*83.5%
Simplified83.5%
if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999997e307Initial program 83.2%
*-un-lft-identity83.2%
associate-*r/83.2%
fma-define83.2%
add-sqr-sqrt83.2%
times-frac83.2%
fma-define83.2%
hypot-define83.2%
fma-define83.2%
fma-define83.2%
hypot-define98.9%
Applied egg-rr98.9%
if 1.99999999999999997e307 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.2%
Taylor expanded in d around inf 55.5%
associate-/l*67.3%
Simplified67.3%
clear-num67.3%
un-div-inv67.3%
Applied egg-rr67.3%
associate-/r/67.3%
Simplified67.3%
Final simplification88.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.5e-7)
(* (/ a (hypot c d)) (/ c (hypot c d)))
(if (<= c -3e-83)
t_0
(if (<= c 1.65e-145)
(/ (+ b (/ a (/ d c))) d)
(if (<= c 2.8e+46)
t_0
(* (/ 1.0 (hypot c d)) (+ a (* b (/ d c))))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.5e-7) {
tmp = (a / hypot(c, d)) * (c / hypot(c, d));
} else if (c <= -3e-83) {
tmp = t_0;
} else if (c <= 1.65e-145) {
tmp = (b + (a / (d / c))) / d;
} else if (c <= 2.8e+46) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (a + (b * (d / c)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.5e-7) {
tmp = (a / Math.hypot(c, d)) * (c / Math.hypot(c, d));
} else if (c <= -3e-83) {
tmp = t_0;
} else if (c <= 1.65e-145) {
tmp = (b + (a / (d / c))) / d;
} else if (c <= 2.8e+46) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (a + (b * (d / c)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.5e-7: tmp = (a / math.hypot(c, d)) * (c / math.hypot(c, d)) elif c <= -3e-83: tmp = t_0 elif c <= 1.65e-145: tmp = (b + (a / (d / c))) / d elif c <= 2.8e+46: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (a + (b * (d / c))) 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))) tmp = 0.0 if (c <= -1.5e-7) tmp = Float64(Float64(a / hypot(c, d)) * Float64(c / hypot(c, d))); elseif (c <= -3e-83) tmp = t_0; elseif (c <= 1.65e-145) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d); elseif (c <= 2.8e+46) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(b * Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -1.5e-7) tmp = (a / hypot(c, d)) * (c / hypot(c, d)); elseif (c <= -3e-83) tmp = t_0; elseif (c <= 1.65e-145) tmp = (b + (a / (d / c))) / d; elseif (c <= 2.8e+46) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (a + (b * (d / c))); 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]}, If[LessEqual[c, -1.5e-7], N[(N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -3e-83], t$95$0, If[LessEqual[c, 1.65e-145], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.8e+46], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -1.5 \cdot 10^{-7}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -3 \cdot 10^{-83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.65 \cdot 10^{-145}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{+46}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + b \cdot \frac{d}{c}\right)\\
\end{array}
\end{array}
if c < -1.4999999999999999e-7Initial program 40.6%
Taylor expanded in a around inf 37.7%
associate-/l*34.1%
Simplified34.1%
*-commutative34.1%
add-sqr-sqrt34.1%
hypot-undefine34.1%
hypot-undefine34.1%
times-frac83.5%
+-commutative83.5%
fma-define83.5%
Applied egg-rr83.5%
Taylor expanded in b around 0 83.3%
if -1.4999999999999999e-7 < c < -3.0000000000000001e-83 or 1.6499999999999999e-145 < c < 2.80000000000000018e46Initial program 87.3%
if -3.0000000000000001e-83 < c < 1.6499999999999999e-145Initial program 65.1%
Taylor expanded in d around inf 92.1%
associate-/l*93.1%
Simplified93.1%
clear-num93.1%
un-div-inv93.1%
Applied egg-rr93.1%
if 2.80000000000000018e46 < c Initial program 41.1%
*-un-lft-identity41.1%
associate-*r/41.1%
fma-define41.1%
add-sqr-sqrt41.1%
times-frac41.2%
fma-define41.2%
hypot-define41.2%
fma-define41.2%
fma-define41.2%
hypot-define61.3%
Applied egg-rr61.3%
Taylor expanded in c around inf 78.9%
associate-/l*83.2%
Simplified83.2%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(if (<= d -9.4e+64)
(/ (+ b (* a (/ c d))) d)
(if (<= d -1.75e-105)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 2.25e+83)
(/ (+ a (* b (/ d c))) c)
(/ (+ b (* c (/ a d))) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -9.4e+64) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -1.75e-105) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.25e+83) {
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 <= (-9.4d+64)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-1.75d-105)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (d <= 2.25d+83) 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 <= -9.4e+64) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -1.75e-105) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.25e+83) {
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 <= -9.4e+64: tmp = (b + (a * (c / d))) / d elif d <= -1.75e-105: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 2.25e+83: 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 <= -9.4e+64) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -1.75e-105) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2.25e+83) tmp = Float64(Float64(a + Float64(b * Float64(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 <= -9.4e+64) tmp = (b + (a * (c / d))) / d; elseif (d <= -1.75e-105) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 2.25e+83) 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, -9.4e+64], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.75e-105], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.25e+83], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $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 -9.4 \cdot 10^{+64}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -1.75 \cdot 10^{-105}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.25 \cdot 10^{+83}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -9.40000000000000058e64Initial program 37.0%
Taylor expanded in d around inf 80.0%
associate-/l*86.9%
Simplified86.9%
if -9.40000000000000058e64 < d < -1.75e-105Initial program 90.7%
if -1.75e-105 < d < 2.25e83Initial program 68.4%
Taylor expanded in c around inf 79.3%
associate-/l*80.9%
Simplified80.9%
if 2.25e83 < d Initial program 47.5%
Taylor expanded in d around inf 73.3%
associate-/l*84.2%
Simplified84.2%
clear-num84.2%
un-div-inv84.3%
Applied egg-rr84.3%
associate-/r/84.3%
Simplified84.3%
Final simplification84.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.7e+37) (not (<= c 0.053))) (/ (+ a (* b (/ d c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.7e+37) || !(c <= 0.053)) {
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 <= (-2.7d+37)) .or. (.not. (c <= 0.053d0))) 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 <= -2.7e+37) || !(c <= 0.053)) {
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 <= -2.7e+37) or not (c <= 0.053): 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 <= -2.7e+37) || !(c <= 0.053)) 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 <= -2.7e+37) || ~((c <= 0.053))) 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, -2.7e+37], N[Not[LessEqual[c, 0.053]], $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 -2.7 \cdot 10^{+37} \lor \neg \left(c \leq 0.053\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 < -2.69999999999999986e37 or 0.0529999999999999985 < c Initial program 43.8%
Taylor expanded in c around inf 75.0%
associate-/l*78.1%
Simplified78.1%
if -2.69999999999999986e37 < c < 0.0529999999999999985Initial program 72.7%
Taylor expanded in d around inf 82.1%
associate-/l*82.7%
Simplified82.7%
Final simplification80.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.45e+76) (not (<= d 1.15e+84))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.45e+76) || !(d <= 1.15e+84)) {
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.45d+76)) .or. (.not. (d <= 1.15d+84))) 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.45e+76) || !(d <= 1.15e+84)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.45e+76) or not (d <= 1.15e+84): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.45e+76) || !(d <= 1.15e+84)) 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.45e+76) || ~((d <= 1.15e+84))) 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.45e+76], N[Not[LessEqual[d, 1.15e+84]], $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.45 \cdot 10^{+76} \lor \neg \left(d \leq 1.15 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.4500000000000001e76 or 1.1499999999999999e84 < d Initial program 41.4%
Taylor expanded in c around 0 69.5%
if -1.4500000000000001e76 < d < 1.1499999999999999e84Initial program 72.6%
Taylor expanded in c around inf 72.7%
associate-/l*73.9%
Simplified73.9%
Final simplification72.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.2e-63) (not (<= d 1.6e+86))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.2e-63) || !(d <= 1.6e+86)) {
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-63)) .or. (.not. (d <= 1.6d+86))) 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-63) || !(d <= 1.6e+86)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.2e-63) or not (d <= 1.6e+86): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.2e-63) || !(d <= 1.6e+86)) 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-63) || ~((d <= 1.6e+86))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.2e-63], N[Not[LessEqual[d, 1.6e+86]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{-63} \lor \neg \left(d \leq 1.6 \cdot 10^{+86}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -9.2e-63 or 1.6e86 < d Initial program 51.4%
Taylor expanded in c around 0 63.0%
if -9.2e-63 < d < 1.6e86Initial program 69.8%
Taylor expanded in c around inf 66.3%
Final simplification64.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 60.4%
Taylor expanded in c around inf 43.3%
(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 2024123
(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))))