
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) y)))
double code(double x, double y) {
return sin(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / y)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) y)))
double code(double x, double y) {
return sin(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / y)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{y}
\end{array}
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) y)))
double code(double x, double y) {
return sin(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / y)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* 0.16666666666666666 (* (sin x) (* y y)))))
(if (<= y -2.5)
t_0
(if (<= y 620.0)
(sin x)
(if (<= y 4e+128) (+ x (* -0.16666666666666666 (pow x 3.0))) t_0)))))
double code(double x, double y) {
double t_0 = 0.16666666666666666 * (sin(x) * (y * y));
double tmp;
if (y <= -2.5) {
tmp = t_0;
} else if (y <= 620.0) {
tmp = sin(x);
} else if (y <= 4e+128) {
tmp = x + (-0.16666666666666666 * pow(x, 3.0));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 0.16666666666666666d0 * (sin(x) * (y * y))
if (y <= (-2.5d0)) then
tmp = t_0
else if (y <= 620.0d0) then
tmp = sin(x)
else if (y <= 4d+128) then
tmp = x + ((-0.16666666666666666d0) * (x ** 3.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 0.16666666666666666 * (Math.sin(x) * (y * y));
double tmp;
if (y <= -2.5) {
tmp = t_0;
} else if (y <= 620.0) {
tmp = Math.sin(x);
} else if (y <= 4e+128) {
tmp = x + (-0.16666666666666666 * Math.pow(x, 3.0));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 0.16666666666666666 * (math.sin(x) * (y * y)) tmp = 0 if y <= -2.5: tmp = t_0 elif y <= 620.0: tmp = math.sin(x) elif y <= 4e+128: tmp = x + (-0.16666666666666666 * math.pow(x, 3.0)) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(0.16666666666666666 * Float64(sin(x) * Float64(y * y))) tmp = 0.0 if (y <= -2.5) tmp = t_0; elseif (y <= 620.0) tmp = sin(x); elseif (y <= 4e+128) tmp = Float64(x + Float64(-0.16666666666666666 * (x ^ 3.0))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 0.16666666666666666 * (sin(x) * (y * y)); tmp = 0.0; if (y <= -2.5) tmp = t_0; elseif (y <= 620.0) tmp = sin(x); elseif (y <= 4e+128) tmp = x + (-0.16666666666666666 * (x ^ 3.0)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(0.16666666666666666 * N[(N[Sin[x], $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.5], t$95$0, If[LessEqual[y, 620.0], N[Sin[x], $MachinePrecision], If[LessEqual[y, 4e+128], N[(x + N[(-0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.16666666666666666 \cdot \left(\sin x \cdot \left(y \cdot y\right)\right)\\
\mathbf{if}\;y \leq -2.5:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 620:\\
\;\;\;\;\sin x\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+128}:\\
\;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.5 or 4.0000000000000003e128 < y Initial program 100.0%
Taylor expanded in y around 0 72.2%
unpow272.2%
Simplified72.2%
Taylor expanded in y around inf 72.2%
unpow272.2%
*-commutative72.2%
Simplified72.2%
if -2.5 < y < 620Initial program 100.0%
Taylor expanded in y around 0 99.2%
if 620 < y < 4.0000000000000003e128Initial program 100.0%
associate-*r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 2.8%
Taylor expanded in x around 0 19.8%
Final simplification80.4%
(FPCore (x y) :precision binary64 (* (sin x) (+ 1.0 (* 0.16666666666666666 (* y y)))))
double code(double x, double y) {
return sin(x) * (1.0 + (0.16666666666666666 * (y * y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (1.0d0 + (0.16666666666666666d0 * (y * y)))
end function
public static double code(double x, double y) {
return Math.sin(x) * (1.0 + (0.16666666666666666 * (y * y)));
}
def code(x, y): return math.sin(x) * (1.0 + (0.16666666666666666 * (y * y)))
function code(x, y) return Float64(sin(x) * Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))) end
function tmp = code(x, y) tmp = sin(x) * (1.0 + (0.16666666666666666 * (y * y))); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 78.8%
unpow278.8%
Simplified78.8%
Final simplification78.8%
(FPCore (x y) :precision binary64 (if (or (<= y -2.5e-8) (not (<= y 7.2e-6))) (+ x (* x (* 0.16666666666666666 (* y y)))) (sin x)))
double code(double x, double y) {
double tmp;
if ((y <= -2.5e-8) || !(y <= 7.2e-6)) {
tmp = x + (x * (0.16666666666666666 * (y * y)));
} else {
tmp = sin(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.5d-8)) .or. (.not. (y <= 7.2d-6))) then
tmp = x + (x * (0.16666666666666666d0 * (y * y)))
else
tmp = sin(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.5e-8) || !(y <= 7.2e-6)) {
tmp = x + (x * (0.16666666666666666 * (y * y)));
} else {
tmp = Math.sin(x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.5e-8) or not (y <= 7.2e-6): tmp = x + (x * (0.16666666666666666 * (y * y))) else: tmp = math.sin(x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.5e-8) || !(y <= 7.2e-6)) tmp = Float64(x + Float64(x * Float64(0.16666666666666666 * Float64(y * y)))); else tmp = sin(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.5e-8) || ~((y <= 7.2e-6))) tmp = x + (x * (0.16666666666666666 * (y * y))); else tmp = sin(x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.5e-8], N[Not[LessEqual[y, 7.2e-6]], $MachinePrecision]], N[(x + N[(x * N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-8} \lor \neg \left(y \leq 7.2 \cdot 10^{-6}\right):\\
\;\;\;\;x + x \cdot \left(0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin x\\
\end{array}
\end{array}
if y < -2.4999999999999999e-8 or 7.19999999999999967e-6 < y Initial program 100.0%
Taylor expanded in y around 0 57.3%
unpow257.3%
Simplified57.3%
Taylor expanded in x around 0 50.9%
*-commutative50.9%
+-commutative50.9%
unpow250.9%
fma-udef50.9%
Simplified50.9%
fma-udef50.9%
distribute-rgt-in50.9%
*-commutative50.9%
*-un-lft-identity50.9%
Applied egg-rr50.9%
if -2.4999999999999999e-8 < y < 7.19999999999999967e-6Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification75.6%
(FPCore (x y) :precision binary64 (if (or (<= y -2e+154) (not (<= y 4e+127))) (* 0.16666666666666666 (* x (* y y))) (+ x (* (* x y) (* y 0.16666666666666666)))))
double code(double x, double y) {
double tmp;
if ((y <= -2e+154) || !(y <= 4e+127)) {
tmp = 0.16666666666666666 * (x * (y * y));
} else {
tmp = x + ((x * y) * (y * 0.16666666666666666));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2d+154)) .or. (.not. (y <= 4d+127))) then
tmp = 0.16666666666666666d0 * (x * (y * y))
else
tmp = x + ((x * y) * (y * 0.16666666666666666d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2e+154) || !(y <= 4e+127)) {
tmp = 0.16666666666666666 * (x * (y * y));
} else {
tmp = x + ((x * y) * (y * 0.16666666666666666));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2e+154) or not (y <= 4e+127): tmp = 0.16666666666666666 * (x * (y * y)) else: tmp = x + ((x * y) * (y * 0.16666666666666666)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2e+154) || !(y <= 4e+127)) tmp = Float64(0.16666666666666666 * Float64(x * Float64(y * y))); else tmp = Float64(x + Float64(Float64(x * y) * Float64(y * 0.16666666666666666))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2e+154) || ~((y <= 4e+127))) tmp = 0.16666666666666666 * (x * (y * y)); else tmp = x + ((x * y) * (y * 0.16666666666666666)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2e+154], N[Not[LessEqual[y, 4e+127]], $MachinePrecision]], N[(0.16666666666666666 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(x * y), $MachinePrecision] * N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+154} \lor \neg \left(y \leq 4 \cdot 10^{+127}\right):\\
\;\;\;\;0.16666666666666666 \cdot \left(x \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(x \cdot y\right) \cdot \left(y \cdot 0.16666666666666666\right)\\
\end{array}
\end{array}
if y < -2.00000000000000007e154 or 3.99999999999999982e127 < y Initial program 100.0%
Taylor expanded in y around 0 91.2%
unpow291.2%
Simplified91.2%
Taylor expanded in y around inf 91.2%
unpow291.2%
*-commutative91.2%
Simplified91.2%
Taylor expanded in x around 0 73.5%
unpow273.5%
Simplified73.5%
if -2.00000000000000007e154 < y < 3.99999999999999982e127Initial program 100.0%
Taylor expanded in y around 0 73.7%
unpow273.7%
Simplified73.7%
Taylor expanded in x around 0 39.5%
*-commutative39.5%
+-commutative39.5%
unpow239.5%
fma-udef39.5%
Simplified39.5%
fma-udef39.5%
distribute-rgt-in39.5%
*-commutative39.5%
*-un-lft-identity39.5%
Applied egg-rr39.5%
Taylor expanded in y around 0 39.5%
unpow239.5%
associate-*l*39.5%
associate-*r*39.5%
*-commutative39.5%
*-commutative39.5%
*-commutative39.5%
Simplified39.5%
Final simplification49.5%
(FPCore (x y) :precision binary64 (if (or (<= y -2.5) (not (<= y 2.4))) (* 0.16666666666666666 (* x (* y y))) x))
double code(double x, double y) {
double tmp;
if ((y <= -2.5) || !(y <= 2.4)) {
tmp = 0.16666666666666666 * (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.4d0))) then
tmp = 0.16666666666666666d0 * (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.4)) {
tmp = 0.16666666666666666 * (x * (y * y));
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.5) or not (y <= 2.4): tmp = 0.16666666666666666 * (x * (y * y)) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.5) || !(y <= 2.4)) tmp = Float64(0.16666666666666666 * Float64(x * Float64(y * y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.5) || ~((y <= 2.4))) tmp = 0.16666666666666666 * (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.4]], $MachinePrecision]], N[(0.16666666666666666 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \lor \neg \left(y \leq 2.4\right):\\
\;\;\;\;0.16666666666666666 \cdot \left(x \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.5 or 2.39999999999999991 < y Initial program 100.0%
Taylor expanded in y around 0 56.8%
unpow256.8%
Simplified56.8%
Taylor expanded in y around inf 56.8%
unpow256.8%
*-commutative56.8%
Simplified56.8%
Taylor expanded in x around 0 50.2%
unpow250.2%
Simplified50.2%
if -2.5 < y < 2.39999999999999991Initial program 100.0%
Taylor expanded in y around 0 99.5%
unpow299.5%
Simplified99.5%
Taylor expanded in x around 0 48.7%
*-commutative48.7%
+-commutative48.7%
unpow248.7%
fma-udef48.7%
Simplified48.7%
Taylor expanded in y around 0 48.4%
Final simplification49.3%
(FPCore (x y) :precision binary64 (if (or (<= y -2e+80) (not (<= y 2.4e-30))) (/ (* x y) y) x))
double code(double x, double y) {
double tmp;
if ((y <= -2e+80) || !(y <= 2.4e-30)) {
tmp = (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 <= (-2d+80)) .or. (.not. (y <= 2.4d-30))) then
tmp = (x * y) / y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2e+80) || !(y <= 2.4e-30)) {
tmp = (x * y) / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2e+80) or not (y <= 2.4e-30): tmp = (x * y) / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2e+80) || !(y <= 2.4e-30)) tmp = Float64(Float64(x * y) / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2e+80) || ~((y <= 2.4e-30))) tmp = (x * y) / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2e+80], N[Not[LessEqual[y, 2.4e-30]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+80} \lor \neg \left(y \leq 2.4 \cdot 10^{-30}\right):\\
\;\;\;\;\frac{x \cdot y}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2e80 or 2.39999999999999985e-30 < y Initial program 100.0%
associate-*r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 10.3%
Taylor expanded in x around 0 18.2%
if -2e80 < y < 2.39999999999999985e-30Initial program 100.0%
Taylor expanded in y around 0 92.8%
unpow292.8%
Simplified92.8%
Taylor expanded in x around 0 45.3%
*-commutative45.3%
+-commutative45.3%
unpow245.3%
fma-udef45.3%
Simplified45.3%
Taylor expanded in y around 0 45.2%
Final simplification32.0%
(FPCore (x y) :precision binary64 (+ x (* x (* 0.16666666666666666 (* y y)))))
double code(double x, double y) {
return x + (x * (0.16666666666666666 * (y * y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (x * (0.16666666666666666d0 * (y * y)))
end function
public static double code(double x, double y) {
return x + (x * (0.16666666666666666 * (y * y)));
}
def code(x, y): return x + (x * (0.16666666666666666 * (y * y)))
function code(x, y) return Float64(x + Float64(x * Float64(0.16666666666666666 * Float64(y * y)))) end
function tmp = code(x, y) tmp = x + (x * (0.16666666666666666 * (y * y))); end
code[x_, y_] := N[(x + N[(x * N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \left(0.16666666666666666 \cdot \left(y \cdot y\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 78.8%
unpow278.8%
Simplified78.8%
Taylor expanded in x around 0 49.4%
*-commutative49.4%
+-commutative49.4%
unpow249.4%
fma-udef49.4%
Simplified49.4%
fma-udef49.4%
distribute-rgt-in49.5%
*-commutative49.5%
*-un-lft-identity49.5%
Applied egg-rr49.5%
Final simplification49.5%
(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 100.0%
Taylor expanded in y around 0 78.8%
unpow278.8%
Simplified78.8%
Taylor expanded in x around 0 49.4%
*-commutative49.4%
+-commutative49.4%
unpow249.4%
fma-udef49.4%
Simplified49.4%
Taylor expanded in y around 0 26.2%
Final simplification26.2%
herbie shell --seed 2023182
(FPCore (x y)
:name "Linear.Quaternion:$ccos from linear-1.19.1.3"
:precision binary64
(* (sin x) (/ (sinh y) y)))