ArticleslgStudy

mathematics

Subtract with carry

Subtract with carry is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Subtract with carry rather than just read about it. In short: Subtract-with-carry (SWC) is a pseudorandom number generator created by George Marsaglia and Arif Zaman in 1991. It falls into a class of generators known as lagged Fibonacci generators, where each new number in the sequence is a function of two previous numbers at fixed distances ("lags").

Key takeaways

  • Subtract with carry belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Subtract with carry to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Subtract with carry from memory before moving on to harder problems.

Reference excerpt

Subtract-with-carry (SWC) is a pseudorandom number generator created by George Marsaglia and Arif Zaman in 1991. It falls into a class of generators known as lagged Fibonacci generators, where each new number in the sequence is a function of two previous numbers at fixed distances ("lags"). SWC is one of three random number generator engines included in the standard C++11 library. It belongs to a family of generators that also includes add-with-carry and subtract-with-borrow engines.

Algorithm The subtract-with-carry algorithm's state is defined by a list of R numbers and a "carry" value, where R is the "long lag". The initial values for this state, known as the "seed," can be chosen arbitrarily. To generate the next number in the sequence, the algorithm uses two values from its state list: the value at the "short lag" position (S steps ago) and the value at the "long lag" position (R steps ago). The new number is calculated by subtracting the long-lag value and the current carry bit from the short-lag value. If this subtraction results in a negative number (a "borrow"), the result is adjusted by adding a large constant M (the modulus), and the carry for the next step is set to 1. Otherwise, the carry is set to 0. The newly generated number replaces the oldest number in the list, and the process repeats.

Example A simple example can illustrate the process. Let the parameters be:

Modulus M = 10 Long lag R = 3 Short lag S = 1 Initial state (seed): a list of 3 numbers x = ( x 0 , x 1 , x 2 ) = ( 6 , 8 , 3 ) {\displaystyle x=(x_{0},x_{1},x_{2})=(6,8,3)} and an initial carry c 2 = 0 {\displaystyle c_{2}=0} . To generate the next number, x 3 {\displaystyle x_{3}} :

Identify the short-lag value x 3 − S = x 2 = 3 {\displaystyle x_{3-S}=x_{2}=3} and the long-lag value x 3 − R = x 0 = 6 {\displaystyle x_{3-R}=x_{0}=6} . Perform the subtraction: x 2 − x 0 − c 2 {\displaystyle x_{2}-x_{0}-c_{2}} → 3 − 6 − 0 = − 3 {\displaystyle 3-6-0=-3} . Since the result is negative, a borrow occurs. The new carry c 3 {\displaystyle c_{3}} becomes 1. The new number x 3 {\displaystyle x_{3}} is the result modulo M: − 3 mod 10 = 7 {\displaystyle -3\mod 10=7} . The state is updated. The list becomes ( x 1 , x 2 , x 3 ) = ( 8 , 3 , 7 ) {\displaystyle (x_{1},x_{2},x_{3})=(8,3,7)} , and the carry is now 1 for the next step. This process can be repeated to generate a long sequence of pseudorandom numbers.

Formal definition The sequence generated by the subtract-with-carry engine is described by the recurrence relation:

x ( i ) = ( x ( i − S ) − x ( i − R ) − c y ( i − 1 ) ) mod M {\displaystyle x(i)=(x(i-S)-x(i-R)-cy(i-1))\ {\bmod {\ }}M}

where the new carry, c y ( i ) {\displaystyle cy(i)} , is defined as:

c y ( i ) = { 1 , if x ( i − S ) − x ( i − R ) − c y ( i − 1 ) < 0 0 , otherwise {\displaystyle cy(i)={\begin{cases}1,&{\text{if }}x(i-S)-x(i-R)-cy(i-1)<0\\0,&{\text{otherwise}}\end{cases}}}

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Subtract with carry

Start with the simplest possible case. Write down what Subtract with carry claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Subtract with carry before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Subtract with carry ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Subtract with carry

In research
Subtract with carry appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Subtract with carry in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Subtract with carry is common in secondary-school and first-year university syllabi. It links to neighbouring topics Pseudorandom number generators, so understanding it makes those chapters shorter.
In everyday life
Look for Subtract with carry outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Subtract with carry” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Subtract with carry in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Subtract with carry means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Subtract with carry out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Subtract with carry in simple terms?

Subtract-with-carry (SWC) is a pseudorandom number generator created by George Marsaglia and Arif Zaman in 1991. It falls into a class of generators known as lagged Fibonacci generators, where each new number in the sequence is a function of two previous numbers at fixed distances ("lags").

Why does Subtract with carry matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Subtract with carry?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Subtract with carry.

Tags

  • Pseudorandom number generators

Keep exploring