Abstract
This chapter discusses rule-based programming. Paragraphs in Mathematica are constructed in essentially three ways: 1) by remaining in the functional programming paradigm and constructing nested sequences of one liners, each of which uses some of the functions defined in the previous one liners; 2) by defining a function by an expression of the form f [ x_] := body, which is just a special case of a rewrite rule of the form f [pattern] := body; and 3) by using Mathematica as a block structured language with the usual control structures of an imperative language. Establishing rewrite rules in Mathematica is done in two primary fashions: through following global rules and local rules. Global rules are rules that are applied whenever the appropriate left-hand side is encountered. There are two kinds of user-defined global rewrite rules: those using “=” and those using “:=”. While local rewrite rules are rules that are applied only to a single expression, the basic syntactical ingredient of a local rewrite rule is an arrow. Pattern matching is a basic ingredient of rule-based programming. A compound pattern is an expression with zero or more of simple patterns as subexpressions. Patterns play an important role in both global and local rules.
Talk to us
Join us for a 30 min session where you can share your feedback and ask us any queries you have
More From: Mastering Mathematica: Programming Methods and Applications
Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.