Hubbry Logo
Infix notationInfix notationMain
Open search
Infix notation
Community hub
Infix notation
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contribute something
Infix notation
Infix notation
from Wikipedia

Infix notation is the notation commonly used in arithmetical and logical formulae and statements. It is characterized by the placement of operators between operands—"infixed operators"—such as the plus sign in 2 + 2.

Usage

[edit]

Binary relations are often denoted by an infix symbol such as set membership aA when the set A has a for an element. In geometry, perpendicular lines a and b are denoted and in projective geometry two points b and c are in perspective when while they are connected by a projectivity when

Infix notation is more difficult to parse by computers than prefix notation (e.g. + 2 2) or postfix notation (e.g. 2 2 +). However many programming languages use it due to its familiarity. It is more used in arithmetic, e.g. 5 × 6.[1]

Further notations

[edit]

Infix notation may also be distinguished from function notation, where the name of a function suggests a particular operation, and its arguments are the operands. An example of such a function notation would be S(1, 3) in which the function S denotes addition ("sum"): S (1, 3) = 1 + 3 = 4.

Order of operations

[edit]

In infix notation, unlike in prefix or postfix notations, parentheses surrounding groups of operands and operators are necessary to indicate the intended order in which operations are to be performed. In the absence of parentheses, certain precedence rules determine the order of operations.

See also

[edit]

References

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
Infix notation is a conventional method of expressing mathematical and logical operations in which the operator is placed between its operands, as in the expression a+ba + b, making it the most intuitive and widely used format for human-readable arithmetic and algebraic statements. This notation requires explicit rules for operator precedence and associativity—such as multiplication preceding —and parentheses to resolve ambiguities in order, ensuring unambiguous . Originating from ancient mathematical practices, infix notation evolved significantly during the , with key symbols like the plus sign emerging as a for "et" (Latin for "and") by the late 1400s, and algebraic forms solidifying in the early 1600s through contributions from mathematicians like and . By the 1700s, figures such as and Leonhard Euler further standardized it, introducing notations for powers and integrals that remain in use today. In , infix notation dominates programming languages due to its , though it poses challenges compared to alternatives like prefix (Polish) or postfix (reverse Polish) notations, which eliminate the need for precedence rules and are more efficient for stack-based . Despite these complexities, it has cemented infix as the foundational notation for mathematics education and scientific communication since the .

Fundamentals

Definition

Infix notation is a syntactic form in which binary operators are placed between their two operands, adhering to the general structure A op B, where A and B represent the operands and op denotes the operator. This positioning of the operator directly between the elements it connects forms the core characteristic of the notation. Infix notation differs from alternative syntactic forms in the placement of operators relative to operands, with operators appearing either preceding or following them in other systems. A formal syntactic definition of infix notation for expressions, such as arithmetic ones, is typically provided through a in Backus-Naur Form (BNF). One standard grammar structure is as follows:

E → E + T | E - T | T T → T * F | T / F | F F → ( E ) | id

E → E + T | E - T | T T → T * F | T / F | F F → ( E ) | id

Here, E denotes an expression non-terminal handling additive operations, T a term non-terminal for multiplicative operations, F a factor non-terminal for atomic elements or parenthesized subexpressions, + and - represent and operators, * and / and division operators, ( and ) parentheses, and id a terminal for identifiers. This recursive enforces operator precedence via non-terminal hierarchy and left-associativity through the production rules. Infix notation serves a primary role in facilitating human-readable mathematical expressions, mirroring conventional writing practices that enhance comprehension of operational relationships. To address ambiguities arising from multiple operators, it relies on established rules for .

Basic Examples

Infix notation is exemplified by simple arithmetic expressions where the operator is placed between two numeric operands. For instance, the expression 2+32 + 3 denotes the of the numbers 2 and 3, resulting in 5. Similarly, 5×45 \times 4 represents the of 5 and 4, yielding 20. In algebraic expressions, variables replace or supplement numbers, maintaining the operator's position between operands. A basic example is a×ba \times b, which signifies the product of variables aa and bb. Another common form is x+y×zx + y \times z, where the of yy and zz is understood to occur before the with xx, illustrating operator precedence in infix structures. Parentheses in infix notation explicitly group operands and operators to override default precedence rules, dictating the evaluation order. For example, (2+3)×4(2 + 3) \times 4 first computes the sum inside the parentheses (yielding 5) and then multiplies by 4, resulting in 20, whereas 2+3×42 + 3 \times 4 without parentheses evaluates to 14 due to multiplication's higher precedence. The hierarchical structure of an infix expression can be visualized using a , which represents the grammar's derivation and operator associations. For the expression a+bca + b - c, assuming left-to-right associativity for operators of equal precedence, the parse tree is as follows:

- / \ + c / \ a b

- / \ + c / \ a b

This tree indicates subtraction as the root operation, with its left subtree being the addition of aa and bb, and the right subtree simply cc; the expression evaluates as (a+b)c(a + b) - c.

Historical Context

Origins in Mathematics

Infix notation, where operators are placed between operands, emerged gradually in mathematical writing as a means to express relations more symbolically than purely verbal descriptions. One of the earliest instances appears in the works of of in the 3rd century AD, who employed a syncopated notation in his Arithmetica that included abbreviations for the unknown quantity and its powers, along with a symbol for equality placed between the sides of an equation, though operations were often indicated verbally or by , marking a preliminary shift toward symbolic placement. For example, Diophantus represented expressions like the sum of terms or equations using abbreviated Greek symbols interspersed among numbers and variables, such as a symbol resembling a final for the unknown. The development of infix notation advanced significantly during the with the introduction of specific symbols for and . In 1489, German mathematician Johannes Widmann first printed the in his treatise Behende und hüpsche Rechenung auf allen Kauffmannschafft (Mercantile Arithmetic), initially using them to denote surpluses and deficits in commercial contexts rather than general operations, though they were soon adapted for arithmetic between terms. These symbols were popularized in by in 1557 in The Whetstone of Witte, where he explicitly defined + as denoting "more" (from surplus) and − as "less" (from defect), facilitating infix expressions like 4 + 5 = 9 in practical calculations. This innovation built on earlier medieval abbreviations like p () and m () but marked the widespread adoption of compact symbols between operands in European texts. Standardization of infix notation in occurred in the late 16th and 17th centuries through the works of and . Viète, in his 1591 publication In artem analyticam isagoge, pioneered systematic literal notation by using vowels for unknowns (e.g., A) and consonants for known quantities (e.g., B, Z), arranging them in infix form with abbreviated words for operations, such as A³ + B²A = B²Z to represent cubic equations while enforcing homogeneity of dimensions. Descartes further refined this in (1637), consistently employing + and − signs, letters near the end of the alphabet (e.g., x, y, z) for unknowns, and superscripts for exponents (e.g., a²), enabling fully symbolic infix equations like x² + 2xy + y² = z² that integrated with geometry. These advancements transformed infix notation from ad hoc abbreviations to a rigorous, universal framework. This period witnessed a broader transition in European from verbose rhetorical descriptions—common in medieval and ancient treatises—to concise symbolic expressions, enabling complex manipulations and influencing subsequent algebraic developments. In the 18th century, introduced notations for (such as aba^b) and early symbols, while Leonhard Euler further standardized forms for powers, functions, and , solidifying its use in advanced .

Adoption in Computing

In the late 1940s and early 1950s, early stored-program computers such as the (1949) and (1951) presented significant challenges for handling infix notation due to their reliance on low-level and assembly languages. Programmers had to manually decompose mathematical expressions into sequential instructions, using subroutines for basic arithmetic operations like addition and multiplication, without any automated parsing of infix forms; this approach was labor-intensive and error-prone, limiting the complexity of expressions that could be efficiently implemented. A breakthrough came in 1954 with the Laning and Zierler system for the Whirlwind computer, the first operational algebraic compiler that accepted mathematical formulas in infix notation, translating them into machine code for guidance computations; however, it had limitations, such as restricted support for operator precedence and no handling of nested expressions beyond basic parentheses. This system highlighted the parsing difficulties of infix notation on resource-constrained hardware, where ad hoc methods like string substitution were often employed to manage associativity without full syntactic analysis. The release of in 1957 by revolutionized the adoption of infix notation in programming, standardizing its use for writing natural mathematical expressions in high-level code, complete with defined precedence rules for operators; this made complex algebraic computations accessible without manual breakdown, influencing subsequent languages and compilers. In calculator design, Hewlett-Packard's (1972) initially employed postfix notation to simplify evaluation on limited hardware, avoiding the need for a full infix parser, but later models like the HP-27S () transitioned to algebraic infix entry to better match user expectations from traditional , incorporating equation-solving capabilities. From the 1960s onward, advancements in technology addressed parsing challenges through methods like recursive descent parsers, which recursively process grammar rules to build syntax trees for expressions. A key contribution was T. Irons' 1961 syntax-directed for , which used a table-driven approach with priority tables to handle operator precedence and parse expressions, integrating semantic actions for code generation; this approach became widely adopted in compilers for its simplicity and adaptability to context-free grammars.

Applications

In Arithmetic and Algebra

Infix notation serves as the standard representation for arithmetic operations in mathematics, positioning the operator between two operands to express computations intuitively. Basic operations such as (++), (-), (×\times or \cdot), and division (÷\div or //) are routinely written this way; for instance, the expression 5+3×25 + 3 \times 2 evaluates to $11$, as multiplication holds higher precedence than addition, requiring evaluation from left to right among operations of equal priority. This notation facilitates everyday calculations, allowing users to directly interpret and perform mental or written arithmetic without additional conversion steps. In algebraic contexts, infix notation enables the formulation and manipulation of equations involving variables and constants, promoting clarity in symbolic reasoning. A common example is the 2x+3=72x + 3 = 7, solved by isolating the variable: subtract $3frombothsidestoobtainfrom both sides to obtain2x = 4, then divide by $2 to yield x=2x = 2. Such expressions rely on the notation's familiarity to balance terms and apply inverse operations systematically, forming the basis for solving systems in introductory . Exponents and roots integrate seamlessly into infix notation, extending its utility to polynomial and radical expressions. For example, x2+yx^2 + y denotes a quadratic expression where the exponent $2appliestoapplies toxbeforeaddition,oftenarisinginformulasforareaordistance.[](https://ocw.mit.edu/courses/6042jmathematicsforcomputersciencespring2015/resources/mit6042js15textbook/)Rootsaresimilarlyhandled,asinbefore addition, often arising in formulas for area or distance.[](https://ocw.mit.edu/courses/6-042j-mathematics-for-computer-science-spring-2015/resources/mit6_042js15_textbook/) Roots are similarly handled, as in\sqrt{x}fortheprincipalsquareroot,whichcanberewrittenasfor the principal square root, which can be rewritten asx^{1/2}$ to align with exponential form while maintaining the infix structure. A frequent pitfall in using infix notation without explicit parentheses arises from overlooking precedence rules, leading to misinterpretation of operator order. Consider 1+2×31 + 2 \times 3, which correctly equals $7(multiplicationfirst:(multiplication first:2 \times 3 = 6,then, then 1 + 6 = 7),butcouldbeerroneouslycomputedas), but could be erroneously computed as (1 + 2) \times 3 = 9ifadditionisprioritized.[](https://runestone.academy/ns/books/published/pythonds/BasicDS/InfixPrefixandPostfixExpressions.html)Parenthesesresolvesuchambiguities,asinif addition is prioritized.[](https://runestone.academy/ns/books/published/pythonds/BasicDS/InfixPrefixandPostfixExpressions.html) Parentheses resolve such ambiguities, as in(1 + 2) \times 3$, ensuring precise evaluation in manual computations.

In Programming and Calculators

In programming languages, infix notation is the standard for expressing operations, where operators are placed between operands, and parsing is handled through built-in precedence rules or user-defined mechanisms like . In C++, allows developers to define custom behavior for infix operators such as + or * for user-defined types, enabling intuitive infix expressions like a + b where a and b are objects of a class, by implementing functions like operator+. Similarly, Python supports infix notation via special methods in its , such as __add__ for the + operator, which permits classes like vectors to use infix syntax (e.g., vec1 + vec2) while the interpreter parses according to operator precedence. Calculators commonly implement infix notation for user input to mimic mathematical writing, with internal evaluation engines that apply . For instance, the accepts infix expressions directly on the , such as 2 + 3 * 4, evaluating them to 14 by respecting precedence ( before ) without requiring postfix conversion from the user. To handle ambiguity in infix expressions, compilers and integrated development environments (IDEs) often issue warnings or errors, prompting the use of parentheses for clarification. In Microsoft Visual C++, compiler warning C4554 flags potential precedence issues in expressions like a & b == c, recommending parentheses (e.g., a & (b == c)) to resolve interpretation. The GNU Compiler Collection (GCC) similarly warns about omitted parentheses in contexts where they affect evaluation, such as assignments mistaken for comparisons, enforcing explicit grouping to avoid unintended results. Many systems employ hybrid approaches for efficient , converting infix input to postfix notation internally using algorithms like the , developed by in 1961. This stack-based method processes infix tokens from left to right, outputting operands immediately and managing operators via a stack based on precedence, producing postfix form (e.g., converting a + b * c to a b c * +) for straightforward stack evaluation without .

Prefix Notation

Prefix notation, also known as Polish notation, is a syntactic form in which an operator precedes its operands. In this system, binary operators are placed before the two operands they connect, and unary operators precede their single operand, eliminating the need for parentheses to denote grouping. For instance, the expression for adding 2 and 3 is written as + 2 3, and negation of a variable p as N p. This notation was invented by the Polish logician Jan Łukasiewicz in the early 1920s as a tool for formal logic, with its first documented use appearing in his 1929 book Elements of Mathematical Logic. Łukasiewicz developed it during lectures at the University of Warsaw to represent logical operations without ambiguity, such as implication (C for "if...then") in expressions like C p q. Unlike conventional infix notation, where operators appear between operands, prefix notation reverses this order to prioritize the operator. A simple conversion from to prefix illustrates the transformation: the infix expression a + b becomes + a b in prefix form, while a more complex one like (a + b) * c converts to * + a b c. This restructuring fully encodes the directly in the sequence of symbols. One key advantage of prefix notation is its unambiguous , as the position of the operator inherently defines the scope and precedence without requiring additional rules or parentheses. This simplifies in logical and computational contexts, reducing errors in complex expressions and facilitating machine processing.

Postfix Notation

Postfix notation, also known as , is a in which operators follow their operands, eliminating the need for parentheses to specify . For instance, the infix expression 2+32 + 3 is written in postfix as 2 3 +2\ 3\ +. This structure allows expressions to be unambiguously parsed from left to right. A common application involves converting infix expressions to postfix form. Consider the infix expression a×(b+c)a \times (b + c): it is transformed to postfix as a b c + ×a\ b\ c\ +\ \times, where the addition is performed first on bb and cc, and the result is then multiplied by aa. This conversion follows a systematic using a stack to handle operator precedence and parentheses. Postfix notation is well-suited for stack-based evaluation, a process where operands are pushed onto a stack as they are encountered, and operators pop the necessary operands, compute the result, and push it back onto the stack. This approach enables efficient, iterative computation without recursive calls or explicit precedence rules. It is prominently used in the Forth programming language, which relies on postfix syntax and stack operations for all expressions and control flow. The notation was developed in the 1950s by Arthur W. Burks, Don W. Warren, and Jesse B. Wright to facilitate in early electronic machines, as outlined in their analysis of a parenthesis-free . Their work demonstrated how postfix enables compact representation and straightforward hardware implementation for arithmetic and logical operations.

Parsing and Evaluation

Order of Operations

Infix notation relies on established conventions to resolve ambiguities in expressions containing multiple operators, ensuring consistent evaluation across mathematical contexts. These conventions, often summarized by the mnemonic PEMDAS (Parentheses, Exponents, and Division, and ) in the , dictate that operations are performed in a specific sequence: first within parentheses (or brackets), then exponents (or orders), followed by multiplication and division from left to right, and finally addition and subtraction from left to right. An equivalent mnemonic, BODMAS (Brackets, Orders, Division and , and ), is commonly used in the and other regions, reflecting the same underlying rules but with terminology adjusted for local preferences. To illustrate, consider the infix expression 2+3×422 + 3 \times 4^2. Evaluation proceeds as follows: first compute the exponent 42=164^2 = 16; then the multiplication 3×16=483 \times 16 = 48; and finally the addition 2+48=502 + 48 = 50. This step-by-step process highlights how precedence levels prevent misinterpretation, such as treating the expression as (2+3)×42=80(2 + 3) \times 4^2 = 80, which would violate the conventions. A key aspect of these conventions is left-to-right associativity for operators of equal precedence, which resolves ties without additional parentheses. For instance, in 20÷4×320 \div 4 \times 3, division and multiplication share precedence, so evaluate left to right: 20÷4=520 \div 4 = 5, then 5×3=155 \times 3 = 15, rather than 20÷(4×3)=20÷121.6720 \div (4 \times 3) = 20 \div 12 \approx 1.67. Similarly, 103+210 - 3 + 2 becomes (103)+2=9(10 - 3) + 2 = 9, not 10(3+2)=510 - (3 + 2) = 5. While arithmetic expressions uniformly adopt left-to-right associativity, variations exist in other fields; for example, in , the implication operator (\to or \Rightarrow) is conventionally right-associative, parsing abca \to b \to c as a(bc)a \to (b \to c). Related notations like prefix and postfix avoid such precedence rules altogether by positioning operators unambiguously relative to operands.

Precedence and Associativity

In infix notation, operator precedence determines the order in which operators are evaluated when multiple operators appear in an expression without parentheses, with higher-precedence operators binding more tightly to their operands. Associativity resolves ambiguities when operators of equal precedence are encountered, specifying whether they group from left to right or right to left. These rules are essential for unambiguously constructing the parse tree of an expression, ensuring consistent interpretation across mathematical and computational contexts. The standard precedence hierarchy for common arithmetic operators in infix expressions follows the conventions of PEMDAS (Parentheses, Exponents, /Division, /), where exponents have the highest precedence among binary operators, followed by and division (equal precedence), and and (lowest, equal precedence). This hierarchy is depicted in the table below, listing operators from highest to lowest precedence (excluding parentheses, which always have the highest effective precedence).
Precedence LevelOperatorsDescription
3 (Highest)^ ()Power operations
2(), / (division)Multiplicative operations
1 (Lowest)+ (), - ()Additive operations
This hierarchy ensures that, for instance, in the expression a+b×ca + b \times c, the multiplication is performed before addition, forming the subtree b×cb \times c first in the . Associativity applies when multiple operators of the same precedence are chained. Most arithmetic operators are left-associative, meaning they group from left to right; for example, abca - b - c parses as (ab)c(a - b) - c, creating a left-leaning where the left is evaluated first. Exponentiation, however, is typically right-associative, so a ^ b ^ c parses as a(bc)a ^ (b ^ c), forming a right-leaning that evaluates the right first. This distinction prevents ambiguities in chained operations and aligns with mathematical conventions for non-commutative operators like and division. The interplay of precedence and associativity directly influences construction. Consider the expression a/bca / b * c: since division and share the same precedence level and are left-associative, it parses as (a/b)c(a / b) * c. The has division as the root of the left subtree, with as the overall root, binding aa to bb first before multiplying by cc. If associativity were right instead, it would parse as a/(bc)a / (b * c), altering the and result, but the standard left associativity ensures predictable left-to-right evaluation for multiplicative operators. Unary operators, such as the unary minus (), are assigned higher precedence than binary arithmetic operators to treat them as modifiers of single operands. For example, in a+b-a + b, the unary minus binds tightly to aa, parsing as (a)+b(-a) + b and forming a subtree for the negation before the . This elevated precedence distinguishes unary minus from binary subtraction, preventing incorrect groupings like (a+b)-(a + b) in such contexts and maintaining the integrity of term-level negations in the overall .

References

  1. https://.org/pdf/2501.07660
Add your contribution
Related Hubs
Contribute something
User Avatar
No comments yet.