
(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 7 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) (* d a)) (+ (* d d) (* c c)))))
(if (<= c -2.15e+80)
(- (/ b c) (* (/ d c) (/ a c)))
(if (<= c -2.1e-298)
t_0
(if (<= c 2.35e-222)
(/ (- a) d)
(if (<= c 8.8e+26) t_0 (+ (/ b c) (* (* d (/ a c)) (/ -1.0 c)))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / ((d * d) + (c * c));
double tmp;
if (c <= -2.15e+80) {
tmp = (b / c) - ((d / c) * (a / c));
} else if (c <= -2.1e-298) {
tmp = t_0;
} else if (c <= 2.35e-222) {
tmp = -a / d;
} else if (c <= 8.8e+26) {
tmp = t_0;
} else {
tmp = (b / c) + ((d * (a / c)) * (-1.0 / 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 = ((b * c) - (d * a)) / ((d * d) + (c * c))
if (c <= (-2.15d+80)) then
tmp = (b / c) - ((d / c) * (a / c))
else if (c <= (-2.1d-298)) then
tmp = t_0
else if (c <= 2.35d-222) then
tmp = -a / d
else if (c <= 8.8d+26) then
tmp = t_0
else
tmp = (b / c) + ((d * (a / c)) * ((-1.0d0) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / ((d * d) + (c * c));
double tmp;
if (c <= -2.15e+80) {
tmp = (b / c) - ((d / c) * (a / c));
} else if (c <= -2.1e-298) {
tmp = t_0;
} else if (c <= 2.35e-222) {
tmp = -a / d;
} else if (c <= 8.8e+26) {
tmp = t_0;
} else {
tmp = (b / c) + ((d * (a / c)) * (-1.0 / c));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (d * a)) / ((d * d) + (c * c)) tmp = 0 if c <= -2.15e+80: tmp = (b / c) - ((d / c) * (a / c)) elif c <= -2.1e-298: tmp = t_0 elif c <= 2.35e-222: tmp = -a / d elif c <= 8.8e+26: tmp = t_0 else: tmp = (b / c) + ((d * (a / c)) * (-1.0 / c)) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))) tmp = 0.0 if (c <= -2.15e+80) tmp = Float64(Float64(b / c) - Float64(Float64(d / c) * Float64(a / c))); elseif (c <= -2.1e-298) tmp = t_0; elseif (c <= 2.35e-222) tmp = Float64(Float64(-a) / d); elseif (c <= 8.8e+26) tmp = t_0; else tmp = Float64(Float64(b / c) + Float64(Float64(d * Float64(a / c)) * Float64(-1.0 / c))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (d * a)) / ((d * d) + (c * c)); tmp = 0.0; if (c <= -2.15e+80) tmp = (b / c) - ((d / c) * (a / c)); elseif (c <= -2.1e-298) tmp = t_0; elseif (c <= 2.35e-222) tmp = -a / d; elseif (c <= 8.8e+26) tmp = t_0; else tmp = (b / c) + ((d * (a / c)) * (-1.0 / c)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.15e+80], N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.1e-298], t$95$0, If[LessEqual[c, 2.35e-222], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 8.8e+26], t$95$0, N[(N[(b / c), $MachinePrecision] + N[(N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{if}\;c \leq -2.15 \cdot 10^{+80}:\\
\;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\
\mathbf{elif}\;c \leq -2.1 \cdot 10^{-298}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 2.35 \cdot 10^{-222}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 8.8 \cdot 10^{+26}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} + \left(d \cdot \frac{a}{c}\right) \cdot \frac{-1}{c}\\
\end{array}
\end{array}
if c < -2.15000000000000002e80Initial program 36.5%
Taylor expanded in c around inf 65.8%
+-commutative65.8%
mul-1-neg65.8%
unsub-neg65.8%
*-commutative65.8%
associate-/l*76.3%
Simplified76.3%
div-inv76.3%
clear-num76.3%
*-un-lft-identity76.3%
unpow276.3%
frac-times79.2%
associate-*r*82.8%
div-inv82.8%
Applied egg-rr82.8%
if -2.15000000000000002e80 < c < -2.10000000000000005e-298 or 2.3499999999999999e-222 < c < 8.80000000000000028e26Initial program 80.0%
if -2.10000000000000005e-298 < c < 2.3499999999999999e-222Initial program 72.7%
Taylor expanded in c around 0 100.0%
associate-*r/100.0%
neg-mul-1100.0%
Simplified100.0%
if 8.80000000000000028e26 < c Initial program 51.3%
Taylor expanded in c around inf 73.5%
+-commutative73.5%
mul-1-neg73.5%
unsub-neg73.5%
*-commutative73.5%
associate-/l*74.5%
Simplified74.5%
div-inv74.4%
clear-num74.4%
*-un-lft-identity74.4%
unpow274.4%
frac-times81.5%
*-commutative81.5%
associate-*l*84.6%
Applied egg-rr84.6%
Final simplification82.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* (/ b (pow d 2.0)) c) (/ a d))))
(if (<= d -5.8e+29)
t_0
(if (<= d 2.9e-121)
(/ (- b (* a (/ d c))) c)
(if (<= d 2e+50) (/ (- (* b c) (* d a)) (fma c c (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((b / pow(d, 2.0)) * c) - (a / d);
double tmp;
if (d <= -5.8e+29) {
tmp = t_0;
} else if (d <= 2.9e-121) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2e+50) {
tmp = ((b * c) - (d * a)) / fma(c, c, (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b / (d ^ 2.0)) * c) - Float64(a / d)) tmp = 0.0 if (d <= -5.8e+29) tmp = t_0; elseif (d <= 2.9e-121) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 2e+50) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / fma(c, c, Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.8e+29], t$95$0, If[LessEqual[d, 2.9e-121], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2e+50], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{{d}^{2}} \cdot c - \frac{a}{d}\\
\mathbf{if}\;d \leq -5.8 \cdot 10^{+29}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.9 \cdot 10^{-121}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{+50}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -5.7999999999999999e29 or 2.0000000000000002e50 < d Initial program 43.7%
Taylor expanded in c around 0 69.8%
+-commutative69.8%
mul-1-neg69.8%
unsub-neg69.8%
associate-/l*70.4%
associate-/r/73.2%
Simplified73.2%
if -5.7999999999999999e29 < d < 2.9e-121Initial program 77.4%
Taylor expanded in c around inf 77.3%
+-commutative77.3%
mul-1-neg77.3%
unsub-neg77.3%
*-commutative77.3%
associate-/l*75.9%
Simplified75.9%
div-inv75.9%
clear-num75.9%
*-un-lft-identity75.9%
unpow275.9%
frac-times79.0%
*-commutative79.0%
associate-*l*85.6%
Applied egg-rr85.6%
Taylor expanded in b around 0 77.3%
neg-mul-177.3%
+-commutative77.3%
unsub-neg77.3%
unpow277.3%
associate-/r*86.3%
div-sub88.9%
*-lft-identity88.9%
times-frac88.9%
/-rgt-identity88.9%
Simplified88.9%
if 2.9e-121 < d < 2.0000000000000002e50Initial program 83.7%
fma-def83.7%
Simplified83.7%
Final simplification82.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* (/ b (pow d 2.0)) c) (/ a d))))
(if (<= d -3.4e+30)
t_0
(if (<= d 2.4e-121)
(/ (- b (* a (/ d c))) c)
(if (<= d 2.1e+50) (/ (- (* b c) (* d a)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((b / pow(d, 2.0)) * c) - (a / d);
double tmp;
if (d <= -3.4e+30) {
tmp = t_0;
} else if (d <= 2.4e-121) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2.1e+50) {
tmp = ((b * c) - (d * a)) / ((d * 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 = ((b / (d ** 2.0d0)) * c) - (a / d)
if (d <= (-3.4d+30)) then
tmp = t_0
else if (d <= 2.4d-121) then
tmp = (b - (a * (d / c))) / c
else if (d <= 2.1d+50) then
tmp = ((b * c) - (d * a)) / ((d * 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 = ((b / Math.pow(d, 2.0)) * c) - (a / d);
double tmp;
if (d <= -3.4e+30) {
tmp = t_0;
} else if (d <= 2.4e-121) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2.1e+50) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b / math.pow(d, 2.0)) * c) - (a / d) tmp = 0 if d <= -3.4e+30: tmp = t_0 elif d <= 2.4e-121: tmp = (b - (a * (d / c))) / c elif d <= 2.1e+50: tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b / (d ^ 2.0)) * c) - Float64(a / d)) tmp = 0.0 if (d <= -3.4e+30) tmp = t_0; elseif (d <= 2.4e-121) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 2.1e+50) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b / (d ^ 2.0)) * c) - (a / d); tmp = 0.0; if (d <= -3.4e+30) tmp = t_0; elseif (d <= 2.4e-121) tmp = (b - (a * (d / c))) / c; elseif (d <= 2.1e+50) tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.4e+30], t$95$0, If[LessEqual[d, 2.4e-121], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.1e+50], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{{d}^{2}} \cdot c - \frac{a}{d}\\
\mathbf{if}\;d \leq -3.4 \cdot 10^{+30}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{-121}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{+50}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -3.4000000000000002e30 or 2.1e50 < d Initial program 43.7%
Taylor expanded in c around 0 69.8%
+-commutative69.8%
mul-1-neg69.8%
unsub-neg69.8%
associate-/l*70.4%
associate-/r/73.2%
Simplified73.2%
if -3.4000000000000002e30 < d < 2.40000000000000003e-121Initial program 77.4%
Taylor expanded in c around inf 77.3%
+-commutative77.3%
mul-1-neg77.3%
unsub-neg77.3%
*-commutative77.3%
associate-/l*75.9%
Simplified75.9%
div-inv75.9%
clear-num75.9%
*-un-lft-identity75.9%
unpow275.9%
frac-times79.0%
*-commutative79.0%
associate-*l*85.6%
Applied egg-rr85.6%
Taylor expanded in b around 0 77.3%
neg-mul-177.3%
+-commutative77.3%
unsub-neg77.3%
unpow277.3%
associate-/r*86.3%
div-sub88.9%
*-lft-identity88.9%
times-frac88.9%
/-rgt-identity88.9%
Simplified88.9%
if 2.40000000000000003e-121 < d < 2.1e50Initial program 83.7%
Final simplification82.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.1e+31) (not (<= d 9.5e-29))) (/ (- a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.1e+31) || !(d <= 9.5e-29)) {
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 <= (-2.1d+31)) .or. (.not. (d <= 9.5d-29))) 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 <= -2.1e+31) || !(d <= 9.5e-29)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.1e+31) or not (d <= 9.5e-29): tmp = -a / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.1e+31) || !(d <= 9.5e-29)) 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 <= -2.1e+31) || ~((d <= 9.5e-29))) tmp = -a / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.1e+31], N[Not[LessEqual[d, 9.5e-29]], $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 -2.1 \cdot 10^{+31} \lor \neg \left(d \leq 9.5 \cdot 10^{-29}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.09999999999999979e31 or 9.50000000000000023e-29 < d Initial program 49.5%
Taylor expanded in c around 0 68.2%
associate-*r/68.2%
neg-mul-168.2%
Simplified68.2%
if -2.09999999999999979e31 < d < 9.50000000000000023e-29Initial program 77.5%
Taylor expanded in c around inf 74.7%
+-commutative74.7%
mul-1-neg74.7%
unsub-neg74.7%
*-commutative74.7%
associate-/l*73.5%
Simplified73.5%
div-inv73.5%
clear-num73.5%
*-un-lft-identity73.5%
unpow273.5%
frac-times76.7%
*-commutative76.7%
associate-*l*82.3%
Applied egg-rr82.3%
Taylor expanded in b around 0 74.7%
neg-mul-174.7%
+-commutative74.7%
unsub-neg74.7%
unpow274.7%
associate-/r*82.9%
div-sub85.1%
*-lft-identity85.1%
times-frac85.1%
/-rgt-identity85.1%
Simplified85.1%
Final simplification77.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.8e+31) (not (<= d 7.2e-40))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.8e+31) || !(d <= 7.2e-40)) {
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.8d+31)) .or. (.not. (d <= 7.2d-40))) 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.8e+31) || !(d <= 7.2e-40)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.8e+31) or not (d <= 7.2e-40): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.8e+31) || !(d <= 7.2e-40)) 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.8e+31) || ~((d <= 7.2e-40))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.8e+31], N[Not[LessEqual[d, 7.2e-40]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.8 \cdot 10^{+31} \lor \neg \left(d \leq 7.2 \cdot 10^{-40}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.8000000000000001e31 or 7.2e-40 < d Initial program 49.9%
Taylor expanded in c around 0 67.9%
associate-*r/67.9%
neg-mul-167.9%
Simplified67.9%
if -3.8000000000000001e31 < d < 7.2e-40Initial program 77.6%
Taylor expanded in c around inf 61.2%
Final simplification64.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.2e+222) (not (<= d 1.25e+203))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.2e+222) || !(d <= 1.25e+203)) {
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 <= (-7.2d+222)) .or. (.not. (d <= 1.25d+203))) 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 <= -7.2e+222) || !(d <= 1.25e+203)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.2e+222) or not (d <= 1.25e+203): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.2e+222) || !(d <= 1.25e+203)) 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 <= -7.2e+222) || ~((d <= 1.25e+203))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.2e+222], N[Not[LessEqual[d, 1.25e+203]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+222} \lor \neg \left(d \leq 1.25 \cdot 10^{+203}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -7.2000000000000003e222 or 1.24999999999999999e203 < d Initial program 43.4%
cancel-sign-sub-inv43.4%
*-commutative43.4%
*-commutative43.4%
add-sqr-sqrt22.3%
sqrt-unprod43.4%
sqr-neg43.4%
sqrt-unprod21.1%
add-sqr-sqrt43.4%
Applied egg-rr43.4%
Taylor expanded in c around 0 43.9%
if -7.2000000000000003e222 < d < 1.24999999999999999e203Initial program 68.8%
Taylor expanded in c around inf 47.4%
Final simplification46.8%
(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 64.9%
cancel-sign-sub-inv64.9%
*-commutative64.9%
*-commutative64.9%
add-sqr-sqrt34.3%
sqrt-unprod44.9%
sqr-neg44.9%
sqrt-unprod17.3%
add-sqr-sqrt38.4%
Applied egg-rr38.4%
Taylor expanded in c around 0 11.1%
Final simplification11.1%
(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 2023322
(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))))