
(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 9 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 (/ (fma d b (* c a)) (fma d d (* c c))))
(t_1 (/ (fma (/ a d) c b) d)))
(if (<= d -4.8e+108)
t_1
(if (<= d -1.7e-137)
t_0
(if (<= d 2.55e-28)
(/ (fma (/ d c) b a) c)
(if (<= d 1.08e+103) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (c * a)) / fma(d, d, (c * c));
double t_1 = fma((a / d), c, b) / d;
double tmp;
if (d <= -4.8e+108) {
tmp = t_1;
} else if (d <= -1.7e-137) {
tmp = t_0;
} else if (d <= 2.55e-28) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 1.08e+103) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))) t_1 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -4.8e+108) tmp = t_1; elseif (d <= -1.7e-137) tmp = t_0; elseif (d <= 2.55e-28) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 1.08e+103) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -4.8e+108], t$95$1, If[LessEqual[d, -1.7e-137], t$95$0, If[LessEqual[d, 2.55e-28], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.08e+103], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
t_1 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{+108}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -1.7 \cdot 10^{-137}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.55 \cdot 10^{-28}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.08 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.80000000000000037e108 or 1.08e103 < d Initial program 19.9%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.8
Applied rewrites86.8%
if -4.80000000000000037e108 < d < -1.70000000000000007e-137 or 2.55000000000000004e-28 < d < 1.08e103Initial program 80.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6480.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.6
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6480.6
Applied rewrites80.6%
if -1.70000000000000007e-137 < d < 2.55000000000000004e-28Initial program 64.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6464.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6464.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6464.8
Applied rewrites64.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.6
Applied rewrites90.6%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -2e+103)
(/ a c)
(if (<= c -5.2e-11)
(* (/ c (fma d d (* c c))) a)
(if (<= c 4.4e-157)
(/ b d)
(if (<= c 1.35e+110) (* (/ c (fma c c (* d d))) a) (/ a c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2e+103) {
tmp = a / c;
} else if (c <= -5.2e-11) {
tmp = (c / fma(d, d, (c * c))) * a;
} else if (c <= 4.4e-157) {
tmp = b / d;
} else if (c <= 1.35e+110) {
tmp = (c / fma(c, c, (d * d))) * a;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2e+103) tmp = Float64(a / c); elseif (c <= -5.2e-11) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * a); elseif (c <= 4.4e-157) tmp = Float64(b / d); elseif (c <= 1.35e+110) tmp = Float64(Float64(c / fma(c, c, Float64(d * d))) * a); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2e+103], N[(a / c), $MachinePrecision], If[LessEqual[c, -5.2e-11], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], If[LessEqual[c, 4.4e-157], N[(b / d), $MachinePrecision], If[LessEqual[c, 1.35e+110], N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{+103}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -5.2 \cdot 10^{-11}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{-157}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.35 \cdot 10^{+110}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot a\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2e103 or 1.35000000000000005e110 < c Initial program 40.0%
Taylor expanded in c around inf
lower-/.f6481.8
Applied rewrites81.8%
if -2e103 < c < -5.2000000000000001e-11Initial program 70.3%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6470.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6470.3
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6470.3
Applied rewrites70.3%
Taylor expanded in a around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6461.9
Applied rewrites61.9%
Applied rewrites62.0%
if -5.2000000000000001e-11 < c < 4.4000000000000002e-157Initial program 63.1%
Taylor expanded in c around 0
lower-/.f6468.9
Applied rewrites68.9%
if 4.4000000000000002e-157 < c < 1.35000000000000005e110Initial program 69.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6469.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6469.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6469.7
Applied rewrites69.7%
Taylor expanded in a around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6461.6
Applied rewrites61.6%
Final simplification71.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ c (fma c c (* d d))) a)))
(if (<= c -2e+103)
(/ a c)
(if (<= c -5.2e-11)
t_0
(if (<= c 4.4e-157) (/ b d) (if (<= c 1.35e+110) t_0 (/ a c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (c / fma(c, c, (d * d))) * a;
double tmp;
if (c <= -2e+103) {
tmp = a / c;
} else if (c <= -5.2e-11) {
tmp = t_0;
} else if (c <= 4.4e-157) {
tmp = b / d;
} else if (c <= 1.35e+110) {
tmp = t_0;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(c / fma(c, c, Float64(d * d))) * a) tmp = 0.0 if (c <= -2e+103) tmp = Float64(a / c); elseif (c <= -5.2e-11) tmp = t_0; elseif (c <= 4.4e-157) tmp = Float64(b / d); elseif (c <= 1.35e+110) tmp = t_0; else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[c, -2e+103], N[(a / c), $MachinePrecision], If[LessEqual[c, -5.2e-11], t$95$0, If[LessEqual[c, 4.4e-157], N[(b / d), $MachinePrecision], If[LessEqual[c, 1.35e+110], t$95$0, N[(a / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot a\\
\mathbf{if}\;c \leq -2 \cdot 10^{+103}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -5.2 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{-157}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.35 \cdot 10^{+110}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2e103 or 1.35000000000000005e110 < c Initial program 40.0%
Taylor expanded in c around inf
lower-/.f6481.8
Applied rewrites81.8%
if -2e103 < c < -5.2000000000000001e-11 or 4.4000000000000002e-157 < c < 1.35000000000000005e110Initial program 69.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6469.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6469.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6469.9
Applied rewrites69.9%
Taylor expanded in a around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6461.7
Applied rewrites61.7%
if -5.2000000000000001e-11 < c < 4.4000000000000002e-157Initial program 63.1%
Taylor expanded in c around 0
lower-/.f6468.9
Applied rewrites68.9%
Final simplification71.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ a (fma d d (* c c))) c)))
(if (<= c -5.4e+100)
(/ a c)
(if (<= c -5.2e-11)
t_0
(if (<= c 4.4e-157) (/ b d) (if (<= c 3.7e+109) t_0 (/ a c)))))))
double code(double a, double b, double c, double d) {
double t_0 = (a / fma(d, d, (c * c))) * c;
double tmp;
if (c <= -5.4e+100) {
tmp = a / c;
} else if (c <= -5.2e-11) {
tmp = t_0;
} else if (c <= 4.4e-157) {
tmp = b / d;
} else if (c <= 3.7e+109) {
tmp = t_0;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a / fma(d, d, Float64(c * c))) * c) tmp = 0.0 if (c <= -5.4e+100) tmp = Float64(a / c); elseif (c <= -5.2e-11) tmp = t_0; elseif (c <= 4.4e-157) tmp = Float64(b / d); elseif (c <= 3.7e+109) tmp = t_0; else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision]}, If[LessEqual[c, -5.4e+100], N[(a / c), $MachinePrecision], If[LessEqual[c, -5.2e-11], t$95$0, If[LessEqual[c, 4.4e-157], N[(b / d), $MachinePrecision], If[LessEqual[c, 3.7e+109], t$95$0, N[(a / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{if}\;c \leq -5.4 \cdot 10^{+100}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -5.2 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{-157}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 3.7 \cdot 10^{+109}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -5.39999999999999997e100 or 3.7000000000000002e109 < c Initial program 40.3%
Taylor expanded in c around inf
lower-/.f6481.2
Applied rewrites81.2%
if -5.39999999999999997e100 < c < -5.2000000000000001e-11 or 4.4000000000000002e-157 < c < 3.7000000000000002e109Initial program 70.3%
Taylor expanded in a around inf
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.6
Applied rewrites59.6%
if -5.2000000000000001e-11 < c < 4.4000000000000002e-157Initial program 63.1%
Taylor expanded in c around 0
lower-/.f6468.9
Applied rewrites68.9%
Final simplification70.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.1e+90) (not (<= d 5.9e-18))) (/ (fma (/ a d) c b) d) (/ (fma (/ d c) b a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.1e+90) || !(d <= 5.9e-18)) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = fma((d / c), b, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.1e+90) || !(d <= 5.9e-18)) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(fma(Float64(d / c), b, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.1e+90], N[Not[LessEqual[d, 5.9e-18]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+90} \lor \neg \left(d \leq 5.9 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\end{array}
\end{array}
if d < -2.09999999999999981e90 or 5.90000000000000019e-18 < d Initial program 42.2%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
if -2.09999999999999981e90 < d < 5.90000000000000019e-18Initial program 69.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6469.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6469.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6469.9
Applied rewrites69.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.9
Applied rewrites82.9%
Final simplification80.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.1e+90) (not (<= d 5.9e-18))) (/ (fma (/ a d) c b) d) (/ (fma (/ b c) d a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.1e+90) || !(d <= 5.9e-18)) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.1e+90) || !(d <= 5.9e-18)) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.1e+90], N[Not[LessEqual[d, 5.9e-18]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+90} \lor \neg \left(d \leq 5.9 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if d < -2.09999999999999981e90 or 5.90000000000000019e-18 < d Initial program 42.2%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
if -2.09999999999999981e90 < d < 5.90000000000000019e-18Initial program 69.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.7
Applied rewrites80.7%
Final simplification79.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.6e+52) (not (<= c 9.5e+65))) (/ a c) (/ (fma (/ a d) c b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.6e+52) || !(c <= 9.5e+65)) {
tmp = a / c;
} else {
tmp = fma((a / d), c, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.6e+52) || !(c <= 9.5e+65)) tmp = Float64(a / c); else tmp = Float64(fma(Float64(a / d), c, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.6e+52], N[Not[LessEqual[c, 9.5e+65]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.6 \cdot 10^{+52} \lor \neg \left(c \leq 9.5 \cdot 10^{+65}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\end{array}
\end{array}
if c < -3.6e52 or 9.5000000000000005e65 < c Initial program 48.7%
Taylor expanded in c around inf
lower-/.f6477.3
Applied rewrites77.3%
if -3.6e52 < c < 9.5000000000000005e65Initial program 64.1%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6471.6
Applied rewrites71.6%
Final simplification74.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.2e-11) (not (<= c 2.2e+51))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e-11) || !(c <= 2.2e+51)) {
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 <= (-5.2d-11)) .or. (.not. (c <= 2.2d+51))) 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 <= -5.2e-11) || !(c <= 2.2e+51)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.2e-11) or not (c <= 2.2e+51): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.2e-11) || !(c <= 2.2e+51)) 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 <= -5.2e-11) || ~((c <= 2.2e+51))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.2e-11], N[Not[LessEqual[c, 2.2e+51]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{-11} \lor \neg \left(c \leq 2.2 \cdot 10^{+51}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -5.2000000000000001e-11 or 2.19999999999999992e51 < c Initial program 49.9%
Taylor expanded in c around inf
lower-/.f6469.7
Applied rewrites69.7%
if -5.2000000000000001e-11 < c < 2.19999999999999992e51Initial program 65.1%
Taylor expanded in c around 0
lower-/.f6461.9
Applied rewrites61.9%
Final simplification65.8%
(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 57.5%
Taylor expanded in c around inf
lower-/.f6446.7
Applied rewrites46.7%
Final simplification46.7%
(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 2024337
(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))))