
(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 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+264) (* (/ 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))) <= 2e+264) {
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))) <= 2e+264) 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], 2e+264], 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 2 \cdot 10^{+264}:\\
\;\;\;\;\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))) < 2.00000000000000009e264Initial program 76.6%
*-un-lft-identity76.6%
associate-*r/76.6%
fma-define76.6%
add-sqr-sqrt76.6%
times-frac76.5%
fma-define76.5%
hypot-define76.5%
fma-define76.5%
fma-define76.6%
hypot-define96.5%
Applied egg-rr96.5%
if 2.00000000000000009e264 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.9%
Taylor expanded in c around inf 57.7%
associate-/l*67.9%
Simplified67.9%
Taylor expanded in b around 0 57.7%
*-rgt-identity57.7%
times-frac64.8%
/-rgt-identity64.8%
associate-/r/68.0%
Simplified68.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* d (/ b c))) c)))
(if (<= c -2.9e-14)
t_0
(if (<= c 1.12e-150)
(/ (+ b (* a (/ c d))) d)
(if (<= c 5e+83) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -2.9e-14) {
tmp = t_0;
} else if (c <= 1.12e-150) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 5e+83) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} 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 = (a + (d * (b / c))) / c
if (c <= (-2.9d-14)) then
tmp = t_0
else if (c <= 1.12d-150) then
tmp = (b + (a * (c / d))) / d
else if (c <= 5d+83) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
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 = (a + (d * (b / c))) / c;
double tmp;
if (c <= -2.9e-14) {
tmp = t_0;
} else if (c <= 1.12e-150) {
tmp = (b + (a * (c / d))) / d;
} else if (c <= 5e+83) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (d * (b / c))) / c tmp = 0 if c <= -2.9e-14: tmp = t_0 elif c <= 1.12e-150: tmp = (b + (a * (c / d))) / d elif c <= 5e+83: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(d * Float64(b / c))) / c) tmp = 0.0 if (c <= -2.9e-14) tmp = t_0; elseif (c <= 1.12e-150) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); elseif (c <= 5e+83) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (d * (b / c))) / c; tmp = 0.0; if (c <= -2.9e-14) tmp = t_0; elseif (c <= 1.12e-150) tmp = (b + (a * (c / d))) / d; elseif (c <= 5e+83) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.9e-14], t$95$0, If[LessEqual[c, 1.12e-150], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5e+83], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -2.9 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.12 \cdot 10^{-150}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{+83}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.9000000000000003e-14 or 5.00000000000000029e83 < c Initial program 47.1%
Taylor expanded in c around inf 76.6%
associate-/l*82.7%
Simplified82.7%
Taylor expanded in b around 0 76.6%
*-rgt-identity76.6%
times-frac83.2%
/-rgt-identity83.2%
associate-/r/82.2%
Simplified82.2%
associate-/r/83.2%
Applied egg-rr83.2%
if -2.9000000000000003e-14 < c < 1.12e-150Initial program 69.6%
Taylor expanded in d around inf 90.0%
associate-/l*90.0%
Simplified90.0%
if 1.12e-150 < c < 5.00000000000000029e83Initial program 86.0%
Final simplification86.5%
(FPCore (a b c d)
:precision binary64
(if (or (<= d -2500000.0)
(not (or (<= d 2e-61) (and (not (<= d 7.8e+112)) (<= d 1.02e+133)))))
(/ b d)
(/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2500000.0) || !((d <= 2e-61) || (!(d <= 7.8e+112) && (d <= 1.02e+133)))) {
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 <= (-2500000.0d0)) .or. (.not. (d <= 2d-61) .or. (.not. (d <= 7.8d+112)) .and. (d <= 1.02d+133))) 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 <= -2500000.0) || !((d <= 2e-61) || (!(d <= 7.8e+112) && (d <= 1.02e+133)))) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2500000.0) or not ((d <= 2e-61) or (not (d <= 7.8e+112) and (d <= 1.02e+133))): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2500000.0) || !((d <= 2e-61) || (!(d <= 7.8e+112) && (d <= 1.02e+133)))) 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 <= -2500000.0) || ~(((d <= 2e-61) || (~((d <= 7.8e+112)) && (d <= 1.02e+133))))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2500000.0], N[Not[Or[LessEqual[d, 2e-61], And[N[Not[LessEqual[d, 7.8e+112]], $MachinePrecision], LessEqual[d, 1.02e+133]]]], $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 -2500000 \lor \neg \left(d \leq 2 \cdot 10^{-61} \lor \neg \left(d \leq 7.8 \cdot 10^{+112}\right) \land d \leq 1.02 \cdot 10^{+133}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.5e6 or 2.0000000000000001e-61 < d < 7.79999999999999937e112 or 1.02e133 < d Initial program 59.4%
Taylor expanded in c around 0 69.9%
if -2.5e6 < d < 2.0000000000000001e-61 or 7.79999999999999937e112 < d < 1.02e133Initial program 67.9%
Taylor expanded in c around inf 82.8%
associate-/l*84.1%
Simplified84.1%
Final simplification76.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -3000000.0)
(/ b d)
(if (<= d 2e-61)
(/ (+ a (/ (* b d) c)) c)
(if (or (<= d 5e+115) (not (<= d 5.4e+135)))
(/ b d)
(/ (+ a (* d (/ b c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3000000.0) {
tmp = b / d;
} else if (d <= 2e-61) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 5e+115) || !(d <= 5.4e+135)) {
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 <= (-3000000.0d0)) then
tmp = b / d
else if (d <= 2d-61) then
tmp = (a + ((b * d) / c)) / c
else if ((d <= 5d+115) .or. (.not. (d <= 5.4d+135))) 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 <= -3000000.0) {
tmp = b / d;
} else if (d <= 2e-61) {
tmp = (a + ((b * d) / c)) / c;
} else if ((d <= 5e+115) || !(d <= 5.4e+135)) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3000000.0: tmp = b / d elif d <= 2e-61: tmp = (a + ((b * d) / c)) / c elif (d <= 5e+115) or not (d <= 5.4e+135): tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3000000.0) tmp = Float64(b / d); elseif (d <= 2e-61) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); elseif ((d <= 5e+115) || !(d <= 5.4e+135)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3000000.0) tmp = b / d; elseif (d <= 2e-61) tmp = (a + ((b * d) / c)) / c; elseif ((d <= 5e+115) || ~((d <= 5.4e+135))) tmp = b / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3000000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 2e-61], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 5e+115], N[Not[LessEqual[d, 5.4e+135]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3000000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{-61}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 5 \cdot 10^{+115} \lor \neg \left(d \leq 5.4 \cdot 10^{+135}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -3e6 or 2.0000000000000001e-61 < d < 5.00000000000000008e115 or 5.3999999999999997e135 < d Initial program 59.4%
Taylor expanded in c around 0 69.9%
if -3e6 < d < 2.0000000000000001e-61Initial program 70.7%
Taylor expanded in c around inf 85.8%
if 5.00000000000000008e115 < d < 5.3999999999999997e135Initial program 34.7%
Taylor expanded in c around inf 45.6%
associate-/l*77.8%
Simplified77.8%
Taylor expanded in b around 0 45.6%
*-rgt-identity45.6%
times-frac78.2%
/-rgt-identity78.2%
associate-/r/78.2%
Simplified78.2%
associate-/r/78.2%
Applied egg-rr78.2%
Final simplification77.0%
(FPCore (a b c d)
:precision binary64
(if (<= d -90000.0)
(/ b d)
(if (<= d 1.9e-61)
(/ (+ a (* b (/ d c))) c)
(if (or (<= d 9e+114) (not (<= d 1.05e+133)))
(/ b d)
(/ (+ a (* d (/ b c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -90000.0) {
tmp = b / d;
} else if (d <= 1.9e-61) {
tmp = (a + (b * (d / c))) / c;
} else if ((d <= 9e+114) || !(d <= 1.05e+133)) {
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 <= (-90000.0d0)) then
tmp = b / d
else if (d <= 1.9d-61) then
tmp = (a + (b * (d / c))) / c
else if ((d <= 9d+114) .or. (.not. (d <= 1.05d+133))) 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 <= -90000.0) {
tmp = b / d;
} else if (d <= 1.9e-61) {
tmp = (a + (b * (d / c))) / c;
} else if ((d <= 9e+114) || !(d <= 1.05e+133)) {
tmp = b / d;
} else {
tmp = (a + (d * (b / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -90000.0: tmp = b / d elif d <= 1.9e-61: tmp = (a + (b * (d / c))) / c elif (d <= 9e+114) or not (d <= 1.05e+133): tmp = b / d else: tmp = (a + (d * (b / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -90000.0) tmp = Float64(b / d); elseif (d <= 1.9e-61) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); elseif ((d <= 9e+114) || !(d <= 1.05e+133)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -90000.0) tmp = b / d; elseif (d <= 1.9e-61) tmp = (a + (b * (d / c))) / c; elseif ((d <= 9e+114) || ~((d <= 1.05e+133))) tmp = b / d; else tmp = (a + (d * (b / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -90000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.9e-61], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 9e+114], N[Not[LessEqual[d, 1.05e+133]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -90000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{-61}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 9 \cdot 10^{+114} \lor \neg \left(d \leq 1.05 \cdot 10^{+133}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if d < -9e4 or 1.8999999999999999e-61 < d < 9.0000000000000001e114 or 1.05e133 < d Initial program 59.4%
Taylor expanded in c around 0 69.9%
if -9e4 < d < 1.8999999999999999e-61Initial program 70.7%
Taylor expanded in c around inf 85.8%
associate-/l*84.6%
Simplified84.6%
if 9.0000000000000001e114 < d < 1.05e133Initial program 34.7%
Taylor expanded in c around inf 45.6%
associate-/l*77.8%
Simplified77.8%
Taylor expanded in b around 0 45.6%
*-rgt-identity45.6%
times-frac78.2%
/-rgt-identity78.2%
associate-/r/78.2%
Simplified78.2%
associate-/r/78.2%
Applied egg-rr78.2%
Final simplification76.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.2e-14) (not (<= c 1.02e-57))) (/ (+ a (* d (/ b c))) c) (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.2e-14) || !(c <= 1.02e-57)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c / d))) / 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.2d-14)) .or. (.not. (c <= 1.02d-57))) then
tmp = (a + (d * (b / c))) / c
else
tmp = (b + (a * (c / d))) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.2e-14) || !(c <= 1.02e-57)) {
tmp = (a + (d * (b / c))) / c;
} else {
tmp = (b + (a * (c / d))) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.2e-14) or not (c <= 1.02e-57): tmp = (a + (d * (b / c))) / c else: tmp = (b + (a * (c / d))) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.2e-14) || !(c <= 1.02e-57)) tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.2e-14) || ~((c <= 1.02e-57))) tmp = (a + (d * (b / c))) / c; else tmp = (b + (a * (c / d))) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.2e-14], N[Not[LessEqual[c, 1.02e-57]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.2 \cdot 10^{-14} \lor \neg \left(c \leq 1.02 \cdot 10^{-57}\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -2.2000000000000001e-14 or 1.02e-57 < c Initial program 55.9%
Taylor expanded in c around inf 73.3%
associate-/l*77.4%
Simplified77.4%
Taylor expanded in b around 0 73.3%
*-rgt-identity73.3%
times-frac78.5%
/-rgt-identity78.5%
associate-/r/77.0%
Simplified77.0%
associate-/r/78.5%
Applied egg-rr78.5%
if -2.2000000000000001e-14 < c < 1.02e-57Initial program 71.6%
Taylor expanded in d around inf 86.9%
associate-/l*86.9%
Simplified86.9%
Final simplification82.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -46000.0) (not (<= d 9.2e-62))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -46000.0) || !(d <= 9.2e-62)) {
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 <= (-46000.0d0)) .or. (.not. (d <= 9.2d-62))) 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 <= -46000.0) || !(d <= 9.2e-62)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -46000.0) or not (d <= 9.2e-62): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -46000.0) || !(d <= 9.2e-62)) 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 <= -46000.0) || ~((d <= 9.2e-62))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -46000.0], N[Not[LessEqual[d, 9.2e-62]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -46000 \lor \neg \left(d \leq 9.2 \cdot 10^{-62}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -46000 or 9.20000000000000002e-62 < d Initial program 57.9%
Taylor expanded in c around 0 65.9%
if -46000 < d < 9.20000000000000002e-62Initial program 70.7%
Taylor expanded in c around inf 66.8%
Final simplification66.3%
(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 41.1%
(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 2024118
(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))))