
(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 11 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+299) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+299) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (b * (d / 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+299) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(b * Float64(d / 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+299], 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[(b * N[(d / c), $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^{+299}:\\
\;\;\;\;\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 + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000001e299Initial program 77.6%
*-un-lft-identity77.6%
associate-*r/77.6%
fma-define77.6%
add-sqr-sqrt77.6%
times-frac77.6%
fma-define77.6%
hypot-define77.6%
fma-define77.6%
fma-define77.6%
hypot-define97.7%
Applied egg-rr97.7%
if 2.0000000000000001e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 13.9%
Taylor expanded in c around inf 54.9%
associate-/l*63.5%
Simplified63.5%
Final simplification89.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -3.6e+65)
(/ (+ a (* b (/ d c))) (- (hypot c d)))
(if (<= c -2.5e-108)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 8.5e-18) (/ (+ 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.6e+65) {
tmp = (a + (b * (d / c))) / -hypot(c, d);
} else if (c <= -2.5e-108) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 8.5e-18) {
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 <= -3.6e+65) {
tmp = (a + (b * (d / c))) / -Math.hypot(c, d);
} else if (c <= -2.5e-108) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 8.5e-18) {
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.6e+65: tmp = (a + (b * (d / c))) / -math.hypot(c, d) elif c <= -2.5e-108: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 8.5e-18: 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.6e+65) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(-hypot(c, d))); elseif (c <= -2.5e-108) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 8.5e-18) tmp = Float64(Float64(b + Float64(Float64(a * 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.6e+65) tmp = (a + (b * (d / c))) / -hypot(c, d); elseif (c <= -2.5e-108) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 8.5e-18) 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.6e+65], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -2.5e-108], 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, 8.5e-18], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $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.6 \cdot 10^{+65}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{-\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -2.5 \cdot 10^{-108}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 8.5 \cdot 10^{-18}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -3.59999999999999978e65Initial program 32.2%
*-un-lft-identity32.2%
associate-*r/32.2%
fma-define32.2%
add-sqr-sqrt32.2%
times-frac32.0%
fma-define32.0%
hypot-define32.0%
fma-define32.0%
fma-define32.0%
hypot-define57.6%
Applied egg-rr57.6%
Taylor expanded in c around -inf 77.7%
associate-*l/77.9%
*-un-lft-identity77.9%
frac-2neg77.9%
Applied egg-rr80.7%
if -3.59999999999999978e65 < c < -2.5e-108Initial program 94.4%
if -2.5e-108 < c < 8.4999999999999995e-18Initial program 73.4%
Taylor expanded in d around inf 88.9%
if 8.4999999999999995e-18 < c Initial program 50.6%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
associate-/l*81.3%
Applied egg-rr81.3%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -3.4e+70)
(/ (+ a (* b (/ d c))) c)
(if (<= c -3e-106)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 3.6e-13) (/ (+ 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.4e+70) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -3e-106) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 3.6e-13) {
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.4d+70)) then
tmp = (a + (b * (d / c))) / c
else if (c <= (-3d-106)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (c <= 3.6d-13) 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.4e+70) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= -3e-106) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 3.6e-13) {
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.4e+70: tmp = (a + (b * (d / c))) / c elif c <= -3e-106: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 3.6e-13: 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.4e+70) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= -3e-106) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 3.6e-13) tmp = Float64(Float64(b + Float64(Float64(a * 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.4e+70) tmp = (a + (b * (d / c))) / c; elseif (c <= -3e-106) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 3.6e-13) 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.4e+70], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -3e-106], 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, 3.6e-13], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $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.4 \cdot 10^{+70}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -3 \cdot 10^{-106}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{-13}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -3.4000000000000001e70Initial program 32.2%
Taylor expanded in c around inf 77.7%
associate-/l*80.4%
Simplified80.4%
if -3.4000000000000001e70 < c < -3.00000000000000019e-106Initial program 94.4%
if -3.00000000000000019e-106 < c < 3.5999999999999998e-13Initial program 73.4%
Taylor expanded in d around inf 88.9%
if 3.5999999999999998e-13 < c Initial program 50.6%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
associate-/l*81.3%
Applied egg-rr81.3%
Final simplification86.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.4e-43) (not (<= c 8.8e-22))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.4e-43) || !(c <= 8.8e-22)) {
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 <= (-1.4d-43)) .or. (.not. (c <= 8.8d-22))) 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 <= -1.4e-43) || !(c <= 8.8e-22)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.4e-43) or not (c <= 8.8e-22): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.4e-43) || !(c <= 8.8e-22)) 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 <= -1.4e-43) || ~((c <= 8.8e-22))) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.4e-43], N[Not[LessEqual[c, 8.8e-22]], $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 -1.4 \cdot 10^{-43} \lor \neg \left(c \leq 8.8 \cdot 10^{-22}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.3999999999999999e-43 or 8.8000000000000002e-22 < c Initial program 52.5%
Taylor expanded in c around inf 74.5%
associate-/l*77.4%
Simplified77.4%
if -1.3999999999999999e-43 < c < 8.8000000000000002e-22Initial program 76.1%
Taylor expanded in c around 0 67.1%
Final simplification72.7%
(FPCore (a b c d) :precision binary64 (if (<= c -7.5e-46) (/ (+ a (* b (/ d c))) c) (if (<= c 6.5e-19) (/ b d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e-46) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 6.5e-19) {
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 (c <= (-7.5d-46)) then
tmp = (a + (b * (d / c))) / c
else if (c <= 6.5d-19) 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 (c <= -7.5e-46) {
tmp = (a + (b * (d / c))) / c;
} else if (c <= 6.5e-19) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -7.5e-46: tmp = (a + (b * (d / c))) / c elif c <= 6.5e-19: tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e-46) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif (c <= 6.5e-19) 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 (c <= -7.5e-46) tmp = (a + (b * (d / c))) / c; elseif (c <= 6.5e-19) tmp = b / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e-46], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 6.5e-19], 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}\;c \leq -7.5 \cdot 10^{-46}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 6.5 \cdot 10^{-19}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -7.50000000000000027e-46Initial program 54.8%
Taylor expanded in c around inf 73.8%
associate-/l*75.5%
Simplified75.5%
if -7.50000000000000027e-46 < c < 6.5000000000000001e-19Initial program 76.1%
Taylor expanded in c around 0 67.1%
if 6.5000000000000001e-19 < c Initial program 50.6%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
associate-/l*81.3%
Applied egg-rr81.3%
Final simplification73.4%
(FPCore (a b c d) :precision binary64 (if (<= c -3.5e-43) (/ (+ a (/ b (/ c d))) c) (if (<= c 2.45e-14) (/ b d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.5e-43) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 2.45e-14) {
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 (c <= (-3.5d-43)) then
tmp = (a + (b / (c / d))) / c
else if (c <= 2.45d-14) 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 (c <= -3.5e-43) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 2.45e-14) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.5e-43: tmp = (a + (b / (c / d))) / c elif c <= 2.45e-14: tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.5e-43) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (c <= 2.45e-14) 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 (c <= -3.5e-43) tmp = (a + (b / (c / d))) / c; elseif (c <= 2.45e-14) tmp = b / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.5e-43], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.45e-14], 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}\;c \leq -3.5 \cdot 10^{-43}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;c \leq 2.45 \cdot 10^{-14}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -3.49999999999999997e-43Initial program 54.8%
Taylor expanded in c around inf 73.8%
*-commutative73.8%
associate-/l*75.5%
Applied egg-rr75.5%
associate-*r/73.8%
associate-*l/75.5%
*-commutative75.5%
clear-num75.5%
un-div-inv75.5%
Applied egg-rr75.5%
if -3.49999999999999997e-43 < c < 2.44999999999999997e-14Initial program 76.1%
Taylor expanded in c around 0 67.1%
if 2.44999999999999997e-14 < c Initial program 50.6%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
associate-/l*81.3%
Applied egg-rr81.3%
Final simplification73.4%
(FPCore (a b c d) :precision binary64 (if (<= c -4.2e-42) (/ (+ a (/ b (/ c d))) c) (if (<= c 1.65e-13) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.2e-42) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 1.65e-13) {
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 <= (-4.2d-42)) then
tmp = (a + (b / (c / d))) / c
else if (c <= 1.65d-13) 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 <= -4.2e-42) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 1.65e-13) {
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 <= -4.2e-42: tmp = (a + (b / (c / d))) / c elif c <= 1.65e-13: 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 <= -4.2e-42) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (c <= 1.65e-13) 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 <= -4.2e-42) tmp = (a + (b / (c / d))) / c; elseif (c <= 1.65e-13) 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, -4.2e-42], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.65e-13], 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 -4.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;c \leq 1.65 \cdot 10^{-13}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -4.20000000000000013e-42Initial program 54.8%
Taylor expanded in c around inf 73.8%
*-commutative73.8%
associate-/l*75.5%
Applied egg-rr75.5%
associate-*r/73.8%
associate-*l/75.5%
*-commutative75.5%
clear-num75.5%
un-div-inv75.5%
Applied egg-rr75.5%
if -4.20000000000000013e-42 < c < 1.65e-13Initial program 76.1%
Taylor expanded in d around inf 86.0%
associate-/l*84.7%
Simplified84.7%
if 1.65e-13 < c Initial program 50.6%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
associate-/l*81.3%
Applied egg-rr81.3%
Final simplification81.4%
(FPCore (a b c d) :precision binary64 (if (<= c -4.8e-43) (/ (+ a (/ b (/ c d))) c) (if (<= c 8.4e-13) (/ (+ b (/ a (/ d c))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.8e-43) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 8.4e-13) {
tmp = (b + (a / (d / c))) / 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 <= (-4.8d-43)) then
tmp = (a + (b / (c / d))) / c
else if (c <= 8.4d-13) then
tmp = (b + (a / (d / c))) / 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 <= -4.8e-43) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 8.4e-13) {
tmp = (b + (a / (d / c))) / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.8e-43: tmp = (a + (b / (c / d))) / c elif c <= 8.4e-13: tmp = (b + (a / (d / c))) / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.8e-43) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (c <= 8.4e-13) tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / 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 <= -4.8e-43) tmp = (a + (b / (c / d))) / c; elseif (c <= 8.4e-13) tmp = (b + (a / (d / c))) / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.8e-43], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 8.4e-13], N[(N[(b + N[(a / N[(d / c), $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 -4.8 \cdot 10^{-43}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;c \leq 8.4 \cdot 10^{-13}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -4.8000000000000004e-43Initial program 54.8%
Taylor expanded in c around inf 73.8%
*-commutative73.8%
associate-/l*75.5%
Applied egg-rr75.5%
associate-*r/73.8%
associate-*l/75.5%
*-commutative75.5%
clear-num75.5%
un-div-inv75.5%
Applied egg-rr75.5%
if -4.8000000000000004e-43 < c < 8.39999999999999955e-13Initial program 76.1%
Taylor expanded in d around inf 86.0%
associate-/l*84.7%
Simplified84.7%
clear-num84.7%
un-div-inv84.7%
Applied egg-rr84.7%
if 8.39999999999999955e-13 < c Initial program 50.6%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
associate-/l*81.3%
Applied egg-rr81.3%
Final simplification81.4%
(FPCore (a b c d) :precision binary64 (if (<= c -5.8e-42) (/ (+ a (/ b (/ c d))) c) (if (<= c 2.2e-17) (/ (+ b (/ (* a c) d)) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.8e-42) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 2.2e-17) {
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 <= (-5.8d-42)) then
tmp = (a + (b / (c / d))) / c
else if (c <= 2.2d-17) 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 <= -5.8e-42) {
tmp = (a + (b / (c / d))) / c;
} else if (c <= 2.2e-17) {
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 <= -5.8e-42: tmp = (a + (b / (c / d))) / c elif c <= 2.2e-17: 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 <= -5.8e-42) tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); elseif (c <= 2.2e-17) tmp = Float64(Float64(b + Float64(Float64(a * 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 <= -5.8e-42) tmp = (a + (b / (c / d))) / c; elseif (c <= 2.2e-17) 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, -5.8e-42], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.2e-17], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $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 -5.8 \cdot 10^{-42}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{-17}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -5.8000000000000006e-42Initial program 54.8%
Taylor expanded in c around inf 73.8%
*-commutative73.8%
associate-/l*75.5%
Applied egg-rr75.5%
associate-*r/73.8%
associate-*l/75.5%
*-commutative75.5%
clear-num75.5%
un-div-inv75.5%
Applied egg-rr75.5%
if -5.8000000000000006e-42 < c < 2.2e-17Initial program 76.1%
Taylor expanded in d around inf 86.0%
if 2.2e-17 < c Initial program 50.6%
Taylor expanded in c around inf 75.0%
*-commutative75.0%
associate-/l*81.3%
Applied egg-rr81.3%
Final simplification82.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.3e-42) (not (<= c 2e-18))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.3e-42) || !(c <= 2e-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 <= (-2.3d-42)) .or. (.not. (c <= 2d-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 <= -2.3e-42) || !(c <= 2e-18)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.3e-42) or not (c <= 2e-18): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.3e-42) || !(c <= 2e-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 <= -2.3e-42) || ~((c <= 2e-18))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.3e-42], N[Not[LessEqual[c, 2e-18]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.3 \cdot 10^{-42} \lor \neg \left(c \leq 2 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.30000000000000004e-42 or 2.0000000000000001e-18 < c Initial program 52.5%
Taylor expanded in c around inf 65.8%
if -2.30000000000000004e-42 < c < 2.0000000000000001e-18Initial program 76.1%
Taylor expanded in c around 0 67.1%
Final simplification66.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 63.2%
Taylor expanded in c around inf 42.6%
Final simplification42.6%
(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 2024071
(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))))