
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(if (<= d -1.85e+112)
(/ (+ b (* a (/ c d))) d)
(if (<= d -1.36e-115)
(/ (+ (* a c) (* d b)) (+ (* c c) (* d d)))
(if (<= d 1.45e+107)
(/ (+ a (/ 1.0 (/ (/ c d) b))) c)
(/ (+ b (/ c (/ d a))) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.85e+112) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -1.36e-115) {
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d));
} else if (d <= 1.45e+107) {
tmp = (a + (1.0 / ((c / d) / b))) / c;
} else {
tmp = (b + (c / (d / a))) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-1.85d+112)) then
tmp = (b + (a * (c / d))) / d
else if (d <= (-1.36d-115)) then
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d))
else if (d <= 1.45d+107) then
tmp = (a + (1.0d0 / ((c / d) / b))) / c
else
tmp = (b + (c / (d / a))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.85e+112) {
tmp = (b + (a * (c / d))) / d;
} else if (d <= -1.36e-115) {
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d));
} else if (d <= 1.45e+107) {
tmp = (a + (1.0 / ((c / d) / b))) / c;
} else {
tmp = (b + (c / (d / a))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.85e+112: tmp = (b + (a * (c / d))) / d elif d <= -1.36e-115: tmp = ((a * c) + (d * b)) / ((c * c) + (d * d)) elif d <= 1.45e+107: tmp = (a + (1.0 / ((c / d) / b))) / c else: tmp = (b + (c / (d / a))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.85e+112) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (d <= -1.36e-115) tmp = Float64(Float64(Float64(a * c) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 1.45e+107) tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / d) / b))) / c); else tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.85e+112) tmp = (b + (a * (c / d))) / d; elseif (d <= -1.36e-115) tmp = ((a * c) + (d * b)) / ((c * c) + (d * d)); elseif (d <= 1.45e+107) tmp = (a + (1.0 / ((c / d) / b))) / c; else tmp = (b + (c / (d / a))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.85e+112], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.36e-115], N[(N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.45e+107], N[(N[(a + N[(1.0 / N[(N[(c / d), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.85 \cdot 10^{+112}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;d \leq -1.36 \cdot 10^{-115}:\\
\;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+107}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{d}}{b}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\end{array}
\end{array}
if d < -1.85000000000000002e112Initial program 32.9%
fma-define33.0%
fma-define33.0%
Simplified33.0%
Taylor expanded in d around inf 77.9%
associate-/l*82.1%
Simplified82.1%
if -1.85000000000000002e112 < d < -1.35999999999999997e-115Initial program 84.7%
if -1.35999999999999997e-115 < d < 1.44999999999999994e107Initial program 69.4%
fma-define69.4%
fma-define69.4%
Simplified69.4%
Taylor expanded in c around inf 86.0%
*-commutative86.0%
Simplified86.0%
clear-num86.0%
inv-pow86.0%
associate-/r*87.2%
Applied egg-rr87.2%
unpow-187.2%
Simplified87.2%
if 1.44999999999999994e107 < d Initial program 33.6%
fma-define33.6%
fma-define33.6%
Simplified33.6%
Taylor expanded in d around inf 81.9%
*-commutative81.9%
*-un-lft-identity81.9%
times-frac86.7%
Applied egg-rr86.7%
/-rgt-identity86.7%
clear-num86.7%
un-div-inv86.7%
Applied egg-rr86.7%
Final simplification85.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e-81) (not (<= d 1.45e+107))) (/ (+ b (/ c (/ d a))) d) (/ (+ a (/ 1.0 (/ (/ c d) b))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e-81) || !(d <= 1.45e+107)) {
tmp = (b + (c / (d / a))) / d;
} else {
tmp = (a + (1.0 / ((c / d) / 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-81)) .or. (.not. (d <= 1.45d+107))) then
tmp = (b + (c / (d / a))) / d
else
tmp = (a + (1.0d0 / ((c / d) / 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-81) || !(d <= 1.45e+107)) {
tmp = (b + (c / (d / a))) / d;
} else {
tmp = (a + (1.0 / ((c / d) / b))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e-81) or not (d <= 1.45e+107): tmp = (b + (c / (d / a))) / d else: tmp = (a + (1.0 / ((c / d) / b))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.05e-81) || !(d <= 1.45e+107)) tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); else tmp = Float64(Float64(a + Float64(1.0 / Float64(Float64(c / d) / b))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.05e-81) || ~((d <= 1.45e+107))) tmp = (b + (c / (d / a))) / d; else tmp = (a + (1.0 / ((c / d) / b))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e-81], N[Not[LessEqual[d, 1.45e+107]], $MachinePrecision]], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(1.0 / N[(N[(c / d), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{-81} \lor \neg \left(d \leq 1.45 \cdot 10^{+107}\right):\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{\frac{c}{d}}{b}}}{c}\\
\end{array}
\end{array}
if d < -1.05e-81 or 1.44999999999999994e107 < d Initial program 47.0%
fma-define47.0%
fma-define47.0%
Simplified47.0%
Taylor expanded in d around inf 74.1%
*-commutative74.1%
*-un-lft-identity74.1%
times-frac78.0%
Applied egg-rr78.0%
/-rgt-identity78.0%
clear-num78.0%
un-div-inv78.1%
Applied egg-rr78.1%
if -1.05e-81 < d < 1.44999999999999994e107Initial program 71.2%
fma-define71.3%
fma-define71.3%
Simplified71.3%
Taylor expanded in c around inf 85.4%
*-commutative85.4%
Simplified85.4%
clear-num85.4%
inv-pow85.4%
associate-/r*86.5%
Applied egg-rr86.5%
unpow-186.5%
Simplified86.5%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.15e-81) (not (<= d 1.45e+107))) (/ (+ b (/ c (/ d a))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.15e-81) || !(d <= 1.45e+107)) {
tmp = (b + (c / (d / a))) / d;
} else {
tmp = (a + (b * (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 <= (-1.15d-81)) .or. (.not. (d <= 1.45d+107))) then
tmp = (b + (c / (d / a))) / d
else
tmp = (a + (b * (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 <= -1.15e-81) || !(d <= 1.45e+107)) {
tmp = (b + (c / (d / a))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.15e-81) or not (d <= 1.45e+107): tmp = (b + (c / (d / a))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.15e-81) || !(d <= 1.45e+107)) tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.15e-81) || ~((d <= 1.45e+107))) tmp = (b + (c / (d / a))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.15e-81], N[Not[LessEqual[d, 1.45e+107]], $MachinePrecision]], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.15 \cdot 10^{-81} \lor \neg \left(d \leq 1.45 \cdot 10^{+107}\right):\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.14999999999999996e-81 or 1.44999999999999994e107 < d Initial program 47.0%
fma-define47.0%
fma-define47.0%
Simplified47.0%
Taylor expanded in d around inf 74.1%
*-commutative74.1%
*-un-lft-identity74.1%
times-frac78.0%
Applied egg-rr78.0%
/-rgt-identity78.0%
clear-num78.0%
un-div-inv78.1%
Applied egg-rr78.1%
if -1.14999999999999996e-81 < d < 1.44999999999999994e107Initial program 71.2%
fma-define71.3%
fma-define71.3%
Simplified71.3%
Taylor expanded in c around inf 85.4%
*-commutative85.4%
Simplified85.4%
Taylor expanded in d around 0 85.4%
associate-*r/86.5%
Simplified86.5%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e-81) (not (<= d 1.45e+107))) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e-81) || !(d <= 1.45e+107)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (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 <= (-1.05d-81)) .or. (.not. (d <= 1.45d+107))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b * (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 <= -1.05e-81) || !(d <= 1.45e+107)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e-81) or not (d <= 1.45e+107): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.05e-81) || !(d <= 1.45e+107)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.05e-81) || ~((d <= 1.45e+107))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e-81], N[Not[LessEqual[d, 1.45e+107]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{-81} \lor \neg \left(d \leq 1.45 \cdot 10^{+107}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.05e-81 or 1.44999999999999994e107 < d Initial program 47.0%
fma-define47.0%
fma-define47.0%
Simplified47.0%
Taylor expanded in d around inf 74.1%
associate-/l*78.1%
Simplified78.1%
if -1.05e-81 < d < 1.44999999999999994e107Initial program 71.2%
fma-define71.3%
fma-define71.3%
Simplified71.3%
Taylor expanded in c around inf 85.4%
*-commutative85.4%
Simplified85.4%
Taylor expanded in d around 0 85.4%
associate-*r/86.5%
Simplified86.5%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -8.5e+27) (not (<= d 5.3e+107))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -8.5e+27) || !(d <= 5.3e+107)) {
tmp = b / d;
} else {
tmp = (a + (b * (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 <= (-8.5d+27)) .or. (.not. (d <= 5.3d+107))) then
tmp = b / d
else
tmp = (a + (b * (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 <= -8.5e+27) || !(d <= 5.3e+107)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -8.5e+27) or not (d <= 5.3e+107): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -8.5e+27) || !(d <= 5.3e+107)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -8.5e+27) || ~((d <= 5.3e+107))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8.5e+27], N[Not[LessEqual[d, 5.3e+107]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.5 \cdot 10^{+27} \lor \neg \left(d \leq 5.3 \cdot 10^{+107}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -8.5e27 or 5.3e107 < d Initial program 39.1%
fma-define39.2%
fma-define39.2%
Simplified39.2%
Taylor expanded in c around 0 73.7%
if -8.5e27 < d < 5.3e107Initial program 73.3%
fma-define73.3%
fma-define73.3%
Simplified73.3%
Taylor expanded in c around inf 81.2%
*-commutative81.2%
Simplified81.2%
Taylor expanded in d around 0 81.2%
associate-*r/82.1%
Simplified82.1%
Final simplification78.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.16e+79) (not (<= c 1.45e+57))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.16e+79) || !(c <= 1.45e+57)) {
tmp = a / c;
} else {
tmp = b / 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 <= (-1.16d+79)) .or. (.not. (c <= 1.45d+57))) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.16e+79) || !(c <= 1.45e+57)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.16e+79) or not (c <= 1.45e+57): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.16e+79) || !(c <= 1.45e+57)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.16e+79) || ~((c <= 1.45e+57))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.16e+79], N[Not[LessEqual[c, 1.45e+57]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.16 \cdot 10^{+79} \lor \neg \left(c \leq 1.45 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -1.16000000000000007e79 or 1.4500000000000001e57 < c Initial program 42.7%
fma-define42.7%
fma-define42.7%
Simplified42.7%
Taylor expanded in c around inf 75.0%
if -1.16000000000000007e79 < c < 1.4500000000000001e57Initial program 70.3%
fma-define70.3%
fma-define70.3%
Simplified70.3%
Taylor expanded in c around 0 63.8%
Final simplification68.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 59.3%
fma-define59.3%
fma-define59.3%
Simplified59.3%
Taylor expanded in c around inf 42.2%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024182
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))