
(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
(let* ((t_0 (- (* b c) (* a d))) (t_1 (/ t_0 (+ (* c c) (* d d)))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e+281)))
(fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (- a) d))
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double t_1 = t_0 / ((c * c) + (d * d));
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 1e+281)) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / d));
} else {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(a * d)) t_1 = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 1e+281)) tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d)); else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 1e+281]], $MachinePrecision]], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+281}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0 or 1e281 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 17.4%
div-sub7.3%
*-commutative7.3%
add-sqr-sqrt7.3%
times-frac15.9%
fma-neg15.9%
hypot-def15.9%
hypot-def45.1%
associate-/l*56.7%
add-sqr-sqrt56.7%
pow256.7%
hypot-def56.7%
Applied egg-rr56.7%
Taylor expanded in c around 0 80.0%
if -inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1e281Initial program 83.7%
*-un-lft-identity83.7%
add-sqr-sqrt83.7%
times-frac83.7%
hypot-def83.7%
hypot-def98.1%
Applied egg-rr98.1%
Final simplification93.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 1e+281)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(* (/ 1.0 d) (- (/ c (/ d b)) a)))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 1e+281) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = (1.0 / d) * ((c / (d / b)) - a);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 1e+281) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = (1.0 / d) * ((c / (d / b)) - a);
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (a * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 1e+281: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = (1.0 / d) * ((c / (d / b)) - a) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 1e+281) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(1.0 / d) * Float64(Float64(c / Float64(d / b)) - a)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) - (a * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 1e+281) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = (1.0 / d) * ((c / (d / b)) - a); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+281], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
\mathbf{if}\;\frac{t_0}{c \cdot c + d \cdot d} \leq 10^{+281}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1e281Initial program 80.0%
*-un-lft-identity80.0%
add-sqr-sqrt80.0%
times-frac80.0%
hypot-def80.0%
hypot-def95.9%
Applied egg-rr95.9%
if 1e281 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.6%
Taylor expanded in c around 0 17.4%
unpow217.4%
Simplified17.4%
clear-num17.4%
inv-pow17.4%
*-commutative17.4%
*-commutative17.4%
Applied egg-rr17.4%
unpow-117.4%
associate-/l*22.2%
associate-/r/22.2%
*-commutative22.2%
div-sub22.2%
associate-/l*26.3%
associate-/l*60.3%
*-inverses60.3%
Simplified60.3%
Final simplification88.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* c c) (* d d))))
(if (<= c -5.5e+42)
(- (/ b c) (* (/ a c) (/ d c)))
(if (<= c -6.5e-97)
(/ (- (* b c) (* a d)) t_0)
(if (<= c 8.5e-137)
(* (/ 1.0 d) (- (/ c (/ d b)) a))
(if (<= c 1.5e+66)
(/ (fma (- d) a (* b c)) t_0)
(/ (- b (* d (/ a c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * c) + (d * d);
double tmp;
if (c <= -5.5e+42) {
tmp = (b / c) - ((a / c) * (d / c));
} else if (c <= -6.5e-97) {
tmp = ((b * c) - (a * d)) / t_0;
} else if (c <= 8.5e-137) {
tmp = (1.0 / d) * ((c / (d / b)) - a);
} else if (c <= 1.5e+66) {
tmp = fma(-d, a, (b * c)) / t_0;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * c) + Float64(d * d)) tmp = 0.0 if (c <= -5.5e+42) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); elseif (c <= -6.5e-97) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / t_0); elseif (c <= 8.5e-137) tmp = Float64(Float64(1.0 / d) * Float64(Float64(c / Float64(d / b)) - a)); elseif (c <= 1.5e+66) tmp = Float64(fma(Float64(-d), a, Float64(b * c)) / t_0); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.5e+42], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -6.5e-97], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[c, 8.5e-137], N[(N[(1.0 / d), $MachinePrecision] * N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.5e+66], N[(N[((-d) * a + N[(b * c), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot c + d \cdot d\\
\mathbf{if}\;c \leq -5.5 \cdot 10^{+42}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;c \leq -6.5 \cdot 10^{-97}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{t_0}\\
\mathbf{elif}\;c \leq 8.5 \cdot 10^{-137}:\\
\;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+66}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-d, a, b \cdot c\right)}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -5.50000000000000001e42Initial program 59.6%
Taylor expanded in c around inf 90.3%
+-commutative90.3%
mul-1-neg90.3%
unsub-neg90.3%
unpow290.3%
times-frac88.6%
Simplified88.6%
if -5.50000000000000001e42 < c < -6.5000000000000004e-97Initial program 79.3%
if -6.5000000000000004e-97 < c < 8.5000000000000001e-137Initial program 67.9%
Taylor expanded in c around 0 65.8%
unpow265.8%
Simplified65.8%
clear-num65.8%
inv-pow65.8%
*-commutative65.8%
*-commutative65.8%
Applied egg-rr65.8%
unpow-165.8%
associate-/l*79.2%
associate-/r/79.4%
*-commutative79.4%
div-sub79.4%
associate-/l*79.3%
associate-/l*92.7%
*-inverses92.7%
Simplified92.7%
if 8.5000000000000001e-137 < c < 1.50000000000000001e66Initial program 89.6%
sub-neg89.6%
+-commutative89.6%
*-commutative89.6%
distribute-lft-neg-in89.6%
fma-def89.7%
Applied egg-rr89.7%
if 1.50000000000000001e66 < c Initial program 52.1%
Taylor expanded in c around inf 81.5%
+-commutative81.5%
mul-1-neg81.5%
unsub-neg81.5%
unpow281.5%
times-frac82.0%
Simplified82.0%
associate-*r/85.5%
sub-div85.5%
Applied egg-rr85.5%
Final simplification88.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
(if (<= c -4.8e+42)
(- (/ b c) (* (/ a c) (/ d c)))
(if (<= c -2.8e-98)
t_0
(if (<= c 1.05e-136)
(* (/ 1.0 d) (- (/ c (/ d b)) a))
(if (<= c 5.8e+69) t_0 (/ (- b (* d (/ a c))) 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 <= -4.8e+42) {
tmp = (b / c) - ((a / c) * (d / c));
} else if (c <= -2.8e-98) {
tmp = t_0;
} else if (c <= 1.05e-136) {
tmp = (1.0 / d) * ((c / (d / b)) - a);
} else if (c <= 5.8e+69) {
tmp = t_0;
} else {
tmp = (b - (d * (a / 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) - (a * d)) / ((c * c) + (d * d))
if (c <= (-4.8d+42)) then
tmp = (b / c) - ((a / c) * (d / c))
else if (c <= (-2.8d-98)) then
tmp = t_0
else if (c <= 1.05d-136) then
tmp = (1.0d0 / d) * ((c / (d / b)) - a)
else if (c <= 5.8d+69) then
tmp = t_0
else
tmp = (b - (d * (a / 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) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -4.8e+42) {
tmp = (b / c) - ((a / c) * (d / c));
} else if (c <= -2.8e-98) {
tmp = t_0;
} else if (c <= 1.05e-136) {
tmp = (1.0 / d) * ((c / (d / b)) - a);
} else if (c <= 5.8e+69) {
tmp = t_0;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -4.8e+42: tmp = (b / c) - ((a / c) * (d / c)) elif c <= -2.8e-98: tmp = t_0 elif c <= 1.05e-136: tmp = (1.0 / d) * ((c / (d / b)) - a) elif c <= 5.8e+69: tmp = t_0 else: tmp = (b - (d * (a / c))) / 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 <= -4.8e+42) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); elseif (c <= -2.8e-98) tmp = t_0; elseif (c <= 1.05e-136) tmp = Float64(Float64(1.0 / d) * Float64(Float64(c / Float64(d / b)) - a)); elseif (c <= 5.8e+69) tmp = t_0; else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / 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 <= -4.8e+42) tmp = (b / c) - ((a / c) * (d / c)); elseif (c <= -2.8e-98) tmp = t_0; elseif (c <= 1.05e-136) tmp = (1.0 / d) * ((c / (d / b)) - a); elseif (c <= 5.8e+69) tmp = t_0; else tmp = (b - (d * (a / c))) / 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, -4.8e+42], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.8e-98], t$95$0, If[LessEqual[c, 1.05e-136], N[(N[(1.0 / d), $MachinePrecision] * N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.8e+69], t$95$0, N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $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 -4.8 \cdot 10^{+42}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;c \leq -2.8 \cdot 10^{-98}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-136}:\\
\;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\
\mathbf{elif}\;c \leq 5.8 \cdot 10^{+69}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -4.7999999999999997e42Initial program 59.6%
Taylor expanded in c around inf 90.3%
+-commutative90.3%
mul-1-neg90.3%
unsub-neg90.3%
unpow290.3%
times-frac88.6%
Simplified88.6%
if -4.7999999999999997e42 < c < -2.7999999999999999e-98 or 1.0499999999999999e-136 < c < 5.7999999999999997e69Initial program 85.7%
if -2.7999999999999999e-98 < c < 1.0499999999999999e-136Initial program 67.9%
Taylor expanded in c around 0 65.8%
unpow265.8%
Simplified65.8%
clear-num65.8%
inv-pow65.8%
*-commutative65.8%
*-commutative65.8%
Applied egg-rr65.8%
unpow-165.8%
associate-/l*79.2%
associate-/r/79.4%
*-commutative79.4%
div-sub79.4%
associate-/l*79.3%
associate-/l*92.7%
*-inverses92.7%
Simplified92.7%
if 5.7999999999999997e69 < c Initial program 52.1%
Taylor expanded in c around inf 81.5%
+-commutative81.5%
mul-1-neg81.5%
unsub-neg81.5%
unpow281.5%
times-frac82.0%
Simplified82.0%
associate-*r/85.5%
sub-div85.5%
Applied egg-rr85.5%
Final simplification88.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -10500.0) (not (<= c 9.7e-26))) (/ (- b (* d (/ a c))) c) (- (* (/ c d) (/ b d)) (/ a d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -10500.0) || !(c <= 9.7e-26)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((c / d) * (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 ((c <= (-10500.0d0)) .or. (.not. (c <= 9.7d-26))) then
tmp = (b - (d * (a / c))) / c
else
tmp = ((c / d) * (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 ((c <= -10500.0) || !(c <= 9.7e-26)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((c / d) * (b / d)) - (a / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -10500.0) or not (c <= 9.7e-26): tmp = (b - (d * (a / c))) / c else: tmp = ((c / d) * (b / d)) - (a / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -10500.0) || !(c <= 9.7e-26)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -10500.0) || ~((c <= 9.7e-26))) tmp = (b - (d * (a / c))) / c; else tmp = ((c / d) * (b / d)) - (a / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -10500.0], N[Not[LessEqual[c, 9.7e-26]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -10500 \lor \neg \left(c \leq 9.7 \cdot 10^{-26}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\end{array}
\end{array}
if c < -10500 or 9.7000000000000001e-26 < c Initial program 61.0%
Taylor expanded in c around inf 81.4%
+-commutative81.4%
mul-1-neg81.4%
unsub-neg81.4%
unpow281.4%
times-frac80.9%
Simplified80.9%
associate-*r/82.4%
sub-div82.4%
Applied egg-rr82.4%
if -10500 < c < 9.7000000000000001e-26Initial program 73.2%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
unpow274.2%
times-frac81.5%
Simplified81.5%
Final simplification81.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6200000000.0) (not (<= c 2.75e-21))) (/ (- b (* d (/ a c))) c) (* (/ 1.0 d) (- (/ c (/ d b)) a))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6200000000.0) || !(c <= 2.75e-21)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (1.0 / d) * ((c / (d / b)) - a);
}
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 <= (-6200000000.0d0)) .or. (.not. (c <= 2.75d-21))) then
tmp = (b - (d * (a / c))) / c
else
tmp = (1.0d0 / d) * ((c / (d / b)) - a)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6200000000.0) || !(c <= 2.75e-21)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (1.0 / d) * ((c / (d / b)) - a);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6200000000.0) or not (c <= 2.75e-21): tmp = (b - (d * (a / c))) / c else: tmp = (1.0 / d) * ((c / (d / b)) - a) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6200000000.0) || !(c <= 2.75e-21)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(1.0 / d) * Float64(Float64(c / Float64(d / b)) - a)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6200000000.0) || ~((c <= 2.75e-21))) tmp = (b - (d * (a / c))) / c; else tmp = (1.0 / d) * ((c / (d / b)) - a); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6200000000.0], N[Not[LessEqual[c, 2.75e-21]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6200000000 \lor \neg \left(c \leq 2.75 \cdot 10^{-21}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\
\end{array}
\end{array}
if c < -6.2e9 or 2.74999999999999989e-21 < c Initial program 61.0%
Taylor expanded in c around inf 81.4%
+-commutative81.4%
mul-1-neg81.4%
unsub-neg81.4%
unpow281.4%
times-frac80.9%
Simplified80.9%
associate-*r/82.4%
sub-div82.4%
Applied egg-rr82.4%
if -6.2e9 < c < 2.74999999999999989e-21Initial program 73.2%
Taylor expanded in c around 0 59.8%
unpow259.8%
Simplified59.8%
clear-num59.7%
inv-pow59.7%
*-commutative59.7%
*-commutative59.7%
Applied egg-rr59.7%
unpow-159.7%
associate-/l*72.6%
associate-/r/72.7%
*-commutative72.7%
div-sub72.7%
associate-/l*72.6%
associate-/l*82.7%
*-inverses82.7%
Simplified82.7%
Final simplification82.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8.5e-14) (not (<= c 3.1e-68))) (/ (- b (* d (/ a c))) c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.5e-14) || !(c <= 3.1e-68)) {
tmp = (b - (d * (a / 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 <= (-8.5d-14)) .or. (.not. (c <= 3.1d-68))) then
tmp = (b - (d * (a / 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 <= -8.5e-14) || !(c <= 3.1e-68)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8.5e-14) or not (c <= 3.1e-68): tmp = (b - (d * (a / c))) / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8.5e-14) || !(c <= 3.1e-68)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -8.5e-14) || ~((c <= 3.1e-68))) tmp = (b - (d * (a / c))) / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.5e-14], N[Not[LessEqual[c, 3.1e-68]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.5 \cdot 10^{-14} \lor \neg \left(c \leq 3.1 \cdot 10^{-68}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -8.50000000000000038e-14 or 3.0999999999999999e-68 < c Initial program 63.7%
Taylor expanded in c around inf 77.4%
+-commutative77.4%
mul-1-neg77.4%
unsub-neg77.4%
unpow277.4%
times-frac77.0%
Simplified77.0%
associate-*r/78.3%
sub-div78.3%
Applied egg-rr78.3%
if -8.50000000000000038e-14 < c < 3.0999999999999999e-68Initial program 71.7%
Taylor expanded in c around 0 70.4%
associate-*r/70.4%
neg-mul-170.4%
Simplified70.4%
Final simplification74.7%
(FPCore (a b c d) :precision binary64 (if (<= c -3e-15) (/ b c) (if (<= c 5.4e-68) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-15) {
tmp = b / c;
} else if (c <= 5.4e-68) {
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 <= (-3d-15)) then
tmp = b / c
else if (c <= 5.4d-68) 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 <= -3e-15) {
tmp = b / c;
} else if (c <= 5.4e-68) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3e-15: tmp = b / c elif c <= 5.4e-68: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-15) tmp = Float64(b / c); elseif (c <= 5.4e-68) 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 <= -3e-15) tmp = b / c; elseif (c <= 5.4e-68) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-15], N[(b / c), $MachinePrecision], If[LessEqual[c, 5.4e-68], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-15}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 5.4 \cdot 10^{-68}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -3e-15 or 5.4000000000000003e-68 < c Initial program 63.7%
Taylor expanded in c around inf 65.8%
if -3e-15 < c < 5.4000000000000003e-68Initial program 71.7%
Taylor expanded in c around 0 70.4%
associate-*r/70.4%
neg-mul-170.4%
Simplified70.4%
Final simplification67.9%
(FPCore (a b c d) :precision binary64 (if (<= d -3.6e+90) (/ a d) (if (<= d 2.6e+191) (/ b c) (/ a d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.6e+90) {
tmp = a / d;
} else if (d <= 2.6e+191) {
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 (d <= (-3.6d+90)) then
tmp = a / d
else if (d <= 2.6d+191) 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 (d <= -3.6e+90) {
tmp = a / d;
} else if (d <= 2.6e+191) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3.6e+90: tmp = a / d elif d <= 2.6e+191: tmp = b / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3.6e+90) tmp = Float64(a / d); elseif (d <= 2.6e+191) tmp = Float64(b / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3.6e+90) tmp = a / d; elseif (d <= 2.6e+191) tmp = b / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.6e+90], N[(a / d), $MachinePrecision], If[LessEqual[d, 2.6e+191], N[(b / c), $MachinePrecision], N[(a / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{+191}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < -3.6e90 or 2.6e191 < d Initial program 46.8%
*-un-lft-identity46.8%
add-sqr-sqrt46.8%
times-frac46.8%
hypot-def46.8%
hypot-def70.1%
Applied egg-rr70.1%
Taylor expanded in c around 0 58.6%
neg-mul-158.6%
unsub-neg58.6%
associate-/l*65.4%
Simplified65.4%
Taylor expanded in d around -inf 42.4%
if -3.6e90 < d < 2.6e191Initial program 73.5%
Taylor expanded in c around inf 50.7%
Final simplification48.8%
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
return a / 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 / d
end function
public static double code(double a, double b, double c, double d) {
return a / d;
}
def code(a, b, c, d): return a / d
function code(a, b, c, d) return Float64(a / d) end
function tmp = code(a, b, c, d) tmp = a / d; end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{d}
\end{array}
Initial program 67.4%
*-un-lft-identity67.4%
add-sqr-sqrt67.4%
times-frac67.4%
hypot-def67.4%
hypot-def81.9%
Applied egg-rr81.9%
Taylor expanded in c around 0 35.4%
neg-mul-135.4%
unsub-neg35.4%
associate-/l*37.0%
Simplified37.0%
Taylor expanded in d around -inf 12.0%
Final simplification12.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 2023178
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(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))))