
(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 9 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 (<= c -5e+102)
(/ (fma a (* d (/ 1.0 c)) (- b)) (- c))
(if (<= c 7.2e+113)
(*
(/ 1.0 (hypot c d))
(- (/ (* c b) (hypot c d)) (* d (/ a (hypot c d)))))
(/ (- b (* d (/ a c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5e+102) {
tmp = fma(a, (d * (1.0 / c)), -b) / -c;
} else if (c <= 7.2e+113) {
tmp = (1.0 / hypot(c, d)) * (((c * b) / hypot(c, d)) - (d * (a / hypot(c, d))));
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5e+102) tmp = Float64(fma(a, Float64(d * Float64(1.0 / c)), Float64(-b)) / Float64(-c)); elseif (c <= 7.2e+113) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(Float64(c * b) / hypot(c, d)) - Float64(d * Float64(a / hypot(c, d))))); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5e+102], N[(N[(a * N[(d * N[(1.0 / c), $MachinePrecision]), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], If[LessEqual[c, 7.2e+113], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(c * b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] - N[(d * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5 \cdot 10^{+102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, d \cdot \frac{1}{c}, -b\right)}{-c}\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{+113}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c \cdot b}{\mathsf{hypot}\left(c, d\right)} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -5e102Initial program 22.4%
fmm-def22.4%
distribute-rgt-neg-out22.4%
+-commutative22.4%
fma-define22.4%
Simplified22.4%
Taylor expanded in c around -inf 80.2%
mul-1-neg80.2%
distribute-neg-frac280.2%
+-commutative80.2%
associate-/l*86.2%
fma-define86.2%
mul-1-neg86.2%
Simplified86.2%
div-inv86.3%
Applied egg-rr86.3%
if -5e102 < c < 7.19999999999999984e113Initial program 66.5%
add-cube-cbrt66.1%
pow366.2%
Applied egg-rr66.2%
*-un-lft-identity66.2%
metadata-eval66.2%
times-frac66.2%
*-un-lft-identity66.2%
add-sqr-sqrt66.2%
times-frac66.1%
hypot-define66.1%
*-commutative66.1%
rem-cube-cbrt66.5%
*-commutative66.5%
hypot-define78.4%
Applied egg-rr78.4%
div-sub78.4%
*-un-lft-identity78.4%
times-frac93.7%
/-rgt-identity93.7%
Applied egg-rr93.7%
if 7.19999999999999984e113 < c Initial program 31.6%
fmm-def31.6%
distribute-rgt-neg-out31.6%
+-commutative31.6%
fma-define31.6%
Simplified31.6%
Taylor expanded in c around inf 77.5%
mul-1-neg77.5%
unsub-neg77.5%
*-commutative77.5%
associate-/l*87.1%
Simplified87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ 1.0 (hypot c d)) (/ (- (* c b) (* a d)) (hypot c d)))))
(if (<= d -7.5e+129)
(/ (- (/ b (/ d c)) a) d)
(if (<= d -1.6e-54)
t_0
(if (<= d 5.4e-199)
(/ (- b (/ (* a d) c)) c)
(if (<= d 5e+83) t_0 (/ (- (* c (/ b d)) a) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / hypot(c, d)) * (((c * b) - (a * d)) / hypot(c, d));
double tmp;
if (d <= -7.5e+129) {
tmp = ((b / (d / c)) - a) / d;
} else if (d <= -1.6e-54) {
tmp = t_0;
} else if (d <= 5.4e-199) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 5e+83) {
tmp = t_0;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (1.0 / Math.hypot(c, d)) * (((c * b) - (a * d)) / Math.hypot(c, d));
double tmp;
if (d <= -7.5e+129) {
tmp = ((b / (d / c)) - a) / d;
} else if (d <= -1.6e-54) {
tmp = t_0;
} else if (d <= 5.4e-199) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 5e+83) {
tmp = t_0;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (1.0 / math.hypot(c, d)) * (((c * b) - (a * d)) / math.hypot(c, d)) tmp = 0 if d <= -7.5e+129: tmp = ((b / (d / c)) - a) / d elif d <= -1.6e-54: tmp = t_0 elif d <= 5.4e-199: tmp = (b - ((a * d) / c)) / c elif d <= 5e+83: tmp = t_0 else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(Float64(c * b) - Float64(a * d)) / hypot(c, d))) tmp = 0.0 if (d <= -7.5e+129) tmp = Float64(Float64(Float64(b / Float64(d / c)) - a) / d); elseif (d <= -1.6e-54) tmp = t_0; elseif (d <= 5.4e-199) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 5e+83) tmp = t_0; else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (1.0 / hypot(c, d)) * (((c * b) - (a * d)) / hypot(c, d)); tmp = 0.0; if (d <= -7.5e+129) tmp = ((b / (d / c)) - a) / d; elseif (d <= -1.6e-54) tmp = t_0; elseif (d <= 5.4e-199) tmp = (b - ((a * d) / c)) / c; elseif (d <= 5e+83) tmp = t_0; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.5e+129], N[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.6e-54], t$95$0, If[LessEqual[d, 5.4e-199], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5e+83], t$95$0, N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -7.5 \cdot 10^{+129}:\\
\;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\
\mathbf{elif}\;d \leq -1.6 \cdot 10^{-54}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5.4 \cdot 10^{-199}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 5 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -7.4999999999999998e129Initial program 30.4%
fmm-def30.4%
distribute-rgt-neg-out30.4%
+-commutative30.4%
fma-define30.4%
Simplified30.4%
Taylor expanded in d around -inf 77.5%
mul-1-neg77.5%
distribute-neg-frac277.5%
mul-1-neg77.5%
unsub-neg77.5%
*-commutative77.5%
associate-/l*84.4%
Simplified84.4%
clear-num84.3%
un-div-inv84.3%
Applied egg-rr84.3%
Taylor expanded in d around inf 77.5%
+-commutative77.5%
neg-mul-177.5%
sub-neg77.5%
associate-*r/84.3%
Simplified84.3%
clear-num84.3%
un-div-inv84.4%
Applied egg-rr84.4%
if -7.4999999999999998e129 < d < -1.59999999999999999e-54 or 5.39999999999999979e-199 < d < 5.00000000000000029e83Initial program 74.4%
add-cube-cbrt73.9%
pow373.9%
Applied egg-rr73.9%
*-un-lft-identity73.9%
metadata-eval73.9%
times-frac73.9%
*-un-lft-identity73.9%
add-sqr-sqrt73.9%
times-frac73.7%
hypot-define73.8%
*-commutative73.8%
rem-cube-cbrt74.3%
*-commutative74.3%
hypot-define84.9%
Applied egg-rr84.9%
if -1.59999999999999999e-54 < d < 5.39999999999999979e-199Initial program 57.5%
fmm-def57.5%
distribute-rgt-neg-out57.5%
+-commutative57.5%
fma-define57.5%
Simplified57.5%
Taylor expanded in c around inf 91.6%
associate-*r/91.6%
neg-mul-191.6%
distribute-rgt-neg-in91.6%
Simplified91.6%
if 5.00000000000000029e83 < d Initial program 37.3%
fmm-def37.4%
distribute-rgt-neg-out37.4%
+-commutative37.4%
fma-define37.4%
Simplified37.4%
Taylor expanded in d around -inf 81.3%
mul-1-neg81.3%
distribute-neg-frac281.3%
mul-1-neg81.3%
unsub-neg81.3%
*-commutative81.3%
associate-/l*85.7%
Simplified85.7%
clear-num85.7%
un-div-inv85.7%
Applied egg-rr85.7%
Taylor expanded in d around inf 81.3%
+-commutative81.3%
neg-mul-181.3%
sub-neg81.3%
associate-*r/85.6%
Simplified85.6%
clear-num85.7%
un-div-inv85.7%
Applied egg-rr85.7%
associate-/r/85.7%
Simplified85.7%
Final simplification87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* a d)) (+ (* c c) (* d d))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.56e+25)
t_1
(if (<= d -3.3e-54)
t_0
(if (<= d 5.8e-130)
(/ (- b (/ (* a d) c)) c)
(if (<= d 5.2e+83) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.56e+25) {
tmp = t_1;
} else if (d <= -3.3e-54) {
tmp = t_0;
} else if (d <= 5.8e-130) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 5.2e+83) {
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) - (a * d)) / ((c * c) + (d * d))
t_1 = ((c * (b / d)) - a) / d
if (d <= (-1.56d+25)) then
tmp = t_1
else if (d <= (-3.3d-54)) then
tmp = t_0
else if (d <= 5.8d-130) then
tmp = (b - ((a * d) / c)) / c
else if (d <= 5.2d+83) 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) - (a * d)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.56e+25) {
tmp = t_1;
} else if (d <= -3.3e-54) {
tmp = t_0;
} else if (d <= 5.8e-130) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 5.2e+83) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d)) t_1 = ((c * (b / d)) - a) / d tmp = 0 if d <= -1.56e+25: tmp = t_1 elif d <= -3.3e-54: tmp = t_0 elif d <= 5.8e-130: tmp = (b - ((a * d) / c)) / c elif d <= 5.2e+83: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -1.56e+25) tmp = t_1; elseif (d <= -3.3e-54) tmp = t_0; elseif (d <= 5.8e-130) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 5.2e+83) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (a * d)) / ((c * c) + (d * d)); t_1 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -1.56e+25) tmp = t_1; elseif (d <= -3.3e-54) tmp = t_0; elseif (d <= 5.8e-130) tmp = (b - ((a * d) / c)) / c; elseif (d <= 5.2e+83) 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[(a * d), $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.56e+25], t$95$1, If[LessEqual[d, -3.3e-54], t$95$0, If[LessEqual[d, 5.8e-130], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.2e+83], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.56 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -3.3 \cdot 10^{-54}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 5.8 \cdot 10^{-130}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 5.2 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.5599999999999999e25 or 5.2000000000000002e83 < d Initial program 38.2%
fmm-def38.2%
distribute-rgt-neg-out38.2%
+-commutative38.2%
fma-define38.2%
Simplified38.2%
Taylor expanded in d around -inf 77.2%
mul-1-neg77.2%
distribute-neg-frac277.2%
mul-1-neg77.2%
unsub-neg77.2%
*-commutative77.2%
associate-/l*82.0%
Simplified82.0%
clear-num82.0%
un-div-inv82.0%
Applied egg-rr82.0%
Taylor expanded in d around inf 77.2%
+-commutative77.2%
neg-mul-177.2%
sub-neg77.2%
associate-*r/81.1%
Simplified81.1%
clear-num81.1%
un-div-inv81.1%
Applied egg-rr81.1%
associate-/r/82.0%
Simplified82.0%
if -1.5599999999999999e25 < d < -3.29999999999999993e-54 or 5.8e-130 < d < 5.2000000000000002e83Initial program 80.4%
if -3.29999999999999993e-54 < d < 5.8e-130Initial program 58.5%
fmm-def58.5%
distribute-rgt-neg-out58.5%
+-commutative58.5%
fma-define58.5%
Simplified58.5%
Taylor expanded in c around inf 90.8%
associate-*r/90.8%
neg-mul-190.8%
distribute-rgt-neg-in90.8%
Simplified90.8%
Final simplification85.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.25e+28) (not (<= c 1.32e+44))) (/ (- b (* d (/ a c))) c) (/ (- (* c (/ b d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.25e+28) || !(c <= 1.32e+44)) {
tmp = (b - (d * (a / c))) / 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 <= (-1.25d+28)) .or. (.not. (c <= 1.32d+44))) then
tmp = (b - (d * (a / c))) / 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 <= -1.25e+28) || !(c <= 1.32e+44)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.25e+28) or not (c <= 1.32e+44): tmp = (b - (d * (a / c))) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.25e+28) || !(c <= 1.32e+44)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / 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 <= -1.25e+28) || ~((c <= 1.32e+44))) tmp = (b - (d * (a / c))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.25e+28], N[Not[LessEqual[c, 1.32e+44]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 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 -1.25 \cdot 10^{+28} \lor \neg \left(c \leq 1.32 \cdot 10^{+44}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -1.24999999999999989e28 or 1.3200000000000001e44 < c Initial program 39.2%
fmm-def39.2%
distribute-rgt-neg-out39.2%
+-commutative39.2%
fma-define39.2%
Simplified39.2%
Taylor expanded in c around inf 73.9%
mul-1-neg73.9%
unsub-neg73.9%
*-commutative73.9%
associate-/l*79.9%
Simplified79.9%
if -1.24999999999999989e28 < c < 1.3200000000000001e44Initial program 65.3%
fmm-def65.4%
distribute-rgt-neg-out65.4%
+-commutative65.4%
fma-define65.4%
Simplified65.4%
Taylor expanded in d around -inf 81.7%
mul-1-neg81.7%
distribute-neg-frac281.7%
mul-1-neg81.7%
unsub-neg81.7%
*-commutative81.7%
associate-/l*81.7%
Simplified81.7%
clear-num81.7%
un-div-inv81.7%
Applied egg-rr81.7%
Taylor expanded in d around inf 81.7%
+-commutative81.7%
neg-mul-181.7%
sub-neg81.7%
associate-*r/81.5%
Simplified81.5%
clear-num81.5%
un-div-inv81.5%
Applied egg-rr81.5%
associate-/r/81.7%
Simplified81.7%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.6e+27) (not (<= c 1.3e+44))) (/ (- b (* d (/ a c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.6e+27) || !(c <= 1.3e+44)) {
tmp = (b - (d * (a / 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 <= (-7.6d+27)) .or. (.not. (c <= 1.3d+44))) then
tmp = (b - (d * (a / 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 <= -7.6e+27) || !(c <= 1.3e+44)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -7.6e+27) or not (c <= 1.3e+44): tmp = (b - (d * (a / c))) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.6e+27) || !(c <= 1.3e+44)) tmp = Float64(Float64(b - Float64(d * Float64(a / 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 <= -7.6e+27) || ~((c <= 1.3e+44))) tmp = (b - (d * (a / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.6e+27], N[Not[LessEqual[c, 1.3e+44]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / 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 -7.6 \cdot 10^{+27} \lor \neg \left(c \leq 1.3 \cdot 10^{+44}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -7.60000000000000043e27 or 1.3e44 < c Initial program 39.2%
fmm-def39.2%
distribute-rgt-neg-out39.2%
+-commutative39.2%
fma-define39.2%
Simplified39.2%
Taylor expanded in c around inf 73.9%
mul-1-neg73.9%
unsub-neg73.9%
*-commutative73.9%
associate-/l*79.9%
Simplified79.9%
if -7.60000000000000043e27 < c < 1.3e44Initial program 65.3%
fmm-def65.4%
distribute-rgt-neg-out65.4%
+-commutative65.4%
fma-define65.4%
Simplified65.4%
Taylor expanded in d around -inf 81.7%
mul-1-neg81.7%
distribute-neg-frac281.7%
mul-1-neg81.7%
unsub-neg81.7%
*-commutative81.7%
associate-/l*81.7%
Simplified81.7%
clear-num81.7%
un-div-inv81.7%
Applied egg-rr81.7%
Taylor expanded in d around inf 81.7%
+-commutative81.7%
neg-mul-181.7%
sub-neg81.7%
associate-*r/81.5%
Simplified81.5%
Final simplification80.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.25e+49) (not (<= d 1.5e+76))) (/ (- a) d) (/ (- b (* d (/ a c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.25e+49) || !(d <= 1.5e+76)) {
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.25d+49)) .or. (.not. (d <= 1.5d+76))) 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.25e+49) || !(d <= 1.5e+76)) {
tmp = -a / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.25e+49) or not (d <= 1.5e+76): tmp = -a / d else: tmp = (b - (d * (a / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.25e+49) || !(d <= 1.5e+76)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.25e+49) || ~((d <= 1.5e+76))) 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.25e+49], N[Not[LessEqual[d, 1.5e+76]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{+49} \lor \neg \left(d \leq 1.5 \cdot 10^{+76}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if d < -1.2500000000000001e49 or 1.4999999999999999e76 < d Initial program 41.5%
fmm-def41.5%
distribute-rgt-neg-out41.5%
+-commutative41.5%
fma-define41.5%
Simplified41.5%
Taylor expanded in c around 0 71.2%
associate-*r/71.2%
neg-mul-171.2%
Simplified71.2%
if -1.2500000000000001e49 < d < 1.4999999999999999e76Initial program 63.7%
fmm-def63.7%
distribute-rgt-neg-out63.7%
+-commutative63.7%
fma-define63.7%
Simplified63.7%
Taylor expanded in c around inf 77.1%
mul-1-neg77.1%
unsub-neg77.1%
*-commutative77.1%
associate-/l*76.8%
Simplified76.8%
Final simplification74.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.6e+49) (not (<= d 1.25e-116))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.6e+49) || !(d <= 1.25e-116)) {
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 <= (-2.6d+49)) .or. (.not. (d <= 1.25d-116))) 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 <= -2.6e+49) || !(d <= 1.25e-116)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.6e+49) or not (d <= 1.25e-116): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.6e+49) || !(d <= 1.25e-116)) 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 <= -2.6e+49) || ~((d <= 1.25e-116))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.6e+49], N[Not[LessEqual[d, 1.25e-116]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.6 \cdot 10^{+49} \lor \neg \left(d \leq 1.25 \cdot 10^{-116}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.59999999999999989e49 or 1.2500000000000001e-116 < d Initial program 48.2%
fmm-def48.3%
distribute-rgt-neg-out48.3%
+-commutative48.3%
fma-define48.3%
Simplified48.3%
Taylor expanded in c around 0 64.4%
associate-*r/64.4%
neg-mul-164.4%
Simplified64.4%
if -2.59999999999999989e49 < d < 1.2500000000000001e-116Initial program 61.5%
fmm-def61.5%
distribute-rgt-neg-out61.5%
+-commutative61.5%
fma-define61.5%
Simplified61.5%
Taylor expanded in c around inf 70.2%
Final simplification67.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7e+138) (not (<= d 2.8e+184))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7e+138) || !(d <= 2.8e+184)) {
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 <= (-7d+138)) .or. (.not. (d <= 2.8d+184))) 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 <= -7e+138) || !(d <= 2.8e+184)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7e+138) or not (d <= 2.8e+184): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7e+138) || !(d <= 2.8e+184)) 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 <= -7e+138) || ~((d <= 2.8e+184))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7e+138], N[Not[LessEqual[d, 2.8e+184]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{+138} \lor \neg \left(d \leq 2.8 \cdot 10^{+184}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -6.9999999999999996e138 or 2.7999999999999999e184 < d Initial program 28.3%
fmm-def28.3%
distribute-rgt-neg-out28.3%
+-commutative28.3%
fma-define28.3%
Simplified28.3%
div-inv28.3%
fma-undefine28.3%
+-commutative28.3%
add-sqr-sqrt16.5%
sqrt-unprod25.9%
distribute-rgt-neg-out25.9%
distribute-rgt-neg-out25.9%
sqr-neg25.9%
sqrt-unprod11.8%
add-sqr-sqrt27.5%
add-sqr-sqrt27.5%
pow227.5%
hypot-define27.5%
Applied egg-rr27.5%
Taylor expanded in c around 0 28.7%
if -6.9999999999999996e138 < d < 2.7999999999999999e184Initial program 62.7%
fmm-def62.7%
distribute-rgt-neg-out62.7%
+-commutative62.7%
fma-define62.7%
Simplified62.7%
Taylor expanded in c around inf 51.8%
Final simplification46.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 54.2%
fmm-def54.2%
distribute-rgt-neg-out54.2%
+-commutative54.2%
fma-define54.2%
Simplified54.2%
div-inv54.1%
fma-undefine54.1%
+-commutative54.1%
add-sqr-sqrt31.3%
sqrt-unprod38.4%
distribute-rgt-neg-out38.4%
distribute-rgt-neg-out38.4%
sqr-neg38.4%
sqrt-unprod20.0%
add-sqr-sqrt34.0%
add-sqr-sqrt34.0%
pow234.0%
hypot-define34.0%
Applied egg-rr34.0%
Taylor expanded in c around 0 10.0%
(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 2024165
(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))))