
(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 10 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 (/ (- (* c (/ b (hypot c d))) (* d (/ a (hypot c d)))) (hypot c d)))
double code(double a, double b, double c, double d) {
return ((c * (b / hypot(c, d))) - (d * (a / hypot(c, d)))) / hypot(c, d);
}
public static double code(double a, double b, double c, double d) {
return ((c * (b / Math.hypot(c, d))) - (d * (a / Math.hypot(c, d)))) / Math.hypot(c, d);
}
def code(a, b, c, d): return ((c * (b / math.hypot(c, d))) - (d * (a / math.hypot(c, d)))) / math.hypot(c, d)
function code(a, b, c, d) return Float64(Float64(Float64(c * Float64(b / hypot(c, d))) - Float64(d * Float64(a / hypot(c, d)))) / hypot(c, d)) end
function tmp = code(a, b, c, d) tmp = ((c * (b / hypot(c, d))) - (d * (a / hypot(c, d)))) / hypot(c, d); end
code[a_, b_, c_, d_] := N[(N[(N[(c * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(d * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}
\end{array}
Initial program 66.5%
*-un-lft-identity66.5%
add-sqr-sqrt66.5%
times-frac66.5%
hypot-define66.5%
hypot-define78.0%
Applied egg-rr78.0%
associate-*l/78.2%
*-un-lft-identity78.2%
*-commutative78.2%
*-commutative78.2%
Applied egg-rr78.2%
div-sub78.2%
Applied egg-rr78.2%
associate-/l*86.3%
associate-/l*97.7%
Simplified97.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* c b) (* d a))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 4e+261)
(/ (/ t_0 (hypot c d)) (hypot c d))
(/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 4e+261) {
tmp = (t_0 / hypot(c, d)) / hypot(c, d);
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 4e+261) {
tmp = (t_0 / Math.hypot(c, d)) / Math.hypot(c, d);
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (c * b) - (d * a) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 4e+261: tmp = (t_0 / math.hypot(c, d)) / math.hypot(c, d) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(c * b) - Float64(d * a)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 4e+261) tmp = Float64(Float64(t_0 / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (c * b) - (d * a); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 4e+261) tmp = (t_0 / hypot(c, d)) / hypot(c, d); else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e+261], N[(N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot b - d \cdot a\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 4 \cdot 10^{+261}:\\
\;\;\;\;\frac{\frac{t\_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 3.9999999999999997e261Initial program 83.6%
*-un-lft-identity83.6%
add-sqr-sqrt83.6%
times-frac83.5%
hypot-define83.5%
hypot-define97.0%
Applied egg-rr97.0%
associate-*l/97.3%
*-un-lft-identity97.3%
*-commutative97.3%
*-commutative97.3%
Applied egg-rr97.3%
if 3.9999999999999997e261 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 10.7%
*-un-lft-identity10.7%
add-sqr-sqrt10.7%
times-frac10.7%
hypot-define10.7%
hypot-define15.8%
Applied egg-rr15.8%
Taylor expanded in d around inf 48.7%
neg-mul-148.7%
+-commutative48.7%
sub-neg48.7%
associate-/l*56.9%
Simplified56.9%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* c b) (* d a)))
(t_1 (- (* c (/ b d)) a))
(t_2 (+ (* c c) (* d d))))
(if (<= d -2.8e+49)
(/ t_1 d)
(if (<= d -1.15e-87)
(/ (+ t_0 (* 2.0 (fma a (- d) (* d a)))) t_2)
(if (<= d 1.9e-158)
(/ (- b (* a (/ d c))) c)
(if (<= d 5.2e+122) (/ t_0 t_2) (/ t_1 (hypot c d))))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (d * a);
double t_1 = (c * (b / d)) - a;
double t_2 = (c * c) + (d * d);
double tmp;
if (d <= -2.8e+49) {
tmp = t_1 / d;
} else if (d <= -1.15e-87) {
tmp = (t_0 + (2.0 * fma(a, -d, (d * a)))) / t_2;
} else if (d <= 1.9e-158) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 5.2e+122) {
tmp = t_0 / t_2;
} else {
tmp = t_1 / hypot(c, d);
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * b) - Float64(d * a)) t_1 = Float64(Float64(c * Float64(b / d)) - a) t_2 = Float64(Float64(c * c) + Float64(d * d)) tmp = 0.0 if (d <= -2.8e+49) tmp = Float64(t_1 / d); elseif (d <= -1.15e-87) tmp = Float64(Float64(t_0 + Float64(2.0 * fma(a, Float64(-d), Float64(d * a)))) / t_2); elseif (d <= 1.9e-158) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 5.2e+122) tmp = Float64(t_0 / t_2); else tmp = Float64(t_1 / hypot(c, d)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.8e+49], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -1.15e-87], N[(N[(t$95$0 + N[(2.0 * N[(a * (-d) + N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], If[LessEqual[d, 1.9e-158], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.2e+122], N[(t$95$0 / t$95$2), $MachinePrecision], N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot b - d \cdot a\\
t_1 := c \cdot \frac{b}{d} - a\\
t_2 := c \cdot c + d \cdot d\\
\mathbf{if}\;d \leq -2.8 \cdot 10^{+49}:\\
\;\;\;\;\frac{t\_1}{d}\\
\mathbf{elif}\;d \leq -1.15 \cdot 10^{-87}:\\
\;\;\;\;\frac{t\_0 + 2 \cdot \mathsf{fma}\left(a, -d, d \cdot a\right)}{t\_2}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{-158}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.2 \cdot 10^{+122}:\\
\;\;\;\;\frac{t\_0}{t\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -2.7999999999999998e49Initial program 50.1%
Taylor expanded in c around 0 76.2%
+-commutative76.2%
mul-1-neg76.2%
unsub-neg76.2%
unpow276.2%
associate-/r*78.0%
div-sub78.0%
*-commutative78.0%
associate-/l*80.0%
Simplified80.0%
if -2.7999999999999998e49 < d < -1.1500000000000001e-87Initial program 91.4%
prod-diff91.4%
*-commutative91.4%
fmm-def91.4%
prod-diff91.4%
*-commutative91.4%
fmm-def91.4%
associate-+l+91.5%
*-commutative91.5%
fma-undefine91.4%
distribute-lft-neg-in91.4%
*-commutative91.4%
distribute-rgt-neg-in91.4%
fma-define91.5%
*-commutative91.5%
fma-undefine91.4%
distribute-lft-neg-in91.4%
*-commutative91.4%
distribute-rgt-neg-in91.4%
fma-define91.5%
Applied egg-rr91.5%
*-commutative91.5%
*-commutative91.5%
count-291.5%
*-commutative91.5%
Simplified91.5%
if -1.1500000000000001e-87 < d < 1.8999999999999999e-158Initial program 76.3%
*-un-lft-identity76.3%
add-sqr-sqrt76.3%
times-frac76.2%
hypot-define76.2%
hypot-define85.4%
Applied egg-rr85.4%
Taylor expanded in c around inf 93.9%
mul-1-neg93.9%
sub-neg93.9%
associate-/l*93.9%
Simplified93.9%
if 1.8999999999999999e-158 < d < 5.20000000000000015e122Initial program 85.9%
if 5.20000000000000015e122 < d Initial program 37.3%
*-un-lft-identity37.3%
add-sqr-sqrt37.3%
times-frac37.3%
hypot-define37.3%
hypot-define63.2%
Applied egg-rr63.2%
associate-*l/63.4%
*-un-lft-identity63.4%
*-commutative63.4%
*-commutative63.4%
Applied egg-rr63.4%
Taylor expanded in c around 0 79.8%
+-commutative79.8%
neg-mul-179.8%
sub-neg79.8%
*-commutative79.8%
associate-*r/88.1%
Simplified88.1%
Final simplification87.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (- (* c (/ b d)) a)))
(if (<= d -3.1e+45)
(/ t_1 d)
(if (<= d -6.5e-88)
t_0
(if (<= d 4.3e-159)
(/ (- b (* a (/ d c))) c)
(if (<= d 5e+123) t_0 (/ t_1 (hypot c d))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = (c * (b / d)) - a;
double tmp;
if (d <= -3.1e+45) {
tmp = t_1 / d;
} else if (d <= -6.5e-88) {
tmp = t_0;
} else if (d <= 4.3e-159) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 5e+123) {
tmp = t_0;
} else {
tmp = t_1 / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = (c * (b / d)) - a;
double tmp;
if (d <= -3.1e+45) {
tmp = t_1 / d;
} else if (d <= -6.5e-88) {
tmp = t_0;
} else if (d <= 4.3e-159) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 5e+123) {
tmp = t_0;
} else {
tmp = t_1 / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) t_1 = (c * (b / d)) - a tmp = 0 if d <= -3.1e+45: tmp = t_1 / d elif d <= -6.5e-88: tmp = t_0 elif d <= 4.3e-159: tmp = (b - (a * (d / c))) / c elif d <= 5e+123: tmp = t_0 else: tmp = t_1 / math.hypot(c, d) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(c * Float64(b / d)) - a) tmp = 0.0 if (d <= -3.1e+45) tmp = Float64(t_1 / d); elseif (d <= -6.5e-88) tmp = t_0; elseif (d <= 4.3e-159) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 5e+123) tmp = t_0; else tmp = Float64(t_1 / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); t_1 = (c * (b / d)) - a; tmp = 0.0; if (d <= -3.1e+45) tmp = t_1 / d; elseif (d <= -6.5e-88) tmp = t_0; elseif (d <= 4.3e-159) tmp = (b - (a * (d / c))) / c; elseif (d <= 5e+123) tmp = t_0; else tmp = t_1 / hypot(c, d); 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[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]}, If[LessEqual[d, -3.1e+45], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -6.5e-88], t$95$0, If[LessEqual[d, 4.3e-159], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5e+123], t$95$0, N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := c \cdot \frac{b}{d} - a\\
\mathbf{if}\;d \leq -3.1 \cdot 10^{+45}:\\
\;\;\;\;\frac{t\_1}{d}\\
\mathbf{elif}\;d \leq -6.5 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.3 \cdot 10^{-159}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 5 \cdot 10^{+123}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -3.09999999999999988e45Initial program 50.9%
Taylor expanded in c around 0 76.7%
+-commutative76.7%
mul-1-neg76.7%
unsub-neg76.7%
unpow276.7%
associate-/r*78.4%
div-sub78.4%
*-commutative78.4%
associate-/l*80.3%
Simplified80.3%
if -3.09999999999999988e45 < d < -6.50000000000000006e-88 or 4.3e-159 < d < 4.99999999999999974e123Initial program 87.5%
if -6.50000000000000006e-88 < d < 4.3e-159Initial program 76.3%
*-un-lft-identity76.3%
add-sqr-sqrt76.3%
times-frac76.2%
hypot-define76.2%
hypot-define85.4%
Applied egg-rr85.4%
Taylor expanded in c around inf 93.9%
mul-1-neg93.9%
sub-neg93.9%
associate-/l*93.9%
Simplified93.9%
if 4.99999999999999974e123 < d Initial program 37.3%
*-un-lft-identity37.3%
add-sqr-sqrt37.3%
times-frac37.3%
hypot-define37.3%
hypot-define63.2%
Applied egg-rr63.2%
associate-*l/63.4%
*-un-lft-identity63.4%
*-commutative63.4%
*-commutative63.4%
Applied egg-rr63.4%
Taylor expanded in c around 0 79.8%
+-commutative79.8%
neg-mul-179.8%
sub-neg79.8%
*-commutative79.8%
associate-*r/88.1%
Simplified88.1%
Final simplification87.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.5e+44)
t_1
(if (<= d -3.5e-86)
t_0
(if (<= d 1.75e-158)
(/ (- b (* a (/ d c))) c)
(if (<= d 6.5e+122) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.5e+44) {
tmp = t_1;
} else if (d <= -3.5e-86) {
tmp = t_0;
} else if (d <= 1.75e-158) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 6.5e+122) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
t_1 = ((c * (b / d)) - a) / d
if (d <= (-1.5d+44)) then
tmp = t_1
else if (d <= (-3.5d-86)) then
tmp = t_0
else if (d <= 1.75d-158) then
tmp = (b - (a * (d / c))) / c
else if (d <= 6.5d+122) then
tmp = t_0
else
tmp = t_1
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) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.5e+44) {
tmp = t_1;
} else if (d <= -3.5e-86) {
tmp = t_0;
} else if (d <= 1.75e-158) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 6.5e+122) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) t_1 = ((c * (b / d)) - a) / d tmp = 0 if d <= -1.5e+44: tmp = t_1 elif d <= -3.5e-86: tmp = t_0 elif d <= 1.75e-158: tmp = (b - (a * (d / c))) / c elif d <= 6.5e+122: 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(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -1.5e+44) tmp = t_1; elseif (d <= -3.5e-86) tmp = t_0; elseif (d <= 1.75e-158) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 6.5e+122) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); t_1 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -1.5e+44) tmp = t_1; elseif (d <= -3.5e-86) tmp = t_0; elseif (d <= 1.75e-158) tmp = (b - (a * (d / c))) / c; elseif (d <= 6.5e+122) tmp = t_0; else tmp = t_1; 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[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.5e+44], t$95$1, If[LessEqual[d, -3.5e-86], t$95$0, If[LessEqual[d, 1.75e-158], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6.5e+122], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.5 \cdot 10^{+44}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -3.5 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.75 \cdot 10^{-158}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.49999999999999993e44 or 6.49999999999999963e122 < d Initial program 44.8%
Taylor expanded in c around 0 76.2%
+-commutative76.2%
mul-1-neg76.2%
unsub-neg76.2%
unpow276.2%
associate-/r*78.1%
div-sub78.1%
*-commutative78.1%
associate-/l*83.7%
Simplified83.7%
if -1.49999999999999993e44 < d < -3.50000000000000021e-86 or 1.75000000000000006e-158 < d < 6.49999999999999963e122Initial program 87.5%
if -3.50000000000000021e-86 < d < 1.75000000000000006e-158Initial program 76.3%
*-un-lft-identity76.3%
add-sqr-sqrt76.3%
times-frac76.2%
hypot-define76.2%
hypot-define85.4%
Applied egg-rr85.4%
Taylor expanded in c around inf 93.9%
mul-1-neg93.9%
sub-neg93.9%
associate-/l*93.9%
Simplified93.9%
Final simplification87.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.0021) (not (<= d 1.4e-24))) (/ (- (* c (/ b d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.0021) || !(d <= 1.4e-24)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (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) :: tmp
if ((d <= (-0.0021d0)) .or. (.not. (d <= 1.4d-24))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.0021) || !(d <= 1.4e-24)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.0021) or not (d <= 1.4e-24): tmp = ((c * (b / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.0021) || !(d <= 1.4e-24)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.0021) || ~((d <= 1.4e-24))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.0021], N[Not[LessEqual[d, 1.4e-24]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0021 \lor \neg \left(d \leq 1.4 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.00209999999999999987 or 1.4000000000000001e-24 < d Initial program 54.7%
Taylor expanded in c around 0 73.6%
+-commutative73.6%
mul-1-neg73.6%
unsub-neg73.6%
unpow273.6%
associate-/r*75.0%
div-sub75.0%
*-commutative75.0%
associate-/l*79.2%
Simplified79.2%
if -0.00209999999999999987 < d < 1.4000000000000001e-24Initial program 81.4%
*-un-lft-identity81.4%
add-sqr-sqrt81.4%
times-frac81.3%
hypot-define81.3%
hypot-define87.5%
Applied egg-rr87.5%
Taylor expanded in c around inf 84.3%
mul-1-neg84.3%
sub-neg84.3%
associate-/l*84.3%
Simplified84.3%
Final simplification81.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.95e-14) (not (<= d 1.26e-23))) (/ (- (* b (/ c d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.95e-14) || !(d <= 1.26e-23)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (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) :: tmp
if ((d <= (-1.95d-14)) .or. (.not. (d <= 1.26d-23))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.95e-14) || !(d <= 1.26e-23)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.95e-14) or not (d <= 1.26e-23): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.95e-14) || !(d <= 1.26e-23)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.95e-14) || ~((d <= 1.26e-23))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.95e-14], N[Not[LessEqual[d, 1.26e-23]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{-14} \lor \neg \left(d \leq 1.26 \cdot 10^{-23}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.9499999999999999e-14 or 1.25999999999999996e-23 < d Initial program 55.3%
*-un-lft-identity55.3%
add-sqr-sqrt55.4%
times-frac55.4%
hypot-define55.4%
hypot-define70.9%
Applied egg-rr70.9%
Taylor expanded in d around inf 74.7%
neg-mul-174.7%
+-commutative74.7%
sub-neg74.7%
associate-/l*76.9%
Simplified76.9%
if -1.9499999999999999e-14 < d < 1.25999999999999996e-23Initial program 81.0%
*-un-lft-identity81.0%
add-sqr-sqrt81.0%
times-frac80.9%
hypot-define81.0%
hypot-define87.3%
Applied egg-rr87.3%
Taylor expanded in c around inf 84.8%
mul-1-neg84.8%
sub-neg84.8%
associate-/l*84.8%
Simplified84.8%
Final simplification80.3%
(FPCore (a b c d) :precision binary64 (if (<= d 7.8e-283) (- (/ b d) (/ a c)) (- (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 7.8e-283) {
tmp = (b / d) - (a / c);
} else {
tmp = (a / c) - (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 <= 7.8d-283) then
tmp = (b / d) - (a / c)
else
tmp = (a / c) - (b / d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= 7.8e-283) {
tmp = (b / d) - (a / c);
} else {
tmp = (a / c) - (b / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 7.8e-283: tmp = (b / d) - (a / c) else: tmp = (a / c) - (b / d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 7.8e-283) tmp = Float64(Float64(b / d) - Float64(a / c)); else tmp = Float64(Float64(a / c) - Float64(b / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 7.8e-283) tmp = (b / d) - (a / c); else tmp = (a / c) - (b / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 7.8e-283], N[(N[(b / d), $MachinePrecision] - N[(a / c), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] - N[(b / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 7.8 \cdot 10^{-283}:\\
\;\;\;\;\frac{b}{d} - \frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} - \frac{b}{d}\\
\end{array}
\end{array}
if d < 7.8000000000000004e-283Initial program 66.7%
*-un-lft-identity66.7%
add-sqr-sqrt66.7%
times-frac66.7%
hypot-define66.7%
hypot-define77.1%
Applied egg-rr77.1%
Taylor expanded in c around -inf 31.2%
+-commutative31.2%
neg-mul-131.2%
sub-neg31.2%
associate-/l*33.4%
Simplified33.4%
Taylor expanded in d around -inf 8.8%
+-commutative8.8%
mul-1-neg8.8%
sub-neg8.8%
Simplified8.8%
if 7.8000000000000004e-283 < d Initial program 66.2%
*-un-lft-identity66.2%
add-sqr-sqrt66.2%
times-frac66.2%
hypot-define66.2%
hypot-define78.9%
Applied egg-rr78.9%
Taylor expanded in c around -inf 33.6%
+-commutative33.6%
neg-mul-133.6%
sub-neg33.6%
associate-/l*34.5%
Simplified34.5%
Taylor expanded in d around inf 10.3%
+-commutative10.3%
neg-mul-110.3%
sub-neg10.3%
Simplified10.3%
(FPCore (a b c d) :precision binary64 (/ (- b (* a (/ d c))) c))
double code(double a, double b, double c, double d) {
return (b - (a * (d / c))) / 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 - (a * (d / c))) / c
end function
public static double code(double a, double b, double c, double d) {
return (b - (a * (d / c))) / c;
}
def code(a, b, c, d): return (b - (a * (d / c))) / c
function code(a, b, c, d) return Float64(Float64(b - Float64(a * Float64(d / c))) / c) end
function tmp = code(a, b, c, d) tmp = (b - (a * (d / c))) / c; end
code[a_, b_, c_, d_] := N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b - a \cdot \frac{d}{c}}{c}
\end{array}
Initial program 66.5%
*-un-lft-identity66.5%
add-sqr-sqrt66.5%
times-frac66.5%
hypot-define66.5%
hypot-define78.0%
Applied egg-rr78.0%
Taylor expanded in c around inf 48.3%
mul-1-neg48.3%
sub-neg48.3%
associate-/l*51.0%
Simplified51.0%
(FPCore (a b c d) :precision binary64 (- (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
return (a / c) - (b / 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)
end function
public static double code(double a, double b, double c, double d) {
return (a / c) - (b / d);
}
def code(a, b, c, d): return (a / c) - (b / d)
function code(a, b, c, d) return Float64(Float64(a / c) - Float64(b / d)) end
function tmp = code(a, b, c, d) tmp = (a / c) - (b / d); end
code[a_, b_, c_, d_] := N[(N[(a / c), $MachinePrecision] - N[(b / d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c} - \frac{b}{d}
\end{array}
Initial program 66.5%
*-un-lft-identity66.5%
add-sqr-sqrt66.5%
times-frac66.5%
hypot-define66.5%
hypot-define78.0%
Applied egg-rr78.0%
Taylor expanded in c around -inf 32.4%
+-commutative32.4%
neg-mul-132.4%
sub-neg32.4%
associate-/l*33.9%
Simplified33.9%
Taylor expanded in d around inf 7.5%
+-commutative7.5%
neg-mul-17.5%
sub-neg7.5%
Simplified7.5%
(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 2024179
(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))))