
(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 9 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 (/ (+ b (* c (/ a d))) d)))
(if (<= d -7e+78)
t_0
(if (<= d -4.4e-110)
(/ (+ (* c a) (* d b)) (+ (* c c) (* d d)))
(if (<= d 2.2e+20) (/ (fma b (/ d c) a) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (c * (a / d))) / d;
double tmp;
if (d <= -7e+78) {
tmp = t_0;
} else if (d <= -4.4e-110) {
tmp = ((c * a) + (d * b)) / ((c * c) + (d * d));
} else if (d <= 2.2e+20) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(c * Float64(a / d))) / d) tmp = 0.0 if (d <= -7e+78) tmp = t_0; elseif (d <= -4.4e-110) tmp = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2.2e+20) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7e+78], t$95$0, If[LessEqual[d, -4.4e-110], N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.2e+20], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -7 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.4 \cdot 10^{-110}:\\
\;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+20}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.0000000000000003e78 or 2.2e20 < d Initial program 48.3%
fma-define48.3%
fma-define48.3%
Simplified48.3%
Taylor expanded in d around inf 80.5%
*-commutative80.5%
associate-/l*85.5%
Applied egg-rr85.5%
if -7.0000000000000003e78 < d < -4.3999999999999999e-110Initial program 90.8%
if -4.3999999999999999e-110 < d < 2.2e20Initial program 69.9%
fma-define69.9%
fma-define69.9%
Simplified69.9%
Taylor expanded in c around inf 84.9%
+-commutative84.9%
associate-/l*84.9%
fma-define84.9%
Simplified84.9%
Final simplification85.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* c (/ a d))) d)))
(if (<= d -7e+78)
t_0
(if (<= d -7.8e-110)
(/ (+ (* c a) (* d b)) (+ (* c c) (* d d)))
(if (<= d 1.05e+18) (/ (+ a (* b (/ d c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b + (c * (a / d))) / d;
double tmp;
if (d <= -7e+78) {
tmp = t_0;
} else if (d <= -7.8e-110) {
tmp = ((c * a) + (d * b)) / ((c * c) + (d * d));
} else if (d <= 1.05e+18) {
tmp = (a + (b * (d / c))) / c;
} 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 * (a / d))) / d
if (d <= (-7d+78)) then
tmp = t_0
else if (d <= (-7.8d-110)) then
tmp = ((c * a) + (d * b)) / ((c * c) + (d * d))
else if (d <= 1.05d+18) then
tmp = (a + (b * (d / c))) / c
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 * (a / d))) / d;
double tmp;
if (d <= -7e+78) {
tmp = t_0;
} else if (d <= -7.8e-110) {
tmp = ((c * a) + (d * b)) / ((c * c) + (d * d));
} else if (d <= 1.05e+18) {
tmp = (a + (b * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + (c * (a / d))) / d tmp = 0 if d <= -7e+78: tmp = t_0 elif d <= -7.8e-110: tmp = ((c * a) + (d * b)) / ((c * c) + (d * d)) elif d <= 1.05e+18: tmp = (a + (b * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(c * Float64(a / d))) / d) tmp = 0.0 if (d <= -7e+78) tmp = t_0; elseif (d <= -7.8e-110) tmp = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 1.05e+18) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + (c * (a / d))) / d; tmp = 0.0; if (d <= -7e+78) tmp = t_0; elseif (d <= -7.8e-110) tmp = ((c * a) + (d * b)) / ((c * c) + (d * d)); elseif (d <= 1.05e+18) tmp = (a + (b * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7e+78], t$95$0, If[LessEqual[d, -7.8e-110], N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.05e+18], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -7 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -7.8 \cdot 10^{-110}:\\
\;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 1.05 \cdot 10^{+18}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.0000000000000003e78 or 1.05e18 < d Initial program 48.3%
fma-define48.3%
fma-define48.3%
Simplified48.3%
Taylor expanded in d around inf 80.5%
*-commutative80.5%
associate-/l*85.5%
Applied egg-rr85.5%
if -7.0000000000000003e78 < d < -7.8e-110Initial program 90.8%
if -7.8e-110 < d < 1.05e18Initial program 69.9%
fma-define69.9%
fma-define69.9%
Simplified69.9%
fma-define69.9%
fma-define69.9%
div-inv69.9%
fma-define69.9%
fma-define69.9%
add-sqr-sqrt69.9%
pow269.9%
fma-define69.9%
hypot-define69.9%
Applied egg-rr69.9%
Taylor expanded in c around inf 84.9%
associate-/l*84.9%
Simplified84.9%
Final simplification85.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.00031) (not (<= d 2.35e+21))) (/ (+ b (* c (/ a d))) d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00031) || !(d <= 2.35e+21)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b / (c / d))) / 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 <= (-0.00031d0)) .or. (.not. (d <= 2.35d+21))) then
tmp = (b + (c * (a / d))) / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.00031) || !(d <= 2.35e+21)) {
tmp = (b + (c * (a / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.00031) or not (d <= 2.35e+21): tmp = (b + (c * (a / d))) / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.00031) || !(d <= 2.35e+21)) tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.00031) || ~((d <= 2.35e+21))) tmp = (b + (c * (a / d))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.00031], N[Not[LessEqual[d, 2.35e+21]], $MachinePrecision]], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.00031 \lor \neg \left(d \leq 2.35 \cdot 10^{+21}\right):\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -3.1e-4 or 2.35e21 < d Initial program 53.6%
fma-define53.6%
fma-define53.6%
Simplified53.6%
Taylor expanded in d around inf 80.0%
*-commutative80.0%
associate-/l*84.5%
Applied egg-rr84.5%
if -3.1e-4 < d < 2.35e21Initial program 72.3%
fma-define72.3%
fma-define72.3%
Simplified72.3%
fma-define72.3%
fma-define72.3%
div-inv72.2%
fma-define72.2%
fma-define72.3%
add-sqr-sqrt72.2%
pow272.2%
fma-define72.2%
hypot-define72.2%
Applied egg-rr72.2%
Taylor expanded in c around inf 81.2%
associate-/l*81.2%
Simplified81.2%
clear-num81.2%
un-div-inv81.2%
Applied egg-rr81.2%
Final simplification82.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.112) (not (<= d 5.5e+20))) (/ (+ b (* a (/ c d))) d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.112) || !(d <= 5.5e+20)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / d))) / 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 <= (-0.112d0)) .or. (.not. (d <= 5.5d+20))) then
tmp = (b + (a * (c / d))) / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.112) || !(d <= 5.5e+20)) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.112) or not (d <= 5.5e+20): tmp = (b + (a * (c / d))) / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.112) || !(d <= 5.5e+20)) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.112) || ~((d <= 5.5e+20))) tmp = (b + (a * (c / d))) / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.112], N[Not[LessEqual[d, 5.5e+20]], $MachinePrecision]], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.112 \lor \neg \left(d \leq 5.5 \cdot 10^{+20}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -0.112000000000000002 or 5.5e20 < d Initial program 53.6%
fma-define53.6%
fma-define53.6%
Simplified53.6%
Taylor expanded in d around inf 80.0%
associate-/l*82.1%
Simplified82.1%
if -0.112000000000000002 < d < 5.5e20Initial program 72.3%
fma-define72.3%
fma-define72.3%
Simplified72.3%
fma-define72.3%
fma-define72.3%
div-inv72.2%
fma-define72.2%
fma-define72.3%
add-sqr-sqrt72.2%
pow272.2%
fma-define72.2%
hypot-define72.2%
Applied egg-rr72.2%
Taylor expanded in c around inf 81.2%
associate-/l*81.2%
Simplified81.2%
clear-num81.2%
un-div-inv81.2%
Applied egg-rr81.2%
Final simplification81.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.0) (not (<= d 6e+19))) (/ b d) (/ (+ a (/ b (/ c d))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.0) || !(d <= 6e+19)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / 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 <= (-7.0d0)) .or. (.not. (d <= 6d+19))) then
tmp = b / d
else
tmp = (a + (b / (c / d))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.0) || !(d <= 6e+19)) {
tmp = b / d;
} else {
tmp = (a + (b / (c / d))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.0) or not (d <= 6e+19): tmp = b / d else: tmp = (a + (b / (c / d))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.0) || !(d <= 6e+19)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -7.0) || ~((d <= 6e+19))) tmp = b / d; else tmp = (a + (b / (c / d))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.0], N[Not[LessEqual[d, 6e+19]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \lor \neg \left(d \leq 6 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\
\end{array}
\end{array}
if d < -7 or 6e19 < d Initial program 53.6%
fma-define53.6%
fma-define53.6%
Simplified53.6%
Taylor expanded in c around 0 68.6%
if -7 < d < 6e19Initial program 72.3%
fma-define72.3%
fma-define72.3%
Simplified72.3%
fma-define72.3%
fma-define72.3%
div-inv72.2%
fma-define72.2%
fma-define72.3%
add-sqr-sqrt72.2%
pow272.2%
fma-define72.2%
hypot-define72.2%
Applied egg-rr72.2%
Taylor expanded in c around inf 81.2%
associate-/l*81.2%
Simplified81.2%
clear-num81.2%
un-div-inv81.2%
Applied egg-rr81.2%
Final simplification75.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -0.46) (not (<= d 1.1e+20))) (/ b d) (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -0.46) || !(d <= 1.1e+20)) {
tmp = b / d;
} else {
tmp = (a + (b * (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 <= (-0.46d0)) .or. (.not. (d <= 1.1d+20))) then
tmp = b / d
else
tmp = (a + (b * (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 <= -0.46) || !(d <= 1.1e+20)) {
tmp = b / d;
} else {
tmp = (a + (b * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -0.46) or not (d <= 1.1e+20): tmp = b / d else: tmp = (a + (b * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -0.46) || !(d <= 1.1e+20)) tmp = Float64(b / d); else tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -0.46) || ~((d <= 1.1e+20))) tmp = b / d; else tmp = (a + (b * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -0.46], N[Not[LessEqual[d, 1.1e+20]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.46 \lor \neg \left(d \leq 1.1 \cdot 10^{+20}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -0.46000000000000002 or 1.1e20 < d Initial program 53.6%
fma-define53.6%
fma-define53.6%
Simplified53.6%
Taylor expanded in c around 0 68.6%
if -0.46000000000000002 < d < 1.1e20Initial program 72.3%
fma-define72.3%
fma-define72.3%
Simplified72.3%
fma-define72.3%
fma-define72.3%
div-inv72.2%
fma-define72.2%
fma-define72.3%
add-sqr-sqrt72.2%
pow272.2%
fma-define72.2%
hypot-define72.2%
Applied egg-rr72.2%
Taylor expanded in c around inf 81.2%
associate-/l*81.2%
Simplified81.2%
Final simplification75.5%
(FPCore (a b c d) :precision binary64 (if (<= c -4.3e-16) (/ a c) (if (<= c 6.6e-24) (/ b d) (/ 1.0 (/ c a)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.3e-16) {
tmp = a / c;
} else if (c <= 6.6e-24) {
tmp = b / d;
} else {
tmp = 1.0 / (c / a);
}
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.3d-16)) then
tmp = a / c
else if (c <= 6.6d-24) then
tmp = b / d
else
tmp = 1.0d0 / (c / a)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.3e-16) {
tmp = a / c;
} else if (c <= 6.6e-24) {
tmp = b / d;
} else {
tmp = 1.0 / (c / a);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.3e-16: tmp = a / c elif c <= 6.6e-24: tmp = b / d else: tmp = 1.0 / (c / a) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.3e-16) tmp = Float64(a / c); elseif (c <= 6.6e-24) tmp = Float64(b / d); else tmp = Float64(1.0 / Float64(c / a)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -4.3e-16) tmp = a / c; elseif (c <= 6.6e-24) tmp = b / d; else tmp = 1.0 / (c / a); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.3e-16], N[(a / c), $MachinePrecision], If[LessEqual[c, 6.6e-24], N[(b / d), $MachinePrecision], N[(1.0 / N[(c / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.3 \cdot 10^{-16}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 6.6 \cdot 10^{-24}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{c}{a}}\\
\end{array}
\end{array}
if c < -4.2999999999999999e-16Initial program 55.9%
fma-define55.9%
fma-define55.9%
Simplified55.9%
Taylor expanded in c around inf 73.6%
if -4.2999999999999999e-16 < c < 6.59999999999999968e-24Initial program 78.3%
fma-define78.3%
fma-define78.3%
Simplified78.3%
Taylor expanded in c around 0 70.7%
if 6.59999999999999968e-24 < c Initial program 45.6%
fma-define45.6%
fma-define45.6%
Simplified45.6%
Taylor expanded in c around inf 56.2%
clear-num56.8%
inv-pow56.8%
Applied egg-rr56.8%
unpow-156.8%
Simplified56.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.5e-16) (not (<= c 6.6e-24))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.5e-16) || !(c <= 6.6e-24)) {
tmp = a / c;
} else {
tmp = b / 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.5d-16)) .or. (.not. (c <= 6.6d-24))) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.5e-16) || !(c <= 6.6e-24)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.5e-16) or not (c <= 6.6e-24): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.5e-16) || !(c <= 6.6e-24)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.5e-16) || ~((c <= 6.6e-24))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.5e-16], N[Not[LessEqual[c, 6.6e-24]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.5 \cdot 10^{-16} \lor \neg \left(c \leq 6.6 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -4.5000000000000002e-16 or 6.59999999999999968e-24 < c Initial program 51.0%
fma-define51.0%
fma-define51.0%
Simplified51.0%
Taylor expanded in c around inf 65.3%
if -4.5000000000000002e-16 < c < 6.59999999999999968e-24Initial program 78.3%
fma-define78.3%
fma-define78.3%
Simplified78.3%
Taylor expanded in c around 0 70.7%
Final simplification67.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 63.9%
fma-define63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in c around inf 40.6%
(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 2024129
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))