
(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 8 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 (<= c -3.2e+90)
(/ (- b (* (/ d c) a)) c)
(if (<= c 1.5e-122)
(/ (- (* b (/ c d)) a) d)
(if (<= c 7.5e+83)
(/ (fma b c (* d (- a))) (fma d d (* c c)))
(/ (- b (/ a (/ c d))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.2e+90) {
tmp = (b - ((d / c) * a)) / c;
} else if (c <= 1.5e-122) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 7.5e+83) {
tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3.2e+90) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); elseif (c <= 1.5e-122) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 7.5e+83) tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c))); else tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.2e+90], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.5e-122], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7.5e+83], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.2 \cdot 10^{+90}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{-122}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{+83}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -3.19999999999999998e90Initial program 39.4%
fmm-def39.4%
distribute-rgt-neg-out39.4%
+-commutative39.4%
fma-define39.4%
Simplified39.4%
Taylor expanded in c around inf 87.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
Simplified87.6%
*-commutative87.6%
associate-*r/90.2%
*-commutative90.2%
Applied egg-rr90.2%
if -3.19999999999999998e90 < c < 1.50000000000000002e-122Initial program 69.5%
fmm-def69.5%
distribute-rgt-neg-out69.5%
+-commutative69.5%
fma-define69.5%
Simplified69.5%
Taylor expanded in d around inf 80.7%
+-commutative80.7%
mul-1-neg80.7%
unsub-neg80.7%
associate-*r/81.6%
Applied egg-rr81.6%
if 1.50000000000000002e-122 < c < 7.49999999999999989e83Initial program 81.4%
fmm-def81.5%
distribute-rgt-neg-out81.5%
+-commutative81.5%
fma-define81.5%
Simplified81.5%
if 7.49999999999999989e83 < c Initial program 34.0%
fmm-def34.0%
distribute-rgt-neg-out34.0%
+-commutative34.0%
fma-define34.0%
Simplified34.0%
Taylor expanded in c around inf 72.7%
mul-1-neg72.7%
unsub-neg72.7%
*-commutative72.7%
Simplified72.7%
Taylor expanded in b around 0 61.8%
+-commutative61.8%
mul-1-neg61.8%
unpow261.8%
associate-/l/72.7%
sub-neg72.7%
div-sub72.7%
associate-*l/78.2%
associate-/r/78.2%
Simplified78.2%
Final simplification82.3%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.4e+90)
(/ (- b (* (/ d c) a)) c)
(if (<= c 2.3e-121)
(/ (- (* b (/ c d)) a) d)
(if (<= c 5.7e+83)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(/ (- b (/ a (/ c d))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.4e+90) {
tmp = (b - ((d / c) * a)) / c;
} else if (c <= 2.3e-121) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 5.7e+83) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * 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 (c <= (-2.4d+90)) then
tmp = (b - ((d / c) * a)) / c
else if (c <= 2.3d-121) then
tmp = ((b * (c / d)) - a) / d
else if (c <= 5.7d+83) then
tmp = ((c * b) - (d * a)) / ((c * c) + (d * 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 (c <= -2.4e+90) {
tmp = (b - ((d / c) * a)) / c;
} else if (c <= 2.3e-121) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 5.7e+83) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.4e+90: tmp = (b - ((d / c) * a)) / c elif c <= 2.3e-121: tmp = ((b * (c / d)) - a) / d elif c <= 5.7e+83: tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)) else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.4e+90) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); elseif (c <= 2.3e-121) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 5.7e+83) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * 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 (c <= -2.4e+90) tmp = (b - ((d / c) * a)) / c; elseif (c <= 2.3e-121) tmp = ((b * (c / d)) - a) / d; elseif (c <= 5.7e+83) tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)); else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.4e+90], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.3e-121], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.7e+83], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{+90}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{-121}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 5.7 \cdot 10^{+83}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -2.4000000000000001e90Initial program 39.4%
fmm-def39.4%
distribute-rgt-neg-out39.4%
+-commutative39.4%
fma-define39.4%
Simplified39.4%
Taylor expanded in c around inf 87.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
Simplified87.6%
*-commutative87.6%
associate-*r/90.2%
*-commutative90.2%
Applied egg-rr90.2%
if -2.4000000000000001e90 < c < 2.30000000000000012e-121Initial program 69.5%
fmm-def69.5%
distribute-rgt-neg-out69.5%
+-commutative69.5%
fma-define69.5%
Simplified69.5%
Taylor expanded in d around inf 80.7%
+-commutative80.7%
mul-1-neg80.7%
unsub-neg80.7%
associate-*r/81.6%
Applied egg-rr81.6%
if 2.30000000000000012e-121 < c < 5.69999999999999949e83Initial program 81.4%
if 5.69999999999999949e83 < c Initial program 34.0%
fmm-def34.0%
distribute-rgt-neg-out34.0%
+-commutative34.0%
fma-define34.0%
Simplified34.0%
Taylor expanded in c around inf 72.7%
mul-1-neg72.7%
unsub-neg72.7%
*-commutative72.7%
Simplified72.7%
Taylor expanded in b around 0 61.8%
+-commutative61.8%
mul-1-neg61.8%
unpow261.8%
associate-/l/72.7%
sub-neg72.7%
div-sub72.7%
associate-*l/78.2%
associate-/r/78.2%
Simplified78.2%
Final simplification82.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5e+39) (not (<= d 3.9e+15))) (/ (- a) d) (/ (- b (/ a (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5e+39) || !(d <= 3.9e+15)) {
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 <= (-5d+39)) .or. (.not. (d <= 3.9d+15))) 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 <= -5e+39) || !(d <= 3.9e+15)) {
tmp = -a / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5e+39) or not (d <= 3.9e+15): tmp = -a / d else: tmp = (b - (a / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5e+39) || !(d <= 3.9e+15)) tmp = Float64(Float64(-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 <= -5e+39) || ~((d <= 3.9e+15))) tmp = -a / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5e+39], N[Not[LessEqual[d, 3.9e+15]], $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 -5 \cdot 10^{+39} \lor \neg \left(d \leq 3.9 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -5.00000000000000015e39 or 3.9e15 < d Initial program 46.9%
fmm-def46.9%
distribute-rgt-neg-out46.9%
+-commutative46.9%
fma-define46.9%
Simplified46.9%
Taylor expanded in c around 0 71.4%
associate-*r/71.4%
neg-mul-171.4%
Simplified71.4%
if -5.00000000000000015e39 < d < 3.9e15Initial program 71.9%
fmm-def71.9%
distribute-rgt-neg-out71.9%
+-commutative71.9%
fma-define71.9%
Simplified71.9%
Taylor expanded in c around inf 77.3%
mul-1-neg77.3%
unsub-neg77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in b around 0 70.9%
+-commutative70.9%
mul-1-neg70.9%
unpow270.9%
associate-/l/77.2%
sub-neg77.2%
div-sub77.3%
associate-*l/75.2%
associate-/r/77.3%
Simplified77.3%
Final simplification74.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.8e+39) (not (<= d 2.15e+15))) (/ (- a) d) (/ (- b (* (/ d c) a)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.8e+39) || !(d <= 2.15e+15)) {
tmp = -a / d;
} else {
tmp = (b - ((d / c) * 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 <= (-7.8d+39)) .or. (.not. (d <= 2.15d+15))) then
tmp = -a / d
else
tmp = (b - ((d / c) * a)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.8e+39) || !(d <= 2.15e+15)) {
tmp = -a / d;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.8e+39) or not (d <= 2.15e+15): tmp = -a / d else: tmp = (b - ((d / c) * a)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.8e+39) || !(d <= 2.15e+15)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -7.8e+39) || ~((d <= 2.15e+15))) tmp = -a / d; else tmp = (b - ((d / c) * a)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.8e+39], N[Not[LessEqual[d, 2.15e+15]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.8 \cdot 10^{+39} \lor \neg \left(d \leq 2.15 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if d < -7.8000000000000002e39 or 2.15e15 < d Initial program 46.9%
fmm-def46.9%
distribute-rgt-neg-out46.9%
+-commutative46.9%
fma-define46.9%
Simplified46.9%
Taylor expanded in c around 0 71.4%
associate-*r/71.4%
neg-mul-171.4%
Simplified71.4%
if -7.8000000000000002e39 < d < 2.15e15Initial program 71.9%
fmm-def71.9%
distribute-rgt-neg-out71.9%
+-commutative71.9%
fma-define71.9%
Simplified71.9%
Taylor expanded in c around inf 77.3%
mul-1-neg77.3%
unsub-neg77.3%
*-commutative77.3%
Simplified77.3%
*-commutative77.3%
associate-*r/77.3%
*-commutative77.3%
Applied egg-rr77.3%
Final simplification74.5%
(FPCore (a b c d) :precision binary64 (if (<= c -3.4e+90) (/ (- b (* (/ d c) a)) c) (if (<= c 5e+65) (/ (- (* b (/ c d)) a) d) (/ (- b (/ a (/ c d))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.4e+90) {
tmp = (b - ((d / c) * a)) / c;
} else if (c <= 5e+65) {
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 (c <= (-3.4d+90)) then
tmp = (b - ((d / c) * a)) / c
else if (c <= 5d+65) 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 (c <= -3.4e+90) {
tmp = (b - ((d / c) * a)) / c;
} else if (c <= 5e+65) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.4e+90: tmp = (b - ((d / c) * a)) / c elif c <= 5e+65: 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 (c <= -3.4e+90) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); elseif (c <= 5e+65) 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 (c <= -3.4e+90) tmp = (b - ((d / c) * a)) / c; elseif (c <= 5e+65) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.4e+90], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 5e+65], 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}\;c \leq -3.4 \cdot 10^{+90}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{+65}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if c < -3.40000000000000018e90Initial program 39.4%
fmm-def39.4%
distribute-rgt-neg-out39.4%
+-commutative39.4%
fma-define39.4%
Simplified39.4%
Taylor expanded in c around inf 87.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
Simplified87.6%
*-commutative87.6%
associate-*r/90.2%
*-commutative90.2%
Applied egg-rr90.2%
if -3.40000000000000018e90 < c < 4.99999999999999973e65Initial program 72.0%
fmm-def72.0%
distribute-rgt-neg-out72.0%
+-commutative72.0%
fma-define72.0%
Simplified72.0%
Taylor expanded in d around inf 77.0%
+-commutative77.0%
mul-1-neg77.0%
unsub-neg77.0%
associate-*r/78.4%
Applied egg-rr78.4%
if 4.99999999999999973e65 < c Initial program 37.3%
fmm-def37.3%
distribute-rgt-neg-out37.3%
+-commutative37.3%
fma-define37.3%
Simplified37.3%
Taylor expanded in c around inf 72.9%
mul-1-neg72.9%
unsub-neg72.9%
*-commutative72.9%
Simplified72.9%
Taylor expanded in b around 0 62.8%
+-commutative62.8%
mul-1-neg62.8%
unpow262.8%
associate-/l/72.9%
sub-neg72.9%
div-sub72.9%
associate-*l/78.0%
associate-/r/78.0%
Simplified78.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.8e+36) (not (<= d 2.15e+15))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.8e+36) || !(d <= 2.15e+15)) {
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+36)) .or. (.not. (d <= 2.15d+15))) 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+36) || !(d <= 2.15e+15)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.8e+36) or not (d <= 2.15e+15): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.8e+36) || !(d <= 2.15e+15)) 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+36) || ~((d <= 2.15e+15))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.8e+36], N[Not[LessEqual[d, 2.15e+15]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.8 \cdot 10^{+36} \lor \neg \left(d \leq 2.15 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.80000000000000025e36 or 2.15e15 < d Initial program 47.7%
fmm-def47.7%
distribute-rgt-neg-out47.7%
+-commutative47.7%
fma-define47.7%
Simplified47.7%
Taylor expanded in c around 0 70.3%
associate-*r/70.3%
neg-mul-170.3%
Simplified70.3%
if -3.80000000000000025e36 < d < 2.15e15Initial program 71.5%
fmm-def71.5%
distribute-rgt-neg-out71.5%
+-commutative71.5%
fma-define71.5%
Simplified71.5%
Taylor expanded in c around inf 59.9%
Final simplification65.0%
(FPCore (a b c d) :precision binary64 (if (<= d 7.2e+200) (/ b c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 7.2e+200) {
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 <= 7.2d+200) 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 <= 7.2e+200) {
tmp = b / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 7.2e+200: tmp = b / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 7.2e+200) 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 <= 7.2e+200) tmp = b / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 7.2e+200], N[(b / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 7.2 \cdot 10^{+200}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 7.1999999999999995e200Initial program 64.1%
fmm-def64.1%
distribute-rgt-neg-out64.1%
+-commutative64.1%
fma-define64.1%
Simplified64.1%
Taylor expanded in c around inf 43.0%
if 7.1999999999999995e200 < d Initial program 24.8%
fmm-def24.8%
distribute-rgt-neg-out24.8%
+-commutative24.8%
fma-define24.8%
Simplified24.8%
Taylor expanded in c around 0 89.6%
associate-*r/89.6%
neg-mul-189.6%
Simplified89.6%
add-sqr-sqrt55.7%
sqrt-unprod57.2%
sqr-neg57.2%
sqrt-unprod12.1%
add-sqr-sqrt25.4%
div-inv25.4%
Applied egg-rr25.4%
associate-*r/25.4%
*-rgt-identity25.4%
Simplified25.4%
(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 60.0%
fmm-def60.0%
distribute-rgt-neg-out60.0%
+-commutative60.0%
fma-define60.0%
Simplified60.0%
Taylor expanded in c around 0 44.5%
associate-*r/44.5%
neg-mul-144.5%
Simplified44.5%
add-sqr-sqrt24.6%
sqrt-unprod23.9%
sqr-neg23.9%
sqrt-unprod4.1%
add-sqr-sqrt8.5%
div-inv8.5%
Applied egg-rr8.5%
associate-*r/8.5%
*-rgt-identity8.5%
Simplified8.5%
(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 2024157
(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))))