
(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 (/ (- b (* d (/ a c))) c)))
(if (<= c -4800000000.0)
t_0
(if (<= c 4.3e-47)
(/ (- (* c (/ b d)) a) d)
(if (<= c 2.75e+66)
(/ (* c (- b (* a (/ d c)))) (+ (* c c) (* d d)))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -4800000000.0) {
tmp = t_0;
} else if (c <= 4.3e-47) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 2.75e+66) {
tmp = (c * (b - (a * (d / c)))) / ((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 - (d * (a / c))) / c
if (c <= (-4800000000.0d0)) then
tmp = t_0
else if (c <= 4.3d-47) then
tmp = ((c * (b / d)) - a) / d
else if (c <= 2.75d+66) then
tmp = (c * (b - (a * (d / c)))) / ((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 - (d * (a / c))) / c;
double tmp;
if (c <= -4800000000.0) {
tmp = t_0;
} else if (c <= 4.3e-47) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 2.75e+66) {
tmp = (c * (b - (a * (d / c)))) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - (d * (a / c))) / c tmp = 0 if c <= -4800000000.0: tmp = t_0 elif c <= 4.3e-47: tmp = ((c * (b / d)) - a) / d elif c <= 2.75e+66: tmp = (c * (b - (a * (d / c)))) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -4800000000.0) tmp = t_0; elseif (c <= 4.3e-47) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (c <= 2.75e+66) tmp = Float64(Float64(c * Float64(b - Float64(a * Float64(d / c)))) / 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 - (d * (a / c))) / c; tmp = 0.0; if (c <= -4800000000.0) tmp = t_0; elseif (c <= 4.3e-47) tmp = ((c * (b / d)) - a) / d; elseif (c <= 2.75e+66) tmp = (c * (b - (a * (d / c)))) / ((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 - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4800000000.0], t$95$0, If[LessEqual[c, 4.3e-47], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.75e+66], N[(N[(c * N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $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 - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -4800000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.3 \cdot 10^{-47}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 2.75 \cdot 10^{+66}:\\
\;\;\;\;\frac{c \cdot \left(b - a \cdot \frac{d}{c}\right)}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.8e9 or 2.75e66 < c Initial program 44.8%
Taylor expanded in c around inf 79.2%
remove-double-neg79.2%
mul-1-neg79.2%
neg-mul-179.2%
distribute-lft-in79.2%
distribute-lft-in79.2%
mul-1-neg79.2%
unsub-neg79.2%
neg-mul-179.2%
mul-1-neg79.2%
remove-double-neg79.2%
associate-/l*81.6%
Simplified81.6%
Taylor expanded in a around 0 79.2%
*-commutative79.2%
*-un-lft-identity79.2%
times-frac82.8%
Applied egg-rr82.8%
if -4.8e9 < c < 4.2999999999999998e-47Initial program 71.0%
Taylor expanded in c around 0 78.4%
+-commutative78.4%
mul-1-neg78.4%
unsub-neg78.4%
unpow278.4%
associate-/r*82.8%
div-sub85.3%
*-commutative85.3%
associate-/l*85.3%
Simplified85.3%
if 4.2999999999999998e-47 < c < 2.75e66Initial program 95.6%
Taylor expanded in c around inf 95.6%
remove-double-neg95.6%
mul-1-neg95.6%
neg-mul-195.6%
distribute-lft-in95.6%
distribute-lft-in95.6%
mul-1-neg95.6%
unsub-neg95.6%
neg-mul-195.6%
mul-1-neg95.6%
remove-double-neg95.6%
associate-/l*95.7%
Simplified95.7%
Final simplification85.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -750000000000.0)
(/ (- b (* d (/ a c))) c)
(if (<= c 1.95e-45)
(/ (- (* c (/ b d)) a) d)
(if (<= c 6.4e+91)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(/ (- b (* a (/ d c))) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -750000000000.0) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= 1.95e-45) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 6.4e+91) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * 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 (c <= (-750000000000.0d0)) then
tmp = (b - (d * (a / c))) / c
else if (c <= 1.95d-45) then
tmp = ((c * (b / d)) - a) / d
else if (c <= 6.4d+91) then
tmp = ((c * b) - (d * a)) / ((c * c) + (d * 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 (c <= -750000000000.0) {
tmp = (b - (d * (a / c))) / c;
} else if (c <= 1.95e-45) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 6.4e+91) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -750000000000.0: tmp = (b - (d * (a / c))) / c elif c <= 1.95e-45: tmp = ((c * (b / d)) - a) / d elif c <= 6.4e+91: tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)) else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -750000000000.0) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (c <= 1.95e-45) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (c <= 6.4e+91) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * 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 (c <= -750000000000.0) tmp = (b - (d * (a / c))) / c; elseif (c <= 1.95e-45) tmp = ((c * (b / d)) - a) / d; elseif (c <= 6.4e+91) tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)); else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -750000000000.0], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.95e-45], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.4e+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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -750000000000:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;c \leq 1.95 \cdot 10^{-45}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 6.4 \cdot 10^{+91}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if c < -7.5e11Initial program 48.1%
Taylor expanded in c around inf 77.4%
remove-double-neg77.4%
mul-1-neg77.4%
neg-mul-177.4%
distribute-lft-in77.4%
distribute-lft-in77.4%
mul-1-neg77.4%
unsub-neg77.4%
neg-mul-177.4%
mul-1-neg77.4%
remove-double-neg77.4%
associate-/l*77.6%
Simplified77.6%
Taylor expanded in a around 0 77.4%
*-commutative77.4%
*-un-lft-identity77.4%
times-frac79.1%
Applied egg-rr79.1%
if -7.5e11 < c < 1.95e-45Initial program 71.0%
Taylor expanded in c around 0 78.4%
+-commutative78.4%
mul-1-neg78.4%
unsub-neg78.4%
unpow278.4%
associate-/r*82.8%
div-sub85.3%
*-commutative85.3%
associate-/l*85.3%
Simplified85.3%
if 1.95e-45 < c < 6.39999999999999979e91Initial program 96.4%
if 6.39999999999999979e91 < c Initial program 32.9%
Taylor expanded in c around inf 79.5%
remove-double-neg79.5%
mul-1-neg79.5%
neg-mul-179.5%
distribute-lft-in79.5%
distribute-lft-in79.5%
mul-1-neg79.5%
unsub-neg79.5%
neg-mul-179.5%
mul-1-neg79.5%
remove-double-neg79.5%
associate-/l*86.7%
Simplified86.7%
Final simplification85.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* d (/ a c))) c)))
(if (<= c -115000000000.0)
t_0
(if (<= c 2.4e-42)
(/ (- (* c (/ b d)) a) d)
(if (<= c 1.05e+66) (/ (* c b) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -115000000000.0) {
tmp = t_0;
} else if (c <= 2.4e-42) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 1.05e+66) {
tmp = (c * b) / ((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 - (d * (a / c))) / c
if (c <= (-115000000000.0d0)) then
tmp = t_0
else if (c <= 2.4d-42) then
tmp = ((c * (b / d)) - a) / d
else if (c <= 1.05d+66) then
tmp = (c * b) / ((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 - (d * (a / c))) / c;
double tmp;
if (c <= -115000000000.0) {
tmp = t_0;
} else if (c <= 2.4e-42) {
tmp = ((c * (b / d)) - a) / d;
} else if (c <= 1.05e+66) {
tmp = (c * b) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - (d * (a / c))) / c tmp = 0 if c <= -115000000000.0: tmp = t_0 elif c <= 2.4e-42: tmp = ((c * (b / d)) - a) / d elif c <= 1.05e+66: tmp = (c * b) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -115000000000.0) tmp = t_0; elseif (c <= 2.4e-42) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (c <= 1.05e+66) tmp = Float64(Float64(c * b) / 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 - (d * (a / c))) / c; tmp = 0.0; if (c <= -115000000000.0) tmp = t_0; elseif (c <= 2.4e-42) tmp = ((c * (b / d)) - a) / d; elseif (c <= 1.05e+66) tmp = (c * b) / ((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 - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -115000000000.0], t$95$0, If[LessEqual[c, 2.4e-42], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.05e+66], N[(N[(c * b), $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 - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -115000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{-42}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{+66}:\\
\;\;\;\;\frac{c \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.15e11 or 1.05000000000000003e66 < c Initial program 44.8%
Taylor expanded in c around inf 79.2%
remove-double-neg79.2%
mul-1-neg79.2%
neg-mul-179.2%
distribute-lft-in79.2%
distribute-lft-in79.2%
mul-1-neg79.2%
unsub-neg79.2%
neg-mul-179.2%
mul-1-neg79.2%
remove-double-neg79.2%
associate-/l*81.6%
Simplified81.6%
Taylor expanded in a around 0 79.2%
*-commutative79.2%
*-un-lft-identity79.2%
times-frac82.8%
Applied egg-rr82.8%
if -1.15e11 < c < 2.40000000000000003e-42Initial program 71.0%
Taylor expanded in c around 0 78.4%
+-commutative78.4%
mul-1-neg78.4%
unsub-neg78.4%
unpow278.4%
associate-/r*82.8%
div-sub85.3%
*-commutative85.3%
associate-/l*85.3%
Simplified85.3%
if 2.40000000000000003e-42 < c < 1.05000000000000003e66Initial program 95.6%
Taylor expanded in b around inf 84.0%
*-commutative84.0%
Simplified84.0%
Final simplification84.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1e-91) (not (<= d 12200000000.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 <= -1e-91) || !(d <= 12200000000.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 <= (-1d-91)) .or. (.not. (d <= 12200000000.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 <= -1e-91) || !(d <= 12200000000.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 <= -1e-91) or not (d <= 12200000000.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 <= -1e-91) || !(d <= 12200000000.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 <= -1e-91) || ~((d <= 12200000000.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, -1e-91], N[Not[LessEqual[d, 12200000000.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 -1 \cdot 10^{-91} \lor \neg \left(d \leq 12200000000\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 < -1.00000000000000002e-91 or 1.22e10 < d Initial program 51.4%
Taylor expanded in c around 0 73.1%
+-commutative73.1%
mul-1-neg73.1%
unsub-neg73.1%
unpow273.1%
associate-/r*75.3%
div-sub75.3%
*-commutative75.3%
associate-/l*76.8%
Simplified76.8%
Taylor expanded in c around 0 75.3%
associate-*r/76.2%
Simplified76.2%
if -1.00000000000000002e-91 < d < 1.22e10Initial program 73.1%
Taylor expanded in c around inf 88.3%
remove-double-neg88.3%
mul-1-neg88.3%
neg-mul-188.3%
distribute-lft-in88.3%
distribute-lft-in88.3%
mul-1-neg88.3%
unsub-neg88.3%
neg-mul-188.3%
mul-1-neg88.3%
remove-double-neg88.3%
associate-/l*87.5%
Simplified87.5%
Taylor expanded in a around 0 88.3%
Final simplification81.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e-50) (not (<= d 95000000.0))) (/ (- a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e-50) || !(d <= 95000000.0)) {
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 <= (-4d-50)) .or. (.not. (d <= 95000000.0d0))) 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 <= -4e-50) || !(d <= 95000000.0)) {
tmp = -a / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e-50) or not (d <= 95000000.0): tmp = -a / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e-50) || !(d <= 95000000.0)) 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 <= -4e-50) || ~((d <= 95000000.0))) tmp = -a / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e-50], N[Not[LessEqual[d, 95000000.0]], $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 -4 \cdot 10^{-50} \lor \neg \left(d \leq 95000000\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000003e-50 or 9.5e7 < d Initial program 50.3%
Taylor expanded in c around 0 69.3%
associate-*r/69.3%
neg-mul-169.3%
Simplified69.3%
if -4.00000000000000003e-50 < d < 9.5e7Initial program 72.7%
Taylor expanded in c around inf 85.4%
remove-double-neg85.4%
mul-1-neg85.4%
neg-mul-185.4%
distribute-lft-in85.4%
distribute-lft-in85.4%
mul-1-neg85.4%
unsub-neg85.4%
neg-mul-185.4%
mul-1-neg85.4%
remove-double-neg85.4%
associate-/l*84.7%
Simplified84.7%
Taylor expanded in a around 0 85.4%
Final simplification77.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e-50) (not (<= d 2.85e+94))) (/ (- a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e-50) || !(d <= 2.85e+94)) {
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 <= (-4d-50)) .or. (.not. (d <= 2.85d+94))) 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 <= -4e-50) || !(d <= 2.85e+94)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e-50) or not (d <= 2.85e+94): tmp = -a / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e-50) || !(d <= 2.85e+94)) 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 <= -4e-50) || ~((d <= 2.85e+94))) tmp = -a / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e-50], N[Not[LessEqual[d, 2.85e+94]], $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 \cdot 10^{-50} \lor \neg \left(d \leq 2.85 \cdot 10^{+94}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000003e-50 or 2.8500000000000001e94 < d Initial program 47.6%
Taylor expanded in c around 0 73.1%
associate-*r/73.1%
neg-mul-173.1%
Simplified73.1%
if -4.00000000000000003e-50 < d < 2.8500000000000001e94Initial program 72.6%
Taylor expanded in c around inf 80.8%
remove-double-neg80.8%
mul-1-neg80.8%
neg-mul-180.8%
distribute-lft-in80.8%
distribute-lft-in80.8%
mul-1-neg80.8%
unsub-neg80.8%
neg-mul-180.8%
mul-1-neg80.8%
remove-double-neg80.8%
associate-/l*80.8%
Simplified80.8%
Final simplification77.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -1e-91)
(/ (- (* b (/ c d)) a) d)
(if (<= d 38000000000.0)
(/ (- b (/ (* d a) c)) c)
(/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1e-91) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 38000000000.0) {
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 (d <= (-1d-91)) then
tmp = ((b * (c / d)) - a) / d
else if (d <= 38000000000.0d0) 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 (d <= -1e-91) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 38000000000.0) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1e-91: tmp = ((b * (c / d)) - a) / d elif d <= 38000000000.0: 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 (d <= -1e-91) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (d <= 38000000000.0) tmp = Float64(Float64(b - Float64(Float64(d * 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 (d <= -1e-91) tmp = ((b * (c / d)) - a) / d; elseif (d <= 38000000000.0) tmp = (b - ((d * a) / c)) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1e-91], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 38000000000.0], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $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}\;d \leq -1 \cdot 10^{-91}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;d \leq 38000000000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.00000000000000002e-91Initial program 59.2%
Taylor expanded in c around 0 75.8%
+-commutative75.8%
mul-1-neg75.8%
unsub-neg75.8%
unpow275.8%
associate-/r*77.0%
div-sub77.0%
*-commutative77.0%
associate-/l*77.1%
Simplified77.1%
Taylor expanded in c around 0 77.0%
associate-*r/77.2%
Simplified77.2%
if -1.00000000000000002e-91 < d < 3.8e10Initial program 73.1%
Taylor expanded in c around inf 88.3%
remove-double-neg88.3%
mul-1-neg88.3%
neg-mul-188.3%
distribute-lft-in88.3%
distribute-lft-in88.3%
mul-1-neg88.3%
unsub-neg88.3%
neg-mul-188.3%
mul-1-neg88.3%
remove-double-neg88.3%
associate-/l*87.5%
Simplified87.5%
Taylor expanded in a around 0 88.3%
if 3.8e10 < d Initial program 40.5%
Taylor expanded in c around 0 69.4%
+-commutative69.4%
mul-1-neg69.4%
unsub-neg69.4%
unpow269.4%
associate-/r*72.8%
div-sub72.8%
*-commutative72.8%
associate-/l*76.4%
Simplified76.4%
Final simplification82.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e-50) (not (<= d 700000000000.0))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e-50) || !(d <= 700000000000.0)) {
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 <= (-4d-50)) .or. (.not. (d <= 700000000000.0d0))) 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 <= -4e-50) || !(d <= 700000000000.0)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e-50) or not (d <= 700000000000.0): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e-50) || !(d <= 700000000000.0)) 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 <= -4e-50) || ~((d <= 700000000000.0))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e-50], N[Not[LessEqual[d, 700000000000.0]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{-50} \lor \neg \left(d \leq 700000000000\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000003e-50 or 7e11 < d Initial program 50.3%
Taylor expanded in c around 0 69.3%
associate-*r/69.3%
neg-mul-169.3%
Simplified69.3%
if -4.00000000000000003e-50 < d < 7e11Initial program 72.7%
Taylor expanded in c around inf 71.3%
Final simplification70.3%
(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 61.7%
Taylor expanded in c around inf 46.1%
(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 2024100
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(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))))