
(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 (<= c -7.5e-20)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= c 3.8e-126)
(+ (/ b d) (/ a (* d (/ d c))))
(if (<= c 2.85e+20)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(+ (/ a c) (/ (/ b c) (/ c d)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e-20) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 3.8e-126) {
tmp = (b / d) + (a / (d * (d / c)));
} else if (c <= 2.85e+20) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (a / c) + ((b / c) / (c / d));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-7.5d-20)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (c <= 3.8d-126) then
tmp = (b / d) + (a / (d * (d / c)))
else if (c <= 2.85d+20) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else
tmp = (a / c) + ((b / c) / (c / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e-20) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 3.8e-126) {
tmp = (b / d) + (a / (d * (d / c)));
} else if (c <= 2.85e+20) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (a / c) + ((b / c) / (c / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -7.5e-20: tmp = (a / c) + ((d * (b / c)) / c) elif c <= 3.8e-126: tmp = (b / d) + (a / (d * (d / c))) elif c <= 2.85e+20: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (a / c) + ((b / c) / (c / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e-20) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= 3.8e-126) tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c)))); elseif (c <= 2.85e+20) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(a / c) + Float64(Float64(b / c) / Float64(c / d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -7.5e-20) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= 3.8e-126) tmp = (b / d) + (a / (d * (d / c))); elseif (c <= 2.85e+20) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (a / c) + ((b / c) / (c / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e-20], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.8e-126], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.85e+20], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{-20}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 3.8 \cdot 10^{-126}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\
\mathbf{elif}\;c \leq 2.85 \cdot 10^{+20}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\end{array}
\end{array}
if c < -7.49999999999999981e-20Initial program 52.3%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
unpow274.6%
times-frac79.4%
Simplified79.4%
associate-*l/80.8%
Applied egg-rr80.8%
if -7.49999999999999981e-20 < c < 3.7999999999999999e-126Initial program 68.8%
Taylor expanded in c around 0 86.4%
associate-/l*86.5%
unpow286.5%
Simplified86.5%
Taylor expanded in d around 0 86.5%
unpow286.5%
associate-*r/88.3%
Simplified88.3%
if 3.7999999999999999e-126 < c < 2.85e20Initial program 86.1%
if 2.85e20 < c Initial program 44.7%
Taylor expanded in c around inf 81.2%
*-commutative81.2%
unpow281.2%
times-frac86.4%
Simplified86.4%
*-commutative86.4%
clear-num86.4%
un-div-inv86.4%
Applied egg-rr86.4%
Final simplification85.8%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+286) (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d)) (+ (* (/ c d) (/ a d)) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+286) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = ((c / d) * (a / d)) + (b / d);
}
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))) <= 5e+286) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(Float64(c / d) * Float64(a / d)) + Float64(b / d)); 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], 5e+286], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+286}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d} + \frac{b}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.0000000000000004e286Initial program 77.9%
*-un-lft-identity77.9%
add-sqr-sqrt77.9%
times-frac77.8%
hypot-def77.8%
fma-def77.8%
hypot-def93.3%
Applied egg-rr93.3%
associate-*l/93.6%
*-un-lft-identity93.6%
Applied egg-rr93.6%
if 5.0000000000000004e286 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 5.8%
Taylor expanded in c around 0 47.6%
+-commutative47.6%
*-commutative47.6%
unpow247.6%
times-frac55.2%
fma-def55.2%
Simplified55.2%
fma-udef55.2%
Applied egg-rr55.2%
Final simplification84.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.9e-21) (not (<= c 1.75e+47))) (+ (/ a c) (* (/ b c) (/ d c))) (+ (* (/ c d) (/ a d)) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.9e-21) || !(c <= 1.75e+47)) {
tmp = (a / c) + ((b / c) * (d / c));
} else {
tmp = ((c / d) * (a / d)) + (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.9d-21)) .or. (.not. (c <= 1.75d+47))) then
tmp = (a / c) + ((b / c) * (d / c))
else
tmp = ((c / d) * (a / d)) + (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.9e-21) || !(c <= 1.75e+47)) {
tmp = (a / c) + ((b / c) * (d / c));
} else {
tmp = ((c / d) * (a / d)) + (b / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.9e-21) or not (c <= 1.75e+47): tmp = (a / c) + ((b / c) * (d / c)) else: tmp = ((c / d) * (a / d)) + (b / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.9e-21) || !(c <= 1.75e+47)) tmp = Float64(Float64(a / c) + Float64(Float64(b / c) * Float64(d / c))); else tmp = Float64(Float64(Float64(c / d) * Float64(a / d)) + Float64(b / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.9e-21) || ~((c <= 1.75e+47))) tmp = (a / c) + ((b / c) * (d / c)); else tmp = ((c / d) * (a / d)) + (b / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.9e-21], N[Not[LessEqual[c, 1.75e+47]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{-21} \lor \neg \left(c \leq 1.75 \cdot 10^{+47}\right):\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d} + \frac{b}{d}\\
\end{array}
\end{array}
if c < -1.8999999999999999e-21 or 1.75000000000000008e47 < c Initial program 48.6%
Taylor expanded in c around inf 78.7%
*-commutative78.7%
unpow278.7%
times-frac83.8%
Simplified83.8%
if -1.8999999999999999e-21 < c < 1.75000000000000008e47Initial program 72.0%
Taylor expanded in c around 0 79.8%
+-commutative79.8%
*-commutative79.8%
unpow279.8%
times-frac81.7%
fma-def81.7%
Simplified81.7%
fma-udef81.7%
Applied egg-rr81.7%
Final simplification82.6%
(FPCore (a b c d) :precision binary64 (if (<= c -4.8e-16) (/ a c) (if (<= c 4.5e+48) (+ (* (/ c d) (/ a d)) (/ b d)) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.8e-16) {
tmp = a / c;
} else if (c <= 4.5e+48) {
tmp = ((c / d) * (a / d)) + (b / d);
} else {
tmp = a / 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-16)) then
tmp = a / c
else if (c <= 4.5d+48) then
tmp = ((c / d) * (a / d)) + (b / d)
else
tmp = a / 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-16) {
tmp = a / c;
} else if (c <= 4.5e+48) {
tmp = ((c / d) * (a / d)) + (b / d);
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.8e-16: tmp = a / c elif c <= 4.5e+48: tmp = ((c / d) * (a / d)) + (b / d) else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.8e-16) tmp = Float64(a / c); elseif (c <= 4.5e+48) tmp = Float64(Float64(Float64(c / d) * Float64(a / d)) + Float64(b / d)); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -4.8e-16) tmp = a / c; elseif (c <= 4.5e+48) tmp = ((c / d) * (a / d)) + (b / d); else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.8e-16], N[(a / c), $MachinePrecision], If[LessEqual[c, 4.5e+48], N[(N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.8 \cdot 10^{-16}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{+48}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d} + \frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.8000000000000001e-16 or 4.49999999999999995e48 < c Initial program 48.1%
Taylor expanded in c around inf 71.1%
if -4.8000000000000001e-16 < c < 4.49999999999999995e48Initial program 72.2%
Taylor expanded in c around 0 79.3%
+-commutative79.3%
*-commutative79.3%
unpow279.3%
times-frac81.2%
fma-def81.2%
Simplified81.2%
fma-udef81.2%
Applied egg-rr81.2%
Final simplification76.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.5e-19)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= c 2.6e+48)
(+ (* (/ c d) (/ a d)) (/ b d))
(+ (/ a c) (* (/ b c) (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.5e-19) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 2.6e+48) {
tmp = ((c / d) * (a / d)) + (b / d);
} else {
tmp = (a / c) + ((b / c) * (d / c));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-5.5d-19)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (c <= 2.6d+48) then
tmp = ((c / d) * (a / d)) + (b / d)
else
tmp = (a / c) + ((b / c) * (d / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.5e-19) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 2.6e+48) {
tmp = ((c / d) * (a / d)) + (b / d);
} else {
tmp = (a / c) + ((b / c) * (d / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.5e-19: tmp = (a / c) + ((d * (b / c)) / c) elif c <= 2.6e+48: tmp = ((c / d) * (a / d)) + (b / d) else: tmp = (a / c) + ((b / c) * (d / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.5e-19) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= 2.6e+48) tmp = Float64(Float64(Float64(c / d) * Float64(a / d)) + Float64(b / d)); else tmp = Float64(Float64(a / c) + Float64(Float64(b / c) * Float64(d / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -5.5e-19) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= 2.6e+48) tmp = ((c / d) * (a / d)) + (b / d); else tmp = (a / c) + ((b / c) * (d / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.5e-19], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.6e+48], N[(N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{-19}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{+48}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d} + \frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\end{array}
\end{array}
if c < -5.4999999999999996e-19Initial program 52.3%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
unpow274.6%
times-frac79.4%
Simplified79.4%
associate-*l/80.8%
Applied egg-rr80.8%
if -5.4999999999999996e-19 < c < 2.59999999999999995e48Initial program 72.0%
Taylor expanded in c around 0 79.8%
+-commutative79.8%
*-commutative79.8%
unpow279.8%
times-frac81.7%
fma-def81.7%
Simplified81.7%
fma-udef81.7%
Applied egg-rr81.7%
if 2.59999999999999995e48 < c Initial program 44.2%
Taylor expanded in c around inf 83.4%
*-commutative83.4%
unpow283.4%
times-frac89.1%
Simplified89.1%
Final simplification83.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.65e-18)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= c 8.6e+51)
(+ (* (/ c d) (/ a d)) (/ b d))
(+ (/ a c) (/ (/ b c) (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.65e-18) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 8.6e+51) {
tmp = ((c / d) * (a / d)) + (b / d);
} else {
tmp = (a / c) + ((b / c) / (c / d));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-1.65d-18)) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (c <= 8.6d+51) then
tmp = ((c / d) * (a / d)) + (b / d)
else
tmp = (a / c) + ((b / c) / (c / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.65e-18) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (c <= 8.6e+51) {
tmp = ((c / d) * (a / d)) + (b / d);
} else {
tmp = (a / c) + ((b / c) / (c / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.65e-18: tmp = (a / c) + ((d * (b / c)) / c) elif c <= 8.6e+51: tmp = ((c / d) * (a / d)) + (b / d) else: tmp = (a / c) + ((b / c) / (c / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.65e-18) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (c <= 8.6e+51) tmp = Float64(Float64(Float64(c / d) * Float64(a / d)) + Float64(b / d)); else tmp = Float64(Float64(a / c) + Float64(Float64(b / c) / Float64(c / d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.65e-18) tmp = (a / c) + ((d * (b / c)) / c); elseif (c <= 8.6e+51) tmp = ((c / d) * (a / d)) + (b / d); else tmp = (a / c) + ((b / c) / (c / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.65e-18], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.6e+51], N[(N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.65 \cdot 10^{-18}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 8.6 \cdot 10^{+51}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d} + \frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\end{array}
\end{array}
if c < -1.6500000000000001e-18Initial program 52.3%
Taylor expanded in c around inf 74.6%
*-commutative74.6%
unpow274.6%
times-frac79.4%
Simplified79.4%
associate-*l/80.8%
Applied egg-rr80.8%
if -1.6500000000000001e-18 < c < 8.5999999999999994e51Initial program 72.0%
Taylor expanded in c around 0 79.8%
+-commutative79.8%
*-commutative79.8%
unpow279.8%
times-frac81.7%
fma-def81.7%
Simplified81.7%
fma-udef81.7%
Applied egg-rr81.7%
if 8.5999999999999994e51 < c Initial program 44.2%
Taylor expanded in c around inf 83.4%
*-commutative83.4%
unpow283.4%
times-frac89.1%
Simplified89.1%
*-commutative89.1%
clear-num89.1%
un-div-inv89.1%
Applied egg-rr89.1%
Final simplification83.0%
(FPCore (a b c d) :precision binary64 (if (<= c -1.45e-16) (/ a c) (if (<= c 0.00024) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.45e-16) {
tmp = a / c;
} else if (c <= 0.00024) {
tmp = b / d;
} else {
tmp = a / 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 <= (-1.45d-16)) then
tmp = a / c
else if (c <= 0.00024d0) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.45e-16) {
tmp = a / c;
} else if (c <= 0.00024) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.45e-16: tmp = a / c elif c <= 0.00024: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.45e-16) tmp = Float64(a / c); elseif (c <= 0.00024) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.45e-16) tmp = a / c; elseif (c <= 0.00024) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.45e-16], N[(a / c), $MachinePrecision], If[LessEqual[c, 0.00024], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{-16}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 0.00024:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.4499999999999999e-16 or 2.40000000000000006e-4 < c Initial program 49.3%
Taylor expanded in c around inf 69.8%
if -1.4499999999999999e-16 < c < 2.40000000000000006e-4Initial program 72.5%
Taylor expanded in c around 0 74.4%
Final simplification72.2%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 61.6%
Taylor expanded in c around inf 41.1%
Final simplification41.1%
(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 2023271
(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))))