
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -7.8e+150)
t_0
(if (<= d -7.5e-131)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(if (<= d 4.1e-25)
(- (/ b c) (/ (* a (/ d c)) c))
(if (<= d 1.2e+133)
(/ (fma b c (* d (- a))) (fma c c (* d d)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -7.8e+150) {
tmp = t_0;
} else if (d <= -7.5e-131) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 4.1e-25) {
tmp = (b / c) - ((a * (d / c)) / c);
} else if (d <= 1.2e+133) {
tmp = fma(b, c, (d * -a)) / fma(c, c, (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -7.8e+150) tmp = t_0; elseif (d <= -7.5e-131) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 4.1e-25) tmp = Float64(Float64(b / c) - Float64(Float64(a * Float64(d / c)) / c)); elseif (d <= 1.2e+133) tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(c, c, Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7.8e+150], t$95$0, If[LessEqual[d, -7.5e-131], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.1e-25], N[(N[(b / c), $MachinePrecision] - N[(N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.2e+133], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -7.8 \cdot 10^{+150}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -7.5 \cdot 10^{-131}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 4.1 \cdot 10^{-25}:\\
\;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{+133}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -7.79999999999999981e150 or 1.1999999999999999e133 < d Initial program 27.2%
Taylor expanded in c around 0 77.0%
+-commutative77.0%
mul-1-neg77.0%
unsub-neg77.0%
*-commutative77.0%
Simplified77.0%
pow277.0%
times-frac88.5%
Applied egg-rr88.5%
associate-*l/88.5%
sub-div88.5%
Applied egg-rr88.5%
if -7.79999999999999981e150 < d < -7.49999999999999964e-131Initial program 81.9%
if -7.49999999999999964e-131 < d < 4.09999999999999987e-25Initial program 63.1%
Taylor expanded in c around inf 79.6%
*-commutative79.6%
pow279.6%
times-frac82.9%
Applied egg-rr82.9%
associate-*r/86.8%
Applied egg-rr86.8%
if 4.09999999999999987e-25 < d < 1.1999999999999999e133Initial program 79.5%
fma-neg79.6%
distribute-lft-neg-out79.6%
*-commutative79.6%
fma-def79.6%
Simplified79.6%
Final simplification85.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.9e+151)
t_1
(if (<= d -1.45e-130)
t_0
(if (<= d 3.85e-25)
(- (/ b c) (/ (* a (/ d c)) c))
(if (<= d 2.8e+132) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.9e+151) {
tmp = t_1;
} else if (d <= -1.45e-130) {
tmp = t_0;
} else if (d <= 3.85e-25) {
tmp = (b / c) - ((a * (d / c)) / c);
} else if (d <= 2.8e+132) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
t_1 = ((c * (b / d)) - a) / d
if (d <= (-1.9d+151)) then
tmp = t_1
else if (d <= (-1.45d-130)) then
tmp = t_0
else if (d <= 3.85d-25) then
tmp = (b / c) - ((a * (d / c)) / c)
else if (d <= 2.8d+132) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.9e+151) {
tmp = t_1;
} else if (d <= -1.45e-130) {
tmp = t_0;
} else if (d <= 3.85e-25) {
tmp = (b / c) - ((a * (d / c)) / c);
} else if (d <= 2.8e+132) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) t_1 = ((c * (b / d)) - a) / d tmp = 0 if d <= -1.9e+151: tmp = t_1 elif d <= -1.45e-130: tmp = t_0 elif d <= 3.85e-25: tmp = (b / c) - ((a * (d / c)) / c) elif d <= 2.8e+132: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -1.9e+151) tmp = t_1; elseif (d <= -1.45e-130) tmp = t_0; elseif (d <= 3.85e-25) tmp = Float64(Float64(b / c) - Float64(Float64(a * Float64(d / c)) / c)); elseif (d <= 2.8e+132) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); t_1 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -1.9e+151) tmp = t_1; elseif (d <= -1.45e-130) tmp = t_0; elseif (d <= 3.85e-25) tmp = (b / c) - ((a * (d / c)) / c); elseif (d <= 2.8e+132) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.9e+151], t$95$1, If[LessEqual[d, -1.45e-130], t$95$0, If[LessEqual[d, 3.85e-25], N[(N[(b / c), $MachinePrecision] - N[(N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.8e+132], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.9 \cdot 10^{+151}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq -1.45 \cdot 10^{-130}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.85 \cdot 10^{-25}:\\
\;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{+132}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if d < -1.9e151 or 2.7999999999999999e132 < d Initial program 27.2%
Taylor expanded in c around 0 77.0%
+-commutative77.0%
mul-1-neg77.0%
unsub-neg77.0%
*-commutative77.0%
Simplified77.0%
pow277.0%
times-frac88.5%
Applied egg-rr88.5%
associate-*l/88.5%
sub-div88.5%
Applied egg-rr88.5%
if -1.9e151 < d < -1.45e-130 or 3.8500000000000001e-25 < d < 2.7999999999999999e132Initial program 80.7%
if -1.45e-130 < d < 3.8500000000000001e-25Initial program 63.1%
Taylor expanded in c around inf 79.6%
*-commutative79.6%
pow279.6%
times-frac82.9%
Applied egg-rr82.9%
associate-*r/86.8%
Applied egg-rr86.8%
Final simplification85.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.22e+73) (not (<= d 5.3e-25))) (/ (- (* c (/ b d)) a) d) (- (/ b c) (* (/ d c) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.22e+73) || !(d <= 5.3e-25)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b / c) - ((d / c) * (a / c));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.22d+73)) .or. (.not. (d <= 5.3d-25))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b / c) - ((d / c) * (a / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.22e+73) || !(d <= 5.3e-25)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b / c) - ((d / c) * (a / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.22e+73) or not (d <= 5.3e-25): tmp = ((c * (b / d)) - a) / d else: tmp = (b / c) - ((d / c) * (a / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.22e+73) || !(d <= 5.3e-25)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b / c) - Float64(Float64(d / c) * Float64(a / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.22e+73) || ~((d <= 5.3e-25))) tmp = ((c * (b / d)) - a) / d; else tmp = (b / c) - ((d / c) * (a / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.22e+73], N[Not[LessEqual[d, 5.3e-25]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.22 \cdot 10^{+73} \lor \neg \left(d \leq 5.3 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\
\end{array}
\end{array}
if d < -1.21999999999999998e73 or 5.2999999999999997e-25 < d Initial program 50.3%
Taylor expanded in c around 0 72.8%
+-commutative72.8%
mul-1-neg72.8%
unsub-neg72.8%
*-commutative72.8%
Simplified72.8%
pow272.8%
times-frac77.9%
Applied egg-rr77.9%
associate-*l/79.3%
sub-div79.3%
Applied egg-rr79.3%
if -1.21999999999999998e73 < d < 5.2999999999999997e-25Initial program 67.5%
Taylor expanded in c around inf 74.1%
*-commutative74.1%
pow274.1%
times-frac78.0%
Applied egg-rr78.0%
Final simplification78.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.22e+73) (not (<= d 5.2e-25))) (/ (- (* c (/ b d)) a) d) (- (/ b c) (/ (* a (/ d c)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.22e+73) || !(d <= 5.2e-25)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b / c) - ((a * (d / c)) / c);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.22d+73)) .or. (.not. (d <= 5.2d-25))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b / c) - ((a * (d / c)) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.22e+73) || !(d <= 5.2e-25)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b / c) - ((a * (d / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.22e+73) or not (d <= 5.2e-25): tmp = ((c * (b / d)) - a) / d else: tmp = (b / c) - ((a * (d / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.22e+73) || !(d <= 5.2e-25)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b / c) - Float64(Float64(a * Float64(d / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.22e+73) || ~((d <= 5.2e-25))) tmp = ((c * (b / d)) - a) / d; else tmp = (b / c) - ((a * (d / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.22e+73], N[Not[LessEqual[d, 5.2e-25]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.22 \cdot 10^{+73} \lor \neg \left(d \leq 5.2 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.21999999999999998e73 or 5.2e-25 < d Initial program 50.3%
Taylor expanded in c around 0 72.8%
+-commutative72.8%
mul-1-neg72.8%
unsub-neg72.8%
*-commutative72.8%
Simplified72.8%
pow272.8%
times-frac77.9%
Applied egg-rr77.9%
associate-*l/79.3%
sub-div79.3%
Applied egg-rr79.3%
if -1.21999999999999998e73 < d < 5.2e-25Initial program 67.5%
Taylor expanded in c around inf 74.1%
*-commutative74.1%
pow274.1%
times-frac78.0%
Applied egg-rr78.0%
associate-*r/81.0%
Applied egg-rr81.0%
Final simplification80.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.4e+49) (not (<= c 8.2e+116))) (/ b c) (/ (- (* c (/ b d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e+49) || !(c <= 8.2e+116)) {
tmp = b / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-2.4d+49)) .or. (.not. (c <= 8.2d+116))) then
tmp = b / c
else
tmp = ((c * (b / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e+49) || !(c <= 8.2e+116)) {
tmp = b / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.4e+49) or not (c <= 8.2e+116): tmp = b / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.4e+49) || !(c <= 8.2e+116)) tmp = Float64(b / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.4e+49) || ~((c <= 8.2e+116))) tmp = b / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e+49], N[Not[LessEqual[c, 8.2e+116]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{+49} \lor \neg \left(c \leq 8.2 \cdot 10^{+116}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.4e49 or 8.1999999999999996e116 < c Initial program 39.7%
Taylor expanded in c around inf 73.8%
if -2.4e49 < c < 8.1999999999999996e116Initial program 69.3%
Taylor expanded in c around 0 68.0%
+-commutative68.0%
mul-1-neg68.0%
unsub-neg68.0%
*-commutative68.0%
Simplified68.0%
pow268.0%
times-frac70.7%
Applied egg-rr70.7%
associate-*l/71.8%
sub-div71.9%
Applied egg-rr71.9%
Final simplification72.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.4e+50) (not (<= c 1e+117))) (/ b c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e+50) || !(c <= 1e+117)) {
tmp = b / c;
} else {
tmp = ((b * (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 <= (-2.4d+50)) .or. (.not. (c <= 1d+117))) then
tmp = b / c
else
tmp = ((b * (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 <= -2.4e+50) || !(c <= 1e+117)) {
tmp = b / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.4e+50) or not (c <= 1e+117): tmp = b / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.4e+50) || !(c <= 1e+117)) tmp = Float64(b / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.4e+50) || ~((c <= 1e+117))) tmp = b / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e+50], N[Not[LessEqual[c, 1e+117]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{+50} \lor \neg \left(c \leq 10^{+117}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.4000000000000002e50 or 1.00000000000000005e117 < c Initial program 39.7%
Taylor expanded in c around inf 73.8%
if -2.4000000000000002e50 < c < 1.00000000000000005e117Initial program 69.3%
Taylor expanded in c around 0 68.0%
+-commutative68.0%
mul-1-neg68.0%
unsub-neg68.0%
*-commutative68.0%
Simplified68.0%
pow268.0%
times-frac70.7%
Applied egg-rr70.7%
associate-*r/73.5%
sub-div73.6%
Applied egg-rr73.6%
Final simplification73.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.2e+18) (not (<= d 15800.0))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.2e+18) || !(d <= 15800.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 ((d <= (-3.2d+18)) .or. (.not. (d <= 15800.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 ((d <= -3.2e+18) || !(d <= 15800.0)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.2e+18) or not (d <= 15800.0): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.2e+18) || !(d <= 15800.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 ((d <= -3.2e+18) || ~((d <= 15800.0))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.2e+18], N[Not[LessEqual[d, 15800.0]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{+18} \lor \neg \left(d \leq 15800\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.2e18 or 15800 < d Initial program 50.1%
Taylor expanded in c around 0 63.1%
associate-*r/63.1%
neg-mul-163.1%
Simplified63.1%
if -3.2e18 < d < 15800Initial program 68.2%
Taylor expanded in c around inf 63.0%
Final simplification63.1%
(FPCore (a b c d) :precision binary64 (if (<= d -1.55e+203) (/ b d) (if (<= d 1.4e+178) (/ b c) (/ a d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.55e+203) {
tmp = b / d;
} else if (d <= 1.4e+178) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-1.55d+203)) then
tmp = b / d
else if (d <= 1.4d+178) then
tmp = b / c
else
tmp = a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.55e+203) {
tmp = b / d;
} else if (d <= 1.4e+178) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.55e+203: tmp = b / d elif d <= 1.4e+178: tmp = b / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.55e+203) tmp = Float64(b / d); elseif (d <= 1.4e+178) tmp = Float64(b / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.55e+203) tmp = b / d; elseif (d <= 1.4e+178) tmp = b / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.55e+203], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.4e+178], N[(b / c), $MachinePrecision], N[(a / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.55 \cdot 10^{+203}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{+178}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < -1.55e203Initial program 28.2%
fma-neg28.2%
*-commutative28.2%
distribute-rgt-neg-out28.2%
add-sqr-sqrt28.2%
*-un-lft-identity28.2%
times-frac28.2%
hypot-def28.2%
add-sqr-sqrt18.8%
sqrt-unprod28.2%
sqr-neg28.2%
sqrt-unprod9.4%
add-sqr-sqrt28.2%
*-commutative28.2%
hypot-def36.1%
Applied egg-rr36.1%
Taylor expanded in b around inf 37.6%
Taylor expanded in d around -inf 34.4%
Taylor expanded in c around -inf 26.5%
if -1.55e203 < d < 1.39999999999999997e178Initial program 67.5%
Taylor expanded in c around inf 48.1%
if 1.39999999999999997e178 < d Initial program 23.9%
fma-neg23.9%
*-commutative23.9%
distribute-rgt-neg-out23.9%
add-sqr-sqrt23.9%
*-un-lft-identity23.9%
times-frac23.9%
hypot-def23.9%
add-sqr-sqrt17.8%
sqrt-unprod23.9%
sqr-neg23.9%
sqrt-unprod6.2%
add-sqr-sqrt23.9%
*-commutative23.9%
hypot-def27.4%
Applied egg-rr27.4%
Taylor expanded in c around 0 25.4%
Final simplification43.5%
(FPCore (a b c d) :precision binary64 (if (<= d 2e+178) (/ b c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 2e+178) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= 2d+178) then
tmp = b / c
else
tmp = a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= 2e+178) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 2e+178: tmp = b / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 2e+178) tmp = Float64(b / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 2e+178) tmp = b / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 2e+178], N[(b / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 2 \cdot 10^{+178}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 2.0000000000000001e178Initial program 63.5%
Taylor expanded in c around inf 44.0%
if 2.0000000000000001e178 < d Initial program 23.9%
fma-neg23.9%
*-commutative23.9%
distribute-rgt-neg-out23.9%
add-sqr-sqrt23.9%
*-un-lft-identity23.9%
times-frac23.9%
hypot-def23.9%
add-sqr-sqrt17.8%
sqrt-unprod23.9%
sqr-neg23.9%
sqrt-unprod6.2%
add-sqr-sqrt23.9%
*-commutative23.9%
hypot-def27.4%
Applied egg-rr27.4%
Taylor expanded in c around 0 25.4%
Final simplification41.8%
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
return a / d;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / d
end function
public static double code(double a, double b, double c, double d) {
return a / d;
}
def code(a, b, c, d): return a / d
function code(a, b, c, d) return Float64(a / d) end
function tmp = code(a, b, c, d) tmp = a / d; end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{d}
\end{array}
Initial program 58.9%
fma-neg58.9%
*-commutative58.9%
distribute-rgt-neg-out58.9%
add-sqr-sqrt58.9%
*-un-lft-identity58.9%
times-frac58.8%
hypot-def58.8%
add-sqr-sqrt34.0%
sqrt-unprod43.1%
sqr-neg43.1%
sqrt-unprod14.8%
add-sqr-sqrt36.0%
*-commutative36.0%
hypot-def44.1%
Applied egg-rr44.1%
Taylor expanded in c around 0 8.8%
Final simplification8.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 2023330
(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))))