Skip to content

Commit 4bcae65

Browse files
committed
WIP #1009: Add missing IMatrch interface
1 parent e3b1b4e commit 4bcae65

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.matheclipse.core.eval.interfaces;
2+
3+
import org.matheclipse.core.eval.EvalEngine;
4+
import org.matheclipse.core.expression.F;
5+
import org.matheclipse.core.interfaces.IAST;
6+
import org.matheclipse.core.interfaces.IExpr;
7+
8+
public interface IMatch {
9+
10+
default IExpr match2(IAST ast, EvalEngine engine) {
11+
return F.NIL;
12+
}
13+
14+
default IExpr match3(IAST ast, EvalEngine engine) {
15+
return F.NIL;
16+
}
17+
18+
default IExpr match4(IAST ast, EvalEngine engine) {
19+
return F.NIL;
20+
}
21+
22+
default IExpr match5(IAST ast, EvalEngine engine) {
23+
return F.NIL;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.matheclipse.core.system;
2+
3+
import org.junit.Test;
4+
5+
public class MinMaxFunctionsTest extends ExprEvaluatorTestCase {
6+
7+
@Test
8+
public void testNArgMax() {
9+
checkNumeric("NArgMax(-2*x^2-3*x+5,x)", //
10+
"{-0.7500000000000001}");
11+
checkNumeric("NArgMax(1-(x*y-3)^2, {x, y})", //
12+
"{1.0,3.0}");
13+
}
14+
15+
16+
@Test
17+
public void testNArgMin() {
18+
checkNumeric("NArgMin(2*x^2-3*x+5,x)", //
19+
"{0.7499999999999998}");
20+
21+
checkNumeric("NArgMin((x*y-3)^2+1, {x,y})", //
22+
"{1.0,3.0}");
23+
checkNumeric("NArgMin({x-2*y, x+y<= 1}, {x, y})", //
24+
"{0.0,1.0}");
25+
}
26+
27+
@Test
28+
public void testNMaxValue() {
29+
checkNumeric("NMaxValue(-2*x^2-3*x+5,x)", //
30+
"6.125");
31+
checkNumeric("NMaxValue(1-(x*y-3)^2, {x, y})", //
32+
"1.0");
33+
}
34+
35+
@Test
36+
public void testNMinValue() {
37+
checkNumeric("NMinValue(2*x^2-3*x+5,x)", //
38+
"3.875");
39+
40+
checkNumeric("NMinValue((x*y-3)^2+1, {x,y})", //
41+
"1.0");
42+
checkNumeric("NMinValue({x-2*y, x+y<= 1}, {x, y})", //
43+
"-2.0");
44+
}
45+
46+
@Test
47+
public void testNMaximize() {
48+
checkNumeric("NMaximize(-x^4 - 3* x^2 + x, x)", //
49+
"{0.08258881886826407,{x->0.16373996720676331}}");
50+
51+
check("NMaximize({-2*x+y-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", //
52+
"{-2.0,{x->0.0,y->3.0}}");
53+
check("NMaximize({-x - y, 3*x + 2*y >= 7 && x + 2*y >= 6}, {x, y})", //
54+
"{-3.25,{x->0.5,y->2.75}}");
55+
}
56+
57+
@Test
58+
public void testNMinimize() {
59+
check("NMinimize({-5-2*x+y,x+2*y<=6&&3*x+2*y<=12},{x,y})", //
60+
"{-13.0,{x->4.0,y->0.0}}");
61+
62+
check("NMinimize({-Sinc(x)-Sinc(y)}, {x, y})", //
63+
"{-2.0,{x->0.0,y->0.0}}");
64+
65+
check("NMinimize(x^2 + y^2 + 2, {x,y})", //
66+
"{2.0,{x->0.0,y->0.0}}");
67+
check("NMinimize({Sinc(x)+Sinc(y)}, {x, y})", //
68+
"{-0.434467,{x->4.49341,y->4.49341}}");
69+
70+
checkNumeric("NMinimize({Sinc(x)+Sinc(y)}, {x, y})", //
71+
"{-0.4344672564224433,{x->4.493409457896563,y->4.493409457738778}}");
72+
73+
checkNumeric("NMinimize(x^4 - 3*x^2 - x, x)", //
74+
"{-3.513905038934788,{x->1.3008395656679863}}");
75+
76+
// TODO non-linear not supported
77+
// check("NMinimize({x^2 - (y - 1)^2, x^2 + y^2 <= 4}, {x, y})", "");
78+
check("NMinimize({-2*y+x-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", //
79+
"{-11.0,{x->0.0,y->3.0}}");
80+
check("NMinimize({-2*y+x-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", //
81+
"{-11.0,{x->0.0,y->3.0}}");
82+
check("NMinimize({-2*x+y-5, x+2*y<=6 && 3*x + 2*y <= 12 }, {x, y})", //
83+
"{-13.0,{x->4.0,y->0.0}}");
84+
check("NMinimize({x + 2*y, -5*x + y == 7 && x + y >= 26 && x >= 3 && y >= 4}, {x, y})", //
85+
"{48.83333,{x->3.16667,y->22.83333}}");
86+
check("NMinimize({x + y, 3*x + 2*y >= 7 && x + 2*y >= 6 }, {x, y})", //
87+
"{3.25,{x->0.5,y->2.75}}");
88+
}
89+
}

0 commit comments

Comments
 (0)