
1.3 加减:最基本的数学运算
本节介绍加、减这两种最基本算数运算。
加法
加法(addition)的运算符为加号(plus sign或plus symbol);加法运算式中,等式(equation)的左边为加数(addend)和被加数(augend或summand),等式的右边是和(sum),如图1.11所示。
加法的表达方式多种多样,如“和(summation)”“加(plus)”“增长(increase)”“小计(subtotal)”和“总数(total)”等。

图1.11 加法运算
图1.12所示是在数轴上可视化2+3=5这一加法运算。

图1.12 2+3=5在数轴上的可视化
Bk3_Ch1_04.py完成图1.12所示加法运算。
Bk3_Ch1_05.py对Bk3_Ch1_04.py稍作调整,利用input()函数,让用户通过键盘输入数值。
结果打印如下:
Enter first number: 2 Enter second number: 3 The sum of 2 and 3 is 5.0
表1.2总结了加法的常用英文表达。
表1.2 加法的英文表达

累计求和
对于一行数字,累计求和(cumulative sum或cumulative total)得到的结果不是一个总和,而是从左向右每加一个数值,得到的分步结果。比如,自然数1到10累计求和的结果为

式(1.4)累计求和计算过程为

Bk3_Ch1_06.py利用numpy.linspace(1, 10, 10)产生1~10这十个自然数,然后利用numpy.cumsum()函数进行累计求和。NumPy是一个开源的Python库,鸢尾花书的大量线性代数运算都离不开NumPy。
减法
减法(subtraction)是加法的逆运算(inverse operation of addition),运算符为减号(minus sign)。如图1.13所示,减法运算过程是,被减数(minuend)减去减数(subtrahend)得到差(difference)。
减法的其他表达方式包括“减(minus)”“少(less)”“差(difference)”“减少(decrease)”“拿走(take away)”和“扣除(deduct)”等。

图1.13 减法运算
图1.14所示为在数轴上展示5–3=2的减法运算。

图1.14 5–3=2在数轴上的可视化
Bk3_Ch1_07.py完成图1.14所示的减法运算。
相反数
求相反数(inverse number或additive inverse number)的过程是改变符号(reverses its sign),这样的操作常称做变号(sign change)。比如,5的相反数为-5(negative five)。表1.3给出了减法常用的英文表达。
表1.3 减法常见英文表达
