/** * Returns the integer square root of this integer. * * @return <code>k<code> such as <code>k^2 <= this < (k + 1)^2</code>. If this integer is negative or it's impossible to find a * square root return <code>F.Sqrt(this)</code>. */ public IExpr sqrt() { try { return valueOf(BigIntegerMath.sqrt(fBigIntValue, RoundingMode.UNNECESSARY)); } catch (RuntimeException ex) { return F.Sqrt(this); } }
/** * Returns the integer square root of this integer. * * @return <code>k<code> such as <code>k^2 <= this < (k + 1)^2</code>. If this integer is negative or it's impossible to find a * square root return <code>F.Sqrt(this)</code>. */ public IExpr sqrt() { try { return valueOf(IntMath.sqrt(fIntValue, RoundingMode.UNNECESSARY)); } catch (RuntimeException ex) { return F.Sqrt(this); } }
/** {@inheritDoc} */ @Override public IExpr abs() { return F.Sqrt(fReal.multiply(fReal).add(fImaginary.multiply(fImaginary))); }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 2); return F.Times(F.C2, F.ArcSin(F.Sqrt(ast.arg1()))); }
public IExpr eabs() { return F.Sqrt(FractionSym.valueOf(_real.multiply(_real).add(_imaginary.multiply(_imaginary)))); }
@Override public IExpr median(IAST dist) { if (dist.isAST2()) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); // (n,m) -> Sqrt((m*InverseGammaRegularized(n, 0, 1/2))/n) return F.Sqrt(F.Times(m, F.Power(n, -1), F.InverseGammaRegularized(n, F.C0, F.C1D2))); } return F.NIL; }
public IExpr evaluate(final IAST ast) { Validate.checkRange(ast, 2, 3); IExpr arg = ast.get(1); if (arg.isNumber()) { // absolute Value of a number return ((INumber) arg).eabs(); } int dim = arg.isVector(); if (dim > (-1)) { return F.Sqrt(((IAST) arg).map(F.Plus, Functors.replaceAll(F.Sqr(F.Abs(F.Null)), F.Null))); } return null; }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 2); if (ast.arg1().isInteger()) { int m = Validate.checkIntType(ast, 1); int[] count = new int[1]; count[0] = 1; IAST scalar = F.Sqrt(F.QQ(1, m)); return F.matrix((i, j) -> unit(F.QQ(2L * ((long) i) * ((long) j), m).times(F.Pi)).times(scalar), m, m); } return F.NIL; }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 2); if (ast.arg1().isList()) { IAST arg1 = (IAST) ast.arg1(); int[] dim = arg1.isMatrix(); if (dim == null && arg1.isListOfLists()) { return F.NIL; } if (dim != null) { IAST matrix = arg1; return matrix.mapMatrixColumns(dim, x -> F.StandardDeviation(x)); } } return F.Sqrt(F.Variance(ast.arg1())); }
/** * Solve the special case of a "Quasi-symmetric equations" <code>Solve(a*x^4+b*x^3+c*x^2+b*x+a==0,x)</code>. See * <a href="http://en.wikipedia.org/wiki/Quartic_equation">Wikipedia - Quartic equation</a>. See Bronstein 1.6.2.4 * * @param a * @param b * @param c * @return */ public static IASTAppendable quasiSymmetricQuarticSolve(IExpr a, IExpr b, IExpr c) { IASTAppendable result = F.ListAlloc(4); // Sqrt[b^2-4*a*c+8*a^2] IExpr sqrt = F.eval(Sqrt(Plus(Power(b, C2), Times(CN1, C4, a, c), Times(ZZ(8L), Power(a, C2))))); // (-b+sqrt)/(2*a) IExpr y1 = Times(Plus(Times(CN1, b), sqrt), Power(Times(C2, a), CN1)); // -(b+sqrt)/(2*a) IExpr y2 = Times(CN1, Plus(b, sqrt), Power(Times(C2, a), CN1)); // (y1+Sqrt[y1^2-4])/2 result.append(Times(C1D2, Plus(y1, Sqrt(Plus(Power(y1, C2), Times(CN1, C4)))))); // (y1-Sqrt[y1^2-4])/2 result.append(Times(C1D2, Plus(y1, Times(CN1, Sqrt(Plus(Power(y1, C2), Times(CN1, C4))))))); // (y2+Sqrt[y2^2-4])/2 result.append(Times(C1D2, Plus(y2, Sqrt(Plus(Power(y2, C2), Times(CN1, C4)))))); // (y2-Sqrt[y2^2-4])/2 result.append(Times(C1D2, Plus(y2, Times(CN1, Sqrt(Plus(Power(y2, C2), Times(CN1, C4))))))); return createSet(result); }
/** * Root of a polynomial: <code>a + b*Slot1 + c*Slot1^2</code>. * * @param a * coefficient a of the polynomial * @param b * coefficient b of the polynomial * @param c * coefficient c of the polynomial * @param nthRoot * <code>1 <= nthRoot <= 3</code> otherwise return F.NIL; * @return */ private static IExpr root2(IExpr a, IExpr b, IExpr c, int nthRoot) { if (nthRoot < 1 || nthRoot > 3) { return F.NIL; } IExpr k = F.ZZ(nthRoot); return Plus(Times(C1D2, Power(F.CN1, k), F.Sqrt(Times(Plus(F.Sqr(b), Times(F.CN4, a, c)), Power(c, -2)))), Times(F.CN1D2, b, Power(c, -1))); }
@Override public IExpr eComFraArg(final IComplex base, final IFraction exponent) { if (exponent.isNumEqualRational(F.C1D2) && base.getRealPart().isZero()) { // square root of pure imaginary number IRational im = base.getImaginaryPart(); boolean negative = false; im = im.divideBy(F.C2); if (im.isNegative()) { im = im.negate(); negative = true; } if (NumberUtil.isPerfectSquare(im)) { IExpr temp = F.Sqrt(im); if (negative) { // Sqrt(im.negate()) - I * Sqrt(im); return F.Plus(temp, F.Times(F.CNI, temp)); } // Sqrt(im.negate()) + I * Sqrt(im); return F.Plus(temp, F.Times(F.CI, temp)); } } return F.NIL; }
@Override public IExpr pdf(IAST dist, IExpr k) { if (dist.isAST0()) { IExpr function = // [$ ( 1/(E^(#^2/2)*Sqrt(2*Pi)) & ) $] F.Function(F.Power(F.Times(F.Exp(F.Times(F.C1D2, F.Sqr(F.Slot1))), F.Sqrt(F.Times(F.C2, F.Pi))), -1)); // $$; return callFunction(function, k); } else if (dist.isAST2()) { // IExpr n = dist.arg1(); IExpr m = dist.arg2(); IExpr function = // [$ ( 1/(E^((# - n)^2/(2*m^2))*(m*Sqrt(2*Pi))) & ) $] F.Function(F.Power(F.Times(F.Exp( F.Times(F.Power(F.Times(F.C2, F.Sqr(m)), -1), F.Sqr(F.Plus(F.Negate(n), F.Slot1)))), m, F.Sqrt(F.Times(F.C2, F.Pi))), -1)); // $$; return callFunction(function, k); } return F.NIL; }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 3); IExpr arg1 = ast.arg1(); IExpr arg2 = ast.arg2(); int dim1 = arg1.isVector(); if (dim1 > (-1)) { int dim2 = arg2.isVector(); if (dim1 == dim2) { if (dim1 == 0) { return F.C0; } IAST a1 = ((IAST) arg1); IAST a2 = ((IAST) arg2); int size = a1.size(); IASTAppendable plusAST = F.PlusAlloc(size); plusAST.appendArgs(size, i -> F.Sqr(F.Abs(F.Subtract(a1.get(i), a2.get(i))))); // for (int i = 1; i < size; i++) { // plusAST.append(F.Sqr(F.Abs(F.Subtract(a1.get(i), a2.get(i))))); // } return F.Sqrt(plusAST); } } return F.NIL; }
@Override public IExpr pdf(IAST dist, IExpr k) { if (dist.isAST1()) { IExpr n = dist.arg1(); // IExpr function = // [$ (n/(#^2 + n))^((1 + n)/2)/(Sqrt(n)*Beta(n/2, 1/2)) & $] F.Function(F.Times( F.Power(F.Times(n, F.Power(F.Plus(F.Sqr(F.Slot1), n), -1)), F.Times(F.C1D2, F.Plus(F.C1, n))), F.Power(F.Times(F.Sqrt(n), F.Beta(F.Times(F.C1D2, n), F.C1D2)), -1))); // $$; return callFunction(function, k); } return F.NIL; }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 2); int dim = ast.arg1().isVector(); if (dim > 0) { IAST list = (IAST) ast.arg1(); if (dim == 2) { IExpr x = list.arg1(); IExpr y = list.arg2(); return F.List(F.Sqrt(F.Plus(F.Sqr(x), F.Sqr(y))), F.ArcTan(x, y)); } else if (dim == 3) { IExpr x = list.arg1(); IExpr y = list.arg2(); IExpr z = list.arg3(); IAST sqrtExpr = F.Sqrt(F.Plus(F.Sqr(x), F.Sqr(y), F.Sqr(z))); return F.List(sqrtExpr, F.ArcCos(F.Divide(x, sqrtExpr)), F.ArcTan(y, z)); } } else if (ast.arg1().isList()) { IAST list = (IAST) ast.arg1(); return list.mapThread(F.ListAlloc(list.size()), ast, 1); } return F.NIL; }
public IExpr evaluate(final IAST functionList) { if (functionList.size() != 3) { throw new WrongNumberOfArguments(functionList, 2, functionList.size() - 1); } IExpr arg1 = functionList.get(1); IExpr arg2 = functionList.get(2); int dim1 = arg1.isVector(); if (dim1 > (-1)) { int dim2 = arg2.isVector(); if (dim1 == dim2) { if (dim1 == 0) { return F.C0; } IAST a1 = ((IAST) arg1); IAST a2 = ((IAST) arg2); IAST plusAST = F.Plus(); for (int i = 1; i < a1.size(); i++) { plusAST.add(F.Sqr(F.Abs(F.Subtract(a1.get(i), a2.get(i))))); } return F.Sqrt(plusAST); } } return null; }
@Override public IExpr pdf(IAST dist, IExpr k) { if (dist.isAST2()) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); // IExpr function = // [$ (Piecewise({{1/(E^((-n + Log(#))^2/(2*m^2))*(#*m*Sqrt(2*Pi))), # > 0}}, 0)) & $] F.Function( F.Piecewise( F.List(F.List( F.Power(F.Times( F.Exp(F.Times(F.Power(F.Times(F.C2, F.Sqr(m)), -1), F.Sqr(F.Plus(F.Negate(n), F.Log(F.Slot1))))), F.Slot1, m, F.Sqrt(F.Times(F.C2, F.Pi))), -1), F.Greater(F.Slot1, F.C0))), F.C0)); // $$; return callFunction(function, k); } return F.NIL; }
@Override public IExpr evaluate(IAST ast, EvalEngine engine) { Validate.checkSize(ast, 2); IExpr m = ast.arg1(); if (m.isInfinity() || m.isNegativeInfinity() || m.isDirectedInfinity(F.CI) || m.isDirectedInfinity(F.CNI)) { return F.C0; } if (m.isZero()) { return F.CPiHalf; } if (m.isOne()) { return F.CComplexInfinity; } if (m.isMinusOne()) { // Gamma(1/4)^2/(4*Sqrt(2*Pi)) return F.Times(F.C1D4, F.C1DSqrt2, F.Power(F.Pi, F.CN1D2), F.Sqr(F.Gamma(F.C1D4))); } if (m.isNumEqualRational(F.C1D2)) { // (8 Pi^(3/2))/Gamma(-(1/4))^2 return F.Times(F.C8, F.Power(F.Pi, F.QQ(3L, 2L)), F.Power(F.Gamma(F.CN1D4), -2)); } if (m.isNumber()) { // EllipticK(m_) := Pi/(2*ArithmeticGeometricMean(1,Sqrt(1-m))) return F.Times(F.C1D2, F.Pi, F.Power(F.ArithmeticGeometricMean(F.C1, F.Sqrt(F.Plus(F.C1, F.Negate(m)))), -1)); } return F.NIL; }