
(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 6 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 (/ (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 (/ (/ x y) (+ (* y 0.16666666666666666) (/ 1.0 y))))
double code(double x, double y) {
return (x / y) / ((y * 0.16666666666666666) + (1.0 / y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / y) / ((y * 0.16666666666666666d0) + (1.0d0 / y))
end function
public static double code(double x, double y) {
return (x / y) / ((y * 0.16666666666666666) + (1.0 / y));
}
def code(x, y): return (x / y) / ((y * 0.16666666666666666) + (1.0 / y))
function code(x, y) return Float64(Float64(x / y) / Float64(Float64(y * 0.16666666666666666) + Float64(1.0 / y))) end
function tmp = code(x, y) tmp = (x / y) / ((y * 0.16666666666666666) + (1.0 / y)); end
code[x_, y_] := N[(N[(x / y), $MachinePrecision] / N[(N[(y * 0.16666666666666666), $MachinePrecision] + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x}{y}}{y \cdot 0.16666666666666666 + \frac{1}{y}}
\end{array}
Initial program 99.8%
clear-num99.7%
div-inv99.8%
div-inv99.6%
associate-/r*90.5%
Applied egg-rr90.5%
Taylor expanded in y around 0 53.8%
Final simplification53.8%
(FPCore (x y) :precision binary64 (* y (/ -1.0 (/ (- y) x))))
double code(double x, double y) {
return y * (-1.0 / (-y / x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * ((-1.0d0) / (-y / x))
end function
public static double code(double x, double y) {
return y * (-1.0 / (-y / x));
}
def code(x, y): return y * (-1.0 / (-y / x))
function code(x, y) return Float64(y * Float64(-1.0 / Float64(Float64(-y) / x))) end
function tmp = code(x, y) tmp = y * (-1.0 / (-y / x)); end
code[x_, y_] := N[(y * N[(-1.0 / N[((-y) / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{-1}{\frac{-y}{x}}
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 89.6%
*-commutative89.6%
associate-/l*90.9%
Simplified90.9%
Taylor expanded in y around 0 53.8%
frac-2neg53.8%
div-inv52.9%
distribute-neg-frac52.9%
Applied egg-rr52.9%
Final simplification52.9%
(FPCore (x y) :precision binary64 (* y (/ x y)))
double code(double x, double y) {
return y * (x / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (x / y)
end function
public static double code(double x, double y) {
return y * (x / y);
}
def code(x, y): return y * (x / y)
function code(x, y) return Float64(y * Float64(x / y)) end
function tmp = code(x, y) tmp = y * (x / y); end
code[x_, y_] := N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{x}{y}
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 89.6%
*-commutative89.6%
associate-/l*90.9%
Simplified90.9%
Taylor expanded in y around 0 53.8%
*-un-lft-identity53.8%
associate-*l/52.9%
clear-num52.3%
Applied egg-rr52.3%
Final simplification52.3%
(FPCore (x y) :precision binary64 (/ y (/ y x)))
double code(double x, double y) {
return y / (y / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y / (y / x)
end function
public static double code(double x, double y) {
return y / (y / x);
}
def code(x, y): return y / (y / x)
function code(x, y) return Float64(y / Float64(y / x)) end
function tmp = code(x, y) tmp = y / (y / x); end
code[x_, y_] := N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{\frac{y}{x}}
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 89.6%
*-commutative89.6%
associate-/l*90.9%
Simplified90.9%
Taylor expanded in y around 0 53.8%
Final simplification53.8%
(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 52.1%
Final simplification52.1%
herbie shell --seed 2024033
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))