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