
(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 7 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) (* (/ d c) (/ b c)))))
(if (<= c -4.6e+151)
t_0
(if (<= c -1.25e-65)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 2.2e+54) (fma (/ c d) (/ a d) (/ b d)) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((d / c) * (b / c));
double tmp;
if (c <= -4.6e+151) {
tmp = t_0;
} else if (c <= -1.25e-65) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.2e+54) {
tmp = fma((c / d), (a / d), (b / d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))) tmp = 0.0 if (c <= -4.6e+151) tmp = t_0; elseif (c <= -1.25e-65) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.2e+54) tmp = fma(Float64(c / d), Float64(a / d), Float64(b / d)); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.6e+151], t$95$0, If[LessEqual[c, -1.25e-65], 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, 2.2e+54], N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{if}\;c \leq -4.6 \cdot 10^{+151}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -1.25 \cdot 10^{-65}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+54}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -4.6000000000000002e151 or 2.1999999999999999e54 < c Initial program 35.6%
Taylor expanded in c around inf 80.5%
associate-/l*82.8%
associate-/r/82.9%
unpow282.9%
Simplified82.9%
Taylor expanded in d around 0 80.5%
unpow280.5%
times-frac91.4%
Simplified91.4%
if -4.6000000000000002e151 < c < -1.24999999999999996e-65Initial program 81.5%
if -1.24999999999999996e-65 < c < 2.1999999999999999e54Initial program 64.9%
Taylor expanded in c around 0 83.8%
+-commutative83.8%
unpow283.8%
times-frac84.9%
fma-def85.8%
Simplified85.8%
Final simplification87.4%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+170) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+170) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (a / c) + ((d / c) * (b / 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))) <= 5e+170) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / 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], 5e+170], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+170}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.99999999999999977e170Initial program 71.5%
*-un-lft-identity71.5%
add-sqr-sqrt71.5%
times-frac71.5%
hypot-def71.5%
fma-def71.5%
hypot-def94.8%
Applied egg-rr94.8%
associate-*l/95.0%
*-un-lft-identity95.0%
Applied egg-rr95.0%
if 4.99999999999999977e170 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 10.8%
Taylor expanded in c around inf 47.3%
associate-/l*51.0%
associate-/r/51.0%
unpow251.0%
Simplified51.0%
Taylor expanded in d around 0 47.3%
unpow247.3%
times-frac59.8%
Simplified59.8%
Final simplification85.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (* (/ d c) (/ b c)))))
(if (<= c -2.5e+153)
t_0
(if (<= c -3.8e-64)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 1.85e+55) (+ (/ b d) (* (/ c d) (/ a d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((d / c) * (b / c));
double tmp;
if (c <= -2.5e+153) {
tmp = t_0;
} else if (c <= -3.8e-64) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.85e+55) {
tmp = (b / d) + ((c / d) * (a / 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 / c) + ((d / c) * (b / c))
if (c <= (-2.5d+153)) then
tmp = t_0
else if (c <= (-3.8d-64)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (c <= 1.85d+55) then
tmp = (b / d) + ((c / d) * (a / 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 / c) + ((d / c) * (b / c));
double tmp;
if (c <= -2.5e+153) {
tmp = t_0;
} else if (c <= -3.8e-64) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.85e+55) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a / c) + ((d / c) * (b / c)) tmp = 0 if c <= -2.5e+153: tmp = t_0 elif c <= -3.8e-64: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 1.85e+55: tmp = (b / d) + ((c / d) * (a / d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))) tmp = 0.0 if (c <= -2.5e+153) tmp = t_0; elseif (c <= -3.8e-64) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.85e+55) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a / c) + ((d / c) * (b / c)); tmp = 0.0; if (c <= -2.5e+153) tmp = t_0; elseif (c <= -3.8e-64) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 1.85e+55) tmp = (b / d) + ((c / d) * (a / d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.5e+153], t$95$0, If[LessEqual[c, -3.8e-64], 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.85e+55], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{if}\;c \leq -2.5 \cdot 10^{+153}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -3.8 \cdot 10^{-64}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{+55}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -2.50000000000000009e153 or 1.8500000000000001e55 < c Initial program 35.6%
Taylor expanded in c around inf 80.5%
associate-/l*82.8%
associate-/r/82.9%
unpow282.9%
Simplified82.9%
Taylor expanded in d around 0 80.5%
unpow280.5%
times-frac91.4%
Simplified91.4%
if -2.50000000000000009e153 < c < -3.8000000000000002e-64Initial program 81.5%
if -3.8000000000000002e-64 < c < 1.8500000000000001e55Initial program 64.9%
*-un-lft-identity64.9%
add-sqr-sqrt64.9%
times-frac64.9%
hypot-def64.9%
fma-def64.9%
hypot-def79.0%
Applied egg-rr79.0%
Taylor expanded in c around 0 83.8%
unpow283.8%
times-frac84.9%
Simplified84.9%
Final simplification87.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8.8e-64) (not (<= c 2.3e+53))) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.8e-64) || !(c <= 2.3e+53)) {
tmp = (a / c) + ((d / c) * (b / 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 <= (-8.8d-64)) .or. (.not. (c <= 2.3d+53))) then
tmp = (a / c) + ((d / c) * (b / 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 <= -8.8e-64) || !(c <= 2.3e+53)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8.8e-64) or not (c <= 2.3e+53): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8.8e-64) || !(c <= 2.3e+53)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -8.8e-64) || ~((c <= 2.3e+53))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.8e-64], N[Not[LessEqual[c, 2.3e+53]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.8 \cdot 10^{-64} \lor \neg \left(c \leq 2.3 \cdot 10^{+53}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -8.7999999999999998e-64 or 2.3000000000000002e53 < c Initial program 47.4%
Taylor expanded in c around inf 75.9%
associate-/l*77.8%
associate-/r/76.8%
unpow276.8%
Simplified76.8%
Taylor expanded in d around 0 75.9%
unpow275.9%
times-frac84.0%
Simplified84.0%
if -8.7999999999999998e-64 < c < 2.3000000000000002e53Initial program 64.9%
Taylor expanded in c around 0 75.8%
Final simplification80.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.1e-60) (not (<= c 5e+56))) (+ (/ a c) (* (/ d c) (/ b c))) (+ (/ b d) (* (/ c d) (/ a d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.1e-60) || !(c <= 5e+56)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + ((c / d) * (a / 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.1d-60)) .or. (.not. (c <= 5d+56))) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = (b / d) + ((c / d) * (a / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.1e-60) || !(c <= 5e+56)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.1e-60) or not (c <= 5e+56): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (b / d) + ((c / d) * (a / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.1e-60) || !(c <= 5e+56)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.1e-60) || ~((c <= 5e+56))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (b / d) + ((c / d) * (a / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.1e-60], N[Not[LessEqual[c, 5e+56]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.1 \cdot 10^{-60} \lor \neg \left(c \leq 5 \cdot 10^{+56}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if c < -1.0999999999999999e-60 or 5.00000000000000024e56 < c Initial program 47.4%
Taylor expanded in c around inf 75.9%
associate-/l*77.8%
associate-/r/76.8%
unpow276.8%
Simplified76.8%
Taylor expanded in d around 0 75.9%
unpow275.9%
times-frac84.0%
Simplified84.0%
if -1.0999999999999999e-60 < c < 5.00000000000000024e56Initial program 64.9%
*-un-lft-identity64.9%
add-sqr-sqrt64.9%
times-frac64.9%
hypot-def64.9%
fma-def64.9%
hypot-def79.0%
Applied egg-rr79.0%
Taylor expanded in c around 0 83.8%
unpow283.8%
times-frac84.9%
Simplified84.9%
Final simplification84.5%
(FPCore (a b c d) :precision binary64 (if (<= c -5.3e-61) (/ a c) (if (<= c 9.5e+54) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.3e-61) {
tmp = a / c;
} else if (c <= 9.5e+54) {
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 (c <= (-5.3d-61)) then
tmp = a / c
else if (c <= 9.5d+54) 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 (c <= -5.3e-61) {
tmp = a / c;
} else if (c <= 9.5e+54) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.3e-61: tmp = a / c elif c <= 9.5e+54: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.3e-61) tmp = Float64(a / c); elseif (c <= 9.5e+54) 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 (c <= -5.3e-61) tmp = a / c; elseif (c <= 9.5e+54) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.3e-61], N[(a / c), $MachinePrecision], If[LessEqual[c, 9.5e+54], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.3 \cdot 10^{-61}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 9.5 \cdot 10^{+54}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -5.3e-61 or 9.4999999999999999e54 < c Initial program 47.4%
Taylor expanded in c around inf 72.5%
if -5.3e-61 < c < 9.4999999999999999e54Initial program 64.9%
Taylor expanded in c around 0 75.8%
Final simplification74.0%
(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 55.6%
Taylor expanded in c around inf 45.4%
Final simplification45.4%
(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 2023240
(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))))