
(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
(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)))
(/ a (- (- d) (* c (/ c 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 = a / (-d - (c * (c / d)));
}
return tmp;
}
public static 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.POSITIVE_INFINITY) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = a / (-d - (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (a * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= math.inf: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = a / (-d - (c * (c / 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(a / Float64(Float64(-d) - Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) - (a * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= Inf) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = a / (-d - (c * (c / d))); end tmp_2 = 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[(a / N[((-d) - N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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{a}{\left(-d\right) - c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 76.5%
*-un-lft-identity76.5%
add-sqr-sqrt76.5%
times-frac76.5%
hypot-def76.6%
hypot-def95.2%
Applied egg-rr95.2%
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 b around 0 1.4%
associate-*r/1.4%
mul-1-neg1.4%
distribute-rgt-neg-out1.4%
associate-/l*3.7%
+-commutative3.7%
unpow23.7%
fma-def3.7%
unpow23.7%
Simplified3.7%
Taylor expanded in d around 0 54.1%
neg-mul-154.1%
+-commutative54.1%
unsub-neg54.1%
mul-1-neg54.1%
unpow254.1%
associate-*l/58.5%
*-commutative58.5%
distribute-rgt-neg-in58.5%
Simplified58.5%
Final simplification88.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(t_1 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -2.7e+97)
t_1
(if (<= c -2e-14)
t_0
(if (<= c 1.15e-122)
(* (/ -1.0 d) (- a (/ (* b c) d)))
(if (<= c 1.15e+99) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -2.7e+97) {
tmp = t_1;
} else if (c <= -2e-14) {
tmp = t_0;
} else if (c <= 1.15e-122) {
tmp = (-1.0 / d) * (a - ((b * c) / d));
} else if (c <= 1.15e+99) {
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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
t_1 = (b / c) - ((a / c) * (d / c))
if (c <= (-2.7d+97)) then
tmp = t_1
else if (c <= (-2d-14)) then
tmp = t_0
else if (c <= 1.15d-122) then
tmp = ((-1.0d0) / d) * (a - ((b * c) / d))
else if (c <= 1.15d+99) 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 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -2.7e+97) {
tmp = t_1;
} else if (c <= -2e-14) {
tmp = t_0;
} else if (c <= 1.15e-122) {
tmp = (-1.0 / d) * (a - ((b * c) / d));
} else if (c <= 1.15e+99) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) t_1 = (b / c) - ((a / c) * (d / c)) tmp = 0 if c <= -2.7e+97: tmp = t_1 elif c <= -2e-14: tmp = t_0 elif c <= 1.15e-122: tmp = (-1.0 / d) * (a - ((b * c) / d)) elif c <= 1.15e+99: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -2.7e+97) tmp = t_1; elseif (c <= -2e-14) tmp = t_0; elseif (c <= 1.15e-122) tmp = Float64(Float64(-1.0 / d) * Float64(a - Float64(Float64(b * c) / d))); elseif (c <= 1.15e+99) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); t_1 = (b / c) - ((a / c) * (d / c)); tmp = 0.0; if (c <= -2.7e+97) tmp = t_1; elseif (c <= -2e-14) tmp = t_0; elseif (c <= 1.15e-122) tmp = (-1.0 / d) * (a - ((b * c) / d)); elseif (c <= 1.15e+99) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.7e+97], t$95$1, If[LessEqual[c, -2e-14], t$95$0, If[LessEqual[c, 1.15e-122], N[(N[(-1.0 / d), $MachinePrecision] * N[(a - N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.15e+99], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+97}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -2 \cdot 10^{-14}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.15 \cdot 10^{-122}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(a - \frac{b \cdot c}{d}\right)\\
\mathbf{elif}\;c \leq 1.15 \cdot 10^{+99}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -2.69999999999999993e97 or 1.1500000000000001e99 < c Initial program 43.1%
*-un-lft-identity43.1%
add-sqr-sqrt43.1%
times-frac43.1%
hypot-def43.1%
hypot-def70.2%
Applied egg-rr70.2%
Taylor expanded in c around inf 78.4%
fma-def78.4%
unpow278.4%
times-frac92.3%
fma-def92.3%
neg-mul-192.3%
+-commutative92.3%
sub-neg92.3%
Simplified92.3%
if -2.69999999999999993e97 < c < -2e-14 or 1.15000000000000003e-122 < c < 1.1500000000000001e99Initial program 71.0%
if -2e-14 < c < 1.15000000000000003e-122Initial program 74.4%
*-un-lft-identity74.4%
add-sqr-sqrt74.4%
times-frac74.4%
hypot-def74.5%
hypot-def88.1%
Applied egg-rr88.1%
Taylor expanded in d around -inf 53.2%
associate-*r/53.2%
mul-1-neg53.2%
*-commutative53.2%
Simplified53.2%
Taylor expanded in d around -inf 96.9%
Final simplification87.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -3.3e+91)
t_0
(if (<= c -1250.0)
(/ a (- (- d) (* c (/ c d))))
(if (or (<= c -1.7e-9) (not (<= c 1.3e+57)))
t_0
(* (/ -1.0 d) (- a (/ (* b c) d))))))))
double code(double a, double b, double c, double d) {
double t_0 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -3.3e+91) {
tmp = t_0;
} else if (c <= -1250.0) {
tmp = a / (-d - (c * (c / d)));
} else if ((c <= -1.7e-9) || !(c <= 1.3e+57)) {
tmp = t_0;
} else {
tmp = (-1.0 / d) * (a - ((b * 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) :: t_0
real(8) :: tmp
t_0 = (b / c) - ((a / c) * (d / c))
if (c <= (-3.3d+91)) then
tmp = t_0
else if (c <= (-1250.0d0)) then
tmp = a / (-d - (c * (c / d)))
else if ((c <= (-1.7d-9)) .or. (.not. (c <= 1.3d+57))) then
tmp = t_0
else
tmp = ((-1.0d0) / d) * (a - ((b * c) / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -3.3e+91) {
tmp = t_0;
} else if (c <= -1250.0) {
tmp = a / (-d - (c * (c / d)));
} else if ((c <= -1.7e-9) || !(c <= 1.3e+57)) {
tmp = t_0;
} else {
tmp = (-1.0 / d) * (a - ((b * c) / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / c) - ((a / c) * (d / c)) tmp = 0 if c <= -3.3e+91: tmp = t_0 elif c <= -1250.0: tmp = a / (-d - (c * (c / d))) elif (c <= -1.7e-9) or not (c <= 1.3e+57): tmp = t_0 else: tmp = (-1.0 / d) * (a - ((b * c) / d)) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -3.3e+91) tmp = t_0; elseif (c <= -1250.0) tmp = Float64(a / Float64(Float64(-d) - Float64(c * Float64(c / d)))); elseif ((c <= -1.7e-9) || !(c <= 1.3e+57)) tmp = t_0; else tmp = Float64(Float64(-1.0 / d) * Float64(a - Float64(Float64(b * c) / d))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / c) - ((a / c) * (d / c)); tmp = 0.0; if (c <= -3.3e+91) tmp = t_0; elseif (c <= -1250.0) tmp = a / (-d - (c * (c / d))); elseif ((c <= -1.7e-9) || ~((c <= 1.3e+57))) tmp = t_0; else tmp = (-1.0 / d) * (a - ((b * c) / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.3e+91], t$95$0, If[LessEqual[c, -1250.0], N[(a / N[((-d) - N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[c, -1.7e-9], N[Not[LessEqual[c, 1.3e+57]], $MachinePrecision]], t$95$0, N[(N[(-1.0 / d), $MachinePrecision] * N[(a - N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -3.3 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -1250:\\
\;\;\;\;\frac{a}{\left(-d\right) - c \cdot \frac{c}{d}}\\
\mathbf{elif}\;c \leq -1.7 \cdot 10^{-9} \lor \neg \left(c \leq 1.3 \cdot 10^{+57}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(a - \frac{b \cdot c}{d}\right)\\
\end{array}
\end{array}
if c < -3.30000000000000017e91 or -1250 < c < -1.6999999999999999e-9 or 1.3e57 < c Initial program 48.9%
*-un-lft-identity48.9%
add-sqr-sqrt48.9%
times-frac48.9%
hypot-def48.9%
hypot-def73.3%
Applied egg-rr73.3%
Taylor expanded in c around inf 77.2%
fma-def77.2%
unpow277.2%
times-frac87.8%
fma-def87.8%
neg-mul-187.8%
+-commutative87.8%
sub-neg87.8%
Simplified87.8%
if -3.30000000000000017e91 < c < -1250Initial program 62.0%
Taylor expanded in b around 0 35.1%
associate-*r/35.1%
mul-1-neg35.1%
distribute-rgt-neg-out35.1%
associate-/l*40.4%
+-commutative40.4%
unpow240.4%
fma-def40.4%
unpow240.4%
Simplified40.4%
Taylor expanded in d around 0 63.4%
neg-mul-163.4%
+-commutative63.4%
unsub-neg63.4%
mul-1-neg63.4%
unpow263.4%
associate-*l/63.5%
*-commutative63.5%
distribute-rgt-neg-in63.5%
Simplified63.5%
if -1.6999999999999999e-9 < c < 1.3e57Initial program 74.1%
*-un-lft-identity74.1%
add-sqr-sqrt74.1%
times-frac74.1%
hypot-def74.2%
hypot-def85.6%
Applied egg-rr85.6%
Taylor expanded in d around -inf 51.0%
associate-*r/51.0%
mul-1-neg51.0%
*-commutative51.0%
Simplified51.0%
Taylor expanded in d around -inf 86.8%
Final simplification85.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.8e+87) (not (<= c 3.2e+58))) (- (/ b c) (* (/ a c) (/ d c))) (/ (- (/ c (/ d b)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.8e+87) || !(c <= 3.2e+58)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = ((c / (d / b)) - 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.8d+87)) .or. (.not. (c <= 3.2d+58))) then
tmp = (b / c) - ((a / c) * (d / c))
else
tmp = ((c / (d / b)) - 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.8e+87) || !(c <= 3.2e+58)) {
tmp = (b / c) - ((a / c) * (d / c));
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.8e+87) or not (c <= 3.2e+58): tmp = (b / c) - ((a / c) * (d / c)) else: tmp = ((c / (d / b)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.8e+87) || !(c <= 3.2e+58)) tmp = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))); else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.8e+87) || ~((c <= 3.2e+58))) tmp = (b / c) - ((a / c) * (d / c)); else tmp = ((c / (d / b)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.8e+87], N[Not[LessEqual[c, 3.2e+58]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.8 \cdot 10^{+87} \lor \neg \left(c \leq 3.2 \cdot 10^{+58}\right):\\
\;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if c < -1.79999999999999997e87 or 3.20000000000000015e58 < c Initial program 48.4%
*-un-lft-identity48.4%
add-sqr-sqrt48.4%
times-frac48.4%
hypot-def48.4%
hypot-def73.0%
Applied egg-rr73.0%
Taylor expanded in c around inf 76.0%
fma-def76.0%
unpow276.0%
times-frac86.7%
fma-def86.7%
neg-mul-186.7%
+-commutative86.7%
sub-neg86.7%
Simplified86.7%
if -1.79999999999999997e87 < c < 3.20000000000000015e58Initial program 72.6%
*-un-lft-identity72.6%
add-sqr-sqrt72.6%
times-frac72.7%
hypot-def72.7%
hypot-def83.2%
Applied egg-rr83.2%
Taylor expanded in d around -inf 47.9%
associate-*r/47.9%
mul-1-neg47.9%
*-commutative47.9%
Simplified47.9%
Taylor expanded in d around -inf 81.4%
Taylor expanded in d around 0 74.2%
associate-*r/74.2%
associate-*l/74.0%
+-commutative74.0%
*-commutative74.0%
unpow274.0%
associate-*l/74.2%
associate-*r/74.2%
mul-1-neg74.2%
sub-neg74.2%
associate-/r*80.8%
div-sub81.6%
associate-/l*80.5%
Simplified80.5%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8e+24) (not (<= d 2.3e+49))) (- (/ a d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8e+24) || !(d <= 2.3e+49)) {
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 <= (-8d+24)) .or. (.not. (d <= 2.3d+49))) 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 <= -8e+24) || !(d <= 2.3e+49)) {
tmp = -(a / d);
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8e+24) or not (d <= 2.3e+49): tmp = -(a / d) else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8e+24) || !(d <= 2.3e+49)) tmp = Float64(-Float64(a / 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 <= -8e+24) || ~((d <= 2.3e+49))) tmp = -(a / d); else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8e+24], N[Not[LessEqual[d, 2.3e+49]], $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 -8 \cdot 10^{+24} \lor \neg \left(d \leq 2.3 \cdot 10^{+49}\right):\\
\;\;\;\;-\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -7.9999999999999999e24 or 2.30000000000000002e49 < d Initial program 51.1%
Taylor expanded in c around 0 75.7%
associate-*r/75.7%
neg-mul-175.7%
Simplified75.7%
if -7.9999999999999999e24 < d < 2.30000000000000002e49Initial program 73.6%
*-un-lft-identity73.6%
add-sqr-sqrt73.6%
times-frac73.6%
hypot-def73.7%
hypot-def86.5%
Applied egg-rr86.5%
Taylor expanded in c around inf 69.1%
fma-def69.1%
unpow269.1%
times-frac73.3%
fma-def73.3%
neg-mul-173.3%
+-commutative73.3%
sub-neg73.3%
Simplified73.3%
Taylor expanded in b around 0 69.1%
+-commutative69.1%
mul-1-neg69.1%
*-commutative69.1%
unpow269.1%
times-frac73.3%
distribute-lft-neg-in73.3%
cancel-sign-sub-inv73.3%
*-commutative73.3%
associate-*l/73.3%
div-sub75.5%
Simplified75.5%
Final simplification75.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.6e+88) (not (<= c 9.5e+57))) (/ (- b (* a (/ d c))) c) (/ (- (/ c (/ d b)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.6e+88) || !(c <= 9.5e+57)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c / (d / b)) - 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 <= (-3.6d+88)) .or. (.not. (c <= 9.5d+57))) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((c / (d / b)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.6e+88) || !(c <= 9.5e+57)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.6e+88) or not (c <= 9.5e+57): tmp = (b - (a * (d / c))) / c else: tmp = ((c / (d / b)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.6e+88) || !(c <= 9.5e+57)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.6e+88) || ~((c <= 9.5e+57))) tmp = (b - (a * (d / c))) / c; else tmp = ((c / (d / b)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.6e+88], N[Not[LessEqual[c, 9.5e+57]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.6 \cdot 10^{+88} \lor \neg \left(c \leq 9.5 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if c < -3.6000000000000002e88 or 9.4999999999999997e57 < c Initial program 48.4%
*-un-lft-identity48.4%
add-sqr-sqrt48.4%
times-frac48.4%
hypot-def48.4%
hypot-def73.0%
Applied egg-rr73.0%
Taylor expanded in c around inf 76.0%
fma-def76.0%
unpow276.0%
times-frac86.7%
fma-def86.7%
neg-mul-186.7%
+-commutative86.7%
sub-neg86.7%
Simplified86.7%
Taylor expanded in b around 0 76.0%
+-commutative76.0%
mul-1-neg76.0%
*-commutative76.0%
unpow276.0%
times-frac86.7%
distribute-lft-neg-in86.7%
cancel-sign-sub-inv86.7%
*-commutative86.7%
associate-*l/86.7%
div-sub86.7%
Simplified86.7%
if -3.6000000000000002e88 < c < 9.4999999999999997e57Initial program 72.6%
*-un-lft-identity72.6%
add-sqr-sqrt72.6%
times-frac72.7%
hypot-def72.7%
hypot-def83.2%
Applied egg-rr83.2%
Taylor expanded in d around -inf 47.9%
associate-*r/47.9%
mul-1-neg47.9%
*-commutative47.9%
Simplified47.9%
Taylor expanded in d around -inf 81.4%
Taylor expanded in d around 0 74.2%
associate-*r/74.2%
associate-*l/74.0%
+-commutative74.0%
*-commutative74.0%
unpow274.0%
associate-*l/74.2%
associate-*r/74.2%
mul-1-neg74.2%
sub-neg74.2%
associate-/r*80.8%
div-sub81.6%
associate-/l*80.5%
Simplified80.5%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (<= c -3.5e+91) (/ b c) (if (<= c 2.7e+56) (- (/ a d)) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.5e+91) {
tmp = b / c;
} else if (c <= 2.7e+56) {
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 (c <= (-3.5d+91)) then
tmp = b / c
else if (c <= 2.7d+56) 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 (c <= -3.5e+91) {
tmp = b / c;
} else if (c <= 2.7e+56) {
tmp = -(a / d);
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.5e+91: tmp = b / c elif c <= 2.7e+56: tmp = -(a / d) else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.5e+91) tmp = Float64(b / c); elseif (c <= 2.7e+56) 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 (c <= -3.5e+91) tmp = b / c; elseif (c <= 2.7e+56) tmp = -(a / d); else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.5e+91], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.7e+56], (-N[(a / d), $MachinePrecision]), N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.5 \cdot 10^{+91}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.7 \cdot 10^{+56}:\\
\;\;\;\;-\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -3.50000000000000001e91 or 2.7000000000000001e56 < c Initial program 47.3%
Taylor expanded in c around inf 75.7%
if -3.50000000000000001e91 < c < 2.7000000000000001e56Initial program 73.0%
Taylor expanded in c around 0 67.5%
associate-*r/67.5%
neg-mul-167.5%
Simplified67.5%
Final simplification70.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.7e+170) (not (<= d 4.6e+175))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.7e+170) || !(d <= 4.6e+175)) {
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.7d+170)) .or. (.not. (d <= 4.6d+175))) 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.7e+170) || !(d <= 4.6e+175)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.7e+170) or not (d <= 4.6e+175): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.7e+170) || !(d <= 4.6e+175)) 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 <= -2.7e+170) || ~((d <= 4.6e+175))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.7e+170], N[Not[LessEqual[d, 4.6e+175]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{+170} \lor \neg \left(d \leq 4.6 \cdot 10^{+175}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.7000000000000002e170 or 4.5999999999999999e175 < d Initial program 35.4%
*-un-lft-identity35.4%
add-sqr-sqrt35.4%
times-frac35.4%
hypot-def35.4%
hypot-def58.0%
Applied egg-rr58.0%
Taylor expanded in d around -inf 65.5%
associate-*r/65.5%
mul-1-neg65.5%
*-commutative65.5%
Simplified65.5%
Taylor expanded in c around 0 34.7%
if -2.7000000000000002e170 < d < 4.5999999999999999e175Initial program 71.5%
Taylor expanded in c around inf 47.9%
Final simplification44.9%
(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 63.4%
*-un-lft-identity63.4%
add-sqr-sqrt63.3%
times-frac63.4%
hypot-def63.4%
hypot-def79.3%
Applied egg-rr79.3%
Taylor expanded in d around -inf 35.5%
associate-*r/35.5%
mul-1-neg35.5%
*-commutative35.5%
Simplified35.5%
Taylor expanded in c around 0 12.2%
Final simplification12.2%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2023297
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(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))))