
(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 d) (/ (* (/ a d) c) d))))
(if (<= d -1.2e+83)
t_0
(if (<= d -1.2e-131)
(* (/ 1.0 (+ (* c c) (* d d))) (+ (* a c) (* d b)))
(if (<= d 9.2e+74) (/ (+ a (* (* d b) (/ 1.0 c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (((a / d) * c) / d);
double tmp;
if (d <= -1.2e+83) {
tmp = t_0;
} else if (d <= -1.2e-131) {
tmp = (1.0 / ((c * c) + (d * d))) * ((a * c) + (d * b));
} else if (d <= 9.2e+74) {
tmp = (a + ((d * b) * (1.0 / 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 / d) + (((a / d) * c) / d)
if (d <= (-1.2d+83)) then
tmp = t_0
else if (d <= (-1.2d-131)) then
tmp = (1.0d0 / ((c * c) + (d * d))) * ((a * c) + (d * b))
else if (d <= 9.2d+74) then
tmp = (a + ((d * b) * (1.0d0 / 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 / d) + (((a / d) * c) / d);
double tmp;
if (d <= -1.2e+83) {
tmp = t_0;
} else if (d <= -1.2e-131) {
tmp = (1.0 / ((c * c) + (d * d))) * ((a * c) + (d * b));
} else if (d <= 9.2e+74) {
tmp = (a + ((d * b) * (1.0 / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + (((a / d) * c) / d) tmp = 0 if d <= -1.2e+83: tmp = t_0 elif d <= -1.2e-131: tmp = (1.0 / ((c * c) + (d * d))) * ((a * c) + (d * b)) elif d <= 9.2e+74: tmp = (a + ((d * b) * (1.0 / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(Float64(a / d) * c) / d)) tmp = 0.0 if (d <= -1.2e+83) tmp = t_0; elseif (d <= -1.2e-131) tmp = Float64(Float64(1.0 / Float64(Float64(c * c) + Float64(d * d))) * Float64(Float64(a * c) + Float64(d * b))); elseif (d <= 9.2e+74) tmp = Float64(Float64(a + Float64(Float64(d * b) * Float64(1.0 / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + (((a / d) * c) / d); tmp = 0.0; if (d <= -1.2e+83) tmp = t_0; elseif (d <= -1.2e-131) tmp = (1.0 / ((c * c) + (d * d))) * ((a * c) + (d * b)); elseif (d <= 9.2e+74) tmp = (a + ((d * b) * (1.0 / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a / d), $MachinePrecision] * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+83], t$95$0, If[LessEqual[d, -1.2e-131], N[(N[(1.0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9.2e+74], N[(N[(a + N[(N[(d * b), $MachinePrecision] * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{\frac{a}{d} \cdot c}{d}\\
\mathbf{if}\;d \leq -1.2 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.2 \cdot 10^{-131}:\\
\;\;\;\;\frac{1}{c \cdot c + d \cdot d} \cdot \left(a \cdot c + d \cdot b\right)\\
\mathbf{elif}\;d \leq 9.2 \cdot 10^{+74}:\\
\;\;\;\;\frac{a + \left(d \cdot b\right) \cdot \frac{1}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.19999999999999996e83 or 9.1999999999999994e74 < d Initial program 35.4%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6481.6%
Simplified81.6%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6484.2%
Applied egg-rr84.2%
if -1.19999999999999996e83 < d < -1.2e-131Initial program 88.3%
div-invN/A
flip-+N/A
clear-numN/A
*-commutativeN/A
*-lowering-*.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6488.3%
Applied egg-rr88.3%
if -1.2e-131 < d < 9.1999999999999994e74Initial program 66.1%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6486.1%
Simplified86.1%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6486.2%
Applied egg-rr86.2%
Final simplification85.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (/ (* (/ a d) c) d))))
(if (<= d -6e+36)
t_0
(if (<= d -3.7e-112)
(/ (+ (* a c) (* d b)) (+ (* c c) (* d d)))
(if (<= d 7.7e+74) (/ (+ a (/ 1.0 (/ c (* d b)))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (((a / d) * c) / d);
double tmp;
if (d <= -6e+36) {
tmp = t_0;
} else if (d <= -3.7e-112) {
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d));
} else if (d <= 7.7e+74) {
tmp = (a + (1.0 / (c / (d * b)))) / 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 / d) + (((a / d) * c) / d)
if (d <= (-6d+36)) then
tmp = t_0
else if (d <= (-3.7d-112)) then
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d))
else if (d <= 7.7d+74) then
tmp = (a + (1.0d0 / (c / (d * b)))) / 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 / d) + (((a / d) * c) / d);
double tmp;
if (d <= -6e+36) {
tmp = t_0;
} else if (d <= -3.7e-112) {
tmp = ((a * c) + (d * b)) / ((c * c) + (d * d));
} else if (d <= 7.7e+74) {
tmp = (a + (1.0 / (c / (d * b)))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + (((a / d) * c) / d) tmp = 0 if d <= -6e+36: tmp = t_0 elif d <= -3.7e-112: tmp = ((a * c) + (d * b)) / ((c * c) + (d * d)) elif d <= 7.7e+74: tmp = (a + (1.0 / (c / (d * b)))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(Float64(a / d) * c) / d)) tmp = 0.0 if (d <= -6e+36) tmp = t_0; elseif (d <= -3.7e-112) tmp = Float64(Float64(Float64(a * c) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 7.7e+74) tmp = Float64(Float64(a + Float64(1.0 / Float64(c / Float64(d * b)))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + (((a / d) * c) / d); tmp = 0.0; if (d <= -6e+36) tmp = t_0; elseif (d <= -3.7e-112) tmp = ((a * c) + (d * b)) / ((c * c) + (d * d)); elseif (d <= 7.7e+74) tmp = (a + (1.0 / (c / (d * b)))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a / d), $MachinePrecision] * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6e+36], t$95$0, If[LessEqual[d, -3.7e-112], N[(N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.7e+74], N[(N[(a + N[(1.0 / N[(c / N[(d * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{\frac{a}{d} \cdot c}{d}\\
\mathbf{if}\;d \leq -6 \cdot 10^{+36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -3.7 \cdot 10^{-112}:\\
\;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 7.7 \cdot 10^{+74}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{c}{d \cdot b}}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6e36 or 7.70000000000000042e74 < d Initial program 38.8%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6480.1%
Simplified80.1%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6482.5%
Applied egg-rr82.5%
if -6e36 < d < -3.6999999999999998e-112Initial program 94.3%
if -3.6999999999999998e-112 < d < 7.70000000000000042e74Initial program 66.7%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6486.4%
Simplified86.4%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6486.4%
Applied egg-rr86.4%
Final simplification85.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (/ (* (/ a d) c) d))))
(if (<= d -11500000.0)
t_0
(if (<= d 7.7e+74) (/ (+ a (/ 1.0 (/ c (* d b)))) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (((a / d) * c) / d);
double tmp;
if (d <= -11500000.0) {
tmp = t_0;
} else if (d <= 7.7e+74) {
tmp = (a + (1.0 / (c / (d * b)))) / 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 / d) + (((a / d) * c) / d)
if (d <= (-11500000.0d0)) then
tmp = t_0
else if (d <= 7.7d+74) then
tmp = (a + (1.0d0 / (c / (d * b)))) / 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 / d) + (((a / d) * c) / d);
double tmp;
if (d <= -11500000.0) {
tmp = t_0;
} else if (d <= 7.7e+74) {
tmp = (a + (1.0 / (c / (d * b)))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + (((a / d) * c) / d) tmp = 0 if d <= -11500000.0: tmp = t_0 elif d <= 7.7e+74: tmp = (a + (1.0 / (c / (d * b)))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(Float64(a / d) * c) / d)) tmp = 0.0 if (d <= -11500000.0) tmp = t_0; elseif (d <= 7.7e+74) tmp = Float64(Float64(a + Float64(1.0 / Float64(c / Float64(d * b)))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + (((a / d) * c) / d); tmp = 0.0; if (d <= -11500000.0) tmp = t_0; elseif (d <= 7.7e+74) tmp = (a + (1.0 / (c / (d * b)))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a / d), $MachinePrecision] * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -11500000.0], t$95$0, If[LessEqual[d, 7.7e+74], N[(N[(a + N[(1.0 / N[(c / N[(d * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{\frac{a}{d} \cdot c}{d}\\
\mathbf{if}\;d \leq -11500000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.7 \cdot 10^{+74}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{c}{d \cdot b}}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.15e7 or 7.70000000000000042e74 < d Initial program 42.4%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6479.7%
Simplified79.7%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6481.9%
Applied egg-rr81.9%
if -1.15e7 < d < 7.70000000000000042e74Initial program 72.5%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6481.0%
Simplified81.0%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6481.0%
Applied egg-rr81.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (/ (* (/ a d) c) d))))
(if (<= d -5200000.0)
t_0
(if (<= d 7.8e+74) (/ (+ a (* (* d b) (/ 1.0 c))) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (((a / d) * c) / d);
double tmp;
if (d <= -5200000.0) {
tmp = t_0;
} else if (d <= 7.8e+74) {
tmp = (a + ((d * b) * (1.0 / 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 / d) + (((a / d) * c) / d)
if (d <= (-5200000.0d0)) then
tmp = t_0
else if (d <= 7.8d+74) then
tmp = (a + ((d * b) * (1.0d0 / 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 / d) + (((a / d) * c) / d);
double tmp;
if (d <= -5200000.0) {
tmp = t_0;
} else if (d <= 7.8e+74) {
tmp = (a + ((d * b) * (1.0 / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + (((a / d) * c) / d) tmp = 0 if d <= -5200000.0: tmp = t_0 elif d <= 7.8e+74: tmp = (a + ((d * b) * (1.0 / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(Float64(a / d) * c) / d)) tmp = 0.0 if (d <= -5200000.0) tmp = t_0; elseif (d <= 7.8e+74) tmp = Float64(Float64(a + Float64(Float64(d * b) * Float64(1.0 / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + (((a / d) * c) / d); tmp = 0.0; if (d <= -5200000.0) tmp = t_0; elseif (d <= 7.8e+74) tmp = (a + ((d * b) * (1.0 / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a / d), $MachinePrecision] * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5200000.0], t$95$0, If[LessEqual[d, 7.8e+74], N[(N[(a + N[(N[(d * b), $MachinePrecision] * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{\frac{a}{d} \cdot c}{d}\\
\mathbf{if}\;d \leq -5200000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.8 \cdot 10^{+74}:\\
\;\;\;\;\frac{a + \left(d \cdot b\right) \cdot \frac{1}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -5.2e6 or 7.80000000000000015e74 < d Initial program 42.4%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6479.7%
Simplified79.7%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6481.9%
Applied egg-rr81.9%
if -5.2e6 < d < 7.80000000000000015e74Initial program 72.5%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6481.0%
Simplified81.0%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6481.0%
Applied egg-rr81.0%
Final simplification81.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (/ (* (/ a d) c) d))))
(if (<= d -5600000.0)
t_0
(if (<= d 7.7e+74) (/ (+ a (/ (* d b) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (((a / d) * c) / d);
double tmp;
if (d <= -5600000.0) {
tmp = t_0;
} else if (d <= 7.7e+74) {
tmp = (a + ((d * b) / 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 / d) + (((a / d) * c) / d)
if (d <= (-5600000.0d0)) then
tmp = t_0
else if (d <= 7.7d+74) then
tmp = (a + ((d * b) / 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 / d) + (((a / d) * c) / d);
double tmp;
if (d <= -5600000.0) {
tmp = t_0;
} else if (d <= 7.7e+74) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + (((a / d) * c) / d) tmp = 0 if d <= -5600000.0: tmp = t_0 elif d <= 7.7e+74: tmp = (a + ((d * b) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(Float64(a / d) * c) / d)) tmp = 0.0 if (d <= -5600000.0) tmp = t_0; elseif (d <= 7.7e+74) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + (((a / d) * c) / d); tmp = 0.0; if (d <= -5600000.0) tmp = t_0; elseif (d <= 7.7e+74) tmp = (a + ((d * b) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a / d), $MachinePrecision] * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5600000.0], t$95$0, If[LessEqual[d, 7.7e+74], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{\frac{a}{d} \cdot c}{d}\\
\mathbf{if}\;d \leq -5600000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.7 \cdot 10^{+74}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -5.6e6 or 7.70000000000000042e74 < d Initial program 42.4%
Taylor expanded in c around 0
*-commutativeN/A
associate-*r/N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
associate-*r/N/A
*-commutativeN/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6479.7%
Simplified79.7%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6481.9%
Applied egg-rr81.9%
if -5.6e6 < d < 7.70000000000000042e74Initial program 72.5%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6481.0%
Simplified81.0%
Final simplification81.4%
(FPCore (a b c d) :precision binary64 (if (<= d -7000000.0) (/ (+ b (/ (* a c) d)) d) (if (<= d 7.7e+74) (/ (+ a (/ (* d b) c)) c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7000000.0) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= 7.7e+74) {
tmp = (a + ((d * b) / c)) / 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 (d <= (-7000000.0d0)) then
tmp = (b + ((a * c) / d)) / d
else if (d <= 7.7d+74) then
tmp = (a + ((d * b) / c)) / 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 (d <= -7000000.0) {
tmp = (b + ((a * c) / d)) / d;
} else if (d <= 7.7e+74) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -7000000.0: tmp = (b + ((a * c) / d)) / d elif d <= 7.7e+74: tmp = (a + ((d * b) / c)) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -7000000.0) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (d <= 7.7e+74) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -7000000.0) tmp = (b + ((a * c) / d)) / d; elseif (d <= 7.7e+74) tmp = (a + ((d * b) / c)) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -7000000.0], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 7.7e+74], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7000000:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;d \leq 7.7 \cdot 10^{+74}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -7e6Initial program 46.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6482.9%
Simplified82.9%
if -7e6 < d < 7.70000000000000042e74Initial program 72.5%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6481.0%
Simplified81.0%
if 7.70000000000000042e74 < d Initial program 36.0%
Taylor expanded in c around 0
/-lowering-/.f6474.5%
Simplified74.5%
Final simplification80.4%
(FPCore (a b c d) :precision binary64 (if (<= d -1.45e+41) (/ b d) (if (<= d 7.7e+74) (/ (+ a (/ (* d b) c)) c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.45e+41) {
tmp = b / d;
} else if (d <= 7.7e+74) {
tmp = (a + ((d * b) / c)) / 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 (d <= (-1.45d+41)) then
tmp = b / d
else if (d <= 7.7d+74) then
tmp = (a + ((d * b) / c)) / 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 (d <= -1.45e+41) {
tmp = b / d;
} else if (d <= 7.7e+74) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.45e+41: tmp = b / d elif d <= 7.7e+74: tmp = (a + ((d * b) / c)) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.45e+41) tmp = Float64(b / d); elseif (d <= 7.7e+74) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.45e+41) tmp = b / d; elseif (d <= 7.7e+74) tmp = (a + ((d * b) / c)) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.45e+41], N[(b / d), $MachinePrecision], If[LessEqual[d, 7.7e+74], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.45 \cdot 10^{+41}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 7.7 \cdot 10^{+74}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.44999999999999994e41 or 7.70000000000000042e74 < d Initial program 39.2%
Taylor expanded in c around 0
/-lowering-/.f6476.2%
Simplified76.2%
if -1.44999999999999994e41 < d < 7.70000000000000042e74Initial program 73.3%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6478.7%
Simplified78.7%
Final simplification77.6%
(FPCore (a b c d) :precision binary64 (if (<= d -45000000000000.0) (/ b d) (if (<= d 1e+78) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -45000000000000.0) {
tmp = b / d;
} else if (d <= 1e+78) {
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 (d <= (-45000000000000.0d0)) then
tmp = b / d
else if (d <= 1d+78) 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 (d <= -45000000000000.0) {
tmp = b / d;
} else if (d <= 1e+78) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -45000000000000.0: tmp = b / d elif d <= 1e+78: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -45000000000000.0) tmp = Float64(b / d); elseif (d <= 1e+78) 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 (d <= -45000000000000.0) tmp = b / d; elseif (d <= 1e+78) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -45000000000000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 1e+78], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -45000000000000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 10^{+78}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -4.5e13 or 1.00000000000000001e78 < d Initial program 41.9%
Taylor expanded in c around 0
/-lowering-/.f6474.4%
Simplified74.4%
if -4.5e13 < d < 1.00000000000000001e78Initial program 72.7%
Taylor expanded in c around inf
/-lowering-/.f6466.0%
Simplified66.0%
(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 58.4%
Taylor expanded in c around inf
/-lowering-/.f6444.7%
Simplified44.7%
(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 2024158
(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))))