
(FPCore (x y) :precision binary64 (/ (* (sin x) (sinh y)) x))
double code(double x, double y) {
return (sin(x) * sinh(y)) / x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sin(x) * sinh(y)) / x
end function
public static double code(double x, double y) {
return (Math.sin(x) * Math.sinh(y)) / x;
}
def code(x, y): return (math.sin(x) * math.sinh(y)) / x
function code(x, y) return Float64(Float64(sin(x) * sinh(y)) / x) end
function tmp = code(x, y) tmp = (sin(x) * sinh(y)) / x; end
code[x_, y_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sinh[y], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin x \cdot \sinh y}{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (sin x) (sinh y)) x))
double code(double x, double y) {
return (sin(x) * sinh(y)) / x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sin(x) * sinh(y)) / x
end function
public static double code(double x, double y) {
return (Math.sin(x) * Math.sinh(y)) / x;
}
def code(x, y): return (math.sin(x) * math.sinh(y)) / x
function code(x, y) return Float64(Float64(sin(x) * sinh(y)) / x) end
function tmp = code(x, y) tmp = (sin(x) * sinh(y)) / x; end
code[x_, y_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sinh[y], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin x \cdot \sinh y}{x}
\end{array}
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) x)))
double code(double x, double y) {
return sin(x) * (sinh(y) / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / x)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / x);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / x)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / x)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / x); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{x}
\end{array}
Initial program 90.1%
associate-/l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y 1350.0) (/ y (/ x (sin x))) (log1p (expm1 y))))
double code(double x, double y) {
double tmp;
if (y <= 1350.0) {
tmp = y / (x / sin(x));
} else {
tmp = log1p(expm1(y));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if (y <= 1350.0) {
tmp = y / (x / Math.sin(x));
} else {
tmp = Math.log1p(Math.expm1(y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1350.0: tmp = y / (x / math.sin(x)) else: tmp = math.log1p(math.expm1(y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 1350.0) tmp = Float64(y / Float64(x / sin(x))); else tmp = log1p(expm1(y)); end return tmp end
code[x_, y_] := If[LessEqual[y, 1350.0], N[(y / N[(x / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(Exp[y] - 1), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1350:\\
\;\;\;\;\frac{y}{\frac{x}{\sin x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(y\right)\right)\\
\end{array}
\end{array}
if y < 1350Initial program 87.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 54.5%
associate-/l*67.4%
Simplified67.4%
Taylor expanded in y around 0 54.5%
associate-*l/76.4%
associate-/r/67.4%
Simplified67.4%
if 1350 < y Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 4.2%
associate-/l*4.2%
Simplified4.2%
associate-/l*4.2%
clear-num4.2%
*-commutative4.2%
Applied egg-rr4.2%
Taylor expanded in x around 0 3.3%
remove-double-div3.3%
log1p-expm1-u62.3%
Applied egg-rr62.3%
Final simplification66.2%
(FPCore (x y) :precision binary64 (if (<= x 8.8e+229) (* (sin x) (/ y x)) (* -0.16666666666666666 (* y (pow x 2.0)))))
double code(double x, double y) {
double tmp;
if (x <= 8.8e+229) {
tmp = sin(x) * (y / x);
} else {
tmp = -0.16666666666666666 * (y * pow(x, 2.0));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 8.8d+229) then
tmp = sin(x) * (y / x)
else
tmp = (-0.16666666666666666d0) * (y * (x ** 2.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 8.8e+229) {
tmp = Math.sin(x) * (y / x);
} else {
tmp = -0.16666666666666666 * (y * Math.pow(x, 2.0));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 8.8e+229: tmp = math.sin(x) * (y / x) else: tmp = -0.16666666666666666 * (y * math.pow(x, 2.0)) return tmp
function code(x, y) tmp = 0.0 if (x <= 8.8e+229) tmp = Float64(sin(x) * Float64(y / x)); else tmp = Float64(-0.16666666666666666 * Float64(y * (x ^ 2.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 8.8e+229) tmp = sin(x) * (y / x); else tmp = -0.16666666666666666 * (y * (x ^ 2.0)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 8.8e+229], N[(N[Sin[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision], N[(-0.16666666666666666 * N[(y * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.8 \cdot 10^{+229}:\\
\;\;\;\;\sin x \cdot \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(y \cdot {x}^{2}\right)\\
\end{array}
\end{array}
if x < 8.80000000000000014e229Initial program 89.4%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 43.6%
*-commutative43.6%
associate-/l*65.6%
Applied egg-rr65.6%
if 8.80000000000000014e229 < x Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 26.8%
associate-/l*26.8%
Simplified26.8%
Taylor expanded in x around 0 62.9%
Taylor expanded in x around inf 62.9%
Final simplification65.4%
(FPCore (x y) :precision binary64 (if (<= y 6.5e+47) (* y (/ (sin x) x)) (/ (* x y) x)))
double code(double x, double y) {
double tmp;
if (y <= 6.5e+47) {
tmp = y * (sin(x) / x);
} else {
tmp = (x * y) / x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6.5d+47) then
tmp = y * (sin(x) / x)
else
tmp = (x * y) / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6.5e+47) {
tmp = y * (Math.sin(x) / x);
} else {
tmp = (x * y) / x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.5e+47: tmp = y * (math.sin(x) / x) else: tmp = (x * y) / x return tmp
function code(x, y) tmp = 0.0 if (y <= 6.5e+47) tmp = Float64(y * Float64(sin(x) / x)); else tmp = Float64(Float64(x * y) / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.5e+47) tmp = y * (sin(x) / x); else tmp = (x * y) / x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.5e+47], N[(y * N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{+47}:\\
\;\;\;\;y \cdot \frac{\sin x}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{x}\\
\end{array}
\end{array}
if y < 6.49999999999999988e47Initial program 87.6%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 52.0%
associate-/l*64.2%
Simplified64.2%
if 6.49999999999999988e47 < y Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 4.6%
Taylor expanded in x around 0 12.7%
Final simplification53.9%
(FPCore (x y) :precision binary64 (* (sin x) (/ y x)))
double code(double x, double y) {
return sin(x) * (y / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (y / x)
end function
public static double code(double x, double y) {
return Math.sin(x) * (y / x);
}
def code(x, y): return math.sin(x) * (y / x)
function code(x, y) return Float64(sin(x) * Float64(y / x)) end
function tmp = code(x, y) tmp = sin(x) * (y / x); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{y}{x}
\end{array}
Initial program 90.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 42.5%
*-commutative42.5%
associate-/l*63.2%
Applied egg-rr63.2%
Final simplification63.2%
(FPCore (x y) :precision binary64 (if (<= x 0.003) y (/ 1.0 (* x (- (/ 1.0 (* x y)) (* -0.16666666666666666 (/ x y)))))))
double code(double x, double y) {
double tmp;
if (x <= 0.003) {
tmp = y;
} else {
tmp = 1.0 / (x * ((1.0 / (x * y)) - (-0.16666666666666666 * (x / y))));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 0.003d0) then
tmp = y
else
tmp = 1.0d0 / (x * ((1.0d0 / (x * y)) - ((-0.16666666666666666d0) * (x / y))))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 0.003) {
tmp = y;
} else {
tmp = 1.0 / (x * ((1.0 / (x * y)) - (-0.16666666666666666 * (x / y))));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.003: tmp = y else: tmp = 1.0 / (x * ((1.0 / (x * y)) - (-0.16666666666666666 * (x / y)))) return tmp
function code(x, y) tmp = 0.0 if (x <= 0.003) tmp = y; else tmp = Float64(1.0 / Float64(x * Float64(Float64(1.0 / Float64(x * y)) - Float64(-0.16666666666666666 * Float64(x / y))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.003) tmp = y; else tmp = 1.0 / (x * ((1.0 / (x * y)) - (-0.16666666666666666 * (x / y)))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.003], y, N[(1.0 / N[(x * N[(N[(1.0 / N[(x * y), $MachinePrecision]), $MachinePrecision] - N[(-0.16666666666666666 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.003:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(\frac{1}{x \cdot y} - -0.16666666666666666 \cdot \frac{x}{y}\right)}\\
\end{array}
\end{array}
if x < 0.0030000000000000001Initial program 86.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 42.0%
associate-/l*55.0%
Simplified55.0%
Taylor expanded in x around 0 34.9%
if 0.0030000000000000001 < x Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 44.1%
associate-/l*44.1%
Simplified44.1%
associate-/l*44.1%
clear-num44.1%
*-commutative44.1%
Applied egg-rr44.1%
frac-2neg44.1%
div-inv44.1%
distribute-rgt-neg-in44.1%
Applied egg-rr44.1%
Taylor expanded in x around 0 18.2%
Final simplification30.7%
(FPCore (x y) :precision binary64 (if (<= y 2e+27) y (/ (* x y) x)))
double code(double x, double y) {
double tmp;
if (y <= 2e+27) {
tmp = y;
} else {
tmp = (x * y) / 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+27) then
tmp = y
else
tmp = (x * y) / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2e+27) {
tmp = y;
} else {
tmp = (x * y) / x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2e+27: tmp = y else: tmp = (x * y) / x return tmp
function code(x, y) tmp = 0.0 if (y <= 2e+27) tmp = y; else tmp = Float64(Float64(x * y) / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e+27) tmp = y; else tmp = (x * y) / x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2e+27], y, N[(N[(x * y), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{+27}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{x}\\
\end{array}
\end{array}
if y < 2e27Initial program 87.3%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 53.2%
associate-/l*65.7%
Simplified65.7%
Taylor expanded in x around 0 33.8%
if 2e27 < y Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 4.4%
Taylor expanded in x around 0 11.8%
Final simplification29.0%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 90.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 42.5%
associate-/l*52.3%
Simplified52.3%
Taylor expanded in x around 0 27.2%
Final simplification27.2%
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) x)))
double code(double x, double y) {
return sin(x) * (sinh(y) / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / x)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / x);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / x)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / x)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / x); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{x}
\end{array}
herbie shell --seed 2024041
(FPCore (x y)
:name "Linear.Quaternion:$ccosh from linear-1.19.1.3"
:precision binary64
:herbie-target
(* (sin x) (/ (sinh y) x))
(/ (* (sin x) (sinh y)) x))