
(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 8 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 (- (/ b c) (/ (/ d c) (/ c a)))))
(if (<= c -6.2e+87)
t_0
(if (<= c 1.16e-122)
(/ (- (* b (/ c d)) a) d)
(if (<= c 1.15e+99) (/ (- (* c b) (* d a)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b / c) - ((d / c) / (c / a));
double tmp;
if (c <= -6.2e+87) {
tmp = t_0;
} else if (c <= 1.16e-122) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 1.15e+99) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (b / c) - ((d / c) / (c / a))
if (c <= (-6.2d+87)) then
tmp = t_0
else if (c <= 1.16d-122) then
tmp = ((b * (c / d)) - a) / d
else if (c <= 1.15d+99) then
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / c) - ((d / c) / (c / a));
double tmp;
if (c <= -6.2e+87) {
tmp = t_0;
} else if (c <= 1.16e-122) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 1.15e+99) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / c) - ((d / c) / (c / a)) tmp = 0 if c <= -6.2e+87: tmp = t_0 elif c <= 1.16e-122: tmp = ((b * (c / d)) - a) / d elif c <= 1.15e+99: tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / c) - Float64(Float64(d / c) / Float64(c / a))) tmp = 0.0 if (c <= -6.2e+87) tmp = t_0; elseif (c <= 1.16e-122) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 1.15e+99) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / c) - ((d / c) / (c / a)); tmp = 0.0; if (c <= -6.2e+87) tmp = t_0; elseif (c <= 1.16e-122) tmp = ((b * (c / d)) - a) / d; elseif (c <= 1.15e+99) tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] / N[(c / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -6.2e+87], t$95$0, If[LessEqual[c, 1.16e-122], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.15e+99], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{c} - \frac{\frac{d}{c}}{\frac{c}{a}}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{+87}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.16 \cdot 10^{-122}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.15 \cdot 10^{+99}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -6.1999999999999999e87 or 1.1500000000000001e99 < c Initial program 45.2%
Taylor expanded in c around inf 77.4%
+-commutative77.4%
mul-1-neg77.4%
unsub-neg77.4%
unpow277.4%
times-frac90.5%
Simplified90.5%
*-commutative90.5%
clear-num90.5%
un-div-inv90.5%
Applied egg-rr90.5%
if -6.1999999999999999e87 < c < 1.16000000000000001e-122Initial program 72.9%
Taylor expanded in c around 0 78.8%
+-commutative78.8%
mul-1-neg78.8%
unsub-neg78.8%
unpow278.8%
associate-/l*78.9%
Simplified78.9%
associate-/l*78.8%
times-frac84.8%
*-commutative84.8%
associate-*r/87.9%
sub-div88.8%
Applied egg-rr88.8%
if 1.16000000000000001e-122 < c < 1.1500000000000001e99Initial program 72.1%
Final simplification86.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.96e+27) (not (<= d 4.8e+46))) (/ (- a) d) (/ (- b (* d (/ a c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.96e+27) || !(d <= 4.8e+46)) {
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 <= (-1.96d+27)) .or. (.not. (d <= 4.8d+46))) 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 <= -1.96e+27) || !(d <= 4.8e+46)) {
tmp = -a / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.96e+27) or not (d <= 4.8e+46): tmp = -a / d else: tmp = (b - (d * (a / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.96e+27) || !(d <= 4.8e+46)) 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 <= -1.96e+27) || ~((d <= 4.8e+46))) tmp = -a / d; else tmp = (b - (d * (a / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.96e+27], N[Not[LessEqual[d, 4.8e+46]], $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 -1.96 \cdot 10^{+27} \lor \neg \left(d \leq 4.8 \cdot 10^{+46}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if d < -1.95999999999999989e27 or 4.80000000000000017e46 < d Initial program 51.1%
Taylor expanded in c around 0 75.7%
associate-*r/75.7%
neg-mul-175.7%
Simplified75.7%
if -1.95999999999999989e27 < d < 4.80000000000000017e46Initial program 73.6%
clear-num73.6%
associate-/r/72.8%
frac-2neg72.8%
frac-2neg72.8%
fma-def72.8%
Applied egg-rr72.8%
Taylor expanded in c around inf 69.1%
+-commutative69.1%
mul-1-neg69.1%
*-commutative69.1%
unpow269.1%
times-frac73.3%
*-commutative73.3%
sub-neg73.3%
associate-*r/73.9%
*-commutative73.9%
div-sub75.4%
Simplified75.4%
Final simplification75.6%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.25e+89) (not (<= c 5.5e+57))) (/ (- b (* d (/ a c))) c) (/ (- (* c (/ b d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.25e+89) || !(c <= 5.5e+57)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((c * (b / 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 <= (-2.25d+89)) .or. (.not. (c <= 5.5d+57))) then
tmp = (b - (d * (a / c))) / c
else
tmp = ((c * (b / 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 <= -2.25e+89) || !(c <= 5.5e+57)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.25e+89) or not (c <= 5.5e+57): tmp = (b - (d * (a / c))) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.25e+89) || !(c <= 5.5e+57)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.25e+89) || ~((c <= 5.5e+57))) tmp = (b - (d * (a / c))) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.25e+89], N[Not[LessEqual[c, 5.5e+57]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.25 \cdot 10^{+89} \lor \neg \left(c \leq 5.5 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.25e89 or 5.5000000000000002e57 < c Initial program 48.4%
clear-num48.4%
associate-/r/48.4%
frac-2neg48.4%
frac-2neg48.4%
fma-def48.4%
Applied egg-rr48.4%
Taylor expanded in c around inf 76.0%
+-commutative76.0%
mul-1-neg76.0%
*-commutative76.0%
unpow276.0%
times-frac86.7%
*-commutative86.7%
sub-neg86.7%
associate-*r/87.6%
*-commutative87.6%
div-sub87.6%
Simplified87.6%
if -2.25e89 < c < 5.5000000000000002e57Initial program 72.6%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
unpow274.2%
associate-/l*74.3%
Simplified74.3%
Taylor expanded in b around 0 74.2%
mul-1-neg74.2%
distribute-frac-neg74.2%
+-commutative74.2%
*-commutative74.2%
unpow274.2%
*-commutative74.2%
associate-/l*74.3%
distribute-frac-neg74.3%
sub-neg74.3%
associate-/l*74.2%
*-commutative74.2%
associate-/r*80.8%
associate-*r/79.0%
div-sub79.9%
Simplified79.9%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.85e+87) (not (<= c 4.4e+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 <= -1.85e+87) || !(c <= 4.4e+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 <= (-1.85d+87)) .or. (.not. (c <= 4.4d+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 <= -1.85e+87) || !(c <= 4.4e+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 <= -1.85e+87) or not (c <= 4.4e+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 <= -1.85e+87) || !(c <= 4.4e+57)) tmp = Float64(Float64(b - Float64(d * 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 <= -1.85e+87) || ~((c <= 4.4e+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, -1.85e+87], N[Not[LessEqual[c, 4.4e+57]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 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 -1.85 \cdot 10^{+87} \lor \neg \left(c \leq 4.4 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -1.85000000000000001e87 or 4.4000000000000001e57 < c Initial program 48.4%
clear-num48.4%
associate-/r/48.4%
frac-2neg48.4%
frac-2neg48.4%
fma-def48.4%
Applied egg-rr48.4%
Taylor expanded in c around inf 76.0%
+-commutative76.0%
mul-1-neg76.0%
*-commutative76.0%
unpow276.0%
times-frac86.7%
*-commutative86.7%
sub-neg86.7%
associate-*r/87.6%
*-commutative87.6%
div-sub87.6%
Simplified87.6%
if -1.85000000000000001e87 < c < 4.4000000000000001e57Initial program 72.6%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
unpow274.2%
associate-/l*74.3%
Simplified74.3%
associate-/l*74.2%
times-frac79.0%
*-commutative79.0%
associate-*r/81.4%
sub-div82.3%
Applied egg-rr82.3%
Final simplification84.3%
(FPCore (a b c d) :precision binary64 (if (<= c -2.25e+89) (- (/ b c) (* (/ d c) (/ a c))) (if (<= c 3.8e+56) (/ (- (* b (/ c d)) a) d) (/ (- b (* d (/ a c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.25e+89) {
tmp = (b / c) - ((d / c) * (a / c));
} else if (c <= 3.8e+56) {
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 (c <= (-2.25d+89)) then
tmp = (b / c) - ((d / c) * (a / c))
else if (c <= 3.8d+56) 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 (c <= -2.25e+89) {
tmp = (b / c) - ((d / c) * (a / c));
} else if (c <= 3.8e+56) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.25e+89: tmp = (b / c) - ((d / c) * (a / c)) elif c <= 3.8e+56: 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 <= -2.25e+89) tmp = Float64(Float64(b / c) - Float64(Float64(d / c) * Float64(a / c))); elseif (c <= 3.8e+56) tmp = Float64(Float64(Float64(b * Float64(c / d)) - 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 (c <= -2.25e+89) tmp = (b / c) - ((d / c) * (a / c)); elseif (c <= 3.8e+56) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (d * (a / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.25e+89], N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.8e+56], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $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 -2.25 \cdot 10^{+89}:\\
\;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\
\mathbf{elif}\;c \leq 3.8 \cdot 10^{+56}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -2.25e89Initial program 49.0%
Taylor expanded in c around inf 75.8%
+-commutative75.8%
mul-1-neg75.8%
unsub-neg75.8%
unpow275.8%
times-frac90.7%
Simplified90.7%
if -2.25e89 < c < 3.79999999999999996e56Initial program 72.6%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
unpow274.2%
associate-/l*74.3%
Simplified74.3%
associate-/l*74.2%
times-frac79.0%
*-commutative79.0%
associate-*r/81.4%
sub-div82.3%
Applied egg-rr82.3%
if 3.79999999999999996e56 < c Initial program 47.9%
clear-num47.9%
associate-/r/47.9%
frac-2neg47.9%
frac-2neg47.9%
fma-def47.9%
Applied egg-rr47.9%
Taylor expanded in c around inf 76.2%
+-commutative76.2%
mul-1-neg76.2%
*-commutative76.2%
unpow276.2%
times-frac83.2%
*-commutative83.2%
sub-neg83.2%
associate-*r/85.0%
*-commutative85.0%
div-sub84.9%
Simplified84.9%
Final simplification84.3%
(FPCore (a b c d) :precision binary64 (if (<= c -1.8e+87) (- (/ b c) (/ (/ d c) (/ c a))) (if (<= c 1.85e+56) (/ (- (* 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.8e+87) {
tmp = (b / c) - ((d / c) / (c / a));
} else if (c <= 1.85e+56) {
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 (c <= (-1.8d+87)) then
tmp = (b / c) - ((d / c) / (c / a))
else if (c <= 1.85d+56) 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 (c <= -1.8e+87) {
tmp = (b / c) - ((d / c) / (c / a));
} else if (c <= 1.85e+56) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.8e+87: tmp = (b / c) - ((d / c) / (c / a)) elif c <= 1.85e+56: 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.8e+87) tmp = Float64(Float64(b / c) - Float64(Float64(d / c) / Float64(c / a))); elseif (c <= 1.85e+56) tmp = Float64(Float64(Float64(b * Float64(c / d)) - 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 (c <= -1.8e+87) tmp = (b / c) - ((d / c) / (c / a)); elseif (c <= 1.85e+56) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (d * (a / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.8e+87], N[(N[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] / N[(c / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.85e+56], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $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.8 \cdot 10^{+87}:\\
\;\;\;\;\frac{b}{c} - \frac{\frac{d}{c}}{\frac{c}{a}}\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{+56}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -1.79999999999999997e87Initial program 49.0%
Taylor expanded in c around inf 75.8%
+-commutative75.8%
mul-1-neg75.8%
unsub-neg75.8%
unpow275.8%
times-frac90.7%
Simplified90.7%
*-commutative90.7%
clear-num90.7%
un-div-inv90.8%
Applied egg-rr90.8%
if -1.79999999999999997e87 < c < 1.84999999999999998e56Initial program 72.6%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
unpow274.2%
associate-/l*74.3%
Simplified74.3%
associate-/l*74.2%
times-frac79.0%
*-commutative79.0%
associate-*r/81.4%
sub-div82.3%
Applied egg-rr82.3%
if 1.84999999999999998e56 < c Initial program 47.9%
clear-num47.9%
associate-/r/47.9%
frac-2neg47.9%
frac-2neg47.9%
fma-def47.9%
Applied egg-rr47.9%
Taylor expanded in c around inf 76.2%
+-commutative76.2%
mul-1-neg76.2%
*-commutative76.2%
unpow276.2%
times-frac83.2%
*-commutative83.2%
sub-neg83.2%
associate-*r/85.0%
*-commutative85.0%
div-sub84.9%
Simplified84.9%
Final simplification84.3%
(FPCore (a b c d) :precision binary64 (if (<= c -3.8e+91) (/ b c) (if (<= c 1e+57) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.8e+91) {
tmp = b / c;
} else if (c <= 1e+57) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-3.8d+91)) then
tmp = b / c
else if (c <= 1d+57) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3.8e+91) {
tmp = b / c;
} else if (c <= 1e+57) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3.8e+91: tmp = b / c elif c <= 1e+57: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3.8e+91) tmp = Float64(b / c); elseif (c <= 1e+57) 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 (c <= -3.8e+91) tmp = b / c; elseif (c <= 1e+57) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.8e+91], N[(b / c), $MachinePrecision], If[LessEqual[c, 1e+57], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.8 \cdot 10^{+91}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 10^{+57}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -3.7999999999999998e91 or 1.00000000000000005e57 < c Initial program 47.3%
Taylor expanded in c around inf 75.7%
if -3.7999999999999998e91 < c < 1.00000000000000005e57Initial program 73.0%
Taylor expanded in c around 0 67.5%
associate-*r/67.5%
neg-mul-167.5%
Simplified67.5%
Final simplification70.6%
(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 63.4%
Taylor expanded in c around inf 39.6%
Final simplification39.6%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2023297
(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))))