
(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
(if (<= d -4e+43)
(/ (- (* c (/ b d)) a) d)
(if (<= d -3.8e-132)
(/ (fma b c (* d (- a))) (fma d d (* c c)))
(if (<= d 1.16e-157)
(/ (- b (/ (* d a) c)) c)
(if (<= d 1.8e+91)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(/ (- (/ 1.0 (/ (/ d b) c)) a) d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e+43) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -3.8e-132) {
tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
} else if (d <= 1.16e-157) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 1.8e+91) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = ((1.0 / ((d / b) / c)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -4e+43) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= -3.8e-132) tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c))); elseif (d <= 1.16e-157) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 1.8e+91) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(Float64(1.0 / Float64(Float64(d / b) / c)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e+43], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3.8e-132], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.16e-157], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+91], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / N[(N[(d / b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{+43}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq -3.8 \cdot 10^{-132}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 1.16 \cdot 10^{-157}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+91}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{\frac{d}{b}}{c}} - a}{d}\\
\end{array}
\end{array}
if d < -4.00000000000000006e43Initial program 57.1%
fma-neg57.1%
distribute-rgt-neg-out57.1%
+-commutative57.1%
fma-define57.1%
Simplified57.1%
Taylor expanded in c around 0 89.9%
+-commutative89.9%
mul-1-neg89.9%
unsub-neg89.9%
unpow289.9%
associate-/r*89.0%
div-sub89.0%
*-commutative89.0%
associate-/l*94.8%
Simplified94.8%
if -4.00000000000000006e43 < d < -3.7999999999999997e-132Initial program 84.7%
fma-neg84.7%
distribute-rgt-neg-out84.7%
+-commutative84.7%
fma-define84.7%
Simplified84.7%
if -3.7999999999999997e-132 < d < 1.15999999999999992e-157Initial program 61.8%
fma-neg61.8%
distribute-rgt-neg-out61.8%
+-commutative61.8%
fma-define61.8%
Simplified61.8%
Taylor expanded in c around inf 90.6%
mul-1-neg90.6%
unsub-neg90.6%
*-commutative90.6%
associate-/l*89.6%
Simplified89.6%
associate-*r/90.6%
Applied egg-rr90.6%
if 1.15999999999999992e-157 < d < 1.8e91Initial program 79.8%
if 1.8e91 < d Initial program 39.3%
fma-neg39.3%
distribute-rgt-neg-out39.3%
+-commutative39.3%
fma-define39.3%
Simplified39.3%
Taylor expanded in d around inf 77.6%
clear-num77.6%
inv-pow77.6%
Applied egg-rr77.6%
unpow-177.6%
associate-/r*77.8%
Simplified77.8%
Final simplification86.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= d -2.9e+43)
(/ (- (* c (/ b d)) a) d)
(if (<= d -9.8e-131)
t_0
(if (<= d 1.05e-157)
(/ (- b (/ (* d a) c)) c)
(if (<= d 2.5e+91) t_0 (/ (- (/ 1.0 (/ (/ d b) c)) a) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (d <= -2.9e+43) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -9.8e-131) {
tmp = t_0;
} else if (d <= 1.05e-157) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 2.5e+91) {
tmp = t_0;
} else {
tmp = ((1.0 / ((d / b) / c)) - 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) :: t_0
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
if (d <= (-2.9d+43)) then
tmp = ((c * (b / d)) - a) / d
else if (d <= (-9.8d-131)) then
tmp = t_0
else if (d <= 1.05d-157) then
tmp = (b - ((d * a) / c)) / c
else if (d <= 2.5d+91) then
tmp = t_0
else
tmp = ((1.0d0 / ((d / b) / c)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (d <= -2.9e+43) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -9.8e-131) {
tmp = t_0;
} else if (d <= 1.05e-157) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 2.5e+91) {
tmp = t_0;
} else {
tmp = ((1.0 / ((d / b) / c)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if d <= -2.9e+43: tmp = ((c * (b / d)) - a) / d elif d <= -9.8e-131: tmp = t_0 elif d <= 1.05e-157: tmp = (b - ((d * a) / c)) / c elif d <= 2.5e+91: tmp = t_0 else: tmp = ((1.0 / ((d / b) / c)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -2.9e+43) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= -9.8e-131) tmp = t_0; elseif (d <= 1.05e-157) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 2.5e+91) tmp = t_0; else tmp = Float64(Float64(Float64(1.0 / Float64(Float64(d / b) / c)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -2.9e+43) tmp = ((c * (b / d)) - a) / d; elseif (d <= -9.8e-131) tmp = t_0; elseif (d <= 1.05e-157) tmp = (b - ((d * a) / c)) / c; elseif (d <= 2.5e+91) tmp = t_0; else tmp = ((1.0 / ((d / b) / c)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.9e+43], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -9.8e-131], t$95$0, If[LessEqual[d, 1.05e-157], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.5e+91], t$95$0, N[(N[(N[(1.0 / N[(N[(d / b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -2.9 \cdot 10^{+43}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq -9.8 \cdot 10^{-131}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.05 \cdot 10^{-157}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 2.5 \cdot 10^{+91}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{\frac{d}{b}}{c}} - a}{d}\\
\end{array}
\end{array}
if d < -2.9000000000000002e43Initial program 57.1%
fma-neg57.1%
distribute-rgt-neg-out57.1%
+-commutative57.1%
fma-define57.1%
Simplified57.1%
Taylor expanded in c around 0 89.9%
+-commutative89.9%
mul-1-neg89.9%
unsub-neg89.9%
unpow289.9%
associate-/r*89.0%
div-sub89.0%
*-commutative89.0%
associate-/l*94.8%
Simplified94.8%
if -2.9000000000000002e43 < d < -9.8000000000000004e-131 or 1.05e-157 < d < 2.5000000000000001e91Initial program 82.1%
if -9.8000000000000004e-131 < d < 1.05e-157Initial program 61.8%
fma-neg61.8%
distribute-rgt-neg-out61.8%
+-commutative61.8%
fma-define61.8%
Simplified61.8%
Taylor expanded in c around inf 90.6%
mul-1-neg90.6%
unsub-neg90.6%
*-commutative90.6%
associate-/l*89.6%
Simplified89.6%
associate-*r/90.6%
Applied egg-rr90.6%
if 2.5000000000000001e91 < d Initial program 39.3%
fma-neg39.3%
distribute-rgt-neg-out39.3%
+-commutative39.3%
fma-define39.3%
Simplified39.3%
Taylor expanded in d around inf 77.6%
clear-num77.6%
inv-pow77.6%
Applied egg-rr77.6%
unpow-177.6%
associate-/r*77.8%
Simplified77.8%
Final simplification86.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.05e+40) (not (<= d 2600000000.0))) (/ (- (* c (/ b d)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.05e+40) || !(d <= 2600000000.0)) {
tmp = ((c * (b / d)) - 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 <= (-1.05d+40)) .or. (.not. (d <= 2600000000.0d0))) then
tmp = ((c * (b / d)) - 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 <= -1.05e+40) || !(d <= 2600000000.0)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.05e+40) or not (d <= 2600000000.0): tmp = ((c * (b / d)) - a) / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.05e+40) || !(d <= 2600000000.0)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.05e+40) || ~((d <= 2600000000.0))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e+40], N[Not[LessEqual[d, 2600000000.0]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+40} \lor \neg \left(d \leq 2600000000\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -1.05000000000000005e40 or 2.6e9 < d Initial program 53.7%
fma-neg53.7%
distribute-rgt-neg-out53.7%
+-commutative53.7%
fma-define53.7%
Simplified53.7%
Taylor expanded in c around 0 78.1%
+-commutative78.1%
mul-1-neg78.1%
unsub-neg78.1%
unpow278.1%
associate-/r*79.3%
div-sub79.3%
*-commutative79.3%
associate-/l*82.8%
Simplified82.8%
if -1.05000000000000005e40 < d < 2.6e9Initial program 71.7%
fma-neg71.7%
distribute-rgt-neg-out71.7%
+-commutative71.7%
fma-define71.7%
Simplified71.7%
Taylor expanded in c around inf 81.5%
mul-1-neg81.5%
unsub-neg81.5%
*-commutative81.5%
associate-/l*80.3%
Simplified80.3%
associate-*r/81.5%
Applied egg-rr81.5%
Final simplification82.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.8e+39) (not (<= d 1800000000.0))) (/ (- (* b (/ c d)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.8e+39) || !(d <= 1800000000.0)) {
tmp = ((b * (c / d)) - 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 <= (-4.8d+39)) .or. (.not. (d <= 1800000000.0d0))) then
tmp = ((b * (c / d)) - 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 <= -4.8e+39) || !(d <= 1800000000.0)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.8e+39) or not (d <= 1800000000.0): 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 ((d <= -4.8e+39) || !(d <= 1800000000.0)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.8e+39) || ~((d <= 1800000000.0))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e+39], N[Not[LessEqual[d, 1800000000.0]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{+39} \lor \neg \left(d \leq 1800000000\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -4.8000000000000002e39 or 1.8e9 < d Initial program 53.7%
fma-neg53.7%
distribute-rgt-neg-out53.7%
+-commutative53.7%
fma-define53.7%
Simplified53.7%
Taylor expanded in d around inf 79.3%
neg-mul-179.3%
+-commutative79.3%
unsub-neg79.3%
associate-/l*81.7%
Applied egg-rr81.7%
if -4.8000000000000002e39 < d < 1.8e9Initial program 71.7%
fma-neg71.7%
distribute-rgt-neg-out71.7%
+-commutative71.7%
fma-define71.7%
Simplified71.7%
Taylor expanded in c around inf 81.5%
mul-1-neg81.5%
unsub-neg81.5%
*-commutative81.5%
associate-/l*80.3%
Simplified80.3%
associate-*r/81.5%
Applied egg-rr81.5%
Final simplification81.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.7e+39) (not (<= d 9e+113))) (/ (- a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.7e+39) || !(d <= 9e+113)) {
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 <= (-2.7d+39)) .or. (.not. (d <= 9d+113))) 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 <= -2.7e+39) || !(d <= 9e+113)) {
tmp = -a / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.7e+39) or not (d <= 9e+113): tmp = -a / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.7e+39) || !(d <= 9e+113)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.7e+39) || ~((d <= 9e+113))) tmp = -a / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.7e+39], N[Not[LessEqual[d, 9e+113]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{+39} \lor \neg \left(d \leq 9 \cdot 10^{+113}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -2.70000000000000003e39 or 9.0000000000000001e113 < d Initial program 50.3%
fma-neg50.3%
distribute-rgt-neg-out50.3%
+-commutative50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around 0 79.0%
associate-*r/79.0%
neg-mul-179.0%
Simplified79.0%
if -2.70000000000000003e39 < d < 9.0000000000000001e113Initial program 70.7%
fma-neg70.7%
distribute-rgt-neg-out70.7%
+-commutative70.7%
fma-define70.7%
Simplified70.7%
Taylor expanded in c around inf 76.4%
mul-1-neg76.4%
unsub-neg76.4%
*-commutative76.4%
associate-/l*75.9%
Simplified75.9%
associate-*r/76.4%
Applied egg-rr76.4%
Final simplification77.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.5e+42) (not (<= d 2e+114))) (/ (- a) d) (/ (- b (* d (/ a c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.5e+42) || !(d <= 2e+114)) {
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 <= (-5.5d+42)) .or. (.not. (d <= 2d+114))) 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 <= -5.5e+42) || !(d <= 2e+114)) {
tmp = -a / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.5e+42) or not (d <= 2e+114): tmp = -a / d else: tmp = (b - (d * (a / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.5e+42) || !(d <= 2e+114)) 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 <= -5.5e+42) || ~((d <= 2e+114))) tmp = -a / d; else tmp = (b - (d * (a / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.5e+42], N[Not[LessEqual[d, 2e+114]], $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 -5.5 \cdot 10^{+42} \lor \neg \left(d \leq 2 \cdot 10^{+114}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if d < -5.50000000000000001e42 or 2e114 < d Initial program 50.3%
fma-neg50.3%
distribute-rgt-neg-out50.3%
+-commutative50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around 0 79.0%
associate-*r/79.0%
neg-mul-179.0%
Simplified79.0%
if -5.50000000000000001e42 < d < 2e114Initial program 70.7%
fma-neg70.7%
distribute-rgt-neg-out70.7%
+-commutative70.7%
fma-define70.7%
Simplified70.7%
Taylor expanded in c around inf 76.4%
mul-1-neg76.4%
unsub-neg76.4%
*-commutative76.4%
associate-/l*75.9%
Simplified75.9%
Final simplification76.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.1e+40) (not (<= d 4.4e+114))) (/ (- a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.1e+40) || !(d <= 4.4e+114)) {
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 <= (-4.1d+40)) .or. (.not. (d <= 4.4d+114))) 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 <= -4.1e+40) || !(d <= 4.4e+114)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.1e+40) or not (d <= 4.4e+114): tmp = -a / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.1e+40) || !(d <= 4.4e+114)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.1e+40) || ~((d <= 4.4e+114))) tmp = -a / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.1e+40], N[Not[LessEqual[d, 4.4e+114]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.1 \cdot 10^{+40} \lor \neg \left(d \leq 4.4 \cdot 10^{+114}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.1000000000000002e40 or 4.4000000000000001e114 < d Initial program 50.3%
fma-neg50.3%
distribute-rgt-neg-out50.3%
+-commutative50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around 0 79.0%
associate-*r/79.0%
neg-mul-179.0%
Simplified79.0%
if -4.1000000000000002e40 < d < 4.4000000000000001e114Initial program 70.7%
fma-neg70.7%
distribute-rgt-neg-out70.7%
+-commutative70.7%
fma-define70.7%
Simplified70.7%
Taylor expanded in c around inf 76.4%
mul-1-neg76.4%
unsub-neg76.4%
*-commutative76.4%
associate-/l*75.9%
Simplified75.9%
Taylor expanded in c around inf 76.4%
mul-1-neg76.4%
sub-neg76.4%
associate-*r/75.6%
Simplified75.6%
Final simplification76.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.2e+39) (not (<= d 9e+113))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.2e+39) || !(d <= 9e+113)) {
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 <= (-2.2d+39)) .or. (.not. (d <= 9d+113))) 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 <= -2.2e+39) || !(d <= 9e+113)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.2e+39) or not (d <= 9e+113): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.2e+39) || !(d <= 9e+113)) 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 <= -2.2e+39) || ~((d <= 9e+113))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.2e+39], N[Not[LessEqual[d, 9e+113]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.2 \cdot 10^{+39} \lor \neg \left(d \leq 9 \cdot 10^{+113}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.2000000000000001e39 or 9.0000000000000001e113 < d Initial program 50.3%
fma-neg50.3%
distribute-rgt-neg-out50.3%
+-commutative50.3%
fma-define50.3%
Simplified50.3%
Taylor expanded in c around 0 79.0%
associate-*r/79.0%
neg-mul-179.0%
Simplified79.0%
if -2.2000000000000001e39 < d < 9.0000000000000001e113Initial program 70.7%
fma-neg70.7%
distribute-rgt-neg-out70.7%
+-commutative70.7%
fma-define70.7%
Simplified70.7%
Taylor expanded in c around inf 59.1%
Final simplification65.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.95e+113) (not (<= d 7.6e+203))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.95e+113) || !(d <= 7.6e+203)) {
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 <= (-2.95d+113)) .or. (.not. (d <= 7.6d+203))) 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 <= -2.95e+113) || !(d <= 7.6e+203)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.95e+113) or not (d <= 7.6e+203): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.95e+113) || !(d <= 7.6e+203)) tmp = 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 <= -2.95e+113) || ~((d <= 7.6e+203))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.95e+113], N[Not[LessEqual[d, 7.6e+203]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.95 \cdot 10^{+113} \lor \neg \left(d \leq 7.6 \cdot 10^{+203}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.95000000000000011e113 or 7.60000000000000047e203 < d Initial program 44.3%
fma-neg44.3%
distribute-rgt-neg-out44.3%
+-commutative44.3%
fma-define44.3%
Simplified44.3%
Taylor expanded in c around 0 87.4%
associate-*r/87.4%
neg-mul-187.4%
Simplified87.4%
add-sqr-sqrt21.1%
sqrt-unprod39.6%
sqr-neg39.6%
sqrt-unprod20.4%
add-sqr-sqrt34.2%
div-inv34.2%
Applied egg-rr34.2%
associate-*r/34.2%
*-rgt-identity34.2%
Simplified34.2%
if -2.95000000000000011e113 < d < 7.60000000000000047e203Initial program 69.1%
fma-neg69.1%
distribute-rgt-neg-out69.1%
+-commutative69.1%
fma-define69.1%
Simplified69.1%
Taylor expanded in c around inf 52.6%
Final simplification48.8%
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
return a / d;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / d
end function
public static double code(double a, double b, double c, double d) {
return a / d;
}
def code(a, b, c, d): return a / d
function code(a, b, c, d) return Float64(a / d) end
function tmp = code(a, b, c, d) tmp = a / d; end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{d}
\end{array}
Initial program 64.0%
fma-neg64.0%
distribute-rgt-neg-out64.0%
+-commutative64.0%
fma-define64.0%
Simplified64.0%
Taylor expanded in c around 0 41.0%
associate-*r/41.0%
neg-mul-141.0%
Simplified41.0%
add-sqr-sqrt15.3%
sqrt-unprod20.6%
sqr-neg20.6%
sqrt-unprod6.4%
add-sqr-sqrt10.7%
div-inv10.7%
Applied egg-rr10.7%
associate-*r/10.7%
*-rgt-identity10.7%
Simplified10.7%
(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 2024136
(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))))