
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(if (<= d -1e+138)
(/ (- (* c (/ b d)) a) d)
(if (<= d -3.3e-128)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 4.6e-8)
(/ (- b (/ (* a d) c)) c)
(/ (fma c (/ 1.0 (/ d b)) (- a)) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1e+138) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -3.3e-128) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 4.6e-8) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = fma(c, (1.0 / (d / b)), -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1e+138) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= -3.3e-128) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 4.6e-8) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = Float64(fma(c, Float64(1.0 / Float64(d / b)), Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1e+138], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3.3e-128], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.6e-8], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(c * N[(1.0 / N[(d / b), $MachinePrecision]), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1 \cdot 10^{+138}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq -3.3 \cdot 10^{-128}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{-8}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{1}{\frac{d}{b}}, -a\right)}{d}\\
\end{array}
\end{array}
if d < -1e138Initial program 22.3%
*-un-lft-identity22.3%
add-sqr-sqrt22.3%
times-frac22.3%
hypot-define22.3%
hypot-define52.3%
Applied egg-rr52.3%
Taylor expanded in d around inf 87.8%
+-commutative87.8%
*-commutative87.8%
associate-*r/90.4%
neg-mul-190.4%
sub-neg90.4%
Simplified90.4%
if -1e138 < d < -3.3e-128Initial program 87.5%
if -3.3e-128 < d < 4.6000000000000002e-8Initial program 70.3%
Taylor expanded in c around inf 91.0%
remove-double-neg91.0%
mul-1-neg91.0%
neg-mul-191.0%
distribute-lft-in91.0%
distribute-lft-in91.0%
neg-mul-191.0%
mul-1-neg91.0%
remove-double-neg91.0%
associate-*r/91.0%
associate-*r*91.0%
mul-1-neg91.0%
Simplified91.0%
if 4.6000000000000002e-8 < d Initial program 57.9%
Taylor expanded in c around 0 78.0%
+-commutative78.0%
mul-1-neg78.0%
unsub-neg78.0%
unpow278.0%
associate-/r*80.5%
div-sub80.5%
*-commutative80.5%
associate-/l*84.5%
fmm-def84.4%
Simplified84.4%
clear-num84.5%
inv-pow84.5%
Applied egg-rr84.5%
unpow-184.5%
Simplified84.5%
Final simplification88.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) INFINITY)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (fma c (/ 1.0 (/ d b)) (- a)) d))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = fma(c, (1.0 / (d / b)), -a) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(fma(c, Float64(1.0 / Float64(d / b)), Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(1.0 / N[(d / b), $MachinePrecision]), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{1}{\frac{d}{b}}, -a\right)}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 79.5%
*-un-lft-identity79.5%
add-sqr-sqrt79.4%
times-frac79.4%
hypot-define79.4%
hypot-define95.5%
Applied egg-rr95.5%
if +inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in c around 0 45.2%
+-commutative45.2%
mul-1-neg45.2%
unsub-neg45.2%
unpow245.2%
associate-/r*47.7%
div-sub47.8%
*-commutative47.8%
associate-/l*53.7%
fmm-def53.7%
Simplified53.7%
clear-num53.7%
inv-pow53.7%
Applied egg-rr53.7%
unpow-153.7%
Simplified53.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -2.7e+138)
t_0
(if (<= d -9.5e-129)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 8.8e-11) (/ (- b (/ (* a d) c)) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.7e+138) {
tmp = t_0;
} else if (d <= -9.5e-129) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 8.8e-11) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = ((c * (b / d)) - a) / d
if (d <= (-2.7d+138)) then
tmp = t_0
else if (d <= (-9.5d-129)) then
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
else if (d <= 8.8d-11) then
tmp = (b - ((a * d) / c)) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.7e+138) {
tmp = t_0;
} else if (d <= -9.5e-129) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 8.8e-11) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * (b / d)) - a) / d tmp = 0 if d <= -2.7e+138: tmp = t_0 elif d <= -9.5e-129: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif d <= 8.8e-11: tmp = (b - ((a * d) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -2.7e+138) tmp = t_0; elseif (d <= -9.5e-129) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 8.8e-11) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -2.7e+138) tmp = t_0; elseif (d <= -9.5e-129) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (d <= 8.8e-11) tmp = (b - ((a * d) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.7e+138], t$95$0, If[LessEqual[d, -9.5e-129], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8.8e-11], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+138}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -9.5 \cdot 10^{-129}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{-11}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.70000000000000009e138 or 8.8000000000000006e-11 < d Initial program 43.3%
*-un-lft-identity43.3%
add-sqr-sqrt43.3%
times-frac43.2%
hypot-define43.2%
hypot-define62.9%
Applied egg-rr62.9%
Taylor expanded in d around inf 83.5%
+-commutative83.5%
*-commutative83.5%
associate-*r/86.9%
neg-mul-186.9%
sub-neg86.9%
Simplified86.9%
if -2.70000000000000009e138 < d < -9.5000000000000006e-129Initial program 87.5%
if -9.5000000000000006e-129 < d < 8.8000000000000006e-11Initial program 70.3%
Taylor expanded in c around inf 91.0%
remove-double-neg91.0%
mul-1-neg91.0%
neg-mul-191.0%
distribute-lft-in91.0%
distribute-lft-in91.0%
neg-mul-191.0%
mul-1-neg91.0%
remove-double-neg91.0%
associate-*r/91.0%
associate-*r*91.0%
mul-1-neg91.0%
Simplified91.0%
Final simplification88.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5e+48) (not (<= d 0.0044))) (/ (- (* c (/ b d)) a) d) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+48) || !(d <= 0.0044)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-5d+48)) .or. (.not. (d <= 0.0044d0))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b - ((a * d) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+48) || !(d <= 0.0044)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5e+48) or not (d <= 0.0044): tmp = ((c * (b / d)) - a) / d else: tmp = (b - ((a * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5e+48) || !(d <= 0.0044)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -5e+48) || ~((d <= 0.0044))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - ((a * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5e+48], N[Not[LessEqual[d, 0.0044]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+48} \lor \neg \left(d \leq 0.0044\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.99999999999999973e48 or 0.00440000000000000027 < d Initial program 48.3%
*-un-lft-identity48.3%
add-sqr-sqrt48.3%
times-frac48.2%
hypot-define48.2%
hypot-define66.2%
Applied egg-rr66.2%
Taylor expanded in d around inf 81.0%
+-commutative81.0%
*-commutative81.0%
associate-*r/84.0%
neg-mul-184.0%
sub-neg84.0%
Simplified84.0%
if -4.99999999999999973e48 < d < 0.00440000000000000027Initial program 76.8%
Taylor expanded in c around inf 80.4%
remove-double-neg80.4%
mul-1-neg80.4%
neg-mul-180.4%
distribute-lft-in80.4%
distribute-lft-in80.4%
neg-mul-180.4%
mul-1-neg80.4%
remove-double-neg80.4%
associate-*r/80.4%
associate-*r*80.4%
mul-1-neg80.4%
Simplified80.4%
Final simplification81.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.4e+48) (not (<= d 7.5e-5))) (/ (- (* c (/ b d)) a) d) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.4e+48) || !(d <= 7.5e-5)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a / (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 ((d <= (-2.4d+48)) .or. (.not. (d <= 7.5d-5))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b - (a / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.4e+48) || !(d <= 7.5e-5)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.4e+48) or not (d <= 7.5e-5): tmp = ((c * (b / d)) - a) / d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.4e+48) || !(d <= 7.5e-5)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.4e+48) || ~((d <= 7.5e-5))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.4e+48], N[Not[LessEqual[d, 7.5e-5]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.4 \cdot 10^{+48} \lor \neg \left(d \leq 7.5 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -2.4000000000000001e48 or 7.49999999999999934e-5 < d Initial program 48.3%
*-un-lft-identity48.3%
add-sqr-sqrt48.3%
times-frac48.2%
hypot-define48.2%
hypot-define66.2%
Applied egg-rr66.2%
Taylor expanded in d around inf 81.0%
+-commutative81.0%
*-commutative81.0%
associate-*r/84.0%
neg-mul-184.0%
sub-neg84.0%
Simplified84.0%
if -2.4000000000000001e48 < d < 7.49999999999999934e-5Initial program 76.8%
Taylor expanded in c around inf 80.4%
mul-1-neg80.4%
unsub-neg80.4%
associate-/l*80.1%
Simplified80.1%
clear-num80.2%
un-div-inv80.1%
Applied egg-rr80.1%
Final simplification81.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.5e+49) (not (<= d 1.02e-7))) (/ a (- d)) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.5e+49) || !(d <= 1.02e-7)) {
tmp = a / -d;
} else {
tmp = (b - (a / (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 ((d <= (-4.5d+49)) .or. (.not. (d <= 1.02d-7))) then
tmp = a / -d
else
tmp = (b - (a / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.5e+49) || !(d <= 1.02e-7)) {
tmp = a / -d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.5e+49) or not (d <= 1.02e-7): tmp = a / -d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.5e+49) || !(d <= 1.02e-7)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.5e+49) || ~((d <= 1.02e-7))) tmp = a / -d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.5e+49], N[Not[LessEqual[d, 1.02e-7]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.5 \cdot 10^{+49} \lor \neg \left(d \leq 1.02 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -4.49999999999999982e49 or 1.02e-7 < d Initial program 48.3%
Taylor expanded in c around 0 71.5%
associate-*r/71.5%
mul-1-neg71.5%
Simplified71.5%
if -4.49999999999999982e49 < d < 1.02e-7Initial program 76.8%
Taylor expanded in c around inf 80.4%
mul-1-neg80.4%
unsub-neg80.4%
associate-/l*80.1%
Simplified80.1%
clear-num80.2%
un-div-inv80.1%
Applied egg-rr80.1%
Final simplification76.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.2e+49) (not (<= d 0.003))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.2e+49) || !(d <= 0.003)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2.2d+49)) .or. (.not. (d <= 0.003d0))) then
tmp = a / -d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.2e+49) || !(d <= 0.003)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.2e+49) or not (d <= 0.003): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.2e+49) || !(d <= 0.003)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.2e+49) || ~((d <= 0.003))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.2e+49], N[Not[LessEqual[d, 0.003]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.2 \cdot 10^{+49} \lor \neg \left(d \leq 0.003\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.2000000000000001e49 or 0.0030000000000000001 < d Initial program 48.3%
Taylor expanded in c around 0 71.5%
associate-*r/71.5%
mul-1-neg71.5%
Simplified71.5%
if -2.2000000000000001e49 < d < 0.0030000000000000001Initial program 76.8%
Taylor expanded in c around inf 80.4%
mul-1-neg80.4%
unsub-neg80.4%
associate-/l*80.1%
Simplified80.1%
Final simplification76.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4e+32) (not (<= c 1e-8))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4e+32) || !(c <= 1e-8)) {
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 <= (-4d+32)) .or. (.not. (c <= 1d-8))) 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 <= -4e+32) || !(c <= 1e-8)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4e+32) or not (c <= 1e-8): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4e+32) || !(c <= 1e-8)) 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 <= -4e+32) || ~((c <= 1e-8))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4e+32], N[Not[LessEqual[c, 1e-8]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4 \cdot 10^{+32} \lor \neg \left(c \leq 10^{-8}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -4.00000000000000021e32 or 1e-8 < c Initial program 58.6%
Taylor expanded in c around inf 68.2%
if -4.00000000000000021e32 < c < 1e-8Initial program 69.7%
Taylor expanded in c around 0 66.4%
associate-*r/66.4%
mul-1-neg66.4%
Simplified66.4%
Final simplification67.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.5e+102) (not (<= d 4e+130))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.5e+102) || !(d <= 4e+130)) {
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 <= (-1.5d+102)) .or. (.not. (d <= 4d+130))) 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 <= -1.5e+102) || !(d <= 4e+130)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.5e+102) or not (d <= 4e+130): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.5e+102) || !(d <= 4e+130)) 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 <= -1.5e+102) || ~((d <= 4e+130))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.5e+102], N[Not[LessEqual[d, 4e+130]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.5 \cdot 10^{+102} \lor \neg \left(d \leq 4 \cdot 10^{+130}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.4999999999999999e102 or 4.0000000000000002e130 < d Initial program 36.3%
*-un-lft-identity36.3%
add-sqr-sqrt36.3%
times-frac36.3%
hypot-define36.3%
hypot-define60.3%
Applied egg-rr60.3%
Taylor expanded in c around 0 47.7%
+-commutative47.7%
*-commutative47.7%
associate-*r/50.2%
neg-mul-150.2%
sub-neg50.2%
Simplified50.2%
Taylor expanded in d around -inf 29.7%
if -1.4999999999999999e102 < d < 4.0000000000000002e130Initial program 76.0%
Taylor expanded in c around inf 54.5%
Final simplification47.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.2e+78) (not (<= d 1.3e+14))) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.2e+78) || !(d <= 1.3e+14)) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-3.2d+78)) .or. (.not. (d <= 1.3d+14))) then
tmp = a / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.2e+78) || !(d <= 1.3e+14)) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.2e+78) or not (d <= 1.3e+14): tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.2e+78) || !(d <= 1.3e+14)) tmp = Float64(a / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.2e+78) || ~((d <= 1.3e+14))) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.2e+78], N[Not[LessEqual[d, 1.3e+14]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{+78} \lor \neg \left(d \leq 1.3 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -3.19999999999999994e78 or 1.3e14 < d Initial program 45.7%
*-un-lft-identity45.7%
add-sqr-sqrt45.7%
times-frac45.7%
hypot-define45.7%
hypot-define64.8%
Applied egg-rr64.8%
Taylor expanded in c around 0 51.1%
+-commutative51.1%
*-commutative51.1%
associate-*r/53.0%
neg-mul-153.0%
sub-neg53.0%
Simplified53.0%
Taylor expanded in d around -inf 24.2%
if -3.19999999999999994e78 < d < 1.3e14Initial program 77.2%
*-un-lft-identity77.2%
add-sqr-sqrt77.2%
times-frac77.2%
hypot-define77.2%
hypot-define87.0%
Applied egg-rr87.0%
Taylor expanded in c around 0 11.0%
+-commutative11.0%
*-commutative11.0%
associate-*r/9.6%
neg-mul-19.6%
sub-neg9.6%
Simplified9.6%
Taylor expanded in c around -inf 8.9%
+-commutative8.9%
mul-1-neg8.9%
sub-neg8.9%
Simplified8.9%
Taylor expanded in a around inf 10.1%
Final simplification15.7%
(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.6%
*-un-lft-identity64.6%
add-sqr-sqrt64.6%
times-frac64.5%
hypot-define64.5%
hypot-define78.1%
Applied egg-rr78.1%
Taylor expanded in c around 0 27.2%
+-commutative27.2%
*-commutative27.2%
associate-*r/27.1%
neg-mul-127.1%
sub-neg27.1%
Simplified27.1%
Taylor expanded in c around -inf 7.6%
+-commutative7.6%
mul-1-neg7.6%
sub-neg7.6%
Simplified7.6%
Taylor expanded in a around inf 8.4%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024186
(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))))