/// <summary> /// Divides the two given polynomials using polynomial long division and returns the division result /// </summary> /// <param name="x">First polynomial</param> /// <param name="y">Second polynomial</param> /// <returns>Divison quotient and remainder</returns> public static (poly Quotient, poly Remainder) PolynomialDivision(poly x, poly y) { int nd = x.Degree; int dd = y.Degree; if (dd < 0) { throw new ArgumentException("Divisor must have at least one one-zero coefficient"); } if (nd < dd) { throw new ArgumentException("The degree of the divisor cannot exceed that of the numerator"); } poly r = (poly)x.Clone(); scalar[] q = new scalar[nd * 2]; while (nd >= dd) { poly d2 = y >> (nd - dd); q[nd - dd] = r[nd] / d2[nd]; d2 *= q[nd - dd]; r -= d2; nd = r.Degree; } return(q, r); }
public DateTime getSystemTime() { OracleQuery request = buildGetSystemTimeQuery(); scalar resultDelegate = delegate() { return(request.Command.ExecuteScalar()); }; return((DateTime)_cxn.query(request, resultDelegate)); }
public static mat4 inverse(this in mat4 m) { scalar Coef00 = m[2, 2] * m[3, 3] - m[3, 2] * m[2, 3]; scalar Coef02 = m[1, 2] * m[3, 3] - m[3, 2] * m[1, 3]; scalar Coef03 = m[1, 2] * m[2, 3] - m[2, 2] * m[1, 3]; scalar Coef04 = m[2, 1] * m[3, 3] - m[3, 1] * m[2, 3]; scalar Coef06 = m[1, 1] * m[3, 3] - m[3, 1] * m[1, 3]; scalar Coef07 = m[1, 1] * m[2, 3] - m[2, 1] * m[1, 3]; scalar Coef08 = m[2, 1] * m[3, 2] - m[3, 1] * m[2, 2]; scalar Coef10 = m[1, 1] * m[3, 2] - m[3, 1] * m[1, 2]; scalar Coef11 = m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2]; scalar Coef12 = m[2, 0] * m[3, 3] - m[3, 0] * m[2, 3]; scalar Coef14 = m[1, 0] * m[3, 3] - m[3, 0] * m[1, 3]; scalar Coef15 = m[1, 0] * m[2, 3] - m[2, 0] * m[1, 3]; scalar Coef16 = m[2, 0] * m[3, 2] - m[3, 0] * m[2, 2]; scalar Coef18 = m[1, 0] * m[3, 2] - m[3, 0] * m[1, 2]; scalar Coef19 = m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2]; scalar Coef20 = m[2, 0] * m[3, 1] - m[3, 0] * m[2, 1]; scalar Coef22 = m[1, 0] * m[3, 1] - m[3, 0] * m[1, 1]; scalar Coef23 = m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1]; vec4 Fac0 = new vec4(Coef00, Coef00, Coef02, Coef03); vec4 Fac1 = new vec4(Coef04, Coef04, Coef06, Coef07); vec4 Fac2 = new vec4(Coef08, Coef08, Coef10, Coef11); vec4 Fac3 = new vec4(Coef12, Coef12, Coef14, Coef15); vec4 Fac4 = new vec4(Coef16, Coef16, Coef18, Coef19); vec4 Fac5 = new vec4(Coef20, Coef20, Coef22, Coef23); vec4 Vec0 = new vec4(m[1, 0], m[0, 0], m[0, 0], m[0, 0]); vec4 Vec1 = new vec4(m[1, 1], m[0, 1], m[0, 1], m[0, 1]); vec4 Vec2 = new vec4(m[1, 2], m[0, 2], m[0, 2], m[0, 2]); vec4 Vec3 = new vec4(m[1, 3], m[0, 3], m[0, 3], m[0, 3]); vec4 Inv0 = new vec4(Vec1 * Fac0 - Vec2 * Fac1 + Vec3 * Fac2); vec4 Inv1 = new vec4(Vec0 * Fac0 - Vec2 * Fac3 + Vec3 * Fac4); vec4 Inv2 = new vec4(Vec0 * Fac1 - Vec1 * Fac3 + Vec3 * Fac5); vec4 Inv3 = new vec4(Vec0 * Fac2 - Vec1 * Fac4 + Vec2 * Fac5); vec4 SignA = new vec4(+1, -1, +1, -1); vec4 SignB = new vec4(-1, +1, -1, +1); mat4 Inverse = new mat4(Inv0 * SignA, Inv1 * SignB, Inv2 * SignA, Inv3 * SignB); vec4 Row0 = new vec4(Inverse[0, 0], Inverse[1, 0], Inverse[2, 0], Inverse[3, 0]); vec4 Dot0 = new vec4(m[0] * Row0); scalar det = Dot0.X + Dot0.Y + (Dot0.Z + Dot0.W); return(Inverse / det); }
/// <inheritdoc/> public poly Multiply(scalar factor) => this * factor;
/// <summary> /// Solves the current polynomial for any given y-value /// </summary> /// <param name="y">y-value</param> /// <returns>X-values</returns> public IEnumerable <scalar> Solve(scalar y) { scalar[] co = _coeff; poly llc = this << 1; int deg = Degree; IEnumerable <scalar> __solve() { if (deg == 0) { if (co[0].@is(y)) { foreach (scalar f in glm.AllNumbers()) { yield return(f); } } } else if (deg == 1) { yield return((y - co[0]) / co[1]); } else if (co[0].@is(y)) { yield return(0); foreach (scalar f in llc.Solve(y)) { yield return(f); } } else { if (deg == 2) { scalar a = co[2]; scalar b = co[1]; scalar c = co[0] - y; scalar q = b * b - 4 * a * c; if (q > -scalar.Epsilon) { q = (scalar)(-.5 * Math.Sqrt(q)); yield return(q / a); if (!q.is_zero()) { yield return(c / q); } } } else if (deg == 3) { foreach ((double real, double imag) in glm.SolveCardano(co[3], co[2], co[1], co[0] - y)) { if (imag.is_zero()) { yield return((scalar)real); } } } else if (deg == 4) { // solve for // 0 = ax⁴ + bx³ + cx² + dx + e // = (((ax + b)x + c)x + d)x + e throw new NotImplementedException(); } else { throw new NotImplementedException(); } } } foreach (scalar x in __solve().Distinct()) { yield return(x); } }
public static bool @is(this scalar x, scalar y) => is_zero(x - y);
public static scalar tanh(scalar angle) => (scalar)Math.Tanh(angle);
/// <inheritdoc cref="this"/> public scalar Evaluate(scalar x) => this[x];
public static scalar acosh(scalar x) => x < 1 ? 0 : (scalar)Math.Log(x + Math.Sqrt(x * x - 1));
public static scalar sinh(scalar angle) => (scalar)Math.Sinh(angle);
public static bool is_zero(this scalar x) => Math.Abs(x) <= 2 * scalar.Epsilon;
public static scalar degrees(scalar radians) => radians * 57.295779513082320876798154814105f;
public static scalar atan(scalar y_over_x) => (scalar)Math.Atan(y_over_x);
public static scalar atanh(scalar x) => Math.Abs(x) >= 1 ? 0 : .5f * (scalar)Math.Log((1 + x) / (1 - x));
public static scalar atan(scalar y, scalar x) => (scalar)Math.Atan2(y, x);
public static scalar asinh(scalar x) => (x < 0 ? -1 : x > 0 ? 1 : 0) * (scalar)Math.Log(Math.Abs(x) + Math.Sqrt(1 + x * x));
public static scalar asin(scalar x) => (scalar)Math.Asin(x);
/// <summary> /// Evaluates the polynomial at the given X value /// </summary> /// <param name="x">X value</param> /// <returns>Polynomial value at X</returns> public scalar this[scalar x] => _coeff.Reverse().Aggregate((acc, c) => acc * x + c);
public static scalar radians(scalar degrees) => degrees * 0.01745329251994329576923690768489f;
public static scalar cosh(scalar angle) => (scalar)Math.Cosh(angle);
public static scalar acos(scalar x) => (scalar)Math.Acos(x);