
(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 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= d -3.25e+105)
(- (/ c (* d (/ d b))) (/ a d))
(if (<= d -2.5e-47)
t_0
(if (<= d 460.0)
(fma -1.0 (* (/ d c) (/ a c)) (/ b c))
(if (<= d 4.2e+77) t_0 (- (* (/ c d) (/ b d)) (/ 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 <= -3.25e+105) {
tmp = (c / (d * (d / b))) - (a / d);
} else if (d <= -2.5e-47) {
tmp = t_0;
} else if (d <= 460.0) {
tmp = fma(-1.0, ((d / c) * (a / c)), (b / c));
} else if (d <= 4.2e+77) {
tmp = t_0;
} else {
tmp = ((c / d) * (b / d)) - (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 <= -3.25e+105) tmp = Float64(Float64(c / Float64(d * Float64(d / b))) - Float64(a / d)); elseif (d <= -2.5e-47) tmp = t_0; elseif (d <= 460.0) tmp = fma(-1.0, Float64(Float64(d / c) * Float64(a / c)), Float64(b / c)); elseif (d <= 4.2e+77) tmp = t_0; else tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d)); end return 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, -3.25e+105], N[(N[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.5e-47], t$95$0, If[LessEqual[d, 460.0], N[(-1.0 * N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+77], t$95$0, N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $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 -3.25 \cdot 10^{+105}:\\
\;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -2.5 \cdot 10^{-47}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 460:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{d}{c} \cdot \frac{a}{c}, \frac{b}{c}\right)\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\end{array}
\end{array}
if d < -3.25000000000000024e105Initial program 33.7%
Taylor expanded in c around 0 71.8%
+-commutative71.8%
mul-1-neg71.8%
unsub-neg71.8%
*-commutative71.8%
associate-/l*74.8%
Simplified74.8%
pow274.8%
*-un-lft-identity74.8%
times-frac88.2%
Applied egg-rr88.2%
if -3.25000000000000024e105 < d < -2.50000000000000006e-47 or 460 < d < 4.1999999999999997e77Initial program 86.2%
if -2.50000000000000006e-47 < d < 460Initial program 65.6%
Taylor expanded in c around inf 83.0%
fma-def83.0%
associate-/l*83.1%
Simplified83.1%
pow283.1%
*-un-lft-identity83.1%
times-frac88.4%
Applied egg-rr88.4%
/-rgt-identity88.4%
*-un-lft-identity88.4%
*-commutative88.4%
times-frac89.2%
clear-num89.2%
Applied egg-rr89.2%
if 4.1999999999999997e77 < d Initial program 38.1%
Taylor expanded in c around 0 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
*-commutative70.1%
associate-/l*74.9%
Simplified74.9%
pow274.9%
associate-/l*70.1%
times-frac78.7%
Applied egg-rr78.7%
Final simplification86.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
(t_1 (- (/ b c) (* d (/ (/ a c) c)))))
(if (<= c -1.9e+89)
t_1
(if (<= c -1.7e-51)
t_0
(if (<= c 6.2e-114)
(/ (- (* b (/ c d)) a) d)
(if (<= c 3e+59) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double t_1 = (b / c) - (d * ((a / c) / c));
double tmp;
if (c <= -1.9e+89) {
tmp = t_1;
} else if (c <= -1.7e-51) {
tmp = t_0;
} else if (c <= 6.2e-114) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 3e+59) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
t_1 = (b / c) - (d * ((a / c) / c))
if (c <= (-1.9d+89)) then
tmp = t_1
else if (c <= (-1.7d-51)) then
tmp = t_0
else if (c <= 6.2d-114) then
tmp = ((b * (c / d)) - a) / d
else if (c <= 3d+59) then
tmp = t_0
else
tmp = t_1
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 t_1 = (b / c) - (d * ((a / c) / c));
double tmp;
if (c <= -1.9e+89) {
tmp = t_1;
} else if (c <= -1.7e-51) {
tmp = t_0;
} else if (c <= 6.2e-114) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 3e+59) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) t_1 = (b / c) - (d * ((a / c) / c)) tmp = 0 if c <= -1.9e+89: tmp = t_1 elif c <= -1.7e-51: tmp = t_0 elif c <= 6.2e-114: tmp = ((b * (c / d)) - a) / d elif c <= 3e+59: tmp = t_0 else: tmp = t_1 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))) t_1 = Float64(Float64(b / c) - Float64(d * Float64(Float64(a / c) / c))) tmp = 0.0 if (c <= -1.9e+89) tmp = t_1; elseif (c <= -1.7e-51) tmp = t_0; elseif (c <= 6.2e-114) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 3e+59) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); t_1 = (b / c) - (d * ((a / c) / c)); tmp = 0.0; if (c <= -1.9e+89) tmp = t_1; elseif (c <= -1.7e-51) tmp = t_0; elseif (c <= 6.2e-114) tmp = ((b * (c / d)) - a) / d; elseif (c <= 3e+59) tmp = t_0; else tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(d * N[(N[(a / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.9e+89], t$95$1, If[LessEqual[c, -1.7e-51], t$95$0, If[LessEqual[c, 6.2e-114], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3e+59], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -1.9 \cdot 10^{+89}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -1.7 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{-114}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 3 \cdot 10^{+59}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -1.90000000000000012e89 or 3e59 < c Initial program 43.1%
Taylor expanded in c around inf 79.4%
+-commutative79.4%
mul-1-neg79.4%
unsub-neg79.4%
associate-/l*78.0%
associate-/r/79.8%
Simplified79.8%
add-sqr-sqrt35.2%
pow235.2%
times-frac37.7%
Applied egg-rr37.7%
associate-*l/37.7%
associate-*r/37.7%
rem-square-sqrt87.5%
Simplified87.5%
if -1.90000000000000012e89 < c < -1.70000000000000001e-51 or 6.2e-114 < c < 3e59Initial program 83.7%
if -1.70000000000000001e-51 < c < 6.2e-114Initial program 65.9%
Taylor expanded in c around 0 78.5%
+-commutative78.5%
mul-1-neg78.5%
unsub-neg78.5%
*-commutative78.5%
associate-/l*76.6%
Simplified76.6%
pow276.6%
associate-/l*78.5%
times-frac83.2%
Applied egg-rr83.2%
associate-*r/85.2%
sub-div85.3%
*-commutative85.3%
Applied egg-rr85.3%
Final simplification85.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.8e-51) (not (<= c 6.2e-52))) (- (/ b c) (* d (/ (/ a c) c))) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.8e-51) || !(c <= 6.2e-52)) {
tmp = (b / c) - (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 <= (-4.8d-51)) .or. (.not. (c <= 6.2d-52))) then
tmp = (b / c) - (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 <= -4.8e-51) || !(c <= 6.2e-52)) {
tmp = (b / c) - (d * ((a / c) / c));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.8e-51) or not (c <= 6.2e-52): tmp = (b / c) - (d * ((a / c) / c)) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.8e-51) || !(c <= 6.2e-52)) tmp = Float64(Float64(b / c) - Float64(d * Float64(Float64(a / c) / c))); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.8e-51) || ~((c <= 6.2e-52))) tmp = (b / c) - (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, -4.8e-51], N[Not[LessEqual[c, 6.2e-52]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(d * N[(N[(a / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.8 \cdot 10^{-51} \lor \neg \left(c \leq 6.2 \cdot 10^{-52}\right):\\
\;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -4.8e-51 or 6.1999999999999998e-52 < c Initial program 54.5%
Taylor expanded in c around inf 76.8%
+-commutative76.8%
mul-1-neg76.8%
unsub-neg76.8%
associate-/l*75.8%
associate-/r/75.8%
Simplified75.8%
add-sqr-sqrt30.6%
pow230.6%
times-frac32.4%
Applied egg-rr32.4%
associate-*l/32.4%
associate-*r/32.4%
rem-square-sqrt81.2%
Simplified81.2%
if -4.8e-51 < c < 6.1999999999999998e-52Initial program 68.5%
Taylor expanded in c around 0 77.3%
+-commutative77.3%
mul-1-neg77.3%
unsub-neg77.3%
*-commutative77.3%
associate-/l*75.5%
Simplified75.5%
pow275.5%
associate-/l*77.3%
times-frac81.6%
Applied egg-rr81.6%
associate-*r/83.5%
sub-div83.7%
*-commutative83.7%
Applied egg-rr83.7%
Final simplification82.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.2e-51) (not (<= c 7e-48))) (/ b c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.2e-51) || !(c <= 7e-48)) {
tmp = b / 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 <= (-7.2d-51)) .or. (.not. (c <= 7d-48))) then
tmp = b / 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 <= -7.2e-51) || !(c <= 7e-48)) {
tmp = b / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -7.2e-51) or not (c <= 7e-48): tmp = b / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.2e-51) || !(c <= 7e-48)) tmp = Float64(b / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -7.2e-51) || ~((c <= 7e-48))) tmp = b / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.2e-51], N[Not[LessEqual[c, 7e-48]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.2 \cdot 10^{-51} \lor \neg \left(c \leq 7 \cdot 10^{-48}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -7.2000000000000001e-51 or 6.99999999999999982e-48 < c Initial program 54.5%
Taylor expanded in c around inf 67.8%
if -7.2000000000000001e-51 < c < 6.99999999999999982e-48Initial program 68.5%
Taylor expanded in c around 0 77.3%
+-commutative77.3%
mul-1-neg77.3%
unsub-neg77.3%
*-commutative77.3%
associate-/l*75.5%
Simplified75.5%
pow275.5%
associate-/l*77.3%
times-frac81.6%
Applied egg-rr81.6%
associate-*r/83.5%
sub-div83.7%
*-commutative83.7%
Applied egg-rr83.7%
Final simplification74.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.2e-51) (not (<= c 5.5e-47))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.2e-51) || !(c <= 5.5e-47)) {
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 <= (-4.2d-51)) .or. (.not. (c <= 5.5d-47))) 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 <= -4.2e-51) || !(c <= 5.5e-47)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.2e-51) or not (c <= 5.5e-47): tmp = b / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.2e-51) || !(c <= 5.5e-47)) 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 <= -4.2e-51) || ~((c <= 5.5e-47))) tmp = b / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.2e-51], N[Not[LessEqual[c, 5.5e-47]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.2 \cdot 10^{-51} \lor \neg \left(c \leq 5.5 \cdot 10^{-47}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -4.20000000000000003e-51 or 5.5000000000000002e-47 < c Initial program 54.5%
Taylor expanded in c around inf 67.8%
if -4.20000000000000003e-51 < c < 5.5000000000000002e-47Initial program 68.5%
Taylor expanded in c around 0 73.9%
associate-*r/73.9%
neg-mul-173.9%
Simplified73.9%
Final simplification70.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.02e+118) (not (<= d 1.25e+156))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.02e+118) || !(d <= 1.25e+156)) {
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 <= (-1.02d+118)) .or. (.not. (d <= 1.25d+156))) 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 <= -1.02e+118) || !(d <= 1.25e+156)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.02e+118) or not (d <= 1.25e+156): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.02e+118) || !(d <= 1.25e+156)) 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 <= -1.02e+118) || ~((d <= 1.25e+156))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.02e+118], N[Not[LessEqual[d, 1.25e+156]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+118} \lor \neg \left(d \leq 1.25 \cdot 10^{+156}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.0199999999999999e118 or 1.24999999999999998e156 < d Initial program 32.1%
Taylor expanded in c around 0 73.4%
associate-*r/73.4%
neg-mul-173.4%
Simplified73.4%
neg-sub073.4%
sub-neg73.4%
add-sqr-sqrt32.5%
sqrt-unprod39.0%
sqr-neg39.0%
sqrt-unprod16.0%
add-sqr-sqrt29.7%
Applied egg-rr29.7%
+-lft-identity29.7%
Simplified29.7%
if -1.0199999999999999e118 < d < 1.24999999999999998e156Initial program 69.3%
Taylor expanded in c around inf 56.7%
Final simplification50.1%
(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 60.1%
Taylor expanded in c around 0 39.0%
associate-*r/39.0%
neg-mul-139.0%
Simplified39.0%
neg-sub039.0%
sub-neg39.0%
add-sqr-sqrt17.7%
sqrt-unprod21.6%
sqr-neg21.6%
sqrt-unprod5.5%
add-sqr-sqrt10.0%
Applied egg-rr10.0%
+-lft-identity10.0%
Simplified10.0%
Final simplification10.0%
(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 2024096
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(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))))