
(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 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 1e+308)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (- (* c (/ 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))) <= 1e+308) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = ((c * (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))) <= 1e+308) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = ((c * (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))) <= 1e+308: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = ((c * (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))) <= 1e+308) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) - (a * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 1e+308) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = ((c * (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], 1e+308], 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 * N[(b / d), $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 10^{+308}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1e308Initial program 79.2%
*-un-lft-identity79.2%
add-sqr-sqrt79.2%
times-frac79.2%
hypot-def79.2%
hypot-def97.2%
Applied egg-rr97.2%
if 1e308 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.2%
*-un-lft-identity15.2%
add-sqr-sqrt15.2%
times-frac15.2%
hypot-def15.2%
hypot-def20.2%
Applied egg-rr20.2%
Taylor expanded in c around 0 40.0%
neg-mul-140.0%
+-commutative40.0%
unpow240.0%
times-frac60.4%
unsub-neg60.4%
associate-*l/60.4%
div-sub60.4%
Simplified60.4%
Final simplification88.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ b c) (/ (/ d (/ c a)) c))))
(if (<= c -1.4e+105)
t_0
(if (<= c -1.18e-141)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= c 6.8e-33) (/ (- (* b (/ c d)) a) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b / c) - ((d / (c / a)) / c);
double tmp;
if (c <= -1.4e+105) {
tmp = t_0;
} else if (c <= -1.18e-141) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 6.8e-33) {
tmp = ((b * (c / d)) - a) / d;
} 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 = (b / c) - ((d / (c / a)) / c)
if (c <= (-1.4d+105)) then
tmp = t_0
else if (c <= (-1.18d-141)) then
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
else if (c <= 6.8d-33) then
tmp = ((b * (c / d)) - a) / d
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 = (b / c) - ((d / (c / a)) / c);
double tmp;
if (c <= -1.4e+105) {
tmp = t_0;
} else if (c <= -1.18e-141) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (c <= 6.8e-33) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / c) - ((d / (c / a)) / c) tmp = 0 if c <= -1.4e+105: tmp = t_0 elif c <= -1.18e-141: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif c <= 6.8e-33: tmp = ((b * (c / d)) - a) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / c) - Float64(Float64(d / Float64(c / a)) / c)) tmp = 0.0 if (c <= -1.4e+105) tmp = t_0; elseif (c <= -1.18e-141) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 6.8e-33) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / c) - ((d / (c / a)) / c); tmp = 0.0; if (c <= -1.4e+105) tmp = t_0; elseif (c <= -1.18e-141) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (c <= 6.8e-33) tmp = ((b * (c / d)) - a) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / c), $MachinePrecision] - N[(N[(d / N[(c / a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.4e+105], t$95$0, If[LessEqual[c, -1.18e-141], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.8e-33], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{c} - \frac{\frac{d}{\frac{c}{a}}}{c}\\
\mathbf{if}\;c \leq -1.4 \cdot 10^{+105}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -1.18 \cdot 10^{-141}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{-33}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -1.4000000000000001e105 or 6.8000000000000001e-33 < c Initial program 51.1%
*-un-lft-identity51.1%
add-sqr-sqrt51.1%
times-frac51.1%
hypot-def51.1%
hypot-def68.4%
Applied egg-rr68.4%
Taylor expanded in c around inf 73.9%
+-commutative73.9%
mul-1-neg73.9%
unsub-neg73.9%
unpow273.9%
associate-/r*77.1%
*-commutative77.1%
associate-/l*81.6%
Simplified81.6%
if -1.4000000000000001e105 < c < -1.17999999999999993e-141Initial program 81.4%
if -1.17999999999999993e-141 < c < 6.8000000000000001e-33Initial program 70.5%
Taylor expanded in c around 0 74.3%
+-commutative74.3%
mul-1-neg74.3%
unsub-neg74.3%
unpow274.3%
times-frac86.5%
Simplified86.5%
associate-*r/89.4%
sub-div89.9%
Applied egg-rr89.9%
Final simplification84.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.1e+116) (not (<= c 3.8e-34))) (- (/ b c) (* (/ d c) (/ a c))) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.1e+116) || !(c <= 3.8e-34)) {
tmp = (b / c) - ((d / c) * (a / 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 <= (-5.1d+116)) .or. (.not. (c <= 3.8d-34))) then
tmp = (b / c) - ((d / c) * (a / 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 <= -5.1e+116) || !(c <= 3.8e-34)) {
tmp = (b / c) - ((d / c) * (a / c));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.1e+116) or not (c <= 3.8e-34): tmp = (b / c) - ((d / c) * (a / c)) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.1e+116) || !(c <= 3.8e-34)) tmp = Float64(Float64(b / c) - Float64(Float64(d / c) * Float64(a / 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 <= -5.1e+116) || ~((c <= 3.8e-34))) tmp = (b / c) - ((d / c) * (a / c)); else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.1e+116], N[Not[LessEqual[c, 3.8e-34]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.1 \cdot 10^{+116} \lor \neg \left(c \leq 3.8 \cdot 10^{-34}\right):\\
\;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -5.09999999999999999e116 or 3.8000000000000001e-34 < c Initial program 51.5%
Taylor expanded in c around inf 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
unpow274.9%
times-frac82.4%
Simplified82.4%
if -5.09999999999999999e116 < c < 3.8000000000000001e-34Initial program 73.5%
Taylor expanded in c around 0 67.6%
+-commutative67.6%
mul-1-neg67.6%
unsub-neg67.6%
unpow267.6%
times-frac77.4%
Simplified77.4%
associate-*r/79.3%
sub-div79.6%
Applied egg-rr79.6%
Final simplification80.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.35e+79) (not (<= c 7e-35))) (- (/ b c) (/ (/ d (/ c a)) c)) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.35e+79) || !(c <= 7e-35)) {
tmp = (b / c) - ((d / (c / a)) / 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 <= (-1.35d+79)) .or. (.not. (c <= 7d-35))) then
tmp = (b / c) - ((d / (c / a)) / 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 <= -1.35e+79) || !(c <= 7e-35)) {
tmp = (b / c) - ((d / (c / a)) / c);
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.35e+79) or not (c <= 7e-35): tmp = (b / c) - ((d / (c / a)) / c) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.35e+79) || !(c <= 7e-35)) tmp = Float64(Float64(b / c) - Float64(Float64(d / Float64(c / a)) / 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 <= -1.35e+79) || ~((c <= 7e-35))) tmp = (b / c) - ((d / (c / a)) / c); else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.35e+79], N[Not[LessEqual[c, 7e-35]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(N[(d / N[(c / a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.35 \cdot 10^{+79} \lor \neg \left(c \leq 7 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{b}{c} - \frac{\frac{d}{\frac{c}{a}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -1.35e79 or 6.99999999999999992e-35 < c Initial program 52.3%
*-un-lft-identity52.3%
add-sqr-sqrt52.3%
times-frac52.3%
hypot-def52.3%
hypot-def69.2%
Applied egg-rr69.2%
Taylor expanded in c around inf 73.7%
+-commutative73.7%
mul-1-neg73.7%
unsub-neg73.7%
unpow273.7%
associate-/r*76.9%
*-commutative76.9%
associate-/l*81.2%
Simplified81.2%
if -1.35e79 < c < 6.99999999999999992e-35Initial program 73.7%
Taylor expanded in c around 0 68.3%
+-commutative68.3%
mul-1-neg68.3%
unsub-neg68.3%
unpow268.3%
times-frac78.6%
Simplified78.6%
associate-*r/80.5%
sub-div80.8%
Applied egg-rr80.8%
Final simplification81.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.1e+116)
(- (/ b c) (/ (* a (/ d c)) c))
(if (<= c 2.15e-36)
(/ (- (* b (/ c d)) a) d)
(- (/ b c) (* (/ d c) (/ a c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.1e+116) {
tmp = (b / c) - ((a * (d / c)) / c);
} else if (c <= 2.15e-36) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b / c) - ((d / c) * (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 (c <= (-5.1d+116)) then
tmp = (b / c) - ((a * (d / c)) / c)
else if (c <= 2.15d-36) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b / c) - ((d / c) * (a / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.1e+116) {
tmp = (b / c) - ((a * (d / c)) / c);
} else if (c <= 2.15e-36) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b / c) - ((d / c) * (a / c));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.1e+116: tmp = (b / c) - ((a * (d / c)) / c) elif c <= 2.15e-36: tmp = ((b * (c / d)) - a) / d else: tmp = (b / c) - ((d / c) * (a / c)) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.1e+116) tmp = Float64(Float64(b / c) - Float64(Float64(a * Float64(d / c)) / c)); elseif (c <= 2.15e-36) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b / c) - Float64(Float64(d / c) * Float64(a / c))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -5.1e+116) tmp = (b / c) - ((a * (d / c)) / c); elseif (c <= 2.15e-36) tmp = ((b * (c / d)) - a) / d; else tmp = (b / c) - ((d / c) * (a / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.1e+116], N[(N[(b / c), $MachinePrecision] - N[(N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.15e-36], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.1 \cdot 10^{+116}:\\
\;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 2.15 \cdot 10^{-36}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\
\end{array}
\end{array}
if c < -5.09999999999999999e116Initial program 47.6%
*-un-lft-identity47.6%
add-sqr-sqrt47.6%
times-frac47.5%
hypot-def47.5%
hypot-def64.2%
Applied egg-rr64.2%
Taylor expanded in c around inf 83.7%
+-commutative83.7%
mul-1-neg83.7%
unsub-neg83.7%
unpow283.7%
associate-/r*86.0%
*-commutative86.0%
associate-/l*90.9%
Simplified90.9%
associate-/r/90.9%
Applied egg-rr90.9%
if -5.09999999999999999e116 < c < 2.1500000000000001e-36Initial program 73.5%
Taylor expanded in c around 0 67.6%
+-commutative67.6%
mul-1-neg67.6%
unsub-neg67.6%
unpow267.6%
times-frac77.4%
Simplified77.4%
associate-*r/79.3%
sub-div79.6%
Applied egg-rr79.6%
if 2.1500000000000001e-36 < c Initial program 53.7%
Taylor expanded in c around inf 69.9%
+-commutative69.9%
mul-1-neg69.9%
unsub-neg69.9%
unpow269.9%
times-frac77.6%
Simplified77.6%
Final simplification80.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= c -5.1e+116)
(/ b c)
(if (<= c 8.2e-132)
t_0
(if (<= c 8.6e-75)
(/ (/ c (/ d b)) d)
(if (<= c 4.5e-9) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (c <= -5.1e+116) {
tmp = b / c;
} else if (c <= 8.2e-132) {
tmp = t_0;
} else if (c <= 8.6e-75) {
tmp = (c / (d / b)) / d;
} else if (c <= 4.5e-9) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = -a / d
if (c <= (-5.1d+116)) then
tmp = b / c
else if (c <= 8.2d-132) then
tmp = t_0
else if (c <= 8.6d-75) then
tmp = (c / (d / b)) / d
else if (c <= 4.5d-9) then
tmp = t_0
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (c <= -5.1e+116) {
tmp = b / c;
} else if (c <= 8.2e-132) {
tmp = t_0;
} else if (c <= 8.6e-75) {
tmp = (c / (d / b)) / d;
} else if (c <= 4.5e-9) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if c <= -5.1e+116: tmp = b / c elif c <= 8.2e-132: tmp = t_0 elif c <= 8.6e-75: tmp = (c / (d / b)) / d elif c <= 4.5e-9: tmp = t_0 else: tmp = b / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (c <= -5.1e+116) tmp = Float64(b / c); elseif (c <= 8.2e-132) tmp = t_0; elseif (c <= 8.6e-75) tmp = Float64(Float64(c / Float64(d / b)) / d); elseif (c <= 4.5e-9) tmp = t_0; else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (c <= -5.1e+116) tmp = b / c; elseif (c <= 8.2e-132) tmp = t_0; elseif (c <= 8.6e-75) tmp = (c / (d / b)) / d; elseif (c <= 4.5e-9) tmp = t_0; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[c, -5.1e+116], N[(b / c), $MachinePrecision], If[LessEqual[c, 8.2e-132], t$95$0, If[LessEqual[c, 8.6e-75], N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.5e-9], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;c \leq -5.1 \cdot 10^{+116}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 8.2 \cdot 10^{-132}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 8.6 \cdot 10^{-75}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}}}{d}\\
\mathbf{elif}\;c \leq 4.5 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.09999999999999999e116 or 4.49999999999999976e-9 < c Initial program 49.8%
Taylor expanded in c around inf 70.7%
if -5.09999999999999999e116 < c < 8.20000000000000013e-132 or 8.5999999999999998e-75 < c < 4.49999999999999976e-9Initial program 74.7%
Taylor expanded in c around 0 64.8%
associate-*r/64.8%
neg-mul-164.8%
Simplified64.8%
if 8.20000000000000013e-132 < c < 8.5999999999999998e-75Initial program 68.0%
Taylor expanded in b around inf 51.7%
add-sqr-sqrt51.7%
hypot-udef51.7%
hypot-udef51.7%
times-frac67.7%
Applied egg-rr67.7%
Taylor expanded in c around 0 37.6%
*-commutative37.6%
unpow237.6%
times-frac53.3%
Simplified53.3%
clear-num53.3%
frac-times61.2%
*-un-lft-identity61.2%
associate-/r*60.9%
Applied egg-rr60.9%
Final simplification67.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.82e+117) (not (<= c 9.2e-7))) (/ b c) (/ (- (* c (/ b d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.82e+117) || !(c <= 9.2e-7)) {
tmp = b / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-1.82d+117)) .or. (.not. (c <= 9.2d-7))) then
tmp = b / c
else
tmp = ((c * (b / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.82e+117) || !(c <= 9.2e-7)) {
tmp = b / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.82e+117) or not (c <= 9.2e-7): tmp = b / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.82e+117) || !(c <= 9.2e-7)) tmp = Float64(b / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.82e+117) || ~((c <= 9.2e-7))) tmp = b / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.82e+117], N[Not[LessEqual[c, 9.2e-7]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.82 \cdot 10^{+117} \lor \neg \left(c \leq 9.2 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -1.82000000000000001e117 or 9.1999999999999998e-7 < c Initial program 49.8%
Taylor expanded in c around inf 70.7%
if -1.82000000000000001e117 < c < 9.1999999999999998e-7Initial program 74.2%
*-un-lft-identity74.2%
add-sqr-sqrt74.2%
times-frac74.1%
hypot-def74.1%
hypot-def87.0%
Applied egg-rr87.0%
Taylor expanded in c around 0 66.5%
neg-mul-166.5%
+-commutative66.5%
unpow266.5%
times-frac76.0%
unsub-neg76.0%
associate-*l/76.6%
div-sub76.9%
Simplified76.9%
Final simplification74.2%
(FPCore (a b c d) :precision binary64 (if (<= c -1.1e+117) (/ b c) (if (<= c 3.3e-6) (/ (- (* b (/ c d)) a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.1e+117) {
tmp = b / c;
} else if (c <= 3.3e-6) {
tmp = ((b * (c / d)) - 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 <= (-1.1d+117)) then
tmp = b / c
else if (c <= 3.3d-6) then
tmp = ((b * (c / d)) - 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 <= -1.1e+117) {
tmp = b / c;
} else if (c <= 3.3e-6) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.1e+117: tmp = b / c elif c <= 3.3e-6: tmp = ((b * (c / d)) - a) / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.1e+117) tmp = Float64(b / c); elseif (c <= 3.3e-6) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.1e+117) tmp = b / c; elseif (c <= 3.3e-6) tmp = ((b * (c / d)) - a) / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.1e+117], N[(b / c), $MachinePrecision], If[LessEqual[c, 3.3e-6], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.1 \cdot 10^{+117}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 3.3 \cdot 10^{-6}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.10000000000000007e117 or 3.30000000000000017e-6 < c Initial program 49.8%
Taylor expanded in c around inf 70.7%
if -1.10000000000000007e117 < c < 3.30000000000000017e-6Initial program 74.2%
Taylor expanded in c around 0 66.5%
+-commutative66.5%
mul-1-neg66.5%
unsub-neg66.5%
unpow266.5%
times-frac76.0%
Simplified76.0%
associate-*r/77.9%
sub-div78.2%
Applied egg-rr78.2%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (<= c -1.12e+117) (/ b c) (if (<= c 5e-10) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.12e+117) {
tmp = b / c;
} else if (c <= 5e-10) {
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 <= (-1.12d+117)) then
tmp = b / c
else if (c <= 5d-10) 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 <= -1.12e+117) {
tmp = b / c;
} else if (c <= 5e-10) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.12e+117: tmp = b / c elif c <= 5e-10: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.12e+117) tmp = Float64(b / c); elseif (c <= 5e-10) 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 <= -1.12e+117) tmp = b / c; elseif (c <= 5e-10) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.12e+117], N[(b / c), $MachinePrecision], If[LessEqual[c, 5e-10], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.12 \cdot 10^{+117}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{-10}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.12000000000000002e117 or 5.00000000000000031e-10 < c Initial program 49.8%
Taylor expanded in c around inf 70.7%
if -1.12000000000000002e117 < c < 5.00000000000000031e-10Initial program 74.2%
Taylor expanded in c around 0 61.2%
associate-*r/61.2%
neg-mul-161.2%
Simplified61.2%
Final simplification65.2%
(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 63.7%
Taylor expanded in c around inf 42.7%
Final simplification42.7%
(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 2023171
(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))))