
(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 7 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 d d (* c c))) (t_1 (fma (/ c t_0) b (* (/ a t_0) (- d)))))
(if (<= c -4e+150)
(/ (- b (/ (* d a) c)) c)
(if (<= c -9e+19)
t_1
(if (<= c 6.8e-10)
(/ (- (/ (* b c) d) a) d)
(if (<= c 2.5e+132) t_1 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma((c / t_0), b, ((a / t_0) * -d));
double tmp;
if (c <= -4e+150) {
tmp = (b - ((d * a) / c)) / c;
} else if (c <= -9e+19) {
tmp = t_1;
} else if (c <= 6.8e-10) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 2.5e+132) {
tmp = t_1;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(Float64(c / t_0), b, Float64(Float64(a / t_0) * Float64(-d))) tmp = 0.0 if (c <= -4e+150) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (c <= -9e+19) tmp = t_1; elseif (c <= 6.8e-10) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 2.5e+132) tmp = t_1; else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / t$95$0), $MachinePrecision] * b + N[(N[(a / t$95$0), $MachinePrecision] * (-d)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4e+150], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -9e+19], t$95$1, If[LessEqual[c, 6.8e-10], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.5e+132], t$95$1, N[(b / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(\frac{c}{t\_0}, b, \frac{a}{t\_0} \cdot \left(-d\right)\right)\\
\mathbf{if}\;c \leq -4 \cdot 10^{+150}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;c \leq -9 \cdot 10^{+19}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{-10}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 2.5 \cdot 10^{+132}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -3.99999999999999992e150Initial program 35.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6495.5
Applied rewrites95.5%
if -3.99999999999999992e150 < c < -9e19 or 6.8000000000000003e-10 < c < 2.5000000000000001e132Initial program 79.9%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
Applied rewrites84.9%
if -9e19 < c < 6.8000000000000003e-10Initial program 70.6%
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-*.f6489.9
Applied rewrites89.9%
if 2.5000000000000001e132 < c Initial program 35.7%
Taylor expanded in c around inf
lower-/.f6493.8
Applied rewrites93.8%
Final simplification89.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.38e+20)
(/ (- b (/ (* d a) c)) c)
(if (<= c 7.2e-59)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.9e+132)
(/ (- (* b c) (* d a)) (+ (* d d) (* c c)))
(/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.38e+20) {
tmp = (b - ((d * a) / c)) / c;
} else if (c <= 7.2e-59) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.9e+132) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} 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 <= (-1.38d+20)) then
tmp = (b - ((d * a) / c)) / c
else if (c <= 7.2d-59) then
tmp = (((b * c) / d) - a) / d
else if (c <= 1.9d+132) then
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c))
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 <= -1.38e+20) {
tmp = (b - ((d * a) / c)) / c;
} else if (c <= 7.2e-59) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.9e+132) {
tmp = ((b * c) - (d * a)) / ((d * d) + (c * c));
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.38e+20: tmp = (b - ((d * a) / c)) / c elif c <= 7.2e-59: tmp = (((b * c) / d) - a) / d elif c <= 1.9e+132: tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)) else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.38e+20) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (c <= 7.2e-59) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.9e+132) tmp = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.38e+20) tmp = (b - ((d * a) / c)) / c; elseif (c <= 7.2e-59) tmp = (((b * c) / d) - a) / d; elseif (c <= 1.9e+132) tmp = ((b * c) - (d * a)) / ((d * d) + (c * c)); else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.38e+20], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 7.2e-59], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.9e+132], N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.38 \cdot 10^{+20}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{-59}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+132}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.38e20Initial program 64.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6484.0
Applied rewrites84.0%
if -1.38e20 < c < 7.20000000000000001e-59Initial program 69.9%
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-*.f6491.8
Applied rewrites91.8%
if 7.20000000000000001e-59 < c < 1.90000000000000003e132Initial program 77.1%
if 1.90000000000000003e132 < c Initial program 35.7%
Taylor expanded in c around inf
lower-/.f6493.8
Applied rewrites93.8%
Final simplification87.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* d a)) (* c c))))
(if (<= c -1.22e+178)
(/ b c)
(if (<= c -9.8e+19)
t_0
(if (<= c 1.05e-8) (/ a (- d)) (if (<= c 1e+130) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / (c * c);
double tmp;
if (c <= -1.22e+178) {
tmp = b / c;
} else if (c <= -9.8e+19) {
tmp = t_0;
} else if (c <= 1.05e-8) {
tmp = a / -d;
} else if (c <= 1e+130) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((b * c) - (d * a)) / (c * c)
if (c <= (-1.22d+178)) then
tmp = b / c
else if (c <= (-9.8d+19)) then
tmp = t_0
else if (c <= 1.05d-8) then
tmp = a / -d
else if (c <= 1d+130) then
tmp = t_0
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (d * a)) / (c * c);
double tmp;
if (c <= -1.22e+178) {
tmp = b / c;
} else if (c <= -9.8e+19) {
tmp = t_0;
} else if (c <= 1.05e-8) {
tmp = a / -d;
} else if (c <= 1e+130) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (d * a)) / (c * c) tmp = 0 if c <= -1.22e+178: tmp = b / c elif c <= -9.8e+19: tmp = t_0 elif c <= 1.05e-8: tmp = a / -d elif c <= 1e+130: tmp = t_0 else: tmp = b / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(d * a)) / Float64(c * c)) tmp = 0.0 if (c <= -1.22e+178) tmp = Float64(b / c); elseif (c <= -9.8e+19) tmp = t_0; elseif (c <= 1.05e-8) tmp = Float64(a / Float64(-d)); elseif (c <= 1e+130) tmp = t_0; else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (d * a)) / (c * c); tmp = 0.0; if (c <= -1.22e+178) tmp = b / c; elseif (c <= -9.8e+19) tmp = t_0; elseif (c <= 1.05e-8) tmp = a / -d; elseif (c <= 1e+130) tmp = t_0; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.22e+178], N[(b / c), $MachinePrecision], If[LessEqual[c, -9.8e+19], t$95$0, If[LessEqual[c, 1.05e-8], N[(a / (-d)), $MachinePrecision], If[LessEqual[c, 1e+130], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - d \cdot a}{c \cdot c}\\
\mathbf{if}\;c \leq -1.22 \cdot 10^{+178}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -9.8 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-8}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{elif}\;c \leq 10^{+130}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.2199999999999999e178 or 1.0000000000000001e130 < c Initial program 31.7%
Taylor expanded in c around inf
lower-/.f6492.2
Applied rewrites92.2%
if -1.2199999999999999e178 < c < -9.8e19 or 1.04999999999999997e-8 < c < 1.0000000000000001e130Initial program 80.8%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6470.8
Applied rewrites70.8%
if -9.8e19 < c < 1.04999999999999997e-8Initial program 70.6%
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%
Final simplification76.6%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- b (/ (* d a) c)) c))) (if (<= c -1.38e+20) t_0 (if (<= c 4e+26) (/ (- (/ (* 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 <= -1.38e+20) {
tmp = t_0;
} else if (c <= 4e+26) {
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 <= (-1.38d+20)) then
tmp = t_0
else if (c <= 4d+26) 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 <= -1.38e+20) {
tmp = t_0;
} else if (c <= 4e+26) {
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 <= -1.38e+20: tmp = t_0 elif c <= 4e+26: 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 <= -1.38e+20) tmp = t_0; elseif (c <= 4e+26) 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 <= -1.38e+20) tmp = t_0; elseif (c <= 4e+26) 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, -1.38e+20], t$95$0, If[LessEqual[c, 4e+26], 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 -1.38 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4 \cdot 10^{+26}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.38e20 or 4.00000000000000019e26 < c Initial program 60.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.8
Applied rewrites83.8%
if -1.38e20 < c < 4.00000000000000019e26Initial program 69.6%
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.9
Applied rewrites87.9%
Final simplification86.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- b (/ (* d a) c)) c))) (if (<= c -9.8e+19) t_0 (if (<= c 1.05e-8) (/ 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 <= -9.8e+19) {
tmp = t_0;
} else if (c <= 1.05e-8) {
tmp = 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 <= (-9.8d+19)) then
tmp = t_0
else if (c <= 1.05d-8) then
tmp = 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 <= -9.8e+19) {
tmp = t_0;
} else if (c <= 1.05e-8) {
tmp = 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 <= -9.8e+19: tmp = t_0 elif c <= 1.05e-8: tmp = 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 <= -9.8e+19) tmp = t_0; elseif (c <= 1.05e-8) tmp = Float64(a / Float64(-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 <= -9.8e+19) tmp = t_0; elseif (c <= 1.05e-8) tmp = 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, -9.8e+19], t$95$0, If[LessEqual[c, 1.05e-8], N[(a / (-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 -9.8 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-8}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -9.8e19 or 1.04999999999999997e-8 < c Initial program 60.3%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6481.5
Applied rewrites81.5%
if -9.8e19 < c < 1.04999999999999997e-8Initial program 70.6%
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%
Final simplification77.4%
(FPCore (a b c d) :precision binary64 (if (<= c -1.38e+20) (/ b c) (if (<= c 4e+26) (/ a (- d)) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.38e+20) {
tmp = b / c;
} else if (c <= 4e+26) {
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 <= (-1.38d+20)) then
tmp = b / c
else if (c <= 4d+26) 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 <= -1.38e+20) {
tmp = b / c;
} else if (c <= 4e+26) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.38e+20: tmp = b / c elif c <= 4e+26: tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.38e+20) tmp = Float64(b / c); elseif (c <= 4e+26) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.38e+20) tmp = b / c; elseif (c <= 4e+26) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.38e+20], N[(b / c), $MachinePrecision], If[LessEqual[c, 4e+26], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.38 \cdot 10^{+20}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{+26}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.38e20 or 4.00000000000000019e26 < c Initial program 60.9%
Taylor expanded in c around inf
lower-/.f6470.4
Applied rewrites70.4%
if -1.38e20 < c < 4.00000000000000019e26Initial program 69.6%
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.f6472.3
Applied rewrites72.3%
(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 66.0%
Taylor expanded in c around inf
lower-/.f6437.6
Applied rewrites37.6%
(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 2024327
(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))))