Vertical bar
The vertical bar, denoted by the glyph | (Unicode U+007C), is a straight vertical line character classified as a mathematical symbol (Sm category) in the Unicode Standard, where it is officially named "Vertical Line."[1][2] Also known by aliases such as pipe or bar, it serves as a versatile punctuation mark and operator with prominent roles in mathematics, computing, and typography, often functioning as a delimiter, separator, or indicator of logical relationships.[3][4] In mathematics, the vertical bar has multiple established notations that convey precise concepts. It denotes the absolute value of a number, as in |x|, representing the magnitude without regard to sign—for instance, |-3| = 3.[5] It appears in set-builder notation to mean "such that," defining elements satisfying a condition, such as {x ∈ ℝ | x > 0}, the set of all positive real numbers.[5][6] Additionally, it indicates conditional probability in statistics, as P(A|B) for the probability of A given B, and divisibility between integers, where a|b means a divides b evenly.[7][8] In computing and programming, the vertical bar functions as the pipe operator in Unix-like operating systems, redirecting the output of one command as input to another—for example,cat file.txt | wc counts the words in a file by piping its contents.[3] It also acts as a bitwise OR operator in languages like C/C++, performing binary operations on integers, and as part of the logical OR (||) for conditional statements.[4] In regular expressions, a single | signifies alternation, matching one pattern or another, such as a|b for "a or b."[3] Typographically, it appears as a separator in URLs, tables, or menus to divide elements clearly.[9]
Mathematical and scientific notation
Mathematics
In number theory, the vertical bar denotes divisibility, where a \mid b means that a divides b if there exists an integer k such that b = a k.[10] This notation indicates that b is an integer multiple of a, without implying division in the arithmetic sense. For example, $2 \mid 4 holds because $4 = 2 \cdot 2, whereas $3 \nmid 4 since no such integer k exists. The symbol was introduced in unpublished notes from G. H. Hardy's 1925 number theory seminar and first appeared in print in Edmund Landau's 1927 book Elementary Number Theory.[11] In probability theory, the vertical bar represents conditional probability, denoted as P(A \mid B), which is the probability that event A occurs given that event B has occurred, assuming P(B) > 0. This is defined as P(A \mid B) = \frac{P(A \cap B)}{P(B)}, where P(A \cap B) is the joint probability of both events.[12] The formula derives from the axioms of probability in measure-theoretic terms, treating events as subsets of a sample space; specifically, it normalizes the measure of the intersection A \cap B by the measure of B, reflecting the restriction of the probability space to outcomes in B. This notation, using the vertical bar for "given," became standardized in the mid-20th century following earlier variants like Kolmogorov's P_B(A) in 1933.[13] The vertical bars also denote the absolute value of a real number x, written as |x|, which gives the distance of x from zero on the number line and is always non-negative. For x \geq 0, |x| = x; for x < 0, |x| = -x. This single-bar notation, adopted widely in the 20th century, replaced earlier uses of double bars \|x\| for magnitude in some contexts, particularly as linear algebra distinguished norms with double bars. The shift emphasized clarity in elementary contexts, as documented in historical surveys of mathematical symbols. In linear algebra, vertical bars enclose a square matrix to denote its determinant, so |A| = \det(A) for an n \times n matrix A. The determinant measures properties like invertibility and volume scaling under linear transformations. For a 2×2 matrix A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, the determinant is computed as |A| = ad - bc. For instance, if A = \begin{pmatrix} 3 & 1 \\ 2 & 4 \end{pmatrix}, then |A| = (3)(4) - (1)(2) = 12 - 2 = 10. This notation traces to Arthur Cayley's 1841 work, where double vertical lines were used, evolving to single bars as the standard by the late 19th century.[14][15]Chemistry
In chemistry, the vertical bar (|) serves as a delimiter in several notations, particularly in electrochemistry and phase representations, to indicate boundaries between different phases or components. A primary application is in the cell notation for electrochemical cells, where a single vertical bar denotes a phase boundary, such as between a solid electrode and its surrounding electrolyte solution. For instance, in the Daniell cell, the notation Zn | Zn²⁺ || Cu²⁺ | Cu represents the zinc anode in contact with zinc ions (separated by |), the salt bridge (||), and the copper cathode with copper ions (separated by |). This convention allows concise depiction of the cell's structure without drawing diagrams, with components listed from left to right across the cell.[16] The double vertical bar (||) specifically indicates the salt bridge or a liquid junction with low resistance, distinguishing it from single bars for phase interfaces.[17] The vertical bar also represents phase boundaries in broader chemical contexts, such as solubility equilibria or multi-phase systems. According to IUPAC recommendations, a single | separates immiscible phases, like in the notation for a gas-liquid interface (e.g., H₂(g) | H₂O(l)), while a dashed vertical bar (│) denotes junctions between miscible liquids, and || indicates immiscible liquid boundaries. This usage extends to phase diagrams, where vertical lines mark transitions, such as the solid | liquid boundary in a one-component diagram, helping to visualize regions of stability for each phase under varying temperature and pressure.[17] The vertical bar has a limited role in SMILES (Simplified Molecular Input Line Entry System) notation for organic structures, primarily in extensions for annotations or stereochemistry. For example, in some parsers like RDKit, | delimits non-standard features such as lone pair specifications (e.g., O|lp for oxygen with a lone pair tag), though core SMILES uses / and \ for double-bond configurations like in trans-but-2-ene (C/C=C/C). This usage supports advanced molecular modeling but is not part of the basic Daylight SMILES specification.[18]Physics
In physics, the vertical bar denotes the magnitude of physical quantities, particularly vectors, distinguishing it from the vector's directional properties. For a velocity vector v, the speed is represented as |v|, yielding a scalar value that quantifies the object's motion without direction. This usage emphasizes the non-negative length of the vector in Euclidean space, as seen in kinematic equations where |r| gives displacement magnitude. Unlike abstract scalar norms in higher mathematics, the single vertical bars in physics conventionally apply the Euclidean norm for three-dimensional vectors, ensuring compatibility with empirical measurements.[19] A prominent application occurs in quantum mechanics through Dirac notation, where vertical bars define kets and contribute to bras. A quantum state is expressed as a ket |φ⟩, a column vector in Hilbert space, while its dual bra is ⟨ψ|, a row vector formed by the Hermitian conjugate. The inner product between states, ⟨ψ|φ⟩, computes the overlap integral, yielding a complex number whose magnitude squared gives the transition probability: \langle \psi | \phi \rangle = \int_{-\infty}^{\infty} \psi^*(x) \, \phi(x) \, dx This notation simplifies operator applications and expectation values, such as ⟨ψ|Ĥ|ψ⟩ for energy. Paul Dirac introduced this bra-ket formalism in 1939 to streamline quantum expressions, replacing cumbersome wave function integrals with abstract vector operations while preserving physical interpretability.[20]Computing and programming
Pipe operator
In Unix-like operating systems, the vertical bar serves as the pipe operator |, which redirects the standard output of a command on its left as the standard input to a command on its right, enabling the chaining of multiple processes in a data stream. This mechanism, known as shell piping, was conceived by Douglas McIlroy and implemented in the third edition of Unix in 1973 by Ken Thompson, following McIlroy's advocacy for linking programs to process streams efficiently.[21][22] For example, the commandls | grep "file" lists directory contents and filters for lines containing "file", demonstrating how output flows seamlessly without manual file handling.
Piping supports chaining of multiple commands, as seen in Bash with expressions like cat file.txt | sort | uniq, where the contents of a file are read, sorted alphabetically, and deduplicated in a single pipeline. PowerShell adopts a similar | operator for object-oriented pipelines, allowing cmdlets to process .NET objects directly; for instance, Get-Process | Where-Object {$_.CPU -gt 100} | Stop-Process retrieves processes, filters those using over 100 CPU units, and terminates them.[23] This streaming approach enhances performance by avoiding the creation of intermediate files, reducing disk I/O overhead compared to temporary file-based workflows, though kernel-level buffering in pipes can introduce latency for very large datasets.[24]
Beyond shells, the pipe concept extends to programming languages for function composition. In Elixir, the |> operator chains functions by passing the result of the left expression as the first argument to the right, as in String.split("hello world", " ") |> Enum.map(&String.capitalize/1), which splits a string and capitalizes each word.[25] Similarly, R's magrittr package provides the %>% operator for forwarding values through a sequence of functions, exemplified by mtcars %>% subset(cyl == 6) %>% transform(mpg = mpg * 1.1), which filters a dataset and modifies values in a readable pipeline.[26]
Logical disjunction
The vertical bar | is used as a symbol for logical disjunction in some notations, particularly in computing and programming languages, representing the inclusive OR operation where the compound proposition P | Q is true if at least one of P or Q is true, and false only if both are false.[27] This operation is fundamental to Boolean algebra and formal reasoning systems. The truth table for the disjunction of two propositions P and Q using | is as follows: | P | Q | P | Q | |-------|-------|-------| | True | True | True | | True | False | True | | False | True | True | | False | False | False | This table illustrates the inclusive nature of the operation, where the result is true in three out of four cases.[28] In programming languages, the vertical bar | is employed as a logical OR operator in certain contexts, notably in ALGOL 68, where it evaluates to true if either operand is true, as defined in the language's standard prelude for boolean expressions.[29] For example, in ALGOL 68, an expression likep | q combines two boolean values, yielding true if at least one is true.[29] This usage was introduced in the design of ALGOL 68, ratified in 1968, influencing subsequent languages' adoption of vertical bar variants for disjunctive logic.[30]
In contrast, many C-like programming languages, such as C and Java, distinguish between the single vertical bar | as a bitwise OR operator—which performs bit-by-bit disjunction on integer operands—and the double vertical bar || as the logical OR operator, which evaluates boolean conditions and supports short-circuit evaluation.[31] For instance, in C, if (a | b) applies bitwise OR to the values of a and b before the conditional check, potentially evaluating both even if the first is nonzero, whereas if (a || b) uses logical OR and skips the second operand if the first is true.[32] This distinction ensures bitwise operations handle numerical data efficiently while logical operations prioritize boolean semantics and performance in control flow.[31]
String concatenation
In several programming languages and database query standards, the vertical bar serves as part of the double vertical bar operator (||), which is dedicated to string concatenation, joining two or more strings or compatible expressions into a single string by appending them sequentially.[33] This operator originated in early systems programming languages and has been standardized for clarity and type safety. One of the earliest uses appears in PL/I, a general-purpose language developed in the 1960s by IBM for mainframe computing, where || explicitly concatenates character, bit, or graphic strings, potentially triggering implicit conversions to string types if operands are not already strings.[33] For example, the expressionNAME = FIRSTNAME || ' ' || LASTNAME; produces a full name string by combining variables and a literal space.[33] Similarly, in REXX, a scripting language introduced by IBM in 1979 for system automation, || performs string concatenation on terms such as variables, literals, or expressions, with no implicit type conversion required as all values are treated as strings by default.[34]
The || operator is also the ANSI SQL standard for string concatenation across database systems like PostgreSQL, Oracle, and Vertica, allowing the merging of column values, literals, and constants.[35] For instance, SELECT first_name || ' ' || last_name AS full_name FROM employees; retrieves employee records with names joined by a space, handling NULL values by propagating them to produce a NULL result if any operand is NULL.[35] This usage extends to other dialects, such as SQLite, where || replaces the non-standard + in some contexts for portability.
A key advantage of || over the + operator—commonly used for arithmetic addition—is its explicit focus on strings, which mitigates type coercion issues where mixing numeric and string operands could lead to unintended addition instead of concatenation.[36] For example, in languages overloading + (like JavaScript or early BASIC dialects), "1" + 2 might yield the string "12", but 1 + "2" could coerce to numeric addition resulting in 3, causing bugs in dynamic contexts; || enforces string handling without such ambiguity.[36] This design choice promotes safer code in mixed-type expressions, as seen in PL/I and SQL where + remains reserved for numerics.[33]
Delimiters and separators
In file URI schemes for Windows and DOS-derived systems, the vertical bar replaces the colon in drive letter specifications to comply with URI syntax rules, where the colon is reserved. For instance, the local pathC:\Users\file.txt is represented as file:///C|/Users/file.txt.[37]
Certain APIs, especially those adhering to the OpenAPI Specification, support the pipeDelimited serialization style for query parameters, using the vertical bar to separate array or object values within a single parameter. An example is ?color=blue|black|brown, which specifies multiple color options.[38]
As an alternative to comma-separated values (CSV) files, pipe-delimited files—often called pipe-separated values (PSV)—use the vertical bar to separate fields, avoiding issues with comma-containing data. A typical record might appear as name|age|city, such as John Doe|30|New York. Government agencies like the U.S. Census Bureau employ this format for datasets, including geographic gazetteer files.[39]
In regular expressions, the vertical bar functions as an alternation operator, enabling a pattern to match one of multiple specified alternatives. For example, cat|dog matches either "cat" or "dog" in a string. To treat the vertical bar as a literal character rather than an operator, it requires escaping, commonly as \| in most regex engines.[40]
Formal grammars
In formal grammars, the vertical bar serves as a key symbol for denoting alternatives within production rules, enabling concise descriptions of syntactic choices in context-free grammars. This usage originated with John Backus's notation for the ALGOL 58 report in 1959, where it separated possible expansions of non-terminals to precisely define the language's syntax.[41] The notation was later refined and named Backus-Naur Form (BNF) by Peter Naur in the ALGOL 60 report, establishing it as a standard for specifying programming language grammars.[42] In BNF, a production rule uses the vertical bar (|) to list mutually exclusive options following the double colon (::=) symbol. For instance, the syntax for a single digit can be expressed as<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9, indicating that any one of these terminal symbols satisfies the non-terminal <digit>.[43] This structure allows recursive definitions for complex constructs, such as arithmetic expressions: <expression> ::= <term> | <expression> + <term> | <expression> - <term>. Such rules underpin the grammars of many programming languages, including Python, where the official grammar employs | to specify alternatives like statement ::= compound_stmt | simple_stmts.[44]
Extended Backus-Naur Form (EBNF) builds on BNF by retaining the vertical bar for alternatives while introducing additional operators, such as square brackets [] for optional elements and curly braces {} or asterisks * for repetition. For example, an EBNF rule for a comma-separated list might be <list> ::= <item> ("," <item>)*, with | used if multiple base forms for <item> are needed, like <item> ::= <number> | <string>. This extension enhances expressiveness without altering the core role of | in marking choices, and it appears in specifications for protocols and data formats.[43]
Graphical representations of grammars, known as syntax or railroad diagrams, visualize alternatives through branching paths connected by vertical lines at choice points. These lines indicate where the parser selects one of several possible routes, mirroring the logical separation provided by | in textual BNF. For example, in a diagram for a conditional statement, vertical lines might fork to paths representing "if-then" or "if-then-else" structures.[45] This visual aid complements textual notations, aiding comprehension of grammar rules in language definitions.
Concurrency and parallelism
In process calculi, the vertical bar symbolizes parallel composition, enabling the concurrent execution of independent processes. In the Calculus of Communicating Systems (CCS), introduced by Robin Milner, the notation P \mid Q represents the parallel execution of two processes P and Q, where they run independently unless they synchronize via complementary actions on shared channels. This operator is associative and commutative, allowing unrestricted interleaving of actions from P and Q, with the overall behavior emerging from their potential interactions.[46] The pi-calculus, an extension of CCS developed by Milner, Parrow, and Walker, employs the same vertical bar for parallel composition, but with enhanced mobility of channel names to model dynamic communication topologies.[47] In P \mid Q, processes operate concurrently, and synchronization occurs only when an output action in one matches an input in the other along the same channel, facilitating scoped interactions without inherent coupling otherwise. The absence of additional operators with | underscores non-interacting parallelism, where processes evolve autonomously until explicit synchronization is possible.[47] In hardware description languages like Verilog, the vertical bar serves as the bitwise OR operator within concurrent procedural blocks, contributing to parallel signal evaluations. For instance, in an always block such asalways @(posedge clk) a <= b | c;, the assignment computes the OR of inputs b and c non-blockingly, with the block executing concurrently alongside other always or assign statements to model hardware simultaneity. This usage highlights how logical operations underpin concurrent behavior in digital designs, distinct from sequential control flow.[48]
Array and language-specific uses
In array programming languages like APL and its successor J, the vertical bar denotes the dyadic residue function, which computes the remainder when the right argument is divided by the left argument, effectively implementing a modulo operation with the arguments in reverse order compared to many other languages. For instance, in APL, the expression3 | 10 evaluates to 1, since 10 divided by 3 yields a quotient of 3 and a remainder of 1; this function extends element-wise to arrays, making it efficient for vectorized computations on numerical data.[49] Monadic application of the vertical bar in APL returns the absolute value of its argument, further supporting array manipulations in mathematical contexts.[49]
J, as a modern dialect of APL designed for array processing, retains this usage of the vertical bar for residue, where m | n produces the residue of n modulo m, facilitating concise expressions for tasks like cyclic indexing or hashing in array operations.[50] This operator aligns with J's emphasis on terse, high-performance array computations, often applied to entire matrices without explicit loops.
In functional languages supporting list comprehensions, such as Haskell, the vertical bar separates the output expression and input generators from conditional guards, enabling readable filtering within declarative list constructions. For example, the comprehension [x^2 | x <- [1..10], even x] generates the squares of even numbers from 1 to 10, with the vertical bar delineating the guard even x that restricts the output.[51] This syntax, borrowed from set-builder notation, promotes clarity in defining filtered arrays or lists. Similarly, in function definitions, vertical bars introduce guards for pattern-based dispatching, as in f x | x > 0 = x; | otherwise = -x, allowing conditional logic without nested if-statements.
Python, while supporting list comprehensions for array-like operations, does not utilize the vertical bar in this syntax; guards are instead prefixed with if, as in [x**2 for x in range(1,11) if x % 2 == 0]. Discussions in Python Enhancement Proposals have explored walrus-like assignment operators (e.g., :=) to enhance expressions within comprehensions, but no adoption of the vertical bar for such roles has occurred, avoiding overlap with its bitwise OR usage.[52] In array contexts, the vertical bar can briefly reference string concatenation for joining array elements into delimited strings, though this is handled via methods like join rather than the operator itself.
Markup and formatting
In wiki markup languages, particularly MediaWiki used by projects like Wikimedia, the vertical bar (|) serves as a key delimiter for constructing tables. Tables begin with {| and end with |}, with rows separated by |- and cells defined by single or double pipes: a single | starts a new cell on a fresh line, while || separates multiple cells on the same line. For example, the syntax { | Orange || Apple | } renders as a simple two-column table row. This pipe-based syntax allows embedding complex wiki content within cells and supports attributes like classes (e.g., { | class="wikitable" | cell1 || cell2 | }), enabling styled tabular presentation without HTML tags.[53]
In Markdown, a lightweight markup language popularized for web documentation, certain flavors such as GitHub Flavored Markdown employ the vertical bar (|) to delineate table columns. Tables are formed by separating headers and rows with pipes, with a header row of hyphens (at least three per column) to distinguish it from data rows; pipes at the edges are optional for simplicity. An example is | First Header | Second Header | \n | ------------- | ------------- | \n | Content Cell | Content Cell |, which produces a basic aligned table. Alignment can be adjusted using colons within the hyphen row (e.g., |:---:| for centering), and pipes within cell content must be escaped as \| to avoid misinterpretation. This extension, not part of original Markdown, facilitates readable tabular data in plain text files rendered to HTML.[54]
LaTeX, a typesetting system for technical documents, utilizes the vertical bar (|) in math mode as a basic delimiter for expressions like sets or absolute values, often paired with commands for proper spacing and scaling. The command \vert produces a single vertical bar suitable as an operator or fence, synonymous with the plain | but recommended for mathematical contexts to ensure consistent rendering. For resizable delimiters, \lvert and \rvert from the amsmath package provide left and right variants that auto-scale with \left and \right (e.g., \left\lvert x \right\rvert for |x| matching content height), while manual sizing options like \big| or \Bigl| allow fine control in complex equations. Double bars for norms use \| or \Vert. These features enhance precise mathematical notation in documents.[55]
In HTML and CSS, the vertical bar (|) appears sparingly in markup and styling, primarily within CSS attribute selectors to handle namespaces or hyphen-separated values. For instance, [lang|=en] targets elements with a lang attribute exactly "en" or starting with "en-" (e.g., "en-US"), using the bar as a namespace separator in qualified names like *|E for any namespace's element E. This selector type, defined in CSS specifications, supports targeted styling based on attribute patterns but is less common than basic attribute matching due to its specialized role in internationalized or modular documents.[56]