2016-09-19 18:48:27 +02:00
|
|
|
package org.warp.picalculator.math.functions.equations;
|
2016-09-12 16:30:51 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
2016-09-18 14:33:25 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-09-19 18:48:27 +02:00
|
|
|
import org.warp.picalculator.Error;
|
2017-01-31 22:29:49 +01:00
|
|
|
import org.warp.picalculator.gui.DisplayManager;
|
2017-02-14 20:02:03 +01:00
|
|
|
import org.warp.picalculator.math.MathContext;
|
|
|
|
import org.warp.picalculator.math.Function;
|
|
|
|
import org.warp.picalculator.math.FunctionDynamic;
|
2016-10-02 16:01:41 +02:00
|
|
|
import org.warp.picalculator.math.functions.Expression;
|
|
|
|
import org.warp.picalculator.math.functions.Number;
|
2016-09-19 18:48:27 +02:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public class EquationsSystem extends FunctionDynamic {
|
2016-09-12 16:30:51 +02:00
|
|
|
static final int spacing = 2;
|
2017-01-17 22:32:40 +01:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public EquationsSystem(MathContext root) {
|
2017-01-17 22:32:40 +01:00
|
|
|
super(root);
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public EquationsSystem(MathContext root, Function value) {
|
2017-01-31 22:29:49 +01:00
|
|
|
super(root, new Function[] { value });
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public EquationsSystem(MathContext root, Function[] value) {
|
2017-01-17 22:32:40 +01:00
|
|
|
super(root, value);
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-02 16:01:41 +02:00
|
|
|
protected boolean isSolvable() {
|
2016-11-25 22:40:43 +01:00
|
|
|
if (functions.length >= 1) {
|
2016-10-02 16:01:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2016-10-02 16:01:41 +02:00
|
|
|
@Override
|
2017-03-03 23:06:43 +01:00
|
|
|
public ObjectArrayList<Function> solve() throws Error {
|
|
|
|
final ObjectArrayList<Function> ret = new ObjectArrayList<>();
|
2016-11-25 22:40:43 +01:00
|
|
|
if (functions.length == 1) {
|
2017-02-14 20:02:03 +01:00
|
|
|
if (functions[0].isSimplified()) {
|
2016-11-25 22:40:43 +01:00
|
|
|
ret.add(functions[0]);
|
2016-10-02 16:01:41 +02:00
|
|
|
return ret;
|
|
|
|
} else {
|
2017-02-14 20:02:03 +01:00
|
|
|
final List<Function> l = functions[0].simplify();
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : l) {
|
2016-10-02 16:01:41 +02:00
|
|
|
if (f instanceof Number) {
|
|
|
|
ret.add(f);
|
|
|
|
} else {
|
2017-01-31 22:29:49 +01:00
|
|
|
ret.add(new Expression(root, new Function[] { f }));
|
2016-10-02 16:01:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : functions) {
|
2017-02-14 20:02:03 +01:00
|
|
|
if (f.isSimplified() == false) {
|
|
|
|
final List<Function> partial = f.simplify();
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function fnc : partial) {
|
|
|
|
ret.add(new Expression(root, new Function[] { fnc }));
|
2016-10-02 16:01:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2016-09-18 14:33:25 +02:00
|
|
|
}
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-03 23:06:43 +01:00
|
|
|
public EquationsSystem clone() {
|
|
|
|
return new EquationsSystem(root, functions);
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-03-03 23:06:43 +01:00
|
|
|
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|