
(FPCore (x y) :precision binary64 (* x (/ (sin y) y)))
double code(double x, double y) {
return x * (sin(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (sin(y) / y)
end function
public static double code(double x, double y) {
return x * (Math.sin(y) / y);
}
def code(x, y): return x * (math.sin(y) / y)
function code(x, y) return Float64(x * Float64(sin(y) / y)) end
function tmp = code(x, y) tmp = x * (sin(y) / y); end
code[x_, y_] := N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\sin y}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (/ (sin y) y)))
double code(double x, double y) {
return x * (sin(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (sin(y) / y)
end function
public static double code(double x, double y) {
return x * (Math.sin(y) / y);
}
def code(x, y): return x * (math.sin(y) / y)
function code(x, y) return Float64(x * Float64(sin(y) / y)) end
function tmp = code(x, y) tmp = x * (sin(y) / y); end
code[x_, y_] := N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\sin y}{y}
\end{array}
(FPCore (x y) :precision binary64 (/ x (/ y (sin y))))
double code(double x, double y) {
return x / (y / sin(y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y / sin(y))
end function
public static double code(double x, double y) {
return x / (y / Math.sin(y));
}
def code(x, y): return x / (y / math.sin(y))
function code(x, y) return Float64(x / Float64(y / sin(y))) end
function tmp = code(x, y) tmp = x / (y / sin(y)); end
code[x_, y_] := N[(x / N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{y}{\sin y}}
\end{array}
Initial program 99.8%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (* x (/ (sin y) y)))
double code(double x, double y) {
return x * (sin(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (sin(y) / y)
end function
public static double code(double x, double y) {
return x * (Math.sin(y) / y);
}
def code(x, y): return x * (math.sin(y) / y)
function code(x, y) return Float64(x * Float64(sin(y) / y)) end
function tmp = code(x, y) tmp = x * (sin(y) / y); end
code[x_, y_] := N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\sin y}{y}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(if (<= y -2.85e+29)
(/ x (/ (* y y) 6.0))
(if (<= y 6.4)
(* x (+ 1.0 (* (* y y) -0.16666666666666666)))
(* 6.0 (/ (/ x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.85e+29) {
tmp = x / ((y * y) / 6.0);
} else if (y <= 6.4) {
tmp = x * (1.0 + ((y * y) * -0.16666666666666666));
} else {
tmp = 6.0 * ((x / y) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.85d+29)) then
tmp = x / ((y * y) / 6.0d0)
else if (y <= 6.4d0) then
tmp = x * (1.0d0 + ((y * y) * (-0.16666666666666666d0)))
else
tmp = 6.0d0 * ((x / y) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.85e+29) {
tmp = x / ((y * y) / 6.0);
} else if (y <= 6.4) {
tmp = x * (1.0 + ((y * y) * -0.16666666666666666));
} else {
tmp = 6.0 * ((x / y) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.85e+29: tmp = x / ((y * y) / 6.0) elif y <= 6.4: tmp = x * (1.0 + ((y * y) * -0.16666666666666666)) else: tmp = 6.0 * ((x / y) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.85e+29) tmp = Float64(x / Float64(Float64(y * y) / 6.0)); elseif (y <= 6.4) tmp = Float64(x * Float64(1.0 + Float64(Float64(y * y) * -0.16666666666666666))); else tmp = Float64(6.0 * Float64(Float64(x / y) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.85e+29) tmp = x / ((y * y) / 6.0); elseif (y <= 6.4) tmp = x * (1.0 + ((y * y) * -0.16666666666666666)); else tmp = 6.0 * ((x / y) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.85e+29], N[(x / N[(N[(y * y), $MachinePrecision] / 6.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.4], N[(x * N[(1.0 + N[(N[(y * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(6.0 * N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.85 \cdot 10^{+29}:\\
\;\;\;\;\frac{x}{\frac{y \cdot y}{6}}\\
\mathbf{elif}\;y \leq 6.4:\\
\;\;\;\;x \cdot \left(1 + \left(y \cdot y\right) \cdot -0.16666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;6 \cdot \frac{\frac{x}{y}}{y}\\
\end{array}
\end{array}
if y < -2.85e29Initial program 99.6%
clear-num99.5%
un-div-inv99.5%
Applied egg-rr99.5%
Taylor expanded in y around 0 27.0%
unpow227.0%
associate-*r*27.0%
Simplified27.0%
Taylor expanded in y around inf 27.0%
unpow227.0%
associate-/r*27.0%
Simplified27.0%
associate-/l/27.0%
associate-*r/27.0%
*-commutative27.0%
associate-/l*27.0%
Applied egg-rr27.0%
if -2.85e29 < y < 6.4000000000000004Initial program 100.0%
Taylor expanded in y around 0 94.5%
unpow294.5%
Simplified94.5%
if 6.4000000000000004 < y Initial program 99.6%
clear-num99.6%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 23.5%
unpow223.5%
associate-*r*23.5%
Simplified23.5%
Taylor expanded in y around inf 23.5%
unpow223.5%
associate-/r*23.5%
Simplified23.5%
Final simplification61.8%
(FPCore (x y) :precision binary64 (if (or (<= y -2.5) (not (<= y 2.45))) (* 6.0 (/ (/ x y) y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -2.5) || !(y <= 2.45)) {
tmp = 6.0 * ((x / y) / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2.5d0)) .or. (.not. (y <= 2.45d0))) then
tmp = 6.0d0 * ((x / y) / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.5) || !(y <= 2.45)) {
tmp = 6.0 * ((x / y) / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.5) or not (y <= 2.45): tmp = 6.0 * ((x / y) / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.5) || !(y <= 2.45)) tmp = Float64(6.0 * Float64(Float64(x / y) / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.5) || ~((y <= 2.45))) tmp = 6.0 * ((x / y) / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.5], N[Not[LessEqual[y, 2.45]], $MachinePrecision]], N[(6.0 * N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \lor \neg \left(y \leq 2.45\right):\\
\;\;\;\;6 \cdot \frac{\frac{x}{y}}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.5 or 2.4500000000000002 < y Initial program 99.6%
clear-num99.5%
un-div-inv99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 24.0%
unpow224.0%
associate-*r*24.0%
Simplified24.0%
Taylor expanded in y around inf 24.0%
unpow224.0%
associate-/r*24.1%
Simplified24.1%
if -2.5 < y < 2.4500000000000002Initial program 100.0%
Taylor expanded in y around 0 99.8%
Final simplification61.6%
(FPCore (x y) :precision binary64 (if (<= y -2.5) (/ 6.0 (* y (/ y x))) (if (<= y 2.45) x (* 6.0 (/ (/ x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.5) {
tmp = 6.0 / (y * (y / x));
} else if (y <= 2.45) {
tmp = x;
} else {
tmp = 6.0 * ((x / y) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.5d0)) then
tmp = 6.0d0 / (y * (y / x))
else if (y <= 2.45d0) then
tmp = x
else
tmp = 6.0d0 * ((x / y) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.5) {
tmp = 6.0 / (y * (y / x));
} else if (y <= 2.45) {
tmp = x;
} else {
tmp = 6.0 * ((x / y) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5: tmp = 6.0 / (y * (y / x)) elif y <= 2.45: tmp = x else: tmp = 6.0 * ((x / y) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5) tmp = Float64(6.0 / Float64(y * Float64(y / x))); elseif (y <= 2.45) tmp = x; else tmp = Float64(6.0 * Float64(Float64(x / y) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.5) tmp = 6.0 / (y * (y / x)); elseif (y <= 2.45) tmp = x; else tmp = 6.0 * ((x / y) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5], N[(6.0 / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.45], x, N[(6.0 * N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5:\\
\;\;\;\;\frac{6}{y \cdot \frac{y}{x}}\\
\mathbf{elif}\;y \leq 2.45:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;6 \cdot \frac{\frac{x}{y}}{y}\\
\end{array}
\end{array}
if y < -2.5Initial program 99.5%
clear-num99.5%
un-div-inv99.5%
Applied egg-rr99.5%
Taylor expanded in y around 0 24.5%
unpow224.5%
associate-*r*24.5%
Simplified24.5%
Taylor expanded in y around inf 24.5%
unpow224.5%
associate-/r*24.5%
Simplified24.5%
associate-*r/24.5%
associate-/l*24.5%
div-inv24.5%
clear-num24.5%
Applied egg-rr24.5%
if -2.5 < y < 2.4500000000000002Initial program 100.0%
Taylor expanded in y around 0 99.8%
if 2.4500000000000002 < y Initial program 99.6%
clear-num99.6%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 23.5%
unpow223.5%
associate-*r*23.5%
Simplified23.5%
Taylor expanded in y around inf 23.5%
unpow223.5%
associate-/r*23.5%
Simplified23.5%
Final simplification61.6%
(FPCore (x y) :precision binary64 (if (<= y -2.5) (/ x (/ (* y y) 6.0)) (if (<= y 2.45) x (* 6.0 (/ (/ x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.5) {
tmp = x / ((y * y) / 6.0);
} else if (y <= 2.45) {
tmp = x;
} else {
tmp = 6.0 * ((x / y) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.5d0)) then
tmp = x / ((y * y) / 6.0d0)
else if (y <= 2.45d0) then
tmp = x
else
tmp = 6.0d0 * ((x / y) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.5) {
tmp = x / ((y * y) / 6.0);
} else if (y <= 2.45) {
tmp = x;
} else {
tmp = 6.0 * ((x / y) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5: tmp = x / ((y * y) / 6.0) elif y <= 2.45: tmp = x else: tmp = 6.0 * ((x / y) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5) tmp = Float64(x / Float64(Float64(y * y) / 6.0)); elseif (y <= 2.45) tmp = x; else tmp = Float64(6.0 * Float64(Float64(x / y) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.5) tmp = x / ((y * y) / 6.0); elseif (y <= 2.45) tmp = x; else tmp = 6.0 * ((x / y) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5], N[(x / N[(N[(y * y), $MachinePrecision] / 6.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.45], x, N[(6.0 * N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5:\\
\;\;\;\;\frac{x}{\frac{y \cdot y}{6}}\\
\mathbf{elif}\;y \leq 2.45:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;6 \cdot \frac{\frac{x}{y}}{y}\\
\end{array}
\end{array}
if y < -2.5Initial program 99.5%
clear-num99.5%
un-div-inv99.5%
Applied egg-rr99.5%
Taylor expanded in y around 0 24.5%
unpow224.5%
associate-*r*24.5%
Simplified24.5%
Taylor expanded in y around inf 24.5%
unpow224.5%
associate-/r*24.5%
Simplified24.5%
associate-/l/24.5%
associate-*r/24.5%
*-commutative24.5%
associate-/l*24.5%
Applied egg-rr24.5%
if -2.5 < y < 2.4500000000000002Initial program 100.0%
Taylor expanded in y around 0 99.8%
if 2.4500000000000002 < y Initial program 99.6%
clear-num99.6%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 23.5%
unpow223.5%
associate-*r*23.5%
Simplified23.5%
Taylor expanded in y around inf 23.5%
unpow223.5%
associate-/r*23.5%
Simplified23.5%
Final simplification61.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.1e+99) (not (<= y 5e-41))) (* y (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -1.1e+99) || !(y <= 5e-41)) {
tmp = y * (x / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.1d+99)) .or. (.not. (y <= 5d-41))) then
tmp = y * (x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.1e+99) || !(y <= 5e-41)) {
tmp = y * (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.1e+99) or not (y <= 5e-41): tmp = y * (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.1e+99) || !(y <= 5e-41)) tmp = Float64(y * Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.1e+99) || ~((y <= 5e-41))) tmp = y * (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.1e+99], N[Not[LessEqual[y, 5e-41]], $MachinePrecision]], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+99} \lor \neg \left(y \leq 5 \cdot 10^{-41}\right):\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.09999999999999989e99 or 4.9999999999999996e-41 < y Initial program 99.6%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around 0 9.0%
associate-/l*30.5%
div-inv30.5%
clear-num28.3%
Applied egg-rr28.3%
if -1.09999999999999989e99 < y < 4.9999999999999996e-41Initial program 99.9%
Taylor expanded in y around 0 85.3%
Final simplification60.1%
(FPCore (x y) :precision binary64 (if (or (<= y -5e+129) (not (<= y 7e-73))) (/ y (/ y x)) x))
double code(double x, double y) {
double tmp;
if ((y <= -5e+129) || !(y <= 7e-73)) {
tmp = y / (y / x);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-5d+129)) .or. (.not. (y <= 7d-73))) then
tmp = y / (y / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -5e+129) || !(y <= 7e-73)) {
tmp = y / (y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+129) or not (y <= 7e-73): tmp = y / (y / x) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+129) || !(y <= 7e-73)) tmp = Float64(y / Float64(y / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -5e+129) || ~((y <= 7e-73))) tmp = y / (y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+129], N[Not[LessEqual[y, 7e-73]], $MachinePrecision]], N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+129} \lor \neg \left(y \leq 7 \cdot 10^{-73}\right):\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.0000000000000003e129 or 6.9999999999999995e-73 < y Initial program 99.6%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around 0 14.9%
associate-/l*36.1%
div-inv36.1%
clear-num34.0%
Applied egg-rr34.0%
clear-num36.1%
un-div-inv36.1%
Applied egg-rr36.1%
if -5.0000000000000003e129 < y < 6.9999999999999995e-73Initial program 99.9%
Taylor expanded in y around 0 81.1%
Final simplification61.1%
(FPCore (x y) :precision binary64 (/ x (+ 1.0 (* 0.16666666666666666 (* y y)))))
double code(double x, double y) {
return x / (1.0 + (0.16666666666666666 * (y * y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (1.0d0 + (0.16666666666666666d0 * (y * y)))
end function
public static double code(double x, double y) {
return x / (1.0 + (0.16666666666666666 * (y * y)));
}
def code(x, y): return x / (1.0 + (0.16666666666666666 * (y * y)))
function code(x, y) return Float64(x / Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))) end
function tmp = code(x, y) tmp = x / (1.0 + (0.16666666666666666 * (y * y))); end
code[x_, y_] := N[(x / N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + 0.16666666666666666 \cdot \left(y \cdot y\right)}
\end{array}
Initial program 99.8%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 61.7%
unpow261.7%
associate-*r*61.7%
Simplified61.7%
Taylor expanded in y around 0 61.7%
unpow261.7%
Simplified61.7%
Final simplification61.7%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 51.7%
Final simplification51.7%
herbie shell --seed 2023192
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))