
(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
(/ c (hypot c d))
(/ b (hypot c d))
(* a (/ (- d) (pow (hypot c d) 2.0))))))
(if (<= c -1.1e-76)
t_0
(if (<= c 2.25e-80)
(/ (- (/ b (/ d c)) a) d)
(if (<= c 9.2e+138) t_0 (/ (- b (* a (/ d c))) c))))))
double code(double a, double b, double c, double d) {
double t_0 = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (-d / pow(hypot(c, d), 2.0))));
double tmp;
if (c <= -1.1e-76) {
tmp = t_0;
} else if (c <= 2.25e-80) {
tmp = ((b / (d / c)) - a) / d;
} else if (c <= 9.2e+138) {
tmp = t_0;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0)))) tmp = 0.0 if (c <= -1.1e-76) tmp = t_0; elseif (c <= 2.25e-80) tmp = Float64(Float64(Float64(b / Float64(d / c)) - a) / d); elseif (c <= 9.2e+138) tmp = t_0; else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[((-d) / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.1e-76], t$95$0, If[LessEqual[c, 2.25e-80], N[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9.2e+138], t$95$0, N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
\mathbf{if}\;c \leq -1.1 \cdot 10^{-76}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.25 \cdot 10^{-80}:\\
\;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\
\mathbf{elif}\;c \leq 9.2 \cdot 10^{+138}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.1e-76 or 2.2500000000000001e-80 < c < 9.2000000000000003e138Initial program 69.7%
div-sub69.7%
*-commutative69.7%
add-sqr-sqrt69.7%
times-frac74.9%
fma-neg74.9%
hypot-define74.9%
hypot-define86.7%
associate-/l*89.3%
add-sqr-sqrt89.3%
pow289.3%
hypot-define89.3%
Applied egg-rr89.3%
if -1.1e-76 < c < 2.2500000000000001e-80Initial program 68.3%
Taylor expanded in c around 0 87.5%
+-commutative87.5%
mul-1-neg87.5%
unsub-neg87.5%
unpow287.5%
associate-/r*92.6%
div-sub92.5%
associate-/l*93.5%
Simplified93.5%
clear-num93.5%
un-div-inv93.5%
Applied egg-rr93.5%
if 9.2000000000000003e138 < c Initial program 37.3%
Taylor expanded in c around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
associate-/l*94.4%
Simplified94.4%
Final simplification91.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ 1.0 (hypot c d)))
(t_1 (* t_0 (/ (fma b c (* d (- a))) (hypot c d)))))
(if (<= c -2.7e+100)
(* t_0 (fma a (/ d c) (- b)))
(if (<= c -5.6e-80)
t_1
(if (<= c 3.4e-81)
(/ (- (/ b (/ d c)) a) d)
(if (<= c 9.8e+58) t_1 (/ (- b (* a (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double t_1 = t_0 * (fma(b, c, (d * -a)) / hypot(c, d));
double tmp;
if (c <= -2.7e+100) {
tmp = t_0 * fma(a, (d / c), -b);
} else if (c <= -5.6e-80) {
tmp = t_1;
} else if (c <= 3.4e-81) {
tmp = ((b / (d / c)) - a) / d;
} else if (c <= 9.8e+58) {
tmp = t_1;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) t_1 = Float64(t_0 * Float64(fma(b, c, Float64(d * Float64(-a))) / hypot(c, d))) tmp = 0.0 if (c <= -2.7e+100) tmp = Float64(t_0 * fma(a, Float64(d / c), Float64(-b))); elseif (c <= -5.6e-80) tmp = t_1; elseif (c <= 3.4e-81) tmp = Float64(Float64(Float64(b / Float64(d / c)) - a) / d); elseif (c <= 9.8e+58) tmp = t_1; else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.7e+100], N[(t$95$0 * N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -5.6e-80], t$95$1, If[LessEqual[c, 3.4e-81], N[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9.8e+58], t$95$1, N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := t\_0 \cdot \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+100}:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(a, \frac{d}{c}, -b\right)\\
\mathbf{elif}\;c \leq -5.6 \cdot 10^{-80}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 3.4 \cdot 10^{-81}:\\
\;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\
\mathbf{elif}\;c \leq 9.8 \cdot 10^{+58}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -2.69999999999999998e100Initial program 44.3%
*-un-lft-identity44.3%
add-sqr-sqrt44.3%
times-frac44.4%
hypot-define44.4%
fma-neg44.4%
distribute-rgt-neg-in44.4%
hypot-define56.2%
Applied egg-rr56.2%
Taylor expanded in c around -inf 83.5%
+-commutative83.5%
associate-/l*86.1%
fma-define86.1%
mul-1-neg86.1%
Simplified86.1%
if -2.69999999999999998e100 < c < -5.59999999999999978e-80 or 3.3999999999999999e-81 < c < 9.80000000000000037e58Initial program 88.2%
*-un-lft-identity88.2%
add-sqr-sqrt88.2%
times-frac88.0%
hypot-define88.0%
fma-neg88.0%
distribute-rgt-neg-in88.0%
hypot-define93.8%
Applied egg-rr93.8%
if -5.59999999999999978e-80 < c < 3.3999999999999999e-81Initial program 68.3%
Taylor expanded in c around 0 87.5%
+-commutative87.5%
mul-1-neg87.5%
unsub-neg87.5%
unpow287.5%
associate-/r*92.6%
div-sub92.5%
associate-/l*93.5%
Simplified93.5%
clear-num93.5%
un-div-inv93.5%
Applied egg-rr93.5%
if 9.80000000000000037e58 < c Initial program 43.0%
Taylor expanded in c around inf 82.6%
mul-1-neg82.6%
unsub-neg82.6%
associate-/l*86.7%
Simplified86.7%
Final simplification91.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= c -1.2e+100)
(* (/ 1.0 (hypot c d)) (fma a (/ d c) (- b)))
(if (<= c -8e-81)
t_0
(if (<= c 2.65e-76)
(/ (- (/ b (/ d c)) a) d)
(if (<= c 9.8e+58) t_0 (/ (- b (* a (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.2e+100) {
tmp = (1.0 / hypot(c, d)) * fma(a, (d / c), -b);
} else if (c <= -8e-81) {
tmp = t_0;
} else if (c <= 2.65e-76) {
tmp = ((b / (d / c)) - a) / d;
} else if (c <= 9.8e+58) {
tmp = t_0;
} else {
tmp = (b - (a * (d / c))) / c;
}
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))) tmp = 0.0 if (c <= -1.2e+100) tmp = Float64(Float64(1.0 / hypot(c, d)) * fma(a, Float64(d / c), Float64(-b))); elseif (c <= -8e-81) tmp = t_0; elseif (c <= 2.65e-76) tmp = Float64(Float64(Float64(b / Float64(d / c)) - a) / d); elseif (c <= 9.8e+58) tmp = t_0; else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return 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]}, If[LessEqual[c, -1.2e+100], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8e-81], t$95$0, If[LessEqual[c, 2.65e-76], N[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9.8e+58], t$95$0, N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -1.2 \cdot 10^{+100}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \mathsf{fma}\left(a, \frac{d}{c}, -b\right)\\
\mathbf{elif}\;c \leq -8 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.65 \cdot 10^{-76}:\\
\;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\
\mathbf{elif}\;c \leq 9.8 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.20000000000000006e100Initial program 44.3%
*-un-lft-identity44.3%
add-sqr-sqrt44.3%
times-frac44.4%
hypot-define44.4%
fma-neg44.4%
distribute-rgt-neg-in44.4%
hypot-define56.2%
Applied egg-rr56.2%
Taylor expanded in c around -inf 83.5%
+-commutative83.5%
associate-/l*86.1%
fma-define86.1%
mul-1-neg86.1%
Simplified86.1%
if -1.20000000000000006e100 < c < -7.9999999999999997e-81 or 2.65e-76 < c < 9.80000000000000037e58Initial program 88.2%
if -7.9999999999999997e-81 < c < 2.65e-76Initial program 68.3%
Taylor expanded in c around 0 87.5%
+-commutative87.5%
mul-1-neg87.5%
unsub-neg87.5%
unpow287.5%
associate-/r*92.6%
div-sub92.5%
associate-/l*93.5%
Simplified93.5%
clear-num93.5%
un-div-inv93.5%
Applied egg-rr93.5%
if 9.80000000000000037e58 < c Initial program 43.0%
Taylor expanded in c around inf 82.6%
mul-1-neg82.6%
unsub-neg82.6%
associate-/l*86.7%
Simplified86.7%
Final simplification89.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (/ (- b (* a (/ d c))) c)))
(if (<= c -9e+99)
t_1
(if (<= c -8.5e-78)
t_0
(if (<= c 4.8e-81)
(/ (- (/ b (/ d c)) a) d)
(if (<= c 2e+58) 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 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -9e+99) {
tmp = t_1;
} else if (c <= -8.5e-78) {
tmp = t_0;
} else if (c <= 4.8e-81) {
tmp = ((b / (d / c)) - a) / d;
} else if (c <= 2e+58) {
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 = (b - (a * (d / c))) / c
if (c <= (-9d+99)) then
tmp = t_1
else if (c <= (-8.5d-78)) then
tmp = t_0
else if (c <= 4.8d-81) then
tmp = ((b / (d / c)) - a) / d
else if (c <= 2d+58) 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 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -9e+99) {
tmp = t_1;
} else if (c <= -8.5e-78) {
tmp = t_0;
} else if (c <= 4.8e-81) {
tmp = ((b / (d / c)) - a) / d;
} else if (c <= 2e+58) {
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 = (b - (a * (d / c))) / c tmp = 0 if c <= -9e+99: tmp = t_1 elif c <= -8.5e-78: tmp = t_0 elif c <= 4.8e-81: tmp = ((b / (d / c)) - a) / d elif c <= 2e+58: 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(b - Float64(a * Float64(d / c))) / c) tmp = 0.0 if (c <= -9e+99) tmp = t_1; elseif (c <= -8.5e-78) tmp = t_0; elseif (c <= 4.8e-81) tmp = Float64(Float64(Float64(b / Float64(d / c)) - a) / d); elseif (c <= 2e+58) 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 = (b - (a * (d / c))) / c; tmp = 0.0; if (c <= -9e+99) tmp = t_1; elseif (c <= -8.5e-78) tmp = t_0; elseif (c <= 4.8e-81) tmp = ((b / (d / c)) - a) / d; elseif (c <= 2e+58) 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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -9e+99], t$95$1, If[LessEqual[c, -8.5e-78], t$95$0, If[LessEqual[c, 4.8e-81], N[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2e+58], 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{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -9 \cdot 10^{+99}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -8.5 \cdot 10^{-78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.8 \cdot 10^{-81}:\\
\;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\
\mathbf{elif}\;c \leq 2 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -8.9999999999999999e99 or 1.99999999999999989e58 < c Initial program 43.6%
Taylor expanded in c around inf 82.8%
mul-1-neg82.8%
unsub-neg82.8%
associate-/l*86.2%
Simplified86.2%
if -8.9999999999999999e99 < c < -8.49999999999999957e-78 or 4.7999999999999998e-81 < c < 1.99999999999999989e58Initial program 88.2%
if -8.49999999999999957e-78 < c < 4.7999999999999998e-81Initial program 68.3%
Taylor expanded in c around 0 87.5%
+-commutative87.5%
mul-1-neg87.5%
unsub-neg87.5%
unpow287.5%
associate-/r*92.6%
div-sub92.5%
associate-/l*93.5%
Simplified93.5%
clear-num93.5%
un-div-inv93.5%
Applied egg-rr93.5%
Final simplification89.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.3e-48) (not (<= c 1.15e+37))) (/ (- b (* a (/ d c))) c) (/ (- (/ b (/ d c)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.3e-48) || !(c <= 1.15e+37)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b / (d / c)) - 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 <= (-1.3d-48)) .or. (.not. (c <= 1.15d+37))) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((b / (d / c)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.3e-48) || !(c <= 1.15e+37)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b / (d / c)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.3e-48) or not (c <= 1.15e+37): tmp = (b - (a * (d / c))) / c else: tmp = ((b / (d / c)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.3e-48) || !(c <= 1.15e+37)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(b / Float64(d / c)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.3e-48) || ~((c <= 1.15e+37))) tmp = (b - (a * (d / c))) / c; else tmp = ((b / (d / c)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.3e-48], N[Not[LessEqual[c, 1.15e+37]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.3 \cdot 10^{-48} \lor \neg \left(c \leq 1.15 \cdot 10^{+37}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\
\end{array}
\end{array}
if c < -1.29999999999999994e-48 or 1.15000000000000001e37 < c Initial program 54.4%
Taylor expanded in c around inf 79.5%
mul-1-neg79.5%
unsub-neg79.5%
associate-/l*82.1%
Simplified82.1%
if -1.29999999999999994e-48 < c < 1.15000000000000001e37Initial program 73.3%
Taylor expanded in c around 0 83.3%
+-commutative83.3%
mul-1-neg83.3%
unsub-neg83.3%
unpow283.3%
associate-/r*87.0%
div-sub87.1%
associate-/l*87.8%
Simplified87.8%
clear-num87.8%
un-div-inv87.8%
Applied egg-rr87.8%
Final simplification85.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e-49) (not (<= c 6.5e+33))) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e-49) || !(c <= 6.5e+33)) {
tmp = (b - (a * (d / c))) / 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.6d-49)) .or. (.not. (c <= 6.5d+33))) then
tmp = (b - (a * (d / c))) / 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.6e-49) || !(c <= 6.5e+33)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.6e-49) or not (c <= 6.5e+33): tmp = (b - (a * (d / c))) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e-49) || !(c <= 6.5e+33)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / 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.6e-49) || ~((c <= 6.5e+33))) tmp = (b - (a * (d / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e-49], N[Not[LessEqual[c, 6.5e+33]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 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.6 \cdot 10^{-49} \lor \neg \left(c \leq 6.5 \cdot 10^{+33}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.59999999999999995e-49 or 6.49999999999999993e33 < c Initial program 54.4%
Taylor expanded in c around inf 79.5%
mul-1-neg79.5%
unsub-neg79.5%
associate-/l*82.1%
Simplified82.1%
if -2.59999999999999995e-49 < c < 6.49999999999999993e33Initial program 73.3%
Taylor expanded in c around 0 83.3%
+-commutative83.3%
mul-1-neg83.3%
unsub-neg83.3%
unpow283.3%
associate-/r*87.0%
div-sub87.1%
associate-/l*87.8%
Simplified87.8%
Final simplification85.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.9e-53) (not (<= c 2.5e+33))) (/ (- b (* a (/ d c))) c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.9e-53) || !(c <= 2.5e+33)) {
tmp = (b - (a * (d / c))) / 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 ((c <= (-1.9d-53)) .or. (.not. (c <= 2.5d+33))) then
tmp = (b - (a * (d / c))) / 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 ((c <= -1.9e-53) || !(c <= 2.5e+33)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.9e-53) or not (c <= 2.5e+33): tmp = (b - (a * (d / c))) / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.9e-53) || !(c <= 2.5e+33)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.9e-53) || ~((c <= 2.5e+33))) tmp = (b - (a * (d / c))) / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.9e-53], N[Not[LessEqual[c, 2.5e+33]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{-53} \lor \neg \left(c \leq 2.5 \cdot 10^{+33}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -1.8999999999999999e-53 or 2.49999999999999986e33 < c Initial program 54.3%
Taylor expanded in c around inf 78.6%
mul-1-neg78.6%
unsub-neg78.6%
associate-/l*81.2%
Simplified81.2%
if -1.8999999999999999e-53 < c < 2.49999999999999986e33Initial program 73.9%
Taylor expanded in c around 0 71.8%
associate-*r/71.8%
neg-mul-171.8%
Simplified71.8%
Final simplification76.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -9.4e+64) (not (<= c 3.3e+46))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9.4e+64) || !(c <= 3.3e+46)) {
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 ((c <= (-9.4d+64)) .or. (.not. (c <= 3.3d+46))) 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 ((c <= -9.4e+64) || !(c <= 3.3e+46)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -9.4e+64) or not (c <= 3.3e+46): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -9.4e+64) || !(c <= 3.3e+46)) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -9.4e+64) || ~((c <= 3.3e+46))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -9.4e+64], N[Not[LessEqual[c, 3.3e+46]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.4 \cdot 10^{+64} \lor \neg \left(c \leq 3.3 \cdot 10^{+46}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -9.40000000000000058e64 or 3.2999999999999998e46 < c Initial program 48.1%
Taylor expanded in c around inf 73.3%
if -9.40000000000000058e64 < c < 3.2999999999999998e46Initial program 74.8%
Taylor expanded in c around 0 65.8%
associate-*r/65.8%
neg-mul-165.8%
Simplified65.8%
Final simplification68.7%
(FPCore (a b c d) :precision binary64 (if (<= d 5.8e+187) (/ b c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 5.8e+187) {
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 <= 5.8d+187) 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 <= 5.8e+187) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 5.8e+187: tmp = b / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 5.8e+187) 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 <= 5.8e+187) tmp = b / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 5.8e+187], N[(b / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 5.8 \cdot 10^{+187}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 5.8000000000000002e187Initial program 65.5%
Taylor expanded in c around inf 41.1%
if 5.8000000000000002e187 < d Initial program 54.8%
Taylor expanded in c around 0 83.6%
+-commutative83.6%
mul-1-neg83.6%
unsub-neg83.6%
unpow283.6%
associate-/r*79.9%
div-sub79.9%
*-commutative79.9%
associate-/l*88.1%
fma-neg88.1%
Simplified88.1%
Taylor expanded in d around 0 55.6%
neg-mul-155.6%
+-commutative55.6%
sub-neg55.6%
*-commutative55.6%
*-commutative55.6%
Simplified55.6%
clear-num55.6%
inv-pow55.6%
Applied egg-rr51.0%
unpow-151.0%
*-rgt-identity51.0%
associate-*r/51.0%
*-commutative51.0%
fma-define51.0%
+-commutative51.0%
distribute-rgt-in51.0%
/-rgt-identity51.0%
times-frac51.0%
*-commutative51.0%
times-frac51.0%
metadata-eval51.0%
associate-/l*51.4%
*-inverses51.4%
*-rgt-identity51.4%
*-lft-identity51.4%
*-commutative51.4%
*-commutative51.4%
/-rgt-identity51.4%
associate-/r/51.4%
associate-*l/51.4%
Simplified51.4%
Taylor expanded in d around inf 55.3%
(FPCore (a b c d) :precision binary64 (if (<= d 3e+83) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 3e+83) {
tmp = a / 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 <= 3d+83) then
tmp = a / 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 <= 3e+83) {
tmp = a / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 3e+83: tmp = a / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 3e+83) tmp = Float64(a / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 3e+83) tmp = a / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 3e+83], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 3 \cdot 10^{+83}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 3e83Initial program 67.8%
*-un-lft-identity67.8%
add-sqr-sqrt67.8%
times-frac67.7%
hypot-define67.8%
fma-neg67.8%
distribute-rgt-neg-in67.8%
hypot-define77.7%
Applied egg-rr77.7%
Taylor expanded in c around inf 33.1%
mul-1-neg33.1%
unsub-neg33.1%
associate-/l*34.0%
Simplified34.0%
Taylor expanded in d around -inf 7.4%
if 3e83 < d Initial program 51.7%
Taylor expanded in c around 0 74.3%
+-commutative74.3%
mul-1-neg74.3%
unsub-neg74.3%
unpow274.3%
associate-/r*72.7%
div-sub72.7%
*-commutative72.7%
associate-/l*78.4%
fma-neg78.4%
Simplified78.4%
Taylor expanded in d around 0 54.5%
neg-mul-154.5%
+-commutative54.5%
sub-neg54.5%
*-commutative54.5%
*-commutative54.5%
Simplified54.5%
clear-num54.3%
inv-pow54.3%
Applied egg-rr29.9%
unpow-129.9%
*-rgt-identity29.9%
associate-*r/29.9%
*-commutative29.9%
fma-define29.9%
+-commutative29.9%
distribute-rgt-in29.9%
/-rgt-identity29.9%
times-frac29.9%
*-commutative29.9%
times-frac29.9%
metadata-eval29.9%
associate-/l*30.2%
*-inverses30.2%
*-rgt-identity30.2%
*-lft-identity30.2%
*-commutative30.2%
*-commutative30.2%
/-rgt-identity30.2%
associate-/r/30.2%
associate-*l/30.1%
Simplified32.1%
Taylor expanded in d around inf 32.3%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 64.5%
*-un-lft-identity64.5%
add-sqr-sqrt64.5%
times-frac64.4%
hypot-define64.4%
fma-neg64.4%
distribute-rgt-neg-in64.4%
hypot-define75.1%
Applied egg-rr75.1%
Taylor expanded in c around inf 30.4%
mul-1-neg30.4%
unsub-neg30.4%
associate-/l*31.1%
Simplified31.1%
Taylor expanded in d around -inf 8.2%
(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 2024106
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(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))))