
(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))) INFINITY) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (+ (/ b d) (/ (/ c d) (/ d a)))))
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) + ((c / d) / (d / a));
}
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(c / d) / Float64(d / a))); 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[(c / d), $MachinePrecision] / N[(d / a), $MachinePrecision]), $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{c}{d}}{\frac{d}{a}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 78.7%
*-un-lft-identity78.7%
add-sqr-sqrt78.7%
times-frac78.6%
hypot-def78.6%
fma-def78.6%
hypot-def95.8%
Applied egg-rr95.8%
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 49.7%
unpow249.7%
times-frac57.8%
Simplified57.8%
clear-num57.9%
un-div-inv57.9%
Applied egg-rr57.9%
Final simplification89.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -5.5e+84)
(+ (/ a c) (* (/ d c) (/ b c)))
(if (<= c -3.25e-201)
t_0
(if (<= c 2.3e-25)
(+ (/ b d) (/ (* a (/ c d)) d))
(if (<= c 1.02e+95) t_0 (+ (/ a c) (/ (/ b c) (/ c d)))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -5.5e+84) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= -3.25e-201) {
tmp = t_0;
} else if (c <= 2.3e-25) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 1.02e+95) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-5.5d+84)) then
tmp = (a / c) + ((d / c) * (b / c))
else if (c <= (-3.25d-201)) then
tmp = t_0
else if (c <= 2.3d-25) then
tmp = (b / d) + ((a * (c / d)) / d)
else if (c <= 1.02d+95) then
tmp = t_0
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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -5.5e+84) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= -3.25e-201) {
tmp = t_0;
} else if (c <= 2.3e-25) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 1.02e+95) {
tmp = t_0;
} else {
tmp = (a / c) + ((b / c) / (c / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -5.5e+84: tmp = (a / c) + ((d / c) * (b / c)) elif c <= -3.25e-201: tmp = t_0 elif c <= 2.3e-25: tmp = (b / d) + ((a * (c / d)) / d) elif c <= 1.02e+95: tmp = t_0 else: tmp = (a / c) + ((b / c) / (c / d)) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -5.5e+84) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); elseif (c <= -3.25e-201) tmp = t_0; elseif (c <= 2.3e-25) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); elseif (c <= 1.02e+95) tmp = t_0; 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) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -5.5e+84) tmp = (a / c) + ((d / c) * (b / c)); elseif (c <= -3.25e-201) tmp = t_0; elseif (c <= 2.3e-25) tmp = (b / d) + ((a * (c / d)) / d); elseif (c <= 1.02e+95) tmp = t_0; else tmp = (a / c) + ((b / c) / (c / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = 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, -5.5e+84], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -3.25e-201], t$95$0, If[LessEqual[c, 2.3e-25], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.02e+95], t$95$0, N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -5.5 \cdot 10^{+84}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{elif}\;c \leq -3.25 \cdot 10^{-201}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{-25}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.02 \cdot 10^{+95}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\end{array}
\end{array}
if c < -5.5000000000000004e84Initial program 45.4%
Taylor expanded in c around inf 90.0%
unpow290.0%
times-frac97.6%
Simplified97.6%
if -5.5000000000000004e84 < c < -3.24999999999999987e-201 or 2.2999999999999999e-25 < c < 1.0200000000000001e95Initial program 80.8%
if -3.24999999999999987e-201 < c < 2.2999999999999999e-25Initial program 70.0%
Taylor expanded in c around 0 85.5%
unpow285.5%
times-frac92.0%
Simplified92.0%
associate-*r/93.1%
Applied egg-rr93.1%
if 1.0200000000000001e95 < c Initial program 36.3%
Taylor expanded in c around inf 64.4%
unpow264.4%
times-frac78.2%
Simplified78.2%
*-commutative78.2%
clear-num78.3%
un-div-inv78.4%
Applied egg-rr78.4%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (/ (/ b c) (/ c d)))))
(if (<= c -0.35)
t_0
(if (<= c 1.2e-24)
(+ (/ b d) (* (/ c d) (/ a d)))
(if (<= c 3.4e+24)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= c 4e+53) (/ b d) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((b / c) / (c / d));
double tmp;
if (c <= -0.35) {
tmp = t_0;
} else if (c <= 1.2e-24) {
tmp = (b / d) + ((c / d) * (a / d));
} else if (c <= 3.4e+24) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (c <= 4e+53) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (a / c) + ((b / c) / (c / d))
if (c <= (-0.35d0)) then
tmp = t_0
else if (c <= 1.2d-24) then
tmp = (b / d) + ((c / d) * (a / d))
else if (c <= 3.4d+24) then
tmp = (a / c) + (b / (c * (c / d)))
else if (c <= 4d+53) then
tmp = b / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((b / c) / (c / d));
double tmp;
if (c <= -0.35) {
tmp = t_0;
} else if (c <= 1.2e-24) {
tmp = (b / d) + ((c / d) * (a / d));
} else if (c <= 3.4e+24) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (c <= 4e+53) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a / c) + ((b / c) / (c / d)) tmp = 0 if c <= -0.35: tmp = t_0 elif c <= 1.2e-24: tmp = (b / d) + ((c / d) * (a / d)) elif c <= 3.4e+24: tmp = (a / c) + (b / (c * (c / d))) elif c <= 4e+53: tmp = b / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(Float64(b / c) / Float64(c / d))) tmp = 0.0 if (c <= -0.35) tmp = t_0; elseif (c <= 1.2e-24) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); elseif (c <= 3.4e+24) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (c <= 4e+53) tmp = Float64(b / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a / c) + ((b / c) / (c / d)); tmp = 0.0; if (c <= -0.35) tmp = t_0; elseif (c <= 1.2e-24) tmp = (b / d) + ((c / d) * (a / d)); elseif (c <= 3.4e+24) tmp = (a / c) + (b / (c * (c / d))); elseif (c <= 4e+53) tmp = b / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -0.35], t$95$0, If[LessEqual[c, 1.2e-24], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.4e+24], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e+53], N[(b / d), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -0.35:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{-24}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{elif}\;c \leq 3.4 \cdot 10^{+24}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{+53}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -0.34999999999999998 or 4e53 < c Initial program 51.2%
Taylor expanded in c around inf 74.4%
unpow274.4%
times-frac81.9%
Simplified81.9%
*-commutative81.9%
clear-num81.9%
un-div-inv82.0%
Applied egg-rr82.0%
if -0.34999999999999998 < c < 1.1999999999999999e-24Initial program 73.4%
Taylor expanded in c around 0 81.9%
unpow281.9%
times-frac85.9%
Simplified85.9%
if 1.1999999999999999e-24 < c < 3.4000000000000001e24Initial program 99.8%
Taylor expanded in c around inf 80.8%
unpow280.8%
times-frac80.6%
Simplified80.6%
clear-num80.6%
frac-times80.8%
*-un-lft-identity80.8%
Applied egg-rr80.8%
if 3.4000000000000001e24 < c < 4e53Initial program 77.6%
Taylor expanded in c around 0 78.7%
Final simplification83.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (/ (/ b c) (/ c d)))))
(if (<= c -6.6e-8)
t_0
(if (<= c 1.9e-23)
(+ (/ b d) (/ (* a (/ c d)) d))
(if (<= c 2.2e+24)
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= c 2.2e+52) (/ b d) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((b / c) / (c / d));
double tmp;
if (c <= -6.6e-8) {
tmp = t_0;
} else if (c <= 1.9e-23) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 2.2e+24) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (c <= 2.2e+52) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (a / c) + ((b / c) / (c / d))
if (c <= (-6.6d-8)) then
tmp = t_0
else if (c <= 1.9d-23) then
tmp = (b / d) + ((a * (c / d)) / d)
else if (c <= 2.2d+24) then
tmp = (a / c) + (b / (c * (c / d)))
else if (c <= 2.2d+52) then
tmp = b / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a / c) + ((b / c) / (c / d));
double tmp;
if (c <= -6.6e-8) {
tmp = t_0;
} else if (c <= 1.9e-23) {
tmp = (b / d) + ((a * (c / d)) / d);
} else if (c <= 2.2e+24) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (c <= 2.2e+52) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a / c) + ((b / c) / (c / d)) tmp = 0 if c <= -6.6e-8: tmp = t_0 elif c <= 1.9e-23: tmp = (b / d) + ((a * (c / d)) / d) elif c <= 2.2e+24: tmp = (a / c) + (b / (c * (c / d))) elif c <= 2.2e+52: tmp = b / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(Float64(b / c) / Float64(c / d))) tmp = 0.0 if (c <= -6.6e-8) tmp = t_0; elseif (c <= 1.9e-23) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); elseif (c <= 2.2e+24) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (c <= 2.2e+52) tmp = Float64(b / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a / c) + ((b / c) / (c / d)); tmp = 0.0; if (c <= -6.6e-8) tmp = t_0; elseif (c <= 1.9e-23) tmp = (b / d) + ((a * (c / d)) / d); elseif (c <= 2.2e+24) tmp = (a / c) + (b / (c * (c / d))); elseif (c <= 2.2e+52) tmp = b / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -6.6e-8], t$95$0, If[LessEqual[c, 1.9e-23], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.2e+24], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.2e+52], N[(b / d), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -6.6 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{-23}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+24}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+52}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -6.59999999999999954e-8 or 2.2e52 < c Initial program 52.1%
Taylor expanded in c around inf 74.0%
unpow274.0%
times-frac81.4%
Simplified81.4%
*-commutative81.4%
clear-num81.4%
un-div-inv81.5%
Applied egg-rr81.5%
if -6.59999999999999954e-8 < c < 1.90000000000000006e-23Initial program 73.4%
Taylor expanded in c around 0 81.9%
unpow281.9%
times-frac85.9%
Simplified85.9%
associate-*r/86.6%
Applied egg-rr86.6%
if 1.90000000000000006e-23 < c < 2.20000000000000002e24Initial program 99.8%
Taylor expanded in c around inf 80.8%
unpow280.8%
times-frac80.6%
Simplified80.6%
clear-num80.6%
frac-times80.8%
*-un-lft-identity80.8%
Applied egg-rr80.8%
if 2.20000000000000002e24 < c < 2.2e52Initial program 71.2%
Taylor expanded in c around 0 86.3%
Final simplification84.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.1e-35) (not (<= d 3.9e+118))) (/ b d) (+ (/ a c) (/ (/ b c) (/ c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.1e-35) || !(d <= 3.9e+118)) {
tmp = 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 ((d <= (-4.1d-35)) .or. (.not. (d <= 3.9d+118))) then
tmp = 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 ((d <= -4.1e-35) || !(d <= 3.9e+118)) {
tmp = b / d;
} else {
tmp = (a / c) + ((b / c) / (c / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.1e-35) or not (d <= 3.9e+118): tmp = b / d else: tmp = (a / c) + ((b / c) / (c / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.1e-35) || !(d <= 3.9e+118)) tmp = 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 ((d <= -4.1e-35) || ~((d <= 3.9e+118))) tmp = b / d; else tmp = (a / c) + ((b / c) / (c / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.1e-35], N[Not[LessEqual[d, 3.9e+118]], $MachinePrecision]], N[(b / d), $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}\;d \leq -4.1 \cdot 10^{-35} \lor \neg \left(d \leq 3.9 \cdot 10^{+118}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\end{array}
\end{array}
if d < -4.10000000000000026e-35 or 3.9e118 < d Initial program 54.5%
Taylor expanded in c around 0 74.9%
if -4.10000000000000026e-35 < d < 3.9e118Initial program 73.8%
Taylor expanded in c around inf 70.7%
unpow270.7%
times-frac76.8%
Simplified76.8%
*-commutative76.8%
clear-num76.8%
un-div-inv76.8%
Applied egg-rr76.8%
Final simplification75.9%
(FPCore (a b c d) :precision binary64 (if (<= d -5.2e-35) (/ b d) (if (<= d 6.6e+117) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.2e-35) {
tmp = b / d;
} else if (d <= 6.6e+117) {
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 <= (-5.2d-35)) then
tmp = b / d
else if (d <= 6.6d+117) 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 <= -5.2e-35) {
tmp = b / d;
} else if (d <= 6.6e+117) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -5.2e-35: tmp = b / d elif d <= 6.6e+117: tmp = (a / c) + ((d / c) * (b / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -5.2e-35) tmp = Float64(b / d); elseif (d <= 6.6e+117) 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 <= -5.2e-35) tmp = b / d; elseif (d <= 6.6e+117) tmp = (a / c) + ((d / c) * (b / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.2e-35], N[(b / d), $MachinePrecision], If[LessEqual[d, 6.6e+117], 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 -5.2 \cdot 10^{-35}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 6.6 \cdot 10^{+117}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -5.20000000000000009e-35 or 6.5999999999999996e117 < d Initial program 54.5%
Taylor expanded in c around 0 74.9%
if -5.20000000000000009e-35 < d < 6.5999999999999996e117Initial program 73.8%
Taylor expanded in c around inf 70.7%
unpow270.7%
times-frac76.8%
Simplified76.8%
Final simplification75.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -3.7e+80)
(/ a c)
(if (or (<= c 1.7e-23) (and (not (<= c 3.8e+24)) (<= c 2.65e+53)))
(/ b d)
(/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.7e+80) {
tmp = a / c;
} else if ((c <= 1.7e-23) || (!(c <= 3.8e+24) && (c <= 2.65e+53))) {
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 <= (-3.7d+80)) then
tmp = a / c
else if ((c <= 1.7d-23) .or. (.not. (c <= 3.8d+24)) .and. (c <= 2.65d+53)) 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 <= -3.7e+80) {
tmp = a / c;
} else if ((c <= 1.7e-23) || (!(c <= 3.8e+24) && (c <= 2.65e+53))) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.7e+80: tmp = a / c elif (c <= 1.7e-23) or (not (c <= 3.8e+24) and (c <= 2.65e+53)): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.7e+80) tmp = Float64(a / c); elseif ((c <= 1.7e-23) || (!(c <= 3.8e+24) && (c <= 2.65e+53))) 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 <= -3.7e+80) tmp = a / c; elseif ((c <= 1.7e-23) || (~((c <= 3.8e+24)) && (c <= 2.65e+53))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.7e+80], N[(a / c), $MachinePrecision], If[Or[LessEqual[c, 1.7e-23], And[N[Not[LessEqual[c, 3.8e+24]], $MachinePrecision], LessEqual[c, 2.65e+53]]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.7 \cdot 10^{+80}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-23} \lor \neg \left(c \leq 3.8 \cdot 10^{+24}\right) \land c \leq 2.65 \cdot 10^{+53}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3.69999999999999996e80 or 1.7e-23 < c < 3.80000000000000015e24 or 2.6500000000000001e53 < c Initial program 51.8%
Taylor expanded in c around inf 72.6%
if -3.69999999999999996e80 < c < 1.7e-23 or 3.80000000000000015e24 < c < 2.6500000000000001e53Initial program 73.7%
Taylor expanded in c around 0 69.0%
Final simplification70.5%
(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 64.5%
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 2023274
(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))))