
(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 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.8e+78)
t_0
(if (<= d -6.6e-152)
(/ (fma b c (* d (- a))) (fma d d (* c c)))
(if (<= d 5.2e-12) (/ (- b (* a (/ d c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.8e+78) {
tmp = t_0;
} else if (d <= -6.6e-152) {
tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
} else if (d <= 5.2e-12) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -1.8e+78) tmp = t_0; elseif (d <= -6.6e-152) tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c))); elseif (d <= 5.2e-12) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.8e+78], t$95$0, If[LessEqual[d, -6.6e-152], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.2e-12], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.8 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -6.6 \cdot 10^{-152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 5.2 \cdot 10^{-12}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.8000000000000001e78 or 5.19999999999999965e-12 < d Initial program 44.1%
fma-neg44.1%
distribute-rgt-neg-out44.1%
+-commutative44.1%
fma-define44.1%
Simplified44.1%
Taylor expanded in c around 0 75.0%
+-commutative75.0%
mul-1-neg75.0%
unsub-neg75.0%
unpow275.0%
associate-/r*79.5%
div-sub79.5%
*-commutative79.5%
associate-/l*82.4%
Simplified82.4%
if -1.8000000000000001e78 < d < -6.59999999999999997e-152Initial program 79.6%
fma-neg79.6%
distribute-rgt-neg-out79.6%
+-commutative79.6%
fma-define79.7%
Simplified79.7%
if -6.59999999999999997e-152 < d < 5.19999999999999965e-12Initial program 66.0%
fma-neg66.0%
distribute-rgt-neg-out66.0%
+-commutative66.0%
fma-define66.0%
Simplified66.0%
Taylor expanded in c around inf 89.6%
mul-1-neg89.6%
unsub-neg89.6%
associate-/l*90.9%
Simplified90.9%
Final simplification85.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.48e+78)
t_0
(if (<= d -3.4e-152)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(if (<= d 6.5e-12) (/ (- b (* a (/ d c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.48e+78) {
tmp = t_0;
} else if (d <= -3.4e-152) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 6.5e-12) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = ((c * (b / d)) - a) / d
if (d <= (-1.48d+78)) then
tmp = t_0
else if (d <= (-3.4d-152)) then
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
else if (d <= 6.5d-12) then
tmp = (b - (a * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.48e+78) {
tmp = t_0;
} else if (d <= -3.4e-152) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 6.5e-12) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * (b / d)) - a) / d tmp = 0 if d <= -1.48e+78: tmp = t_0 elif d <= -3.4e-152: tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)) elif d <= 6.5e-12: tmp = (b - (a * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -1.48e+78) tmp = t_0; elseif (d <= -3.4e-152) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 6.5e-12) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -1.48e+78) tmp = t_0; elseif (d <= -3.4e-152) tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)); elseif (d <= 6.5e-12) tmp = (b - (a * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.48e+78], t$95$0, If[LessEqual[d, -3.4e-152], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.5e-12], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.48 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -3.4 \cdot 10^{-152}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 6.5 \cdot 10^{-12}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.47999999999999998e78 or 6.5000000000000002e-12 < d Initial program 44.1%
fma-neg44.1%
distribute-rgt-neg-out44.1%
+-commutative44.1%
fma-define44.1%
Simplified44.1%
Taylor expanded in c around 0 75.0%
+-commutative75.0%
mul-1-neg75.0%
unsub-neg75.0%
unpow275.0%
associate-/r*79.5%
div-sub79.5%
*-commutative79.5%
associate-/l*82.4%
Simplified82.4%
if -1.47999999999999998e78 < d < -3.39999999999999984e-152Initial program 79.6%
if -3.39999999999999984e-152 < d < 6.5000000000000002e-12Initial program 66.0%
fma-neg66.0%
distribute-rgt-neg-out66.0%
+-commutative66.0%
fma-define66.0%
Simplified66.0%
Taylor expanded in c around inf 89.6%
mul-1-neg89.6%
unsub-neg89.6%
associate-/l*90.9%
Simplified90.9%
Final simplification85.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.75e-41) (not (<= d 6.4e-12))) (/ (- (* b (/ c d)) a) d) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.75e-41) || !(d <= 6.4e-12)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2.75d-41)) .or. (.not. (d <= 6.4d-12))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.75e-41) || !(d <= 6.4e-12)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.75e-41) or not (d <= 6.4e-12): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.75e-41) || !(d <= 6.4e-12)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.75e-41) || ~((d <= 6.4e-12))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.75e-41], N[Not[LessEqual[d, 6.4e-12]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.75 \cdot 10^{-41} \lor \neg \left(d \leq 6.4 \cdot 10^{-12}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -2.75000000000000011e-41 or 6.4000000000000002e-12 < d Initial program 49.2%
add-cbrt-cube44.2%
pow1/344.1%
pow344.1%
pow244.1%
pow-pow44.1%
metadata-eval44.1%
Applied egg-rr44.1%
Taylor expanded in d around inf 76.2%
+-commutative76.2%
mul-1-neg76.2%
unsub-neg76.2%
associate-/l*78.6%
Simplified78.6%
if -2.75000000000000011e-41 < d < 6.4000000000000002e-12Initial program 69.7%
fma-neg69.7%
distribute-rgt-neg-out69.7%
+-commutative69.7%
fma-define69.8%
Simplified69.8%
Taylor expanded in c around inf 83.1%
mul-1-neg83.1%
unsub-neg83.1%
associate-/l*84.1%
Simplified84.1%
Taylor expanded in a around 0 83.1%
associate-*l/83.4%
associate-/r/84.1%
Simplified84.1%
Final simplification81.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8.0) (not (<= d 1.6e+73))) (/ a (- d)) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8.0) || !(d <= 1.6e+73)) {
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 <= (-8.0d0)) .or. (.not. (d <= 1.6d+73))) 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 <= -8.0) || !(d <= 1.6e+73)) {
tmp = a / -d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8.0) or not (d <= 1.6e+73): tmp = a / -d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8.0) || !(d <= 1.6e+73)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -8.0) || ~((d <= 1.6e+73))) tmp = a / -d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8.0], N[Not[LessEqual[d, 1.6e+73]], $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 -8 \lor \neg \left(d \leq 1.6 \cdot 10^{+73}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -8 or 1.59999999999999991e73 < d Initial program 43.1%
fma-neg43.1%
distribute-rgt-neg-out43.1%
+-commutative43.1%
fma-define43.1%
Simplified43.1%
Taylor expanded in c around 0 71.3%
associate-*r/71.3%
neg-mul-171.3%
Simplified71.3%
if -8 < d < 1.59999999999999991e73Initial program 69.8%
fma-neg69.8%
distribute-rgt-neg-out69.8%
+-commutative69.8%
fma-define69.8%
Simplified69.8%
Taylor expanded in c around inf 75.5%
mul-1-neg75.5%
unsub-neg75.5%
associate-/l*76.8%
Simplified76.8%
Taylor expanded in a around 0 75.5%
associate-*l/76.2%
associate-/r/76.9%
Simplified76.9%
Final simplification74.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.00125) (not (<= d 2.1e+73))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00125) || !(d <= 2.1e+73)) {
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 <= (-0.00125d0)) .or. (.not. (d <= 2.1d+73))) 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 <= -0.00125) || !(d <= 2.1e+73)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.00125) or not (d <= 2.1e+73): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.00125) || !(d <= 2.1e+73)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.00125) || ~((d <= 2.1e+73))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.00125], N[Not[LessEqual[d, 2.1e+73]], $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 -0.00125 \lor \neg \left(d \leq 2.1 \cdot 10^{+73}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.00125000000000000003 or 2.1000000000000001e73 < d Initial program 43.1%
fma-neg43.1%
distribute-rgt-neg-out43.1%
+-commutative43.1%
fma-define43.1%
Simplified43.1%
Taylor expanded in c around 0 71.3%
associate-*r/71.3%
neg-mul-171.3%
Simplified71.3%
if -0.00125000000000000003 < d < 2.1000000000000001e73Initial program 69.8%
fma-neg69.8%
distribute-rgt-neg-out69.8%
+-commutative69.8%
fma-define69.8%
Simplified69.8%
Taylor expanded in c around inf 75.5%
mul-1-neg75.5%
unsub-neg75.5%
associate-/l*76.8%
Simplified76.8%
Final simplification74.7%
(FPCore (a b c d) :precision binary64 (if (<= d -1.06e-42) (/ (- (/ b (/ d c)) a) d) (if (<= d 6.2e-12) (/ (- b (/ a (/ c d))) c) (/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.06e-42) {
tmp = ((b / (d / c)) - a) / d;
} else if (d <= 6.2e-12) {
tmp = (b - (a / (c / d))) / 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 (d <= (-1.06d-42)) then
tmp = ((b / (d / c)) - a) / d
else if (d <= 6.2d-12) then
tmp = (b - (a / (c / d))) / 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 (d <= -1.06e-42) {
tmp = ((b / (d / c)) - a) / d;
} else if (d <= 6.2e-12) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.06e-42: tmp = ((b / (d / c)) - a) / d elif d <= 6.2e-12: tmp = (b - (a / (c / d))) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.06e-42) tmp = Float64(Float64(Float64(b / Float64(d / c)) - a) / d); elseif (d <= 6.2e-12) tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / 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 (d <= -1.06e-42) tmp = ((b / (d / c)) - a) / d; elseif (d <= 6.2e-12) tmp = (b - (a / (c / d))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.06e-42], N[(N[(N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 6.2e-12], N[(N[(b - N[(a / N[(c / d), $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}\;d \leq -1.06 \cdot 10^{-42}:\\
\;\;\;\;\frac{\frac{b}{\frac{d}{c}} - a}{d}\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{-12}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.0600000000000001e-42Initial program 42.7%
add-cbrt-cube40.9%
pow1/340.8%
pow340.8%
pow240.8%
pow-pow40.8%
metadata-eval40.8%
Applied egg-rr40.8%
Taylor expanded in d around inf 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
associate-/l*76.8%
Simplified76.8%
clear-num76.8%
un-div-inv76.8%
Applied egg-rr76.8%
if -1.0600000000000001e-42 < d < 6.2000000000000002e-12Initial program 69.7%
fma-neg69.7%
distribute-rgt-neg-out69.7%
+-commutative69.7%
fma-define69.8%
Simplified69.8%
Taylor expanded in c around inf 83.1%
mul-1-neg83.1%
unsub-neg83.1%
associate-/l*84.1%
Simplified84.1%
Taylor expanded in a around 0 83.1%
associate-*l/83.4%
associate-/r/84.1%
Simplified84.1%
if 6.2000000000000002e-12 < d Initial program 54.7%
fma-neg54.7%
distribute-rgt-neg-out54.7%
+-commutative54.7%
fma-define54.7%
Simplified54.7%
Taylor expanded in c around 0 73.2%
+-commutative73.2%
mul-1-neg73.2%
unsub-neg73.2%
unpow273.2%
associate-/r*77.3%
div-sub77.3%
*-commutative77.3%
associate-/l*80.2%
Simplified80.2%
(FPCore (a b c d) :precision binary64 (if (<= d -1.12e-41) (/ (- (* b (/ c d)) a) d) (if (<= d 5.2e-12) (/ (- b (/ a (/ c d))) c) (/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.12e-41) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 5.2e-12) {
tmp = (b - (a / (c / d))) / 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 (d <= (-1.12d-41)) then
tmp = ((b * (c / d)) - a) / d
else if (d <= 5.2d-12) then
tmp = (b - (a / (c / d))) / 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 (d <= -1.12e-41) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 5.2e-12) {
tmp = (b - (a / (c / d))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.12e-41: tmp = ((b * (c / d)) - a) / d elif d <= 5.2e-12: tmp = (b - (a / (c / d))) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.12e-41) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (d <= 5.2e-12) tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / 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 (d <= -1.12e-41) tmp = ((b * (c / d)) - a) / d; elseif (d <= 5.2e-12) tmp = (b - (a / (c / d))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.12e-41], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 5.2e-12], N[(N[(b - N[(a / N[(c / d), $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}\;d \leq -1.12 \cdot 10^{-41}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;d \leq 5.2 \cdot 10^{-12}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.11999999999999999e-41Initial program 42.7%
add-cbrt-cube40.9%
pow1/340.8%
pow340.8%
pow240.8%
pow-pow40.8%
metadata-eval40.8%
Applied egg-rr40.8%
Taylor expanded in d around inf 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
associate-/l*76.8%
Simplified76.8%
if -1.11999999999999999e-41 < d < 5.19999999999999965e-12Initial program 69.7%
fma-neg69.7%
distribute-rgt-neg-out69.7%
+-commutative69.7%
fma-define69.8%
Simplified69.8%
Taylor expanded in c around inf 83.1%
mul-1-neg83.1%
unsub-neg83.1%
associate-/l*84.1%
Simplified84.1%
Taylor expanded in a around 0 83.1%
associate-*l/83.4%
associate-/r/84.1%
Simplified84.1%
if 5.19999999999999965e-12 < d Initial program 54.7%
fma-neg54.7%
distribute-rgt-neg-out54.7%
+-commutative54.7%
fma-define54.7%
Simplified54.7%
Taylor expanded in c around 0 73.2%
+-commutative73.2%
mul-1-neg73.2%
unsub-neg73.2%
unpow273.2%
associate-/r*77.3%
div-sub77.3%
*-commutative77.3%
associate-/l*80.2%
Simplified80.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8e+19) (not (<= c 1.04e+71))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8e+19) || !(c <= 1.04e+71)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-8d+19)) .or. (.not. (c <= 1.04d+71))) then
tmp = b / c
else
tmp = a / -d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8e+19) || !(c <= 1.04e+71)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8e+19) or not (c <= 1.04e+71): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8e+19) || !(c <= 1.04e+71)) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -8e+19) || ~((c <= 1.04e+71))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8e+19], N[Not[LessEqual[c, 1.04e+71]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8 \cdot 10^{+19} \lor \neg \left(c \leq 1.04 \cdot 10^{+71}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -8e19 or 1.04e71 < c Initial program 46.5%
fma-neg46.5%
distribute-rgt-neg-out46.5%
+-commutative46.5%
fma-define46.5%
Simplified46.5%
Taylor expanded in c around inf 73.4%
if -8e19 < c < 1.04e71Initial program 69.7%
fma-neg69.7%
distribute-rgt-neg-out69.7%
+-commutative69.7%
fma-define69.7%
Simplified69.7%
Taylor expanded in c around 0 63.0%
associate-*r/63.0%
neg-mul-163.0%
Simplified63.0%
Final simplification67.6%
(FPCore (a b c d) :precision binary64 (if (<= d 1.18e+131) (/ b c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 1.18e+131) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= 1.18d+131) then
tmp = b / c
else
tmp = a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= 1.18e+131) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 1.18e+131: tmp = b / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 1.18e+131) tmp = Float64(b / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 1.18e+131) tmp = b / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 1.18e+131], N[(b / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 1.18 \cdot 10^{+131}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 1.18e131Initial program 63.1%
fma-neg63.1%
distribute-rgt-neg-out63.1%
+-commutative63.1%
fma-define63.1%
Simplified63.1%
Taylor expanded in c around inf 50.0%
if 1.18e131 < d Initial program 37.7%
fma-neg37.7%
distribute-rgt-neg-out37.7%
+-commutative37.7%
fma-define37.7%
Simplified37.7%
Taylor expanded in c around 0 77.2%
associate-*r/77.2%
neg-mul-177.2%
Simplified77.2%
*-un-lft-identity77.2%
*-commutative77.2%
add-sqr-sqrt41.6%
sqrt-unprod44.1%
sqr-neg44.1%
sqrt-unprod13.6%
add-sqr-sqrt28.1%
Applied egg-rr28.1%
*-rgt-identity28.1%
Simplified28.1%
(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 59.6%
fma-neg59.6%
distribute-rgt-neg-out59.6%
+-commutative59.6%
fma-define59.6%
Simplified59.6%
Taylor expanded in c around 0 42.0%
associate-*r/42.0%
neg-mul-142.0%
Simplified42.0%
*-un-lft-identity42.0%
*-commutative42.0%
add-sqr-sqrt21.1%
sqrt-unprod23.0%
sqr-neg23.0%
sqrt-unprod4.6%
add-sqr-sqrt8.8%
Applied egg-rr8.8%
*-rgt-identity8.8%
Simplified8.8%
(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 2024137
(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))))