
(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 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+295) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (* a (+ 1.0 (* b (/ d (* a c))))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+295) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a * (1.0 + (b * (d / (a * c))))) / 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))) <= 2e+295) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a * Float64(1.0 + Float64(b * Float64(d / Float64(a * c))))) / 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], 2e+295], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a * N[(1.0 + N[(b * N[(d / N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+295}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \left(1 + b \cdot \frac{d}{a \cdot c}\right)}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2e295Initial program 80.5%
*-un-lft-identity80.5%
associate-*r/80.5%
fma-define80.5%
add-sqr-sqrt80.5%
times-frac80.5%
fma-define80.5%
hypot-define80.5%
fma-define80.5%
fma-define80.5%
hypot-define97.6%
Applied egg-rr97.6%
if 2e295 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.4%
Taylor expanded in c around inf 56.7%
Taylor expanded in a around inf 56.4%
associate-/l*59.9%
*-commutative59.9%
Simplified59.9%
Final simplification87.7%
(FPCore (a b c d) :precision binary64 (if (<= c -2.1e-53) (* (+ a (/ (* b d) c)) (/ -1.0 (hypot c d))) (if (<= c 2.15e-58) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.1e-53) {
tmp = (a + ((b * d) / c)) * (-1.0 / hypot(c, d));
} else if (c <= 2.15e-58) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.1e-53) {
tmp = (a + ((b * d) / c)) * (-1.0 / Math.hypot(c, d));
} else if (c <= 2.15e-58) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.1e-53: tmp = (a + ((b * d) / c)) * (-1.0 / math.hypot(c, d)) elif c <= 2.15e-58: tmp = (b + (a * (c / d))) / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.1e-53) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) * Float64(-1.0 / hypot(c, d))); elseif (c <= 2.15e-58) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / 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 (c <= -2.1e-53) tmp = (a + ((b * d) / c)) * (-1.0 / hypot(c, d)); elseif (c <= 2.15e-58) tmp = (b + (a * (c / d))) / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.1e-53], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.15e-58], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.1 \cdot 10^{-53}:\\
\;\;\;\;\left(a + \frac{b \cdot d}{c}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq 2.15 \cdot 10^{-58}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -2.09999999999999977e-53Initial program 55.7%
*-un-lft-identity55.7%
associate-*r/55.7%
fma-define55.7%
add-sqr-sqrt55.7%
times-frac55.7%
fma-define55.7%
hypot-define55.7%
fma-define55.7%
fma-define55.7%
hypot-define73.3%
Applied egg-rr73.3%
Taylor expanded in c around -inf 84.7%
if -2.09999999999999977e-53 < c < 2.15e-58Initial program 75.2%
Taylor expanded in d around inf 91.4%
associate-/l*91.4%
Simplified91.4%
if 2.15e-58 < c Initial program 53.2%
Taylor expanded in c around inf 81.4%
*-commutative81.4%
associate-/l*83.0%
Applied egg-rr83.0%
Final simplification87.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.7e-53) (not (<= c 7.2e-61))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.7e-53) || !(c <= 7.2e-61)) {
tmp = (a + (b * (d / c))) / 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.7d-53)) .or. (.not. (c <= 7.2d-61))) then
tmp = (a + (b * (d / c))) / 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.7e-53) || !(c <= 7.2e-61)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.7e-53) or not (c <= 7.2e-61): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.7e-53) || !(c <= 7.2e-61)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.7e-53) || ~((c <= 7.2e-61))) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.7e-53], N[Not[LessEqual[c, 7.2e-61]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.7 \cdot 10^{-53} \lor \neg \left(c \leq 7.2 \cdot 10^{-61}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.69999999999999982e-53 or 7.20000000000000028e-61 < c Initial program 54.5%
Taylor expanded in c around inf 82.4%
associate-/l*82.6%
Simplified82.6%
if -3.69999999999999982e-53 < c < 7.20000000000000028e-61Initial program 75.2%
Taylor expanded in c around 0 74.1%
Final simplification78.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.6e-41) (not (<= c 1.35e-59))) (/ (+ a (* d (/ b c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.6e-41) || !(c <= 1.35e-59)) {
tmp = (a + (d * (b / c))) / 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 <= (-1.6d-41)) .or. (.not. (c <= 1.35d-59))) then
tmp = (a + (d * (b / c))) / 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 <= -1.6e-41) || !(c <= 1.35e-59)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.6e-41) or not (c <= 1.35e-59): tmp = (a + (d * (b / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.6e-41) || !(c <= 1.35e-59)) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.6e-41) || ~((c <= 1.35e-59))) tmp = (a + (d * (b / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.6e-41], N[Not[LessEqual[c, 1.35e-59]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.6 \cdot 10^{-41} \lor \neg \left(c \leq 1.35 \cdot 10^{-59}\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.60000000000000006e-41 or 1.3499999999999999e-59 < c Initial program 54.2%
Taylor expanded in c around inf 82.7%
*-commutative82.7%
associate-/l*84.3%
Applied egg-rr84.3%
if -1.60000000000000006e-41 < c < 1.3499999999999999e-59Initial program 75.0%
Taylor expanded in c around 0 73.1%
Final simplification79.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.6e-41) (not (<= c 4.2e-63))) (/ (+ a (* d (/ b c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.6e-41) || !(c <= 4.2e-63)) {
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 <= (-4.6d-41)) .or. (.not. (c <= 4.2d-63))) 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 <= -4.6e-41) || !(c <= 4.2e-63)) {
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 <= -4.6e-41) or not (c <= 4.2e-63): 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 <= -4.6e-41) || !(c <= 4.2e-63)) 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 <= -4.6e-41) || ~((c <= 4.2e-63))) 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, -4.6e-41], N[Not[LessEqual[c, 4.2e-63]], $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 -4.6 \cdot 10^{-41} \lor \neg \left(c \leq 4.2 \cdot 10^{-63}\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 < -4.6000000000000002e-41 or 4.2e-63 < c Initial program 54.2%
Taylor expanded in c around inf 82.7%
*-commutative82.7%
associate-/l*84.3%
Applied egg-rr84.3%
if -4.6000000000000002e-41 < c < 4.2e-63Initial program 75.0%
Taylor expanded in d around inf 89.9%
associate-/l*89.9%
Simplified89.9%
Final simplification86.8%
(FPCore (a b c d) :precision binary64 (if (<= c -3.5e-53) (/ (* a (+ 1.0 (* b (/ d (* a c))))) c) (if (<= c 2.15e-58) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.5e-53) {
tmp = (a * (1.0 + (b * (d / (a * c))))) / c;
} else if (c <= 2.15e-58) {
tmp = (b + (a * (c / d))) / 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 (c <= (-3.5d-53)) then
tmp = (a * (1.0d0 + (b * (d / (a * c))))) / c
else if (c <= 2.15d-58) then
tmp = (b + (a * (c / d))) / 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 (c <= -3.5e-53) {
tmp = (a * (1.0 + (b * (d / (a * c))))) / c;
} else if (c <= 2.15e-58) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.5e-53: tmp = (a * (1.0 + (b * (d / (a * c))))) / c elif c <= 2.15e-58: tmp = (b + (a * (c / d))) / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.5e-53) tmp = Float64(Float64(a * Float64(1.0 + Float64(b * Float64(d / Float64(a * c))))) / c); elseif (c <= 2.15e-58) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / 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 (c <= -3.5e-53) tmp = (a * (1.0 + (b * (d / (a * c))))) / c; elseif (c <= 2.15e-58) tmp = (b + (a * (c / d))) / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.5e-53], N[(N[(a * N[(1.0 + N[(b * N[(d / N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.15e-58], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.5 \cdot 10^{-53}:\\
\;\;\;\;\frac{a \cdot \left(1 + b \cdot \frac{d}{a \cdot c}\right)}{c}\\
\mathbf{elif}\;c \leq 2.15 \cdot 10^{-58}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -3.49999999999999993e-53Initial program 55.7%
Taylor expanded in c around inf 83.3%
Taylor expanded in a around inf 83.0%
associate-/l*84.6%
*-commutative84.6%
Simplified84.6%
if -3.49999999999999993e-53 < c < 2.15e-58Initial program 75.2%
Taylor expanded in d around inf 91.4%
associate-/l*91.4%
Simplified91.4%
if 2.15e-58 < c Initial program 53.2%
Taylor expanded in c around inf 81.4%
*-commutative81.4%
associate-/l*83.0%
Applied egg-rr83.0%
Final simplification87.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.15e-39) (not (<= c 4.8e-62))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.15e-39) || !(c <= 4.8e-62)) {
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 <= (-1.15d-39)) .or. (.not. (c <= 4.8d-62))) 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 <= -1.15e-39) || !(c <= 4.8e-62)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.15e-39) or not (c <= 4.8e-62): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.15e-39) || !(c <= 4.8e-62)) 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 <= -1.15e-39) || ~((c <= 4.8e-62))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.15e-39], N[Not[LessEqual[c, 4.8e-62]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.15 \cdot 10^{-39} \lor \neg \left(c \leq 4.8 \cdot 10^{-62}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.15000000000000004e-39 or 4.79999999999999967e-62 < c Initial program 54.2%
Taylor expanded in c around inf 73.0%
if -1.15000000000000004e-39 < c < 4.79999999999999967e-62Initial program 75.0%
Taylor expanded in c around 0 73.1%
Final simplification73.0%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 63.5%
Taylor expanded in c around inf 49.4%
Final simplification49.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 2024059
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(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))))