SOEN 6011 – Deliverable 1

F8 · Σ (Summation Operator)

Introduction to the Summation Operator Σ

In mathematics, the uppercase Greek letter Σ (sigma) denotes the summation operator. It instructs us to “add up” a sequence of terms that follow a common pattern. The general form is written in LaTeX as

$$\Sigma_{i=1}^{n} a_{i}$$

where $a_{1},\,a_{2},\,\dots,\,a_{n}$ are the items to be added and the index i runs from 1 to n. In the context of a scientific calculator, Σ provides a quick way for users to add a finite list of numbers—be it experimental readings, intermediate results in problem‑solving, or partial sums of a series.

For example, adding the first five squares $$\Sigma_{k=1}^{5} k^{2} = 1^{2}+2^{2}+3^{2}+4^{2}+5^{2} = 55$$ can be performed instantly by our calculator’s summation mode.

The Java CLI tool delivered in this project implements exactly that: it reads up to 1 000 numeric tokens from standard input, computes their sum using IEEE‑754 double precision, and outputs the result rounded to six decimals.

Mind‑Map Overview (Mermaid)

%%{init:{'flowchart':{'useMaxWidth':true}}}%% mindmap root((Σ Summation Project)) Context of Use Users Tasks Environments Technical Non‑technical Constraints Requirements Functional FR‑1 FR‑2 FR‑3 FR‑4 Non‑Functional NFR‑1 NFR‑2 NFR‑3 Implementation CLI Java Double precision

Context of Use Model

AspectDescription
Intended usersStudents and engineers who need to add a sequence of real numbers or evaluate series in a calculator‑like tool.
User goalsEnter a list or mathematical range of values and obtain their exact sum quickly and reliably.
Tasks1. Input up to 1 000 real numbers separated by spaces.
2. View Σ result rounded to 6 decimals.
3. Receive plain‑English feedback for invalid tokens.
Non‑technical environment
  • Physical: classroom labs, home desks, exam rooms.
  • Social/organizational: individual coursework in SOEN 6011; occasional peer code‑review by classmates; instructor & TA evaluation sessions over Zoom.
Technical environment
  • Hardware: standard laptop/desktop (≥ 2 GHz CPU, ≥ 4 GB RAM).
  • Software: Java 17 JDK, command‑line terminal (Windows Terminal, macOS Terminal, Linux Bash).
  • Dependencies: none—no external libraries; standard input/output only.
ConstraintsUp to 1 000 numbers; cumulative |Σ| ≤ 1 × 10¹² to avoid double overflow; must gracefully handle whitespace and scientific notation.
StakeholdersStudents (primary), instructor/TA (evaluators), future maintainers.
Quality goalsError‑free addition; < 1 ms response for 1 000 numbers; clear plain‑English error messages; portable across OSes.

Requirements

Functional (FR)

  1. FR‑1: The system shall read a line of text from standard input containing zero‑ or space‑separated real numbers.
  2. FR‑2: The system shall parse up to 1 000 tokens into double values; any non‑numeric token shall trigger an error message and safe termination.
  3. FR‑3: The system shall compute Σ = Σi=1m ai where m is the count of valid numbers.
  4. FR‑4: The system shall output “Σ = <value>” rounded to 6 decimal places.

Non‑Functional (NFR)

  1. NFR‑1 (Performance): Execution time ≤ 1 ms for ≤ 1 000 numbers on a 2 GHz CPU.
  2. NFR‑2 (Accuracy): Result shall respect IEEE‑754 double precision with absolute error ≤ 1 × 10⁻¹².
  3. NFR‑3 (Portability): Source code shall compile with javac --release 17 on Windows, macOS, and Linux without external libraries.

Reference Implementation (CLI Java)

Compile with javac SummationCalculator.java and run with java SummationCalculator.

import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * Command‑line calculator for the summation operator Σ.
 * Accepts up to 1 000 real numbers and outputs their sum.
 * Author:  – SOEN 6011 (D1)
 * Version: 0.1.0
 */
public final class SummationCalculator {
    private static final int MAX_COUNT = 1000;
    private static final Pattern NUMBER = Pattern.compile("[+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?");

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter up to 1000 numbers separated by space: ");
        if (!sc.hasNextLine()) return;
        String line = sc.nextLine().trim();
        if (line.isEmpty()) {
            System.out.println("Σ = 0.000000");
            return;
        }

        String[] tokens = line.split("\\s+");
        if (tokens.length > MAX_COUNT) {
            System.out.println("Error: more than 1000 numbers provided.");
            return;
        }

        double sum = 0.0;
        for (String tok : tokens) {
            if (!NUMBER.matcher(tok).matches()) {
                System.out.println("Invalid number token: " + tok);
                return;
            }
            sum += Double.parseDouble(tok);
        }
        System.out.printf("Σ = %.6f%n", sum);
    }
    private SummationCalculator() { }
}