
(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 (- (/ c (* d (/ d b))) (/ a d))))
(if (<= d -4.8e+91)
t_0
(if (<= d 1.72e-69)
(- (/ b c) (/ (/ a (/ c d)) c))
(if (<= d 1.9e+45) (/ (fma b c (* d (- a))) (fma c c (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (c / (d * (d / b))) - (a / d);
double tmp;
if (d <= -4.8e+91) {
tmp = t_0;
} else if (d <= 1.72e-69) {
tmp = (b / c) - ((a / (c / d)) / c);
} else if (d <= 1.9e+45) {
tmp = fma(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(c / Float64(d * Float64(d / b))) - Float64(a / d)) tmp = 0.0 if (d <= -4.8e+91) tmp = t_0; elseif (d <= 1.72e-69) tmp = Float64(Float64(b / c) - Float64(Float64(a / Float64(c / d)) / c)); elseif (d <= 1.9e+45) tmp = Float64(fma(b, c, Float64(d * Float64(-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[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.8e+91], t$95$0, If[LessEqual[d, 1.72e-69], N[(N[(b / c), $MachinePrecision] - N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.9e+45], N[(N[(b * c + 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{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.72 \cdot 10^{-69}:\\
\;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+45}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -4.79999999999999966e91 or 1.9000000000000001e45 < d Initial program 41.8%
Taylor expanded in c around 0 74.5%
+-commutative74.5%
mul-1-neg74.5%
unsub-neg74.5%
*-commutative74.5%
associate-/l*76.7%
Simplified76.7%
pow276.7%
*-un-lft-identity76.7%
times-frac80.2%
Applied egg-rr80.2%
if -4.79999999999999966e91 < d < 1.72e-69Initial program 66.7%
Taylor expanded in c around inf 72.7%
+-commutative72.7%
mul-1-neg72.7%
unsub-neg72.7%
associate-/l*72.1%
associate-/r/65.4%
Simplified65.4%
*-un-lft-identity65.4%
pow265.4%
times-frac70.6%
Applied egg-rr70.6%
associate-*l*77.5%
associate-*l/77.5%
*-un-lft-identity77.5%
associate-/r/80.1%
Applied egg-rr80.1%
if 1.72e-69 < d < 1.9000000000000001e45Initial program 76.7%
fma-neg76.8%
distribute-lft-neg-out76.8%
*-commutative76.8%
fma-def76.8%
Simplified76.8%
Final simplification79.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ c (* d (/ d b))) (/ a d))))
(if (<= d -5e+91)
t_0
(if (<= d 4.5e-72)
(- (/ b c) (/ (/ a (/ c d)) c))
(if (<= d 1.55e+44) (/ (- (* c b) (* d a)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (c / (d * (d / b))) - (a / d);
double tmp;
if (d <= -5e+91) {
tmp = t_0;
} else if (d <= 4.5e-72) {
tmp = (b / c) - ((a / (c / d)) / c);
} else if (d <= 1.55e+44) {
tmp = ((c * b) - (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 = (c / (d * (d / b))) - (a / d)
if (d <= (-5d+91)) then
tmp = t_0
else if (d <= 4.5d-72) then
tmp = (b / c) - ((a / (c / d)) / c)
else if (d <= 1.55d+44) then
tmp = ((c * b) - (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 = (c / (d * (d / b))) - (a / d);
double tmp;
if (d <= -5e+91) {
tmp = t_0;
} else if (d <= 4.5e-72) {
tmp = (b / c) - ((a / (c / d)) / c);
} else if (d <= 1.55e+44) {
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (c / (d * (d / b))) - (a / d) tmp = 0 if d <= -5e+91: tmp = t_0 elif d <= 4.5e-72: tmp = (b / c) - ((a / (c / d)) / c) elif d <= 1.55e+44: tmp = ((c * b) - (d * a)) / ((d * d) + (c * c)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(c / Float64(d * Float64(d / b))) - Float64(a / d)) tmp = 0.0 if (d <= -5e+91) tmp = t_0; elseif (d <= 4.5e-72) tmp = Float64(Float64(b / c) - Float64(Float64(a / Float64(c / d)) / c)); elseif (d <= 1.55e+44) tmp = Float64(Float64(Float64(c * b) - 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 = (c / (d * (d / b))) - (a / d); tmp = 0.0; if (d <= -5e+91) tmp = t_0; elseif (d <= 4.5e-72) tmp = (b / c) - ((a / (c / d)) / c); elseif (d <= 1.55e+44) tmp = ((c * b) - (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[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5e+91], t$95$0, If[LessEqual[d, 4.5e-72], N[(N[(b / c), $MachinePrecision] - N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.55e+44], N[(N[(N[(c * b), $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{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\
\mathbf{if}\;d \leq -5 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{-72}:\\
\;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\
\mathbf{elif}\;d \leq 1.55 \cdot 10^{+44}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -5.0000000000000002e91 or 1.54999999999999998e44 < d Initial program 41.8%
Taylor expanded in c around 0 74.5%
+-commutative74.5%
mul-1-neg74.5%
unsub-neg74.5%
*-commutative74.5%
associate-/l*76.7%
Simplified76.7%
pow276.7%
*-un-lft-identity76.7%
times-frac80.2%
Applied egg-rr80.2%
if -5.0000000000000002e91 < d < 4.5e-72Initial program 66.7%
Taylor expanded in c around inf 72.7%
+-commutative72.7%
mul-1-neg72.7%
unsub-neg72.7%
associate-/l*72.1%
associate-/r/65.4%
Simplified65.4%
*-un-lft-identity65.4%
pow265.4%
times-frac70.6%
Applied egg-rr70.6%
associate-*l*77.5%
associate-*l/77.5%
*-un-lft-identity77.5%
associate-/r/80.1%
Applied egg-rr80.1%
if 4.5e-72 < d < 1.54999999999999998e44Initial program 76.7%
Final simplification79.7%
(FPCore (a b c d)
:precision binary64
(if (or (<= c -0.000235)
(and (not (<= c -3.55e-168))
(or (<= c -6.2e-202) (not (<= c 360000000000.0)))))
(- (/ b c) (* d (/ (/ a c) c)))
(/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -0.000235) || (!(c <= -3.55e-168) && ((c <= -6.2e-202) || !(c <= 360000000000.0)))) {
tmp = (b / c) - (d * ((a / c) / 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 <= (-0.000235d0)) .or. (.not. (c <= (-3.55d-168))) .and. (c <= (-6.2d-202)) .or. (.not. (c <= 360000000000.0d0))) then
tmp = (b / c) - (d * ((a / c) / 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 <= -0.000235) || (!(c <= -3.55e-168) && ((c <= -6.2e-202) || !(c <= 360000000000.0)))) {
tmp = (b / c) - (d * ((a / c) / c));
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -0.000235) or (not (c <= -3.55e-168) and ((c <= -6.2e-202) or not (c <= 360000000000.0))): tmp = (b / c) - (d * ((a / c) / c)) else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -0.000235) || (!(c <= -3.55e-168) && ((c <= -6.2e-202) || !(c <= 360000000000.0)))) tmp = Float64(Float64(b / c) - Float64(d * Float64(Float64(a / c) / c))); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -0.000235) || (~((c <= -3.55e-168)) && ((c <= -6.2e-202) || ~((c <= 360000000000.0))))) tmp = (b / c) - (d * ((a / c) / c)); else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -0.000235], And[N[Not[LessEqual[c, -3.55e-168]], $MachinePrecision], Or[LessEqual[c, -6.2e-202], N[Not[LessEqual[c, 360000000000.0]], $MachinePrecision]]]], N[(N[(b / c), $MachinePrecision] - N[(d * N[(N[(a / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -0.000235 \lor \neg \left(c \leq -3.55 \cdot 10^{-168}\right) \land \left(c \leq -6.2 \cdot 10^{-202} \lor \neg \left(c \leq 360000000000\right)\right):\\
\;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -2.34999999999999993e-4 or -3.55000000000000009e-168 < c < -6.2e-202 or 3.6e11 < c Initial program 47.6%
Taylor expanded in c around inf 62.5%
+-commutative62.5%
mul-1-neg62.5%
unsub-neg62.5%
associate-/l*62.2%
associate-/r/64.7%
Simplified64.7%
*-un-lft-identity64.7%
pow264.7%
times-frac73.9%
Applied egg-rr73.9%
associate-*l/73.9%
*-lft-identity73.9%
Simplified73.9%
if -2.34999999999999993e-4 < c < -3.55000000000000009e-168 or -6.2e-202 < c < 3.6e11Initial program 70.5%
Taylor expanded in c around 0 68.9%
associate-*r/68.9%
neg-mul-168.9%
Simplified68.9%
Final simplification71.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.9e+93) (not (<= d 9e+43))) (/ (- a) d) (- (/ b c) (/ (/ a (/ c d)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.9e+93) || !(d <= 9e+43)) {
tmp = -a / d;
} else {
tmp = (b / c) - ((a / (c / d)) / c);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.9d+93)) .or. (.not. (d <= 9d+43))) then
tmp = -a / d
else
tmp = (b / c) - ((a / (c / d)) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.9e+93) || !(d <= 9e+43)) {
tmp = -a / d;
} else {
tmp = (b / c) - ((a / (c / d)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.9e+93) or not (d <= 9e+43): tmp = -a / d else: tmp = (b / c) - ((a / (c / d)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.9e+93) || !(d <= 9e+43)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b / c) - Float64(Float64(a / Float64(c / d)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.9e+93) || ~((d <= 9e+43))) tmp = -a / d; else tmp = (b / c) - ((a / (c / d)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.9e+93], N[Not[LessEqual[d, 9e+43]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{+93} \lor \neg \left(d \leq 9 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -1.8999999999999999e93 or 9e43 < d Initial program 41.3%
Taylor expanded in c around 0 71.2%
associate-*r/71.2%
neg-mul-171.2%
Simplified71.2%
if -1.8999999999999999e93 < d < 9e43Initial program 69.3%
Taylor expanded in c around inf 69.5%
+-commutative69.5%
mul-1-neg69.5%
unsub-neg69.5%
associate-/l*69.0%
associate-/r/63.9%
Simplified63.9%
*-un-lft-identity63.9%
pow263.9%
times-frac68.5%
Applied egg-rr68.5%
associate-*l*73.8%
associate-*l/73.8%
*-un-lft-identity73.8%
associate-/r/75.8%
Applied egg-rr75.8%
Final simplification73.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.8e+91) (not (<= d 5.2e+43))) (- (/ c (* d (/ d b))) (/ a d)) (- (/ b c) (/ (/ a (/ c d)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e+91) || !(d <= 5.2e+43)) {
tmp = (c / (d * (d / b))) - (a / d);
} else {
tmp = (b / c) - ((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 <= (-4.8d+91)) .or. (.not. (d <= 5.2d+43))) then
tmp = (c / (d * (d / b))) - (a / d)
else
tmp = (b / c) - ((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 <= -4.8e+91) || !(d <= 5.2e+43)) {
tmp = (c / (d * (d / b))) - (a / d);
} else {
tmp = (b / c) - ((a / (c / d)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.8e+91) or not (d <= 5.2e+43): tmp = (c / (d * (d / b))) - (a / d) else: tmp = (b / c) - ((a / (c / d)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.8e+91) || !(d <= 5.2e+43)) tmp = Float64(Float64(c / Float64(d * Float64(d / b))) - Float64(a / d)); else tmp = Float64(Float64(b / c) - Float64(Float64(a / Float64(c / d)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.8e+91) || ~((d <= 5.2e+43))) tmp = (c / (d * (d / b))) - (a / d); else tmp = (b / c) - ((a / (c / d)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e+91], N[Not[LessEqual[d, 5.2e+43]], $MachinePrecision]], N[(N[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], N[(N[(b / c), $MachinePrecision] - N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{+91} \lor \neg \left(d \leq 5.2 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -4.79999999999999966e91 or 5.20000000000000042e43 < d Initial program 41.8%
Taylor expanded in c around 0 74.5%
+-commutative74.5%
mul-1-neg74.5%
unsub-neg74.5%
*-commutative74.5%
associate-/l*76.7%
Simplified76.7%
pow276.7%
*-un-lft-identity76.7%
times-frac80.2%
Applied egg-rr80.2%
if -4.79999999999999966e91 < d < 5.20000000000000042e43Initial program 69.1%
Taylor expanded in c around inf 69.9%
+-commutative69.9%
mul-1-neg69.9%
unsub-neg69.9%
associate-/l*69.5%
associate-/r/64.3%
Simplified64.3%
*-un-lft-identity64.3%
pow264.3%
times-frac68.9%
Applied egg-rr68.9%
associate-*l*74.3%
associate-*l/74.3%
*-un-lft-identity74.3%
associate-/r/76.3%
Applied egg-rr76.3%
Final simplification77.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.7e+44) (not (<= d 3.1e+41))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.7e+44) || !(d <= 3.1e+41)) {
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 <= (-1.7d+44)) .or. (.not. (d <= 3.1d+41))) 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 <= -1.7e+44) || !(d <= 3.1e+41)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.7e+44) or not (d <= 3.1e+41): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.7e+44) || !(d <= 3.1e+41)) 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 <= -1.7e+44) || ~((d <= 3.1e+41))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.7e+44], N[Not[LessEqual[d, 3.1e+41]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{+44} \lor \neg \left(d \leq 3.1 \cdot 10^{+41}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.7e44 or 3.1e41 < d Initial program 44.1%
Taylor expanded in c around 0 68.6%
associate-*r/68.6%
neg-mul-168.6%
Simplified68.6%
if -1.7e44 < d < 3.1e41Initial program 68.7%
Taylor expanded in c around inf 62.9%
Final simplification65.5%
(FPCore (a b c d) :precision binary64 (if (<= d -1.2e+108) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.2e+108) {
tmp = a / d;
} else {
tmp = 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 (d <= (-1.2d+108)) then
tmp = a / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.2e+108) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.2e+108: tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.2e+108) tmp = Float64(a / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.2e+108) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.2e+108], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.2 \cdot 10^{+108}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.20000000000000009e108Initial program 39.7%
fma-neg39.7%
*-commutative39.7%
distribute-rgt-neg-out39.7%
add-sqr-sqrt39.7%
*-un-lft-identity39.7%
times-frac39.7%
hypot-def39.7%
add-sqr-sqrt24.8%
sqrt-unprod37.5%
sqr-neg37.5%
sqrt-unprod12.7%
add-sqr-sqrt33.3%
*-commutative33.3%
hypot-def37.3%
Applied egg-rr37.3%
Taylor expanded in c around 0 32.0%
if -1.20000000000000009e108 < d Initial program 61.3%
fma-neg61.3%
*-commutative61.3%
distribute-rgt-neg-out61.3%
add-sqr-sqrt61.3%
*-un-lft-identity61.3%
times-frac61.2%
hypot-def61.2%
add-sqr-sqrt28.8%
sqrt-unprod42.1%
sqr-neg42.1%
sqrt-unprod19.7%
add-sqr-sqrt34.1%
*-commutative34.1%
hypot-def41.7%
Applied egg-rr41.7%
Taylor expanded in c around inf 35.8%
Taylor expanded in c around 0 9.4%
Final simplification13.5%
(FPCore (a b c d) :precision binary64 (if (<= d -1.05e+114) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.05e+114) {
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 <= (-1.05d+114)) 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 <= -1.05e+114) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.05e+114: tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.05e+114) 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 <= -1.05e+114) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.05e+114], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+114}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.05e114Initial program 40.5%
fma-neg40.5%
*-commutative40.5%
distribute-rgt-neg-out40.5%
add-sqr-sqrt40.5%
*-un-lft-identity40.5%
times-frac40.5%
hypot-def40.5%
add-sqr-sqrt25.3%
sqrt-unprod38.2%
sqr-neg38.2%
sqrt-unprod12.9%
add-sqr-sqrt34.0%
*-commutative34.0%
hypot-def38.1%
Applied egg-rr38.1%
Taylor expanded in c around 0 32.7%
if -1.05e114 < d Initial program 61.0%
Taylor expanded in c around inf 46.7%
Final simplification44.2%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 57.3%
fma-neg57.3%
*-commutative57.3%
distribute-rgt-neg-out57.3%
add-sqr-sqrt57.3%
*-un-lft-identity57.3%
times-frac57.3%
hypot-def57.3%
add-sqr-sqrt28.0%
sqrt-unprod41.2%
sqr-neg41.2%
sqrt-unprod18.4%
add-sqr-sqrt34.0%
*-commutative34.0%
hypot-def40.9%
Applied egg-rr40.9%
Taylor expanded in c around inf 32.0%
Taylor expanded in c around 0 10.2%
Final simplification10.2%
(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 2024010
(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))))