| 512 | return NotImplemented |
| 513 | |
| 514 | def __pow__(self, other): |
| 515 | other = as_expr(other) |
| 516 | if isinstance(other, Expr): |
| 517 | if other.op is Op.INTEGER: |
| 518 | exponent = other.data[0] |
| 519 | # TODO: other kind not used |
| 520 | if exponent == 0: |
| 521 | return as_number(1) |
| 522 | if exponent == 1: |
| 523 | return self |
| 524 | if exponent > 0: |
| 525 | if self.op is Op.FACTORS: |
| 526 | r = Expr(self.op, {}) |
| 527 | for k, v in self.data.items(): |
| 528 | r.data[k] = v * exponent |
| 529 | return normalize(r) |
| 530 | return self * (self ** (exponent - 1)) |
| 531 | elif exponent != -1: |
| 532 | return (self ** (-exponent)) ** -1 |
| 533 | return Expr(Op.FACTORS, {self: exponent}) |
| 534 | return as_apply(ArithOp.POW, self, other) |
| 535 | return NotImplemented |
| 536 | |
| 537 | def __truediv__(self, other): |
| 538 | other = as_expr(other) |