
(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 10 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))))
(if (<= (/ t_0 (+ (* c c) (* d d))) INFINITY)
(/ (/ t_0 (hypot c d)) (hypot c d))
(+ (/ b d) (* (/ c d) (/ a d))))))
double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (b * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (t_0 / hypot(c, d)) / hypot(c, d);
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (b * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= Double.POSITIVE_INFINITY) {
tmp = (t_0 / Math.hypot(c, d)) / Math.hypot(c, d);
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = (a * c) + (b * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= math.inf: tmp = (t_0 / math.hypot(c, d)) / math.hypot(c, d) else: tmp = (b / d) + ((c / d) * (a / d)) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a * c) + Float64(b * d)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= Inf) tmp = Float64(Float64(t_0 / hypot(c, d)) / hypot(c, d)); 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) t_0 = (a * c) + (b * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= Inf) tmp = (t_0 / hypot(c, d)) / hypot(c, d); else tmp = (b / d) + ((c / d) * (a / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
\mathbf{if}\;\frac{t_0}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{\frac{t_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 77.6%
*-un-lft-identity77.6%
add-sqr-sqrt77.6%
times-frac77.5%
hypot-def77.5%
fma-def77.5%
hypot-def94.0%
Applied egg-rr94.0%
associate-*l/94.3%
*-un-lft-identity94.3%
Applied egg-rr94.3%
fma-def94.3%
+-commutative94.3%
Applied egg-rr94.3%
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 0 45.3%
unpow245.3%
times-frac55.4%
Simplified55.4%
Final simplification86.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.46e+85)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= c -9e-46)
t_0
(if (<= c 2.6e-159)
(+ (/ b d) (/ (* a (/ c d)) d))
(if (<= c 2.45e+36)
t_0
(* (/ 1.0 (hypot c d)) (+ a (/ d (/ c b))))))))))
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.46e+85) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= -9e-46) {
tmp = t_0;
} else if (c <= 2.6e-159) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 2.45e+36) {
tmp = t_0;
} else {
tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b)));
}
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.46e+85) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= -9e-46) {
tmp = t_0;
} else if (c <= 2.6e-159) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 2.45e+36) {
tmp = t_0;
} else {
tmp = (1.0 / Math.hypot(c, d)) * (a + (d / (c / b)));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.46e+85: tmp = (a / c) + ((d * (b / c)) / c) elif c <= -9e-46: tmp = t_0 elif c <= 2.6e-159: tmp = (b / d) + ((a * (c / d)) / d) elif c <= 2.45e+36: tmp = t_0 else: tmp = (1.0 / math.hypot(c, d)) * (a + (d / (c / b))) 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.46e+85) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= -9e-46) tmp = t_0; elseif (c <= 2.6e-159) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); elseif (c <= 2.45e+36) tmp = t_0; else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(d / Float64(c / b)))); 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.46e+85) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= -9e-46) tmp = t_0; elseif (c <= 2.6e-159) tmp = (b / d) + ((a * (c / d)) / d); elseif (c <= 2.45e+36) tmp = t_0; else tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b))); 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.46e+85], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -9e-46], t$95$0, If[LessEqual[c, 2.6e-159], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.45e+36], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(d / N[(c / b), $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.46 \cdot 10^{+85}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq -9 \cdot 10^{-46}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{-159}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.45 \cdot 10^{+36}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\
\end{array}
\end{array}
if c < -1.46e85Initial program 41.5%
Taylor expanded in c around inf 78.3%
unpow278.3%
times-frac86.2%
Simplified86.2%
associate-*l/87.5%
Applied egg-rr87.5%
if -1.46e85 < c < -9.00000000000000001e-46 or 2.5999999999999998e-159 < c < 2.4499999999999999e36Initial program 90.0%
if -9.00000000000000001e-46 < c < 2.5999999999999998e-159Initial program 63.0%
Taylor expanded in c around 0 80.4%
unpow280.4%
times-frac79.3%
Simplified79.3%
associate-*r/85.4%
Applied egg-rr85.4%
if 2.4499999999999999e36 < c Initial program 43.4%
*-un-lft-identity43.4%
add-sqr-sqrt43.4%
times-frac43.4%
hypot-def43.4%
fma-def43.4%
hypot-def62.3%
Applied egg-rr62.3%
Taylor expanded in c around inf 78.6%
associate-/l*80.5%
Simplified80.5%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (+ (/ a c) (/ (* d (/ b c)) c))))
(if (<= c -2.15e+85)
t_1
(if (<= c -1.15e-45)
t_0
(if (<= c 4.5e-159)
(+ (/ b d) (/ (* a (/ c d)) d))
(if (<= c 1.2e+34) 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 * (b / c)) / c);
double tmp;
if (c <= -2.15e+85) {
tmp = t_1;
} else if (c <= -1.15e-45) {
tmp = t_0;
} else if (c <= 4.5e-159) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 1.2e+34) {
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 * (b / c)) / c)
if (c <= (-2.15d+85)) then
tmp = t_1
else if (c <= (-1.15d-45)) then
tmp = t_0
else if (c <= 4.5d-159) then
tmp = (b / d) + ((a * (c / d)) / d)
else if (c <= 1.2d+34) 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 * (b / c)) / c);
double tmp;
if (c <= -2.15e+85) {
tmp = t_1;
} else if (c <= -1.15e-45) {
tmp = t_0;
} else if (c <= 4.5e-159) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 1.2e+34) {
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 * (b / c)) / c) tmp = 0 if c <= -2.15e+85: tmp = t_1 elif c <= -1.15e-45: tmp = t_0 elif c <= 4.5e-159: tmp = (b / d) + ((a * (c / d)) / d) elif c <= 1.2e+34: 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 * Float64(b / c)) / c)) tmp = 0.0 if (c <= -2.15e+85) tmp = t_1; elseif (c <= -1.15e-45) tmp = t_0; elseif (c <= 4.5e-159) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); elseif (c <= 1.2e+34) 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 * (b / c)) / c); tmp = 0.0; if (c <= -2.15e+85) tmp = t_1; elseif (c <= -1.15e-45) tmp = t_0; elseif (c <= 4.5e-159) tmp = (b / d) + ((a * (c / d)) / d); elseif (c <= 1.2e+34) 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 * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.15e+85], t$95$1, If[LessEqual[c, -1.15e-45], t$95$0, If[LessEqual[c, 4.5e-159], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.2e+34], 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 \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -2.15 \cdot 10^{+85}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -1.15 \cdot 10^{-45}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{-159}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{+34}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -2.15e85 or 1.19999999999999993e34 < c Initial program 42.4%
Taylor expanded in c around inf 75.5%
unpow275.5%
times-frac82.4%
Simplified82.4%
associate-*l/83.9%
Applied egg-rr83.9%
if -2.15e85 < c < -1.14999999999999996e-45 or 4.49999999999999989e-159 < c < 1.19999999999999993e34Initial program 90.0%
if -1.14999999999999996e-45 < c < 4.49999999999999989e-159Initial program 63.0%
Taylor expanded in c around 0 80.4%
unpow280.4%
times-frac79.3%
Simplified79.3%
associate-*r/85.4%
Applied egg-rr85.4%
Final simplification86.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.8e+36) (not (<= d 1.05e+33))) (/ b (+ d (* c (/ c d)))) (+ (/ a c) (* (/ b c) (/ d c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+36) || !(d <= 1.05e+33)) {
tmp = b / (d + (c * (c / d)));
} else {
tmp = (a / c) + ((b / c) * (d / 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.8d+36)) .or. (.not. (d <= 1.05d+33))) then
tmp = b / (d + (c * (c / d)))
else
tmp = (a / c) + ((b / c) * (d / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+36) || !(d <= 1.05e+33)) {
tmp = b / (d + (c * (c / d)));
} else {
tmp = (a / c) + ((b / c) * (d / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.8e+36) or not (d <= 1.05e+33): tmp = b / (d + (c * (c / d))) else: tmp = (a / c) + ((b / c) * (d / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.8e+36) || !(d <= 1.05e+33)) tmp = Float64(b / Float64(d + Float64(c * Float64(c / d)))); else tmp = Float64(Float64(a / c) + Float64(Float64(b / c) * Float64(d / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.8e+36) || ~((d <= 1.05e+33))) tmp = b / (d + (c * (c / d))); else tmp = (a / c) + ((b / c) * (d / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.8e+36], N[Not[LessEqual[d, 1.05e+33]], $MachinePrecision]], N[(b / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{+36} \lor \neg \left(d \leq 1.05 \cdot 10^{+33}\right):\\
\;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\end{array}
\end{array}
if d < -1.7999999999999999e36 or 1.05e33 < d Initial program 47.1%
Taylor expanded in a around 0 37.5%
*-commutative37.5%
associate-/l*41.7%
unpow241.7%
unpow241.7%
+-commutative41.7%
fma-udef41.7%
Simplified41.7%
add-sqr-sqrt41.7%
fma-udef41.7%
hypot-udef41.7%
fma-udef41.7%
hypot-udef41.7%
*-un-lft-identity41.7%
times-frac73.5%
/-rgt-identity73.5%
Applied egg-rr73.5%
Taylor expanded in c around 0 64.1%
+-commutative64.1%
unpow264.1%
associate-*r/73.5%
Simplified73.5%
if -1.7999999999999999e36 < d < 1.05e33Initial program 73.9%
Taylor expanded in c around inf 77.4%
unpow277.4%
times-frac81.0%
Simplified81.0%
Final simplification77.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.02e+36) (not (<= d 3.8e+33))) (/ b (+ d (* c (/ c d)))) (+ (/ a c) (/ (* d (/ b c)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.02e+36) || !(d <= 3.8e+33)) {
tmp = b / (d + (c * (c / d)));
} else {
tmp = (a / c) + ((d * (b / 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.02d+36)) .or. (.not. (d <= 3.8d+33))) then
tmp = b / (d + (c * (c / d)))
else
tmp = (a / c) + ((d * (b / 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.02e+36) || !(d <= 3.8e+33)) {
tmp = b / (d + (c * (c / d)));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.02e+36) or not (d <= 3.8e+33): tmp = b / (d + (c * (c / d))) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.02e+36) || !(d <= 3.8e+33)) tmp = Float64(b / Float64(d + Float64(c * Float64(c / d)))); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.02e+36) || ~((d <= 3.8e+33))) tmp = b / (d + (c * (c / d))); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.02e+36], N[Not[LessEqual[d, 3.8e+33]], $MachinePrecision]], N[(b / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+36} \lor \neg \left(d \leq 3.8 \cdot 10^{+33}\right):\\
\;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.02000000000000003e36 or 3.80000000000000002e33 < d Initial program 47.1%
Taylor expanded in a around 0 37.5%
*-commutative37.5%
associate-/l*41.7%
unpow241.7%
unpow241.7%
+-commutative41.7%
fma-udef41.7%
Simplified41.7%
add-sqr-sqrt41.7%
fma-udef41.7%
hypot-udef41.7%
fma-udef41.7%
hypot-udef41.7%
*-un-lft-identity41.7%
times-frac73.5%
/-rgt-identity73.5%
Applied egg-rr73.5%
Taylor expanded in c around 0 64.1%
+-commutative64.1%
unpow264.1%
associate-*r/73.5%
Simplified73.5%
if -1.02000000000000003e36 < d < 3.80000000000000002e33Initial program 73.9%
Taylor expanded in c around inf 77.4%
unpow277.4%
times-frac81.0%
Simplified81.0%
associate-*l/82.2%
Applied egg-rr82.2%
Final simplification78.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5e+18) (not (<= d 7e+26))) (+ (/ b d) (* (/ c d) (/ a d))) (+ (/ a c) (/ (* d (/ b c)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+18) || !(d <= 7e+26)) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d * (b / 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 <= (-5d+18)) .or. (.not. (d <= 7d+26))) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (a / c) + ((d * (b / c)) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+18) || !(d <= 7e+26)) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5e+18) or not (d <= 7e+26): tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5e+18) || !(d <= 7e+26)) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5e+18) || ~((d <= 7e+26))) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5e+18], N[Not[LessEqual[d, 7e+26]], $MachinePrecision]], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+18} \lor \neg \left(d \leq 7 \cdot 10^{+26}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -5e18 or 6.9999999999999998e26 < d Initial program 48.9%
Taylor expanded in c around 0 74.4%
unpow274.4%
times-frac79.2%
Simplified79.2%
if -5e18 < d < 6.9999999999999998e26Initial program 73.4%
Taylor expanded in c around inf 79.2%
unpow279.2%
times-frac83.0%
Simplified83.0%
associate-*l/84.2%
Applied egg-rr84.2%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -4.1e+18)
(+ (/ b d) (/ (* a (/ c d)) d))
(if (<= d 7.5e+26)
(+ (/ a c) (/ (* d (/ b c)) c))
(+ (/ b d) (* (/ c d) (/ a d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.1e+18) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (d <= 7.5e+26) {
tmp = (a / c) + ((d * (b / c)) / 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 (d <= (-4.1d+18)) then
tmp = (b / d) + ((a * (c / d)) / d)
else if (d <= 7.5d+26) then
tmp = (a / c) + ((d * (b / c)) / 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 (d <= -4.1e+18) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (d <= 7.5e+26) {
tmp = (a / c) + ((d * (b / c)) / c);
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4.1e+18: tmp = (b / d) + ((a * (c / d)) / d) elif d <= 7.5e+26: tmp = (a / c) + ((d * (b / c)) / c) else: tmp = (b / d) + ((c / d) * (a / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4.1e+18) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); elseif (d <= 7.5e+26) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / 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 (d <= -4.1e+18) tmp = (b / d) + ((a * (c / d)) / d); elseif (d <= 7.5e+26) tmp = (a / c) + ((d * (b / c)) / c); else tmp = (b / d) + ((c / d) * (a / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.1e+18], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.5e+26], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $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}\;d \leq -4.1 \cdot 10^{+18}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+26}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if d < -4.1e18Initial program 55.3%
Taylor expanded in c around 0 78.3%
unpow278.3%
times-frac84.5%
Simplified84.5%
associate-*r/84.5%
Applied egg-rr84.5%
if -4.1e18 < d < 7.49999999999999941e26Initial program 73.4%
Taylor expanded in c around inf 79.2%
unpow279.2%
times-frac83.0%
Simplified83.0%
associate-*l/84.2%
Applied egg-rr84.2%
if 7.49999999999999941e26 < d Initial program 44.5%
Taylor expanded in c around 0 71.7%
unpow271.7%
times-frac75.5%
Simplified75.5%
Final simplification81.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.45e+96) (not (<= c 8e-18))) (/ a c) (/ b (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.45e+96) || !(c <= 8e-18)) {
tmp = a / c;
} else {
tmp = b / (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 ((c <= (-1.45d+96)) .or. (.not. (c <= 8d-18))) then
tmp = a / c
else
tmp = b / (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 ((c <= -1.45e+96) || !(c <= 8e-18)) {
tmp = a / c;
} else {
tmp = b / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.45e+96) or not (c <= 8e-18): tmp = a / c else: tmp = b / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.45e+96) || !(c <= 8e-18)) tmp = Float64(a / c); else tmp = Float64(b / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.45e+96) || ~((c <= 8e-18))) tmp = a / c; else tmp = b / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.45e+96], N[Not[LessEqual[c, 8e-18]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{+96} \lor \neg \left(c \leq 8 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
if c < -1.44999999999999989e96 or 8.0000000000000006e-18 < c Initial program 47.6%
Taylor expanded in c around inf 72.4%
if -1.44999999999999989e96 < c < 8.0000000000000006e-18Initial program 73.2%
Taylor expanded in a around 0 48.0%
*-commutative48.0%
associate-/l*51.3%
unpow251.3%
unpow251.3%
+-commutative51.3%
fma-udef51.3%
Simplified51.3%
add-sqr-sqrt51.3%
fma-udef51.3%
hypot-udef51.3%
fma-udef51.3%
hypot-udef51.3%
*-un-lft-identity51.3%
times-frac69.8%
/-rgt-identity69.8%
Applied egg-rr69.8%
Taylor expanded in c around 0 68.2%
+-commutative68.2%
unpow268.2%
associate-*r/69.8%
Simplified69.8%
Final simplification71.0%
(FPCore (a b c d) :precision binary64 (if (<= d -1.3e+39) (/ b d) (if (<= d 7.6e+26) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.3e+39) {
tmp = b / d;
} else if (d <= 7.6e+26) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-1.3d+39)) then
tmp = b / d
else if (d <= 7.6d+26) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.3e+39) {
tmp = b / d;
} else if (d <= 7.6e+26) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.3e+39: tmp = b / d elif d <= 7.6e+26: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.3e+39) tmp = Float64(b / d); elseif (d <= 7.6e+26) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.3e+39) tmp = b / d; elseif (d <= 7.6e+26) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.3e+39], N[(b / d), $MachinePrecision], If[LessEqual[d, 7.6e+26], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.3 \cdot 10^{+39}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 7.6 \cdot 10^{+26}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.3e39 or 7.6000000000000004e26 < d Initial program 47.6%
Taylor expanded in c around 0 66.3%
if -1.3e39 < d < 7.6000000000000004e26Initial program 74.0%
Taylor expanded in c around inf 65.5%
Final simplification65.9%
(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 61.8%
Taylor expanded in c around inf 42.8%
Final simplification42.8%
(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 2023230
(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))))