
(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 9 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))) INFINITY) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (+ (/ b d) (/ (/ a (/ d c)) d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b / d) + ((a / (d / c)) / 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))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b / d) + Float64(Float64(a / Float64(d / c)) / 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], Infinity], 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[(b / d), $MachinePrecision] + N[(N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision] / 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 \infty:\\
\;\;\;\;\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{b}{d} + \frac{\frac{a}{\frac{d}{c}}}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 74.1%
*-un-lft-identity74.1%
add-sqr-sqrt74.1%
times-frac74.1%
hypot-def74.1%
fma-def74.1%
hypot-def95.1%
Applied egg-rr95.1%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in c around 0 43.2%
unpow243.2%
times-frac54.4%
Simplified54.4%
associate-*r/54.4%
Applied egg-rr54.4%
*-commutative54.4%
clear-num54.4%
un-div-inv54.4%
Applied egg-rr54.4%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -0.86)
(/ b d)
(if (<= d 3.8e-29)
(+ (/ a c) (/ (* d (/ b c)) c))
(if (<= d 6.4e+62)
(/ b d)
(if (<= d 3.5e+127) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.86) {
tmp = b / d;
} else if (d <= 3.8e-29) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (d <= 6.4e+62) {
tmp = b / d;
} else if (d <= 3.5e+127) {
tmp = (a / c) + ((d / c) * (b / 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 (d <= (-0.86d0)) then
tmp = b / d
else if (d <= 3.8d-29) then
tmp = (a / c) + ((d * (b / c)) / c)
else if (d <= 6.4d+62) then
tmp = b / d
else if (d <= 3.5d+127) then
tmp = (a / c) + ((d / c) * (b / 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 (d <= -0.86) {
tmp = b / d;
} else if (d <= 3.8e-29) {
tmp = (a / c) + ((d * (b / c)) / c);
} else if (d <= 6.4e+62) {
tmp = b / d;
} else if (d <= 3.5e+127) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -0.86: tmp = b / d elif d <= 3.8e-29: tmp = (a / c) + ((d * (b / c)) / c) elif d <= 6.4e+62: tmp = b / d elif d <= 3.5e+127: tmp = (a / c) + ((d / c) * (b / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -0.86) tmp = Float64(b / d); elseif (d <= 3.8e-29) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); elseif (d <= 6.4e+62) tmp = Float64(b / d); elseif (d <= 3.5e+127) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -0.86) tmp = b / d; elseif (d <= 3.8e-29) tmp = (a / c) + ((d * (b / c)) / c); elseif (d <= 6.4e+62) tmp = b / d; elseif (d <= 3.5e+127) tmp = (a / c) + ((d / c) * (b / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.86], N[(b / d), $MachinePrecision], If[LessEqual[d, 3.8e-29], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.4e+62], N[(b / d), $MachinePrecision], If[LessEqual[d, 3.5e+127], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.86:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 3.8 \cdot 10^{-29}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;d \leq 6.4 \cdot 10^{+62}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{+127}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -0.859999999999999987 or 3.79999999999999976e-29 < d < 6.39999999999999968e62 or 3.49999999999999978e127 < d Initial program 51.4%
Taylor expanded in c around 0 70.6%
if -0.859999999999999987 < d < 3.79999999999999976e-29Initial program 70.3%
Taylor expanded in c around inf 74.5%
unpow274.5%
times-frac77.2%
Simplified77.2%
associate-*l/78.9%
Applied egg-rr78.9%
if 6.39999999999999968e62 < d < 3.49999999999999978e127Initial program 61.6%
Taylor expanded in c around inf 67.8%
unpow267.8%
times-frac74.2%
Simplified74.2%
Final simplification74.7%
(FPCore (a b c d)
:precision binary64
(if (<= c -7.8e+107)
(+ (/ a c) (* (/ d c) (/ b c)))
(if (<= c -2.35e-142)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 6.8e-33)
(+ (/ b d) (/ (* a (/ c d)) d))
(+ (/ a c) (/ (* d (/ b c)) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.8e+107) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= -2.35e-142) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 6.8e-33) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (a / c) + ((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.8d+107)) then
tmp = (a / c) + ((d / c) * (b / c))
else if (c <= (-2.35d-142)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (c <= 6.8d-33) then
tmp = (b / d) + ((a * (c / d)) / d)
else
tmp = (a / c) + ((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.8e+107) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= -2.35e-142) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 6.8e-33) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -7.8e+107: tmp = (a / c) + ((d / c) * (b / c)) elif c <= -2.35e-142: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 6.8e-33: tmp = (b / d) + ((a * (c / d)) / d) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -7.8e+107) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); elseif (c <= -2.35e-142) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 6.8e-33) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -7.8e+107) tmp = (a / c) + ((d / c) * (b / c)); elseif (c <= -2.35e-142) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 6.8e-33) tmp = (b / d) + ((a * (c / d)) / d); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.8e+107], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.35e-142], 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, 6.8e-33], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.8 \cdot 10^{+107}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{elif}\;c \leq -2.35 \cdot 10^{-142}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -7.7999999999999997e107Initial program 35.8%
Taylor expanded in c around inf 78.9%
unpow278.9%
times-frac89.1%
Simplified89.1%
if -7.7999999999999997e107 < c < -2.34999999999999995e-142Initial program 77.9%
if -2.34999999999999995e-142 < c < 6.8000000000000001e-33Initial program 69.1%
Taylor expanded in c around 0 80.1%
unpow280.1%
times-frac85.4%
Simplified85.4%
associate-*r/89.4%
Applied egg-rr89.4%
if 6.8000000000000001e-33 < c Initial program 53.8%
Taylor expanded in c around inf 76.4%
unpow276.4%
times-frac75.5%
Simplified75.5%
associate-*l/78.2%
Applied egg-rr78.2%
Final simplification84.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.86) (not (<= d 1.6e+127))) (/ b d) (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.86) || !(d <= 1.6e+127)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / 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 <= (-0.86d0)) .or. (.not. (d <= 1.6d+127))) then
tmp = b / d
else
tmp = (a / c) + ((d / c) * (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.86) || !(d <= 1.6e+127)) {
tmp = b / d;
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.86) or not (d <= 1.6e+127): tmp = b / d else: tmp = (a / c) + ((d / c) * (b / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.86) || !(d <= 1.6e+127)) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.86) || ~((d <= 1.6e+127))) tmp = b / d; else tmp = (a / c) + ((d / c) * (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.86], N[Not[LessEqual[d, 1.6e+127]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.86 \lor \neg \left(d \leq 1.6 \cdot 10^{+127}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\end{array}
\end{array}
if d < -0.859999999999999987 or 1.59999999999999988e127 < d Initial program 44.4%
Taylor expanded in c around 0 74.8%
if -0.859999999999999987 < d < 1.59999999999999988e127Initial program 71.5%
Taylor expanded in c around inf 67.4%
unpow267.4%
times-frac70.7%
Simplified70.7%
Final simplification72.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -9.6e+75)
(+ (/ a c) (* (/ d c) (/ b c)))
(if (<= c 7e-37)
(+ (/ b d) (* (/ c d) (/ a d)))
(+ (/ a c) (/ (* d (/ b c)) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9.6e+75) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 7e-37) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((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 <= (-9.6d+75)) then
tmp = (a / c) + ((d / c) * (b / c))
else if (c <= 7d-37) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (a / c) + ((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 <= -9.6e+75) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 7e-37) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -9.6e+75: tmp = (a / c) + ((d / c) * (b / c)) elif c <= 7e-37: tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -9.6e+75) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); elseif (c <= 7e-37) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -9.6e+75) tmp = (a / c) + ((d / c) * (b / c)); elseif (c <= 7e-37) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -9.6e+75], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7e-37], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.6 \cdot 10^{+75}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{elif}\;c \leq 7 \cdot 10^{-37}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -9.5999999999999999e75Initial program 39.2%
Taylor expanded in c around inf 76.7%
unpow276.7%
times-frac86.0%
Simplified86.0%
if -9.5999999999999999e75 < c < 7.0000000000000003e-37Initial program 72.1%
Taylor expanded in c around 0 72.7%
unpow272.7%
times-frac77.0%
Simplified77.0%
if 7.0000000000000003e-37 < c Initial program 53.8%
Taylor expanded in c around inf 76.4%
unpow276.4%
times-frac75.5%
Simplified75.5%
associate-*l/78.2%
Applied egg-rr78.2%
Final simplification79.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -8.5e+75)
(+ (/ a c) (* (/ d c) (/ b c)))
(if (<= c 1.95e-38)
(+ (/ b d) (/ a (* d (/ d c))))
(+ (/ a c) (/ (* d (/ b c)) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.5e+75) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 1.95e-38) {
tmp = (b / d) + (a / (d * (d / c)));
} else {
tmp = (a / c) + ((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 <= (-8.5d+75)) then
tmp = (a / c) + ((d / c) * (b / c))
else if (c <= 1.95d-38) then
tmp = (b / d) + (a / (d * (d / c)))
else
tmp = (a / c) + ((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 <= -8.5e+75) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 1.95e-38) {
tmp = (b / d) + (a / (d * (d / c)));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -8.5e+75: tmp = (a / c) + ((d / c) * (b / c)) elif c <= 1.95e-38: tmp = (b / d) + (a / (d * (d / c))) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -8.5e+75) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); elseif (c <= 1.95e-38) tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c)))); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -8.5e+75) tmp = (a / c) + ((d / c) * (b / c)); elseif (c <= 1.95e-38) tmp = (b / d) + (a / (d * (d / c))); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -8.5e+75], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.95e-38], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.5 \cdot 10^{+75}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{elif}\;c \leq 1.95 \cdot 10^{-38}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -8.4999999999999993e75Initial program 39.2%
Taylor expanded in c around inf 76.7%
unpow276.7%
times-frac86.0%
Simplified86.0%
if -8.4999999999999993e75 < c < 1.95e-38Initial program 72.1%
Taylor expanded in c around 0 72.7%
unpow272.7%
times-frac77.0%
Simplified77.0%
clear-num77.0%
frac-times78.9%
*-un-lft-identity78.9%
Applied egg-rr78.9%
if 1.95e-38 < c Initial program 53.8%
Taylor expanded in c around inf 76.4%
unpow276.4%
times-frac75.5%
Simplified75.5%
associate-*l/78.2%
Applied egg-rr78.2%
Final simplification80.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.35e+79)
(+ (/ a c) (* (/ d c) (/ b c)))
(if (<= c 7e-35)
(+ (/ b d) (/ (* a (/ c d)) d))
(+ (/ a c) (/ (* d (/ b c)) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.35e+79) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 7e-35) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (a / c) + ((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 <= (-1.35d+79)) then
tmp = (a / c) + ((d / c) * (b / c))
else if (c <= 7d-35) then
tmp = (b / d) + ((a * (c / d)) / d)
else
tmp = (a / c) + ((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 <= -1.35e+79) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 7e-35) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.35e+79: tmp = (a / c) + ((d / c) * (b / c)) elif c <= 7e-35: tmp = (b / d) + ((a * (c / d)) / d) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.35e+79) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); elseif (c <= 7e-35) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.35e+79) tmp = (a / c) + ((d / c) * (b / c)); elseif (c <= 7e-35) tmp = (b / d) + ((a * (c / d)) / d); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.35e+79], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7e-35], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.35 \cdot 10^{+79}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{elif}\;c \leq 7 \cdot 10^{-35}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -1.35e79Initial program 39.2%
Taylor expanded in c around inf 76.7%
unpow276.7%
times-frac86.0%
Simplified86.0%
if -1.35e79 < c < 6.99999999999999992e-35Initial program 72.1%
Taylor expanded in c around 0 72.7%
unpow272.7%
times-frac77.0%
Simplified77.0%
associate-*r/79.8%
Applied egg-rr79.8%
if 6.99999999999999992e-35 < c Initial program 53.8%
Taylor expanded in c around inf 76.4%
unpow276.4%
times-frac75.5%
Simplified75.5%
associate-*l/78.2%
Applied egg-rr78.2%
Final simplification80.5%
(FPCore (a b c d) :precision binary64 (if (<= c -9e+75) (/ a c) (if (<= c 3.4e-34) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+75) {
tmp = a / c;
} else if (c <= 3.4e-34) {
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 <= (-9d+75)) then
tmp = a / c
else if (c <= 3.4d-34) 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 <= -9e+75) {
tmp = a / c;
} else if (c <= 3.4e-34) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -9e+75: tmp = a / c elif c <= 3.4e-34: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -9e+75) tmp = Float64(a / c); elseif (c <= 3.4e-34) 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 <= -9e+75) tmp = a / c; elseif (c <= 3.4e-34) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+75], N[(a / c), $MachinePrecision], If[LessEqual[c, 3.4e-34], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+75}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 3.4 \cdot 10^{-34}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -9.0000000000000007e75 or 3.4000000000000001e-34 < c Initial program 48.0%
Taylor expanded in c around inf 69.4%
if -9.0000000000000007e75 < c < 3.4000000000000001e-34Initial program 72.1%
Taylor expanded in c around 0 64.3%
Final simplification66.7%
(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 60.8%
Taylor expanded in c around inf 41.6%
Final simplification41.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 2023171
(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))))