Create your own
Lesson illustration

Translating Workflow Steps into Algebraic Expressions

Hello. In the previous lesson, you learned to read the compact notation that appears in ML writing: labels such as , indices such as , Greek letters, and constraint symbols. Now we will use that notation to do something more active: turn a precise description of one deterministic workflow step into algebra.

A deterministic step is one whose output is fully determined once its inputs are known. For example, if a prompt-building step always joins a fixed system prompt, a user request, and retrieved context, then the total prompt-token count is determined by the token counts of those pieces. There is no sampling, model judgment, or probability involved in this specific calculation.

By the end of the lesson, you should be able to identify the output of a workflow step, name its inputs and fixed settings, choose the operations described by the words, and write a clear algebraic equation for the step.


From a workflow sentence to an equation

Suppose a workflow specification says:

The prompt builder creates an input prompt by combining the system instructions, the user message, and retrieved context.

This describes a relationship, but it does not yet give us quantities or operations. To formalize it, first ask four questions:

  1. What quantity does the step produce?
    Here, we may care about the total number of input tokens.

  2. What quantities does it use?
    The token counts in the system instructions, user message, and retrieved context.

  3. Which parts vary, and which are fixed?
    The user message and retrieved context may vary from request to request. System instructions may be fixed for a deployment, although they can still be represented by a symbol.

  4. How are the inputs combined?
    “Combining” token counts means adding them.

Choose symbols with informative labels:

QuantitySymbolUnit
Total input-prompt tokenstokens
System-instruction tokenstokens
User-message tokenstokens
Retrieved-context tokenstokens

Now write the relationship:

Read it as a complete sentence:

The input-token count equals the system-instruction token count plus the user-message token count plus the retrieved-context token count.

The expression on the right,

is an algebraic expression: it calculates a quantity but does not make a complete claim by itself. Adding the equality sign and the output quantity gives an equation:

For workflow design, equations are usually what you want. They document both the calculation and the meaning of its result.

Writing expressions | Math (article) | Khan Academy

Read Khan Academy's “Writing expressions” to reinforce how ordinary language signals algebraic operations, and why an expression becomes a complete mathematical statement only when it is connected to an output with an equals sign.

Begin with the opening explanation that verbal descriptions with variables can be written algebraically. Read the opening rationale, then use the “Different words for addition, subtraction, multiplication, and division” table as a quick lookup reference. Next, in the “Word problems” section, read the two examples beginning with Daniel's weekly earnings and Sebastian's trophy count; focus on how a changing input is named before the expression is written. Finally, find the discussion beginning “What is the difference in English between a phrase and a sentence?” and read through the definition and examples of an equation. Keep the distinction between a right-hand-side expression and a full workflow equation in view.


A translation procedure that works for workflow specifications

Natural language tends to mix the story of a system with its calculation. Algebra asks you to separate them.

Use this procedure for one deterministic step.

1. State the step’s output in words

Start with a sentence in the form:

This step calculates __________.

For the prompt-builder example:

This step calculates the total number of tokens sent to the model.

This prevents a common mistake: writing an expression but never saying what it represents.

2. Name every input quantity

Use symbols that preserve role and scope:

The subscripts do not change the arithmetic. They make the equation understandable later, when a workflow has many token counts.

3. Circle the operation words

The words in the specification usually reveal the arithmetic.

Wording in a workflow descriptionTypical operationExample
total, combined, plus, addedaddition
reduced by, minus, excludingsubtraction
per call, each, times, scaled bymultiplication
split among, average per, divided bydivision
total of, entire, combined resultgrouping may be needed

These are clues, not magic translations. You must still determine what is being operated on and in what order.

4. Write the right-hand-side expression

For three components combined into a prompt:

5. Assign it to the output

6. Validate it with a small numerical test

Suppose:

Then:

The result has units of tokens, as it should. This simple check catches many translation errors.

A useful habit is to ask:

If I substituted reasonable values into this equation, would it calculate the quantity described by the sentence?

That is stronger than merely checking whether the equation “looks mathematical.”


Deterministic does not mean “all inputs are constant”

A workflow step can be deterministic even when some inputs change between runs.

Consider this description:

The system estimates the input cost by multiplying input tokens by the configured input price per token.

Let:

QuantitySymbolUnit
Input costdollars
Input-token counttokens
Input pricedollars per token

The algebraic model is:

Here, will generally vary with each request. The price might be fixed by your selected provider and model for a particular period. Yet the step is deterministic: when the values of and are supplied, the output cost is fixed.

The units provide a built-in check:

If your proposed formula produces “dollars times tokens squared,” or “dollars per token,” when the target is a dollar cost, pause. Either the intended quantity or the operation is wrong.

This is one reason units are useful in AI-systems design. They make a formula testable before you have production measurements.


Order matters: subtraction, division, and “less than”

Addition is forgiving:

The order does not change the result. Subtraction and division are different:

and

So read wording carefully.

Suppose a context-management step is described this way:

The remaining token budget is the maximum context size minus the tokens already used.

Define:

  • : maximum allowed context tokens
  • : tokens already used
  • : remaining token budget

Then:

A quick reality check helps. If the maximum is tokens and are used, the remaining budget should be positive and relatively small:

Reversing the terms gives , which contradicts the intended meaning of “remaining budget.”

The wording “less than” is especially easy to reverse. Consider:

The remaining budget is 500 tokens less than the maximum budget.

Starting from the thing being described—remaining budget—gives:

The phrase does not mean .

Translating Words To Algebraic Expressions Explained!

Watch “Translating Words To Algebraic Expressions Explained!” by The Organic Chemistry Tutor for two short visual demonstrations of the translation habits that matter most here: preserving subtraction order and using parentheses when an operation applies to a complete grouped quantity.

Watch subtraction order to see why “6 less than five times a number” begins with the product and then subtracts 6. Then watch grouped calculation, focusing on the setup before the algebra is solved: “three times the sum” requires parentheses around the sum. The solving portion is optional context; your immediate goal is accurate translation.


Parentheses preserve the workflow’s structure

Parentheses are not decorative. They tell the reader which calculation happens first.

Imagine a workflow policy that says:

The system reserves 10% of the combined system, user, and context tokens for formatting overhead.

Let be the number of reserved overhead tokens. “10%” is , so:

The parentheses say: first find the combined prompt size; then take 10% of that total.

Without parentheses:

only the system tokens are multiplied by . That is a different workflow rule.

Take a numerical case:

The intended rule gives:

The incorrect ungrouped version gives:

The huge discrepancy is a reminder that the algebra must preserve the meaning of the workflow sentence, not merely contain familiar-looking symbols.


A worked translation: context selection with a fixed reserve

Let us formalize one complete deterministic step from a plausible agent harness.

Before calling the model, the context manager sets the retrieved-context allowance to the model’s maximum context size minus the system prompt, user message, and a fixed safety reserve.

The output is not the final prompt size; it is the allowance for retrieved context. This distinction is essential.

Define the quantities

MeaningSymbolUnit
Retrieved-context allowancetokens
Model context limittokens
System-prompt sizetokens
User-message sizetokens
Safety reservetokens

Identify the calculation in layers

The starting quantity is:

The workflow then removes three quantities from that total:

So the full equation is:

The same rule can be grouped to emphasize that all three quantities form the total reserved space:

These two versions are equivalent because subtracting each component one at a time has the same result as subtracting their sum.

Test the equation

Suppose:

Then:

This formula makes a design assumption explicit: the safety reserve is a fixed number of tokens. Later, you might decide the reserve should depend on task type or desired output length. For now, it is enough to see how a verbal rule becomes a model that can be evaluated, audited, and changed.


One step can combine several inputs with different weights

Not every deterministic workflow step is simply a total or a subtraction. A scoring rule can give inputs different importance.

For example:

A routing score equals a base score plus twice the retrieval-quality score minus the latency penalty.

Let:

  • : routing score
  • : fixed base score
  • : retrieval-quality score
  • : latency penalty

Then:

The coefficient means that each one-unit increase in retrieval quality contributes two score units. The negative sign means a larger latency penalty lowers the routing score. This is still a deterministic calculation: provide the three inputs and it produces one score.

The same pattern appears in basic predictive models, where each feature contributes its value multiplied by a weight.

A multiple-feature linear model: the predicted output \(y'\) is a base value \(b\) plus one weighted contribution \(w_i x_i\) from each car feature, such as pounds, displacement, acceleration, cylinders, and horsepower. It is an example of a deterministic rule that combines several inputs into one output.

For the moment, do not treat the image as a model you need to train or fully interpret. Its immediate lesson is structural: one output can be defined as a base amount plus several carefully named, weighted input contributions. You will return to this form later when studying linear functions, vectors, and optimization.


A compact quality check before accepting an equation

Before treating a formula as a faithful description of a workflow step, check five things:

  1. Output check: Is the left-hand side exactly the quantity the step is supposed to produce?
  2. Input check: Does every quantity used on the right-hand side have a definition?
  3. Operation check: Do plus, minus, multiplication, division, and parentheses match the wording?
  4. Unit check: Does the right-hand side have the same units as the output?
  5. Reality check: Does substituting a small, sensible set of values produce a plausible result?

This approach matters when reading papers as well as when designing systems. A formula may be correct algebraically but still be a poor model of a workflow if it omits a relevant input, encodes an unstated assumption, or uses the wrong quantity as its output.


You can now translate a deterministic workflow rule into algebra by identifying its output, naming inputs with meaningful symbols, mapping the wording to operations, preserving grouping and order, and checking the result with units and example values.

The central distinction is worth retaining:

An expression computes a value. An equation assigns that expression to a named output and makes the workflow relationship explicit.

Next, you will make this idea more general by treating a workflow rule as a function: a named input-output mapping that can be evaluated for different inputs.

Can't find a good explanation? Sign up and we'll make it for you

Sign up