
(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))))
(if (<= (/ t_0 (+ (* c c) (* d d))) INFINITY)
(/ (/ t_0 (hypot c d)) (hypot c d))
(* (/ d (hypot c d)) (/ b (hypot c 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 = (d / hypot(c, d)) * (b / hypot(c, 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 = (d / Math.hypot(c, d)) * (b / Math.hypot(c, 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 = (d / math.hypot(c, d)) * (b / math.hypot(c, 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(d / hypot(c, d)) * Float64(b / hypot(c, 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 = (d / hypot(c, d)) * (b / hypot(c, 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[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $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{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\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.0Initial program 76.7%
+-commutative76.7%
fma-udef76.8%
*-un-lft-identity76.8%
associate-*r/76.8%
add-sqr-sqrt76.7%
times-frac76.7%
fma-udef76.7%
+-commutative76.7%
hypot-def76.7%
fma-def76.7%
fma-udef76.7%
+-commutative76.7%
hypot-def93.2%
Applied egg-rr93.2%
associate-*l/93.4%
*-un-lft-identity93.4%
Applied egg-rr93.4%
fma-def93.4%
+-commutative93.4%
Applied egg-rr93.4%
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 a around 0 1.2%
*-commutative1.2%
add-sqr-sqrt1.2%
hypot-udef1.2%
hypot-udef1.2%
times-frac65.2%
Applied egg-rr65.2%
Final simplification88.3%
(FPCore (a b c d)
:precision binary64
(if (<= d -3.4e+130)
(+ (/ b d) (/ (/ 1.0 (/ (/ d c) a)) d))
(if (<= d -3.4e-105)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 3.2e+23)
(* (/ 1.0 c) (+ a (/ b (/ c d))))
(* (/ d (hypot c d)) (/ b (hypot c d)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.4e+130) {
tmp = (b / d) + ((1.0 / ((d / c) / a)) / d);
} else if (d <= -3.4e-105) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 3.2e+23) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (d / hypot(c, d)) * (b / hypot(c, d));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.4e+130) {
tmp = (b / d) + ((1.0 / ((d / c) / a)) / d);
} else if (d <= -3.4e-105) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 3.2e+23) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (d / Math.hypot(c, d)) * (b / Math.hypot(c, d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3.4e+130: tmp = (b / d) + ((1.0 / ((d / c) / a)) / d) elif d <= -3.4e-105: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 3.2e+23: tmp = (1.0 / c) * (a + (b / (c / d))) else: tmp = (d / math.hypot(c, d)) * (b / math.hypot(c, d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3.4e+130) tmp = Float64(Float64(b / d) + Float64(Float64(1.0 / Float64(Float64(d / c) / a)) / d)); elseif (d <= -3.4e-105) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 3.2e+23) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); else tmp = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3.4e+130) tmp = (b / d) + ((1.0 / ((d / c) / a)) / d); elseif (d <= -3.4e-105) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 3.2e+23) tmp = (1.0 / c) * (a + (b / (c / d))); else tmp = (d / hypot(c, d)) * (b / hypot(c, d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.4e+130], N[(N[(b / d), $MachinePrecision] + N[(N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.4e-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, 3.2e+23], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.4 \cdot 10^{+130}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\
\mathbf{elif}\;d \leq -3.4 \cdot 10^{-105}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{+23}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -3.4000000000000001e130Initial program 41.1%
Taylor expanded in c around 0 81.6%
associate-/l*77.6%
associate-/r/82.0%
Simplified82.0%
pow282.0%
associate-*l/81.6%
associate-/r*88.4%
Applied egg-rr88.4%
clear-num88.4%
inv-pow88.4%
Applied egg-rr88.4%
unpow-188.4%
*-commutative88.4%
associate-/r*88.5%
Simplified88.5%
if -3.4000000000000001e130 < d < -3.39999999999999992e-105Initial program 81.6%
if -3.39999999999999992e-105 < d < 3.2e23Initial program 70.7%
+-commutative70.7%
fma-udef70.7%
*-un-lft-identity70.7%
associate-*r/70.7%
add-sqr-sqrt70.7%
times-frac70.7%
fma-udef70.7%
+-commutative70.7%
hypot-def70.7%
fma-def70.7%
fma-udef70.7%
+-commutative70.7%
hypot-def85.8%
Applied egg-rr85.8%
Taylor expanded in c around inf 49.3%
associate-/l*50.2%
Simplified50.2%
Taylor expanded in c around inf 89.8%
if 3.2e23 < d Initial program 46.3%
Taylor expanded in a around 0 41.7%
*-commutative41.7%
add-sqr-sqrt41.7%
hypot-udef41.7%
hypot-udef41.7%
times-frac81.5%
Applied egg-rr81.5%
Final simplification86.0%
(FPCore (a b c d)
:precision binary64
(if (<= d -3.4e+130)
(+ (/ b d) (/ (/ 1.0 (/ (/ d c) a)) d))
(if (<= d -9.5e-107)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 6.2e+23)
(* (/ 1.0 c) (+ a (/ b (/ c d))))
(+ (/ b d) (/ (* c (/ a d)) d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.4e+130) {
tmp = (b / d) + ((1.0 / ((d / c) / a)) / d);
} else if (d <= -9.5e-107) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 6.2e+23) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (b / d) + ((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 <= (-3.4d+130)) then
tmp = (b / d) + ((1.0d0 / ((d / c) / a)) / d)
else if (d <= (-9.5d-107)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (d <= 6.2d+23) then
tmp = (1.0d0 / c) * (a + (b / (c / d)))
else
tmp = (b / d) + ((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 <= -3.4e+130) {
tmp = (b / d) + ((1.0 / ((d / c) / a)) / d);
} else if (d <= -9.5e-107) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 6.2e+23) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (b / d) + ((c * (a / d)) / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3.4e+130: tmp = (b / d) + ((1.0 / ((d / c) / a)) / d) elif d <= -9.5e-107: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 6.2e+23: tmp = (1.0 / c) * (a + (b / (c / d))) else: tmp = (b / d) + ((c * (a / d)) / d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3.4e+130) tmp = Float64(Float64(b / d) + Float64(Float64(1.0 / Float64(Float64(d / c) / a)) / d)); elseif (d <= -9.5e-107) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 6.2e+23) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); else tmp = Float64(Float64(b / d) + Float64(Float64(c * Float64(a / d)) / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3.4e+130) tmp = (b / d) + ((1.0 / ((d / c) / a)) / d); elseif (d <= -9.5e-107) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 6.2e+23) tmp = (1.0 / c) * (a + (b / (c / d))); else tmp = (b / d) + ((c * (a / d)) / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.4e+130], N[(N[(b / d), $MachinePrecision] + N[(N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -9.5e-107], 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, 6.2e+23], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.4 \cdot 10^{+130}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\
\mathbf{elif}\;d \leq -9.5 \cdot 10^{-107}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{+23}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -3.4000000000000001e130Initial program 41.1%
Taylor expanded in c around 0 81.6%
associate-/l*77.6%
associate-/r/82.0%
Simplified82.0%
pow282.0%
associate-*l/81.6%
associate-/r*88.4%
Applied egg-rr88.4%
clear-num88.4%
inv-pow88.4%
Applied egg-rr88.4%
unpow-188.4%
*-commutative88.4%
associate-/r*88.5%
Simplified88.5%
if -3.4000000000000001e130 < d < -9.4999999999999999e-107Initial program 81.6%
if -9.4999999999999999e-107 < d < 6.19999999999999941e23Initial program 70.7%
+-commutative70.7%
fma-udef70.7%
*-un-lft-identity70.7%
associate-*r/70.7%
add-sqr-sqrt70.7%
times-frac70.7%
fma-udef70.7%
+-commutative70.7%
hypot-def70.7%
fma-def70.7%
fma-udef70.7%
+-commutative70.7%
hypot-def85.8%
Applied egg-rr85.8%
Taylor expanded in c around inf 49.3%
associate-/l*50.2%
Simplified50.2%
Taylor expanded in c around inf 89.8%
if 6.19999999999999941e23 < d Initial program 46.3%
Taylor expanded in c around 0 72.8%
associate-/l*74.9%
associate-/r/76.5%
Simplified76.5%
pow276.5%
associate-*l/72.8%
associate-/r*74.8%
Applied egg-rr74.8%
expm1-log1p-u72.8%
expm1-udef67.6%
associate-/l*70.8%
div-inv70.8%
clear-num70.8%
Applied egg-rr70.8%
expm1-def76.0%
expm1-log1p78.5%
associate-*r/74.8%
*-commutative74.8%
associate-*r/78.5%
Simplified78.5%
Final simplification85.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.3e+38) (not (<= d 8.6e+23))) (/ b d) (* (/ 1.0 c) (+ a (/ b (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.3e+38) || !(d <= 8.6e+23)) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + (b / (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 ((d <= (-3.3d+38)) .or. (.not. (d <= 8.6d+23))) then
tmp = b / d
else
tmp = (1.0d0 / c) * (a + (b / (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.3e+38) || !(d <= 8.6e+23)) {
tmp = b / d;
} else {
tmp = (1.0 / c) * (a + (b / (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.3e+38) or not (d <= 8.6e+23): tmp = b / d else: tmp = (1.0 / c) * (a + (b / (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.3e+38) || !(d <= 8.6e+23)) tmp = Float64(b / d); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.3e+38) || ~((d <= 8.6e+23))) tmp = b / d; else tmp = (1.0 / c) * (a + (b / (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.3e+38], N[Not[LessEqual[d, 8.6e+23]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.3 \cdot 10^{+38} \lor \neg \left(d \leq 8.6 \cdot 10^{+23}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\end{array}
\end{array}
if d < -3.2999999999999999e38 or 8.5999999999999997e23 < d Initial program 49.8%
Taylor expanded in c around 0 70.3%
if -3.2999999999999999e38 < d < 8.5999999999999997e23Initial program 73.6%
+-commutative73.6%
fma-udef73.6%
*-un-lft-identity73.6%
associate-*r/73.6%
add-sqr-sqrt73.6%
times-frac73.6%
fma-udef73.6%
+-commutative73.6%
hypot-def73.6%
fma-def73.6%
fma-udef73.6%
+-commutative73.6%
hypot-def87.1%
Applied egg-rr87.1%
Taylor expanded in c around inf 44.2%
associate-/l*44.9%
Simplified44.9%
Taylor expanded in c around inf 82.6%
Final simplification76.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.0115) (not (<= d 5e+24))) (+ (/ b d) (* (/ c d) (/ a d))) (* (/ 1.0 c) (+ a (/ b (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.0115) || !(d <= 5e+24)) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (1.0 / c) * (a + (b / (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 ((d <= (-0.0115d0)) .or. (.not. (d <= 5d+24))) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (1.0d0 / c) * (a + (b / (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.0115) || !(d <= 5e+24)) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (1.0 / c) * (a + (b / (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.0115) or not (d <= 5e+24): tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (1.0 / c) * (a + (b / (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.0115) || !(d <= 5e+24)) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.0115) || ~((d <= 5e+24))) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (1.0 / c) * (a + (b / (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.0115], N[Not[LessEqual[d, 5e+24]], $MachinePrecision]], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0115 \lor \neg \left(d \leq 5 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\end{array}
\end{array}
if d < -0.0115 or 5.00000000000000045e24 < d Initial program 52.6%
Taylor expanded in c around 0 73.5%
associate-/l*72.3%
associate-/r/75.3%
Simplified75.3%
pow275.3%
associate-*l/73.5%
associate-/r*76.6%
Applied egg-rr76.6%
associate-/l/73.5%
*-commutative73.5%
times-frac78.3%
Applied egg-rr78.3%
if -0.0115 < d < 5.00000000000000045e24Initial program 72.6%
+-commutative72.6%
fma-udef72.6%
*-un-lft-identity72.6%
associate-*r/72.6%
add-sqr-sqrt72.6%
times-frac72.6%
fma-udef72.6%
+-commutative72.6%
hypot-def72.6%
fma-def72.6%
fma-udef72.6%
+-commutative72.6%
hypot-def86.9%
Applied egg-rr86.9%
Taylor expanded in c around inf 44.8%
associate-/l*45.5%
Simplified45.5%
Taylor expanded in c around inf 85.1%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -8e-5)
(+ (/ b d) (* (/ c d) (/ a d)))
(if (<= d 1.25e+24)
(* (/ 1.0 c) (+ a (/ b (/ c d))))
(+ (/ b d) (/ (* c (/ a d)) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -8e-5) {
tmp = (b / d) + ((c / d) * (a / d));
} else if (d <= 1.25e+24) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (b / d) + ((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 <= (-8d-5)) then
tmp = (b / d) + ((c / d) * (a / d))
else if (d <= 1.25d+24) then
tmp = (1.0d0 / c) * (a + (b / (c / d)))
else
tmp = (b / d) + ((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 <= -8e-5) {
tmp = (b / d) + ((c / d) * (a / d));
} else if (d <= 1.25e+24) {
tmp = (1.0 / c) * (a + (b / (c / d)));
} else {
tmp = (b / d) + ((c * (a / d)) / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -8e-5: tmp = (b / d) + ((c / d) * (a / d)) elif d <= 1.25e+24: tmp = (1.0 / c) * (a + (b / (c / d))) else: tmp = (b / d) + ((c * (a / d)) / d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -8e-5) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); elseif (d <= 1.25e+24) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d)))); else tmp = Float64(Float64(b / d) + Float64(Float64(c * Float64(a / d)) / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -8e-5) tmp = (b / d) + ((c / d) * (a / d)); elseif (d <= 1.25e+24) tmp = (1.0 / c) * (a + (b / (c / d))); else tmp = (b / d) + ((c * (a / d)) / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -8e-5], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.25e+24], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8 \cdot 10^{-5}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{+24}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\end{array}
\end{array}
if d < -8.00000000000000065e-5Initial program 57.7%
Taylor expanded in c around 0 74.0%
associate-/l*70.3%
associate-/r/74.3%
Simplified74.3%
pow274.3%
associate-*l/74.0%
associate-/r*78.1%
Applied egg-rr78.1%
associate-/l/74.0%
*-commutative74.0%
times-frac78.2%
Applied egg-rr78.2%
if -8.00000000000000065e-5 < d < 1.25000000000000011e24Initial program 72.6%
+-commutative72.6%
fma-udef72.6%
*-un-lft-identity72.6%
associate-*r/72.6%
add-sqr-sqrt72.6%
times-frac72.6%
fma-udef72.6%
+-commutative72.6%
hypot-def72.6%
fma-def72.6%
fma-udef72.6%
+-commutative72.6%
hypot-def86.9%
Applied egg-rr86.9%
Taylor expanded in c around inf 44.8%
associate-/l*45.5%
Simplified45.5%
Taylor expanded in c around inf 85.1%
if 1.25000000000000011e24 < d Initial program 46.3%
Taylor expanded in c around 0 72.8%
associate-/l*74.9%
associate-/r/76.5%
Simplified76.5%
pow276.5%
associate-*l/72.8%
associate-/r*74.8%
Applied egg-rr74.8%
expm1-log1p-u72.8%
expm1-udef67.6%
associate-/l*70.8%
div-inv70.8%
clear-num70.8%
Applied egg-rr70.8%
expm1-def76.0%
expm1-log1p78.5%
associate-*r/74.8%
*-commutative74.8%
associate-*r/78.5%
Simplified78.5%
Final simplification81.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.8e+59) (not (<= c 2.7e+18))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.8e+59) || !(c <= 2.7e+18)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-3.8d+59)) .or. (.not. (c <= 2.7d+18))) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.8e+59) || !(c <= 2.7e+18)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.8e+59) or not (c <= 2.7e+18): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.8e+59) || !(c <= 2.7e+18)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.8e+59) || ~((c <= 2.7e+18))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.8e+59], N[Not[LessEqual[c, 2.7e+18]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.8 \cdot 10^{+59} \lor \neg \left(c \leq 2.7 \cdot 10^{+18}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.8000000000000001e59 or 2.7e18 < c Initial program 43.6%
Taylor expanded in c around inf 73.4%
if -3.8000000000000001e59 < c < 2.7e18Initial program 75.9%
Taylor expanded in c around 0 63.9%
Final simplification67.8%
(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 62.7%
Taylor expanded in c around inf 42.2%
Final simplification42.2%
(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 2024027
(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))))