
(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
(let* ((t_0 (* (/ b c) d)))
(if (<= c -2.9e+70)
(/ (+ a t_0) c)
(if (<= c 3.6e-95)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.25e+14)
(/ (* a (+ c (* b (/ d a)))) (+ (* c c) (* d d)))
(/ (+ a (- t_0 (* a (* (/ d c) (/ d c))))) c))))))
double code(double a, double b, double c, double d) {
double t_0 = (b / c) * d;
double tmp;
if (c <= -2.9e+70) {
tmp = (a + t_0) / c;
} else if (c <= 3.6e-95) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.25e+14) {
tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
} else {
tmp = (a + (t_0 - (a * ((d / c) * (d / 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) :: t_0
real(8) :: tmp
t_0 = (b / c) * d
if (c <= (-2.9d+70)) then
tmp = (a + t_0) / c
else if (c <= 3.6d-95) then
tmp = (b + (a * (c / d))) / d
else if (c <= 1.25d+14) then
tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d))
else
tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / c) * d;
double tmp;
if (c <= -2.9e+70) {
tmp = (a + t_0) / c;
} else if (c <= 3.6e-95) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.25e+14) {
tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
} else {
tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / c) * d tmp = 0 if c <= -2.9e+70: tmp = (a + t_0) / c elif c <= 3.6e-95: tmp = (b + (a * (c / d))) / d elif c <= 1.25e+14: tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d)) else: tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / c) * d) tmp = 0.0 if (c <= -2.9e+70) tmp = Float64(Float64(a + t_0) / c); elseif (c <= 3.6e-95) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.25e+14) tmp = Float64(Float64(a * Float64(c + Float64(b * Float64(d / a)))) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(a + Float64(t_0 - Float64(a * Float64(Float64(d / c) * Float64(d / c))))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / c) * d; tmp = 0.0; if (c <= -2.9e+70) tmp = (a + t_0) / c; elseif (c <= 3.6e-95) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.25e+14) tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d)); else tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]}, If[LessEqual[c, -2.9e+70], N[(N[(a + t$95$0), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 3.6e-95], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.25e+14], N[(N[(a * N[(c + N[(b * N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(t$95$0 - N[(a * N[(N[(d / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{c} \cdot d\\
\mathbf{if}\;c \leq -2.9 \cdot 10^{+70}:\\
\;\;\;\;\frac{a + t\_0}{c}\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{-95}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{+14}:\\
\;\;\;\;\frac{a \cdot \left(c + b \cdot \frac{d}{a}\right)}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \left(t\_0 - a \cdot \left(\frac{d}{c} \cdot \frac{d}{c}\right)\right)}{c}\\
\end{array}
\end{array}
if c < -2.8999999999999998e70Initial program 36.0%
Taylor expanded in c around inf 85.9%
*-commutative85.9%
Simplified85.9%
associate-*r/89.6%
*-commutative89.6%
Applied egg-rr89.6%
if -2.8999999999999998e70 < c < 3.6e-95Initial program 66.1%
Taylor expanded in d around inf 85.3%
associate-/l*86.8%
Simplified86.8%
if 3.6e-95 < c < 1.25e14Initial program 94.6%
Taylor expanded in a around inf 94.5%
associate-/l*94.7%
Simplified94.7%
if 1.25e14 < c Initial program 43.9%
Taylor expanded in c around inf 68.6%
+-commutative68.6%
mul-1-neg68.6%
unsub-neg68.6%
*-commutative68.6%
associate-/l*72.3%
associate-/l*74.6%
Simplified74.6%
unpow274.6%
unpow274.6%
times-frac81.8%
Applied egg-rr81.8%
Final simplification87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* (/ b c) d)) c)))
(if (<= c -1.25e+71)
t_0
(if (<= c 3.2e-95)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.06e+14)
(/ (* a (+ c (* b (/ d a)))) (+ (* c c) (* d d)))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + ((b / c) * d)) / c;
double tmp;
if (c <= -1.25e+71) {
tmp = t_0;
} else if (c <= 3.2e-95) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.06e+14) {
tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * 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 + ((b / c) * d)) / c
if (c <= (-1.25d+71)) then
tmp = t_0
else if (c <= 3.2d-95) then
tmp = (b + (a * (c / d))) / d
else if (c <= 1.06d+14) then
tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * 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 + ((b / c) * d)) / c;
double tmp;
if (c <= -1.25e+71) {
tmp = t_0;
} else if (c <= 3.2e-95) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.06e+14) {
tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + ((b / c) * d)) / c tmp = 0 if c <= -1.25e+71: tmp = t_0 elif c <= 3.2e-95: tmp = (b + (a * (c / d))) / d elif c <= 1.06e+14: tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(Float64(b / c) * d)) / c) tmp = 0.0 if (c <= -1.25e+71) tmp = t_0; elseif (c <= 3.2e-95) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.06e+14) tmp = Float64(Float64(a * Float64(c + Float64(b * Float64(d / a)))) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + ((b / c) * d)) / c; tmp = 0.0; if (c <= -1.25e+71) tmp = t_0; elseif (c <= 3.2e-95) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.06e+14) tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.25e+71], t$95$0, If[LessEqual[c, 3.2e-95], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.06e+14], N[(N[(a * N[(c + N[(b * N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + \frac{b}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{+71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{-95}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.06 \cdot 10^{+14}:\\
\;\;\;\;\frac{a \cdot \left(c + b \cdot \frac{d}{a}\right)}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.24999999999999993e71 or 1.06e14 < c Initial program 39.9%
Taylor expanded in c around inf 81.9%
*-commutative81.9%
Simplified81.9%
associate-*r/85.6%
*-commutative85.6%
Applied egg-rr85.6%
if -1.24999999999999993e71 < c < 3.1999999999999997e-95Initial program 66.1%
Taylor expanded in d around inf 85.3%
associate-/l*86.8%
Simplified86.8%
if 3.1999999999999997e-95 < c < 1.06e14Initial program 94.6%
Taylor expanded in a around inf 94.5%
associate-/l*94.7%
Simplified94.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* (/ b c) d)) c)))
(if (<= c -1.28e+71)
t_0
(if (<= c 5.1e-99)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.28e+14) (/ (+ (* c a) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + ((b / c) * d)) / c;
double tmp;
if (c <= -1.28e+71) {
tmp = t_0;
} else if (c <= 5.1e-99) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.28e+14) {
tmp = ((c * a) + (b * d)) / ((c * c) + (d * 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 + ((b / c) * d)) / c
if (c <= (-1.28d+71)) then
tmp = t_0
else if (c <= 5.1d-99) then
tmp = (b + (a * (c / d))) / d
else if (c <= 1.28d+14) then
tmp = ((c * a) + (b * d)) / ((c * c) + (d * 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 + ((b / c) * d)) / c;
double tmp;
if (c <= -1.28e+71) {
tmp = t_0;
} else if (c <= 5.1e-99) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.28e+14) {
tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + ((b / c) * d)) / c tmp = 0 if c <= -1.28e+71: tmp = t_0 elif c <= 5.1e-99: tmp = (b + (a * (c / d))) / d elif c <= 1.28e+14: tmp = ((c * a) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(Float64(b / c) * d)) / c) tmp = 0.0 if (c <= -1.28e+71) tmp = t_0; elseif (c <= 5.1e-99) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.28e+14) tmp = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + ((b / c) * d)) / c; tmp = 0.0; if (c <= -1.28e+71) tmp = t_0; elseif (c <= 5.1e-99) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.28e+14) tmp = ((c * a) + (b * d)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.28e+71], t$95$0, If[LessEqual[c, 5.1e-99], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.28e+14], N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + \frac{b}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -1.28 \cdot 10^{+71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 5.1 \cdot 10^{-99}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.28 \cdot 10^{+14}:\\
\;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.2800000000000001e71 or 1.28e14 < c Initial program 39.9%
Taylor expanded in c around inf 81.9%
*-commutative81.9%
Simplified81.9%
associate-*r/85.6%
*-commutative85.6%
Applied egg-rr85.6%
if -1.2800000000000001e71 < c < 5.0999999999999999e-99Initial program 66.1%
Taylor expanded in d around inf 85.3%
associate-/l*86.8%
Simplified86.8%
if 5.0999999999999999e-99 < c < 1.28e14Initial program 94.6%
Final simplification87.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.9e+70) (not (<= c 2.5e-79))) (/ (+ a (* (/ b c) d)) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.9e+70) || !(c <= 2.5e-79)) {
tmp = (a + ((b / c) * d)) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-2.9d+70)) .or. (.not. (c <= 2.5d-79))) then
tmp = (a + ((b / c) * d)) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.9e+70) || !(c <= 2.5e-79)) {
tmp = (a + ((b / c) * d)) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.9e+70) or not (c <= 2.5e-79): tmp = (a + ((b / c) * d)) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.9e+70) || !(c <= 2.5e-79)) tmp = Float64(Float64(a + Float64(Float64(b / c) * d)) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.9e+70) || ~((c <= 2.5e-79))) tmp = (a + ((b / c) * d)) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.9e+70], N[Not[LessEqual[c, 2.5e-79]], $MachinePrecision]], N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.9 \cdot 10^{+70} \lor \neg \left(c \leq 2.5 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -2.8999999999999998e70 or 2.5e-79 < c Initial program 47.8%
Taylor expanded in c around inf 78.6%
*-commutative78.6%
Simplified78.6%
associate-*r/81.0%
*-commutative81.0%
Applied egg-rr81.0%
if -2.8999999999999998e70 < c < 2.5e-79Initial program 67.4%
Taylor expanded in d around inf 84.8%
associate-/l*86.2%
Simplified86.2%
Final simplification83.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6e-19) (not (<= c 1.3e-80))) (/ (+ a (* (/ b c) d)) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6e-19) || !(c <= 1.3e-80)) {
tmp = (a + ((b / c) * d)) / 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 <= (-6d-19)) .or. (.not. (c <= 1.3d-80))) then
tmp = (a + ((b / c) * d)) / 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 <= -6e-19) || !(c <= 1.3e-80)) {
tmp = (a + ((b / c) * d)) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6e-19) or not (c <= 1.3e-80): tmp = (a + ((b / c) * d)) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6e-19) || !(c <= 1.3e-80)) tmp = Float64(Float64(a + Float64(Float64(b / c) * d)) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6e-19) || ~((c <= 1.3e-80))) tmp = (a + ((b / c) * d)) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6e-19], N[Not[LessEqual[c, 1.3e-80]], $MachinePrecision]], N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6 \cdot 10^{-19} \lor \neg \left(c \leq 1.3 \cdot 10^{-80}\right):\\
\;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -5.99999999999999985e-19 or 1.3e-80 < c Initial program 50.4%
Taylor expanded in c around inf 74.0%
*-commutative74.0%
Simplified74.0%
associate-*r/76.1%
*-commutative76.1%
Applied egg-rr76.1%
if -5.99999999999999985e-19 < c < 1.3e-80Initial program 67.5%
Taylor expanded in c around 0 68.6%
Final simplification72.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.5e-21) (not (<= c 1.85e-79))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.5e-21) || !(c <= 1.85e-79)) {
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.5d-21)) .or. (.not. (c <= 1.85d-79))) 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.5e-21) || !(c <= 1.85e-79)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.5e-21) or not (c <= 1.85e-79): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.5e-21) || !(c <= 1.85e-79)) 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.5e-21) || ~((c <= 1.85e-79))) 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.5e-21], N[Not[LessEqual[c, 1.85e-79]], $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.5 \cdot 10^{-21} \lor \neg \left(c \leq 1.85 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.49999999999999996e-21 or 1.85000000000000009e-79 < c Initial program 50.4%
div-inv50.3%
fma-define50.3%
add-sqr-sqrt50.3%
pow250.3%
hypot-define50.3%
Applied egg-rr50.3%
Taylor expanded in c around inf 74.0%
associate-/l*76.0%
Simplified76.0%
if -1.49999999999999996e-21 < c < 1.85000000000000009e-79Initial program 67.5%
Taylor expanded in c around 0 68.6%
Final simplification72.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.2e-21) (not (<= c 14500000000.0))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.2e-21) || !(c <= 14500000000.0)) {
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 <= (-3.2d-21)) .or. (.not. (c <= 14500000000.0d0))) 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 <= -3.2e-21) || !(c <= 14500000000.0)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.2e-21) or not (c <= 14500000000.0): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.2e-21) || !(c <= 14500000000.0)) 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 <= -3.2e-21) || ~((c <= 14500000000.0))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.2e-21], N[Not[LessEqual[c, 14500000000.0]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.2 \cdot 10^{-21} \lor \neg \left(c \leq 14500000000\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3.2000000000000002e-21 or 1.45e10 < c Initial program 44.0%
Taylor expanded in c around inf 63.5%
if -3.2000000000000002e-21 < c < 1.45e10Initial program 71.4%
Taylor expanded in c around 0 64.2%
Final simplification63.8%
(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 57.6%
Taylor expanded in c around inf 40.4%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024180
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))