40 likes | 266 Views
Notations for Writing Expressions. There are multiple ways to write a mathematical expression. Each way constitutes a distinct syntax . Regardless of the syntax, the expression has a particular meaning. This is its semantics . Examples: a + b Infix notation
E N D
Notations for Writing Expressions • There are multiple ways to write a mathematical expression. • Each way constitutes a distinct syntax. • Regardless of the syntax, the expression has a particular meaning. This is its semantics. • Examples: • a + b Infix notation • sum(a, b) Prefix ("Polish") notation • (+ a b) "Cambridge Polish" notation • a b + Postfix ("Reverse Polish") notation
Why "Polish", "Reverse Polish", etc? • The syntactic structure of expressions was considered by Jan Lukasiewicz, a Polish mathematician, in the early 1900s. • (So it's "Polish" as from Poland, not "polish" like shoe polish.) • Polish, or prefix, notation is commonly found in programming language functions (or methods) • The LISP language uses Cambridge Polish notation • RPN, or Reverse Polish Notation, seems to reflect how computers perform operations – get the operands first, then operate on them. • RPN, is notable for not requiring the use of parentheses to write any expression. • HP scientific calculators were based on RPN for years.
What is "more natural?" • Most people are used to infix notation, but consider: • Elementary arithmetic by hand is done in postfix. 7 + 8 15
A complex example: Quadratic Formula • "by hand": • Infix:X = ( -b ± sqrt( b * b – 4 * a * c ) / (2 * a) • RPN:Xbnegbb * 4 a * c * - sqrt ± 2 a * / =