
(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 7 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 87.7%
associate-/l*99.9%
Simplified99.9%
(FPCore (x y)
:precision binary64
(if (<= y 650.0)
(* y (/ (sin x) x))
(if (or (<= y 1.7e+21) (not (<= y 1.55e+32)))
(log (exp y))
(/ (* x (+ y (* -0.16666666666666666 (* y (pow x 2.0))))) x))))
double code(double x, double y) {
double tmp;
if (y <= 650.0) {
tmp = y * (sin(x) / x);
} else if ((y <= 1.7e+21) || !(y <= 1.55e+32)) {
tmp = log(exp(y));
} else {
tmp = (x * (y + (-0.16666666666666666 * (y * pow(x, 2.0))))) / x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 650.0d0) then
tmp = y * (sin(x) / x)
else if ((y <= 1.7d+21) .or. (.not. (y <= 1.55d+32))) then
tmp = log(exp(y))
else
tmp = (x * (y + ((-0.16666666666666666d0) * (y * (x ** 2.0d0))))) / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 650.0) {
tmp = y * (Math.sin(x) / x);
} else if ((y <= 1.7e+21) || !(y <= 1.55e+32)) {
tmp = Math.log(Math.exp(y));
} else {
tmp = (x * (y + (-0.16666666666666666 * (y * Math.pow(x, 2.0))))) / x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 650.0: tmp = y * (math.sin(x) / x) elif (y <= 1.7e+21) or not (y <= 1.55e+32): tmp = math.log(math.exp(y)) else: tmp = (x * (y + (-0.16666666666666666 * (y * math.pow(x, 2.0))))) / x return tmp
function code(x, y) tmp = 0.0 if (y <= 650.0) tmp = Float64(y * Float64(sin(x) / x)); elseif ((y <= 1.7e+21) || !(y <= 1.55e+32)) tmp = log(exp(y)); else tmp = Float64(Float64(x * Float64(y + Float64(-0.16666666666666666 * Float64(y * (x ^ 2.0))))) / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 650.0) tmp = y * (sin(x) / x); elseif ((y <= 1.7e+21) || ~((y <= 1.55e+32))) tmp = log(exp(y)); else tmp = (x * (y + (-0.16666666666666666 * (y * (x ^ 2.0))))) / x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 650.0], N[(y * N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.7e+21], N[Not[LessEqual[y, 1.55e+32]], $MachinePrecision]], N[Log[N[Exp[y], $MachinePrecision]], $MachinePrecision], N[(N[(x * N[(y + N[(-0.16666666666666666 * N[(y * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 650:\\
\;\;\;\;y \cdot \frac{\sin x}{x}\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+21} \lor \neg \left(y \leq 1.55 \cdot 10^{+32}\right):\\
\;\;\;\;\log \left(e^{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(y + -0.16666666666666666 \cdot \left(y \cdot {x}^{2}\right)\right)}{x}\\
\end{array}
\end{array}
if y < 650Initial program 84.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 49.4%
associate-/l*65.3%
Simplified65.3%
if 650 < y < 1.7e21 or 1.54999999999999997e32 < y Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 4.6%
associate-/l*4.6%
Simplified4.6%
associate-*r/4.6%
clear-num4.6%
*-commutative4.6%
Applied egg-rr4.6%
Taylor expanded in x around 0 5.1%
remove-double-div5.1%
add-log-exp85.5%
Applied egg-rr85.5%
if 1.7e21 < y < 1.54999999999999997e32Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 2.6%
Taylor expanded in x around 0 52.1%
Final simplification69.4%
(FPCore (x y) :precision binary64 (if (<= y 2.45e+33) (* y (/ (sin x) x)) (/ (/ y x) (/ 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 2.45e+33) {
tmp = y * (sin(x) / x);
} else {
tmp = (y / x) / (1.0 / 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.45d+33) then
tmp = y * (sin(x) / x)
else
tmp = (y / x) / (1.0d0 / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.45e+33) {
tmp = y * (Math.sin(x) / x);
} else {
tmp = (y / x) / (1.0 / x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.45e+33: tmp = y * (math.sin(x) / x) else: tmp = (y / x) / (1.0 / x) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.45e+33) tmp = Float64(y * Float64(sin(x) / x)); else tmp = Float64(Float64(y / x) / Float64(1.0 / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.45e+33) tmp = y * (sin(x) / x); else tmp = (y / x) / (1.0 / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.45e+33], N[(y * N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(y / x), $MachinePrecision] / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.45 \cdot 10^{+33}:\\
\;\;\;\;y \cdot \frac{\sin x}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y}{x}}{\frac{1}{x}}\\
\end{array}
\end{array}
if y < 2.45000000000000007e33Initial program 84.8%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 47.2%
associate-/l*62.3%
Simplified62.3%
if 2.45000000000000007e33 < y Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 4.9%
*-commutative4.9%
associate-/l*39.2%
Applied egg-rr39.2%
associate-*r/4.9%
clear-num4.9%
associate-/r*4.9%
clear-num4.9%
div-inv4.9%
associate-/r*39.2%
Applied egg-rr39.2%
Taylor expanded in x around 0 39.6%
(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 87.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 39.1%
*-commutative39.1%
associate-/l*64.7%
Applied egg-rr64.7%
(FPCore (x y) :precision binary64 (if (<= x 5e-48) y (/ (* x y) x)))
double code(double x, double y) {
double tmp;
if (x <= 5e-48) {
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 (x <= 5d-48) 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 (x <= 5e-48) {
tmp = y;
} else {
tmp = (x * y) / x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 5e-48: tmp = y else: tmp = (x * y) / x return tmp
function code(x, y) tmp = 0.0 if (x <= 5e-48) tmp = y; else tmp = Float64(Float64(x * y) / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 5e-48) tmp = y; else tmp = (x * y) / x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 5e-48], y, N[(N[(x * y), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-48}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{x}\\
\end{array}
\end{array}
if x < 4.9999999999999999e-48Initial program 83.2%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 33.1%
associate-/l*49.9%
Simplified49.9%
Taylor expanded in x around 0 36.2%
if 4.9999999999999999e-48 < x Initial program 100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 55.3%
Taylor expanded in x around 0 20.5%
(FPCore (x y) :precision binary64 (/ (/ y x) (/ 1.0 x)))
double code(double x, double y) {
return (y / x) / (1.0 / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y / x) / (1.0d0 / x)
end function
public static double code(double x, double y) {
return (y / x) / (1.0 / x);
}
def code(x, y): return (y / x) / (1.0 / x)
function code(x, y) return Float64(Float64(y / x) / Float64(1.0 / x)) end
function tmp = code(x, y) tmp = (y / x) / (1.0 / x); end
code[x_, y_] := N[(N[(y / x), $MachinePrecision] / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{y}{x}}{\frac{1}{x}}
\end{array}
Initial program 87.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 39.1%
*-commutative39.1%
associate-/l*64.7%
Applied egg-rr64.7%
associate-*r/39.1%
clear-num38.8%
associate-/r*51.0%
clear-num51.3%
div-inv51.2%
associate-/r*64.6%
Applied egg-rr64.6%
Taylor expanded in x around 0 54.5%
(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 87.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 39.1%
associate-/l*51.3%
Simplified51.3%
Taylor expanded in x around 0 29.4%
(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 2024084
(FPCore (x y)
:name "Linear.Quaternion:$ccosh from linear-1.19.1.3"
:precision binary64
:alt
(* (sin x) (/ (sinh y) x))
(/ (* (sin x) (sinh y)) x))