
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* c b) (* a d))))
(if (<= c -3e+52)
(/ (- b (* a (/ d c))) c)
(if (<= c -2.3e-131)
(/ t_0 (fma c c (* d d)))
(if (<= c 3.9e-91)
(/ (- (/ (* c b) d) a) d)
(if (<= c 1e+39)
(/ t_0 (+ (* d d) (* c c)))
(/ (+ b (* a (/ -1.0 (/ c d)))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (a * d);
double tmp;
if (c <= -3e+52) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -2.3e-131) {
tmp = t_0 / fma(c, c, (d * d));
} else if (c <= 3.9e-91) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 1e+39) {
tmp = t_0 / ((d * d) + (c * c));
} else {
tmp = (b + (a * (-1.0 / (c / d)))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c * b) - Float64(a * d)) tmp = 0.0 if (c <= -3e+52) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= -2.3e-131) tmp = Float64(t_0 / fma(c, c, Float64(d * d))); elseif (c <= 3.9e-91) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); elseif (c <= 1e+39) tmp = Float64(t_0 / Float64(Float64(d * d) + Float64(c * c))); else tmp = Float64(Float64(b + Float64(a * Float64(-1.0 / Float64(c / d)))) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3e+52], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.3e-131], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.9e-91], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1e+39], N[(t$95$0 / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(-1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot b - a \cdot d\\
\mathbf{if}\;c \leq -3 \cdot 10^{+52}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -2.3 \cdot 10^{-131}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 3.9 \cdot 10^{-91}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 10^{+39}:\\
\;\;\;\;\frac{t\_0}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{-1}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -3e52Initial program 45.2%
Taylor expanded in c around inf 82.4%
mul-1-neg82.4%
remove-double-neg82.4%
mul-1-neg82.4%
distribute-neg-in82.4%
distribute-neg-in82.4%
mul-1-neg82.4%
remove-double-neg82.4%
unsub-neg82.4%
associate-/l*89.0%
Simplified89.0%
if -3e52 < c < -2.30000000000000022e-131Initial program 84.5%
fma-define84.5%
Simplified84.5%
if -2.30000000000000022e-131 < c < 3.89999999999999994e-91Initial program 68.1%
Taylor expanded in d around -inf 93.0%
mul-1-neg93.0%
distribute-neg-frac293.0%
mul-1-neg93.0%
unsub-neg93.0%
*-commutative93.0%
associate-/l*91.0%
Simplified91.0%
associate-*r/93.0%
*-commutative93.0%
clear-num93.0%
*-commutative93.0%
Applied egg-rr93.0%
Taylor expanded in a around 0 85.5%
neg-mul-185.5%
neg-sub085.5%
*-commutative85.5%
unpow285.5%
associate-/r*93.0%
*-lft-identity93.0%
associate-*l/93.0%
associate--r-93.0%
div-sub93.0%
neg-sub093.0%
distribute-neg-frac93.0%
Simplified92.0%
Taylor expanded in b around 0 93.0%
if 3.89999999999999994e-91 < c < 9.9999999999999994e38Initial program 89.1%
if 9.9999999999999994e38 < c Initial program 35.1%
Taylor expanded in c around inf 73.4%
mul-1-neg73.4%
remove-double-neg73.4%
mul-1-neg73.4%
distribute-neg-in73.4%
distribute-neg-in73.4%
mul-1-neg73.4%
remove-double-neg73.4%
unsub-neg73.4%
associate-/l*78.5%
Simplified78.5%
clear-num78.5%
inv-pow78.5%
Applied egg-rr78.5%
unpow-178.5%
Simplified78.5%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* a d)) (+ (* d d) (* c c)))))
(if (<= c -1.65e+50)
(/ (- b (* a (/ d c))) c)
(if (<= c -2.5e-131)
t_0
(if (<= c 3.4e-91)
(/ (- (/ (* c b) d) a) d)
(if (<= c 1e+39) t_0 (/ (+ b (* a (/ -1.0 (/ c d)))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (a * d)) / ((d * d) + (c * c));
double tmp;
if (c <= -1.65e+50) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -2.5e-131) {
tmp = t_0;
} else if (c <= 3.4e-91) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 1e+39) {
tmp = t_0;
} else {
tmp = (b + (a * (-1.0 / (c / d)))) / 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) :: t_0
real(8) :: tmp
t_0 = ((c * b) - (a * d)) / ((d * d) + (c * c))
if (c <= (-1.65d+50)) then
tmp = (b - (a * (d / c))) / c
else if (c <= (-2.5d-131)) then
tmp = t_0
else if (c <= 3.4d-91) then
tmp = (((c * b) / d) - a) / d
else if (c <= 1d+39) then
tmp = t_0
else
tmp = (b + (a * ((-1.0d0) / (c / d)))) / c
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)) / ((d * d) + (c * c));
double tmp;
if (c <= -1.65e+50) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -2.5e-131) {
tmp = t_0;
} else if (c <= 3.4e-91) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 1e+39) {
tmp = t_0;
} else {
tmp = (b + (a * (-1.0 / (c / d)))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (a * d)) / ((d * d) + (c * c)) tmp = 0 if c <= -1.65e+50: tmp = (b - (a * (d / c))) / c elif c <= -2.5e-131: tmp = t_0 elif c <= 3.4e-91: tmp = (((c * b) / d) - a) / d elif c <= 1e+39: tmp = t_0 else: tmp = (b + (a * (-1.0 / (c / d)))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(Float64(d * d) + Float64(c * c))) tmp = 0.0 if (c <= -1.65e+50) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= -2.5e-131) tmp = t_0; elseif (c <= 3.4e-91) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); elseif (c <= 1e+39) tmp = t_0; else tmp = Float64(Float64(b + Float64(a * Float64(-1.0 / Float64(c / d)))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (a * d)) / ((d * d) + (c * c)); tmp = 0.0; if (c <= -1.65e+50) tmp = (b - (a * (d / c))) / c; elseif (c <= -2.5e-131) tmp = t_0; elseif (c <= 3.4e-91) tmp = (((c * b) / d) - a) / d; elseif (c <= 1e+39) tmp = t_0; else tmp = (b + (a * (-1.0 / (c / d)))) / c; 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[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.65e+50], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.5e-131], t$95$0, If[LessEqual[c, 3.4e-91], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1e+39], t$95$0, N[(N[(b + N[(a * N[(-1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - a \cdot d}{d \cdot d + c \cdot c}\\
\mathbf{if}\;c \leq -1.65 \cdot 10^{+50}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -2.5 \cdot 10^{-131}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.4 \cdot 10^{-91}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 10^{+39}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{-1}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -1.65e50Initial program 45.2%
Taylor expanded in c around inf 82.4%
mul-1-neg82.4%
remove-double-neg82.4%
mul-1-neg82.4%
distribute-neg-in82.4%
distribute-neg-in82.4%
mul-1-neg82.4%
remove-double-neg82.4%
unsub-neg82.4%
associate-/l*89.0%
Simplified89.0%
if -1.65e50 < c < -2.5000000000000002e-131 or 3.40000000000000027e-91 < c < 9.9999999999999994e38Initial program 86.6%
if -2.5000000000000002e-131 < c < 3.40000000000000027e-91Initial program 68.1%
Taylor expanded in d around -inf 93.0%
mul-1-neg93.0%
distribute-neg-frac293.0%
mul-1-neg93.0%
unsub-neg93.0%
*-commutative93.0%
associate-/l*91.0%
Simplified91.0%
associate-*r/93.0%
*-commutative93.0%
clear-num93.0%
*-commutative93.0%
Applied egg-rr93.0%
Taylor expanded in a around 0 85.5%
neg-mul-185.5%
neg-sub085.5%
*-commutative85.5%
unpow285.5%
associate-/r*93.0%
*-lft-identity93.0%
associate-*l/93.0%
associate--r-93.0%
div-sub93.0%
neg-sub093.0%
distribute-neg-frac93.0%
Simplified92.0%
Taylor expanded in b around 0 93.0%
if 9.9999999999999994e38 < c Initial program 35.1%
Taylor expanded in c around inf 73.4%
mul-1-neg73.4%
remove-double-neg73.4%
mul-1-neg73.4%
distribute-neg-in73.4%
distribute-neg-in73.4%
mul-1-neg73.4%
remove-double-neg73.4%
unsub-neg73.4%
associate-/l*78.5%
Simplified78.5%
clear-num78.5%
inv-pow78.5%
Applied egg-rr78.5%
unpow-178.5%
Simplified78.5%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.6e-15)
(/ (- b (* a (/ d c))) c)
(if (<= c 1.02e-57)
(/ (- (/ 1.0 (/ d (* c b))) a) d)
(/ (+ b (* a (/ -1.0 (/ c d)))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.6e-15) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.02e-57) {
tmp = ((1.0 / (d / (c * b))) - a) / d;
} else {
tmp = (b + (a * (-1.0 / (c / d)))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-4.6d-15)) then
tmp = (b - (a * (d / c))) / c
else if (c <= 1.02d-57) then
tmp = ((1.0d0 / (d / (c * b))) - a) / d
else
tmp = (b + (a * ((-1.0d0) / (c / d)))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.6e-15) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.02e-57) {
tmp = ((1.0 / (d / (c * b))) - a) / d;
} else {
tmp = (b + (a * (-1.0 / (c / d)))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.6e-15: tmp = (b - (a * (d / c))) / c elif c <= 1.02e-57: tmp = ((1.0 / (d / (c * b))) - a) / d else: tmp = (b + (a * (-1.0 / (c / d)))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.6e-15) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= 1.02e-57) tmp = Float64(Float64(Float64(1.0 / Float64(d / Float64(c * b))) - a) / d); else tmp = Float64(Float64(b + Float64(a * Float64(-1.0 / Float64(c / d)))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -4.6e-15) tmp = (b - (a * (d / c))) / c; elseif (c <= 1.02e-57) tmp = ((1.0 / (d / (c * b))) - a) / d; else tmp = (b + (a * (-1.0 / (c / d)))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.6e-15], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.02e-57], N[(N[(N[(1.0 / N[(d / N[(c * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b + N[(a * N[(-1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.6 \cdot 10^{-15}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 1.02 \cdot 10^{-57}:\\
\;\;\;\;\frac{\frac{1}{\frac{d}{c \cdot b}} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{-1}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -4.59999999999999981e-15Initial program 56.0%
Taylor expanded in c around inf 80.4%
mul-1-neg80.4%
remove-double-neg80.4%
mul-1-neg80.4%
distribute-neg-in80.4%
distribute-neg-in80.4%
mul-1-neg80.4%
remove-double-neg80.4%
unsub-neg80.4%
associate-/l*85.5%
Simplified85.5%
if -4.59999999999999981e-15 < c < 1.02e-57Initial program 71.9%
Taylor expanded in d around -inf 87.6%
mul-1-neg87.6%
distribute-neg-frac287.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
associate-/l*86.1%
Simplified86.1%
associate-*r/87.6%
*-commutative87.6%
clear-num87.6%
*-commutative87.6%
Applied egg-rr87.6%
Taylor expanded in a around 0 81.8%
neg-mul-181.8%
neg-sub081.8%
*-commutative81.8%
unpow281.8%
associate-/r*87.5%
*-lft-identity87.5%
associate-*l/87.5%
associate--r-87.5%
div-sub87.6%
neg-sub087.6%
distribute-neg-frac87.6%
Simplified86.8%
associate-*r/87.6%
clear-num87.6%
Applied egg-rr87.6%
if 1.02e-57 < c Initial program 47.9%
Taylor expanded in c around inf 69.6%
mul-1-neg69.6%
remove-double-neg69.6%
mul-1-neg69.6%
distribute-neg-in69.6%
distribute-neg-in69.6%
mul-1-neg69.6%
remove-double-neg69.6%
unsub-neg69.6%
associate-/l*73.3%
Simplified73.3%
clear-num73.4%
inv-pow73.4%
Applied egg-rr73.4%
unpow-173.4%
Simplified73.4%
Final simplification82.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -2e-14)
(/ (- b (* a (/ d c))) c)
(if (<= c 1.02e-57)
(/ (- (/ (* c b) d) a) d)
(/ (+ b (* a (/ -1.0 (/ c d)))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2e-14) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.02e-57) {
tmp = (((c * b) / d) - a) / d;
} else {
tmp = (b + (a * (-1.0 / (c / d)))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-2d-14)) then
tmp = (b - (a * (d / c))) / c
else if (c <= 1.02d-57) then
tmp = (((c * b) / d) - a) / d
else
tmp = (b + (a * ((-1.0d0) / (c / d)))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2e-14) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= 1.02e-57) {
tmp = (((c * b) / d) - a) / d;
} else {
tmp = (b + (a * (-1.0 / (c / d)))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2e-14: tmp = (b - (a * (d / c))) / c elif c <= 1.02e-57: tmp = (((c * b) / d) - a) / d else: tmp = (b + (a * (-1.0 / (c / d)))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2e-14) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= 1.02e-57) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); else tmp = Float64(Float64(b + Float64(a * Float64(-1.0 / Float64(c / d)))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2e-14) tmp = (b - (a * (d / c))) / c; elseif (c <= 1.02e-57) tmp = (((c * b) / d) - a) / d; else tmp = (b + (a * (-1.0 / (c / d)))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2e-14], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.02e-57], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b + N[(a * N[(-1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{-14}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 1.02 \cdot 10^{-57}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{-1}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -2e-14Initial program 56.0%
Taylor expanded in c around inf 80.4%
mul-1-neg80.4%
remove-double-neg80.4%
mul-1-neg80.4%
distribute-neg-in80.4%
distribute-neg-in80.4%
mul-1-neg80.4%
remove-double-neg80.4%
unsub-neg80.4%
associate-/l*85.5%
Simplified85.5%
if -2e-14 < c < 1.02e-57Initial program 71.9%
Taylor expanded in d around -inf 87.6%
mul-1-neg87.6%
distribute-neg-frac287.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
associate-/l*86.1%
Simplified86.1%
associate-*r/87.6%
*-commutative87.6%
clear-num87.6%
*-commutative87.6%
Applied egg-rr87.6%
Taylor expanded in a around 0 81.8%
neg-mul-181.8%
neg-sub081.8%
*-commutative81.8%
unpow281.8%
associate-/r*87.5%
*-lft-identity87.5%
associate-*l/87.5%
associate--r-87.5%
div-sub87.6%
neg-sub087.6%
distribute-neg-frac87.6%
Simplified86.8%
Taylor expanded in b around 0 87.6%
if 1.02e-57 < c Initial program 47.9%
Taylor expanded in c around inf 69.6%
mul-1-neg69.6%
remove-double-neg69.6%
mul-1-neg69.6%
distribute-neg-in69.6%
distribute-neg-in69.6%
mul-1-neg69.6%
remove-double-neg69.6%
unsub-neg69.6%
associate-/l*73.3%
Simplified73.3%
clear-num73.4%
inv-pow73.4%
Applied egg-rr73.4%
unpow-173.4%
Simplified73.4%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.75e-14) (not (<= c 4.5e-58))) (/ (- b (* a (/ d c))) c) (/ (- (/ (* c b) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.75e-14) || !(c <= 4.5e-58)) {
tmp = (b - (a * (d / 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 <= (-2.75d-14)) .or. (.not. (c <= 4.5d-58))) then
tmp = (b - (a * (d / 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 <= -2.75e-14) || !(c <= 4.5e-58)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = (((c * b) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.75e-14) or not (c <= 4.5e-58): tmp = (b - (a * (d / c))) / c else: tmp = (((c * b) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.75e-14) || !(c <= 4.5e-58)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.75e-14) || ~((c <= 4.5e-58))) tmp = (b - (a * (d / c))) / c; else tmp = (((c * b) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.75e-14], N[Not[LessEqual[c, 4.5e-58]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.75 \cdot 10^{-14} \lor \neg \left(c \leq 4.5 \cdot 10^{-58}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.74999999999999996e-14 or 4.5000000000000003e-58 < c Initial program 51.3%
Taylor expanded in c around inf 74.1%
mul-1-neg74.1%
remove-double-neg74.1%
mul-1-neg74.1%
distribute-neg-in74.1%
distribute-neg-in74.1%
mul-1-neg74.1%
remove-double-neg74.1%
unsub-neg74.1%
associate-/l*78.5%
Simplified78.5%
if -2.74999999999999996e-14 < c < 4.5000000000000003e-58Initial program 71.9%
Taylor expanded in d around -inf 87.6%
mul-1-neg87.6%
distribute-neg-frac287.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
associate-/l*86.1%
Simplified86.1%
associate-*r/87.6%
*-commutative87.6%
clear-num87.6%
*-commutative87.6%
Applied egg-rr87.6%
Taylor expanded in a around 0 81.8%
neg-mul-181.8%
neg-sub081.8%
*-commutative81.8%
unpow281.8%
associate-/r*87.5%
*-lft-identity87.5%
associate-*l/87.5%
associate--r-87.5%
div-sub87.6%
neg-sub087.6%
distribute-neg-frac87.6%
Simplified86.8%
Taylor expanded in b around 0 87.6%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.1e-15) (not (<= c 1e-57))) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.1e-15) || !(c <= 1e-57)) {
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 <= (-4.1d-15)) .or. (.not. (c <= 1d-57))) 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 <= -4.1e-15) || !(c <= 1e-57)) {
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 <= -4.1e-15) or not (c <= 1e-57): 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 <= -4.1e-15) || !(c <= 1e-57)) 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 <= -4.1e-15) || ~((c <= 1e-57))) 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, -4.1e-15], N[Not[LessEqual[c, 1e-57]], $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 -4.1 \cdot 10^{-15} \lor \neg \left(c \leq 10^{-57}\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 < -4.10000000000000036e-15 or 9.99999999999999955e-58 < c Initial program 51.3%
Taylor expanded in c around inf 74.1%
mul-1-neg74.1%
remove-double-neg74.1%
mul-1-neg74.1%
distribute-neg-in74.1%
distribute-neg-in74.1%
mul-1-neg74.1%
remove-double-neg74.1%
unsub-neg74.1%
associate-/l*78.5%
Simplified78.5%
if -4.10000000000000036e-15 < c < 9.99999999999999955e-58Initial program 71.9%
Taylor expanded in d around -inf 87.6%
mul-1-neg87.6%
distribute-neg-frac287.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
associate-/l*86.1%
Simplified86.1%
associate-*r/87.6%
*-commutative87.6%
clear-num87.6%
*-commutative87.6%
Applied egg-rr87.6%
Taylor expanded in a around 0 81.8%
neg-mul-181.8%
neg-sub081.8%
*-commutative81.8%
unpow281.8%
associate-/r*87.5%
*-lft-identity87.5%
associate-*l/87.5%
associate--r-87.5%
div-sub87.6%
neg-sub087.6%
distribute-neg-frac87.6%
Simplified86.8%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.05e-14) (not (<= c 4.9e-107))) (/ (- b (* a (/ d c))) c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.05e-14) || !(c <= 4.9e-107)) {
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 <= (-2.05d-14)) .or. (.not. (c <= 4.9d-107))) 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 <= -2.05e-14) || !(c <= 4.9e-107)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.05e-14) or not (c <= 4.9e-107): tmp = (b - (a * (d / c))) / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.05e-14) || !(c <= 4.9e-107)) 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 <= -2.05e-14) || ~((c <= 4.9e-107))) tmp = (b - (a * (d / c))) / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.05e-14], N[Not[LessEqual[c, 4.9e-107]], $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 -2.05 \cdot 10^{-14} \lor \neg \left(c \leq 4.9 \cdot 10^{-107}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.0500000000000001e-14 or 4.8999999999999998e-107 < c Initial program 54.3%
Taylor expanded in c around inf 71.8%
mul-1-neg71.8%
remove-double-neg71.8%
mul-1-neg71.8%
distribute-neg-in71.8%
distribute-neg-in71.8%
mul-1-neg71.8%
remove-double-neg71.8%
unsub-neg71.8%
associate-/l*75.8%
Simplified75.8%
if -2.0500000000000001e-14 < c < 4.8999999999999998e-107Initial program 70.3%
Taylor expanded in c around 0 72.3%
associate-*r/72.3%
mul-1-neg72.3%
Simplified72.3%
Final simplification74.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.7e-14) (not (<= c 6.5e-91))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.7e-14) || !(c <= 6.5e-91)) {
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 <= (-2.7d-14)) .or. (.not. (c <= 6.5d-91))) 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 <= -2.7e-14) || !(c <= 6.5e-91)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.7e-14) or not (c <= 6.5e-91): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.7e-14) || !(c <= 6.5e-91)) 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 <= -2.7e-14) || ~((c <= 6.5e-91))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.7e-14], N[Not[LessEqual[c, 6.5e-91]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.7 \cdot 10^{-14} \lor \neg \left(c \leq 6.5 \cdot 10^{-91}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.6999999999999999e-14 or 6.5000000000000001e-91 < c Initial program 54.0%
Taylor expanded in c around inf 63.1%
if -2.6999999999999999e-14 < c < 6.5000000000000001e-91Initial program 70.0%
Taylor expanded in c around 0 71.0%
associate-*r/71.0%
mul-1-neg71.0%
Simplified71.0%
Final simplification66.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.2e+186) (not (<= d 3.6e+135))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.2e+186) || !(d <= 3.6e+135)) {
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 <= (-7.2d+186)) .or. (.not. (d <= 3.6d+135))) 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 <= -7.2e+186) || !(d <= 3.6e+135)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.2e+186) or not (d <= 3.6e+135): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.2e+186) || !(d <= 3.6e+135)) 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 <= -7.2e+186) || ~((d <= 3.6e+135))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.2e+186], N[Not[LessEqual[d, 3.6e+135]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+186} \lor \neg \left(d \leq 3.6 \cdot 10^{+135}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -7.2000000000000003e186 or 3.5999999999999998e135 < d Initial program 34.8%
Taylor expanded in c around 0 85.3%
associate-*r/85.3%
mul-1-neg85.3%
Simplified85.3%
add-sqr-sqrt48.8%
sqrt-unprod56.3%
sqr-neg56.3%
sqrt-unprod12.2%
add-sqr-sqrt32.4%
*-un-lft-identity32.4%
*-un-lft-identity32.4%
times-frac32.4%
metadata-eval32.4%
Applied egg-rr32.4%
*-lft-identity32.4%
Simplified32.4%
if -7.2000000000000003e186 < d < 3.5999999999999998e135Initial program 69.8%
Taylor expanded in c around inf 49.7%
Final simplification45.4%
(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 61.0%
Taylor expanded in c around 0 43.9%
associate-*r/43.9%
mul-1-neg43.9%
Simplified43.9%
add-sqr-sqrt23.7%
sqrt-unprod23.4%
sqr-neg23.4%
sqrt-unprod4.9%
add-sqr-sqrt11.8%
*-un-lft-identity11.8%
*-un-lft-identity11.8%
times-frac11.8%
metadata-eval11.8%
Applied egg-rr11.8%
*-lft-identity11.8%
Simplified11.8%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024118
(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))))