Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit fe8304e

Browse files
mforetsFrédéric Chapoton
authored andcommitted
add pow method to piecewise
1 parent 9dde00f commit fe8304e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/sage/functions/piecewise.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
0.125000000000...
5959
"""
6060

61-
#*****************************************************************************
61+
# ****************************************************************************
6262
# Copyright (C) 2006 William Stein <[email protected]>
6363
# 2006 David Joyner <[email protected]>
6464
# 2013 Volker Braun <[email protected]>
@@ -68,7 +68,7 @@
6868
# the Free Software Foundation, either version 2 of the License, or
6969
# (at your option) any later version.
7070
# http://www.gnu.org/licenses/
71-
#*****************************************************************************
71+
# ****************************************************************************
7272

7373
from __future__ import absolute_import, division, print_function
7474

@@ -290,6 +290,26 @@ def simplify(ex):
290290

291291
class EvaluationMethods(object):
292292

293+
def __pow__(self, parameters, variable, n):
294+
"""
295+
Return the `n`-th power of the piecewise function by applying the
296+
operation to each piece.
297+
298+
INPUT:
299+
300+
- ``n`` -- number or symbolic expression
301+
302+
EXAMPLES::
303+
304+
sage: f1(x) = -abs(x) + 1; f2(x) = abs(x - 2) - 1
305+
sage: f = piecewise([ [(-1,1), f1], [(1,3), f2]])
306+
sage: (f^2).integral(definite=True)
307+
4/3
308+
"""
309+
return piecewise(zip(self.domains(),
310+
[ex**n for ex in self.expressions()]),
311+
var=variable)
312+
293313
def expression_at(self, parameters, variable, point):
294314
"""
295315
Return the expression defining the piecewise function at
@@ -702,6 +722,7 @@ def piecewise_add(self, parameters, variable, other):
702722
def integral(self, parameters, variable, x=None, a=None, b=None, definite=False):
703723
r"""
704724
By default, return the indefinite integral of the function.
725+
705726
If definite=True is given, returns the definite integral.
706727
707728
AUTHOR:

0 commit comments

Comments
 (0)