
(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 (* d (/ a c))) c)))
(if (<= c -2.7e+65)
t_0
(if (<= c -2.4e-75)
(/ (fma b c (* d (- a))) (fma d d (* c c)))
(if (<= c 3.9e-156)
(/ (- (* c (/ b d)) a) d)
(if (<= c 4.6e+67)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -2.7e+65) {
tmp = t_0;
} else if (c <= -2.4e-75) {
tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
} else if (c <= 3.9e-156) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 4.6e+67) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -2.7e+65) tmp = t_0; elseif (c <= -2.4e-75) tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c))); elseif (c <= 3.9e-156) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (c <= 4.6e+67) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.7e+65], t$95$0, If[LessEqual[c, -2.4e-75], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.9e-156], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.6e+67], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -2.4 \cdot 10^{-75}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;c \leq 3.9 \cdot 10^{-156}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 4.6 \cdot 10^{+67}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.70000000000000019e65 or 4.5999999999999997e67 < c Initial program 40.8%
fmm-def40.8%
distribute-rgt-neg-out40.8%
+-commutative40.8%
fma-define40.8%
Simplified40.8%
Taylor expanded in c around inf 73.8%
mul-1-neg73.8%
unsub-neg73.8%
*-commutative73.8%
associate-/l*81.7%
Simplified81.7%
if -2.70000000000000019e65 < c < -2.40000000000000019e-75Initial program 88.6%
fmm-def88.8%
distribute-rgt-neg-out88.8%
+-commutative88.8%
fma-define88.8%
Simplified88.8%
if -2.40000000000000019e-75 < c < 3.9000000000000001e-156Initial program 58.0%
fmm-def58.0%
distribute-rgt-neg-out58.0%
+-commutative58.0%
fma-define58.0%
Simplified58.0%
Taylor expanded in d around inf 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
*-commutative88.9%
associate-*r/90.3%
Applied egg-rr90.3%
if 3.9000000000000001e-156 < c < 4.5999999999999997e67Initial program 80.0%
Final simplification84.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (/ (- b (* d (/ a c))) c)))
(if (<= c -3.6e+62)
t_1
(if (<= c -4.2e-75)
t_0
(if (<= c 2.3e-154)
(/ (- (* c (/ b d)) a) d)
(if (<= c 1.4e+68) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -3.6e+62) {
tmp = t_1;
} else if (c <= -4.2e-75) {
tmp = t_0;
} else if (c <= 2.3e-154) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 1.4e+68) {
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 = ((c * b) - (d * a)) / ((c * c) + (d * d))
t_1 = (b - (d * (a / c))) / c
if (c <= (-3.6d+62)) then
tmp = t_1
else if (c <= (-4.2d-75)) then
tmp = t_0
else if (c <= 2.3d-154) then
tmp = ((c * (b / d)) - a) / d
else if (c <= 1.4d+68) 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 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -3.6e+62) {
tmp = t_1;
} else if (c <= -4.2e-75) {
tmp = t_0;
} else if (c <= 2.3e-154) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 1.4e+68) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) t_1 = (b - (d * (a / c))) / c tmp = 0 if c <= -3.6e+62: tmp = t_1 elif c <= -4.2e-75: tmp = t_0 elif c <= 2.3e-154: tmp = ((c * (b / d)) - a) / d elif c <= 1.4e+68: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -3.6e+62) tmp = t_1; elseif (c <= -4.2e-75) tmp = t_0; elseif (c <= 2.3e-154) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (c <= 1.4e+68) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); t_1 = (b - (d * (a / c))) / c; tmp = 0.0; if (c <= -3.6e+62) tmp = t_1; elseif (c <= -4.2e-75) tmp = t_0; elseif (c <= 2.3e-154) tmp = ((c * (b / d)) - a) / d; elseif (c <= 1.4e+68) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.6e+62], t$95$1, If[LessEqual[c, -4.2e-75], t$95$0, If[LessEqual[c, 2.3e-154], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.4e+68], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -3.6 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -4.2 \cdot 10^{-75}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{-154}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{+68}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -3.6e62 or 1.4e68 < c Initial program 40.8%
fmm-def40.8%
distribute-rgt-neg-out40.8%
+-commutative40.8%
fma-define40.8%
Simplified40.8%
Taylor expanded in c around inf 73.8%
mul-1-neg73.8%
unsub-neg73.8%
*-commutative73.8%
associate-/l*81.7%
Simplified81.7%
if -3.6e62 < c < -4.2000000000000002e-75 or 2.3e-154 < c < 1.4e68Initial program 83.5%
if -4.2000000000000002e-75 < c < 2.3e-154Initial program 58.0%
fmm-def58.0%
distribute-rgt-neg-out58.0%
+-commutative58.0%
fma-define58.0%
Simplified58.0%
Taylor expanded in d around inf 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
*-commutative88.9%
associate-*r/90.3%
Applied egg-rr90.3%
Final simplification84.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5e-8) (not (<= c 1.4e-30))) (/ (- b (* d (/ a c))) c) (/ (- (* c (/ b d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5e-8) || !(c <= 1.4e-30)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5d-8)) .or. (.not. (c <= 1.4d-30))) then
tmp = (b - (d * (a / c))) / c
else
tmp = ((c * (b / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5e-8) || !(c <= 1.4e-30)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5e-8) or not (c <= 1.4e-30): tmp = (b - (d * (a / c))) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5e-8) || !(c <= 1.4e-30)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / 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 <= -5e-8) || ~((c <= 1.4e-30))) tmp = (b - (d * (a / c))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5e-8], N[Not[LessEqual[c, 1.4e-30]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 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 -5 \cdot 10^{-8} \lor \neg \left(c \leq 1.4 \cdot 10^{-30}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -4.9999999999999998e-8 or 1.39999999999999994e-30 < c Initial program 49.4%
fmm-def49.4%
distribute-rgt-neg-out49.4%
+-commutative49.4%
fma-define49.4%
Simplified49.4%
Taylor expanded in c around inf 70.5%
mul-1-neg70.5%
unsub-neg70.5%
*-commutative70.5%
associate-/l*76.7%
Simplified76.7%
if -4.9999999999999998e-8 < c < 1.39999999999999994e-30Initial program 67.0%
fmm-def67.0%
distribute-rgt-neg-out67.0%
+-commutative67.0%
fma-define67.0%
Simplified67.0%
Taylor expanded in d around inf 84.5%
+-commutative84.5%
mul-1-neg84.5%
unsub-neg84.5%
*-commutative84.5%
associate-*r/85.5%
Applied egg-rr85.5%
Final simplification80.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6.2e-8) (not (<= c 5.9e-30))) (/ (- b (* d (/ a c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.2e-8) || !(c <= 5.9e-30)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-6.2d-8)) .or. (.not. (c <= 5.9d-30))) then
tmp = (b - (d * (a / c))) / c
else
tmp = ((b * (c / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.2e-8) || !(c <= 5.9e-30)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6.2e-8) or not (c <= 5.9e-30): tmp = (b - (d * (a / c))) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6.2e-8) || !(c <= 5.9e-30)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6.2e-8) || ~((c <= 5.9e-30))) tmp = (b - (d * (a / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6.2e-8], N[Not[LessEqual[c, 5.9e-30]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-8} \lor \neg \left(c \leq 5.9 \cdot 10^{-30}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -6.2e-8 or 5.89999999999999979e-30 < c Initial program 49.4%
fmm-def49.4%
distribute-rgt-neg-out49.4%
+-commutative49.4%
fma-define49.4%
Simplified49.4%
Taylor expanded in c around inf 70.5%
mul-1-neg70.5%
unsub-neg70.5%
*-commutative70.5%
associate-/l*76.7%
Simplified76.7%
if -6.2e-8 < c < 5.89999999999999979e-30Initial program 67.0%
fmm-def67.0%
distribute-rgt-neg-out67.0%
+-commutative67.0%
fma-define67.0%
Simplified67.0%
Taylor expanded in d around -inf 84.5%
mul-1-neg84.5%
distribute-neg-frac284.5%
mul-1-neg84.5%
unsub-neg84.5%
*-commutative84.5%
associate-/l*85.5%
Simplified85.5%
Taylor expanded in a around 0 76.7%
+-commutative76.7%
mul-1-neg76.7%
unsub-neg76.7%
*-commutative76.7%
unpow276.7%
associate-/r*82.6%
associate-*r/83.6%
div-sub85.5%
associate-*r/84.5%
associate-*l/84.4%
*-commutative84.4%
Simplified84.4%
Final simplification80.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.8e+36) (not (<= d 9e+87))) (/ a (- d)) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e+36) || !(d <= 9e+87)) {
tmp = a / -d;
} else {
tmp = (b - ((d * a) / 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 <= (-4.8d+36)) .or. (.not. (d <= 9d+87))) then
tmp = a / -d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e+36) || !(d <= 9e+87)) {
tmp = a / -d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.8e+36) or not (d <= 9e+87): tmp = a / -d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.8e+36) || !(d <= 9e+87)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.8e+36) || ~((d <= 9e+87))) tmp = a / -d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e+36], N[Not[LessEqual[d, 9e+87]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{+36} \lor \neg \left(d \leq 9 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -4.79999999999999985e36 or 9.0000000000000005e87 < d Initial program 42.6%
fmm-def42.6%
distribute-rgt-neg-out42.6%
+-commutative42.6%
fma-define42.6%
Simplified42.6%
Taylor expanded in c around 0 71.0%
associate-*r/71.0%
neg-mul-171.0%
Simplified71.0%
if -4.79999999999999985e36 < d < 9.0000000000000005e87Initial program 68.9%
fmm-def68.9%
distribute-rgt-neg-out68.9%
+-commutative68.9%
fma-define68.9%
Simplified68.9%
Taylor expanded in c around inf 78.2%
mul-1-neg78.2%
unsub-neg78.2%
*-commutative78.2%
associate-/l*76.9%
Simplified76.9%
associate-*r/78.2%
Applied egg-rr78.2%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.55e+131) (not (<= d 4.6e+87))) (/ a (- d)) (/ (- b (* d (/ a c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.55e+131) || !(d <= 4.6e+87)) {
tmp = a / -d;
} else {
tmp = (b - (d * (a / 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.55d+131)) .or. (.not. (d <= 4.6d+87))) then
tmp = a / -d
else
tmp = (b - (d * (a / 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.55e+131) || !(d <= 4.6e+87)) {
tmp = a / -d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.55e+131) or not (d <= 4.6e+87): tmp = a / -d else: tmp = (b - (d * (a / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.55e+131) || !(d <= 4.6e+87)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.55e+131) || ~((d <= 4.6e+87))) tmp = a / -d; else tmp = (b - (d * (a / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.55e+131], N[Not[LessEqual[d, 4.6e+87]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.55 \cdot 10^{+131} \lor \neg \left(d \leq 4.6 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if d < -1.55000000000000008e131 or 4.6000000000000003e87 < d Initial program 37.0%
fmm-def37.0%
distribute-rgt-neg-out37.0%
+-commutative37.0%
fma-define37.0%
Simplified37.0%
Taylor expanded in c around 0 78.4%
associate-*r/78.4%
neg-mul-178.4%
Simplified78.4%
if -1.55000000000000008e131 < d < 4.6000000000000003e87Initial program 67.8%
fmm-def67.8%
distribute-rgt-neg-out67.8%
+-commutative67.8%
fma-define67.8%
Simplified67.8%
Taylor expanded in c around inf 73.0%
mul-1-neg73.0%
unsub-neg73.0%
*-commutative73.0%
associate-/l*72.9%
Simplified72.9%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.5e-42) (not (<= d 1.85e+87))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.5e-42) || !(d <= 1.85e+87)) {
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 <= (-4.5d-42)) .or. (.not. (d <= 1.85d+87))) 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 <= -4.5e-42) || !(d <= 1.85e+87)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.5e-42) or not (d <= 1.85e+87): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.5e-42) || !(d <= 1.85e+87)) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.5e-42) || ~((d <= 1.85e+87))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.5e-42], N[Not[LessEqual[d, 1.85e+87]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.5 \cdot 10^{-42} \lor \neg \left(d \leq 1.85 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -4.5e-42 or 1.85000000000000001e87 < d Initial program 45.4%
fmm-def45.4%
distribute-rgt-neg-out45.4%
+-commutative45.4%
fma-define45.4%
Simplified45.4%
Taylor expanded in c around 0 68.3%
associate-*r/68.3%
neg-mul-168.3%
Simplified68.3%
if -4.5e-42 < d < 1.85000000000000001e87Initial program 68.4%
fmm-def68.4%
distribute-rgt-neg-out68.4%
+-commutative68.4%
fma-define68.4%
Simplified68.4%
Taylor expanded in c around inf 65.9%
Final simplification67.1%
(FPCore (a b c d) :precision binary64 (if (<= d -3e+133) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e+133) {
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 <= (-3d+133)) 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 <= -3e+133) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3e+133: tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3e+133) 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 <= -3e+133) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3e+133], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{+133}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.00000000000000007e133Initial program 39.3%
fmm-def39.3%
distribute-rgt-neg-out39.3%
+-commutative39.3%
fma-define39.3%
Simplified39.3%
Taylor expanded in c around 0 81.7%
associate-*r/81.7%
neg-mul-181.7%
Simplified81.7%
add-sqr-sqrt40.5%
sqrt-unprod47.4%
sqr-neg47.4%
sqrt-unprod12.0%
add-sqr-sqrt35.0%
*-un-lft-identity35.0%
Applied egg-rr35.0%
*-lft-identity35.0%
Simplified35.0%
if -3.00000000000000007e133 < d Initial program 60.2%
fmm-def60.2%
distribute-rgt-neg-out60.2%
+-commutative60.2%
fma-define60.2%
Simplified60.2%
Taylor expanded in c around inf 49.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 57.0%
fmm-def57.0%
distribute-rgt-neg-out57.0%
+-commutative57.0%
fma-define57.0%
Simplified57.0%
Taylor expanded in c around 0 43.5%
associate-*r/43.5%
neg-mul-143.5%
Simplified43.5%
add-sqr-sqrt21.5%
sqrt-unprod23.7%
sqr-neg23.7%
sqrt-unprod4.9%
add-sqr-sqrt13.4%
*-un-lft-identity13.4%
Applied egg-rr13.4%
*-lft-identity13.4%
Simplified13.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 2024188
(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))))