PieceWise Defined Function
==2024-11-14
Theory
Piece-wise defined functions → defined differently at different condition.
- Greatest Integer Function(floor)()
Important
- If number is int, don’t touch it.
- Greatest int is from left.
- Least Integer Function(ceil)()
Important
- If number is int, don’t touch it.
- Least int is from right.
- Absolute Function()
y=x|x>0|blue
y=-x|x<0|blue
- Signum Function ()
\frac{x}{x}|x>0|blue
\frac{-x}{x}|x<0|blue
Examples
Implementation
- Floor
def floor(x: float):
return int(x)
print(floor(2.9))
- Ceil
def ceil(x):
return int(x)+1 if isinstance(x, float) else x
print(ceil(2.5))
- Absolute
def abs(x):
return x if x>0 else -x
print(abs(-1))
PTR
- different condition from break of differentiability.