
(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 9 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 (/ b d) (- a)) d)))
(if (<= d -1.05e+113)
t_1
(if (<= d -3.2e-120)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 6.6e-71)
(/ (- b (/ (* a d) c)) c)
(if (<= d 7e+102) (fma (/ c t_0) b (* (- d) (/ a t_0))) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -1.05e+113) {
tmp = t_1;
} else if (d <= -3.2e-120) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 6.6e-71) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 7e+102) {
tmp = fma((c / t_0), b, (-d * (a / t_0)));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -1.05e+113) tmp = t_1; elseif (d <= -3.2e-120) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 6.6e-71) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 7e+102) tmp = fma(Float64(c / t_0), b, Float64(Float64(-d) * Float64(a / t_0))); else tmp = t_1; 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 * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.05e+113], t$95$1, If[LessEqual[d, -3.2e-120], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.6e-71], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7e+102], N[(N[(c / t$95$0), $MachinePrecision] * b + N[((-d) * N[(a / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -3.2 \cdot 10^{-120}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 6.6 \cdot 10^{-71}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t\_0}, b, \left(-d\right) \cdot \frac{a}{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.0499999999999999e113 or 7.00000000000000021e102 < d Initial program 43.0%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f648.6
Applied rewrites8.6%
Applied rewrites13.5%
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
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.7
Applied rewrites91.7%
if -1.0499999999999999e113 < d < -3.1999999999999999e-120Initial program 82.5%
if -3.1999999999999999e-120 < d < 6.6000000000000003e-71Initial program 71.5%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6496.3
Applied rewrites96.3%
if 6.6000000000000003e-71 < d < 7.00000000000000021e102Initial program 79.1%
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 rewrites87.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(t_1 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -1.05e+113)
t_1
(if (<= d -3.2e-120)
t_0
(if (<= d 6.6e-71)
(/ (- b (/ (* a d) c)) c)
(if (<= d 8e+83) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = fma(c, (b / d), -a) / d;
double tmp;
if (d <= -1.05e+113) {
tmp = t_1;
} else if (d <= -3.2e-120) {
tmp = t_0;
} else if (d <= 6.6e-71) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 8e+83) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(fma(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -1.05e+113) tmp = t_1; elseif (d <= -3.2e-120) tmp = t_0; elseif (d <= 6.6e-71) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 8e+83) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.05e+113], t$95$1, If[LessEqual[d, -3.2e-120], t$95$0, If[LessEqual[d, 6.6e-71], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 8e+83], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -3.2 \cdot 10^{-120}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 6.6 \cdot 10^{-71}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.0499999999999999e113 or 8.00000000000000025e83 < d Initial program 44.1%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f649.5
Applied rewrites9.5%
Applied rewrites15.2%
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
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6490.0
Applied rewrites90.0%
if -1.0499999999999999e113 < d < -3.1999999999999999e-120 or 6.6000000000000003e-71 < d < 8.00000000000000025e83Initial program 82.2%
if -3.1999999999999999e-120 < d < 6.6000000000000003e-71Initial program 71.5%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6496.3
Applied rewrites96.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -4.5e-36)
t_0
(if (<= d 1.25e-123)
(/ b c)
(if (<= d 3.45e+143) (* (- a) (/ d (fma d d (* c c)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -4.5e-36) {
tmp = t_0;
} else if (d <= 1.25e-123) {
tmp = b / c;
} else if (d <= 3.45e+143) {
tmp = -a * (d / fma(d, d, (c * c)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -4.5e-36) tmp = t_0; elseif (d <= 1.25e-123) tmp = Float64(b / c); elseif (d <= 3.45e+143) tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -4.5e-36], t$95$0, If[LessEqual[d, 1.25e-123], N[(b / c), $MachinePrecision], If[LessEqual[d, 3.45e+143], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -4.5 \cdot 10^{-36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{-123}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 3.45 \cdot 10^{+143}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.50000000000000024e-36 or 3.44999999999999995e143 < d Initial program 50.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.f6478.0
Applied rewrites78.0%
if -4.50000000000000024e-36 < d < 1.25000000000000007e-123Initial program 74.7%
Taylor expanded in c around inf
lower-/.f6476.6
Applied rewrites76.6%
if 1.25000000000000007e-123 < d < 3.44999999999999995e143Initial program 76.7%
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-*.f6460.8
Applied rewrites60.8%
Final simplification73.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.45e-21) (not (<= d 1.66e-65))) (/ (fma c (/ b d) (- a)) d) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.45e-21) || !(d <= 1.66e-65)) {
tmp = fma(c, (b / d), -a) / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.45e-21) || !(d <= 1.66e-65)) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.45e-21], N[Not[LessEqual[d, 1.66e-65]], $MachinePrecision]], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.45 \cdot 10^{-21} \lor \neg \left(d \leq 1.66 \cdot 10^{-65}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.45e-21 or 1.6599999999999999e-65 < d Initial program 59.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6421.4
Applied rewrites21.4%
Applied rewrites25.5%
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
sub-negN/A
*-commutativeN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6478.9
Applied rewrites78.9%
if -1.45e-21 < d < 1.6599999999999999e-65Initial program 73.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6491.9
Applied rewrites91.9%
Final simplification84.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.45e-21) (not (<= d 1.66e-65))) (/ (- (/ (* b c) d) a) d) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.45e-21) || !(d <= 1.66e-65)) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.45d-21)) .or. (.not. (d <= 1.66d-65))) then
tmp = (((b * c) / d) - a) / d
else
tmp = (b - ((a * d) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.45e-21) || !(d <= 1.66e-65)) {
tmp = (((b * c) / d) - a) / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.45e-21) or not (d <= 1.66e-65): tmp = (((b * c) / d) - a) / d else: tmp = (b - ((a * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.45e-21) || !(d <= 1.66e-65)) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.45e-21) || ~((d <= 1.66e-65))) tmp = (((b * c) / d) - a) / d; else tmp = (b - ((a * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.45e-21], N[Not[LessEqual[d, 1.66e-65]], $MachinePrecision]], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.45 \cdot 10^{-21} \lor \neg \left(d \leq 1.66 \cdot 10^{-65}\right):\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.45e-21 or 1.6599999999999999e-65 < d Initial program 59.2%
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-*.f6476.0
Applied rewrites76.0%
if -1.45e-21 < d < 1.6599999999999999e-65Initial program 73.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6491.9
Applied rewrites91.9%
Final simplification83.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.5e-11) (not (<= d 5e+51))) (/ (- a) d) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.5e-11) || !(d <= 5e+51)) {
tmp = -a / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-9.5d-11)) .or. (.not. (d <= 5d+51))) then
tmp = -a / d
else
tmp = (b - ((a * d) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.5e-11) || !(d <= 5e+51)) {
tmp = -a / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.5e-11) or not (d <= 5e+51): tmp = -a / d else: tmp = (b - ((a * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.5e-11) || !(d <= 5e+51)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -9.5e-11) || ~((d <= 5e+51))) tmp = -a / d; else tmp = (b - ((a * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.5e-11], N[Not[LessEqual[d, 5e+51]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.5 \cdot 10^{-11} \lor \neg \left(d \leq 5 \cdot 10^{+51}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -9.49999999999999951e-11 or 5e51 < d Initial program 53.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.f6478.2
Applied rewrites78.2%
if -9.49999999999999951e-11 < d < 5e51Initial program 75.8%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6482.1
Applied rewrites82.1%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.5e-11) (not (<= d 1.75e+84))) (/ (- a) d) (/ (- b (* d (/ a c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.5e-11) || !(d <= 1.75e+84)) {
tmp = -a / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-9.5d-11)) .or. (.not. (d <= 1.75d+84))) then
tmp = -a / d
else
tmp = (b - (d * (a / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.5e-11) || !(d <= 1.75e+84)) {
tmp = -a / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -9.5e-11) or not (d <= 1.75e+84): tmp = -a / d else: tmp = (b - (d * (a / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.5e-11) || !(d <= 1.75e+84)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -9.5e-11) || ~((d <= 1.75e+84))) tmp = -a / d; else tmp = (b - (d * (a / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.5e-11], N[Not[LessEqual[d, 1.75e+84]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.5 \cdot 10^{-11} \lor \neg \left(d \leq 1.75 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if d < -9.49999999999999951e-11 or 1.7499999999999999e84 < d Initial program 52.7%
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.f6479.8
Applied rewrites79.8%
if -9.49999999999999951e-11 < d < 1.7499999999999999e84Initial program 75.2%
Taylor expanded in c around inf
lower-/.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6480.8
Applied rewrites80.8%
Applied rewrites80.2%
Final simplification80.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.5e-36) (not (<= d 9.2e-104))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.5e-36) || !(d <= 9.2e-104)) {
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 ((d <= (-4.5d-36)) .or. (.not. (d <= 9.2d-104))) 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 ((d <= -4.5e-36) || !(d <= 9.2e-104)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.5e-36) or not (d <= 9.2e-104): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.5e-36) || !(d <= 9.2e-104)) 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 ((d <= -4.5e-36) || ~((d <= 9.2e-104))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.5e-36], N[Not[LessEqual[d, 9.2e-104]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.5 \cdot 10^{-36} \lor \neg \left(d \leq 9.2 \cdot 10^{-104}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -4.50000000000000024e-36 or 9.1999999999999998e-104 < d Initial program 59.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.f6467.2
Applied rewrites67.2%
if -4.50000000000000024e-36 < d < 9.1999999999999998e-104Initial program 75.0%
Taylor expanded in c around inf
lower-/.f6476.9
Applied rewrites76.9%
Final simplification70.9%
(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 65.7%
Taylor expanded in c around inf
lower-/.f6441.8
Applied rewrites41.8%
(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 2024325
(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))))