Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Reduce (computer algebra system)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Types and variable scope == REDUCE inherits [[Scope (computer science)|dynamic scoping]] from Lisp, which means that data have types but variables themselves do not: the type of a variable is the type of the data assigned to it. The simplest REDUCE data types are Standard Lisp [[Lisp (programming language)|atomic]] types such as identifiers, machine numbers (i.e. "small" integers and floating-point numbers supported directly by the computer hardware), and strings. Most other REDUCE data types are represented internally as Lisp lists whose first element (<code>car</code>) indicates the data type. For example, the REDUCE input <syntaxhighlight lang="octave" copy> mat((1, 2), (3, 4)); </syntaxhighlight> produces the display <div class="center" style="width: auto; margin-left: auto; margin-right: auto;"><math> \left(\begin{matrix}1&2\\3&4\end{matrix}\right) </math></div> and the internal representation of this matrix is the Lisp list (mat (1 2) (3 4)) The main algebraic objects used in REDUCE are quotients of two possibly-multivariate polynomials, the indeterminates of which, called ''kernels'', may in fact be functions of one or more variables, e.g. the input <syntaxhighlight lang="octave" copy> z := (x + y^2)/f(x,y); </syntaxhighlight> produces the display <div class="center" style="width: auto; margin-left: auto; margin-right: auto;"><math> z\ \mathrm{:=}\ \frac{x+y^2}{f\left(x,y\right)} </math></div> REDUCE uses two representations for such algebraic objects. One is called ''prefix form'', which is just the Standard Lisp code for the expression and is convenient for operations such as input and output; e.g. for <math>z</math> it is (quotient (plus x (expt y 2)) (f x y)) The other is called ''standard quotient'' form, which is better for performing algebraic manipulations such as addition; e.g. for <math>z</math> it is (!*sq ((((x . 1) . 1) ((y . 2) . 1)) (((f x y) . 1) . 1)) t) REDUCE converts between these two representations as necessary, but tries to retain ''standard quotient'' form as much as possible to avoid the conversion overhead. Because variables have no types there are no variable type [[Declaration (computer programming)|declarations]] in REDUCE, but there are [[Variable (computer science)|variable scope]] declarations. The scope of a variable refers to the range of a program throughout which it has the same significance. By default, REDUCE variables are automatically [[Scope (computer science)|global]] in scope, meaning that they have the same significance everywhere, i.e. once a variable has been assigned a value, it will evaluate to that same value everywhere. Variables can be declared to have scope limited to a particular block of code by delimiting that block of code by the keywords <code>begin</code> and <code>end</code>, and declaring the variables <code>scalar</code> at the start of the block, using the following syntax (as illustrated in the [[#Algebraic programming examples|algebraic programming examples]] above): <code>begin</code> <code>scalar</code> ''variable1'', ''variable2'', ...; ''statements'' <code>end</code> Each variable so declared can optionally be followed by an assignment operator (<code>:=</code>) and an initial value. The keyword <code>scalar</code> should be read as meaning ''[[Local variable|local]]''. (The reason for the name ''[[Scalar (physics)|scalar]]'' is buried in the history of REDUCE, but it was probably chosen to distinguish local variables from the [[Four-vector|relativistic 4-vectors]] and [[Gamma matrices|Dirac gamma matrices]] defined in the [[Particle physics|high-energy physics]] package, which was the original core of REDUCE.<ref name=":0" />) The <code>scalar</code> keyword can be replaced by <code>integer</code> or <code>real</code>. The difference is that <code>integer</code> variables are initialized by default to 0, whereas <code>scalar</code> and <code>real</code> variables are initialized by default to the Lisp value <code>nil</code> (which has the algebraic value 0 anyway). This distinction is more significant in the REDUCE implementation language, RLISP, also known as ''symbolic'' or ''lisp mode''. Otherwise, it is useful as documentation of the intended use of local variables. There are two other variable declarations that are used only in the implementation of REDUCE, i.e. in symbolic mode. The REDUCE <code>begin</code>...<code>end</code> block described above is translated into a Standard Lisp <code>prog</code> form by the REDUCE [[Parsing|parser]], and all Standard Lisp variables should either be [[Free variables and bound variables|bound]] in <code>prog</code> forms, or declared <code>global</code> or <code>fluid</code>. In RLISP, these declarations look like this: <code>fluid '(</code>''variable1'' ''variable2'' ...<code>)</code> <code>global '(</code>''variable1'' ''variable2'' ...<code>)</code> A <code>global</code> variable cannot be rebound in a <code>prog</code> form, whereas a <code>fluid</code> variable can. This distinction is normally only significant to a Lisp compiler and is used to maximize efficiency; in interpreted code these declarations can be skipped and undeclared variables are effectively <code>fluid</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)