
(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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -5e+130)
(/ (+ a (* d (/ b c))) c)
(if (<= c -2.3e-86)
t_0
(if (<= c 2.4e-141)
(/ (+ b (* a (/ c d))) d)
(if (<= c 6.8e-68)
t_0
(if (<= c 2.3e+30)
(/ (+ b (* c (/ a d))) d)
(if (<= c 2.7e+163)
(* (/ c (hypot d c)) (/ a (hypot d c)))
(/ (+ a (* b (/ d c))) c)))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -5e+130) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -2.3e-86) {
tmp = t_0;
} else if (c <= 2.4e-141) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 6.8e-68) {
tmp = t_0;
} else if (c <= 2.3e+30) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 2.7e+163) {
tmp = (c / hypot(d, c)) * (a / hypot(d, c));
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -5e+130) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -2.3e-86) {
tmp = t_0;
} else if (c <= 2.4e-141) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 6.8e-68) {
tmp = t_0;
} else if (c <= 2.3e+30) {
tmp = (b + (c * (a / d))) / d;
} else if (c <= 2.7e+163) {
tmp = (c / Math.hypot(d, c)) * (a / Math.hypot(d, c));
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -5e+130: tmp = (a + (d * (b / c))) / c elif c <= -2.3e-86: tmp = t_0 elif c <= 2.4e-141: tmp = (b + (a * (c / d))) / d elif c <= 6.8e-68: tmp = t_0 elif c <= 2.3e+30: tmp = (b + (c * (a / d))) / d elif c <= 2.7e+163: tmp = (c / math.hypot(d, c)) * (a / math.hypot(d, c)) else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -5e+130) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= -2.3e-86) tmp = t_0; elseif (c <= 2.4e-141) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 6.8e-68) tmp = t_0; elseif (c <= 2.3e+30) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); elseif (c <= 2.7e+163) tmp = Float64(Float64(c / hypot(d, c)) * Float64(a / hypot(d, c))); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -5e+130) tmp = (a + (d * (b / c))) / c; elseif (c <= -2.3e-86) tmp = t_0; elseif (c <= 2.4e-141) tmp = (b + (a * (c / d))) / d; elseif (c <= 6.8e-68) tmp = t_0; elseif (c <= 2.3e+30) tmp = (b + (c * (a / d))) / d; elseif (c <= 2.7e+163) tmp = (c / hypot(d, c)) * (a / hypot(d, c)); else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5e+130], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.3e-86], t$95$0, If[LessEqual[c, 2.4e-141], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.8e-68], t$95$0, If[LessEqual[c, 2.3e+30], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.7e+163], N[(N[(c / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -5 \cdot 10^{+130}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq -2.3 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{-141}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{-68}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;c \leq 2.7 \cdot 10^{+163}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -4.9999999999999996e130Initial program 36.2%
Taylor expanded in c around inf 73.8%
associate-/l*83.2%
Simplified83.2%
clear-num83.2%
un-div-inv83.2%
Applied egg-rr83.2%
associate-/r/85.7%
Applied egg-rr85.7%
if -4.9999999999999996e130 < c < -2.29999999999999996e-86 or 2.4000000000000001e-141 < c < 6.80000000000000037e-68Initial program 88.9%
if -2.29999999999999996e-86 < c < 2.4000000000000001e-141Initial program 74.2%
Taylor expanded in d around inf 95.9%
associate-/l*96.3%
Simplified96.3%
if 6.80000000000000037e-68 < c < 2.3e30Initial program 61.1%
Taylor expanded in d around inf 83.9%
associate-/l*83.8%
Simplified83.8%
clear-num79.0%
un-div-inv78.9%
Applied egg-rr78.9%
associate-/r/84.0%
Applied egg-rr84.0%
if 2.3e30 < c < 2.69999999999999999e163Initial program 60.8%
Taylor expanded in a around inf 54.1%
*-commutative54.1%
Simplified54.1%
*-un-lft-identity54.1%
add-sqr-sqrt54.1%
hypot-undefine54.1%
hypot-undefine54.1%
times-frac62.1%
hypot-undefine54.1%
+-commutative54.1%
hypot-define62.1%
hypot-undefine54.1%
+-commutative54.1%
hypot-define62.1%
Applied egg-rr62.1%
associate-*l/62.2%
*-lft-identity62.2%
associate-/l*79.7%
associate-*l/79.7%
Simplified79.7%
if 2.69999999999999999e163 < c Initial program 27.5%
Taylor expanded in c around inf 84.1%
associate-/l*90.5%
Simplified90.5%
Final simplification89.8%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+292) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+292) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 5e+292) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+292], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+292}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.9999999999999996e292Initial program 78.2%
*-un-lft-identity78.2%
add-sqr-sqrt78.1%
times-frac78.1%
hypot-define78.1%
fma-define78.1%
hypot-define95.3%
Applied egg-rr95.3%
if 4.9999999999999996e292 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 20.4%
Taylor expanded in c around inf 54.6%
associate-/l*64.6%
Simplified64.6%
clear-num64.6%
un-div-inv64.7%
Applied egg-rr64.7%
Final simplification87.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -1.9e+130)
(/ (+ a (* d (/ b c))) c)
(if (<= c -2e-86)
t_0
(if (<= c 1.62e-136)
(/ (+ b (* a (/ c d))) d)
(if (<= c 1.7e-66)
t_0
(if (<= c 1.88e+31)
(/ (+ b (* c (/ a d))) d)
(/ (+ a (* b (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.9e+130) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -2e-86) {
tmp = t_0;
} else if (c <= 1.62e-136) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.7e-66) {
tmp = t_0;
} else if (c <= 1.88e+31) {
tmp = (b + (c * (a / 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (c <= (-1.9d+130)) then
tmp = (a + (d * (b / c))) / c
else if (c <= (-2d-86)) then
tmp = t_0
else if (c <= 1.62d-136) then
tmp = (b + (a * (c / d))) / d
else if (c <= 1.7d-66) then
tmp = t_0
else if (c <= 1.88d+31) then
tmp = (b + (c * (a / 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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.9e+130) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= -2e-86) {
tmp = t_0;
} else if (c <= 1.62e-136) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 1.7e-66) {
tmp = t_0;
} else if (c <= 1.88e+31) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -1.9e+130: tmp = (a + (d * (b / c))) / c elif c <= -2e-86: tmp = t_0 elif c <= 1.62e-136: tmp = (b + (a * (c / d))) / d elif c <= 1.7e-66: tmp = t_0 elif c <= 1.88e+31: tmp = (b + (c * (a / d))) / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -1.9e+130) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= -2e-86) tmp = t_0; elseif (c <= 1.62e-136) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 1.7e-66) tmp = t_0; elseif (c <= 1.88e+31) tmp = Float64(Float64(b + Float64(c * Float64(a / 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) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -1.9e+130) tmp = (a + (d * (b / c))) / c; elseif (c <= -2e-86) tmp = t_0; elseif (c <= 1.62e-136) tmp = (b + (a * (c / d))) / d; elseif (c <= 1.7e-66) tmp = t_0; elseif (c <= 1.88e+31) tmp = (b + (c * (a / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.9e+130], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2e-86], t$95$0, If[LessEqual[c, 1.62e-136], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.7e-66], t$95$0, If[LessEqual[c, 1.88e+31], N[(N[(b + N[(c * N[(a / 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}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -1.9 \cdot 10^{+130}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq -2 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.62 \cdot 10^{-136}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 1.7 \cdot 10^{-66}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.88 \cdot 10^{+31}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.9000000000000001e130Initial program 36.2%
Taylor expanded in c around inf 73.8%
associate-/l*83.2%
Simplified83.2%
clear-num83.2%
un-div-inv83.2%
Applied egg-rr83.2%
associate-/r/85.7%
Applied egg-rr85.7%
if -1.9000000000000001e130 < c < -2.00000000000000017e-86 or 1.6200000000000001e-136 < c < 1.69999999999999999e-66Initial program 88.9%
if -2.00000000000000017e-86 < c < 1.6200000000000001e-136Initial program 74.2%
Taylor expanded in d around inf 95.9%
associate-/l*96.3%
Simplified96.3%
if 1.69999999999999999e-66 < c < 1.87999999999999996e31Initial program 61.1%
Taylor expanded in d around inf 83.9%
associate-/l*83.8%
Simplified83.8%
clear-num79.0%
un-div-inv78.9%
Applied egg-rr78.9%
associate-/r/84.0%
Applied egg-rr84.0%
if 1.87999999999999996e31 < c Initial program 42.0%
Taylor expanded in c around inf 74.0%
associate-/l*77.6%
Simplified77.6%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.5e-80) (not (<= c 1.08e+30))) (/ (+ a (* b (/ d c))) c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.5e-80) || !(c <= 1.08e+30)) {
tmp = (a + (b * (d / c))) / 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 <= (-7.5d-80)) .or. (.not. (c <= 1.08d+30))) then
tmp = (a + (b * (d / c))) / 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 <= -7.5e-80) || !(c <= 1.08e+30)) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -7.5e-80) or not (c <= 1.08e+30): tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.5e-80) || !(c <= 1.08e+30)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -7.5e-80) || ~((c <= 1.08e+30))) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.5e-80], N[Not[LessEqual[c, 1.08e+30]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{-80} \lor \neg \left(c \leq 1.08 \cdot 10^{+30}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -7.49999999999999999e-80 or 1.08e30 < c Initial program 52.1%
Taylor expanded in c around inf 69.4%
associate-/l*73.6%
Simplified73.6%
if -7.49999999999999999e-80 < c < 1.08e30Initial program 75.7%
Taylor expanded in c around 0 76.4%
Final simplification74.9%
(FPCore (a b c d) :precision binary64 (if (<= c -6.4e-80) (/ (+ a (* d (/ b c))) c) (if (<= c 1.75e+30) (/ b d) (/ (+ a (* b (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.4e-80) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 1.75e+30) {
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 (c <= (-6.4d-80)) then
tmp = (a + (d * (b / c))) / c
else if (c <= 1.75d+30) 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 (c <= -6.4e-80) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 1.75e+30) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -6.4e-80: tmp = (a + (d * (b / c))) / c elif c <= 1.75e+30: tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -6.4e-80) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= 1.75e+30) 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 (c <= -6.4e-80) tmp = (a + (d * (b / c))) / c; elseif (c <= 1.75e+30) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.4e-80], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.75e+30], 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}\;c \leq -6.4 \cdot 10^{-80}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 1.75 \cdot 10^{+30}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -6.3999999999999998e-80Initial program 60.6%
Taylor expanded in c around inf 65.6%
associate-/l*70.3%
Simplified70.3%
clear-num70.3%
un-div-inv70.3%
Applied egg-rr70.3%
associate-/r/71.6%
Applied egg-rr71.6%
if -6.3999999999999998e-80 < c < 1.75000000000000011e30Initial program 75.7%
Taylor expanded in c around 0 76.4%
if 1.75000000000000011e30 < c Initial program 42.0%
Taylor expanded in c around inf 74.0%
associate-/l*77.6%
Simplified77.6%
Final simplification75.3%
(FPCore (a b c d) :precision binary64 (if (<= c -6.8e+33) (/ (+ a (* d (/ b c))) c) (if (<= c 2.6e+30) (/ (+ b (* a (/ c d))) d) (/ (+ a (* b (/ d c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -6.8e+33) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 2.6e+30) {
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 (c <= (-6.8d+33)) then
tmp = (a + (d * (b / c))) / c
else if (c <= 2.6d+30) 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 (c <= -6.8e+33) {
tmp = (a + (d * (b / c))) / c;
} else if (c <= 2.6e+30) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -6.8e+33: tmp = (a + (d * (b / c))) / c elif c <= 2.6e+30: 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 (c <= -6.8e+33) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); elseif (c <= 2.6e+30) 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 (c <= -6.8e+33) tmp = (a + (d * (b / c))) / c; elseif (c <= 2.6e+30) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.8e+33], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.6e+30], 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}\;c \leq -6.8 \cdot 10^{+33}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -6.7999999999999999e33Initial program 54.8%
Taylor expanded in c around inf 71.3%
associate-/l*77.4%
Simplified77.4%
clear-num77.3%
un-div-inv77.4%
Applied egg-rr77.4%
associate-/r/79.0%
Applied egg-rr79.0%
if -6.7999999999999999e33 < c < 2.59999999999999988e30Initial program 76.4%
Taylor expanded in d around inf 86.6%
associate-/l*86.8%
Simplified86.8%
if 2.59999999999999988e30 < c Initial program 42.0%
Taylor expanded in c around inf 74.0%
associate-/l*77.6%
Simplified77.6%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.1e-80) (not (<= c 3.55e+31))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.1e-80) || !(c <= 3.55e+31)) {
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 <= (-2.1d-80)) .or. (.not. (c <= 3.55d+31))) 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 <= -2.1e-80) || !(c <= 3.55e+31)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.1e-80) or not (c <= 3.55e+31): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.1e-80) || !(c <= 3.55e+31)) 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 <= -2.1e-80) || ~((c <= 3.55e+31))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.1e-80], N[Not[LessEqual[c, 3.55e+31]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.1 \cdot 10^{-80} \lor \neg \left(c \leq 3.55 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.10000000000000001e-80 or 3.5499999999999998e31 < c Initial program 52.1%
Taylor expanded in c around inf 61.7%
if -2.10000000000000001e-80 < c < 3.5499999999999998e31Initial program 75.7%
Taylor expanded in c around 0 76.4%
Final simplification68.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 63.3%
Taylor expanded in c around inf 40.0%
Final simplification40.0%
(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 2024080
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(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))))