
(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 (if (or (<= d -2.9e-72) (not (<= d 3.4e-121))) (* (/ (- (* b (/ c d)) a) (hypot d c)) (/ d (hypot d c))) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.9e-72) || !(d <= 3.4e-121)) {
tmp = (((b * (c / d)) - a) / hypot(d, c)) * (d / hypot(d, c));
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.9e-72) || !(d <= 3.4e-121)) {
tmp = (((b * (c / d)) - a) / Math.hypot(d, c)) * (d / Math.hypot(d, c));
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.9e-72) or not (d <= 3.4e-121): tmp = (((b * (c / d)) - a) / math.hypot(d, c)) * (d / math.hypot(d, c)) else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.9e-72) || !(d <= 3.4e-121)) tmp = Float64(Float64(Float64(Float64(b * Float64(c / d)) - a) / hypot(d, c)) * Float64(d / hypot(d, c))); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.9e-72) || ~((d <= 3.4e-121))) tmp = (((b * (c / d)) - a) / hypot(d, c)) * (d / hypot(d, c)); else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.9e-72], N[Not[LessEqual[d, 3.4e-121]], $MachinePrecision]], N[(N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.9 \cdot 10^{-72} \lor \neg \left(d \leq 3.4 \cdot 10^{-121}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{d}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -2.89999999999999998e-72 or 3.40000000000000001e-121 < d Initial program 55.7%
fmm-def55.7%
distribute-rgt-neg-out55.7%
+-commutative55.7%
fma-define55.7%
Simplified55.7%
Taylor expanded in d around inf 55.7%
+-commutative55.7%
neg-mul-155.7%
sub-neg55.7%
associate-/l*55.2%
Simplified55.2%
*-commutative55.2%
add-sqr-sqrt55.2%
times-frac62.3%
fma-undefine62.3%
hypot-define62.3%
fma-undefine62.3%
hypot-define95.0%
Applied egg-rr95.0%
if -2.89999999999999998e-72 < d < 3.40000000000000001e-121Initial program 68.5%
fmm-def68.5%
distribute-rgt-neg-out68.5%
+-commutative68.5%
fma-define68.5%
Simplified68.5%
Taylor expanded in c around inf 93.6%
mul-1-neg93.6%
unsub-neg93.6%
*-commutative93.6%
Simplified93.6%
Final simplification94.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (/ c (/ d b)) a) d)))
(if (<= d -1.9e+23)
t_0
(if (<= d 5e-80)
(/ (- b (/ (* d a) c)) c)
(if (<= d 2.75e+65)
(/ (* d (- (* b (/ c d)) a)) (fma d d (* c c)))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c / (d / b)) - a) / d;
double tmp;
if (d <= -1.9e+23) {
tmp = t_0;
} else if (d <= 5e-80) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 2.75e+65) {
tmp = (d * ((b * (c / d)) - a)) / fma(d, d, (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c / Float64(d / b)) - a) / d) tmp = 0.0 if (d <= -1.9e+23) tmp = t_0; elseif (d <= 5e-80) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 2.75e+65) tmp = Float64(Float64(d * Float64(Float64(b * Float64(c / d)) - a)) / fma(d, d, Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.9e+23], t$95$0, If[LessEqual[d, 5e-80], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.75e+65], N[(N[(d * N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\mathbf{if}\;d \leq -1.9 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5 \cdot 10^{-80}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 2.75 \cdot 10^{+65}:\\
\;\;\;\;\frac{d \cdot \left(b \cdot \frac{c}{d} - a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.89999999999999987e23 or 2.7499999999999998e65 < d Initial program 43.9%
fmm-def43.9%
distribute-rgt-neg-out43.9%
+-commutative43.9%
fma-define43.9%
Simplified43.9%
Taylor expanded in d around -inf 79.2%
mul-1-neg79.2%
distribute-neg-frac279.2%
mul-1-neg79.2%
unsub-neg79.2%
*-commutative79.2%
associate-/l*86.7%
Simplified86.7%
clear-num86.8%
un-div-inv86.8%
Applied egg-rr86.8%
if -1.89999999999999987e23 < d < 5e-80Initial program 72.2%
fmm-def72.2%
distribute-rgt-neg-out72.2%
+-commutative72.2%
fma-define72.2%
Simplified72.2%
Taylor expanded in c around inf 89.2%
mul-1-neg89.2%
unsub-neg89.2%
*-commutative89.2%
Simplified89.2%
if 5e-80 < d < 2.7499999999999998e65Initial program 86.0%
fmm-def86.0%
distribute-rgt-neg-out86.0%
+-commutative86.0%
fma-define86.0%
Simplified86.0%
Taylor expanded in d around inf 86.0%
+-commutative86.0%
neg-mul-186.0%
sub-neg86.0%
associate-/l*86.1%
Simplified86.1%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (/ c (/ d b)) a) d)))
(if (<= d -2.6e+22)
t_0
(if (<= d 4.8e-65)
(/ (- b (/ (* d a) c)) c)
(if (<= d 3.5e+65) (/ (- (* b c) (* d a)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c / (d / b)) - a) / d;
double tmp;
if (d <= -2.6e+22) {
tmp = t_0;
} else if (d <= 4.8e-65) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 3.5e+65) {
tmp = ((b * c) - (d * a)) / ((c * c) + (d * 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 = ((c / (d / b)) - a) / d
if (d <= (-2.6d+22)) then
tmp = t_0
else if (d <= 4.8d-65) then
tmp = (b - ((d * a) / c)) / c
else if (d <= 3.5d+65) then
tmp = ((b * c) - (d * a)) / ((c * c) + (d * 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 = ((c / (d / b)) - a) / d;
double tmp;
if (d <= -2.6e+22) {
tmp = t_0;
} else if (d <= 4.8e-65) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 3.5e+65) {
tmp = ((b * c) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c / (d / b)) - a) / d tmp = 0 if d <= -2.6e+22: tmp = t_0 elif d <= 4.8e-65: tmp = (b - ((d * a) / c)) / c elif d <= 3.5e+65: tmp = ((b * c) - (d * a)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c / Float64(d / b)) - a) / d) tmp = 0.0 if (d <= -2.6e+22) tmp = t_0; elseif (d <= 4.8e-65) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 3.5e+65) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c / (d / b)) - a) / d; tmp = 0.0; if (d <= -2.6e+22) tmp = t_0; elseif (d <= 4.8e-65) tmp = (b - ((d * a) / c)) / c; elseif (d <= 3.5e+65) tmp = ((b * c) - (d * a)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.6e+22], t$95$0, If[LessEqual[d, 4.8e-65], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.5e+65], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\mathbf{if}\;d \leq -2.6 \cdot 10^{+22}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-65}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{+65}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.6e22 or 3.5000000000000001e65 < d Initial program 43.9%
fmm-def43.9%
distribute-rgt-neg-out43.9%
+-commutative43.9%
fma-define43.9%
Simplified43.9%
Taylor expanded in d around -inf 79.2%
mul-1-neg79.2%
distribute-neg-frac279.2%
mul-1-neg79.2%
unsub-neg79.2%
*-commutative79.2%
associate-/l*86.7%
Simplified86.7%
clear-num86.8%
un-div-inv86.8%
Applied egg-rr86.8%
if -2.6e22 < d < 4.8000000000000003e-65Initial program 72.2%
fmm-def72.2%
distribute-rgt-neg-out72.2%
+-commutative72.2%
fma-define72.2%
Simplified72.2%
Taylor expanded in c around inf 89.2%
mul-1-neg89.2%
unsub-neg89.2%
*-commutative89.2%
Simplified89.2%
if 4.8000000000000003e-65 < d < 3.5000000000000001e65Initial program 86.0%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.2e+19) (not (<= d 9.5e-59))) (/ (- (/ c (/ d b)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.2e+19) || !(d <= 9.5e-59)) {
tmp = ((c / (d / b)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-9.2d+19)) .or. (.not. (d <= 9.5d-59))) then
tmp = ((c / (d / b)) - a) / d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.2e+19) || !(d <= 9.5e-59)) {
tmp = ((c / (d / b)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.2e+19) or not (d <= 9.5e-59): tmp = ((c / (d / b)) - a) / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.2e+19) || !(d <= 9.5e-59)) tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -9.2e+19) || ~((d <= 9.5e-59))) tmp = ((c / (d / b)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.2e+19], N[Not[LessEqual[d, 9.5e-59]], $MachinePrecision]], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{+19} \lor \neg \left(d \leq 9.5 \cdot 10^{-59}\right):\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -9.2e19 or 9.4999999999999994e-59 < d Initial program 50.1%
fmm-def50.0%
distribute-rgt-neg-out50.0%
+-commutative50.0%
fma-define50.1%
Simplified50.1%
Taylor expanded in d around -inf 76.2%
mul-1-neg76.2%
distribute-neg-frac276.2%
mul-1-neg76.2%
unsub-neg76.2%
*-commutative76.2%
associate-/l*82.6%
Simplified82.6%
clear-num82.6%
un-div-inv82.6%
Applied egg-rr82.6%
if -9.2e19 < d < 9.4999999999999994e-59Initial program 72.5%
fmm-def72.5%
distribute-rgt-neg-out72.5%
+-commutative72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 89.3%
mul-1-neg89.3%
unsub-neg89.3%
*-commutative89.3%
Simplified89.3%
Final simplification85.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9e+21) (not (<= d 1.3e-58))) (/ (- (* c (/ b d)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9e+21) || !(d <= 1.3e-58)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-9d+21)) .or. (.not. (d <= 1.3d-58))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9e+21) || !(d <= 1.3e-58)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9e+21) or not (d <= 1.3e-58): tmp = ((c * (b / d)) - a) / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9e+21) || !(d <= 1.3e-58)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -9e+21) || ~((d <= 1.3e-58))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9e+21], N[Not[LessEqual[d, 1.3e-58]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{+21} \lor \neg \left(d \leq 1.3 \cdot 10^{-58}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -9e21 or 1.30000000000000003e-58 < d Initial program 50.1%
fmm-def50.0%
distribute-rgt-neg-out50.0%
+-commutative50.0%
fma-define50.1%
Simplified50.1%
Taylor expanded in d around -inf 76.2%
mul-1-neg76.2%
distribute-neg-frac276.2%
mul-1-neg76.2%
unsub-neg76.2%
*-commutative76.2%
associate-/l*82.6%
Simplified82.6%
if -9e21 < d < 1.30000000000000003e-58Initial program 72.5%
fmm-def72.5%
distribute-rgt-neg-out72.5%
+-commutative72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 89.3%
mul-1-neg89.3%
unsub-neg89.3%
*-commutative89.3%
Simplified89.3%
Final simplification85.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.55e+23) (not (<= d 7.6e-59))) (/ (- (* b (/ c d)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.55e+23) || !(d <= 7.6e-59)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.55d+23)) .or. (.not. (d <= 7.6d-59))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.55e+23) || !(d <= 7.6e-59)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.55e+23) or not (d <= 7.6e-59): tmp = ((b * (c / d)) - a) / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.55e+23) || !(d <= 7.6e-59)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.55e+23) || ~((d <= 7.6e-59))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.55e+23], N[Not[LessEqual[d, 7.6e-59]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.55 \cdot 10^{+23} \lor \neg \left(d \leq 7.6 \cdot 10^{-59}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -1.54999999999999985e23 or 7.59999999999999966e-59 < d Initial program 50.1%
fmm-def50.0%
distribute-rgt-neg-out50.0%
+-commutative50.0%
fma-define50.1%
Simplified50.1%
Taylor expanded in d around -inf 76.2%
mul-1-neg76.2%
distribute-neg-frac276.2%
mul-1-neg76.2%
unsub-neg76.2%
*-commutative76.2%
associate-/l*82.6%
Simplified82.6%
Taylor expanded in d around inf 76.2%
neg-mul-176.2%
associate-*r/81.7%
+-commutative81.7%
sub-neg81.7%
Simplified81.7%
if -1.54999999999999985e23 < d < 7.59999999999999966e-59Initial program 72.5%
fmm-def72.5%
distribute-rgt-neg-out72.5%
+-commutative72.5%
fma-define72.5%
Simplified72.5%
Taylor expanded in c around inf 89.3%
mul-1-neg89.3%
unsub-neg89.3%
*-commutative89.3%
Simplified89.3%
Final simplification85.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.3e+21) (not (<= d 1.8e-26))) (/ a (- d)) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.3e+21) || !(d <= 1.8e-26)) {
tmp = a / -d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.3d+21)) .or. (.not. (d <= 1.8d-26))) then
tmp = a / -d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.3e+21) || !(d <= 1.8e-26)) {
tmp = a / -d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.3e+21) or not (d <= 1.8e-26): tmp = a / -d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.3e+21) || !(d <= 1.8e-26)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.3e+21) || ~((d <= 1.8e-26))) tmp = a / -d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.3e+21], N[Not[LessEqual[d, 1.8e-26]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.3 \cdot 10^{+21} \lor \neg \left(d \leq 1.8 \cdot 10^{-26}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -1.3e21 or 1.8000000000000001e-26 < d Initial program 49.7%
fmm-def49.7%
distribute-rgt-neg-out49.7%
+-commutative49.7%
fma-define49.7%
Simplified49.7%
Taylor expanded in c around 0 67.0%
associate-*r/67.0%
neg-mul-167.0%
Simplified67.0%
if -1.3e21 < d < 1.8000000000000001e-26Initial program 72.3%
fmm-def72.3%
distribute-rgt-neg-out72.3%
+-commutative72.3%
fma-define72.3%
Simplified72.3%
Taylor expanded in c around inf 88.0%
mul-1-neg88.0%
unsub-neg88.0%
*-commutative88.0%
Simplified88.0%
Final simplification76.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.2e+20) (not (<= d 1.75e-26))) (/ (- a) d) (/ (- b (* (/ d c) a)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.2e+20) || !(d <= 1.75e-26)) {
tmp = -a / d;
} else {
tmp = (b - ((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 <= (-4.2d+20)) .or. (.not. (d <= 1.75d-26))) then
tmp = -a / d
else
tmp = (b - ((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 <= -4.2e+20) || !(d <= 1.75e-26)) {
tmp = -a / d;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.2e+20) or not (d <= 1.75e-26): tmp = -a / d else: tmp = (b - ((d / c) * a)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.2e+20) || !(d <= 1.75e-26)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.2e+20) || ~((d <= 1.75e-26))) tmp = -a / d; else tmp = (b - ((d / c) * a)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.2e+20], N[Not[LessEqual[d, 1.75e-26]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.2 \cdot 10^{+20} \lor \neg \left(d \leq 1.75 \cdot 10^{-26}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if d < -4.2e20 or 1.74999999999999992e-26 < d Initial program 49.7%
fmm-def49.7%
distribute-rgt-neg-out49.7%
+-commutative49.7%
fma-define49.7%
Simplified49.7%
Taylor expanded in c around 0 67.0%
associate-*r/67.0%
neg-mul-167.0%
Simplified67.0%
if -4.2e20 < d < 1.74999999999999992e-26Initial program 72.3%
fmm-def72.3%
distribute-rgt-neg-out72.3%
+-commutative72.3%
fma-define72.3%
Simplified72.3%
Taylor expanded in c around -inf 88.0%
mul-1-neg88.0%
fma-define88.0%
associate-/l*86.5%
Simplified86.5%
Taylor expanded in b around 0 82.6%
sub-neg82.6%
remove-double-neg82.6%
distribute-neg-frac82.6%
distribute-frac-neg282.6%
*-rgt-identity82.6%
associate-*r/82.4%
*-commutative82.4%
mul-1-neg82.4%
associate-*r/82.4%
unpow282.4%
times-frac86.8%
metadata-eval86.8%
distribute-neg-frac86.8%
distribute-frac-neg286.8%
distribute-lft-in87.8%
neg-mul-187.8%
fma-define87.8%
*-commutative87.8%
distribute-frac-neg287.8%
distribute-rgt-neg-in87.8%
distribute-lft-neg-out87.8%
associate-*r/88.0%
Simplified86.5%
Final simplification76.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8.4e-16) (not (<= d 5.4e-31))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8.4e-16) || !(d <= 5.4e-31)) {
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 <= (-8.4d-16)) .or. (.not. (d <= 5.4d-31))) 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 <= -8.4e-16) || !(d <= 5.4e-31)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8.4e-16) or not (d <= 5.4e-31): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8.4e-16) || !(d <= 5.4e-31)) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -8.4e-16) || ~((d <= 5.4e-31))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8.4e-16], N[Not[LessEqual[d, 5.4e-31]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.4 \cdot 10^{-16} \lor \neg \left(d \leq 5.4 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -8.4000000000000004e-16 or 5.40000000000000027e-31 < d Initial program 51.1%
fmm-def51.1%
distribute-rgt-neg-out51.1%
+-commutative51.1%
fma-define51.1%
Simplified51.1%
Taylor expanded in c around 0 65.6%
associate-*r/65.6%
neg-mul-165.6%
Simplified65.6%
if -8.4000000000000004e-16 < d < 5.40000000000000027e-31Initial program 71.8%
fmm-def71.8%
distribute-rgt-neg-out71.8%
+-commutative71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in c around inf 72.2%
Final simplification68.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.5e+190) (not (<= d 2.35e+169))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.5e+190) || !(d <= 2.35e+169)) {
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 <= (-6.5d+190)) .or. (.not. (d <= 2.35d+169))) 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 <= -6.5e+190) || !(d <= 2.35e+169)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.5e+190) or not (d <= 2.35e+169): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.5e+190) || !(d <= 2.35e+169)) tmp = 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 <= -6.5e+190) || ~((d <= 2.35e+169))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.5e+190], N[Not[LessEqual[d, 2.35e+169]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.5 \cdot 10^{+190} \lor \neg \left(d \leq 2.35 \cdot 10^{+169}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -6.5000000000000001e190 or 2.3499999999999999e169 < d Initial program 31.1%
fmm-def31.1%
distribute-rgt-neg-out31.1%
+-commutative31.1%
fma-define31.1%
Simplified31.1%
Taylor expanded in c around 0 81.5%
associate-*r/81.5%
neg-mul-181.5%
Simplified81.5%
neg-sub081.5%
sub-neg81.5%
add-sqr-sqrt50.3%
sqrt-unprod51.8%
sqr-neg51.8%
sqrt-unprod16.2%
add-sqr-sqrt32.3%
Applied egg-rr32.3%
+-lft-identity32.3%
Simplified32.3%
if -6.5000000000000001e190 < d < 2.3499999999999999e169Initial program 68.8%
fmm-def68.8%
distribute-rgt-neg-out68.8%
+-commutative68.8%
fma-define68.8%
Simplified68.8%
Taylor expanded in c around inf 52.9%
Final simplification48.1%
(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 60.1%
fmm-def60.1%
distribute-rgt-neg-out60.1%
+-commutative60.1%
fma-define60.1%
Simplified60.1%
Taylor expanded in c around 0 41.8%
associate-*r/41.8%
neg-mul-141.8%
Simplified41.8%
neg-sub041.8%
sub-neg41.8%
add-sqr-sqrt20.8%
sqrt-unprod22.6%
sqr-neg22.6%
sqrt-unprod6.0%
add-sqr-sqrt11.4%
Applied egg-rr11.4%
+-lft-identity11.4%
Simplified11.4%
(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 2024167
(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))))