Plain English first
Absolute value answers one question: how far from zero?
It strips away direction and gives you only distance. 3 steps right: distance 3. 3 steps left: distance also 3. Same number, opposite directions — absolute value makes them equal.
The picture
|← 3 units →| |← 3 units →|
←──────────────────────────────────────→
-3 0 3
|-3| = 3 |3| = 3
Standard math notation
|n| = n if n ≥ 0 (already positive)
|n| = -n if n < 0 (flip the sign)
|7| = 7
|-7| = 7
|-3.5| = 3.5
Distance between a and b: |a - b|
Verbose Python with descriptive names
def compute_absolute_value(number):
"""
Absolute value is the distance from zero — always non-negative.
If positive or zero: keep it. If negative: flip the sign.
"""
if number >= 0:
return number
else:
return -number # -(-3) = 3
def compute_distance_between_points(point_a, point_b):
"""
Subtract to find the gap; absolute value makes it positive.
Distance from 2 to 7 and from 7 to 2 are both 5.
"""
return compute_absolute_value(point_a - point_b)
def check_if_within_tolerance(measured_value, target_value, allowed_error):
"""
Common engineering use: is this measurement close enough?
We care about the SIZE of the error, not its direction.
"""
size_of_error = compute_absolute_value(measured_value - target_value)
passed = size_of_error <= allowed_error
print(f" Error size: {size_of_error:.3f}, allowed: ±{allowed_error} → {'PASS ✓' if passed else 'FAIL ✗'}")
return passed
# Demonstrations
print(compute_absolute_value(-7)) # 7
print(compute_distance_between_points(-3, 4)) # 7
check_if_within_tolerance(98.3, 98.6, 0.5) # PASS
check_if_within_tolerance(10.08, 10.0, 0.05) # FAIL
Where absolute value appears
- Error measurement — size of the error, regardless of direction
- Distance formulas — always positive, regardless of subtraction order
- Tolerance checks — is this within ±X of the target?
Common mistakes
|-5| = -5is wrong. Always non-negative.|-5| = 5.|a + b| ≠ |a| + |b|in general.|3 + (-3)| = 0, but|3| + |-3| = 6.
Comentarios
Aún no hay comentarios. ¡Sé el primero!