
(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 11 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 d d (* c c)))
(t_1 (fma (- a) (/ d t_0) (* b (/ c t_0))))
(t_2 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -4.2e+153)
t_2
(if (<= d -2.1e-141)
t_1
(if (<= d 2.7e-138)
(/ (+ b (* (/ d c) (/ 1.0 (/ -1.0 a)))) c)
(if (<= d 4.5e+104) t_1 t_2))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma(-a, (d / t_0), (b * (c / t_0)));
double t_2 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -4.2e+153) {
tmp = t_2;
} else if (d <= -2.1e-141) {
tmp = t_1;
} else if (d <= 2.7e-138) {
tmp = (b + ((d / c) * (1.0 / (-1.0 / a)))) / c;
} else if (d <= 4.5e+104) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(Float64(-a), Float64(d / t_0), Float64(b * Float64(c / t_0))) t_2 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -4.2e+153) tmp = t_2; elseif (d <= -2.1e-141) tmp = t_1; elseif (d <= 2.7e-138) tmp = Float64(Float64(b + Float64(Float64(d / c) * Float64(1.0 / Float64(-1.0 / a)))) / c); elseif (d <= 4.5e+104) tmp = t_1; else tmp = t_2; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-a) * N[(d / t$95$0), $MachinePrecision] + N[(b * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -4.2e+153], t$95$2, If[LessEqual[d, -2.1e-141], t$95$1, If[LessEqual[d, 2.7e-138], N[(N[(b + N[(N[(d / c), $MachinePrecision] * N[(1.0 / N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.5e+104], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(-a, \frac{d}{t\_0}, b \cdot \frac{c}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -4.2 \cdot 10^{+153}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq -2.1 \cdot 10^{-141}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{-138}:\\
\;\;\;\;\frac{b + \frac{d}{c} \cdot \frac{1}{\frac{-1}{a}}}{c}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+104}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if d < -4.20000000000000033e153 or 4.4999999999999998e104 < d Initial program 35.4%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6486.0
Applied rewrites86.0%
if -4.20000000000000033e153 < d < -2.0999999999999999e-141 or 2.70000000000000029e-138 < d < 4.4999999999999998e104Initial program 78.4%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-/.f6484.2
Applied rewrites84.2%
lift-/.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6487.7
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-fma.f6487.7
Applied rewrites87.7%
if -2.0999999999999999e-141 < d < 2.70000000000000029e-138Initial program 71.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6492.9
Applied rewrites92.9%
Applied rewrites92.7%
Applied rewrites94.0%
Final simplification89.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma c c (* d d))) (t_1 (/ (- b (* d (/ a c))) c)))
(if (<= c -6.2e+59)
t_1
(if (<= c -3.55e-103)
(/ (fma c b (* d (- a))) t_0)
(if (<= c 5e-161)
(/ (- (/ (* b c) d) a) d)
(if (<= c 7.5e+106) (/ (- (* b c) (* d a)) t_0) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, c, (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6.2e+59) {
tmp = t_1;
} else if (c <= -3.55e-103) {
tmp = fma(c, b, (d * -a)) / t_0;
} else if (c <= 5e-161) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 7.5e+106) {
tmp = ((b * c) - (d * a)) / t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(c, c, Float64(d * d)) t_1 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -6.2e+59) tmp = t_1; elseif (c <= -3.55e-103) tmp = Float64(fma(c, b, Float64(d * Float64(-a))) / t_0); elseif (c <= 5e-161) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 7.5e+106) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / t_0); else tmp = t_1; 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[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e+59], t$95$1, If[LessEqual[c, -3.55e-103], N[(N[(c * b + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[c, 5e-161], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7.5e+106], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, c, d \cdot d\right)\\
t_1 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{+59}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -3.55 \cdot 10^{-103}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, b, d \cdot \left(-a\right)\right)}{t\_0}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{-161}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{+106}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -6.20000000000000029e59 or 7.50000000000000058e106 < c Initial program 38.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6474.0
Applied rewrites74.0%
Applied rewrites82.1%
if -6.20000000000000029e59 < c < -3.55000000000000023e-103Initial program 84.0%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6484.0
Applied rewrites84.0%
lift--.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-neg.f6484.1
Applied rewrites84.1%
if -3.55000000000000023e-103 < c < 4.9999999999999999e-161Initial program 74.5%
Taylor expanded in c around inf
lower-/.f6418.1
Applied rewrites18.1%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6494.9
Applied rewrites94.9%
if 4.9999999999999999e-161 < c < 7.50000000000000058e106Initial program 86.3%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6486.3
Applied rewrites86.3%
Final simplification86.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* d a)) (fma c c (* d d))))
(t_1 (/ (- b (* d (/ a c))) c)))
(if (<= c -6.2e+59)
t_1
(if (<= c -3.55e-103)
t_0
(if (<= c 5e-161)
(/ (- (/ (* b c) d) a) d)
(if (<= c 7.5e+106) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / fma(c, c, (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6.2e+59) {
tmp = t_1;
} else if (c <= -3.55e-103) {
tmp = t_0;
} else if (c <= 5e-161) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 7.5e+106) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(d * a)) / fma(c, c, Float64(d * d))) t_1 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -6.2e+59) tmp = t_1; elseif (c <= -3.55e-103) tmp = t_0; elseif (c <= 5e-161) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 7.5e+106) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e+59], t$95$1, If[LessEqual[c, -3.55e-103], t$95$0, If[LessEqual[c, 5e-161], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7.5e+106], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
t_1 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{+59}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -3.55 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 5 \cdot 10^{-161}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{+106}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -6.20000000000000029e59 or 7.50000000000000058e106 < c Initial program 38.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6474.0
Applied rewrites74.0%
Applied rewrites82.1%
if -6.20000000000000029e59 < c < -3.55000000000000023e-103 or 4.9999999999999999e-161 < c < 7.50000000000000058e106Initial program 85.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6485.4
Applied rewrites85.4%
if -3.55000000000000023e-103 < c < 4.9999999999999999e-161Initial program 74.5%
Taylor expanded in c around inf
lower-/.f6418.1
Applied rewrites18.1%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6494.9
Applied rewrites94.9%
Final simplification86.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* d a))))
(if (<= c -1.32e+154)
(/ b c)
(if (<= c -3.1e-86)
(* b (/ c (fma c c (* d d))))
(if (<= c 1.55e-108)
(/ t_0 (* d d))
(if (<= c 6e+116) (/ t_0 (* c c)) (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (d * a);
double tmp;
if (c <= -1.32e+154) {
tmp = b / c;
} else if (c <= -3.1e-86) {
tmp = b * (c / fma(c, c, (d * d)));
} else if (c <= 1.55e-108) {
tmp = t_0 / (d * d);
} else if (c <= 6e+116) {
tmp = t_0 / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(d * a)) tmp = 0.0 if (c <= -1.32e+154) tmp = Float64(b / c); elseif (c <= -3.1e-86) tmp = Float64(b * Float64(c / fma(c, c, Float64(d * d)))); elseif (c <= 1.55e-108) tmp = Float64(t_0 / Float64(d * d)); elseif (c <= 6e+116) tmp = Float64(t_0 / Float64(c * c)); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.32e+154], N[(b / c), $MachinePrecision], If[LessEqual[c, -3.1e-86], N[(b * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.55e-108], N[(t$95$0 / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6e+116], N[(t$95$0 / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - d \cdot a\\
\mathbf{if}\;c \leq -1.32 \cdot 10^{+154}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -3.1 \cdot 10^{-86}:\\
\;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 1.55 \cdot 10^{-108}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\
\mathbf{elif}\;c \leq 6 \cdot 10^{+116}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.31999999999999998e154 or 5.9999999999999997e116 < c Initial program 26.4%
Taylor expanded in c around inf
lower-/.f6472.7
Applied rewrites72.7%
if -1.31999999999999998e154 < c < -3.09999999999999989e-86Initial program 75.3%
Taylor expanded in c around inf
lower-/.f6444.9
Applied rewrites44.9%
Taylor expanded in b around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.5
Applied rewrites59.5%
if -3.09999999999999989e-86 < c < 1.55000000000000007e-108Initial program 76.6%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6472.0
Applied rewrites72.0%
if 1.55000000000000007e-108 < c < 5.9999999999999997e116Initial program 84.5%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6459.0
Applied rewrites59.0%
Final simplification66.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma c c (* d d))) (t_1 (/ a (- d))))
(if (<= d -4.8e+153)
t_1
(if (<= d -6.6e-123)
(* a (/ (- d) t_0))
(if (<= d 1.2e-142)
(/ b c)
(if (<= d 2.25e+23) (* b (/ c t_0)) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, c, (d * d));
double t_1 = a / -d;
double tmp;
if (d <= -4.8e+153) {
tmp = t_1;
} else if (d <= -6.6e-123) {
tmp = a * (-d / t_0);
} else if (d <= 1.2e-142) {
tmp = b / c;
} else if (d <= 2.25e+23) {
tmp = b * (c / t_0);
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(c, c, Float64(d * d)) t_1 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -4.8e+153) tmp = t_1; elseif (d <= -6.6e-123) tmp = Float64(a * Float64(Float64(-d) / t_0)); elseif (d <= 1.2e-142) tmp = Float64(b / c); elseif (d <= 2.25e+23) tmp = Float64(b * Float64(c / t_0)); else tmp = t_1; 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 / (-d)), $MachinePrecision]}, If[LessEqual[d, -4.8e+153], t$95$1, If[LessEqual[d, -6.6e-123], N[(a * N[((-d) / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.2e-142], N[(b / c), $MachinePrecision], If[LessEqual[d, 2.25e+23], N[(b * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, c, d \cdot d\right)\\
t_1 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{+153}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -6.6 \cdot 10^{-123}:\\
\;\;\;\;a \cdot \frac{-d}{t\_0}\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-142}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 2.25 \cdot 10^{+23}:\\
\;\;\;\;b \cdot \frac{c}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.79999999999999985e153 or 2.2499999999999999e23 < d Initial program 45.1%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6472.4
Applied rewrites72.4%
if -4.79999999999999985e153 < d < -6.6000000000000005e-123Initial program 75.2%
Taylor expanded in c around inf
lower-/.f6429.7
Applied rewrites29.7%
Taylor expanded in b around 0
mul-1-negN/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6457.0
Applied rewrites57.0%
if -6.6000000000000005e-123 < d < 1.19999999999999994e-142Initial program 71.0%
Taylor expanded in c around inf
lower-/.f6475.5
Applied rewrites75.5%
if 1.19999999999999994e-142 < d < 2.2499999999999999e23Initial program 81.6%
Taylor expanded in c around inf
lower-/.f6434.7
Applied rewrites34.7%
Taylor expanded in b around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6451.9
Applied rewrites51.9%
Final simplification66.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -4.8e+153)
t_0
(if (<= d -1.2e-41)
(* a (/ (- d) (fma c c (* d d))))
(if (<= d 14200000000000.0) (/ (- 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 <= -4.8e+153) {
tmp = t_0;
} else if (d <= -1.2e-41) {
tmp = a * (-d / fma(c, c, (d * d)));
} else if (d <= 14200000000000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -4.8e+153) tmp = t_0; elseif (d <= -1.2e-41) tmp = Float64(a * Float64(Float64(-d) / fma(c, c, Float64(d * d)))); elseif (d <= 14200000000000.0) 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, -4.8e+153], t$95$0, If[LessEqual[d, -1.2e-41], N[(a * N[((-d) / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 14200000000000.0], 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 -4.8 \cdot 10^{+153}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.2 \cdot 10^{-41}:\\
\;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 14200000000000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.79999999999999985e153 or 1.42e13 < d Initial program 46.5%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.8
Applied rewrites71.8%
if -4.79999999999999985e153 < d < -1.20000000000000011e-41Initial program 76.2%
Taylor expanded in c around inf
lower-/.f6423.1
Applied rewrites23.1%
Taylor expanded in b around 0
mul-1-negN/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6460.9
Applied rewrites60.9%
if -1.20000000000000011e-41 < d < 1.42e13Initial program 73.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6478.4
Applied rewrites78.4%
Final simplification73.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -4.8e+153)
t_0
(if (<= d -2.2e-28)
(* a (/ (- d) (fma c c (* d d))))
(if (<= d 14200000000000.0) (/ (- 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 <= -4.8e+153) {
tmp = t_0;
} else if (d <= -2.2e-28) {
tmp = a * (-d / fma(c, c, (d * d)));
} else if (d <= 14200000000000.0) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -4.8e+153) tmp = t_0; elseif (d <= -2.2e-28) tmp = Float64(a * Float64(Float64(-d) / fma(c, c, Float64(d * d)))); elseif (d <= 14200000000000.0) tmp = Float64(Float64(b - Float64(d * Float64(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, -4.8e+153], t$95$0, If[LessEqual[d, -2.2e-28], N[(a * N[((-d) / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 14200000000000.0], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{+153}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.2 \cdot 10^{-28}:\\
\;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;d \leq 14200000000000:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.79999999999999985e153 or 1.42e13 < d Initial program 46.5%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.8
Applied rewrites71.8%
if -4.79999999999999985e153 < d < -2.19999999999999996e-28Initial program 75.2%
Taylor expanded in c around inf
lower-/.f6424.0
Applied rewrites24.0%
Taylor expanded in b around 0
mul-1-negN/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6461.3
Applied rewrites61.3%
if -2.19999999999999996e-28 < d < 1.42e13Initial program 74.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6478.0
Applied rewrites78.0%
Applied rewrites77.2%
Final simplification72.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -2.1e-6)
t_0
(if (<= d 1.2e-142)
(/ b c)
(if (<= d 2.25e+23) (* b (/ c (fma c c (* d d)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -2.1e-6) {
tmp = t_0;
} else if (d <= 1.2e-142) {
tmp = b / c;
} else if (d <= 2.25e+23) {
tmp = b * (c / fma(c, c, (d * d)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -2.1e-6) tmp = t_0; elseif (d <= 1.2e-142) tmp = Float64(b / c); elseif (d <= 2.25e+23) tmp = Float64(b * Float64(c / fma(c, c, Float64(d * d)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -2.1e-6], t$95$0, If[LessEqual[d, 1.2e-142], N[(b / c), $MachinePrecision], If[LessEqual[d, 2.25e+23], N[(b * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -2.1 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-142}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 2.25 \cdot 10^{+23}:\\
\;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.0999999999999998e-6 or 2.2499999999999999e23 < d Initial program 55.1%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6463.1
Applied rewrites63.1%
if -2.0999999999999998e-6 < d < 1.19999999999999994e-142Initial program 72.4%
Taylor expanded in c around inf
lower-/.f6468.2
Applied rewrites68.2%
if 1.19999999999999994e-142 < d < 2.2499999999999999e23Initial program 81.6%
Taylor expanded in c around inf
lower-/.f6434.7
Applied rewrites34.7%
Taylor expanded in b around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6451.9
Applied rewrites51.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* d (/ a c))) c)))
(if (<= c -6.7e+24)
t_0
(if (<= c 1.45e-30) (/ (- (/ (* b c) d) a) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6.7e+24) {
tmp = t_0;
} else if (c <= 1.45e-30) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b - (d * (a / c))) / c
if (c <= (-6.7d+24)) then
tmp = t_0
else if (c <= 1.45d-30) then
tmp = (((b * c) / d) - a) / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6.7e+24) {
tmp = t_0;
} else if (c <= 1.45e-30) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - (d * (a / c))) / c tmp = 0 if c <= -6.7e+24: tmp = t_0 elif c <= 1.45e-30: tmp = (((b * c) / d) - a) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -6.7e+24) tmp = t_0; elseif (c <= 1.45e-30) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b - (d * (a / c))) / c; tmp = 0.0; if (c <= -6.7e+24) tmp = t_0; elseif (c <= 1.45e-30) tmp = (((b * c) / d) - a) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.7e+24], t$95$0, If[LessEqual[c, 1.45e-30], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -6.7 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.45 \cdot 10^{-30}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6.6999999999999999e24 or 1.44999999999999995e-30 < c Initial program 52.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6470.7
Applied rewrites70.7%
Applied rewrites76.4%
if -6.6999999999999999e24 < c < 1.44999999999999995e-30Initial program 79.6%
Taylor expanded in c around inf
lower-/.f6420.3
Applied rewrites20.3%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.5
Applied rewrites79.5%
Final simplification77.9%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ a (- d)))) (if (<= d -2.1e-6) t_0 (if (<= d 14200000000000.0) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -2.1e-6) {
tmp = t_0;
} else if (d <= 14200000000000.0) {
tmp = b / 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 = a / -d
if (d <= (-2.1d-6)) then
tmp = t_0
else if (d <= 14200000000000.0d0) then
tmp = b / 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 = a / -d;
double tmp;
if (d <= -2.1e-6) {
tmp = t_0;
} else if (d <= 14200000000000.0) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = a / -d tmp = 0 if d <= -2.1e-6: tmp = t_0 elif d <= 14200000000000.0: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(a / Float64(-d)) tmp = 0.0 if (d <= -2.1e-6) tmp = t_0; elseif (d <= 14200000000000.0) tmp = Float64(b / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = a / -d; tmp = 0.0; if (d <= -2.1e-6) tmp = t_0; elseif (d <= 14200000000000.0) tmp = b / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -2.1e-6], t$95$0, If[LessEqual[d, 14200000000000.0], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -2.1 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 14200000000000:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.0999999999999998e-6 or 1.42e13 < d Initial program 55.9%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6462.9
Applied rewrites62.9%
if -2.0999999999999998e-6 < d < 1.42e13Initial program 74.6%
Taylor expanded in c around inf
lower-/.f6459.8
Applied rewrites59.8%
(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 65.6%
Taylor expanded in c around inf
lower-/.f6440.6
Applied rewrites40.6%
(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 2024221
(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))))