-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP #1009: Add missing IMatrch interface
- Loading branch information
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...d_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/interfaces/IMatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.matheclipse.core.eval.interfaces; | ||
|
||
import org.matheclipse.core.eval.EvalEngine; | ||
import org.matheclipse.core.expression.F; | ||
import org.matheclipse.core.interfaces.IAST; | ||
import org.matheclipse.core.interfaces.IExpr; | ||
|
||
public interface IMatch { | ||
|
||
default IExpr match2(IAST ast, EvalEngine engine) { | ||
return F.NIL; | ||
} | ||
|
||
default IExpr match3(IAST ast, EvalEngine engine) { | ||
return F.NIL; | ||
} | ||
|
||
default IExpr match4(IAST ast, EvalEngine engine) { | ||
return F.NIL; | ||
} | ||
|
||
default IExpr match5(IAST ast, EvalEngine engine) { | ||
return F.NIL; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...brary/matheclipse-core/src/test/java/org/matheclipse/core/system/MinMaxFunctionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.matheclipse.core.system; | ||
|
||
import org.junit.Test; | ||
|
||
public class MinMaxFunctionsTest extends ExprEvaluatorTestCase { | ||
|
||
@Test | ||
public void testNArgMax() { | ||
checkNumeric("NArgMax(-2*x^2-3*x+5,x)", // | ||
"{-0.7500000000000001}"); | ||
checkNumeric("NArgMax(1-(x*y-3)^2, {x, y})", // | ||
"{1.0,3.0}"); | ||
} | ||
|
||
|
||
@Test | ||
public void testNArgMin() { | ||
checkNumeric("NArgMin(2*x^2-3*x+5,x)", // | ||
"{0.7499999999999998}"); | ||
|
||
checkNumeric("NArgMin((x*y-3)^2+1, {x,y})", // | ||
"{1.0,3.0}"); | ||
checkNumeric("NArgMin({x-2*y, x+y<= 1}, {x, y})", // | ||
"{0.0,1.0}"); | ||
} | ||
|
||
@Test | ||
public void testNMaxValue() { | ||
checkNumeric("NMaxValue(-2*x^2-3*x+5,x)", // | ||
"6.125"); | ||
checkNumeric("NMaxValue(1-(x*y-3)^2, {x, y})", // | ||
"1.0"); | ||
} | ||
|
||
@Test | ||
public void testNMinValue() { | ||
checkNumeric("NMinValue(2*x^2-3*x+5,x)", // | ||
"3.875"); | ||
|
||
checkNumeric("NMinValue((x*y-3)^2+1, {x,y})", // | ||
"1.0"); | ||
checkNumeric("NMinValue({x-2*y, x+y<= 1}, {x, y})", // | ||
"-2.0"); | ||
} | ||
|
||
@Test | ||
public void testNMaximize() { | ||
checkNumeric("NMaximize(-x^4 - 3* x^2 + x, x)", // | ||
"{0.08258881886826407,{x->0.16373996720676331}}"); | ||
|
||
check("NMaximize({-2*x+y-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", // | ||
"{-2.0,{x->0.0,y->3.0}}"); | ||
check("NMaximize({-x - y, 3*x + 2*y >= 7 && x + 2*y >= 6}, {x, y})", // | ||
"{-3.25,{x->0.5,y->2.75}}"); | ||
} | ||
|
||
@Test | ||
public void testNMinimize() { | ||
check("NMinimize({-5-2*x+y,x+2*y<=6&&3*x+2*y<=12},{x,y})", // | ||
"{-13.0,{x->4.0,y->0.0}}"); | ||
|
||
check("NMinimize({-Sinc(x)-Sinc(y)}, {x, y})", // | ||
"{-2.0,{x->0.0,y->0.0}}"); | ||
|
||
check("NMinimize(x^2 + y^2 + 2, {x,y})", // | ||
"{2.0,{x->0.0,y->0.0}}"); | ||
check("NMinimize({Sinc(x)+Sinc(y)}, {x, y})", // | ||
"{-0.434467,{x->4.49341,y->4.49341}}"); | ||
|
||
checkNumeric("NMinimize({Sinc(x)+Sinc(y)}, {x, y})", // | ||
"{-0.4344672564224433,{x->4.493409457896563,y->4.493409457738778}}"); | ||
|
||
checkNumeric("NMinimize(x^4 - 3*x^2 - x, x)", // | ||
"{-3.513905038934788,{x->1.3008395656679863}}"); | ||
|
||
// TODO non-linear not supported | ||
// check("NMinimize({x^2 - (y - 1)^2, x^2 + y^2 <= 4}, {x, y})", ""); | ||
check("NMinimize({-2*y+x-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", // | ||
"{-11.0,{x->0.0,y->3.0}}"); | ||
check("NMinimize({-2*y+x-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", // | ||
"{-11.0,{x->0.0,y->3.0}}"); | ||
check("NMinimize({-2*x+y-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", // | ||
"{-13.0,{x->4.0,y->0.0}}"); | ||
check("NMinimize({x + 2*y, -5*x + y == 7 && x + y >= 26 && x >= 3 && y >= 4}, {x, y})", // | ||
"{48.83333,{x->3.16667,y->22.83333}}"); | ||
check("NMinimize({x + y, 3*x + 2*y >= 7 && x + 2*y >= 6 }, {x, y})", // | ||
"{3.25,{x->0.5,y->2.75}}"); | ||
} | ||
} |