
(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 a (/ c d) b) d)))
(if (<= d -7e-29)
t_0
(if (<= d 4.25e-106)
(/ (fma b (/ d c) a) c)
(if (<= d 2.9e+60) (/ (+ (* a c) (* d b)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(a, (c / d), b) / d;
double tmp;
if (d <= -7e-29) {
tmp = t_0;
} else if (d <= 4.25e-106) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 2.9e+60) {
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(a, Float64(c / d), b) / d) tmp = 0.0 if (d <= -7e-29) tmp = t_0; elseif (d <= 4.25e-106) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 2.9e+60) tmp = Float64(Float64(Float64(a * c) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7e-29], t$95$0, If[LessEqual[d, 4.25e-106], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.9e+60], N[(N[(N[(a * c), $MachinePrecision] + N[(d * b), $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{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{if}\;d \leq -7 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.25 \cdot 10^{-106}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 2.9 \cdot 10^{+60}:\\
\;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.9999999999999995e-29 or 2.9e60 < d Initial program 43.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.0
Applied rewrites81.0%
if -6.9999999999999995e-29 < d < 4.2499999999999999e-106Initial program 69.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6488.7
Applied rewrites88.7%
if 4.2499999999999999e-106 < d < 2.9e60Initial program 94.4%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(if (<= d -2.1e+82)
(/ b d)
(if (<= d -3.7e-29)
(/ (fma d b (* a c)) (* d d))
(if (<= d 2.05e-120)
(/ a c)
(if (<= d 7.5e+130) (* b (/ d (fma c c (* d d)))) (/ b d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.1e+82) {
tmp = b / d;
} else if (d <= -3.7e-29) {
tmp = fma(d, b, (a * c)) / (d * d);
} else if (d <= 2.05e-120) {
tmp = a / c;
} else if (d <= 7.5e+130) {
tmp = b * (d / fma(c, c, (d * d)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -2.1e+82) tmp = Float64(b / d); elseif (d <= -3.7e-29) tmp = Float64(fma(d, b, Float64(a * c)) / Float64(d * d)); elseif (d <= 2.05e-120) tmp = Float64(a / c); elseif (d <= 7.5e+130) tmp = Float64(b * Float64(d / fma(c, c, Float64(d * d)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.1e+82], N[(b / d), $MachinePrecision], If[LessEqual[d, -3.7e-29], N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.05e-120], N[(a / c), $MachinePrecision], If[LessEqual[d, 7.5e+130], N[(b * N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+82}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -3.7 \cdot 10^{-29}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{d \cdot d}\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+130}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -2.1e82 or 7.5000000000000003e130 < d Initial program 30.5%
Taylor expanded in c around 0
lower-/.f6476.9
Applied rewrites76.9%
if -2.1e82 < d < -3.6999999999999997e-29Initial program 78.3%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6469.8
Applied rewrites69.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6469.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6469.8
Applied rewrites69.8%
if -3.6999999999999997e-29 < d < 2.05000000000000017e-120Initial program 71.5%
Taylor expanded in c around inf
lower-/.f6472.7
Applied rewrites72.7%
if 2.05000000000000017e-120 < d < 7.5000000000000003e130Initial program 75.2%
Taylor expanded in a around 0
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6458.1
Applied rewrites58.1%
Applied rewrites67.2%
Final simplification72.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -8e-22)
(/ b d)
(if (<= d 2.05e-120)
(/ a c)
(if (<= d 7.5e+130) (* b (/ d (fma c c (* d d)))) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -8e-22) {
tmp = b / d;
} else if (d <= 2.05e-120) {
tmp = a / c;
} else if (d <= 7.5e+130) {
tmp = b * (d / fma(c, c, (d * d)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -8e-22) tmp = Float64(b / d); elseif (d <= 2.05e-120) tmp = Float64(a / c); elseif (d <= 7.5e+130) tmp = Float64(b * Float64(d / fma(c, c, Float64(d * d)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -8e-22], N[(b / d), $MachinePrecision], If[LessEqual[d, 2.05e-120], N[(a / c), $MachinePrecision], If[LessEqual[d, 7.5e+130], N[(b * N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+130}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -8.0000000000000004e-22 or 7.5000000000000003e130 < d Initial program 40.4%
Taylor expanded in c around 0
lower-/.f6472.0
Applied rewrites72.0%
if -8.0000000000000004e-22 < d < 2.05000000000000017e-120Initial program 71.8%
Taylor expanded in c around inf
lower-/.f6471.9
Applied rewrites71.9%
if 2.05000000000000017e-120 < d < 7.5000000000000003e130Initial program 75.2%
Taylor expanded in a around 0
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6458.1
Applied rewrites58.1%
Applied rewrites67.2%
Final simplification70.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -8e-22)
(/ b d)
(if (<= d 5.5e-109)
(/ a c)
(if (<= d 5.6e+92) (* d (/ b (fma c c (* d d)))) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -8e-22) {
tmp = b / d;
} else if (d <= 5.5e-109) {
tmp = a / c;
} else if (d <= 5.6e+92) {
tmp = d * (b / fma(c, c, (d * d)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -8e-22) tmp = Float64(b / d); elseif (d <= 5.5e-109) tmp = Float64(a / c); elseif (d <= 5.6e+92) tmp = Float64(d * Float64(b / fma(c, c, Float64(d * d)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -8e-22], N[(b / d), $MachinePrecision], If[LessEqual[d, 5.5e-109], N[(a / c), $MachinePrecision], If[LessEqual[d, 5.6e+92], N[(d * N[(b / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 5.5 \cdot 10^{-109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 5.6 \cdot 10^{+92}:\\
\;\;\;\;d \cdot \frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -8.0000000000000004e-22 or 5.60000000000000001e92 < d Initial program 42.5%
Taylor expanded in c around 0
lower-/.f6471.7
Applied rewrites71.7%
if -8.0000000000000004e-22 < d < 5.5000000000000003e-109Initial program 69.9%
Taylor expanded in c around inf
lower-/.f6471.0
Applied rewrites71.0%
if 5.5000000000000003e-109 < d < 5.60000000000000001e92Initial program 83.2%
Taylor expanded in a around 0
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.0
Applied rewrites64.0%
Applied rewrites64.3%
(FPCore (a b c d) :precision binary64 (if (<= d -7e-29) (/ (fma a (/ c d) b) d) (if (<= d 2.1e-36) (/ (fma b (/ d c) a) c) (/ b (fma (/ c d) c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7e-29) {
tmp = fma(a, (c / d), b) / d;
} else if (d <= 2.1e-36) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = b / fma((c / d), c, d);
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -7e-29) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (d <= 2.1e-36) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = Float64(b / fma(Float64(c / d), c, d)); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -7e-29], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.1e-36], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(b / N[(N[(c / d), $MachinePrecision] * c + d), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{-29}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-36}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}\\
\end{array}
\end{array}
if d < -6.9999999999999995e-29Initial program 43.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
if -6.9999999999999995e-29 < d < 2.09999999999999991e-36Initial program 73.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6485.3
Applied rewrites85.3%
if 2.09999999999999991e-36 < d Initial program 56.1%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6456.1
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6456.1
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6456.1
Applied rewrites56.1%
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
*-commutativeN/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
Applied rewrites69.2%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6481.5
Applied rewrites81.5%
Applied rewrites82.8%
(FPCore (a b c d) :precision binary64 (if (<= d -3.7e-29) (/ (fma a (/ c d) b) d) (if (<= d 2.05e-120) (/ a c) (/ b (fma (/ c d) c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.7e-29) {
tmp = fma(a, (c / d), b) / d;
} else if (d <= 2.05e-120) {
tmp = a / c;
} else {
tmp = b / fma((c / d), c, d);
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -3.7e-29) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (d <= 2.05e-120) tmp = Float64(a / c); else tmp = Float64(b / fma(Float64(c / d), c, d)); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.7e-29], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.05e-120], N[(a / c), $MachinePrecision], N[(b / N[(N[(c / d), $MachinePrecision] * c + d), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.7 \cdot 10^{-29}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}\\
\end{array}
\end{array}
if d < -3.6999999999999997e-29Initial program 43.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
if -3.6999999999999997e-29 < d < 2.05000000000000017e-120Initial program 71.5%
Taylor expanded in c around inf
lower-/.f6472.7
Applied rewrites72.7%
if 2.05000000000000017e-120 < d Initial program 61.4%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6461.4
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6461.4
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6461.4
Applied rewrites61.4%
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
*-commutativeN/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
Applied rewrites71.4%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6476.0
Applied rewrites76.0%
Applied rewrites77.0%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ b (fma (/ c d) c d)))) (if (<= d -3.2e-137) t_0 (if (<= d 2.05e-120) (/ a c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = b / fma((c / d), c, d);
double tmp;
if (d <= -3.2e-137) {
tmp = t_0;
} else if (d <= 2.05e-120) {
tmp = a / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(b / fma(Float64(c / d), c, d)) tmp = 0.0 if (d <= -3.2e-137) tmp = t_0; elseif (d <= 2.05e-120) tmp = Float64(a / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b / N[(N[(c / d), $MachinePrecision] * c + d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.2e-137], t$95$0, If[LessEqual[d, 2.05e-120], N[(a / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}\\
\mathbf{if}\;d \leq -3.2 \cdot 10^{-137}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.20000000000000021e-137 or 2.05000000000000017e-120 < d Initial program 56.9%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6456.9
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6456.9
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6456.9
Applied rewrites56.9%
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
*-commutativeN/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
Applied rewrites64.6%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6466.4
Applied rewrites66.4%
Applied rewrites70.4%
if -3.20000000000000021e-137 < d < 2.05000000000000017e-120Initial program 68.1%
Taylor expanded in c around inf
lower-/.f6479.0
Applied rewrites79.0%
(FPCore (a b c d) :precision binary64 (if (<= d -8e-22) (/ b d) (if (<= d 5.1e-120) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -8e-22) {
tmp = b / d;
} else if (d <= 5.1e-120) {
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 (d <= (-8d-22)) then
tmp = b / d
else if (d <= 5.1d-120) 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 (d <= -8e-22) {
tmp = b / d;
} else if (d <= 5.1e-120) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -8e-22: tmp = b / d elif d <= 5.1e-120: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -8e-22) tmp = Float64(b / d); elseif (d <= 5.1e-120) 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 (d <= -8e-22) tmp = b / d; elseif (d <= 5.1e-120) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -8e-22], N[(b / d), $MachinePrecision], If[LessEqual[d, 5.1e-120], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 5.1 \cdot 10^{-120}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -8.0000000000000004e-22 or 5.0999999999999998e-120 < d Initial program 53.5%
Taylor expanded in c around 0
lower-/.f6462.8
Applied rewrites62.8%
if -8.0000000000000004e-22 < d < 5.0999999999999998e-120Initial program 71.8%
Taylor expanded in c around inf
lower-/.f6471.9
Applied rewrites71.9%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 59.9%
Taylor expanded in c around inf
lower-/.f6438.3
Applied rewrites38.3%
(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 2024216
(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))))