-
Notifications
You must be signed in to change notification settings - Fork 0
/
unknowns.dart
34 lines (31 loc) · 1013 Bytes
/
unknowns.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import 'term.dart';
import 'constants.dart';
import 'products.dart';
/// A Term object representing a single named unknown variable.
class Unknown extends Term {
final String name;
const Unknown(this.name);
@override bool isNegative() => false;
@override bool negatesGracefully() => false;
@override Term operator -() => Product(coefficient: neg_one, factors: [this]);
@override bool equals(Term term) => term == this;
@override Term addDirect(Term other, isNegated) {
if (other is Product) {
if (other.factors.length == 1 && other.factors[0].equals(this)) {
return isNegated ? (this - other) : (this + other);
}
} else if (other is Unknown) {
if (other.equals(this)) {
if (isNegated) return zero;
return Product(
coefficient: one + one,
factors: [this],
);
}
}
return null;
}
@override String toString() => name;
@override String toOutline() => 'v';
@override bool startsWithMinus() => false;
}