
(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 (if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) 4e+289) (* (/ 1.0 (hypot c d)) (/ (fma b c (* a (- d))) (hypot c d))) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 4e+289) {
tmp = (1.0 / hypot(c, d)) * (fma(b, c, (a * -d)) / hypot(c, d));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 4e+289) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(a * Float64(-d))) / hypot(c, d))); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e+289], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(a * (-d)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 4 \cdot 10^{+289}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.0000000000000002e289Initial program 79.0%
*-un-lft-identity79.0%
add-sqr-sqrt79.0%
times-frac78.9%
hypot-define78.9%
fma-neg78.9%
distribute-rgt-neg-in78.9%
hypot-define96.5%
Applied egg-rr96.5%
if 4.0000000000000002e289 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 12.7%
Taylor expanded in c around 0 44.1%
+-commutative44.1%
mul-1-neg44.1%
unsub-neg44.1%
unpow244.1%
associate-/r*50.4%
div-sub54.9%
associate-/l*65.0%
Simplified65.0%
Final simplification88.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.08e+102)
t_0
(if (<= d -1.65e-139)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 5.3e+19) (/ (- 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.08e+102) {
tmp = t_0;
} else if (d <= -1.65e-139) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 5.3e+19) {
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.08d+102)) then
tmp = t_0
else if (d <= (-1.65d-139)) then
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
else if (d <= 5.3d+19) 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.08e+102) {
tmp = t_0;
} else if (d <= -1.65e-139) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 5.3e+19) {
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.08e+102: tmp = t_0 elif d <= -1.65e-139: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif d <= 5.3e+19: 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.08e+102) tmp = t_0; elseif (d <= -1.65e-139) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 5.3e+19) tmp = Float64(Float64(b - Float64(Float64(a * 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.08e+102) tmp = t_0; elseif (d <= -1.65e-139) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (d <= 5.3e+19) 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.08e+102], t$95$0, If[LessEqual[d, -1.65e-139], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.3e+19], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $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.08 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.65 \cdot 10^{-139}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 5.3 \cdot 10^{+19}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.08000000000000002e102 or 5.3e19 < d Initial program 43.5%
Taylor expanded in c around 0 78.2%
+-commutative78.2%
mul-1-neg78.2%
unsub-neg78.2%
unpow278.2%
associate-/r*83.3%
div-sub83.3%
associate-/l*88.0%
Simplified88.0%
Taylor expanded in b around 0 83.3%
associate-*l/88.0%
*-commutative88.0%
Simplified88.0%
if -1.08000000000000002e102 < d < -1.65e-139Initial program 92.0%
if -1.65e-139 < d < 5.3e19Initial program 65.2%
Taylor expanded in c around inf 85.0%
remove-double-neg85.0%
mul-1-neg85.0%
neg-mul-185.0%
distribute-lft-in85.0%
distribute-lft-in85.0%
neg-mul-185.0%
mul-1-neg85.0%
remove-double-neg85.0%
associate-*r/85.0%
mul-1-neg85.0%
distribute-rgt-neg-out85.0%
Simplified85.0%
Final simplification87.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.9e+35) (not (<= d 3.4e+72))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.9e+35) || !(d <= 3.4e+72)) {
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 <= (-4.9d+35)) .or. (.not. (d <= 3.4d+72))) 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 <= -4.9e+35) || !(d <= 3.4e+72)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.9e+35) or not (d <= 3.4e+72): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.9e+35) || !(d <= 3.4e+72)) 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 <= -4.9e+35) || ~((d <= 3.4e+72))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.9e+35], N[Not[LessEqual[d, 3.4e+72]], $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 -4.9 \cdot 10^{+35} \lor \neg \left(d \leq 3.4 \cdot 10^{+72}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.90000000000000025e35 or 3.3999999999999998e72 < d Initial program 48.4%
Taylor expanded in c around 0 72.7%
associate-*r/72.7%
neg-mul-172.7%
Simplified72.7%
if -4.90000000000000025e35 < d < 3.3999999999999998e72Initial program 72.1%
Taylor expanded in c around inf 72.8%
remove-double-neg72.8%
mul-1-neg72.8%
neg-mul-172.8%
distribute-lft-in72.8%
distribute-lft-in72.8%
mul-1-neg72.8%
unsub-neg72.8%
neg-mul-172.8%
mul-1-neg72.8%
remove-double-neg72.8%
associate-/l*73.5%
Simplified73.5%
Final simplification73.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -120.0) (not (<= d 4.4e+18))) (/ (- (* b (/ c d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -120.0) || !(d <= 4.4e+18)) {
tmp = ((b * (c / d)) - 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 <= (-120.0d0)) .or. (.not. (d <= 4.4d+18))) then
tmp = ((b * (c / d)) - 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 <= -120.0) || !(d <= 4.4e+18)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -120.0) or not (d <= 4.4e+18): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -120.0) || !(d <= 4.4e+18)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - 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 <= -120.0) || ~((d <= 4.4e+18))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -120.0], N[Not[LessEqual[d, 4.4e+18]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / 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 -120 \lor \neg \left(d \leq 4.4 \cdot 10^{+18}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -120 or 4.4e18 < d Initial program 54.2%
Taylor expanded in c around 0 75.6%
+-commutative75.6%
mul-1-neg75.6%
unsub-neg75.6%
unpow275.6%
associate-/r*79.6%
div-sub79.6%
associate-/l*83.3%
Simplified83.3%
if -120 < d < 4.4e18Initial program 69.8%
Taylor expanded in c around inf 80.7%
remove-double-neg80.7%
mul-1-neg80.7%
neg-mul-180.7%
distribute-lft-in80.7%
distribute-lft-in80.7%
mul-1-neg80.7%
unsub-neg80.7%
neg-mul-180.7%
mul-1-neg80.7%
remove-double-neg80.7%
associate-/l*79.9%
Simplified79.9%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.062) (not (<= d 2.2e+19))) (/ (- (* c (/ b d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.062) || !(d <= 2.2e+19)) {
tmp = ((c * (b / d)) - 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.062d0)) .or. (.not. (d <= 2.2d+19))) then
tmp = ((c * (b / d)) - 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.062) || !(d <= 2.2e+19)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.062) or not (d <= 2.2e+19): tmp = ((c * (b / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.062) || !(d <= 2.2e+19)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - 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 <= -0.062) || ~((d <= 2.2e+19))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.062], N[Not[LessEqual[d, 2.2e+19]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / 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.062 \lor \neg \left(d \leq 2.2 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.062 or 2.2e19 < d Initial program 54.2%
Taylor expanded in c around 0 75.6%
+-commutative75.6%
mul-1-neg75.6%
unsub-neg75.6%
unpow275.6%
associate-/r*79.6%
div-sub79.6%
associate-/l*83.3%
Simplified83.3%
Taylor expanded in b around 0 79.6%
associate-*l/83.3%
*-commutative83.3%
Simplified83.3%
if -0.062 < d < 2.2e19Initial program 69.8%
Taylor expanded in c around inf 80.7%
remove-double-neg80.7%
mul-1-neg80.7%
neg-mul-180.7%
distribute-lft-in80.7%
distribute-lft-in80.7%
mul-1-neg80.7%
unsub-neg80.7%
neg-mul-180.7%
mul-1-neg80.7%
remove-double-neg80.7%
associate-/l*79.9%
Simplified79.9%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -28.0) (not (<= d 7.8e+18))) (/ (- (* c (/ b d)) a) d) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -28.0) || !(d <= 7.8e+18)) {
tmp = ((c * (b / d)) - 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 <= (-28.0d0)) .or. (.not. (d <= 7.8d+18))) then
tmp = ((c * (b / d)) - 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 <= -28.0) || !(d <= 7.8e+18)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -28.0) or not (d <= 7.8e+18): tmp = ((c * (b / d)) - a) / d else: tmp = (b - ((a * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -28.0) || !(d <= 7.8e+18)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -28.0) || ~((d <= 7.8e+18))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - ((a * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -28.0], N[Not[LessEqual[d, 7.8e+18]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -28 \lor \neg \left(d \leq 7.8 \cdot 10^{+18}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -28 or 7.8e18 < d Initial program 54.2%
Taylor expanded in c around 0 75.6%
+-commutative75.6%
mul-1-neg75.6%
unsub-neg75.6%
unpow275.6%
associate-/r*79.6%
div-sub79.6%
associate-/l*83.3%
Simplified83.3%
Taylor expanded in b around 0 79.6%
associate-*l/83.3%
*-commutative83.3%
Simplified83.3%
if -28 < d < 7.8e18Initial program 69.8%
Taylor expanded in c around inf 80.7%
remove-double-neg80.7%
mul-1-neg80.7%
neg-mul-180.7%
distribute-lft-in80.7%
distribute-lft-in80.7%
neg-mul-180.7%
mul-1-neg80.7%
remove-double-neg80.7%
associate-*r/80.7%
mul-1-neg80.7%
distribute-rgt-neg-out80.7%
Simplified80.7%
Final simplification82.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.92) (not (<= d 9.5e+72))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.92) || !(d <= 9.5e+72)) {
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.92d0)) .or. (.not. (d <= 9.5d+72))) 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.92) || !(d <= 9.5e+72)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.92) or not (d <= 9.5e+72): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.92) || !(d <= 9.5e+72)) 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 <= -1.92) || ~((d <= 9.5e+72))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.92], N[Not[LessEqual[d, 9.5e+72]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.92 \lor \neg \left(d \leq 9.5 \cdot 10^{+72}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.9199999999999999 or 9.50000000000000054e72 < d Initial program 52.9%
Taylor expanded in c around 0 69.7%
associate-*r/69.7%
neg-mul-169.7%
Simplified69.7%
if -1.9199999999999999 < d < 9.50000000000000054e72Initial program 69.8%
Taylor expanded in c around inf 57.9%
Final simplification63.6%
(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 61.6%
*-un-lft-identity61.6%
add-sqr-sqrt61.6%
times-frac61.6%
hypot-define61.6%
fma-neg61.6%
distribute-rgt-neg-in61.6%
hypot-define76.6%
Applied egg-rr76.6%
Taylor expanded in c around -inf 26.0%
+-commutative26.0%
neg-mul-126.0%
unsub-neg26.0%
associate-/l*26.4%
Simplified26.4%
Taylor expanded in c around 0 10.7%
Final simplification10.7%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 61.6%
Taylor expanded in c around inf 38.0%
Final simplification38.0%
(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 2024078
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(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))))