
(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 10 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 (- a) (/ d t_0) (* (/ c t_0) b))))
(if (<= c -6.2e+47)
(/ (fma (- a) (/ d c) b) c)
(if (<= c -1.26e-145)
t_1
(if (<= c 4.25e-103)
(/ (fma (/ c d) b (- a)) d)
(if (<= c 4.2e+126) t_1 (/ (- b (* d (/ a c))) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma(-a, (d / t_0), ((c / t_0) * b));
double tmp;
if (c <= -6.2e+47) {
tmp = fma(-a, (d / c), b) / c;
} else if (c <= -1.26e-145) {
tmp = t_1;
} else if (c <= 4.25e-103) {
tmp = fma((c / d), b, -a) / d;
} else if (c <= 4.2e+126) {
tmp = t_1;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(Float64(-a), Float64(d / t_0), Float64(Float64(c / t_0) * b)) tmp = 0.0 if (c <= -6.2e+47) tmp = Float64(fma(Float64(-a), Float64(d / c), b) / c); elseif (c <= -1.26e-145) tmp = t_1; elseif (c <= 4.25e-103) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); elseif (c <= 4.2e+126) tmp = t_1; else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / 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[((-a) * N[(d / t$95$0), $MachinePrecision] + N[(N[(c / t$95$0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -6.2e+47], N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.26e-145], t$95$1, If[LessEqual[c, 4.25e-103], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.2e+126], t$95$1, N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(-a, \frac{d}{t\_0}, \frac{c}{t\_0} \cdot b\right)\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{+47}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{elif}\;c \leq -1.26 \cdot 10^{-145}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 4.25 \cdot 10^{-103}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{elif}\;c \leq 4.2 \cdot 10^{+126}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -6.2000000000000001e47Initial program 43.7%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6478.5
Applied rewrites78.5%
Applied rewrites91.5%
if -6.2000000000000001e47 < c < -1.2599999999999999e-145 or 4.25000000000000016e-103 < c < 4.1999999999999998e126Initial program 75.3%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/l*N/A
Applied rewrites82.4%
if -1.2599999999999999e-145 < c < 4.25000000000000016e-103Initial program 64.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-*.f6493.5
Applied rewrites93.5%
Applied rewrites93.5%
if 4.1999999999999998e126 < c Initial program 33.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.5
Applied rewrites77.5%
Applied rewrites82.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.1e-139)
(/ (fma (- a) (/ d c) b) c)
(if (<= c 8.1e-103)
(/ (fma (/ c d) b (- a)) d)
(if (<= c 6e+120)
(/ (fma (- d) a (* b c)) (fma d d (* c c)))
(/ (- b (* d (/ a c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.1e-139) {
tmp = fma(-a, (d / c), b) / c;
} else if (c <= 8.1e-103) {
tmp = fma((c / d), b, -a) / d;
} else if (c <= 6e+120) {
tmp = fma(-d, a, (b * c)) / fma(d, d, (c * c));
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.1e-139) tmp = Float64(fma(Float64(-a), Float64(d / c), b) / c); elseif (c <= 8.1e-103) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); elseif (c <= 6e+120) tmp = Float64(fma(Float64(-d), a, Float64(b * c)) / fma(d, d, Float64(c * c))); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.1e-139], N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 8.1e-103], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6e+120], N[(N[((-d) * a + N[(b * c), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.1 \cdot 10^{-139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{elif}\;c \leq 8.1 \cdot 10^{-103}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{elif}\;c \leq 6 \cdot 10^{+120}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-d, a, b \cdot c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -1.10000000000000005e-139Initial program 52.0%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6468.3
Applied rewrites68.3%
Applied rewrites75.7%
if -1.10000000000000005e-139 < c < 8.09999999999999979e-103Initial program 64.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-*.f6493.5
Applied rewrites93.5%
Applied rewrites93.5%
if 8.09999999999999979e-103 < c < 6e120Initial program 85.4%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6485.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6485.4
Applied rewrites85.4%
if 6e120 < c Initial program 33.9%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.5
Applied rewrites77.5%
Applied rewrites82.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -2e+30)
(/ b c)
(if (<= c 5.5e-99)
(/ (- a) d)
(if (<= c 7.6e+62) (/ (- (* b c) (* a d)) (* c c)) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2e+30) {
tmp = b / c;
} else if (c <= 5.5e-99) {
tmp = -a / d;
} else if (c <= 7.6e+62) {
tmp = ((b * c) - (a * 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 <= (-2d+30)) then
tmp = b / c
else if (c <= 5.5d-99) then
tmp = -a / d
else if (c <= 7.6d+62) then
tmp = ((b * c) - (a * 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 <= -2e+30) {
tmp = b / c;
} else if (c <= 5.5e-99) {
tmp = -a / d;
} else if (c <= 7.6e+62) {
tmp = ((b * c) - (a * d)) / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2e+30: tmp = b / c elif c <= 5.5e-99: tmp = -a / d elif c <= 7.6e+62: tmp = ((b * c) - (a * d)) / (c * c) else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2e+30) tmp = Float64(b / c); elseif (c <= 5.5e-99) tmp = Float64(Float64(-a) / d); elseif (c <= 7.6e+62) tmp = Float64(Float64(Float64(b * c) - Float64(a * 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 <= -2e+30) tmp = b / c; elseif (c <= 5.5e-99) tmp = -a / d; elseif (c <= 7.6e+62) tmp = ((b * c) - (a * d)) / (c * c); else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2e+30], N[(b / c), $MachinePrecision], If[LessEqual[c, 5.5e-99], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 7.6e+62], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{+30}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 5.5 \cdot 10^{-99}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 7.6 \cdot 10^{+62}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2e30 or 7.59999999999999967e62 < c Initial program 45.1%
Taylor expanded in c around inf
lower-/.f6471.5
Applied rewrites71.5%
if -2e30 < c < 5.49999999999999991e-99Initial program 64.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.f6469.3
Applied rewrites69.3%
if 5.49999999999999991e-99 < c < 7.59999999999999967e62Initial program 85.6%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6467.6
Applied rewrites67.6%
Final simplification70.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -2e+30)
(/ b c)
(if (<= c 9.5e-101)
(/ (- a) d)
(if (<= c 6e+120) (/ (* c b) (fma d d (* c c))) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2e+30) {
tmp = b / c;
} else if (c <= 9.5e-101) {
tmp = -a / d;
} else if (c <= 6e+120) {
tmp = (c * b) / fma(d, d, (c * c));
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2e+30) tmp = Float64(b / c); elseif (c <= 9.5e-101) tmp = Float64(Float64(-a) / d); elseif (c <= 6e+120) tmp = Float64(Float64(c * b) / fma(d, d, Float64(c * c))); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2e+30], N[(b / c), $MachinePrecision], If[LessEqual[c, 9.5e-101], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 6e+120], N[(N[(c * b), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{+30}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 9.5 \cdot 10^{-101}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 6 \cdot 10^{+120}:\\
\;\;\;\;\frac{c \cdot b}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2e30 or 6e120 < c Initial program 41.1%
Taylor expanded in c around inf
lower-/.f6472.1
Applied rewrites72.1%
if -2e30 < c < 9.49999999999999994e-101Initial program 63.8%
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.f6469.6
Applied rewrites69.6%
if 9.49999999999999994e-101 < c < 6e120Initial program 85.1%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6485.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6485.1
Applied rewrites85.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f6465.4
Applied rewrites65.4%
Final simplification69.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2e+30) (not (<= c 2.05e-57))) (/ (- b (* d (/ a c))) c) (/ (- (/ (* b c) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2e+30) || !(c <= 2.05e-57)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((b * 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 ((c <= (-2d+30)) .or. (.not. (c <= 2.05d-57))) then
tmp = (b - (d * (a / c))) / c
else
tmp = (((b * 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 ((c <= -2e+30) || !(c <= 2.05e-57)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2e+30) or not (c <= 2.05e-57): tmp = (b - (d * (a / c))) / c else: tmp = (((b * c) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2e+30) || !(c <= 2.05e-57)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2e+30) || ~((c <= 2.05e-57))) tmp = (b - (d * (a / c))) / c; else tmp = (((b * c) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2e+30], N[Not[LessEqual[c, 2.05e-57]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{+30} \lor \neg \left(c \leq 2.05 \cdot 10^{-57}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2e30 or 2.0500000000000001e-57 < c Initial program 51.0%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6474.2
Applied rewrites74.2%
Applied rewrites80.7%
if -2e30 < c < 2.0500000000000001e-57Initial program 66.1%
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-*.f6483.1
Applied rewrites83.1%
Final simplification81.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6e-146) (not (<= c 5.5e-99))) (/ (- b (* d (/ a c))) c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6e-146) || !(c <= 5.5e-99)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = -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 ((c <= (-6d-146)) .or. (.not. (c <= 5.5d-99))) then
tmp = (b - (d * (a / c))) / c
else
tmp = -a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6e-146) || !(c <= 5.5e-99)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6e-146) or not (c <= 5.5e-99): tmp = (b - (d * (a / c))) / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6e-146) || !(c <= 5.5e-99)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6e-146) || ~((c <= 5.5e-99))) tmp = (b - (d * (a / c))) / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6e-146], N[Not[LessEqual[c, 5.5e-99]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6 \cdot 10^{-146} \lor \neg \left(c \leq 5.5 \cdot 10^{-99}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -6.00000000000000038e-146 or 5.49999999999999991e-99 < c Initial program 54.6%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6470.8
Applied rewrites70.8%
Applied rewrites74.2%
if -6.00000000000000038e-146 < c < 5.49999999999999991e-99Initial program 65.1%
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.f6476.8
Applied rewrites76.8%
Final simplification75.1%
(FPCore (a b c d) :precision binary64 (if (<= c -1.1e-139) (/ (fma (- a) (/ d c) b) c) (if (<= c 2.05e-57) (/ (fma (/ c d) b (- a)) d) (/ (- b (* d (/ a c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.1e-139) {
tmp = fma(-a, (d / c), b) / c;
} else if (c <= 2.05e-57) {
tmp = fma((c / d), b, -a) / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.1e-139) tmp = Float64(fma(Float64(-a), Float64(d / c), b) / c); elseif (c <= 2.05e-57) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.1e-139], N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.05e-57], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.1 \cdot 10^{-139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{elif}\;c \leq 2.05 \cdot 10^{-57}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -1.10000000000000005e-139Initial program 52.0%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6468.3
Applied rewrites68.3%
Applied rewrites75.7%
if -1.10000000000000005e-139 < c < 2.0500000000000001e-57Initial program 67.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-*.f6491.2
Applied rewrites91.2%
Applied rewrites91.2%
if 2.0500000000000001e-57 < c Initial program 53.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6473.2
Applied rewrites73.2%
Applied rewrites76.5%
(FPCore (a b c d) :precision binary64 (if (<= c -1.1e-139) (/ (fma (- a) (/ d c) b) c) (if (<= c 2.05e-57) (/ (- (/ (* b c) d) a) d) (/ (- b (* d (/ a c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.1e-139) {
tmp = fma(-a, (d / c), b) / c;
} else if (c <= 2.05e-57) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.1e-139) tmp = Float64(fma(Float64(-a), Float64(d / c), b) / c); elseif (c <= 2.05e-57) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.1e-139], N[(N[((-a) * N[(d / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.05e-57], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.1 \cdot 10^{-139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c}\\
\mathbf{elif}\;c \leq 2.05 \cdot 10^{-57}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -1.10000000000000005e-139Initial program 52.0%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6468.3
Applied rewrites68.3%
Applied rewrites75.7%
if -1.10000000000000005e-139 < c < 2.0500000000000001e-57Initial program 67.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-*.f6491.2
Applied rewrites91.2%
if 2.0500000000000001e-57 < c Initial program 53.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6473.2
Applied rewrites73.2%
Applied rewrites76.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2e+30) (not (<= c 6.5e-99))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2e+30) || !(c <= 6.5e-99)) {
tmp = b / c;
} else {
tmp = -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 ((c <= (-2d+30)) .or. (.not. (c <= 6.5d-99))) then
tmp = b / c
else
tmp = -a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2e+30) || !(c <= 6.5e-99)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2e+30) or not (c <= 6.5e-99): tmp = b / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2e+30) || !(c <= 6.5e-99)) tmp = Float64(b / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2e+30) || ~((c <= 6.5e-99))) tmp = b / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2e+30], N[Not[LessEqual[c, 6.5e-99]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2 \cdot 10^{+30} \lor \neg \left(c \leq 6.5 \cdot 10^{-99}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -2e30 or 6.50000000000000033e-99 < c Initial program 53.1%
Taylor expanded in c around inf
lower-/.f6467.1
Applied rewrites67.1%
if -2e30 < c < 6.50000000000000033e-99Initial program 64.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.f6469.3
Applied rewrites69.3%
Final simplification68.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 58.3%
Taylor expanded in c around inf
lower-/.f6442.4
Applied rewrites42.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 2024313
(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))))