
(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 7 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 (/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -2.45e+73)
(+ (/ (/ b c) (/ c d)) (/ a c))
(if (<= c -8.8e-94)
t_0
(if (<= c 1.8e-124)
(/ (+ b (/ (* c a) d)) d)
(if (<= c 3.2e+48) t_0 (/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * a) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.45e+73) {
tmp = ((b / c) / (c / d)) + (a / c);
} else if (c <= -8.8e-94) {
tmp = t_0;
} else if (c <= 1.8e-124) {
tmp = (b + ((c * a) / d)) / d;
} else if (c <= 3.2e+48) {
tmp = t_0;
} 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 = ((c * a) + (b * d)) / ((c * c) + (d * d))
if (c <= (-2.45d+73)) then
tmp = ((b / c) / (c / d)) + (a / c)
else if (c <= (-8.8d-94)) then
tmp = t_0
else if (c <= 1.8d-124) then
tmp = (b + ((c * a) / d)) / d
else if (c <= 3.2d+48) then
tmp = t_0
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 = ((c * a) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.45e+73) {
tmp = ((b / c) / (c / d)) + (a / c);
} else if (c <= -8.8e-94) {
tmp = t_0;
} else if (c <= 1.8e-124) {
tmp = (b + ((c * a) / d)) / d;
} else if (c <= 3.2e+48) {
tmp = t_0;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * a) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -2.45e+73: tmp = ((b / c) / (c / d)) + (a / c) elif c <= -8.8e-94: tmp = t_0 elif c <= 1.8e-124: tmp = (b + ((c * a) / d)) / d elif c <= 3.2e+48: tmp = t_0 else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -2.45e+73) tmp = Float64(Float64(Float64(b / c) / Float64(c / d)) + Float64(a / c)); elseif (c <= -8.8e-94) tmp = t_0; elseif (c <= 1.8e-124) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); elseif (c <= 3.2e+48) tmp = t_0; 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 = ((c * a) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -2.45e+73) tmp = ((b / c) / (c / d)) + (a / c); elseif (c <= -8.8e-94) tmp = t_0; elseif (c <= 1.8e-124) tmp = (b + ((c * a) / d)) / d; elseif (c <= 3.2e+48) tmp = t_0; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.45e+73], N[(N[(N[(b / c), $MachinePrecision] / N[(c / d), $MachinePrecision]), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8.8e-94], t$95$0, If[LessEqual[c, 1.8e-124], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.2e+48], t$95$0, N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -2.45 \cdot 10^{+73}:\\
\;\;\;\;\frac{\frac{b}{c}}{\frac{c}{d}} + \frac{a}{c}\\
\mathbf{elif}\;c \leq -8.8 \cdot 10^{-94}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{-124}:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{+48}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -2.45e73Initial program 38.2%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6476.7%
Simplified76.7%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6482.4%
Applied egg-rr82.4%
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f6482.3%
Applied egg-rr82.3%
clear-numN/A
+-commutativeN/A
associate-/r/N/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
+-lowering-+.f64N/A
associate-*l/N/A
div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
un-div-invN/A
/-lowering-/.f6482.4%
Applied egg-rr82.4%
if -2.45e73 < c < -8.80000000000000004e-94 or 1.80000000000000005e-124 < c < 3.2000000000000001e48Initial program 86.0%
if -8.80000000000000004e-94 < c < 1.80000000000000005e-124Initial program 58.0%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6494.4%
Simplified94.4%
if 3.2000000000000001e48 < c Initial program 35.7%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6474.0%
Simplified74.0%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6478.8%
Applied egg-rr78.8%
Final simplification86.6%
(FPCore (a b c d)
:precision binary64
(if (<= d -3e+25)
(+ (/ b d) (/ (* (/ c d) a) d))
(if (<= d 1650000.0)
(/ (+ a (* b (/ d c))) c)
(+ (/ b d) (* (/ c d) (/ a d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e+25) {
tmp = (b / d) + (((c / d) * a) / d);
} else if (d <= 1650000.0) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b / d) + ((c / d) * (a / 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 <= (-3d+25)) then
tmp = (b / d) + (((c / d) * a) / d)
else if (d <= 1650000.0d0) then
tmp = (a + (b * (d / c))) / c
else
tmp = (b / d) + ((c / d) * (a / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e+25) {
tmp = (b / d) + (((c / d) * a) / d);
} else if (d <= 1650000.0) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3e+25: tmp = (b / d) + (((c / d) * a) / d) elif d <= 1650000.0: tmp = (a + (b * (d / c))) / c else: tmp = (b / d) + ((c / d) * (a / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3e+25) tmp = Float64(Float64(b / d) + Float64(Float64(Float64(c / d) * a) / d)); elseif (d <= 1650000.0) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3e+25) tmp = (b / d) + (((c / d) * a) / d); elseif (d <= 1650000.0) tmp = (a + (b * (d / c))) / c; else tmp = (b / d) + ((c / d) * (a / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3e+25], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(c / d), $MachinePrecision] * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1650000.0], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{+25}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{c}{d} \cdot a}{d}\\
\mathbf{elif}\;d \leq 1650000:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if d < -3.00000000000000006e25Initial program 34.4%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6474.8%
Simplified74.8%
*-commutativeN/A
frac-2negN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
neg-sub0N/A
--lowering--.f6480.8%
Applied egg-rr80.8%
if -3.00000000000000006e25 < d < 1.65e6Initial program 75.8%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6485.0%
Simplified85.0%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6485.8%
Applied egg-rr85.8%
if 1.65e6 < d Initial program 42.7%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6468.3%
Simplified68.3%
associate-/l/N/A
associate-*r/N/A
*-commutativeN/A
times-fracN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6473.7%
Applied egg-rr73.7%
Final simplification81.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (* (/ c d) (/ a d)))))
(if (<= d -1.12e+27)
t_0
(if (<= d 290000000.0) (/ (+ a (* b (/ d c))) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -1.12e+27) {
tmp = t_0;
} else if (d <= 290000000.0) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b / d) + ((c / d) * (a / d))
if (d <= (-1.12d+27)) then
tmp = t_0
else if (d <= 290000000.0d0) then
tmp = (a + (b * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -1.12e+27) {
tmp = t_0;
} else if (d <= 290000000.0) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + ((c / d) * (a / d)) tmp = 0 if d <= -1.12e+27: tmp = t_0 elif d <= 290000000.0: tmp = (a + (b * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))) tmp = 0.0 if (d <= -1.12e+27) tmp = t_0; elseif (d <= 290000000.0) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + ((c / d) * (a / d)); tmp = 0.0; if (d <= -1.12e+27) tmp = t_0; elseif (d <= 290000000.0) tmp = (a + (b * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.12e+27], t$95$0, If[LessEqual[d, 290000000.0], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -1.12 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 290000000:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.12e27 or 2.9e8 < d Initial program 38.7%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6471.4%
Simplified71.4%
associate-/l/N/A
associate-*r/N/A
*-commutativeN/A
times-fracN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6477.1%
Applied egg-rr77.1%
if -1.12e27 < d < 2.9e8Initial program 75.8%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6485.0%
Simplified85.0%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6485.8%
Applied egg-rr85.8%
Final simplification81.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (/ (* c a) d)) d)))
(if (<= d -6.8e+26)
t_0
(if (<= d 185000000.0) (/ (+ a (* b (/ d c))) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b + ((c * a) / d)) / d;
double tmp;
if (d <= -6.8e+26) {
tmp = t_0;
} else if (d <= 185000000.0) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b + ((c * a) / d)) / d
if (d <= (-6.8d+26)) then
tmp = t_0
else if (d <= 185000000.0d0) then
tmp = (a + (b * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b + ((c * a) / d)) / d;
double tmp;
if (d <= -6.8e+26) {
tmp = t_0;
} else if (d <= 185000000.0) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + ((c * a) / d)) / d tmp = 0 if d <= -6.8e+26: tmp = t_0 elif d <= 185000000.0: tmp = (a + (b * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(Float64(c * a) / d)) / d) tmp = 0.0 if (d <= -6.8e+26) tmp = t_0; elseif (d <= 185000000.0) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + ((c * a) / d)) / d; tmp = 0.0; if (d <= -6.8e+26) tmp = t_0; elseif (d <= 185000000.0) tmp = (a + (b * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -6.8e+26], t$95$0, If[LessEqual[d, 185000000.0], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{if}\;d \leq -6.8 \cdot 10^{+26}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 185000000:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.8000000000000005e26 or 1.85e8 < d Initial program 38.7%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6476.2%
Simplified76.2%
if -6.8000000000000005e26 < d < 1.85e8Initial program 75.8%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6485.0%
Simplified85.0%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6485.8%
Applied egg-rr85.8%
Final simplification81.2%
(FPCore (a b c d) :precision binary64 (if (<= d -1.52e+29) (/ b d) (if (<= d 5.9e+29) (/ (+ a (* b (/ d c))) c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.52e+29) {
tmp = b / d;
} else if (d <= 5.9e+29) {
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 (d <= (-1.52d+29)) then
tmp = b / d
else if (d <= 5.9d+29) 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 (d <= -1.52e+29) {
tmp = b / d;
} else if (d <= 5.9e+29) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.52e+29: tmp = b / d elif d <= 5.9e+29: tmp = (a + (b * (d / c))) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.52e+29) tmp = Float64(b / d); elseif (d <= 5.9e+29) 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 (d <= -1.52e+29) tmp = b / d; elseif (d <= 5.9e+29) tmp = (a + (b * (d / c))) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.52e+29], N[(b / d), $MachinePrecision], If[LessEqual[d, 5.9e+29], 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}\;d \leq -1.52 \cdot 10^{+29}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 5.9 \cdot 10^{+29}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.52e29 or 5.8999999999999999e29 < d Initial program 35.9%
Taylor expanded in c around 0
/-lowering-/.f6469.4%
Simplified69.4%
if -1.52e29 < d < 5.8999999999999999e29Initial program 76.3%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6483.0%
Simplified83.0%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6483.7%
Applied egg-rr83.7%
Final simplification77.2%
(FPCore (a b c d) :precision binary64 (if (<= d -4.5e-16) (/ b d) (if (<= d 65000000000000.0) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.5e-16) {
tmp = b / d;
} else if (d <= 65000000000000.0) {
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 <= (-4.5d-16)) then
tmp = b / d
else if (d <= 65000000000000.0d0) 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 <= -4.5e-16) {
tmp = b / d;
} else if (d <= 65000000000000.0) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4.5e-16: tmp = b / d elif d <= 65000000000000.0: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4.5e-16) tmp = Float64(b / d); elseif (d <= 65000000000000.0) 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 <= -4.5e-16) tmp = b / d; elseif (d <= 65000000000000.0) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.5e-16], N[(b / d), $MachinePrecision], If[LessEqual[d, 65000000000000.0], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.5 \cdot 10^{-16}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 65000000000000:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -4.5000000000000002e-16 or 6.5e13 < d Initial program 40.1%
Taylor expanded in c around 0
/-lowering-/.f6466.5%
Simplified66.5%
if -4.5000000000000002e-16 < d < 6.5e13Initial program 76.2%
Taylor expanded in c around inf
/-lowering-/.f6466.4%
Simplified66.4%
(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 58.0%
Taylor expanded in c around inf
/-lowering-/.f6440.9%
Simplified40.9%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024150
(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))))