CalcPlus

CalcPlus

CalcPlus[ a1, a2, ... ] returns the sum of numbers.

Usages

CalcPlus[ a1, a2, ... ]

CalcPlus[ a1, a2, ... ] calculates a1 + a2 + .... The arguments must be integers or decimal numbers. Fractions are only added with the option AddFractions (see below). If the sum cannot be calculated, CalcPlus is left unevaluated.

Example in out
Two integers. CalcPlus[ 1, 2 ] 3
A negative number. CalcPlus[ 13, -1 ] 12
Decimal numbers. The result is exact. CalcPlus[ 3.7, -1.2 ] 2.5
The result of adding decimal numbers can be an integer. CalcPlus[ 0.5, 1.4, 2.1 ] 4

CalcPlus[ list, a ]

If an argument is a list, the sum is calculated for each element. Two lists are added element by element.

Example in out
Add 10 to each element. CalcPlus[ {1, 2}, 10 ] {11, 12}
Add two lists element by element. CalcPlus[ {1, 2}, {10, 20} ] {11, 22}
Options

AddFractions

If set to True, fractions are added as well. The result is a simplified fraction or an integer. Default: False.

Syntax Example out
CalcPlus[ a1, a2, AddFractions=>True ] CalcPlus[ 1/6, 1/3, AddFractions=>True ] 1/2
CalcPlus[ 1/6, 2, AddFractions=>True ] 13/6
CalcPlus[ 1/2, 0.5, AddFractions=>True ] 1

FallbackToPlus

If set to True, a sum that cannot be calculated is returned as an ordinary sum instead of staying unevaluated. Default: False.

Syntax Example out
CalcPlus[ a1, a2, FallbackToPlus=>True ] CalcPlus[ 2, x, FallbackToPlus=>True ] 2+x
Details
  • Fractions without AddFractions are not added: CalcPlus[ 1/6, 1/3 ] and CalcPlus[ 1/6, 2 ] are left unevaluated.
  • Roots, Pi and variables are not calculated: CalcPlus[ Sqrt[2], 1 ], CalcPlus[ Pi, 1 ] and CalcPlus[ 2, 3, x ] are left unevaluated. Similar terms are not combined: CalcPlus[ 2x, 3x ] is left unevaluated.
  • One argument: CalcPlus[ 5 ] returns 5. No arguments: CalcPlus[] returns 0.
Invalid input Result
CalcPlus[ 2, 3, Foo=>True ] Error: Invalid associative argument for CalcPlus: Foo

See also: CalcTimes, CalcDivision, CalcPower, Simplify