
(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 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* d (/ b c))) c)) (t_1 (+ (* c c) (* d d))))
(if (<= c -1.15e-33)
t_0
(if (<= c 5.2e-79)
(/ (+ b (/ (* c a) d)) d)
(if (<= c 1e+130) (* a (+ (/ c t_1) (/ (/ (* d b) t_1) a))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (a + (d * (b / c))) / c;
double t_1 = (c * c) + (d * d);
double tmp;
if (c <= -1.15e-33) {
tmp = t_0;
} else if (c <= 5.2e-79) {
tmp = (b + ((c * a) / d)) / d;
} else if (c <= 1e+130) {
tmp = a * ((c / t_1) + (((d * b) / t_1) / a));
} 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) :: t_1
real(8) :: tmp
t_0 = (a + (d * (b / c))) / c
t_1 = (c * c) + (d * d)
if (c <= (-1.15d-33)) then
tmp = t_0
else if (c <= 5.2d-79) then
tmp = (b + ((c * a) / d)) / d
else if (c <= 1d+130) then
tmp = a * ((c / t_1) + (((d * b) / t_1) / a))
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 t_1 = (c * c) + (d * d);
double tmp;
if (c <= -1.15e-33) {
tmp = t_0;
} else if (c <= 5.2e-79) {
tmp = (b + ((c * a) / d)) / d;
} else if (c <= 1e+130) {
tmp = a * ((c / t_1) + (((d * b) / t_1) / a));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (d * (b / c))) / c t_1 = (c * c) + (d * d) tmp = 0 if c <= -1.15e-33: tmp = t_0 elif c <= 5.2e-79: tmp = (b + ((c * a) / d)) / d elif c <= 1e+130: tmp = a * ((c / t_1) + (((d * b) / t_1) / a)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(d * Float64(b / c))) / c) t_1 = Float64(Float64(c * c) + Float64(d * d)) tmp = 0.0 if (c <= -1.15e-33) tmp = t_0; elseif (c <= 5.2e-79) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); elseif (c <= 1e+130) tmp = Float64(a * Float64(Float64(c / t_1) + Float64(Float64(Float64(d * b) / t_1) / a))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + (d * (b / c))) / c; t_1 = (c * c) + (d * d); tmp = 0.0; if (c <= -1.15e-33) tmp = t_0; elseif (c <= 5.2e-79) tmp = (b + ((c * a) / d)) / d; elseif (c <= 1e+130) tmp = a * ((c / t_1) + (((d * b) / t_1) / a)); 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]}, Block[{t$95$1 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.15e-33], t$95$0, If[LessEqual[c, 5.2e-79], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1e+130], N[(a * N[(N[(c / t$95$1), $MachinePrecision] + N[(N[(N[(d * b), $MachinePrecision] / t$95$1), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\
t_1 := c \cdot c + d \cdot d\\
\mathbf{if}\;c \leq -1.15 \cdot 10^{-33}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{-79}:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{elif}\;c \leq 10^{+130}:\\
\;\;\;\;a \cdot \left(\frac{c}{t\_1} + \frac{\frac{d \cdot b}{t\_1}}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.14999999999999993e-33 or 1.0000000000000001e130 < c Initial program 41.9%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6471.7%
Simplified71.7%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6477.3%
Applied egg-rr77.3%
if -1.14999999999999993e-33 < c < 5.19999999999999987e-79Initial program 73.6%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6487.7%
Simplified87.7%
if 5.19999999999999987e-79 < c < 1.0000000000000001e130Initial program 83.0%
Taylor expanded in a around inf
*-lowering-*.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-/l/N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6483.1%
Simplified83.1%
Final simplification82.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ a (* d (/ b c))) c)))
(if (<= c -1.85e-33)
t_0
(if (<= c 9.2e-83)
(/ (+ b (/ (* c a) d)) d)
(if (<= c 1.12e+125)
(/ (+ (* d b) (* c a)) (+ (* 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 <= -1.85e-33) {
tmp = t_0;
} else if (c <= 9.2e-83) {
tmp = (b + ((c * a) / d)) / d;
} else if (c <= 1.12e+125) {
tmp = ((d * b) + (c * a)) / ((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 <= (-1.85d-33)) then
tmp = t_0
else if (c <= 9.2d-83) then
tmp = (b + ((c * a) / d)) / d
else if (c <= 1.12d+125) then
tmp = ((d * b) + (c * a)) / ((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 <= -1.85e-33) {
tmp = t_0;
} else if (c <= 9.2e-83) {
tmp = (b + ((c * a) / d)) / d;
} else if (c <= 1.12e+125) {
tmp = ((d * b) + (c * a)) / ((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 <= -1.85e-33: tmp = t_0 elif c <= 9.2e-83: tmp = (b + ((c * a) / d)) / d elif c <= 1.12e+125: tmp = ((d * b) + (c * a)) / ((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 <= -1.85e-33) tmp = t_0; elseif (c <= 9.2e-83) tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d); elseif (c <= 1.12e+125) tmp = Float64(Float64(Float64(d * b) + Float64(c * a)) / 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 <= -1.85e-33) tmp = t_0; elseif (c <= 9.2e-83) tmp = (b + ((c * a) / d)) / d; elseif (c <= 1.12e+125) tmp = ((d * b) + (c * a)) / ((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, -1.85e-33], t$95$0, If[LessEqual[c, 9.2e-83], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.12e+125], N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $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 -1.85 \cdot 10^{-33}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 9.2 \cdot 10^{-83}:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{elif}\;c \leq 1.12 \cdot 10^{+125}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.85000000000000007e-33 or 1.12e125 < c Initial program 41.9%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6471.7%
Simplified71.7%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6477.3%
Applied egg-rr77.3%
if -1.85000000000000007e-33 < c < 9.19999999999999959e-83Initial program 73.6%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6487.7%
Simplified87.7%
if 9.19999999999999959e-83 < c < 1.12e125Initial program 83.0%
Final simplification82.5%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (+ a (* d (/ b c))) c))) (if (<= c -4.15e-32) t_0 (if (<= c 92.0) (/ (+ b (/ (* c a) 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 <= -4.15e-32) {
tmp = t_0;
} else if (c <= 92.0) {
tmp = (b + ((c * a) / 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 <= (-4.15d-32)) then
tmp = t_0
else if (c <= 92.0d0) then
tmp = (b + ((c * a) / 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 <= -4.15e-32) {
tmp = t_0;
} else if (c <= 92.0) {
tmp = (b + ((c * a) / 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 <= -4.15e-32: tmp = t_0 elif c <= 92.0: tmp = (b + ((c * a) / 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 <= -4.15e-32) tmp = t_0; elseif (c <= 92.0) tmp = Float64(Float64(b + Float64(Float64(c * a) / 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 <= -4.15e-32) tmp = t_0; elseif (c <= 92.0) tmp = (b + ((c * a) / 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, -4.15e-32], t$95$0, If[LessEqual[c, 92.0], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -4.15 \cdot 10^{-32}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 92:\\
\;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.15000000000000006e-32 or 92 < c Initial program 51.3%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6470.9%
Simplified70.9%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6475.3%
Applied egg-rr75.3%
if -4.15000000000000006e-32 < c < 92Initial program 73.7%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6484.9%
Simplified84.9%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (+ a (* d (/ b c))) c))) (if (<= c -3.05e-55) t_0 (if (<= c 2.9e-68) (/ b 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 <= -3.05e-55) {
tmp = t_0;
} else if (c <= 2.9e-68) {
tmp = b / 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 <= (-3.05d-55)) then
tmp = t_0
else if (c <= 2.9d-68) then
tmp = b / 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 <= -3.05e-55) {
tmp = t_0;
} else if (c <= 2.9e-68) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + (d * (b / c))) / c tmp = 0 if c <= -3.05e-55: tmp = t_0 elif c <= 2.9e-68: tmp = b / 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 <= -3.05e-55) tmp = t_0; elseif (c <= 2.9e-68) tmp = Float64(b / 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 <= -3.05e-55) tmp = t_0; elseif (c <= 2.9e-68) tmp = b / 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, -3.05e-55], t$95$0, If[LessEqual[c, 2.9e-68], N[(b / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -3.05 \cdot 10^{-55}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.9 \cdot 10^{-68}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.0500000000000001e-55 or 2.9e-68 < c Initial program 52.6%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6469.3%
Simplified69.3%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6473.3%
Applied egg-rr73.3%
if -3.0500000000000001e-55 < c < 2.9e-68Initial program 74.5%
Taylor expanded in c around 0
/-lowering-/.f6469.6%
Simplified69.6%
(FPCore (a b c d) :precision binary64 (if (<= c -1.3e-53) (/ a c) (if (<= c 1.42e-67) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.3e-53) {
tmp = a / c;
} else if (c <= 1.42e-67) {
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 (c <= (-1.3d-53)) then
tmp = a / c
else if (c <= 1.42d-67) 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 (c <= -1.3e-53) {
tmp = a / c;
} else if (c <= 1.42e-67) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.3e-53: tmp = a / c elif c <= 1.42e-67: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.3e-53) tmp = Float64(a / c); elseif (c <= 1.42e-67) 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 (c <= -1.3e-53) tmp = a / c; elseif (c <= 1.42e-67) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.3e-53], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.42e-67], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.3 \cdot 10^{-53}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.42 \cdot 10^{-67}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.29999999999999998e-53 or 1.42000000000000004e-67 < c Initial program 52.6%
Taylor expanded in c around inf
/-lowering-/.f6462.6%
Simplified62.6%
if -1.29999999999999998e-53 < c < 1.42000000000000004e-67Initial program 74.5%
Taylor expanded in c around 0
/-lowering-/.f6469.6%
Simplified69.6%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 61.7%
Taylor expanded in c around inf
/-lowering-/.f6443.0%
Simplified43.0%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024160
(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))))