
(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 8 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
(let* ((t_0 (/ 1.0 (/ d (+ (* c (/ a d)) b)))) (t_1 (cbrt (fma a c (* d b)))))
(if (<= d -7.5e+25)
t_0
(if (<= d 1.45e-74)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 1.02e+57)
(* (/ (pow t_1 2.0) (hypot c d)) (/ t_1 (hypot c d)))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / (d / ((c * (a / d)) + b));
double t_1 = cbrt(fma(a, c, (d * b)));
double tmp;
if (d <= -7.5e+25) {
tmp = t_0;
} else if (d <= 1.45e-74) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 1.02e+57) {
tmp = (pow(t_1, 2.0) / hypot(c, d)) * (t_1 / hypot(c, d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / Float64(d / Float64(Float64(c * Float64(a / d)) + b))) t_1 = cbrt(fma(a, c, Float64(d * b))) tmp = 0.0 if (d <= -7.5e+25) tmp = t_0; elseif (d <= 1.45e-74) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 1.02e+57) tmp = Float64(Float64((t_1 ^ 2.0) / hypot(c, d)) * Float64(t_1 / hypot(c, d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[(d / N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[d, -7.5e+25], t$95$0, If[LessEqual[d, 1.45e-74], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.02e+57], N[(N[(N[Power[t$95$1, 2.0], $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\frac{d}{c \cdot \frac{a}{d} + b}}\\
t_1 := \sqrt[3]{\mathsf{fma}\left(a, c, d \cdot b\right)}\\
\mathbf{if}\;d \leq -7.5 \cdot 10^{+25}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{-74}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 1.02 \cdot 10^{+57}:\\
\;\;\;\;\frac{{t\_1}^{2}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.49999999999999993e25 or 1.02e57 < d Initial program 53.2%
fma-define53.2%
fma-define53.2%
Simplified53.2%
Taylor expanded in d around inf 80.3%
associate-/l*84.2%
Simplified84.2%
clear-num83.9%
inv-pow83.9%
+-commutative83.9%
fma-define83.9%
Applied egg-rr83.9%
unpow-183.9%
Simplified83.9%
fma-undefine83.9%
associate-*r/80.1%
*-commutative80.1%
associate-*r/85.3%
Applied egg-rr85.3%
if -7.49999999999999993e25 < d < 1.45e-74Initial program 69.4%
fma-define69.4%
fma-define69.4%
Simplified69.4%
Taylor expanded in c around inf 91.6%
*-commutative91.6%
Simplified91.6%
if 1.45e-74 < d < 1.02e57Initial program 80.6%
fma-define80.6%
fma-define80.7%
Simplified80.7%
add-cube-cbrt79.6%
add-sqr-sqrt79.6%
times-frac79.5%
pow279.5%
fma-define79.5%
hypot-define79.5%
fma-define79.5%
hypot-define98.1%
Applied egg-rr98.1%
Final simplification89.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ 1.0 (/ d (+ (* c (/ a d)) b)))))
(if (<= d -2.7e+29)
t_0
(if (<= d 1.5e-76)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 4.7e+55) (/ (fma a c (* d b)) (fma c c (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / (d / ((c * (a / d)) + b));
double tmp;
if (d <= -2.7e+29) {
tmp = t_0;
} else if (d <= 1.5e-76) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 4.7e+55) {
tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / Float64(d / Float64(Float64(c * Float64(a / d)) + b))) tmp = 0.0 if (d <= -2.7e+29) tmp = t_0; elseif (d <= 1.5e-76) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 4.7e+55) tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[(d / N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.7e+29], t$95$0, If[LessEqual[d, 1.5e-76], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.7e+55], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\frac{d}{c \cdot \frac{a}{d} + b}}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+29}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.5 \cdot 10^{-76}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 4.7 \cdot 10^{+55}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.7e29 or 4.7000000000000001e55 < d Initial program 53.2%
fma-define53.2%
fma-define53.2%
Simplified53.2%
Taylor expanded in d around inf 80.3%
associate-/l*84.2%
Simplified84.2%
clear-num83.9%
inv-pow83.9%
+-commutative83.9%
fma-define83.9%
Applied egg-rr83.9%
unpow-183.9%
Simplified83.9%
fma-undefine83.9%
associate-*r/80.1%
*-commutative80.1%
associate-*r/85.3%
Applied egg-rr85.3%
if -2.7e29 < d < 1.50000000000000012e-76Initial program 69.4%
fma-define69.4%
fma-define69.4%
Simplified69.4%
Taylor expanded in c around inf 91.6%
*-commutative91.6%
Simplified91.6%
if 1.50000000000000012e-76 < d < 4.7000000000000001e55Initial program 80.6%
fma-define80.6%
fma-define80.7%
Simplified80.7%
Final simplification87.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ 1.0 (/ d (+ (* c (/ a d)) b)))))
(if (<= d -4.5e+28)
t_0
(if (<= d 4.7e-71)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 2.15e+58) (/ (+ (* d b) (* c a)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / (d / ((c * (a / d)) + b));
double tmp;
if (d <= -4.5e+28) {
tmp = t_0;
} else if (d <= 4.7e-71) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.15e+58) {
tmp = ((d * b) + (c * 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 = 1.0d0 / (d / ((c * (a / d)) + b))
if (d <= (-4.5d+28)) then
tmp = t_0
else if (d <= 4.7d-71) then
tmp = (a + ((d * b) / c)) / c
else if (d <= 2.15d+58) then
tmp = ((d * b) + (c * 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 = 1.0 / (d / ((c * (a / d)) + b));
double tmp;
if (d <= -4.5e+28) {
tmp = t_0;
} else if (d <= 4.7e-71) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.15e+58) {
tmp = ((d * b) + (c * a)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = 1.0 / (d / ((c * (a / d)) + b)) tmp = 0 if d <= -4.5e+28: tmp = t_0 elif d <= 4.7e-71: tmp = (a + ((d * b) / c)) / c elif d <= 2.15e+58: tmp = ((d * b) + (c * a)) / ((d * d) + (c * c)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(1.0 / Float64(d / Float64(Float64(c * Float64(a / d)) + b))) tmp = 0.0 if (d <= -4.5e+28) tmp = t_0; elseif (d <= 4.7e-71) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 2.15e+58) tmp = Float64(Float64(Float64(d * b) + Float64(c * 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 = 1.0 / (d / ((c * (a / d)) + b)); tmp = 0.0; if (d <= -4.5e+28) tmp = t_0; elseif (d <= 4.7e-71) tmp = (a + ((d * b) / c)) / c; elseif (d <= 2.15e+58) tmp = ((d * b) + (c * a)) / ((d * d) + (c * c)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[(d / N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.5e+28], t$95$0, If[LessEqual[d, 4.7e-71], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.15e+58], N[(N[(N[(d * b), $MachinePrecision] + N[(c * 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{1}{\frac{d}{c \cdot \frac{a}{d} + b}}\\
\mathbf{if}\;d \leq -4.5 \cdot 10^{+28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.7 \cdot 10^{-71}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{+58}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.4999999999999997e28 or 2.14999999999999996e58 < d Initial program 53.2%
fma-define53.2%
fma-define53.2%
Simplified53.2%
Taylor expanded in d around inf 80.3%
associate-/l*84.2%
Simplified84.2%
clear-num83.9%
inv-pow83.9%
+-commutative83.9%
fma-define83.9%
Applied egg-rr83.9%
unpow-183.9%
Simplified83.9%
fma-undefine83.9%
associate-*r/80.1%
*-commutative80.1%
associate-*r/85.3%
Applied egg-rr85.3%
if -4.4999999999999997e28 < d < 4.69999999999999996e-71Initial program 69.4%
fma-define69.4%
fma-define69.4%
Simplified69.4%
Taylor expanded in c around inf 91.6%
*-commutative91.6%
Simplified91.6%
if 4.69999999999999996e-71 < d < 2.14999999999999996e58Initial program 80.6%
Final simplification87.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e+28) (not (<= d 1.3e-53))) (/ 1.0 (/ d (+ (* c (/ a d)) b))) (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+28) || !(d <= 1.3e-53)) {
tmp = 1.0 / (d / ((c * (a / d)) + b));
} else {
tmp = (a + ((d * b) / 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+28)) .or. (.not. (d <= 1.3d-53))) then
tmp = 1.0d0 / (d / ((c * (a / d)) + b))
else
tmp = (a + ((d * b) / 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+28) || !(d <= 1.3e-53)) {
tmp = 1.0 / (d / ((c * (a / d)) + b));
} else {
tmp = (a + ((d * b) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e+28) or not (d <= 1.3e-53): tmp = 1.0 / (d / ((c * (a / d)) + b)) else: tmp = (a + ((d * b) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.05e+28) || !(d <= 1.3e-53)) tmp = Float64(1.0 / Float64(d / Float64(Float64(c * Float64(a / d)) + b))); else tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.05e+28) || ~((d <= 1.3e-53))) tmp = 1.0 / (d / ((c * (a / d)) + b)); else tmp = (a + ((d * b) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e+28], N[Not[LessEqual[d, 1.3e-53]], $MachinePrecision]], N[(1.0 / N[(d / N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+28} \lor \neg \left(d \leq 1.3 \cdot 10^{-53}\right):\\
\;\;\;\;\frac{1}{\frac{d}{c \cdot \frac{a}{d} + b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.04999999999999995e28 or 1.29999999999999998e-53 < d Initial program 58.6%
fma-define58.6%
fma-define58.6%
Simplified58.6%
Taylor expanded in d around inf 78.2%
associate-/l*81.4%
Simplified81.4%
clear-num81.2%
inv-pow81.2%
+-commutative81.2%
fma-define81.2%
Applied egg-rr81.2%
unpow-181.2%
Simplified81.2%
fma-undefine81.2%
associate-*r/78.0%
*-commutative78.0%
associate-*r/82.3%
Applied egg-rr82.3%
if -1.04999999999999995e28 < d < 1.29999999999999998e-53Initial program 69.0%
fma-define69.1%
fma-define69.1%
Simplified69.1%
Taylor expanded in c around inf 90.3%
*-commutative90.3%
Simplified90.3%
Final simplification85.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.4e+28) (not (<= d 1e-53))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.4e+28) || !(d <= 1e-53)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + ((d * b) / 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 <= (-7.4d+28)) .or. (.not. (d <= 1d-53))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + ((d * b) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.4e+28) || !(d <= 1e-53)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + ((d * b) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.4e+28) or not (d <= 1e-53): tmp = (b + (a * (c / d))) / d else: tmp = (a + ((d * b) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.4e+28) || !(d <= 1e-53)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -7.4e+28) || ~((d <= 1e-53))) tmp = (b + (a * (c / d))) / d; else tmp = (a + ((d * b) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.4e+28], N[Not[LessEqual[d, 1e-53]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.4 \cdot 10^{+28} \lor \neg \left(d \leq 10^{-53}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\end{array}
\end{array}
if d < -7.3999999999999998e28 or 1.00000000000000003e-53 < d Initial program 58.6%
fma-define58.6%
fma-define58.6%
Simplified58.6%
Taylor expanded in d around inf 78.2%
associate-/l*81.4%
Simplified81.4%
if -7.3999999999999998e28 < d < 1.00000000000000003e-53Initial program 69.0%
fma-define69.1%
fma-define69.1%
Simplified69.1%
Taylor expanded in c around inf 90.3%
*-commutative90.3%
Simplified90.3%
Final simplification85.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.6e+28) (not (<= d 3.1e+35))) (/ b d) (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.6e+28) || !(d <= 3.1e+35)) {
tmp = b / d;
} else {
tmp = (a + ((d * b) / 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.6d+28)) .or. (.not. (d <= 3.1d+35))) then
tmp = b / d
else
tmp = (a + ((d * b) / 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.6e+28) || !(d <= 3.1e+35)) {
tmp = b / d;
} else {
tmp = (a + ((d * b) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.6e+28) or not (d <= 3.1e+35): tmp = b / d else: tmp = (a + ((d * b) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.6e+28) || !(d <= 3.1e+35)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.6e+28) || ~((d <= 3.1e+35))) tmp = b / d; else tmp = (a + ((d * b) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.6e+28], N[Not[LessEqual[d, 3.1e+35]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.6 \cdot 10^{+28} \lor \neg \left(d \leq 3.1 \cdot 10^{+35}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\end{array}
\end{array}
if d < -1.6e28 or 3.09999999999999987e35 < d Initial program 54.4%
fma-define54.4%
fma-define54.4%
Simplified54.4%
Taylor expanded in c around 0 69.7%
if -1.6e28 < d < 3.09999999999999987e35Initial program 71.1%
fma-define71.1%
fma-define71.1%
Simplified71.1%
Taylor expanded in c around inf 82.3%
*-commutative82.3%
Simplified82.3%
Final simplification76.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e+16) (not (<= d 1.25e-53))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e+16) || !(d <= 1.25e-53)) {
tmp = b / 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 <= (-4d+16)) .or. (.not. (d <= 1.25d-53))) then
tmp = b / 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 <= -4e+16) || !(d <= 1.25e-53)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e+16) or not (d <= 1.25e-53): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e+16) || !(d <= 1.25e-53)) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4e+16) || ~((d <= 1.25e-53))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e+16], N[Not[LessEqual[d, 1.25e-53]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{+16} \lor \neg \left(d \leq 1.25 \cdot 10^{-53}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -4e16 or 1.25e-53 < d Initial program 59.1%
fma-define59.1%
fma-define59.1%
Simplified59.1%
Taylor expanded in c around 0 63.9%
if -4e16 < d < 1.25e-53Initial program 68.5%
fma-define68.5%
fma-define68.5%
Simplified68.5%
Taylor expanded in c around inf 68.7%
Final simplification66.0%
(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 63.3%
fma-define63.3%
fma-define63.3%
Simplified63.3%
Taylor expanded in c around inf 39.9%
(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 2024145
(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))))