
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ a c) (/ 1.0 (* c (/ (/ c b) d))))))
(if (<= c -2.35e+98)
t_0
(if (<= c -1.6e-9)
(* (fma a c (* b d)) (/ 1.0 (fma c c (* d d))))
(if (<= c 5.2e-123)
(* (/ 1.0 d) (+ b (* a (/ c d))))
(if (<= c 9.4e-54)
(/ (+ (* b d) (* c a)) (+ (* d d) (* c c)))
(if (<= c 1.85e+56) (+ (/ b d) (* (/ c d) (/ a d))) t_0)))))))
double code(double a, double b, double c, double d) {
double t_0 = (a / c) + (1.0 / (c * ((c / b) / d)));
double tmp;
if (c <= -2.35e+98) {
tmp = t_0;
} else if (c <= -1.6e-9) {
tmp = fma(a, c, (b * d)) * (1.0 / fma(c, c, (d * d)));
} else if (c <= 5.2e-123) {
tmp = (1.0 / d) * (b + (a * (c / d)));
} else if (c <= 9.4e-54) {
tmp = ((b * d) + (c * a)) / ((d * d) + (c * c));
} else if (c <= 1.85e+56) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a / c) + Float64(1.0 / Float64(c * Float64(Float64(c / b) / d)))) tmp = 0.0 if (c <= -2.35e+98) tmp = t_0; elseif (c <= -1.6e-9) tmp = Float64(fma(a, c, Float64(b * d)) * Float64(1.0 / fma(c, c, Float64(d * d)))); elseif (c <= 5.2e-123) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); elseif (c <= 9.4e-54) tmp = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))); elseif (c <= 1.85e+56) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(c * N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.35e+98], t$95$0, If[LessEqual[c, -1.6e-9], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.2e-123], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.4e-54], N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.85e+56], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\
\mathbf{if}\;c \leq -2.35 \cdot 10^{+98}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -1.6 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{-123}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\mathbf{elif}\;c \leq 9.4 \cdot 10^{-54}:\\
\;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{+56}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if c < -2.34999999999999985e98 or 1.84999999999999998e56 < c Initial program 35.1%
Taylor expanded in c around inf 78.5%
unpow278.5%
associate-/l*79.7%
Simplified79.7%
clear-num79.7%
inv-pow79.7%
metadata-eval79.7%
sqr-pow76.1%
associate-/l/72.7%
*-commutative72.7%
times-frac73.7%
metadata-eval73.7%
metadata-eval73.7%
associate-/l/73.6%
*-commutative73.6%
times-frac78.9%
metadata-eval78.9%
metadata-eval78.9%
Applied egg-rr78.9%
pow-sqr87.7%
metadata-eval87.7%
unpow-187.7%
associate-*l/85.8%
*-lft-identity85.8%
times-frac88.7%
/-rgt-identity88.7%
Simplified88.7%
if -2.34999999999999985e98 < c < -1.60000000000000006e-9Initial program 72.3%
div-inv72.4%
fma-def72.4%
fma-def72.4%
Applied egg-rr72.4%
if -1.60000000000000006e-9 < c < 5.1999999999999999e-123Initial program 69.3%
Taylor expanded in c around 0 88.2%
unpow288.2%
associate-/l*89.3%
Simplified89.3%
associate-/l*94.1%
*-rgt-identity94.1%
associate-/r/94.0%
times-frac95.6%
Applied egg-rr95.6%
+-commutative95.6%
div-inv95.4%
distribute-rgt-out96.4%
div-inv96.3%
clear-num96.4%
Applied egg-rr96.4%
if 5.1999999999999999e-123 < c < 9.4e-54Initial program 80.6%
if 9.4e-54 < c < 1.84999999999999998e56Initial program 53.6%
Taylor expanded in c around 0 69.9%
unpow269.9%
associate-/l*69.8%
Simplified69.8%
associate-/r/65.2%
associate-*l/69.9%
*-commutative69.9%
times-frac69.9%
Applied egg-rr69.9%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* b d) (* c a)) (+ (* d d) (* c c))))
(t_1 (+ (/ a c) (/ 1.0 (* c (/ (/ c b) d))))))
(if (<= c -3.2e+97)
t_1
(if (<= c -1.6e-9)
t_0
(if (<= c 1.5e-122)
(* (/ 1.0 d) (+ b (* a (/ c d))))
(if (<= c 4.3e-44)
t_0
(if (<= c 1.5e+59) (+ (/ b d) (* (/ c d) (/ a d))) t_1)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * d) + (c * a)) / ((d * d) + (c * c));
double t_1 = (a / c) + (1.0 / (c * ((c / b) / d)));
double tmp;
if (c <= -3.2e+97) {
tmp = t_1;
} else if (c <= -1.6e-9) {
tmp = t_0;
} else if (c <= 1.5e-122) {
tmp = (1.0 / d) * (b + (a * (c / d)));
} else if (c <= 4.3e-44) {
tmp = t_0;
} else if (c <= 1.5e+59) {
tmp = (b / d) + ((c / d) * (a / d));
} 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 = ((b * d) + (c * a)) / ((d * d) + (c * c))
t_1 = (a / c) + (1.0d0 / (c * ((c / b) / d)))
if (c <= (-3.2d+97)) then
tmp = t_1
else if (c <= (-1.6d-9)) then
tmp = t_0
else if (c <= 1.5d-122) then
tmp = (1.0d0 / d) * (b + (a * (c / d)))
else if (c <= 4.3d-44) then
tmp = t_0
else if (c <= 1.5d+59) then
tmp = (b / d) + ((c / d) * (a / d))
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 = ((b * d) + (c * a)) / ((d * d) + (c * c));
double t_1 = (a / c) + (1.0 / (c * ((c / b) / d)));
double tmp;
if (c <= -3.2e+97) {
tmp = t_1;
} else if (c <= -1.6e-9) {
tmp = t_0;
} else if (c <= 1.5e-122) {
tmp = (1.0 / d) * (b + (a * (c / d)));
} else if (c <= 4.3e-44) {
tmp = t_0;
} else if (c <= 1.5e+59) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * d) + (c * a)) / ((d * d) + (c * c)) t_1 = (a / c) + (1.0 / (c * ((c / b) / d))) tmp = 0 if c <= -3.2e+97: tmp = t_1 elif c <= -1.6e-9: tmp = t_0 elif c <= 1.5e-122: tmp = (1.0 / d) * (b + (a * (c / d))) elif c <= 4.3e-44: tmp = t_0 elif c <= 1.5e+59: tmp = (b / d) + ((c / d) * (a / d)) else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c))) t_1 = Float64(Float64(a / c) + Float64(1.0 / Float64(c * Float64(Float64(c / b) / d)))) tmp = 0.0 if (c <= -3.2e+97) tmp = t_1; elseif (c <= -1.6e-9) tmp = t_0; elseif (c <= 1.5e-122) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); elseif (c <= 4.3e-44) tmp = t_0; elseif (c <= 1.5e+59) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * d) + (c * a)) / ((d * d) + (c * c)); t_1 = (a / c) + (1.0 / (c * ((c / b) / d))); tmp = 0.0; if (c <= -3.2e+97) tmp = t_1; elseif (c <= -1.6e-9) tmp = t_0; elseif (c <= 1.5e-122) tmp = (1.0 / d) * (b + (a * (c / d))); elseif (c <= 4.3e-44) tmp = t_0; elseif (c <= 1.5e+59) tmp = (b / d) + ((c / d) * (a / d)); else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(c * N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.2e+97], t$95$1, If[LessEqual[c, -1.6e-9], t$95$0, If[LessEqual[c, 1.5e-122], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.3e-44], t$95$0, If[LessEqual[c, 1.5e+59], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\
t_1 := \frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\
\mathbf{if}\;c \leq -3.2 \cdot 10^{+97}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -1.6 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{-122}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\mathbf{elif}\;c \leq 4.3 \cdot 10^{-44}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+59}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if c < -3.20000000000000016e97 or 1.5e59 < c Initial program 35.1%
Taylor expanded in c around inf 78.5%
unpow278.5%
associate-/l*79.7%
Simplified79.7%
clear-num79.7%
inv-pow79.7%
metadata-eval79.7%
sqr-pow76.1%
associate-/l/72.7%
*-commutative72.7%
times-frac73.7%
metadata-eval73.7%
metadata-eval73.7%
associate-/l/73.6%
*-commutative73.6%
times-frac78.9%
metadata-eval78.9%
metadata-eval78.9%
Applied egg-rr78.9%
pow-sqr87.7%
metadata-eval87.7%
unpow-187.7%
associate-*l/85.8%
*-lft-identity85.8%
times-frac88.7%
/-rgt-identity88.7%
Simplified88.7%
if -3.20000000000000016e97 < c < -1.60000000000000006e-9 or 1.50000000000000002e-122 < c < 4.30000000000000013e-44Initial program 75.3%
if -1.60000000000000006e-9 < c < 1.50000000000000002e-122Initial program 69.3%
Taylor expanded in c around 0 88.2%
unpow288.2%
associate-/l*89.3%
Simplified89.3%
associate-/l*94.1%
*-rgt-identity94.1%
associate-/r/94.0%
times-frac95.6%
Applied egg-rr95.6%
+-commutative95.6%
div-inv95.4%
distribute-rgt-out96.4%
div-inv96.3%
clear-num96.4%
Applied egg-rr96.4%
if 4.30000000000000013e-44 < c < 1.5e59Initial program 53.6%
Taylor expanded in c around 0 69.9%
unpow269.9%
associate-/l*69.8%
Simplified69.8%
associate-/r/65.2%
associate-*l/69.9%
*-commutative69.9%
times-frac69.9%
Applied egg-rr69.9%
Final simplification88.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.05e+88) (not (<= c 1e+57))) (+ (/ a c) (/ 1.0 (* c (/ (/ c b) d)))) (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.05e+88) || !(c <= 1e+57)) {
tmp = (a / c) + (1.0 / (c * ((c / b) / d)));
} else {
tmp = (1.0 / d) * (b + (a * (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 ((c <= (-2.05d+88)) .or. (.not. (c <= 1d+57))) then
tmp = (a / c) + (1.0d0 / (c * ((c / b) / d)))
else
tmp = (1.0d0 / d) * (b + (a * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.05e+88) || !(c <= 1e+57)) {
tmp = (a / c) + (1.0 / (c * ((c / b) / d)));
} else {
tmp = (1.0 / d) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.05e+88) or not (c <= 1e+57): tmp = (a / c) + (1.0 / (c * ((c / b) / d))) else: tmp = (1.0 / d) * (b + (a * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.05e+88) || !(c <= 1e+57)) tmp = Float64(Float64(a / c) + Float64(1.0 / Float64(c * Float64(Float64(c / b) / d)))); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.05e+88) || ~((c <= 1e+57))) tmp = (a / c) + (1.0 / (c * ((c / b) / d))); else tmp = (1.0 / d) * (b + (a * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.05e+88], N[Not[LessEqual[c, 1e+57]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(c * N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.05 \cdot 10^{+88} \lor \neg \left(c \leq 10^{+57}\right):\\
\;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if c < -2.05000000000000014e88 or 1.00000000000000005e57 < c Initial program 38.1%
Taylor expanded in c around inf 77.9%
unpow277.9%
associate-/l*78.1%
Simplified78.1%
clear-num78.1%
inv-pow78.1%
metadata-eval78.1%
sqr-pow74.6%
associate-/l/69.3%
*-commutative69.3%
times-frac70.3%
metadata-eval70.3%
metadata-eval70.3%
associate-/l/70.1%
*-commutative70.1%
times-frac75.2%
metadata-eval75.2%
metadata-eval75.2%
Applied egg-rr75.2%
pow-sqr85.6%
metadata-eval85.6%
unpow-185.6%
associate-*l/84.7%
*-lft-identity84.7%
times-frac87.4%
/-rgt-identity87.4%
Simplified87.4%
if -2.05000000000000014e88 < c < 1.00000000000000005e57Initial program 68.6%
Taylor expanded in c around 0 75.2%
unpow275.2%
associate-/l*76.4%
Simplified76.4%
associate-/l*79.5%
*-rgt-identity79.5%
associate-/r/79.5%
times-frac81.6%
Applied egg-rr81.6%
+-commutative81.6%
div-inv81.5%
distribute-rgt-out82.1%
div-inv82.1%
clear-num82.1%
Applied egg-rr82.1%
Final simplification84.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e+90) (not (<= c 3.3e+56))) (/ a c) (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e+90) || !(c <= 3.3e+56)) {
tmp = a / c;
} else {
tmp = (1.0 / d) * (b + (a * (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 ((c <= (-2.6d+90)) .or. (.not. (c <= 3.3d+56))) then
tmp = a / c
else
tmp = (1.0d0 / d) * (b + (a * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e+90) || !(c <= 3.3e+56)) {
tmp = a / c;
} else {
tmp = (1.0 / d) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.6e+90) or not (c <= 3.3e+56): tmp = a / c else: tmp = (1.0 / d) * (b + (a * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e+90) || !(c <= 3.3e+56)) tmp = Float64(a / c); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.6e+90) || ~((c <= 3.3e+56))) tmp = a / c; else tmp = (1.0 / d) * (b + (a * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e+90], N[Not[LessEqual[c, 3.3e+56]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+90} \lor \neg \left(c \leq 3.3 \cdot 10^{+56}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if c < -2.5999999999999998e90 or 3.30000000000000002e56 < c Initial program 38.1%
Taylor expanded in c around inf 77.1%
if -2.5999999999999998e90 < c < 3.30000000000000002e56Initial program 68.6%
Taylor expanded in c around 0 75.2%
unpow275.2%
associate-/l*76.4%
Simplified76.4%
associate-/l*79.5%
*-rgt-identity79.5%
associate-/r/79.5%
times-frac81.6%
Applied egg-rr81.6%
+-commutative81.6%
div-inv81.5%
distribute-rgt-out82.1%
div-inv82.1%
clear-num82.1%
Applied egg-rr82.1%
Final simplification80.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6.5e+88) (not (<= c 2.5e+57))) (+ (/ a c) (* (/ d c) (/ b c))) (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.5e+88) || !(c <= 2.5e+57)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (1.0 / d) * (b + (a * (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 ((c <= (-6.5d+88)) .or. (.not. (c <= 2.5d+57))) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = (1.0d0 / d) * (b + (a * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.5e+88) || !(c <= 2.5e+57)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (1.0 / d) * (b + (a * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6.5e+88) or not (c <= 2.5e+57): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (1.0 / d) * (b + (a * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6.5e+88) || !(c <= 2.5e+57)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6.5e+88) || ~((c <= 2.5e+57))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (1.0 / d) * (b + (a * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6.5e+88], N[Not[LessEqual[c, 2.5e+57]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.5 \cdot 10^{+88} \lor \neg \left(c \leq 2.5 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\end{array}
if c < -6.5000000000000002e88 or 2.49999999999999986e57 < c Initial program 38.1%
Taylor expanded in c around inf 77.9%
unpow277.9%
associate-/l*78.1%
Simplified78.1%
associate-/r/80.9%
associate-*l/77.9%
*-commutative77.9%
times-frac85.4%
Applied egg-rr85.4%
if -6.5000000000000002e88 < c < 2.49999999999999986e57Initial program 68.6%
Taylor expanded in c around 0 75.2%
unpow275.2%
associate-/l*76.4%
Simplified76.4%
associate-/l*79.5%
*-rgt-identity79.5%
associate-/r/79.5%
times-frac81.6%
Applied egg-rr81.6%
+-commutative81.6%
div-inv81.5%
distribute-rgt-out82.1%
div-inv82.1%
clear-num82.1%
Applied egg-rr82.1%
Final simplification83.4%
(FPCore (a b c d) :precision binary64 (if (<= c -1.8e+87) (+ (/ a c) (* d (/ b (* c c)))) (if (<= c 3e+56) (* (/ 1.0 d) (+ b (* a (/ c d)))) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.8e+87) {
tmp = (a / c) + (d * (b / (c * c)));
} else if (c <= 3e+56) {
tmp = (1.0 / d) * (b + (a * (c / d)));
} else {
tmp = a / 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 = (a / c) + (d * (b / (c * c)))
else if (c <= 3d+56) then
tmp = (1.0d0 / d) * (b + (a * (c / d)))
else
tmp = a / 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 = (a / c) + (d * (b / (c * c)));
} else if (c <= 3e+56) {
tmp = (1.0 / d) * (b + (a * (c / d)));
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.8e+87: tmp = (a / c) + (d * (b / (c * c))) elif c <= 3e+56: tmp = (1.0 / d) * (b + (a * (c / d))) else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.8e+87) tmp = Float64(Float64(a / c) + Float64(d * Float64(b / Float64(c * c)))); elseif (c <= 3e+56) tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d)))); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.8e+87) tmp = (a / c) + (d * (b / (c * c))); elseif (c <= 3e+56) tmp = (1.0 / d) * (b + (a * (c / d))); else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.8e+87], N[(N[(a / c), $MachinePrecision] + N[(d * N[(b / N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3e+56], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.8 \cdot 10^{+87}:\\
\;\;\;\;\frac{a}{c} + d \cdot \frac{b}{c \cdot c}\\
\mathbf{elif}\;c \leq 3 \cdot 10^{+56}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.79999999999999997e87Initial program 39.4%
Taylor expanded in c around inf 78.9%
unpow278.9%
associate-/l*79.5%
Simplified79.5%
associate-/r/85.5%
Applied egg-rr85.5%
if -1.79999999999999997e87 < c < 3.00000000000000006e56Initial program 68.6%
Taylor expanded in c around 0 75.2%
unpow275.2%
associate-/l*76.4%
Simplified76.4%
associate-/l*79.5%
*-rgt-identity79.5%
associate-/r/79.5%
times-frac81.6%
Applied egg-rr81.6%
+-commutative81.6%
div-inv81.5%
distribute-rgt-out82.1%
div-inv82.1%
clear-num82.1%
Applied egg-rr82.1%
if 3.00000000000000006e56 < c Initial program 36.9%
Taylor expanded in c around inf 77.1%
Final simplification81.7%
(FPCore (a b c d) :precision binary64 (if (<= c -1.7e-9) (/ a c) (if (<= c 4.4e+19) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.7e-9) {
tmp = a / c;
} else if (c <= 4.4e+19) {
tmp = b / d;
} else {
tmp = a / 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.7d-9)) then
tmp = a / c
else if (c <= 4.4d+19) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.7e-9) {
tmp = a / c;
} else if (c <= 4.4e+19) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.7e-9: tmp = a / c elif c <= 4.4e+19: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.7e-9) tmp = Float64(a / c); elseif (c <= 4.4e+19) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.7e-9) tmp = a / c; elseif (c <= 4.4e+19) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.7e-9], N[(a / c), $MachinePrecision], If[LessEqual[c, 4.4e+19], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.7 \cdot 10^{-9}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{+19}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.6999999999999999e-9 or 4.4e19 < c Initial program 44.7%
Taylor expanded in c around inf 70.0%
if -1.6999999999999999e-9 < c < 4.4e19Initial program 69.2%
Taylor expanded in c around 0 75.9%
Final simplification72.9%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 56.9%
Taylor expanded in c around inf 43.4%
Final simplification43.4%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \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, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))