
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \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 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) (/ d c) b) c)))
(if (<= c -2.7e+83)
t_0
(if (<= c 1e-133)
(/ (- (/ (* b c) d) a) d)
(if (<= c 3.2e+155) (/ (- (* b c) (* d a)) (+ (* d d) (* c c))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, (d / c), b) / c;
double tmp;
if (c <= -2.7e+83) {
tmp = t_0;
} else if (c <= 1e-133) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 3.2e+155) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), Float64(d / c), b) / c) tmp = 0.0 if (c <= -2.7e+83) tmp = t_0; elseif (c <= 1e-133) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 3.2e+155) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.7e+83], t$95$0, If[LessEqual[c, 1e-133], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.2e+155], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 10^{-133}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{+155}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.70000000000000007e83 or 3.20000000000000012e155 < c Initial program 41.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.1
Applied rewrites85.1%
Applied rewrites89.1%
if -2.70000000000000007e83 < c < 1.0000000000000001e-133Initial program 73.4%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6487.7
Applied rewrites87.7%
if 1.0000000000000001e-133 < c < 3.20000000000000012e155Initial program 72.7%
Final simplification84.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (* (/ d (fma d d (* c c))) (- a))))
(if (<= d -1.25e+157)
t_0
(if (<= d -4e-59)
t_1
(if (<= d 1850000000.0)
(/ (- b (/ (* d a) c)) c)
(if (<= d 7e+158) t_1 t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double t_1 = (d / fma(d, d, (c * c))) * -a;
double tmp;
if (d <= -1.25e+157) {
tmp = t_0;
} else if (d <= -4e-59) {
tmp = t_1;
} else if (d <= 1850000000.0) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 7e+158) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) t_1 = Float64(Float64(d / fma(d, d, Float64(c * c))) * Float64(-a)) tmp = 0.0 if (d <= -1.25e+157) tmp = t_0; elseif (d <= -4e-59) tmp = t_1; elseif (d <= 1850000000.0) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 7e+158) tmp = t_1; else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]}, If[LessEqual[d, -1.25e+157], t$95$0, If[LessEqual[d, -4e-59], t$95$1, If[LessEqual[d, 1850000000.0], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7e+158], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \left(-a\right)\\
\mathbf{if}\;d \leq -1.25 \cdot 10^{+157}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4 \cdot 10^{-59}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 1850000000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+158}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.24999999999999994e157 or 7.0000000000000003e158 < d Initial program 35.3%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6484.5
Applied rewrites84.5%
if -1.24999999999999994e157 < d < -4.0000000000000001e-59 or 1.85e9 < d < 7.0000000000000003e158Initial program 75.2%
Taylor expanded in a around inf
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6468.3
Applied rewrites68.3%
if -4.0000000000000001e-59 < d < 1.85e9Initial program 70.6%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.2
Applied rewrites86.2%
Final simplification80.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (* (/ d (fma d d (* c c))) (- a))))
(if (<= d -1.25e+157)
t_0
(if (<= d -6.5e-179)
t_1
(if (<= d 3.8e-49) (/ b c) (if (<= d 7e+158) t_1 t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double t_1 = (d / fma(d, d, (c * c))) * -a;
double tmp;
if (d <= -1.25e+157) {
tmp = t_0;
} else if (d <= -6.5e-179) {
tmp = t_1;
} else if (d <= 3.8e-49) {
tmp = b / c;
} else if (d <= 7e+158) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) t_1 = Float64(Float64(d / fma(d, d, Float64(c * c))) * Float64(-a)) tmp = 0.0 if (d <= -1.25e+157) tmp = t_0; elseif (d <= -6.5e-179) tmp = t_1; elseif (d <= 3.8e-49) tmp = Float64(b / c); elseif (d <= 7e+158) tmp = t_1; else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]}, If[LessEqual[d, -1.25e+157], t$95$0, If[LessEqual[d, -6.5e-179], t$95$1, If[LessEqual[d, 3.8e-49], N[(b / c), $MachinePrecision], If[LessEqual[d, 7e+158], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \left(-a\right)\\
\mathbf{if}\;d \leq -1.25 \cdot 10^{+157}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -6.5 \cdot 10^{-179}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 3.8 \cdot 10^{-49}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+158}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.24999999999999994e157 or 7.0000000000000003e158 < d Initial program 35.3%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6484.5
Applied rewrites84.5%
if -1.24999999999999994e157 < d < -6.49999999999999996e-179 or 3.7999999999999997e-49 < d < 7.0000000000000003e158Initial program 74.2%
Taylor expanded in a around inf
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.9
Applied rewrites64.9%
if -6.49999999999999996e-179 < d < 3.7999999999999997e-49Initial program 70.0%
Taylor expanded in c around inf
lower-/.f6477.8
Applied rewrites77.8%
Final simplification74.2%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.5e+80)
(/ b c)
(if (<= c 6.4e-134)
(/ (- a) d)
(if (<= c 3.2e+155) (* (/ c (fma d d (* c c))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.5e+80) {
tmp = b / c;
} else if (c <= 6.4e-134) {
tmp = -a / d;
} else if (c <= 3.2e+155) {
tmp = (c / fma(d, d, (c * c))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.5e+80) tmp = Float64(b / c); elseif (c <= 6.4e-134) tmp = Float64(Float64(-a) / d); elseif (c <= 3.2e+155) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.5e+80], N[(b / c), $MachinePrecision], If[LessEqual[c, 6.4e-134], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 3.2e+155], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.5 \cdot 10^{+80}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 6.4 \cdot 10^{-134}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{+155}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.4999999999999998e80 or 3.20000000000000012e155 < c Initial program 41.2%
Taylor expanded in c around inf
lower-/.f6479.5
Applied rewrites79.5%
if -2.4999999999999998e80 < c < 6.4000000000000003e-134Initial program 73.4%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6474.1
Applied rewrites74.1%
if 6.4000000000000003e-134 < c < 3.20000000000000012e155Initial program 72.7%
Taylor expanded in a around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6457.3
Applied rewrites57.3%
Final simplification72.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) (/ d c) b) c)))
(if (<= c -2.7e+83)
t_0
(if (<= c 1.05e-46) (/ (- (/ (* b c) d) a) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, (d / c), b) / c;
double tmp;
if (c <= -2.7e+83) {
tmp = t_0;
} else if (c <= 1.05e-46) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), Float64(d / c), b) / c) tmp = 0.0 if (c <= -2.7e+83) tmp = t_0; elseif (c <= 1.05e-46) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.7e+83], t$95$0, If[LessEqual[c, 1.05e-46], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-46}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.70000000000000007e83 or 1.04999999999999994e-46 < c Initial program 50.6%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6476.3
Applied rewrites76.3%
Applied rewrites79.0%
if -2.70000000000000007e83 < c < 1.04999999999999994e-46Initial program 74.4%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.8
Applied rewrites85.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (/ (* d a) c)) c)))
(if (<= c -2.7e+83)
t_0
(if (<= c 1.05e-46) (/ (- (/ (* b c) d) a) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((d * a) / c)) / c;
double tmp;
if (c <= -2.7e+83) {
tmp = t_0;
} else if (c <= 1.05e-46) {
tmp = (((b * c) / d) - a) / 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 = (b - ((d * a) / c)) / c
if (c <= (-2.7d+83)) then
tmp = t_0
else if (c <= 1.05d-46) then
tmp = (((b * c) / d) - a) / 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 = (b - ((d * a) / c)) / c;
double tmp;
if (c <= -2.7e+83) {
tmp = t_0;
} else if (c <= 1.05e-46) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - ((d * a) / c)) / c tmp = 0 if c <= -2.7e+83: tmp = t_0 elif c <= 1.05e-46: tmp = (((b * c) / d) - a) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(Float64(d * a) / c)) / c) tmp = 0.0 if (c <= -2.7e+83) tmp = t_0; elseif (c <= 1.05e-46) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b - ((d * a) / c)) / c; tmp = 0.0; if (c <= -2.7e+83) tmp = t_0; elseif (c <= 1.05e-46) tmp = (((b * c) / d) - a) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.7e+83], t$95$0, If[LessEqual[c, 1.05e-46], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-46}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.70000000000000007e83 or 1.04999999999999994e-46 < c Initial program 50.6%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6476.3
Applied rewrites76.3%
if -2.70000000000000007e83 < c < 1.04999999999999994e-46Initial program 74.4%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6485.8
Applied rewrites85.8%
Final simplification81.2%
(FPCore (a b c d) :precision binary64 (if (<= c -2.5e+80) (/ b c) (if (<= c 5e-47) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.5e+80) {
tmp = b / c;
} else if (c <= 5e-47) {
tmp = -a / d;
} else {
tmp = b / 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 <= (-2.5d+80)) then
tmp = b / c
else if (c <= 5d-47) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.5e+80) {
tmp = b / c;
} else if (c <= 5e-47) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.5e+80: tmp = b / c elif c <= 5e-47: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.5e+80) tmp = Float64(b / c); elseif (c <= 5e-47) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2.5e+80) tmp = b / c; elseif (c <= 5e-47) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.5e+80], N[(b / c), $MachinePrecision], If[LessEqual[c, 5e-47], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.5 \cdot 10^{+80}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{-47}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.4999999999999998e80 or 5.00000000000000011e-47 < c Initial program 50.6%
Taylor expanded in c around inf
lower-/.f6468.9
Applied rewrites68.9%
if -2.4999999999999998e80 < c < 5.00000000000000011e-47Initial program 74.4%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6471.3
Applied rewrites71.3%
Final simplification70.1%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / 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 = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 62.8%
Taylor expanded in c around inf
lower-/.f6444.4
Applied rewrites44.4%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (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(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * 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 = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * 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{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024298
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))