PieceWise Defined Function

==2024-11-14

Theory

Piece-wise defined functions defined differently at different condition.

  1. Greatest Integer Function(floor)()

Important

  1. If number is int, don’t touch it.
  2. Greatest int is from left.
  1. Least Integer Function(ceil)()

Important

  1. If number is int, don’t touch it.
  2. Least int is from right.
  1. Absolute Function()
y=x|x>0|blue
y=-x|x<0|blue
  1. Signum Function ()
\frac{x}{x}|x>0|blue
\frac{-x}{x}|x<0|blue

Examples


Implementation

  1. Floor
def floor(x: float):
	return int(x)
print(floor(2.9))
  1. Ceil
def ceil(x):
	return int(x)+1 if isinstance(x, float) else x
 
print(ceil(2.5))
  1. Absolute
def abs(x):
	return x if x>0 else -x
print(abs(-1))

PTR

  1. different condition from break of differentiability.