
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \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 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (or (<= a -7.1e-71) (not (<= a 1.3e-69))) (* (/ (fma b (/ c a) (- d)) (hypot d c)) (/ a (hypot d c))) (* b (* (/ 1.0 (hypot d c)) (/ c (hypot d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((a <= -7.1e-71) || !(a <= 1.3e-69)) {
tmp = (fma(b, (c / a), -d) / hypot(d, c)) * (a / hypot(d, c));
} else {
tmp = b * ((1.0 / hypot(d, c)) * (c / hypot(d, c)));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((a <= -7.1e-71) || !(a <= 1.3e-69)) tmp = Float64(Float64(fma(b, Float64(c / a), Float64(-d)) / hypot(d, c)) * Float64(a / hypot(d, c))); else tmp = Float64(b * Float64(Float64(1.0 / hypot(d, c)) * Float64(c / hypot(d, c)))); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[a, -7.1e-71], N[Not[LessEqual[a, 1.3e-69]], $MachinePrecision]], N[(N[(N[(b * N[(c / a), $MachinePrecision] + (-d)), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(N[(1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -7.1 \cdot 10^{-71} \lor \neg \left(a \leq 1.3 \cdot 10^{-69}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{a}, -d\right)}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}\right)\\
\end{array}
\end{array}
if a < -7.10000000000000008e-71 or 1.3000000000000001e-69 < a Initial program 49.7%
Taylor expanded in a around inf 49.6%
associate-/l*48.4%
Simplified48.4%
*-commutative48.4%
add-sqr-sqrt48.3%
times-frac55.3%
fma-neg55.3%
+-commutative55.3%
hypot-define55.3%
+-commutative55.3%
hypot-define90.5%
Applied egg-rr90.5%
if -7.10000000000000008e-71 < a < 1.3000000000000001e-69Initial program 72.6%
Taylor expanded in b around inf 65.1%
associate-/l*66.7%
Simplified66.7%
*-un-lft-identity66.7%
pow266.7%
pow266.7%
add-sqr-sqrt66.7%
times-frac66.6%
+-commutative66.6%
hypot-define66.6%
+-commutative66.6%
hypot-define87.4%
Applied egg-rr87.4%
Final simplification89.3%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.5e+22)
(/ (- b (* a (/ d c))) c)
(if (<= c -9e-74)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= c 4.2e-153)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.5e+75)
(/ (fma b c (* d (- a))) (fma d d (* c c)))
(* (- b (* d (/ a c))) (/ 1.0 c)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.5e+22) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -9e-74) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 4.2e-153) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.5e+75) {
tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
} else {
tmp = (b - (d * (a / c))) * (1.0 / c);
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.5e+22) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= -9e-74) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 4.2e-153) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.5e+75) tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c))); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) * Float64(1.0 / c)); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.5e+22], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -9e-74], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.2e-153], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.5e+75], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.5 \cdot 10^{+22}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -9 \cdot 10^{-74}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 4.2 \cdot 10^{-153}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+75}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(b - d \cdot \frac{a}{c}\right) \cdot \frac{1}{c}\\
\end{array}
\end{array}
if c < -1.5e22Initial program 36.9%
Taylor expanded in c around inf 71.8%
remove-double-neg71.8%
mul-1-neg71.8%
neg-mul-171.8%
distribute-lft-in71.8%
mul-1-neg71.8%
distribute-neg-in71.8%
mul-1-neg71.8%
remove-double-neg71.8%
unsub-neg71.8%
associate-/l*80.8%
Simplified80.8%
if -1.5e22 < c < -8.9999999999999998e-74Initial program 99.7%
if -8.9999999999999998e-74 < c < 4.20000000000000008e-153Initial program 65.0%
Taylor expanded in d around inf 91.2%
if 4.20000000000000008e-153 < c < 1.5e75Initial program 80.5%
fma-neg80.5%
distribute-rgt-neg-out80.5%
+-commutative80.5%
fma-define80.5%
Simplified80.5%
if 1.5e75 < c Initial program 39.7%
Taylor expanded in c around inf 79.0%
remove-double-neg79.0%
mul-1-neg79.0%
neg-mul-179.0%
distribute-lft-in79.0%
mul-1-neg79.0%
distribute-neg-in79.0%
mul-1-neg79.0%
remove-double-neg79.0%
unsub-neg79.0%
associate-/l*83.8%
Simplified83.8%
Taylor expanded in a around 0 79.0%
*-commutative79.0%
associate-*r/85.3%
*-commutative85.3%
associate-/r/83.8%
Simplified83.8%
div-inv83.7%
associate-/r/85.1%
Applied egg-rr85.1%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
(if (<= c -1.5e+22)
(/ (- b (* a (/ d c))) c)
(if (<= c -9e-72)
t_0
(if (<= c 1.12e-153)
(/ (- (/ (* b c) d) a) d)
(if (<= c 5.2e+73) t_0 (* (- b (* d (/ a c))) (/ 1.0 c))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.5e+22) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -9e-72) {
tmp = t_0;
} else if (c <= 1.12e-153) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 5.2e+73) {
tmp = t_0;
} else {
tmp = (b - (d * (a / c))) * (1.0 / 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) - (a * d)) / ((c * c) + (d * d))
if (c <= (-1.5d+22)) then
tmp = (b - (a * (d / c))) / c
else if (c <= (-9d-72)) then
tmp = t_0
else if (c <= 1.12d-153) then
tmp = (((b * c) / d) - a) / d
else if (c <= 5.2d+73) then
tmp = t_0
else
tmp = (b - (d * (a / c))) * (1.0d0 / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.5e+22) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -9e-72) {
tmp = t_0;
} else if (c <= 1.12e-153) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 5.2e+73) {
tmp = t_0;
} else {
tmp = (b - (d * (a / c))) * (1.0 / c);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.5e+22: tmp = (b - (a * (d / c))) / c elif c <= -9e-72: tmp = t_0 elif c <= 1.12e-153: tmp = (((b * c) / d) - a) / d elif c <= 5.2e+73: tmp = t_0 else: tmp = (b - (d * (a / c))) * (1.0 / c) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -1.5e+22) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= -9e-72) tmp = t_0; elseif (c <= 1.12e-153) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 5.2e+73) tmp = t_0; else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) * Float64(1.0 / c)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -1.5e+22) tmp = (b - (a * (d / c))) / c; elseif (c <= -9e-72) tmp = t_0; elseif (c <= 1.12e-153) tmp = (((b * c) / d) - a) / d; elseif (c <= 5.2e+73) tmp = t_0; else tmp = (b - (d * (a / c))) * (1.0 / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.5e+22], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -9e-72], t$95$0, If[LessEqual[c, 1.12e-153], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.2e+73], t$95$0, N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -1.5 \cdot 10^{+22}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -9 \cdot 10^{-72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.12 \cdot 10^{-153}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(b - d \cdot \frac{a}{c}\right) \cdot \frac{1}{c}\\
\end{array}
\end{array}
if c < -1.5e22Initial program 36.9%
Taylor expanded in c around inf 71.8%
remove-double-neg71.8%
mul-1-neg71.8%
neg-mul-171.8%
distribute-lft-in71.8%
mul-1-neg71.8%
distribute-neg-in71.8%
mul-1-neg71.8%
remove-double-neg71.8%
unsub-neg71.8%
associate-/l*80.8%
Simplified80.8%
if -1.5e22 < c < -9e-72 or 1.12000000000000005e-153 < c < 5.2000000000000001e73Initial program 86.3%
if -9e-72 < c < 1.12000000000000005e-153Initial program 65.0%
Taylor expanded in d around inf 91.2%
if 5.2000000000000001e73 < c Initial program 39.7%
Taylor expanded in c around inf 79.0%
remove-double-neg79.0%
mul-1-neg79.0%
neg-mul-179.0%
distribute-lft-in79.0%
mul-1-neg79.0%
distribute-neg-in79.0%
mul-1-neg79.0%
remove-double-neg79.0%
unsub-neg79.0%
associate-/l*83.8%
Simplified83.8%
Taylor expanded in a around 0 79.0%
*-commutative79.0%
associate-*r/85.3%
*-commutative85.3%
associate-/r/83.8%
Simplified83.8%
div-inv83.7%
associate-/r/85.1%
Applied egg-rr85.1%
Final simplification86.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.9e-26) (not (<= c 7.8e-102))) (/ (- b (* a (/ d c))) c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.9e-26) || !(c <= 7.8e-102)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -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.9d-26)) .or. (.not. (c <= 7.8d-102))) then
tmp = (b - (a * (d / c))) / c
else
tmp = a / -d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.9e-26) || !(c <= 7.8e-102)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.9e-26) or not (c <= 7.8e-102): tmp = (b - (a * (d / c))) / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.9e-26) || !(c <= 7.8e-102)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.9e-26) || ~((c <= 7.8e-102))) tmp = (b - (a * (d / c))) / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.9e-26], N[Not[LessEqual[c, 7.8e-102]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.9 \cdot 10^{-26} \lor \neg \left(c \leq 7.8 \cdot 10^{-102}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -3.89999999999999986e-26 or 7.79999999999999999e-102 < c Initial program 50.9%
Taylor expanded in c around inf 70.9%
remove-double-neg70.9%
mul-1-neg70.9%
neg-mul-170.9%
distribute-lft-in70.9%
mul-1-neg70.9%
distribute-neg-in70.9%
mul-1-neg70.9%
remove-double-neg70.9%
unsub-neg70.9%
associate-/l*75.7%
Simplified75.7%
if -3.89999999999999986e-26 < c < 7.79999999999999999e-102Initial program 71.8%
Taylor expanded in c around 0 72.7%
associate-*r/72.7%
neg-mul-172.7%
Simplified72.7%
Final simplification74.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.15e-65) (not (<= d 1.05e+53))) (/ (- (* b (/ c d)) a) d) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-65) || !(d <= 1.05e+53)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a / (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 ((d <= (-1.15d-65)) .or. (.not. (d <= 1.05d+53))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-65) || !(d <= 1.05e+53)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.15e-65) or not (d <= 1.05e+53): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.15e-65) || !(d <= 1.05e+53)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.15e-65) || ~((d <= 1.05e+53))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.15e-65], N[Not[LessEqual[d, 1.05e+53]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.15 \cdot 10^{-65} \lor \neg \left(d \leq 1.05 \cdot 10^{+53}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -1.15e-65 or 1.0500000000000001e53 < d Initial program 46.5%
Taylor expanded in a around inf 39.0%
associate-/l*35.4%
Simplified35.4%
*-commutative35.4%
add-sqr-sqrt35.4%
times-frac42.6%
fma-neg42.6%
+-commutative42.6%
hypot-define42.6%
+-commutative42.6%
hypot-define75.0%
Applied egg-rr75.0%
Taylor expanded in d around inf 70.7%
+-commutative70.7%
mul-1-neg70.7%
sub-neg70.7%
associate-/l*76.9%
Simplified76.9%
if -1.15e-65 < d < 1.0500000000000001e53Initial program 69.1%
Taylor expanded in c around inf 82.2%
remove-double-neg82.2%
mul-1-neg82.2%
neg-mul-182.2%
distribute-lft-in82.2%
mul-1-neg82.2%
distribute-neg-in82.2%
mul-1-neg82.2%
remove-double-neg82.2%
unsub-neg82.2%
associate-/l*83.5%
Simplified83.5%
Taylor expanded in a around 0 82.2%
*-commutative82.2%
associate-*r/82.1%
*-commutative82.1%
associate-/r/83.6%
Simplified83.6%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (<= c -8.2e-26) (/ (- b (* a (/ d c))) c) (if (<= c 7.8e-102) (/ a (- d)) (/ (- b (/ a (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.2e-26) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 7.8e-102) {
tmp = a / -d;
} else {
tmp = (b - (a / (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 <= (-8.2d-26)) then
tmp = (b - (a * (d / c))) / c
else if (c <= 7.8d-102) then
tmp = a / -d
else
tmp = (b - (a / (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 <= -8.2e-26) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 7.8e-102) {
tmp = a / -d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -8.2e-26: tmp = (b - (a * (d / c))) / c elif c <= 7.8e-102: tmp = a / -d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -8.2e-26) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= 7.8e-102) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -8.2e-26) tmp = (b - (a * (d / c))) / c; elseif (c <= 7.8e-102) tmp = a / -d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -8.2e-26], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 7.8e-102], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.2 \cdot 10^{-26}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{-102}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -8.1999999999999997e-26Initial program 48.9%
Taylor expanded in c around inf 71.6%
remove-double-neg71.6%
mul-1-neg71.6%
neg-mul-171.6%
distribute-lft-in71.6%
mul-1-neg71.6%
distribute-neg-in71.6%
mul-1-neg71.6%
remove-double-neg71.6%
unsub-neg71.6%
associate-/l*78.9%
Simplified78.9%
if -8.1999999999999997e-26 < c < 7.79999999999999999e-102Initial program 71.8%
Taylor expanded in c around 0 72.7%
associate-*r/72.7%
neg-mul-172.7%
Simplified72.7%
if 7.79999999999999999e-102 < c Initial program 52.4%
Taylor expanded in c around inf 70.4%
remove-double-neg70.4%
mul-1-neg70.4%
neg-mul-170.4%
distribute-lft-in70.4%
mul-1-neg70.4%
distribute-neg-in70.4%
mul-1-neg70.4%
remove-double-neg70.4%
unsub-neg70.4%
associate-/l*73.5%
Simplified73.5%
Taylor expanded in a around 0 70.4%
*-commutative70.4%
associate-*r/74.4%
*-commutative74.4%
associate-/r/73.5%
Simplified73.5%
Final simplification74.6%
(FPCore (a b c d) :precision binary64 (if (<= d -1.15e-65) (/ (- (* b (/ c d)) a) d) (if (<= d 3.8e+52) (/ (- b (/ a (/ c d))) c) (/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.15e-65) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 3.8e+52) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = ((c * (b / d)) - a) / 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 <= (-1.15d-65)) then
tmp = ((b * (c / d)) - a) / d
else if (d <= 3.8d+52) then
tmp = (b - (a / (c / d))) / c
else
tmp = ((c * (b / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.15e-65) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 3.8e+52) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.15e-65: tmp = ((b * (c / d)) - a) / d elif d <= 3.8e+52: tmp = (b - (a / (c / d))) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.15e-65) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (d <= 3.8e+52) tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.15e-65) tmp = ((b * (c / d)) - a) / d; elseif (d <= 3.8e+52) tmp = (b - (a / (c / d))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.15e-65], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 3.8e+52], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.15 \cdot 10^{-65}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;d \leq 3.8 \cdot 10^{+52}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.15e-65Initial program 55.9%
Taylor expanded in a around inf 46.4%
associate-/l*42.3%
Simplified42.3%
*-commutative42.3%
add-sqr-sqrt42.3%
times-frac46.9%
fma-neg46.9%
+-commutative46.9%
hypot-define46.9%
+-commutative46.9%
hypot-define75.2%
Applied egg-rr75.2%
Taylor expanded in d around inf 72.9%
+-commutative72.9%
mul-1-neg72.9%
sub-neg72.9%
associate-/l*76.4%
Simplified76.4%
if -1.15e-65 < d < 3.8e52Initial program 69.1%
Taylor expanded in c around inf 82.2%
remove-double-neg82.2%
mul-1-neg82.2%
neg-mul-182.2%
distribute-lft-in82.2%
mul-1-neg82.2%
distribute-neg-in82.2%
mul-1-neg82.2%
remove-double-neg82.2%
unsub-neg82.2%
associate-/l*83.5%
Simplified83.5%
Taylor expanded in a around 0 82.2%
*-commutative82.2%
associate-*r/82.1%
*-commutative82.1%
associate-/r/83.6%
Simplified83.6%
if 3.8e52 < d Initial program 31.8%
Taylor expanded in c around 0 57.5%
+-commutative57.5%
mul-1-neg57.5%
unsub-neg57.5%
unpow257.5%
associate-/r*67.3%
div-sub67.3%
*-commutative67.3%
associate-/l*77.9%
Simplified77.9%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -9.5e-35) (not (<= c 0.0031))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9.5e-35) || !(c <= 0.0031)) {
tmp = b / c;
} else {
tmp = a / -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 <= (-9.5d-35)) .or. (.not. (c <= 0.0031d0))) then
tmp = b / c
else
tmp = a / -d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9.5e-35) || !(c <= 0.0031)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -9.5e-35) or not (c <= 0.0031): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -9.5e-35) || !(c <= 0.0031)) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -9.5e-35) || ~((c <= 0.0031))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -9.5e-35], N[Not[LessEqual[c, 0.0031]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.5 \cdot 10^{-35} \lor \neg \left(c \leq 0.0031\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -9.5000000000000003e-35 or 0.00309999999999999989 < c Initial program 48.0%
Taylor expanded in c around inf 65.4%
if -9.5000000000000003e-35 < c < 0.00309999999999999989Initial program 72.3%
Taylor expanded in c around 0 68.3%
associate-*r/68.3%
neg-mul-168.3%
Simplified68.3%
Final simplification66.7%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / 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 = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 58.4%
Taylor expanded in c around inf 44.8%
Final simplification44.8%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (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(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * 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 = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * 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{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024050
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))