diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java index 24204b5ec5..d283cefd31 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java @@ -4626,14 +4626,22 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { normFunction = ast.arg2(); } IExpr arg1 = ast.arg1(); - if (arg1.isEmptyList() && ast.isAST1()) { + if (arg1.isEmptyList()) { return arg1; } - IExpr norm = engine.evaluate(F.unaryAST1(normFunction, ast.arg1())); - if (norm.isZero()) { - return arg1; + if (ast.isAST1() && arg1.isMatrix(false) != null) { + // The first argument is not a number or a vector, or the second argument is not a norm + // function that always returns a non-negative real number for any numeric argument. + return Errors.printMessage(S.Normalize, "nlnmt2", ast, engine); + } + if (ast.isAST2() || arg1.isNumber() || arg1.isVector() > 0) { + IExpr norm = engine.evaluate(F.unaryAST1(normFunction, arg1)); + if (norm.isZero()) { + return arg1; + } + return F.Divide(arg1, norm); } - return F.Divide(ast.arg1(), norm); + return F.NIL; } @Override diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java index 7419ac2c1f..9d6da7f9a9 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java @@ -231,6 +231,8 @@ public static void initGeneralMessages() { "ncvi", "NIntegrate failed to converge after `1` refinements in `2` in the region `3`.", // "ndimv", "There is no `1`-dimensional `2` for the `3`-dimensional vector `4`.", // "nliter", "Non-list iterator `1` at position `2` does not evaluate to a real numeric value.", // + "nlnmt2", + "The first argument is not a number or a vector, or the second argument is not a norm function that always returns a non-negative real number for any numeric argument.", // ", "nil", "unexpected NIL expression encountered.", // "ninv", "`1` is not invertible modulo `2`.", // "nmet", "Unable to find the domain with the available methods.", // diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java index a83fb8b23b..b18cc5ea39 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java @@ -15818,6 +15818,14 @@ public void testNormal() { @Test public void testNormalize() { + // message Normalize: The first argument is not a number or a vector, or the second argument is + // not a norm function that always returns a non-negative real number for any numeric argument. + check("Normalize({{1, 2}, {4, 5}})", // + "Normalize({{1,2},{4,5}})"); + // set the name of the norm to get a result + check("Normalize({{1, 2}, {4, 5}}, Norm)", // + "{{0.147758,0.295516},{0.591031,0.738789}}"); + check( "Normalize({0.9999999999999999, -0.12609662354252538+I*0.3870962681438435, 0.3692814336284687+I*0.0968290630091466})", // "{0.8732080940136610352,-0.1101085923051267364+I*0.33801559450568667,0.3224595368133474565+I*0.0845519215553456008}"); @@ -15836,11 +15844,11 @@ public void testNormalize() { "{1/Sqrt(91),(I*2)/Sqrt(91),3/Sqrt(91),(I*4)/Sqrt(91),5/Sqrt(91),(I*6)/Sqrt(91)}"); check("Normalize(N({1, 2*I, 3, 4*I, 5, 6*I}))", // "{0.104828,I*0.209657,0.314485,I*0.419314,0.524142,I*0.628971}"); - check("Normalize({{1, 2}, {4, 5}}, Norm)", // - "{{0.147758,0.295516},{0.591031,0.738789}}"); + check("Normalize(1 + x + x^2, Integrate(#^2, {x, -1, 1}) &)", // "5/22*(1+x+x^2)"); - + check("Normalize(1 + x + x^2)", // + "Normalize(1+x+x^2)"); check("Normalize({1, 1, 1, 1})", // "{1/2,1/2,1/2,1/2}"); check("Normalize(1 + I)", // @@ -19908,8 +19916,18 @@ public void testRational() { "f(7/22,64/201,x/y)"); } + @Test + public void testRationalizeIssue1065() { + // issue 1065 + checkNumeric("Rationalize(878159.58,1*10^-12) - Rationalize(431874.32,1*10^-12)", // + "22314263/50"); + checkNumeric("22314263/50 // N", // + "446285.26"); + } + @Test public void testRationalize() { + // check("Rationalize(0.1234567*^2)", // // "1234567/100000"); // // check("Rationalize(0.12345678*^2)", //