
(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 (/ c t_0) b (- (/ (* d a) t_0))))
(t_2 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -3.2e+81)
t_2
(if (<= d -4.3e-91)
t_1
(if (<= d 1.85e-82)
(/ (- b (/ (* d a) c)) c)
(if (<= d 7e+39) 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((c / t_0), b, -((d * a) / t_0));
double t_2 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -3.2e+81) {
tmp = t_2;
} else if (d <= -4.3e-91) {
tmp = t_1;
} else if (d <= 1.85e-82) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 7e+39) {
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(c / t_0), b, Float64(-Float64(Float64(d * a) / t_0))) t_2 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -3.2e+81) tmp = t_2; elseif (d <= -4.3e-91) tmp = t_1; elseif (d <= 1.85e-82) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 7e+39) 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[(N[(c / t$95$0), $MachinePrecision] * b + (-N[(N[(d * a), $MachinePrecision] / t$95$0), $MachinePrecision])), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3.2e+81], t$95$2, If[LessEqual[d, -4.3e-91], t$95$1, If[LessEqual[d, 1.85e-82], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7e+39], 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(\frac{c}{t\_0}, b, -\frac{d \cdot a}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -3.2 \cdot 10^{+81}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq -4.3 \cdot 10^{-91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 1.85 \cdot 10^{-82}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+39}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if d < -3.2e81 or 7.0000000000000003e39 < d Initial program 43.2%
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.f6485.8
Applied rewrites85.8%
if -3.2e81 < d < -4.3e-91 or 1.85e-82 < d < 7.0000000000000003e39Initial program 80.0%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
distribute-neg-frac2N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.7%
if -4.3e-91 < d < 1.85e-82Initial program 67.5%
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-*.f6498.1
Applied rewrites98.1%
Final simplification90.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))) (t_1 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -9e+70)
t_1
(if (<= d -1e-85)
(fma (- d) (/ a t_0) (/ (* b c) t_0))
(if (<= d 5800000.0) (/ (- b (/ (* d a) c)) c) t_1)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -9e+70) {
tmp = t_1;
} else if (d <= -1e-85) {
tmp = fma(-d, (a / t_0), ((b * c) / t_0));
} else if (d <= 5800000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -9e+70) tmp = t_1; elseif (d <= -1e-85) tmp = fma(Float64(-d), Float64(a / t_0), Float64(Float64(b * c) / t_0)); elseif (d <= 5800000.0) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_1; 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[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -9e+70], t$95$1, If[LessEqual[d, -1e-85], N[((-d) * N[(a / t$95$0), $MachinePrecision] + N[(N[(b * c), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5800000.0], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -9 \cdot 10^{+70}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-85}:\\
\;\;\;\;\mathsf{fma}\left(-d, \frac{a}{t\_0}, \frac{b \cdot c}{t\_0}\right)\\
\mathbf{elif}\;d \leq 5800000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -8.9999999999999999e70 or 5.8e6 < d Initial program 45.5%
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.f6484.1
Applied rewrites84.1%
if -8.9999999999999999e70 < d < -9.9999999999999998e-86Initial program 82.2%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/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-/.f6482.3
Applied rewrites82.3%
if -9.9999999999999998e-86 < d < 5.8e6Initial program 69.3%
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%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -6.5e+70)
t_0
(if (<= d -1e-85)
(/ (- (* b c) (* d a)) (+ (* c c) (* d d)))
(if (<= d 5800000.0) (/ (- b (/ (* d a) c)) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -6.5e+70) {
tmp = t_0;
} else if (d <= -1e-85) {
tmp = ((b * c) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 5800000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -6.5e+70) tmp = t_0; elseif (d <= -1e-85) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 5800000.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[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -6.5e+70], t$95$0, If[LessEqual[d, -1e-85], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5800000.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{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -6.5 \cdot 10^{+70}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-85}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 5800000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.49999999999999978e70 or 5.8e6 < d Initial program 45.5%
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.f6484.1
Applied rewrites84.1%
if -6.49999999999999978e70 < d < -9.9999999999999998e-86Initial program 82.2%
if -9.9999999999999998e-86 < d < 5.8e6Initial program 69.3%
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%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -1.3e+108)
t_0
(if (<= d -5e+30)
(/ (- (* b c) (* d a)) (* d d))
(if (<= d 15500000.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 <= -1.3e+108) {
tmp = t_0;
} else if (d <= -5e+30) {
tmp = ((b * c) - (d * a)) / (d * d);
} else if (d <= 15500000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = a / -d
if (d <= (-1.3d+108)) then
tmp = t_0
else if (d <= (-5d+30)) then
tmp = ((b * c) - (d * a)) / (d * d)
else if (d <= 15500000.0d0) then
tmp = (b - ((d * a) / c)) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -1.3e+108) {
tmp = t_0;
} else if (d <= -5e+30) {
tmp = ((b * c) - (d * a)) / (d * d);
} else if (d <= 15500000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = a / -d tmp = 0 if d <= -1.3e+108: tmp = t_0 elif d <= -5e+30: tmp = ((b * c) - (d * a)) / (d * d) elif d <= 15500000.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 <= -1.3e+108) tmp = t_0; elseif (d <= -5e+30) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(d * d)); elseif (d <= 15500000.0) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = a / -d; tmp = 0.0; if (d <= -1.3e+108) tmp = t_0; elseif (d <= -5e+30) tmp = ((b * c) - (d * a)) / (d * d); elseif (d <= 15500000.0) tmp = (b - ((d * a) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -1.3e+108], t$95$0, If[LessEqual[d, -5e+30], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 15500000.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 -1.3 \cdot 10^{+108}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -5 \cdot 10^{+30}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq 15500000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.3000000000000001e108 or 1.55e7 < d Initial program 42.8%
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.f6473.2
Applied rewrites73.2%
if -1.3000000000000001e108 < d < -4.9999999999999998e30Initial program 92.2%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6485.6
Applied rewrites85.6%
if -4.9999999999999998e30 < d < 1.55e7Initial program 70.3%
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-*.f6488.2
Applied rewrites88.2%
Final simplification82.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -1.3e+108)
t_0
(if (<= d -4.8e+30)
(/ (- (* b c) (* d a)) (* d d))
(if (<= d -1.35e-118)
(* d (/ (- a) (fma d d (* c c))))
(if (<= d 4800000.0) (/ b c) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -1.3e+108) {
tmp = t_0;
} else if (d <= -4.8e+30) {
tmp = ((b * c) - (d * a)) / (d * d);
} else if (d <= -1.35e-118) {
tmp = d * (-a / fma(d, d, (c * c)));
} else if (d <= 4800000.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 <= -1.3e+108) tmp = t_0; elseif (d <= -4.8e+30) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(d * d)); elseif (d <= -1.35e-118) tmp = Float64(d * Float64(Float64(-a) / fma(d, d, Float64(c * c)))); elseif (d <= 4800000.0) tmp = Float64(b / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -1.3e+108], t$95$0, If[LessEqual[d, -4.8e+30], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.35e-118], N[(d * N[((-a) / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4800000.0], N[(b / c), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{+108}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.8 \cdot 10^{+30}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -1.35 \cdot 10^{-118}:\\
\;\;\;\;d \cdot \frac{-a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 4800000:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.3000000000000001e108 or 4.8e6 < d Initial program 42.8%
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.f6473.2
Applied rewrites73.2%
if -1.3000000000000001e108 < d < -4.7999999999999999e30Initial program 92.2%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6485.6
Applied rewrites85.6%
if -4.7999999999999999e30 < d < -1.34999999999999997e-118Initial program 82.3%
Taylor expanded in b around 0
mul-1-negN/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.4
Applied rewrites64.4%
Applied rewrites64.5%
if -1.34999999999999997e-118 < d < 4.8e6Initial program 67.5%
Taylor expanded in c around inf
lower-/.f6481.6
Applied rewrites81.6%
Final simplification76.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma c (/ b d) (- a)) d))) (if (<= d -5e+30) t_0 (if (<= d 5800000.0) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -5e+30) {
tmp = t_0;
} else if (d <= 5800000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -5e+30) tmp = t_0; elseif (d <= 5800000.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[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -5e+30], t$95$0, If[LessEqual[d, 5800000.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{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -5 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5800000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.9999999999999998e30 or 5.8e6 < d Initial program 48.8%
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.f6484.3
Applied rewrites84.3%
if -4.9999999999999998e30 < d < 5.8e6Initial program 70.3%
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-*.f6488.2
Applied rewrites88.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- (/ (* b c) d) a) d))) (if (<= d -5e+30) t_0 (if (<= d 5800000.0) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (((b * c) / d) - a) / d;
double tmp;
if (d <= -5e+30) {
tmp = t_0;
} else if (d <= 5800000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (((b * c) / d) - a) / d
if (d <= (-5d+30)) then
tmp = t_0
else if (d <= 5800000.0d0) then
tmp = (b - ((d * a) / c)) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (((b * c) / d) - a) / d;
double tmp;
if (d <= -5e+30) {
tmp = t_0;
} else if (d <= 5800000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (((b * c) / d) - a) / d tmp = 0 if d <= -5e+30: tmp = t_0 elif d <= 5800000.0: tmp = (b - ((d * a) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(Float64(b * c) / d) - a) / d) tmp = 0.0 if (d <= -5e+30) tmp = t_0; elseif (d <= 5800000.0) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (((b * c) / d) - a) / d; tmp = 0.0; if (d <= -5e+30) tmp = t_0; elseif (d <= 5800000.0) tmp = (b - ((d * a) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -5e+30], t$95$0, If[LessEqual[d, 5800000.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{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{if}\;d \leq -5 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5800000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.9999999999999998e30 or 5.8e6 < d Initial program 48.8%
Taylor expanded in c around inf
lower-/.f6419.2
Applied rewrites19.2%
Taylor expanded in d around inf
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.2
Applied rewrites79.2%
if -4.9999999999999998e30 < d < 5.8e6Initial program 70.3%
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-*.f6488.2
Applied rewrites88.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -1.58e+72)
t_0
(if (<= d -1.35e-118)
(* d (/ (- a) (fma d d (* c c))))
(if (<= d 4800000.0) (/ b c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -1.58e+72) {
tmp = t_0;
} else if (d <= -1.35e-118) {
tmp = d * (-a / fma(d, d, (c * c)));
} else if (d <= 4800000.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 <= -1.58e+72) tmp = t_0; elseif (d <= -1.35e-118) tmp = Float64(d * Float64(Float64(-a) / fma(d, d, Float64(c * c)))); elseif (d <= 4800000.0) tmp = Float64(b / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -1.58e+72], t$95$0, If[LessEqual[d, -1.35e-118], N[(d * N[((-a) / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4800000.0], N[(b / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -1.58 \cdot 10^{+72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.35 \cdot 10^{-118}:\\
\;\;\;\;d \cdot \frac{-a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 4800000:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.58000000000000006e72 or 4.8e6 < d Initial program 46.0%
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.3
Applied rewrites71.3%
if -1.58000000000000006e72 < d < -1.34999999999999997e-118Initial program 83.3%
Taylor expanded in b around 0
mul-1-negN/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6458.7
Applied rewrites58.7%
Applied rewrites58.8%
if -1.34999999999999997e-118 < d < 4.8e6Initial program 67.5%
Taylor expanded in c around inf
lower-/.f6481.6
Applied rewrites81.6%
Final simplification74.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- d))))
(if (<= d -1.58e+72)
t_0
(if (<= d -4.4e-112)
(* a (/ (- d) (fma d d (* c c))))
(if (<= d 4800000.0) (/ b c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -1.58e+72) {
tmp = t_0;
} else if (d <= -4.4e-112) {
tmp = a * (-d / fma(d, d, (c * c)));
} else if (d <= 4800000.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 <= -1.58e+72) tmp = t_0; elseif (d <= -4.4e-112) tmp = Float64(a * Float64(Float64(-d) / fma(d, d, Float64(c * c)))); elseif (d <= 4800000.0) tmp = Float64(b / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -1.58e+72], t$95$0, If[LessEqual[d, -4.4e-112], N[(a * N[((-d) / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4800000.0], N[(b / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -1.58 \cdot 10^{+72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.4 \cdot 10^{-112}:\\
\;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 4800000:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.58000000000000006e72 or 4.8e6 < d Initial program 46.0%
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.3
Applied rewrites71.3%
if -1.58000000000000006e72 < d < -4.40000000000000042e-112Initial program 82.3%
Taylor expanded in b around 0
mul-1-negN/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.2
Applied rewrites59.2%
if -4.40000000000000042e-112 < d < 4.8e6Initial program 68.0%
Taylor expanded in c around inf
lower-/.f6481.0
Applied rewrites81.0%
Final simplification74.1%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ a (- d)))) (if (<= d -8.8e+17) t_0 (if (<= d 4800000.0) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a / -d;
double tmp;
if (d <= -8.8e+17) {
tmp = t_0;
} else if (d <= 4800000.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 <= (-8.8d+17)) then
tmp = t_0
else if (d <= 4800000.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 <= -8.8e+17) {
tmp = t_0;
} else if (d <= 4800000.0) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = a / -d tmp = 0 if d <= -8.8e+17: tmp = t_0 elif d <= 4800000.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 <= -8.8e+17) tmp = t_0; elseif (d <= 4800000.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 <= -8.8e+17) tmp = t_0; elseif (d <= 4800000.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, -8.8e+17], t$95$0, If[LessEqual[d, 4800000.0], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{-d}\\
\mathbf{if}\;d \leq -8.8 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4800000:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -8.8e17 or 4.8e6 < d Initial program 49.4%
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.f6468.2
Applied rewrites68.2%
if -8.8e17 < d < 4.8e6Initial program 70.3%
Taylor expanded in c around inf
lower-/.f6475.8
Applied rewrites75.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 60.6%
Taylor expanded in c around inf
lower-/.f6449.5
Applied rewrites49.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 2024232
(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))))