
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos 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 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y 0.049) (not (<= y 1.26e+151))) (* (cos x) (+ 1.0 (* (* y y) 0.16666666666666666))) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if ((y <= 0.049) || !(y <= 1.26e+151)) {
tmp = cos(x) * (1.0 + ((y * y) * 0.16666666666666666));
} else {
tmp = sinh(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 <= 0.049d0) .or. (.not. (y <= 1.26d+151))) then
tmp = cos(x) * (1.0d0 + ((y * y) * 0.16666666666666666d0))
else
tmp = sinh(y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 0.049) || !(y <= 1.26e+151)) {
tmp = Math.cos(x) * (1.0 + ((y * y) * 0.16666666666666666));
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 0.049) or not (y <= 1.26e+151): tmp = math.cos(x) * (1.0 + ((y * y) * 0.16666666666666666)) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if ((y <= 0.049) || !(y <= 1.26e+151)) tmp = Float64(cos(x) * Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666))); else tmp = Float64(sinh(y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 0.049) || ~((y <= 1.26e+151))) tmp = cos(x) * (1.0 + ((y * y) * 0.16666666666666666)); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 0.049], N[Not[LessEqual[y, 1.26e+151]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.049 \lor \neg \left(y \leq 1.26 \cdot 10^{+151}\right):\\
\;\;\;\;\cos x \cdot \left(1 + \left(y \cdot y\right) \cdot 0.16666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.049000000000000002 or 1.26000000000000006e151 < y Initial program 100.0%
Taylor expanded in y around 0 87.3%
+-commutative87.3%
*-rgt-identity87.3%
*-commutative87.3%
associate-*l*87.3%
distribute-lft-out87.3%
unpow287.3%
Simplified87.3%
if 0.049000000000000002 < y < 1.26000000000000006e151Initial program 100.0%
Taylor expanded in x around 0 66.7%
Final simplification85.4%
(FPCore (x y) :precision binary64 (if (<= y 0.035) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.035) {
tmp = cos(x);
} else {
tmp = sinh(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 <= 0.035d0) then
tmp = cos(x)
else
tmp = sinh(y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.035) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.035: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.035) tmp = cos(x); else tmp = Float64(sinh(y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.035) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.035], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.035:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.035000000000000003Initial program 100.0%
Taylor expanded in y around 0 68.0%
if 0.035000000000000003 < y Initial program 100.0%
Taylor expanded in x around 0 75.5%
Final simplification69.5%
(FPCore (x y)
:precision binary64
(if (<= y 4.4e+44)
(cos x)
(if (<= y 1.5e+165)
(* (+ 1.0 (* (* y y) 0.16666666666666666)) (+ 1.0 (* (* x x) -0.5)))
(+ 1.0 (* y (* y 0.16666666666666666))))))
double code(double x, double y) {
double tmp;
if (y <= 4.4e+44) {
tmp = cos(x);
} else if (y <= 1.5e+165) {
tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5));
} else {
tmp = 1.0 + (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 <= 4.4d+44) then
tmp = cos(x)
else if (y <= 1.5d+165) then
tmp = (1.0d0 + ((y * y) * 0.16666666666666666d0)) * (1.0d0 + ((x * x) * (-0.5d0)))
else
tmp = 1.0d0 + (y * (y * 0.16666666666666666d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.4e+44) {
tmp = Math.cos(x);
} else if (y <= 1.5e+165) {
tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5));
} else {
tmp = 1.0 + (y * (y * 0.16666666666666666));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.4e+44: tmp = math.cos(x) elif y <= 1.5e+165: tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5)) else: tmp = 1.0 + (y * (y * 0.16666666666666666)) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.4e+44) tmp = cos(x); elseif (y <= 1.5e+165) tmp = Float64(Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666)) * Float64(1.0 + Float64(Float64(x * x) * -0.5))); else tmp = Float64(1.0 + Float64(y * Float64(y * 0.16666666666666666))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.4e+44) tmp = cos(x); elseif (y <= 1.5e+165) tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5)); else tmp = 1.0 + (y * (y * 0.16666666666666666)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.4e+44], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.5e+165], N[(N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(y * N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.4 \cdot 10^{+44}:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+165}:\\
\;\;\;\;\left(1 + \left(y \cdot y\right) \cdot 0.16666666666666666\right) \cdot \left(1 + \left(x \cdot x\right) \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1 + y \cdot \left(y \cdot 0.16666666666666666\right)\\
\end{array}
\end{array}
if y < 4.39999999999999991e44Initial program 100.0%
Taylor expanded in y around 0 65.8%
if 4.39999999999999991e44 < y < 1.49999999999999995e165Initial program 100.0%
Taylor expanded in y around 0 22.5%
+-commutative22.5%
*-rgt-identity22.5%
*-commutative22.5%
associate-*l*22.5%
distribute-lft-out22.5%
unpow222.5%
Simplified22.5%
Taylor expanded in x around 0 47.0%
*-commutative20.4%
unpow220.4%
Simplified47.0%
if 1.49999999999999995e165 < y Initial program 100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
*-rgt-identity100.0%
*-commutative100.0%
associate-*l*100.0%
distribute-lft-out100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in x around 0 87.5%
Taylor expanded in y around 0 87.5%
unpow287.5%
*-commutative87.5%
associate-*r*87.5%
Simplified87.5%
Final simplification66.2%
(FPCore (x y) :precision binary64 (if (or (<= y 4.4e+44) (not (<= y 1.16e+166))) (+ 1.0 (* y (* y 0.16666666666666666))) (* (+ 1.0 (* (* y y) 0.16666666666666666)) (+ 1.0 (* (* x x) -0.5)))))
double code(double x, double y) {
double tmp;
if ((y <= 4.4e+44) || !(y <= 1.16e+166)) {
tmp = 1.0 + (y * (y * 0.16666666666666666));
} else {
tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= 4.4d+44) .or. (.not. (y <= 1.16d+166))) then
tmp = 1.0d0 + (y * (y * 0.16666666666666666d0))
else
tmp = (1.0d0 + ((y * y) * 0.16666666666666666d0)) * (1.0d0 + ((x * x) * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 4.4e+44) || !(y <= 1.16e+166)) {
tmp = 1.0 + (y * (y * 0.16666666666666666));
} else {
tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 4.4e+44) or not (y <= 1.16e+166): tmp = 1.0 + (y * (y * 0.16666666666666666)) else: tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5)) return tmp
function code(x, y) tmp = 0.0 if ((y <= 4.4e+44) || !(y <= 1.16e+166)) tmp = Float64(1.0 + Float64(y * Float64(y * 0.16666666666666666))); else tmp = Float64(Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666)) * Float64(1.0 + Float64(Float64(x * x) * -0.5))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 4.4e+44) || ~((y <= 1.16e+166))) tmp = 1.0 + (y * (y * 0.16666666666666666)); else tmp = (1.0 + ((y * y) * 0.16666666666666666)) * (1.0 + ((x * x) * -0.5)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 4.4e+44], N[Not[LessEqual[y, 1.16e+166]], $MachinePrecision]], N[(1.0 + N[(y * N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.4 \cdot 10^{+44} \lor \neg \left(y \leq 1.16 \cdot 10^{+166}\right):\\
\;\;\;\;1 + y \cdot \left(y \cdot 0.16666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(y \cdot y\right) \cdot 0.16666666666666666\right) \cdot \left(1 + \left(x \cdot x\right) \cdot -0.5\right)\\
\end{array}
\end{array}
if y < 4.39999999999999991e44 or 1.16000000000000002e166 < y Initial program 100.0%
Taylor expanded in y around 0 85.0%
+-commutative85.0%
*-rgt-identity85.0%
*-commutative85.0%
associate-*l*85.0%
distribute-lft-out84.9%
unpow284.9%
Simplified84.9%
Taylor expanded in x around 0 55.1%
Taylor expanded in y around 0 55.1%
unpow255.1%
*-commutative55.1%
associate-*r*55.1%
Simplified55.1%
if 4.39999999999999991e44 < y < 1.16000000000000002e166Initial program 100.0%
Taylor expanded in y around 0 22.5%
+-commutative22.5%
*-rgt-identity22.5%
*-commutative22.5%
associate-*l*22.5%
distribute-lft-out22.5%
unpow222.5%
Simplified22.5%
Taylor expanded in x around 0 47.0%
*-commutative20.4%
unpow220.4%
Simplified47.0%
Final simplification54.4%
(FPCore (x y) :precision binary64 (if (<= y 4.6e+44) 1.0 (+ 1.0 (* (* x x) -0.5))))
double code(double x, double y) {
double tmp;
if (y <= 4.6e+44) {
tmp = 1.0;
} else {
tmp = 1.0 + ((x * x) * -0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 4.6d+44) then
tmp = 1.0d0
else
tmp = 1.0d0 + ((x * x) * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.6e+44) {
tmp = 1.0;
} else {
tmp = 1.0 + ((x * x) * -0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.6e+44: tmp = 1.0 else: tmp = 1.0 + ((x * x) * -0.5) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.6e+44) tmp = 1.0; else tmp = Float64(1.0 + Float64(Float64(x * x) * -0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.6e+44) tmp = 1.0; else tmp = 1.0 + ((x * x) * -0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.6e+44], 1.0, N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.6 \cdot 10^{+44}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot -0.5\\
\end{array}
\end{array}
if y < 4.60000000000000009e44Initial program 100.0%
Taylor expanded in y around 0 65.8%
Taylor expanded in x around 0 37.4%
if 4.60000000000000009e44 < y Initial program 100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 15.0%
*-commutative15.0%
unpow215.0%
Simplified15.0%
Final simplification33.4%
(FPCore (x y) :precision binary64 (+ 1.0 (* y (* y 0.16666666666666666))))
double code(double x, double y) {
return 1.0 + (y * (y * 0.16666666666666666));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (y * (y * 0.16666666666666666d0))
end function
public static double code(double x, double y) {
return 1.0 + (y * (y * 0.16666666666666666));
}
def code(x, y): return 1.0 + (y * (y * 0.16666666666666666))
function code(x, y) return Float64(1.0 + Float64(y * Float64(y * 0.16666666666666666))) end
function tmp = code(x, y) tmp = 1.0 + (y * (y * 0.16666666666666666)); end
code[x_, y_] := N[(1.0 + N[(y * N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + y \cdot \left(y \cdot 0.16666666666666666\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 79.6%
+-commutative79.6%
*-rgt-identity79.6%
*-commutative79.6%
associate-*l*79.6%
distribute-lft-out79.6%
unpow279.6%
Simplified79.6%
Taylor expanded in x around 0 51.7%
Taylor expanded in y around 0 51.7%
unpow251.7%
*-commutative51.7%
associate-*r*51.4%
Simplified51.4%
Final simplification51.4%
(FPCore (x y) :precision binary64 (+ 1.0 (* (* y y) 0.16666666666666666)))
double code(double x, double y) {
return 1.0 + ((y * y) * 0.16666666666666666);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((y * y) * 0.16666666666666666d0)
end function
public static double code(double x, double y) {
return 1.0 + ((y * y) * 0.16666666666666666);
}
def code(x, y): return 1.0 + ((y * y) * 0.16666666666666666)
function code(x, y) return Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666)) end
function tmp = code(x, y) tmp = 1.0 + ((y * y) * 0.16666666666666666); end
code[x_, y_] := N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(y \cdot y\right) \cdot 0.16666666666666666
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 79.6%
+-commutative79.6%
*-rgt-identity79.6%
*-commutative79.6%
associate-*l*79.6%
distribute-lft-out79.6%
unpow279.6%
Simplified79.6%
Taylor expanded in x around 0 51.7%
Final simplification51.7%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 54.5%
Taylor expanded in x around 0 31.1%
Final simplification31.1%
herbie shell --seed 2023199
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))