
(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 9 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))) INFINITY) (/ (/ (fma b d (* a c)) (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))) <= ((double) INFINITY)) {
tmp = (fma(b, d, (a * c)) / 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))) <= Inf) tmp = Float64(Float64(fma(b, d, Float64(a * c)) / 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], Infinity], N[(N[(N[(b * d + N[(a * c), $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 \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\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))) < +inf.0Initial program 73.7%
*-un-lft-identity73.7%
add-sqr-sqrt73.7%
times-frac73.6%
hypot-define73.6%
fma-define73.6%
hypot-define93.6%
Applied egg-rr93.6%
frac-times73.7%
*-un-lft-identity73.7%
fma-undefine73.7%
+-commutative73.7%
*-commutative73.7%
fma-undefine73.7%
associate-/r*93.8%
fma-undefine93.8%
*-commutative93.8%
fma-define93.8%
Applied egg-rr93.8%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in c around inf 51.7%
associate-/l*56.7%
Simplified56.7%
pow256.7%
associate-*r/51.7%
associate-/r*52.2%
Applied egg-rr52.2%
associate-/l/51.7%
*-commutative51.7%
times-frac66.4%
Applied egg-rr66.4%
Final simplification88.6%
(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 (<= c -2.05e+71)
t_1
(if (<= c -1.5e-107)
t_0
(if (<= c 1.75e-151)
(+ (/ b d) (* a (/ c (pow d 2.0))))
(if (<= c 1.8e+112) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a / c) + ((d / c) * (b / c));
double tmp;
if (c <= -2.05e+71) {
tmp = t_1;
} else if (c <= -1.5e-107) {
tmp = t_0;
} else if (c <= 1.75e-151) {
tmp = (b / d) + (a * (c / pow(d, 2.0)));
} else if (c <= 1.8e+112) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (a / c) + ((d / c) * (b / c))
if (c <= (-2.05d+71)) then
tmp = t_1
else if (c <= (-1.5d-107)) then
tmp = t_0
else if (c <= 1.75d-151) then
tmp = (b / d) + (a * (c / (d ** 2.0d0)))
else if (c <= 1.8d+112) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a / c) + ((d / c) * (b / c));
double tmp;
if (c <= -2.05e+71) {
tmp = t_1;
} else if (c <= -1.5e-107) {
tmp = t_0;
} else if (c <= 1.75e-151) {
tmp = (b / d) + (a * (c / Math.pow(d, 2.0)));
} else if (c <= 1.8e+112) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (a / c) + ((d / c) * (b / c)) tmp = 0 if c <= -2.05e+71: tmp = t_1 elif c <= -1.5e-107: tmp = t_0 elif c <= 1.75e-151: tmp = (b / d) + (a * (c / math.pow(d, 2.0))) elif c <= 1.8e+112: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))) tmp = 0.0 if (c <= -2.05e+71) tmp = t_1; elseif (c <= -1.5e-107) tmp = t_0; elseif (c <= 1.75e-151) tmp = Float64(Float64(b / d) + Float64(a * Float64(c / (d ^ 2.0)))); elseif (c <= 1.8e+112) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (a / c) + ((d / c) * (b / c)); tmp = 0.0; if (c <= -2.05e+71) tmp = t_1; elseif (c <= -1.5e-107) tmp = t_0; elseif (c <= 1.75e-151) tmp = (b / d) + (a * (c / (d ^ 2.0))); elseif (c <= 1.8e+112) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.05e+71], t$95$1, If[LessEqual[c, -1.5e-107], t$95$0, If[LessEqual[c, 1.75e-151], N[(N[(b / d), $MachinePrecision] + N[(a * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.8e+112], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{if}\;c \leq -2.05 \cdot 10^{+71}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -1.5 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{-151}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{+112}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -2.0500000000000001e71 or 1.8e112 < c Initial program 34.0%
Taylor expanded in c around inf 75.7%
associate-/l*77.3%
Simplified77.3%
pow277.3%
associate-*r/75.7%
associate-/r*81.0%
Applied egg-rr81.0%
associate-/l/75.7%
*-commutative75.7%
times-frac86.5%
Applied egg-rr86.5%
if -2.0500000000000001e71 < c < -1.4999999999999999e-107 or 1.74999999999999998e-151 < c < 1.8e112Initial program 78.0%
if -1.4999999999999999e-107 < c < 1.74999999999999998e-151Initial program 68.7%
Taylor expanded in c around 0 89.4%
associate-/l*85.2%
Simplified85.2%
Final simplification83.1%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.25e-21)
(+ (/ b d) (* a (/ c (pow d 2.0))))
(if (<= d 1.9e+67)
(+ (/ a c) (/ (/ (* b d) c) c))
(/ (+ b (* a (/ c d))) (hypot c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.25e-21) {
tmp = (b / d) + (a * (c / pow(d, 2.0)));
} else if (d <= 1.9e+67) {
tmp = (a / c) + (((b * d) / c) / c);
} else {
tmp = (b + (a * (c / d))) / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.25e-21) {
tmp = (b / d) + (a * (c / Math.pow(d, 2.0)));
} else if (d <= 1.9e+67) {
tmp = (a / c) + (((b * d) / c) / c);
} else {
tmp = (b + (a * (c / d))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.25e-21: tmp = (b / d) + (a * (c / math.pow(d, 2.0))) elif d <= 1.9e+67: tmp = (a / c) + (((b * d) / c) / c) else: tmp = (b + (a * (c / d))) / math.hypot(c, d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.25e-21) tmp = Float64(Float64(b / d) + Float64(a * Float64(c / (d ^ 2.0)))); elseif (d <= 1.9e+67) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.25e-21) tmp = (b / d) + (a * (c / (d ^ 2.0))); elseif (d <= 1.9e+67) tmp = (a / c) + (((b * d) / c) / c); else tmp = (b + (a * (c / d))) / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.25e-21], N[(N[(b / d), $MachinePrecision] + N[(a * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.9e+67], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{-21}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+67}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.24999999999999993e-21Initial program 50.3%
Taylor expanded in c around 0 70.0%
associate-/l*71.4%
Simplified71.4%
if -1.24999999999999993e-21 < d < 1.9000000000000001e67Initial program 71.4%
Taylor expanded in c around inf 78.2%
associate-/l*77.1%
Simplified77.1%
pow277.1%
associate-*r/78.2%
associate-/r*84.1%
Applied egg-rr84.1%
if 1.9000000000000001e67 < d Initial program 39.1%
*-un-lft-identity39.1%
add-sqr-sqrt39.1%
times-frac39.1%
hypot-define39.1%
fma-define39.1%
hypot-define63.2%
Applied egg-rr63.2%
frac-times39.1%
*-un-lft-identity39.1%
fma-undefine39.1%
+-commutative39.1%
*-commutative39.1%
fma-undefine39.1%
associate-/r*63.4%
fma-undefine63.3%
*-commutative63.3%
fma-define63.4%
Applied egg-rr63.4%
Taylor expanded in d around inf 82.0%
associate-/l*86.3%
Simplified86.3%
Final simplification81.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ b (* a (/ c d)))))
(if (<= d -2e-21)
(/ t_0 (- (hypot c d)))
(if (<= d 1.9e+67) (+ (/ a c) (/ (/ (* b d) c) c)) (/ t_0 (hypot c d))))))
double code(double a, double b, double c, double d) {
double t_0 = b + (a * (c / d));
double tmp;
if (d <= -2e-21) {
tmp = t_0 / -hypot(c, d);
} else if (d <= 1.9e+67) {
tmp = (a / c) + (((b * d) / c) / c);
} else {
tmp = t_0 / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = b + (a * (c / d));
double tmp;
if (d <= -2e-21) {
tmp = t_0 / -Math.hypot(c, d);
} else if (d <= 1.9e+67) {
tmp = (a / c) + (((b * d) / c) / c);
} else {
tmp = t_0 / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = b + (a * (c / d)) tmp = 0 if d <= -2e-21: tmp = t_0 / -math.hypot(c, d) elif d <= 1.9e+67: tmp = (a / c) + (((b * d) / c) / c) else: tmp = t_0 / math.hypot(c, d) return tmp
function code(a, b, c, d) t_0 = Float64(b + Float64(a * Float64(c / d))) tmp = 0.0 if (d <= -2e-21) tmp = Float64(t_0 / Float64(-hypot(c, d))); elseif (d <= 1.9e+67) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); else tmp = Float64(t_0 / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = b + (a * (c / d)); tmp = 0.0; if (d <= -2e-21) tmp = t_0 / -hypot(c, d); elseif (d <= 1.9e+67) tmp = (a / c) + (((b * d) / c) / c); else tmp = t_0 / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2e-21], N[(t$95$0 / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[d, 1.9e+67], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b + a \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -2 \cdot 10^{-21}:\\
\;\;\;\;\frac{t\_0}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+67}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.99999999999999982e-21Initial program 50.3%
*-un-lft-identity50.3%
add-sqr-sqrt50.3%
times-frac50.3%
hypot-define50.3%
fma-define50.3%
hypot-define70.7%
Applied egg-rr70.7%
frac-times50.3%
*-un-lft-identity50.3%
fma-undefine50.3%
+-commutative50.3%
*-commutative50.3%
fma-undefine50.3%
associate-/r*70.8%
fma-undefine70.8%
*-commutative70.8%
fma-define70.8%
Applied egg-rr70.8%
Taylor expanded in d around -inf 75.5%
distribute-lft-out75.5%
associate-/l*78.4%
Simplified78.4%
if -1.99999999999999982e-21 < d < 1.9000000000000001e67Initial program 71.4%
Taylor expanded in c around inf 78.2%
associate-/l*77.1%
Simplified77.1%
pow277.1%
associate-*r/78.2%
associate-/r*84.1%
Applied egg-rr84.1%
if 1.9000000000000001e67 < d Initial program 39.1%
*-un-lft-identity39.1%
add-sqr-sqrt39.1%
times-frac39.1%
hypot-define39.1%
fma-define39.1%
hypot-define63.2%
Applied egg-rr63.2%
frac-times39.1%
*-un-lft-identity39.1%
fma-undefine39.1%
+-commutative39.1%
*-commutative39.1%
fma-undefine39.1%
associate-/r*63.4%
fma-undefine63.3%
*-commutative63.3%
fma-define63.4%
Applied egg-rr63.4%
Taylor expanded in d around inf 82.0%
associate-/l*86.3%
Simplified86.3%
Final simplification83.0%
(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 (<= c -8.8e+70)
t_1
(if (<= c -3.1e-107)
t_0
(if (<= c 4e-152) (/ b d) (if (<= c 1.76e+112) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a / c) + ((d / c) * (b / c));
double tmp;
if (c <= -8.8e+70) {
tmp = t_1;
} else if (c <= -3.1e-107) {
tmp = t_0;
} else if (c <= 4e-152) {
tmp = b / d;
} else if (c <= 1.76e+112) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = (a / c) + ((d / c) * (b / c))
if (c <= (-8.8d+70)) then
tmp = t_1
else if (c <= (-3.1d-107)) then
tmp = t_0
else if (c <= 4d-152) then
tmp = b / d
else if (c <= 1.76d+112) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = (a / c) + ((d / c) * (b / c));
double tmp;
if (c <= -8.8e+70) {
tmp = t_1;
} else if (c <= -3.1e-107) {
tmp = t_0;
} else if (c <= 4e-152) {
tmp = b / d;
} else if (c <= 1.76e+112) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = (a / c) + ((d / c) * (b / c)) tmp = 0 if c <= -8.8e+70: tmp = t_1 elif c <= -3.1e-107: tmp = t_0 elif c <= 4e-152: tmp = b / d elif c <= 1.76e+112: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))) tmp = 0.0 if (c <= -8.8e+70) tmp = t_1; elseif (c <= -3.1e-107) tmp = t_0; elseif (c <= 4e-152) tmp = Float64(b / d); elseif (c <= 1.76e+112) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = (a / c) + ((d / c) * (b / c)); tmp = 0.0; if (c <= -8.8e+70) tmp = t_1; elseif (c <= -3.1e-107) tmp = t_0; elseif (c <= 4e-152) tmp = b / d; elseif (c <= 1.76e+112) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -8.8e+70], t$95$1, If[LessEqual[c, -3.1e-107], t$95$0, If[LessEqual[c, 4e-152], N[(b / d), $MachinePrecision], If[LessEqual[c, 1.76e+112], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{if}\;c \leq -8.8 \cdot 10^{+70}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -3.1 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-152}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.76 \cdot 10^{+112}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -8.80000000000000003e70 or 1.75999999999999999e112 < c Initial program 34.0%
Taylor expanded in c around inf 75.7%
associate-/l*77.3%
Simplified77.3%
pow277.3%
associate-*r/75.7%
associate-/r*81.0%
Applied egg-rr81.0%
associate-/l/75.7%
*-commutative75.7%
times-frac86.5%
Applied egg-rr86.5%
if -8.80000000000000003e70 < c < -3.10000000000000022e-107 or 4.00000000000000026e-152 < c < 1.75999999999999999e112Initial program 78.0%
if -3.10000000000000022e-107 < c < 4.00000000000000026e-152Initial program 68.7%
Taylor expanded in c around 0 77.4%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.3e-21) (not (<= d 3.4e+67))) (/ b d) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.3e-21) || !(d <= 3.4e+67)) {
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 <= (-2.3d-21)) .or. (.not. (d <= 3.4d+67))) 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 <= -2.3e-21) || !(d <= 3.4e+67)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.3e-21) or not (d <= 3.4e+67): tmp = b / d else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.3e-21) || !(d <= 3.4e+67)) 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 <= -2.3e-21) || ~((d <= 3.4e+67))) 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, -2.3e-21], N[Not[LessEqual[d, 3.4e+67]], $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 -2.3 \cdot 10^{-21} \lor \neg \left(d \leq 3.4 \cdot 10^{+67}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if d < -2.29999999999999999e-21 or 3.4000000000000002e67 < d Initial program 45.8%
Taylor expanded in c around 0 65.8%
if -2.29999999999999999e-21 < d < 3.4000000000000002e67Initial program 71.4%
Taylor expanded in c around inf 78.2%
associate-/l*77.1%
Simplified77.1%
pow277.1%
associate-*r/78.2%
associate-/r*84.1%
Applied egg-rr84.1%
associate-/l/78.2%
*-commutative78.2%
times-frac82.1%
Applied egg-rr82.1%
Final simplification74.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.9e-21) (not (<= d 1.8e+67))) (/ b d) (+ (/ a c) (/ (/ (* b d) c) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.9e-21) || !(d <= 1.8e+67)) {
tmp = b / d;
} else {
tmp = (a / c) + (((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.9d-21)) .or. (.not. (d <= 1.8d+67))) then
tmp = b / d
else
tmp = (a / c) + (((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.9e-21) || !(d <= 1.8e+67)) {
tmp = b / d;
} else {
tmp = (a / c) + (((b * d) / c) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.9e-21) or not (d <= 1.8e+67): tmp = b / d else: tmp = (a / c) + (((b * d) / c) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.9e-21) || !(d <= 1.8e+67)) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.9e-21) || ~((d <= 1.8e+67))) tmp = b / d; else tmp = (a / c) + (((b * d) / c) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.9e-21], N[Not[LessEqual[d, 1.8e+67]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{-21} \lor \neg \left(d \leq 1.8 \cdot 10^{+67}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.8999999999999999e-21 or 1.7999999999999999e67 < d Initial program 45.8%
Taylor expanded in c around 0 65.8%
if -1.8999999999999999e-21 < d < 1.7999999999999999e67Initial program 71.4%
Taylor expanded in c around inf 78.2%
associate-/l*77.1%
Simplified77.1%
pow277.1%
associate-*r/78.2%
associate-/r*84.1%
Applied egg-rr84.1%
Final simplification75.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.2e-22) (not (<= d 3.4e+68))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.2e-22) || !(d <= 3.4e+68)) {
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 <= (-3.2d-22)) .or. (.not. (d <= 3.4d+68))) 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 <= -3.2e-22) || !(d <= 3.4e+68)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.2e-22) or not (d <= 3.4e+68): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.2e-22) || !(d <= 3.4e+68)) 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 <= -3.2e-22) || ~((d <= 3.4e+68))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.2e-22], N[Not[LessEqual[d, 3.4e+68]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{-22} \lor \neg \left(d \leq 3.4 \cdot 10^{+68}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -3.19999999999999987e-22 or 3.40000000000000015e68 < d Initial program 45.8%
Taylor expanded in c around 0 65.8%
if -3.19999999999999987e-22 < d < 3.40000000000000015e68Initial program 71.4%
Taylor expanded in c around inf 67.1%
Final simplification66.5%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 59.6%
Taylor expanded in c around inf 45.0%
Final simplification45.0%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024039
(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))))