
(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 (/ 1.0 (hypot c d))) (t_1 (- (* b c) (* a d))))
(if (<= (/ t_1 (+ (* c c) (* d d))) 4e+288)
(* t_0 (/ t_1 (hypot c d)))
(- (* t_0 (/ c (/ (hypot c d) b))) (/ a d)))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double t_1 = (b * c) - (a * d);
double tmp;
if ((t_1 / ((c * c) + (d * d))) <= 4e+288) {
tmp = t_0 * (t_1 / hypot(c, d));
} else {
tmp = (t_0 * (c / (hypot(c, d) / b))) - (a / d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = 1.0 / Math.hypot(c, d);
double t_1 = (b * c) - (a * d);
double tmp;
if ((t_1 / ((c * c) + (d * d))) <= 4e+288) {
tmp = t_0 * (t_1 / Math.hypot(c, d));
} else {
tmp = (t_0 * (c / (Math.hypot(c, d) / b))) - (a / d);
}
return tmp;
}
def code(a, b, c, d): t_0 = 1.0 / math.hypot(c, d) t_1 = (b * c) - (a * d) tmp = 0 if (t_1 / ((c * c) + (d * d))) <= 4e+288: tmp = t_0 * (t_1 / math.hypot(c, d)) else: tmp = (t_0 * (c / (math.hypot(c, d) / b))) - (a / d) return tmp
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) t_1 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (Float64(t_1 / Float64(Float64(c * c) + Float64(d * d))) <= 4e+288) tmp = Float64(t_0 * Float64(t_1 / hypot(c, d))); else tmp = Float64(Float64(t_0 * Float64(c / Float64(hypot(c, d) / b))) - Float64(a / d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = 1.0 / hypot(c, d); t_1 = (b * c) - (a * d); tmp = 0.0; if ((t_1 / ((c * c) + (d * d))) <= 4e+288) tmp = t_0 * (t_1 / hypot(c, d)); else tmp = (t_0 * (c / (hypot(c, d) / b))) - (a / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e+288], N[(t$95$0 * N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(c / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := b \cdot c - a \cdot d\\
\mathbf{if}\;\frac{t_1}{c \cdot c + d \cdot d} \leq 4 \cdot 10^{+288}:\\
\;\;\;\;t_0 \cdot \frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4e288Initial program 78.8%
*-un-lft-identity78.8%
add-sqr-sqrt78.8%
times-frac78.7%
hypot-def78.7%
hypot-def95.8%
Applied egg-rr95.8%
if 4e288 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 8.0%
div-sub4.9%
*-un-lft-identity4.9%
add-sqr-sqrt4.9%
times-frac4.9%
fma-neg4.9%
hypot-def4.9%
hypot-def7.6%
associate-/l*16.3%
add-sqr-sqrt16.3%
pow216.3%
hypot-def16.3%
Applied egg-rr16.3%
fma-neg16.3%
*-commutative16.3%
associate-/l*61.8%
associate-/l*47.3%
*-commutative47.3%
associate-/l*61.8%
Simplified61.8%
Taylor expanded in d around inf 77.4%
Final simplification90.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 4e+288)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(- (* (/ c d) (/ b d)) (/ 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))) <= 4e+288) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = ((c / d) * (b / d)) - (a / 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))) <= 4e+288) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = ((c / d) * (b / d)) - (a / d);
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (a * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 4e+288: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = ((c / d) * (b / d)) - (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))) <= 4e+288) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / 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))) <= 4e+288) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = ((c / d) * (b / d)) - (a / 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], 4e+288], 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[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $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 4 \cdot 10^{+288}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4e288Initial program 78.8%
*-un-lft-identity78.8%
add-sqr-sqrt78.8%
times-frac78.7%
hypot-def78.7%
hypot-def95.8%
Applied egg-rr95.8%
if 4e288 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 8.0%
Taylor expanded in c around 0 45.2%
+-commutative45.2%
mul-1-neg45.2%
unsub-neg45.2%
unpow245.2%
times-frac63.2%
Simplified63.2%
Final simplification87.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* (/ c d) (/ b d)) (/ a d))))
(if (<= d -1.16e+63)
t_0
(if (<= d -1.65e-133)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 2e+99) (/ (- b (/ a (/ c d))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c / d) * (b / d)) - (a / d);
double tmp;
if (d <= -1.16e+63) {
tmp = t_0;
} else if (d <= -1.65e-133) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 2e+99) {
tmp = (b - (a / (c / d))) / 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 / d) * (b / d)) - (a / d)
if (d <= (-1.16d+63)) then
tmp = t_0
else if (d <= (-1.65d-133)) then
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
else if (d <= 2d+99) then
tmp = (b - (a / (c / d))) / 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 / d) * (b / d)) - (a / d);
double tmp;
if (d <= -1.16e+63) {
tmp = t_0;
} else if (d <= -1.65e-133) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 2e+99) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c / d) * (b / d)) - (a / d) tmp = 0 if d <= -1.16e+63: tmp = t_0 elif d <= -1.65e-133: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif d <= 2e+99: tmp = (b - (a / (c / d))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d)) tmp = 0.0 if (d <= -1.16e+63) tmp = t_0; elseif (d <= -1.65e-133) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2e+99) tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c / d) * (b / d)) - (a / d); tmp = 0.0; if (d <= -1.16e+63) tmp = t_0; elseif (d <= -1.65e-133) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (d <= 2e+99) tmp = (b - (a / (c / d))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.16e+63], t$95$0, If[LessEqual[d, -1.65e-133], 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, 2e+99], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\mathbf{if}\;d \leq -1.16 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -1.65 \cdot 10^{-133}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{+99}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -1.15999999999999994e63 or 1.9999999999999999e99 < d Initial program 39.5%
Taylor expanded in c around 0 76.4%
+-commutative76.4%
mul-1-neg76.4%
unsub-neg76.4%
unpow276.4%
times-frac89.4%
Simplified89.4%
if -1.15999999999999994e63 < d < -1.65000000000000005e-133Initial program 92.1%
if -1.65000000000000005e-133 < d < 1.9999999999999999e99Initial program 67.9%
Taylor expanded in c around inf 75.7%
+-commutative75.7%
mul-1-neg75.7%
unsub-neg75.7%
unpow275.7%
times-frac79.2%
Simplified79.2%
associate-*r/80.0%
sub-div81.0%
Applied egg-rr81.0%
Taylor expanded in a around 0 85.4%
associate-/l*85.5%
Simplified85.5%
Final simplification88.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.85e-31) (not (<= d 2.8e+99))) (- (* (/ c d) (/ b d)) (/ a d)) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.85e-31) || !(d <= 2.8e+99)) {
tmp = ((c / d) * (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 <= (-1.85d-31)) .or. (.not. (d <= 2.8d+99))) then
tmp = ((c / d) * (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 <= -1.85e-31) || !(d <= 2.8e+99)) {
tmp = ((c / d) * (b / d)) - (a / d);
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.85e-31) or not (d <= 2.8e+99): tmp = ((c / d) * (b / d)) - (a / d) else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.85e-31) || !(d <= 2.8e+99)) tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(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 <= -1.85e-31) || ~((d <= 2.8e+99))) tmp = ((c / d) * (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, -1.85e-31], N[Not[LessEqual[d, 2.8e+99]], $MachinePrecision]], N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.85 \cdot 10^{-31} \lor \neg \left(d \leq 2.8 \cdot 10^{+99}\right):\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -1.8499999999999999e-31 or 2.8e99 < d Initial program 45.7%
Taylor expanded in c around 0 77.0%
+-commutative77.0%
mul-1-neg77.0%
unsub-neg77.0%
unpow277.0%
times-frac88.3%
Simplified88.3%
if -1.8499999999999999e-31 < d < 2.8e99Initial program 73.4%
Taylor expanded in c around inf 73.8%
+-commutative73.8%
mul-1-neg73.8%
unsub-neg73.8%
unpow273.8%
times-frac76.1%
Simplified76.1%
associate-*r/76.8%
sub-div77.6%
Applied egg-rr77.6%
Taylor expanded in a around 0 81.8%
associate-/l*81.9%
Simplified81.9%
Final simplification85.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.5e-25) (not (<= d 1.92e+99))) (/ (- a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.5e-25) || !(d <= 1.92e+99)) {
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 <= (-1.5d-25)) .or. (.not. (d <= 1.92d+99))) 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 <= -1.5e-25) || !(d <= 1.92e+99)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.5e-25) or not (d <= 1.92e+99): tmp = -a / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.5e-25) || !(d <= 1.92e+99)) 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 <= -1.5e-25) || ~((d <= 1.92e+99))) tmp = -a / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.5e-25], N[Not[LessEqual[d, 1.92e+99]], $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 -1.5 \cdot 10^{-25} \lor \neg \left(d \leq 1.92 \cdot 10^{+99}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.4999999999999999e-25 or 1.9199999999999999e99 < d Initial program 45.7%
Taylor expanded in c around 0 76.8%
associate-*r/76.8%
neg-mul-176.8%
Simplified76.8%
if -1.4999999999999999e-25 < d < 1.9199999999999999e99Initial program 73.4%
Taylor expanded in c around inf 73.8%
+-commutative73.8%
mul-1-neg73.8%
unsub-neg73.8%
unpow273.8%
times-frac76.1%
Simplified76.1%
Taylor expanded in b around 0 73.8%
+-commutative73.8%
associate-*r/73.8%
*-commutative73.8%
neg-mul-173.8%
distribute-frac-neg73.8%
unpow273.8%
times-frac76.1%
*-commutative76.1%
unsub-neg76.1%
associate-*l/80.3%
div-sub81.8%
Simplified81.8%
Final simplification79.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.05e-26) (not (<= d 2.05e+99))) (/ (- a) d) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.05e-26) || !(d <= 2.05e+99)) {
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 <= (-2.05d-26)) .or. (.not. (d <= 2.05d+99))) 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 <= -2.05e-26) || !(d <= 2.05e+99)) {
tmp = -a / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.05e-26) or not (d <= 2.05e+99): tmp = -a / d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.05e-26) || !(d <= 2.05e+99)) tmp = Float64(Float64(-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.05e-26) || ~((d <= 2.05e+99))) tmp = -a / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.05e-26], N[Not[LessEqual[d, 2.05e+99]], $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 -2.05 \cdot 10^{-26} \lor \neg \left(d \leq 2.05 \cdot 10^{+99}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -2.0499999999999999e-26 or 2.0499999999999999e99 < d Initial program 45.7%
Taylor expanded in c around 0 76.8%
associate-*r/76.8%
neg-mul-176.8%
Simplified76.8%
if -2.0499999999999999e-26 < d < 2.0499999999999999e99Initial program 73.4%
Taylor expanded in c around inf 73.8%
+-commutative73.8%
mul-1-neg73.8%
unsub-neg73.8%
unpow273.8%
times-frac76.1%
Simplified76.1%
associate-*r/76.8%
sub-div77.6%
Applied egg-rr77.6%
Taylor expanded in a around 0 81.8%
associate-/l*81.9%
Simplified81.9%
Final simplification79.4%
(FPCore (a b c d) :precision binary64 (if (<= d -3.5e-64) (/ (- a) (+ d (/ (* c c) d))) (if (<= d 1.92e+99) (/ (- b (/ a (/ c d))) c) (/ (- a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.5e-64) {
tmp = -a / (d + ((c * c) / d));
} else if (d <= 1.92e+99) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = -a / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-3.5d-64)) then
tmp = -a / (d + ((c * c) / d))
else if (d <= 1.92d+99) then
tmp = (b - (a / (c / d))) / c
else
tmp = -a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.5e-64) {
tmp = -a / (d + ((c * c) / d));
} else if (d <= 1.92e+99) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3.5e-64: tmp = -a / (d + ((c * c) / d)) elif d <= 1.92e+99: tmp = (b - (a / (c / d))) / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3.5e-64) tmp = Float64(Float64(-a) / Float64(d + Float64(Float64(c * c) / d))); elseif (d <= 1.92e+99) tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3.5e-64) tmp = -a / (d + ((c * c) / d)); elseif (d <= 1.92e+99) tmp = (b - (a / (c / d))) / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.5e-64], N[((-a) / N[(d + N[(N[(c * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.92e+99], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.5 \cdot 10^{-64}:\\
\;\;\;\;\frac{-a}{d + \frac{c \cdot c}{d}}\\
\mathbf{elif}\;d \leq 1.92 \cdot 10^{+99}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if d < -3.5000000000000003e-64Initial program 57.0%
*-un-lft-identity57.0%
add-sqr-sqrt57.0%
times-frac57.0%
hypot-def57.0%
hypot-def70.6%
Applied egg-rr70.6%
Taylor expanded in b around 0 51.9%
mul-1-neg51.9%
associate-/l*56.5%
distribute-neg-frac56.5%
unpow256.5%
unpow256.5%
fma-def56.6%
Simplified56.6%
Taylor expanded in d around 0 78.7%
+-commutative78.7%
unpow278.7%
Simplified78.7%
if -3.5000000000000003e-64 < d < 1.9199999999999999e99Initial program 73.4%
Taylor expanded in c around inf 74.4%
+-commutative74.4%
mul-1-neg74.4%
unsub-neg74.4%
unpow274.4%
times-frac76.8%
Simplified76.8%
associate-*r/77.5%
sub-div78.3%
Applied egg-rr78.3%
Taylor expanded in a around 0 82.6%
associate-/l*82.7%
Simplified82.7%
if 1.9199999999999999e99 < d Initial program 32.8%
Taylor expanded in c around 0 76.0%
associate-*r/76.0%
neg-mul-176.0%
Simplified76.0%
Final simplification80.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.2e-64) (not (<= d 1.92e+99))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.2e-64) || !(d <= 1.92e+99)) {
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 <= (-3.2d-64)) .or. (.not. (d <= 1.92d+99))) 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 <= -3.2e-64) || !(d <= 1.92e+99)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.2e-64) or not (d <= 1.92e+99): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.2e-64) || !(d <= 1.92e+99)) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.2e-64) || ~((d <= 1.92e+99))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.2e-64], N[Not[LessEqual[d, 1.92e+99]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{-64} \lor \neg \left(d \leq 1.92 \cdot 10^{+99}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.19999999999999975e-64 or 1.9199999999999999e99 < d Initial program 46.6%
Taylor expanded in c around 0 75.5%
associate-*r/75.5%
neg-mul-175.5%
Simplified75.5%
if -3.19999999999999975e-64 < d < 1.9199999999999999e99Initial program 73.4%
Taylor expanded in c around inf 65.2%
Final simplification70.3%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / 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 = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 60.0%
Taylor expanded in c around inf 39.3%
Final simplification39.3%
(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 2023257
(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))))