
(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 8 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 (* (/ 1.0 (hypot c d)) (/ (- (* c b) (* a d)) (hypot c d))))
(t_1 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -7.7e+28)
t_1
(if (<= c -2.6e-189)
t_0
(if (<= c 2.3e-162)
(- (/ (* c (/ b d)) d) (/ a d))
(if (<= c 12500000000000.0) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / hypot(c, d)) * (((c * b) - (a * d)) / hypot(c, d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -7.7e+28) {
tmp = t_1;
} else if (c <= -2.6e-189) {
tmp = t_0;
} else if (c <= 2.3e-162) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (c <= 12500000000000.0) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (1.0 / Math.hypot(c, d)) * (((c * b) - (a * d)) / Math.hypot(c, d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -7.7e+28) {
tmp = t_1;
} else if (c <= -2.6e-189) {
tmp = t_0;
} else if (c <= 2.3e-162) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (c <= 12500000000000.0) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = (1.0 / math.hypot(c, d)) * (((c * b) - (a * d)) / math.hypot(c, d)) t_1 = (b / c) - ((a / c) * (d / c)) tmp = 0 if c <= -7.7e+28: tmp = t_1 elif c <= -2.6e-189: tmp = t_0 elif c <= 2.3e-162: tmp = ((c * (b / d)) / d) - (a / d) elif c <= 12500000000000.0: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(Float64(c * b) - Float64(a * d)) / hypot(c, d))) t_1 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -7.7e+28) tmp = t_1; elseif (c <= -2.6e-189) tmp = t_0; elseif (c <= 2.3e-162) tmp = Float64(Float64(Float64(c * Float64(b / d)) / d) - Float64(a / d)); elseif (c <= 12500000000000.0) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (1.0 / hypot(c, d)) * (((c * b) - (a * d)) / hypot(c, d)); t_1 = (b / c) - ((a / c) * (d / c)); tmp = 0.0; if (c <= -7.7e+28) tmp = t_1; elseif (c <= -2.6e-189) tmp = t_0; elseif (c <= 2.3e-162) tmp = ((c * (b / d)) / d) - (a / d); elseif (c <= 12500000000000.0) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -7.7e+28], t$95$1, If[LessEqual[c, -2.6e-189], t$95$0, If[LessEqual[c, 2.3e-162], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 12500000000000.0], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -7.7 \cdot 10^{+28}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -2.6 \cdot 10^{-189}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{-162}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 12500000000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -7.6999999999999997e28 or 1.25e13 < c Initial program 52.4%
Taylor expanded in c around inf 96.1%
+-commutative96.1%
mul-1-neg96.1%
unsub-neg96.1%
unpow296.1%
times-frac98.6%
Simplified98.6%
if -7.6999999999999997e28 < c < -2.5999999999999999e-189 or 2.2999999999999998e-162 < c < 1.25e13Initial program 79.8%
*-un-lft-identity79.8%
add-sqr-sqrt79.8%
times-frac79.7%
hypot-def79.7%
hypot-def92.0%
Applied egg-rr92.0%
if -2.5999999999999999e-189 < c < 2.2999999999999998e-162Initial program 63.8%
Taylor expanded in c around 0 79.5%
+-commutative79.5%
mul-1-neg79.5%
unsub-neg79.5%
unpow279.5%
times-frac91.2%
Simplified91.2%
associate-*l/91.3%
Applied egg-rr91.3%
Final simplification93.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* c b) (* a d))) (t_1 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -1.5e+29)
t_1
(if (<= c -3.7e-73)
(/ t_0 (+ (* c c) (* d d)))
(if (<= c 6.4e-162)
(- (/ (* c (/ b d)) d) (/ a d))
(if (<= c 1.1e-42)
(/ t_0 (fma c c (* d d)))
(if (<= c 1e-10) (- (* (/ b d) (/ c d)) (/ a d)) t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (a * d);
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -1.5e+29) {
tmp = t_1;
} else if (c <= -3.7e-73) {
tmp = t_0 / ((c * c) + (d * d));
} else if (c <= 6.4e-162) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (c <= 1.1e-42) {
tmp = t_0 / fma(c, c, (d * d));
} else if (c <= 1e-10) {
tmp = ((b / d) * (c / d)) - (a / d);
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * b) - Float64(a * d)) t_1 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -1.5e+29) tmp = t_1; elseif (c <= -3.7e-73) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 6.4e-162) tmp = Float64(Float64(Float64(c * Float64(b / d)) / d) - Float64(a / d)); elseif (c <= 1.1e-42) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (c <= 1e-10) tmp = Float64(Float64(Float64(b / d) * Float64(c / d)) - Float64(a / d)); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.5e+29], t$95$1, If[LessEqual[c, -3.7e-73], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.4e-162], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.1e-42], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1e-10], N[(N[(N[(b / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot b - a \cdot d\\
t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -1.5 \cdot 10^{+29}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -3.7 \cdot 10^{-73}:\\
\;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 6.4 \cdot 10^{-162}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 1.1 \cdot 10^{-42}:\\
\;\;\;\;\frac{t_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 10^{-10}:\\
\;\;\;\;\frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -1.5e29 or 1.00000000000000004e-10 < c Initial program 54.3%
Taylor expanded in c around inf 94.4%
+-commutative94.4%
mul-1-neg94.4%
unsub-neg94.4%
unpow294.4%
times-frac96.9%
Simplified96.9%
if -1.5e29 < c < -3.7000000000000001e-73Initial program 91.8%
if -3.7000000000000001e-73 < c < 6.39999999999999951e-162Initial program 64.8%
Taylor expanded in c around 0 75.5%
+-commutative75.5%
mul-1-neg75.5%
unsub-neg75.5%
unpow275.5%
times-frac86.0%
Simplified86.0%
associate-*l/86.0%
Applied egg-rr86.0%
if 6.39999999999999951e-162 < c < 1.10000000000000003e-42Initial program 91.3%
fma-def91.4%
Simplified91.4%
if 1.10000000000000003e-42 < c < 1.00000000000000004e-10Initial program 59.7%
Taylor expanded in c around 0 77.6%
+-commutative77.6%
mul-1-neg77.6%
unsub-neg77.6%
unpow277.6%
times-frac84.5%
Simplified84.5%
Final simplification90.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* a d)) (+ (* c c) (* d d))))
(t_1 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -1.12e+29)
t_1
(if (<= c -2.8e-73)
t_0
(if (<= c 6e-162)
(- (/ (* c (/ b d)) d) (/ a d))
(if (<= c 1.1e-42)
t_0
(if (<= c 1e-7) (- (* (/ b d) (/ c d)) (/ a d)) t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -1.12e+29) {
tmp = t_1;
} else if (c <= -2.8e-73) {
tmp = t_0;
} else if (c <= 6e-162) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (c <= 1.1e-42) {
tmp = t_0;
} else if (c <= 1e-7) {
tmp = ((b / d) * (c / d)) - (a / d);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d))
t_1 = (b / c) - ((a / c) * (d / c))
if (c <= (-1.12d+29)) then
tmp = t_1
else if (c <= (-2.8d-73)) then
tmp = t_0
else if (c <= 6d-162) then
tmp = ((c * (b / d)) / d) - (a / d)
else if (c <= 1.1d-42) then
tmp = t_0
else if (c <= 1d-7) then
tmp = ((b / d) * (c / d)) - (a / d)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -1.12e+29) {
tmp = t_1;
} else if (c <= -2.8e-73) {
tmp = t_0;
} else if (c <= 6e-162) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (c <= 1.1e-42) {
tmp = t_0;
} else if (c <= 1e-7) {
tmp = ((b / d) * (c / d)) - (a / d);
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d)) t_1 = (b / c) - ((a / c) * (d / c)) tmp = 0 if c <= -1.12e+29: tmp = t_1 elif c <= -2.8e-73: tmp = t_0 elif c <= 6e-162: tmp = ((c * (b / d)) / d) - (a / d) elif c <= 1.1e-42: tmp = t_0 elif c <= 1e-7: tmp = ((b / d) * (c / d)) - (a / d) else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -1.12e+29) tmp = t_1; elseif (c <= -2.8e-73) tmp = t_0; elseif (c <= 6e-162) tmp = Float64(Float64(Float64(c * Float64(b / d)) / d) - Float64(a / d)); elseif (c <= 1.1e-42) tmp = t_0; elseif (c <= 1e-7) tmp = Float64(Float64(Float64(b / d) * Float64(c / d)) - Float64(a / d)); else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d)); t_1 = (b / c) - ((a / c) * (d / c)); tmp = 0.0; if (c <= -1.12e+29) tmp = t_1; elseif (c <= -2.8e-73) tmp = t_0; elseif (c <= 6e-162) tmp = ((c * (b / d)) / d) - (a / d); elseif (c <= 1.1e-42) tmp = t_0; elseif (c <= 1e-7) tmp = ((b / d) * (c / d)) - (a / d); else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.12e+29], t$95$1, If[LessEqual[c, -2.8e-73], t$95$0, If[LessEqual[c, 6e-162], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.1e-42], t$95$0, If[LessEqual[c, 1e-7], N[(N[(N[(b / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -1.12 \cdot 10^{+29}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -2.8 \cdot 10^{-73}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 6 \cdot 10^{-162}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 1.1 \cdot 10^{-42}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 10^{-7}:\\
\;\;\;\;\frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -1.1200000000000001e29 or 9.9999999999999995e-8 < c Initial program 54.3%
Taylor expanded in c around inf 94.4%
+-commutative94.4%
mul-1-neg94.4%
unsub-neg94.4%
unpow294.4%
times-frac96.9%
Simplified96.9%
if -1.1200000000000001e29 < c < -2.80000000000000012e-73 or 5.99999999999999997e-162 < c < 1.10000000000000003e-42Initial program 91.5%
if -2.80000000000000012e-73 < c < 5.99999999999999997e-162Initial program 64.8%
Taylor expanded in c around 0 75.5%
+-commutative75.5%
mul-1-neg75.5%
unsub-neg75.5%
unpow275.5%
times-frac86.0%
Simplified86.0%
associate-*l/86.0%
Applied egg-rr86.0%
if 1.10000000000000003e-42 < c < 9.9999999999999995e-8Initial program 59.7%
Taylor expanded in c around 0 77.6%
+-commutative77.6%
mul-1-neg77.6%
unsub-neg77.6%
unpow277.6%
times-frac84.5%
Simplified84.5%
Final simplification90.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5e-8) (not (<= c 1.45e-10))) (- (/ b c) (* (/ a c) (/ d c))) (- (* (/ b d) (/ c d)) (/ a d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5e-8) || !(c <= 1.45e-10)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = ((b / d) * (c / 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 <= (-5d-8)) .or. (.not. (c <= 1.45d-10))) then
tmp = (b / c) - ((a / c) * (d / c))
else
tmp = ((b / d) * (c / 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 <= -5e-8) || !(c <= 1.45e-10)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = ((b / d) * (c / d)) - (a / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5e-8) or not (c <= 1.45e-10): tmp = (b / c) - ((a / c) * (d / c)) else: tmp = ((b / d) * (c / d)) - (a / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5e-8) || !(c <= 1.45e-10)) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); else tmp = Float64(Float64(Float64(b / d) * Float64(c / d)) - Float64(a / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5e-8) || ~((c <= 1.45e-10))) tmp = (b / c) - ((a / c) * (d / c)); else tmp = ((b / d) * (c / d)) - (a / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5e-8], N[Not[LessEqual[c, 1.45e-10]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5 \cdot 10^{-8} \lor \neg \left(c \leq 1.45 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\
\end{array}
\end{array}
if c < -4.9999999999999998e-8 or 1.4499999999999999e-10 < c Initial program 60.9%
Taylor expanded in c around inf 92.6%
+-commutative92.6%
mul-1-neg92.6%
unsub-neg92.6%
unpow292.6%
times-frac94.7%
Simplified94.7%
if -4.9999999999999998e-8 < c < 1.4499999999999999e-10Initial program 71.5%
Taylor expanded in c around 0 74.3%
+-commutative74.3%
mul-1-neg74.3%
unsub-neg74.3%
unpow274.3%
times-frac81.7%
Simplified81.7%
Final simplification86.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8e-7) (not (<= c 9.8e-8))) (- (/ b c) (* (/ a c) (/ d c))) (- (/ (* c (/ b d)) d) (/ a d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8e-7) || !(c <= 9.8e-8)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = ((c * (b / d)) / 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 <= (-8d-7)) .or. (.not. (c <= 9.8d-8))) then
tmp = (b / c) - ((a / c) * (d / c))
else
tmp = ((c * (b / d)) / 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 <= -8e-7) || !(c <= 9.8e-8)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = ((c * (b / d)) / d) - (a / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8e-7) or not (c <= 9.8e-8): tmp = (b / c) - ((a / c) * (d / c)) else: tmp = ((c * (b / d)) / d) - (a / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8e-7) || !(c <= 9.8e-8)) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); else tmp = Float64(Float64(Float64(c * Float64(b / d)) / d) - Float64(a / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -8e-7) || ~((c <= 9.8e-8))) tmp = (b / c) - ((a / c) * (d / c)); else tmp = ((c * (b / d)) / d) - (a / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8e-7], N[Not[LessEqual[c, 9.8e-8]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8 \cdot 10^{-7} \lor \neg \left(c \leq 9.8 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\
\end{array}
\end{array}
if c < -7.9999999999999996e-7 or 9.8000000000000004e-8 < c Initial program 60.9%
Taylor expanded in c around inf 92.6%
+-commutative92.6%
mul-1-neg92.6%
unsub-neg92.6%
unpow292.6%
times-frac94.7%
Simplified94.7%
if -7.9999999999999996e-7 < c < 9.8000000000000004e-8Initial program 71.5%
Taylor expanded in c around 0 74.3%
+-commutative74.3%
mul-1-neg74.3%
unsub-neg74.3%
unpow274.3%
times-frac81.7%
Simplified81.7%
associate-*l/81.7%
Applied egg-rr81.7%
Final simplification86.2%
(FPCore (a b c d) :precision binary64 (if (<= c -1.86e-6) (/ b c) (if (<= c 250000000000.0) (- (* (/ b d) (/ c d)) (/ a d)) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.86e-6) {
tmp = b / c;
} else if (c <= 250000000000.0) {
tmp = ((b / d) * (c / d)) - (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 <= (-1.86d-6)) then
tmp = b / c
else if (c <= 250000000000.0d0) then
tmp = ((b / d) * (c / d)) - (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 <= -1.86e-6) {
tmp = b / c;
} else if (c <= 250000000000.0) {
tmp = ((b / d) * (c / d)) - (a / d);
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.86e-6: tmp = b / c elif c <= 250000000000.0: tmp = ((b / d) * (c / d)) - (a / d) else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.86e-6) tmp = Float64(b / c); elseif (c <= 250000000000.0) tmp = Float64(Float64(Float64(b / d) * Float64(c / d)) - 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 <= -1.86e-6) tmp = b / c; elseif (c <= 250000000000.0) tmp = ((b / d) * (c / d)) - (a / d); else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.86e-6], N[(b / c), $MachinePrecision], If[LessEqual[c, 250000000000.0], N[(N[(N[(b / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.86 \cdot 10^{-6}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 250000000000:\\
\;\;\;\;\frac{b}{d} \cdot \frac{c}{d} - \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.86e-6 or 2.5e11 < c Initial program 59.6%
Taylor expanded in c around inf 86.6%
if -1.86e-6 < c < 2.5e11Initial program 72.0%
Taylor expanded in c around 0 73.6%
+-commutative73.6%
mul-1-neg73.6%
unsub-neg73.6%
unpow273.6%
times-frac80.9%
Simplified80.9%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (<= c -2.7e-7) (/ b c) (if (<= c 1350000000000.0) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.7e-7) {
tmp = b / c;
} else if (c <= 1350000000000.0) {
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 <= (-2.7d-7)) then
tmp = b / c
else if (c <= 1350000000000.0d0) 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 <= -2.7e-7) {
tmp = b / c;
} else if (c <= 1350000000000.0) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.7e-7: tmp = b / c elif c <= 1350000000000.0: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.7e-7) tmp = Float64(b / c); elseif (c <= 1350000000000.0) 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 <= -2.7e-7) tmp = b / c; elseif (c <= 1350000000000.0) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.7e-7], N[(b / c), $MachinePrecision], If[LessEqual[c, 1350000000000.0], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.7 \cdot 10^{-7}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1350000000000:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.70000000000000009e-7 or 1.35e12 < c Initial program 59.6%
Taylor expanded in c around inf 86.6%
if -2.70000000000000009e-7 < c < 1.35e12Initial program 72.0%
Taylor expanded in c around 0 65.3%
associate-*r/65.3%
neg-mul-165.3%
Simplified65.3%
Final simplification72.5%
(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 67.8%
Taylor expanded in c around inf 42.8%
Final simplification42.8%
(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 2023278
(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))))