
(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 (* d (/ b c))) c)))
(if (<= c -1.15e+85)
t_0
(if (<= c -8.2e-112)
(* (fma a c (* d b)) (/ 1.0 (pow (hypot c d) 2.0)))
(if (<= c 2.2e-24) (/ (+ b (/ (* c a) d)) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -1.15e+85) {
tmp = t_0;
} else if (c <= -8.2e-112) {
tmp = fma(a, c, (d * b)) * (1.0 / pow(hypot(c, d), 2.0));
} else if (c <= 2.2e-24) {
tmp = (b + ((c * a) / d)) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(d * Float64(b / c))) / c) tmp = 0.0 if (c <= -1.15e+85) tmp = t_0; elseif (c <= -8.2e-112) tmp = Float64(fma(a, c, Float64(d * b)) * Float64(1.0 / (hypot(c, d) ^ 2.0))); elseif (c <= 2.2e-24) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.15e+85], t$95$0, If[LessEqual[c, -8.2e-112], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.2e-24], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -1.15 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -8.2 \cdot 10^{-112}:\\
\;\;\;\;\mathsf{fma}\left(a, c, d \cdot b\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{-24}:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.1499999999999999e85 or 2.20000000000000002e-24 < c Initial program 47.9%
fma-define47.9%
fma-define47.9%
Simplified47.9%
Taylor expanded in c around inf 77.7%
*-commutative77.7%
Simplified77.7%
associate-/l*82.6%
Applied egg-rr82.6%
if -1.1499999999999999e85 < c < -8.19999999999999991e-112Initial program 81.7%
fma-define81.7%
fma-define81.7%
Simplified81.7%
fma-define81.7%
fma-define81.7%
div-inv81.8%
fma-define81.8%
fma-define81.8%
add-sqr-sqrt81.8%
pow281.8%
fma-define81.8%
hypot-define81.8%
Applied egg-rr81.8%
if -8.19999999999999991e-112 < c < 2.20000000000000002e-24Initial program 69.6%
fma-define69.6%
fma-define69.6%
Simplified69.6%
Taylor expanded in d around inf 89.7%
Final simplification85.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* d (/ b c))) c)))
(if (<= c -7.8e+82)
t_0
(if (<= c -1e-112)
(/ (+ (* d b) (* c a)) (+ (* c c) (* d d)))
(if (<= c 6.2e-24) (/ (+ b (/ (* c a) d)) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -7.8e+82) {
tmp = t_0;
} else if (c <= -1e-112) {
tmp = ((d * b) + (c * a)) / ((c * c) + (d * d));
} else if (c <= 6.2e-24) {
tmp = (b + ((c * a) / d)) / 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 + (d * (b / c))) / c
if (c <= (-7.8d+82)) then
tmp = t_0
else if (c <= (-1d-112)) then
tmp = ((d * b) + (c * a)) / ((c * c) + (d * d))
else if (c <= 6.2d-24) then
tmp = (b + ((c * a) / d)) / 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 + (d * (b / c))) / c;
double tmp;
if (c <= -7.8e+82) {
tmp = t_0;
} else if (c <= -1e-112) {
tmp = ((d * b) + (c * a)) / ((c * c) + (d * d));
} else if (c <= 6.2e-24) {
tmp = (b + ((c * a) / d)) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (d * (b / c))) / c tmp = 0 if c <= -7.8e+82: tmp = t_0 elif c <= -1e-112: tmp = ((d * b) + (c * a)) / ((c * c) + (d * d)) elif c <= 6.2e-24: tmp = (b + ((c * a) / d)) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(d * Float64(b / c))) / c) tmp = 0.0 if (c <= -7.8e+82) tmp = t_0; elseif (c <= -1e-112) tmp = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 6.2e-24) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (d * (b / c))) / c; tmp = 0.0; if (c <= -7.8e+82) tmp = t_0; elseif (c <= -1e-112) tmp = ((d * b) + (c * a)) / ((c * c) + (d * d)); elseif (c <= 6.2e-24) tmp = (b + ((c * a) / d)) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -7.8e+82], t$95$0, If[LessEqual[c, -1e-112], N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.2e-24], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -7.8 \cdot 10^{+82}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1 \cdot 10^{-112}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{-24}:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -7.79999999999999951e82 or 6.2000000000000001e-24 < c Initial program 47.9%
fma-define47.9%
fma-define47.9%
Simplified47.9%
Taylor expanded in c around inf 77.7%
*-commutative77.7%
Simplified77.7%
associate-/l*82.6%
Applied egg-rr82.6%
if -7.79999999999999951e82 < c < -9.9999999999999995e-113Initial program 81.7%
if -9.9999999999999995e-113 < c < 6.2000000000000001e-24Initial program 69.6%
fma-define69.6%
fma-define69.6%
Simplified69.6%
Taylor expanded in d around inf 89.7%
Final simplification85.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.6e-68) (not (<= c 3.25e-24))) (/ (+ a (* d (/ b c))) c) (/ (+ b (/ (* c a) d)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.6e-68) || !(c <= 3.25e-24)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + ((c * a) / d)) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-4.6d-68)) .or. (.not. (c <= 3.25d-24))) then
tmp = (a + (d * (b / c))) / c
else
tmp = (b + ((c * a) / d)) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.6e-68) || !(c <= 3.25e-24)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + ((c * a) / d)) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.6e-68) or not (c <= 3.25e-24): tmp = (a + (d * (b / c))) / c else: tmp = (b + ((c * a) / d)) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.6e-68) || !(c <= 3.25e-24)) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.6e-68) || ~((c <= 3.25e-24))) tmp = (a + (d * (b / c))) / c; else tmp = (b + ((c * a) / d)) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.6e-68], N[Not[LessEqual[c, 3.25e-24]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.6 \cdot 10^{-68} \lor \neg \left(c \leq 3.25 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\end{array}
\end{array}
if c < -4.59999999999999994e-68 or 3.25e-24 < c Initial program 56.0%
fma-define56.0%
fma-define56.0%
Simplified56.0%
Taylor expanded in c around inf 75.2%
*-commutative75.2%
Simplified75.2%
associate-/l*79.0%
Applied egg-rr79.0%
if -4.59999999999999994e-68 < c < 3.25e-24Initial program 70.4%
fma-define70.4%
fma-define70.4%
Simplified70.4%
Taylor expanded in d around inf 86.6%
Final simplification82.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.6e-68) (not (<= c 1.45e-24))) (/ (+ a (* d (/ b c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.6e-68) || !(c <= 1.45e-24)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.6d-68)) .or. (.not. (c <= 1.45d-24))) then
tmp = (a + (d * (b / c))) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.6e-68) || !(c <= 1.45e-24)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.6e-68) or not (c <= 1.45e-24): tmp = (a + (d * (b / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.6e-68) || !(c <= 1.45e-24)) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.6e-68) || ~((c <= 1.45e-24))) tmp = (a + (d * (b / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.6e-68], N[Not[LessEqual[c, 1.45e-24]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.6 \cdot 10^{-68} \lor \neg \left(c \leq 1.45 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -5.6000000000000002e-68 or 1.4499999999999999e-24 < c Initial program 56.0%
fma-define56.0%
fma-define56.0%
Simplified56.0%
Taylor expanded in c around inf 75.2%
*-commutative75.2%
Simplified75.2%
associate-/l*79.0%
Applied egg-rr79.0%
if -5.6000000000000002e-68 < c < 1.4499999999999999e-24Initial program 70.4%
fma-define70.4%
fma-define70.4%
Simplified70.4%
Taylor expanded in d around inf 86.6%
associate-/l*84.9%
Simplified84.9%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.3e+32) (not (<= d 8500000000.0))) (/ b d) (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.3e+32) || !(d <= 8500000000.0)) {
tmp = b / d;
} else {
tmp = (a + ((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 <= (-6.3d+32)) .or. (.not. (d <= 8500000000.0d0))) then
tmp = b / d
else
tmp = (a + ((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 <= -6.3e+32) || !(d <= 8500000000.0)) {
tmp = b / d;
} else {
tmp = (a + ((d * b) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.3e+32) or not (d <= 8500000000.0): tmp = b / d else: tmp = (a + ((d * b) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.3e+32) || !(d <= 8500000000.0)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -6.3e+32) || ~((d <= 8500000000.0))) tmp = b / d; else tmp = (a + ((d * b) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.3e+32], N[Not[LessEqual[d, 8500000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.3 \cdot 10^{+32} \lor \neg \left(d \leq 8500000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\end{array}
\end{array}
if d < -6.3000000000000002e32 or 8.5e9 < d Initial program 41.6%
fma-define41.6%
fma-define41.6%
Simplified41.6%
Taylor expanded in c around 0 70.4%
if -6.3000000000000002e32 < d < 8.5e9Initial program 76.9%
fma-define76.9%
fma-define76.9%
Simplified76.9%
Taylor expanded in c around inf 80.4%
*-commutative80.4%
Simplified80.4%
Final simplification76.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.36e+38) (not (<= d 1050000000.0))) (/ b d) (/ (+ a (* d (/ b c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.36e+38) || !(d <= 1050000000.0)) {
tmp = b / d;
} else {
tmp = (a + (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.36d+38)) .or. (.not. (d <= 1050000000.0d0))) then
tmp = b / d
else
tmp = (a + (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.36e+38) || !(d <= 1050000000.0)) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.36e+38) or not (d <= 1050000000.0): tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.36e+38) || !(d <= 1050000000.0)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.36e+38) || ~((d <= 1050000000.0))) tmp = b / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.36e+38], N[Not[LessEqual[d, 1050000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.36 \cdot 10^{+38} \lor \neg \left(d \leq 1050000000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.36000000000000002e38 or 1.05e9 < d Initial program 41.6%
fma-define41.6%
fma-define41.6%
Simplified41.6%
Taylor expanded in c around 0 70.4%
if -1.36000000000000002e38 < d < 1.05e9Initial program 76.9%
fma-define76.9%
fma-define76.9%
Simplified76.9%
Taylor expanded in c around inf 80.4%
*-commutative80.4%
Simplified80.4%
associate-/l*80.1%
Applied egg-rr80.1%
Final simplification76.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.8e-64) (not (<= c 1.16e-59))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.8e-64) || !(c <= 1.16e-59)) {
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 <= (-2.8d-64)) .or. (.not. (c <= 1.16d-59))) 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 <= -2.8e-64) || !(c <= 1.16e-59)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.8e-64) or not (c <= 1.16e-59): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.8e-64) || !(c <= 1.16e-59)) 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 <= -2.8e-64) || ~((c <= 1.16e-59))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.8e-64], N[Not[LessEqual[c, 1.16e-59]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.8 \cdot 10^{-64} \lor \neg \left(c \leq 1.16 \cdot 10^{-59}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.80000000000000004e-64 or 1.16e-59 < c Initial program 56.8%
fma-define56.8%
fma-define56.8%
Simplified56.8%
Taylor expanded in c around inf 65.9%
if -2.80000000000000004e-64 < c < 1.16e-59Initial program 70.3%
fma-define70.3%
fma-define70.3%
Simplified70.3%
Taylor expanded in c around 0 69.5%
Final simplification67.4%
(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%
fma-define62.7%
fma-define62.7%
Simplified62.7%
Taylor expanded in c around inf 44.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 2024144
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))