
(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
(let* ((t_0 (fma c c (* d d)))
(t_1 (fma (- a) (/ d t_0) (/ (* c b) t_0)))
(t_2 (/ (fma (- d) (/ a c) b) c)))
(if (<= c -2.4e+82)
t_2
(if (<= c -8.8e-91)
t_1
(if (<= c 8.6e-164)
(/ (- (* b (/ c d)) a) d)
(if (<= c 2e+53) t_1 t_2))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, c, (d * d));
double t_1 = fma(-a, (d / t_0), ((c * b) / t_0));
double t_2 = fma(-d, (a / c), b) / c;
double tmp;
if (c <= -2.4e+82) {
tmp = t_2;
} else if (c <= -8.8e-91) {
tmp = t_1;
} else if (c <= 8.6e-164) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 2e+53) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(c, c, Float64(d * d)) t_1 = fma(Float64(-a), Float64(d / t_0), Float64(Float64(c * b) / t_0)) t_2 = Float64(fma(Float64(-d), Float64(a / c), b) / c) tmp = 0.0 if (c <= -2.4e+82) tmp = t_2; elseif (c <= -8.8e-91) tmp = t_1; elseif (c <= 8.6e-164) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 2e+53) tmp = t_1; else tmp = t_2; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-a) * N[(d / t$95$0), $MachinePrecision] + N[(N[(c * b), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[((-d) * N[(a / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.4e+82], t$95$2, If[LessEqual[c, -8.8e-91], t$95$1, If[LessEqual[c, 8.6e-164], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2e+53], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, c, d \cdot d\right)\\
t_1 := \mathsf{fma}\left(-a, \frac{d}{t\_0}, \frac{c \cdot b}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -2.4 \cdot 10^{+82}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;c \leq -8.8 \cdot 10^{-91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 8.6 \cdot 10^{-164}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 2 \cdot 10^{+53}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if c < -2.39999999999999998e82 or 2e53 < c Initial program 32.4%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6479.0
Simplified79.0%
div-invN/A
cancel-sign-sub-invN/A
div-invN/A
+-commutativeN/A
distribute-lft-neg-inN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f6482.7
Applied egg-rr82.7%
if -2.39999999999999998e82 < c < -8.8000000000000003e-91 or 8.5999999999999996e-164 < c < 2e53Initial program 79.0%
div-subN/A
sub-negN/A
+-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6484.3
Applied egg-rr84.3%
if -8.8000000000000003e-91 < c < 8.5999999999999996e-164Initial program 62.4%
div-subN/A
sub-negN/A
+-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6464.1
Applied egg-rr64.1%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6484.7
Simplified84.7%
distribute-frac-neg2N/A
unsub-negN/A
*-commutativeN/A
associate-/r*N/A
associate-*l/N/A
sub-divN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6492.2
Applied egg-rr92.2%
Final simplification85.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* d d) (* c c))))
(t_1 (/ (fma (- d) (/ a c) b) c)))
(if (<= c -5.8e+81)
t_1
(if (<= c -2.1e-87)
t_0
(if (<= c 8.6e-164)
(/ (- (* b (/ c d)) a) d)
(if (<= c 3.65e+53) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((d * d) + (c * c));
double t_1 = fma(-d, (a / c), b) / c;
double tmp;
if (c <= -5.8e+81) {
tmp = t_1;
} else if (c <= -2.1e-87) {
tmp = t_0;
} else if (c <= 8.6e-164) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 3.65e+53) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))) t_1 = Float64(fma(Float64(-d), Float64(a / c), b) / c) tmp = 0.0 if (c <= -5.8e+81) tmp = t_1; elseif (c <= -2.1e-87) tmp = t_0; elseif (c <= 8.6e-164) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 3.65e+53) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-d) * N[(a / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -5.8e+81], t$95$1, If[LessEqual[c, -2.1e-87], t$95$0, If[LessEqual[c, 8.6e-164], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.65e+53], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\
t_1 := \frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -5.8 \cdot 10^{+81}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -2.1 \cdot 10^{-87}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 8.6 \cdot 10^{-164}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 3.65 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -5.7999999999999999e81 or 3.65000000000000008e53 < c Initial program 32.4%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6479.0
Simplified79.0%
div-invN/A
cancel-sign-sub-invN/A
div-invN/A
+-commutativeN/A
distribute-lft-neg-inN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f6482.7
Applied egg-rr82.7%
if -5.7999999999999999e81 < c < -2.10000000000000007e-87 or 8.5999999999999996e-164 < c < 3.65000000000000008e53Initial program 79.0%
if -2.10000000000000007e-87 < c < 8.5999999999999996e-164Initial program 62.4%
div-subN/A
sub-negN/A
+-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6464.1
Applied egg-rr64.1%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6484.7
Simplified84.7%
distribute-frac-neg2N/A
unsub-negN/A
*-commutativeN/A
associate-/r*N/A
associate-*l/N/A
sub-divN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6492.2
Applied egg-rr92.2%
Final simplification84.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (* c c))))
(if (<= c -5.5e+123)
(/ b c)
(if (<= c -1.55e-80)
t_0
(if (<= c 4.8e-31) (/ (- a) d) (if (<= c 5.1e+92) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / (c * c);
double tmp;
if (c <= -5.5e+123) {
tmp = b / c;
} else if (c <= -1.55e-80) {
tmp = t_0;
} else if (c <= 4.8e-31) {
tmp = -a / d;
} else if (c <= 5.1e+92) {
tmp = t_0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / (c * c)
if (c <= (-5.5d+123)) then
tmp = b / c
else if (c <= (-1.55d-80)) then
tmp = t_0
else if (c <= 4.8d-31) then
tmp = -a / d
else if (c <= 5.1d+92) then
tmp = t_0
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / (c * c);
double tmp;
if (c <= -5.5e+123) {
tmp = b / c;
} else if (c <= -1.55e-80) {
tmp = t_0;
} else if (c <= 4.8e-31) {
tmp = -a / d;
} else if (c <= 5.1e+92) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / (c * c) tmp = 0 if c <= -5.5e+123: tmp = b / c elif c <= -1.55e-80: tmp = t_0 elif c <= 4.8e-31: tmp = -a / d elif c <= 5.1e+92: tmp = t_0 else: tmp = b / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(c * c)) tmp = 0.0 if (c <= -5.5e+123) tmp = Float64(b / c); elseif (c <= -1.55e-80) tmp = t_0; elseif (c <= 4.8e-31) tmp = Float64(Float64(-a) / d); elseif (c <= 5.1e+92) tmp = t_0; else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / (c * c); tmp = 0.0; if (c <= -5.5e+123) tmp = b / c; elseif (c <= -1.55e-80) tmp = t_0; elseif (c <= 4.8e-31) tmp = -a / d; elseif (c <= 5.1e+92) tmp = t_0; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.5e+123], N[(b / c), $MachinePrecision], If[LessEqual[c, -1.55e-80], t$95$0, If[LessEqual[c, 4.8e-31], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 5.1e+92], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c}\\
\mathbf{if}\;c \leq -5.5 \cdot 10^{+123}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -1.55 \cdot 10^{-80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-31}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 5.1 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.5000000000000002e123 or 5.1000000000000003e92 < c Initial program 25.3%
Taylor expanded in c around inf
/-lowering-/.f6477.5
Simplified77.5%
if -5.5000000000000002e123 < c < -1.55000000000000008e-80 or 4.8e-31 < c < 5.1000000000000003e92Initial program 80.2%
Taylor expanded in c around inf
unpow2N/A
*-lowering-*.f6461.4
Simplified61.4%
if -1.55000000000000008e-80 < c < 4.8e-31Initial program 65.0%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6465.6
Simplified65.6%
Final simplification68.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -1.3e+150)
t_0
(if (<= d -0.48)
(* a (/ (- d) (fma c c (* d d))))
(if (<= d 2.15e+51) (/ (- b (/ (* d a) c)) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -1.3e+150) {
tmp = t_0;
} else if (d <= -0.48) {
tmp = a * (-d / fma(c, c, (d * d)));
} else if (d <= 2.15e+51) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -1.3e+150) tmp = t_0; elseif (d <= -0.48) tmp = Float64(a * Float64(Float64(-d) / fma(c, c, Float64(d * d)))); elseif (d <= 2.15e+51) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -1.3e+150], t$95$0, If[LessEqual[d, -0.48], N[(a * N[((-d) / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.15e+51], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{+150}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -0.48:\\
\;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{+51}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.30000000000000003e150 or 2.1499999999999999e51 < d Initial program 32.1%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6468.8
Simplified68.8%
if -1.30000000000000003e150 < d < -0.47999999999999998Initial program 64.9%
div-subN/A
sub-negN/A
+-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6481.8
Applied egg-rr81.8%
Taylor expanded in a around inf
mul-1-negN/A
neg-lowering-neg.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6465.7
Simplified65.7%
if -0.47999999999999998 < d < 2.1499999999999999e51Initial program 64.4%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6480.5
Simplified80.5%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (<= d -1.65e-9) (/ (fma c (/ b d) (- a)) d) (if (<= d 3.3e+49) (/ (- b (/ (* d a) c)) c) (/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.65e-9) {
tmp = fma(c, (b / d), -a) / d;
} else if (d <= 3.3e+49) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.65e-9) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); elseif (d <= 3.3e+49) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.65e-9], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 3.3e+49], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.65 \cdot 10^{-9}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+49}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.65000000000000009e-9Initial program 47.9%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
/-lowering-/.f64N/A
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6477.3
Simplified77.3%
if -1.65000000000000009e-9 < d < 3.2999999999999998e49Initial program 64.2%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6481.0
Simplified81.0%
if 3.2999999999999998e49 < d Initial program 35.4%
div-subN/A
sub-negN/A
+-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6444.2
Applied egg-rr44.2%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6475.8
Simplified75.8%
distribute-frac-neg2N/A
unsub-negN/A
*-commutativeN/A
associate-/r*N/A
associate-*l/N/A
sub-divN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6480.8
Applied egg-rr80.8%
Final simplification80.1%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- (* b (/ c d)) a) d))) (if (<= d -2.1e-9) t_0 (if (<= d 8e+49) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * (c / d)) - a) / d;
double tmp;
if (d <= -2.1e-9) {
tmp = t_0;
} else if (d <= 8e+49) {
tmp = (b - ((d * a) / c)) / c;
} 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 = ((b * (c / d)) - a) / d
if (d <= (-2.1d-9)) then
tmp = t_0
else if (d <= 8d+49) then
tmp = (b - ((d * a) / c)) / c
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 = ((b * (c / d)) - a) / d;
double tmp;
if (d <= -2.1e-9) {
tmp = t_0;
} else if (d <= 8e+49) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * (c / d)) - a) / d tmp = 0 if d <= -2.1e-9: tmp = t_0 elif d <= 8e+49: tmp = (b - ((d * a) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * Float64(c / d)) - a) / d) tmp = 0.0 if (d <= -2.1e-9) tmp = t_0; elseif (d <= 8e+49) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * (c / d)) - a) / d; tmp = 0.0; if (d <= -2.1e-9) tmp = t_0; elseif (d <= 8e+49) tmp = (b - ((d * a) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.1e-9], t$95$0, If[LessEqual[d, 8e+49], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.1 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+49}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.10000000000000019e-9 or 7.99999999999999957e49 < d Initial program 42.3%
div-subN/A
sub-negN/A
+-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6451.4
Applied egg-rr51.4%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6471.2
Simplified71.2%
distribute-frac-neg2N/A
unsub-negN/A
*-commutativeN/A
associate-/r*N/A
associate-*l/N/A
sub-divN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6478.4
Applied egg-rr78.4%
if -2.10000000000000019e-9 < d < 7.99999999999999957e49Initial program 64.2%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6481.0
Simplified81.0%
Final simplification79.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.8e+82)
(/ b c)
(if (<= c -1.75e-91)
(/ (* c b) (fma d d (* c c)))
(if (<= c 5.8e-31) (/ (- a) d) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.8e+82) {
tmp = b / c;
} else if (c <= -1.75e-91) {
tmp = (c * b) / fma(d, d, (c * c));
} else if (c <= 5.8e-31) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.8e+82) tmp = Float64(b / c); elseif (c <= -1.75e-91) tmp = Float64(Float64(c * b) / fma(d, d, Float64(c * c))); elseif (c <= 5.8e-31) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.8e+82], N[(b / c), $MachinePrecision], If[LessEqual[c, -1.75e-91], N[(N[(c * b), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.8e-31], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.8 \cdot 10^{+82}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -1.75 \cdot 10^{-91}:\\
\;\;\;\;\frac{c \cdot b}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 5.8 \cdot 10^{-31}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.80000000000000007e82 or 5.8000000000000001e-31 < c Initial program 37.9%
Taylor expanded in c around inf
/-lowering-/.f6469.2
Simplified69.2%
if -1.80000000000000007e82 < c < -1.7499999999999999e-91Initial program 83.2%
Taylor expanded in b around inf
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
unpow2N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6459.6
Simplified59.6%
if -1.7499999999999999e-91 < c < 5.8000000000000001e-31Initial program 64.7%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6466.2
Simplified66.2%
Final simplification66.7%
(FPCore (a b c d) :precision binary64 (if (<= c -3500000.0) (/ b c) (if (<= c 2.6e-31) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3500000.0) {
tmp = b / c;
} else if (c <= 2.6e-31) {
tmp = -a / d;
} else {
tmp = 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 (c <= (-3500000.0d0)) then
tmp = b / c
else if (c <= 2.6d-31) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3500000.0) {
tmp = b / c;
} else if (c <= 2.6e-31) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3500000.0: tmp = b / c elif c <= 2.6e-31: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3500000.0) tmp = Float64(b / c); elseif (c <= 2.6e-31) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3500000.0) tmp = b / c; elseif (c <= 2.6e-31) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3500000.0], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.6e-31], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3500000:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{-31}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -3.5e6 or 2.59999999999999995e-31 < c Initial program 43.5%
Taylor expanded in c around inf
/-lowering-/.f6467.3
Simplified67.3%
if -3.5e6 < c < 2.59999999999999995e-31Initial program 67.2%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-lowering-neg.f6461.6
Simplified61.6%
Final simplification64.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 54.5%
Taylor expanded in c around inf
/-lowering-/.f6445.0
Simplified45.0%
(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 2024204
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (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))))