Go to the first, previous, next, last section, table of contents.![Expressions Expressions](https://s2.studylib.net/store/data/014070344_1-753f47a717196bb33f6c0a51654f22ee.png)
![X 3 5 x 1 2 X 3 5 x 1 2](https://saylordotorg.github.io/text_elementary-algebra/section_10/f654d416a6bede19ef08a92cb069dc06.jpg)
A Scheme expression is a construct that returns a value, such as avariable reference, literal, procedure call, or conditional.
![Expressions Expressions](https://s2.studylib.net/store/data/014070344_1-753f47a717196bb33f6c0a51654f22ee.png)
Expression types are categorized as primitive or derived.Primitive expression types include variables and procedure calls.Derived expression types are not semantically primitive, but can insteadbe explained in terms of the primitive constructs as insection derived expression types. They are redundant in the strict sense ofthe word, but they capture common patterns of usage, and are thereforeprovided as convenient abbreviations.
- After you enter the expression, Algebra Calculator will plug x=6 in for the equation 2x+3=15: 2(6)+3 = 15. The calculator prints 'True' to let you know that the answer is right. More Examples Here are more examples of how to check your answers with Algebra Calculator. Feel free to try them now. For x+6=2x+3, check (correct) solution x=3: x+6=2x.
- 5xy 2 has a degree of 3 (x has an exponent of 1, y has 2, and 1+2=3) 3x has a degree of 1 (x has an exponent of 1) 5y 3 has a degree of 3 (y has an exponent of 3) 3 has a degree of 0 (no variable) The largest degree of those is 3 (in fact two terms have a degree of 3), so the polynomial has a degree of 3.
Primitive expression types
Free math problem solver answers your algebra, geometry, trigonometry, calculus, and statistics homework questions with step-by-step explanations, just like a math tutor.
Variable references
essential syntax:<variable>
An expression consisting of a variable
(section Variables and regions) is a variable reference. The value ofthe variable reference is the value stored in the location to which thevariable is bound. It is an error to reference anunboundvariable.
Literal expressions
essential syntax:quote<datum>
essential syntax:'<datum>
essential syntax:<constant>
(quote <datum>)
evaluates to <datum>.<Datum> may be any external representation of a Scheme object (seesection External representations). This notation is used toinclude literal constants in Scheme code.(quote <datum>)
may be abbreviated as'<datum>. The two notations are equivalent in allrespects.Numerical constants, string constants, character constants, and booleanconstants evaluate 'to themselves'; they need not be quoted.
As noted in section Storage model, it is an error to alter a constant(i.e. the value of a literal expression) using a mutation procedure like
set-car!
or string-set!
.Procedure calls
Screenflick 2 2 11 – capture screen movement to video. essential syntax:<operator><operand 1> ..
A procedure call is written by simply enclosing in parenthesesexpressions for the procedure to be called and the arguments to bepassed to it. The operator and operand expressions are evaluated (in anunspecified order) and the resulting procedure is passed the resultingarguments.
A number of procedures are available as the values of variables in theinitial environment; for example, the addition and multiplicationprocedures in the above examples are the values of the variables
+
and *
.New procedures are created by evaluating lambda expressions (see sectionsection Lambda expressions).Procedure calls are also called combinations.
Note: In contrast to other dialects of Lisp, the order ofevaluation is unspecified, and the operator expression and the operandexpressions are always evaluated with the same evaluation rules.
Note: Although the order of evaluation is otherwise unspecified, the effect ofany concurrent evaluation of the operator and operand expressions isconstrained to be consistent with some sequential order of evaluation.The order of evaluation may be chosen differently for each procedure call.
Note: In many dialects of Lisp, the empty combination,
()
, is a legitimate expression. In Scheme, combinations musthave atleast one subexpression, so ()
is not a syntactically validexpression.Lambda expressions
essential syntax:lambda<formals> <body>
Syntax: <Formals> should be a formal arguments list as described below,and <body> should be a sequence of one or more expressions.
Semantics: A lambda expression evaluates to a procedure. The environment ineffect when the lambda expression was evaluated is remembered as part of theprocedure. When the procedure is later called with some actualarguments, the environment in which the lambda expression was evaluated willbe extended by binding the variables in the formal argument list tofresh locations, the corresponding actual argument values will be storedin those locations, and the expressions in the body of the lambda expressionwill be evaluated sequentially in the extended environment. The resultof the last expression in the body will be returned as the result ofthe procedure call.
<Formals> should have one of the following forms:
(<variable 1> ..)
:The procedure takes a fixed number of arguments; when the procedure iscalled, the arguments will be stored in the bindings of thecorresponding variables.- <variable>:The procedure takes any number of arguments; when the procedure iscalled, the sequence of actual arguments is converted into a newlyallocated list, and the list is stored in the binding of the<variable>.
(<variable 1> .. <variable n-1> . <variable n>)
:If a space-delimited period precedes the last variable, thenthe value stored in the binding of the last variable will be anewly allocatedlist of the actual arguments left over after all the other actualarguments have been matched up against the other formal arguments.
It is an error for a <variable> to appear more than once in<formals>.
![X 3 5 x 1 2 X 3 5 x 1 2](https://saylordotorg.github.io/text_elementary-algebra/section_10/f654d416a6bede19ef08a92cb069dc06.jpg)
Each procedure created as the result of evaluating a lambda expressionis tagged with a storage location, in order to make
eqv?
andeq?
work on procedures (see section Equivalence predicates).Conditionals
essential syntax:if<test> <consequent> <alternate>
syntax:if<test> <consequent>
Syntax: <Test>, <consequent>, and <alternate> may be arbitraryexpressions.
Semantics: An
if
expression is evaluated as follows: first,<test> is evaluated. If it yields a true value(see section Booleans), then <consequent> is evaluatedand its value is returned. Otherwise <alternate> is evaluated andits value is returned. If <test> yields a false value and no<alternate> is specified, then the result of the expression isunspecified.Assignments
essential syntax:set!<variable> <expression>
<Expression> is evaluated, and the resulting value is stored inthe location to which <variable> is bound. <Variable> mustbe bound either in some regionenclosing the
set!
expressionor at top level. The result of the set!
expression isunspecified.Derived expression types
For reference purposes, section derived expression types gives rewrite rulesthat will convert constructs described in this section into theprimitive constructs described in the previous section.
Conditionals
essential syntax:cond<clause 1> <clause 2> ..
Syntax: Each <clause> should be of the formwhere <test> is any expression. The last <clause> may bean 'else clause,' which has the form
Semantics: A
cond
expression is evaluated by evaluating the <test>expressions of successive <clause>s in order until one of themevaluates to a true value(see section Booleans). When a <test> evaluates to atrue value, then the remaining <expression>s in its <clause> areevaluated in order, and the result of the last <expression> in the<clause> is returned as the result of the entire cond
expression. If the selected <clause> contains only the <test>and no <expression>s, then the value of the <test> is returnedas the result. If all <test>s evaluate to false values, and thereis no else clause, then the result of the conditional expression isunspecified; if there is an else clause, then its <expression>s areevaluated, and the value of the last one is returned.Some implementations support an alternative <clause> syntax,
(<test> => <recipient>)
, where <recipient> is anexpression. If <test> evaluates to a true value, then<recipient> is evaluated. Its value must be a procedure of oneargument; this procedure is then invoked on the value of the<test>.essential syntax:case<key> <clause 1> <clause 2> ..
Syntax: <Key> may be any expression. Each <clause> should havethe formwhere each <datum> is an external representation of some object.All the <datum>s must be distinct.The last <clause> may be an 'else clause,' which has the form
Semantics: A
case
expression is evaluated as follows. <Key> isevaluated and its result is compared against each <datum>. If theresult of evaluating <key> is equivalent (in the sense ofeqv?
; see section Equivalence predicates) to a <datum>, then theexpressions in the corresponding <clause> are evaluated from leftto right and the result of the last expression in the <clause> isreturned as the result of the case
expression. If the result ofevaluating <key> is different from every <datum>, then ifthere is an else clause its expressions are evaluated and theresult of the last is the result of the case
expression;otherwisethe result of the case
expression is unspecified.essential syntax:and<test 1> ..
The <test> expressions are evaluated from left to right, and thevalue of the first expression that evaluates to a false value (seesection Booleans) is returned. Any remaining expressionsare not evaluated. If all the expressions evaluate to true values, thevalue of the last expression is returned. If there are no expressionsthen
#t
is returned.essential syntax:or<test 1> ..
The <test> expressions are evaluated from left to right, and the value of thefirst expression that evaluates to a true value (seesection Booleans) is returned. Any remaining expressionsare not evaluated. If all expressions evaluate to false values, thevalue of the last expression is returned. If there are noexpressions then
#f
is returned.Binding constructs
The three binding constructs
let
, let*
, and letrec
give Scheme a block structure, like Algol 60. The syntax of the threeconstructs is identical, but they differ in the regionsthey establishfor their variable bindings. In a let
expression, the initialvalues are computed before any of the variables become bound; in alet*
expression, the bindings and evaluations are performedsequentially; while in a letrec
expression, all the bindings areineffect while their initial values are being computed, thus allowingmutually recursive definitions.essential syntax:let<bindings> <body>
Syntax: <Bindings> should have the formwhere each <init> is an expression, and <body> should be asequence of one or more expressions. Arcsoft™ – website builder 1 2. It isan error for a <variable> to appear more than once in the list of variablesbeing bound.
Semantics: The <init>s are evaluated in the current environment (in someunspecified order), the <variable>s are bound to fresh locationsholding the results, the <body> is evaluated in the extendedenvironment, and the value of the last expression of <body> isreturned. Each binding of a <variable> has <body> as itsregion.
See also named
let
, section Iteration.syntax:let*<bindings> <body>
Syntax: <Bindings> should have the formand <body> should be a sequence ofone or more expressions.
Semantics:
Let*
is similar to let
, but the bindings are performedsequentially from left to right, and the regionof a binding indicatedby (<variable> <init>)
is that part of the let*
expression to the right of the binding. Thus the second binding is donein an environment in which the first binding is visible, and so on.essential syntax:letrec<bindings> <body>
Syntax: <Bindings> should have the formand <body> should be a sequence ofone or more expressions. It is an error for a <variable> to appear morethan once in the list of variables being bound.
Semantics: The <variable>s are bound to fresh locationsholding undefined values, the <init>s are evaluated in the resultingenvironment (in some unspecified order), each <variable> is assignedto the result of the corresponding <init>, the <body> isevaluated in the resulting environment, and the value of the lastexpression in <body> is returned. Each binding of a <variable>has the entire
letrec
expression as its region , making itpossible to define mutually recursive procedures.One restriction on
letrec
is very important: it must be possibleto evaluate each <init> without assigning or referring to the value of any<variable>. If this restriction is violated, then it is an error. Therestriction is necessary because Scheme passes arguments by value rather than byname. In the most common uses of letrec
, all the <init>s arelambda expressions and the restriction is satisfied automatically.Sequencing
essential syntax:begin<expression 1> <expression 2> ..
The <expression>s are evaluated sequentially from left to right,and the value of the last <expression> is returned. Thisexpression type is used to sequence side effects such as input andoutput.
Note:[SICP] uses the keyword
sequence
instead of begin
.Iteration
syntax:do<bindings> <clause> <body>
Syntax: <Bindings> should have the form<clause> should be of the formand <body> should be a sequence of one or more expressions.
Do
is an iteration construct. It specifies a set of variables tobe bound, how they are to be initialized at the start, and how they areto be updated on each iteration. When a termination condition is met,the loop exits with a specified result value.Do
expressions are evaluated as follows:The <init> expressions are evaluated (in some unspecified order),the <variable>s are bound to fresh locations, the results of the<init> expressions are stored in the bindings of the<variable>s, and then the iteration phase begins.Each iteration begins by evaluating <test>; if the result isfalse (see section Booleans), then the <command>expressions are evaluated in order for effect, the <step>expressions are evaluated in some unspecified order, the<variable>s are bound to fresh locations, the results of the<step>s are stored in the bindings of the<variable>s, and the next iteration begins.
If <test> evaluates to a true value, then the<expression>s are evaluated from left to right and the value ofthe last <expression> is returned as the value of the
do
expression. If no <expression>s are present, then the value ofthe do
expression is unspecified.1 3 X 1 3 Fraction
The regionof the binding of a <variable> consists of the entire
do
expression except for the <init>s. It is an error for a<variable> to appear more than once in the list of do
variables.A <step> may be omitted, in which case the effect is thesame as if
(<variable> <init> <variable>)
hadbeen written instead of (<variable> <init>)
.syntax:let<variable> <bindings> <body>
Some implementations of Scheme permit a variant on the syntax of
let
called 'named let
' which provides a more generallooping construct than do
, and may also be used to expressrecursions.Named
let
has the same syntax and semantics as ordinarylet
except that <variable> is bound within <body> to aprocedure whose formal arguments are the bound variables and whose bodyis <body>. Thus the execution of <body> may be repeated byinvoking the procedure named by <variable>.Delayed evaluation
syntax:delay<expression>
The
delay
construct is used together with theprocedure force
toimplement lazy evaluation or call by need.(delay <expression>)
returns an object called apromise which at some point in the future may be asked (bythe force
procedure)to evaluate <expression> and deliver the resulting value.See the description of
force
(section Control features) for amore complete description of delay
.Quasiquotation
essential syntax:quasiquote<template>
essential syntax:`<template>
'Backquote' or 'quasiquote'expressions are usefulfor constructing a list or vector structure when most but not all of thedesired structure is known in advance. If nocommasappear within the <template>, the result of evaluating
`<template>
is equivalent to the result of evaluating'<template>
. If a commaappears within the<template>, however, the expression following the comma isevaluated ('unquoted') and its result is inserted into the structureinstead of the comma and the expression. If a comma appears followedimmediately by an at-sign (@),then the followingexpression must evaluate to a list; the opening and closing parenthesesof the list are then 'stripped away' and the elements of the list areinserted in place of the comma at-sign expression sequence.Quasiquote forms may be nested. Substitutions are made only forunquoted components appearing at the same nesting levelas the outermost backquote. The nesting level increases by one insideeach successive quasiquotation, and decreases by one inside eachunquotation.
The notations
`<template>
and(quasiquote <template>)
are identical in all respects.,<expression>
is identical to (unquote<expression>)
, and ,<expression>
is identical to(unquote-splicing <expression>)
. The external syntaxgenerated by write
for two-element lists whosecar is one of these symbols may vary between implementations.Unpredictable behavior can result if any of the symbols
Go to the first, previous, next, last section, table of contents.quasiquote
, unquote
, or unquote-splicing
appear inpositions within a <template> otherwise than as described above.Problem: Evaluate the following arithmetic expression:
3 5 X 2 3
3 + 4 x 2
Solution:
Student 1 | Student 2 |
3 + 4 x 2 | 3 + 4 x 2 |
= 7 x 2 | = 3 + 8 |
= 14 | = 11 |
It seems that each student interpreted the problem differently, resulting in two different answers. Student 1 performed the operation of addition first, then multiplication; whereas student 2 performed multiplication first, then addition. When performing arithmetic operations there can be only one correct answer. We need a set of rules in order to avoid this kind of confusion. Mathematicians have devised a standard order of operations for calculations involving more than one arithmetic operation.
Rule 1: First perform any calculations inside parentheses.
Rule 2: Next perform all multiplications and divisions, working from left to right.
Rule 3: Lastly, perform all additions and subtractions, working from left to right.
The above problem was solved correctly by Student 2 since she followed Rules 2 and 3. Let's look at some examples of solving arithmetic expressions using these rules.
Expressions 1 3 3 X 5/6
Example 1: Evaluate each expression using the rules for order of operations.
Solution: Popchar x 7 6 download free.
Order of Operations | ||
Expression | Evaluation | Operation |
6 + 7 x 8 | = 6 + 7 x 8 | Multiplication |
= 6 + 56 | Addition | |
= 62 | ||
16 ÷ 8 - 2 | = 16 ÷ 8 - 2 | Division |
= 2 - 2 | Subtraction | |
= 0 | ||
(25 - 11) x 3 | = (25 - 11) x 3 | Parentheses |
= 14 x 3 | Multiplication | |
= 42 |
In Example 1, each problem involved only 2 operations. Let's look at some examples that involve more than two operations.
Example 2: Evaluate 3 + 6 x (5 + 4) ÷ 3 - 7 using the order of operations.
Solution:
Step 1: | 3 + 6 x (5 + 4)÷ 3 - 7 | = | 3 + 6 x 9 ÷ 3 - 7 | Parentheses |
Step 2: | 3 + 6 x 9÷ 3 - 7 | = | 3 + 54 ÷ 3 - 7 | Multiplication |
Step 3: | 3 + 54 ÷ 3 - 7 | = | 3 + 18 - 7 | Division |
Step 4: | 3 + 18 - 7 | = | 21 - 7 | Addition |
Step 5: | 21 - 7 | = | 14 | Subtraction |
Example 3: Evaluate 9 - 5 ÷ (8 - 3) x 2 + 6 using the order of operations.
Solution:
Step 1: | 9 - 5 ÷(8 - 3) x 2 + 6 | = | 9 - 5 ÷ 5 x 2 + 6 | Parentheses |
Step 2: | 9 - 5 ÷ 5 x 2 + 6 | = | 9 - 1 x 2 + 6 | Division |
Step 3: | 9 - 1 x 2 + 6 | = | 9 - 2 + 6 | Multiplication |
Step 4: | 9 - 2 + 6 | = | 7 + 6 | Subtraction |
Step 5: | 7 + 6 | = | 13 | Addition |
In Examples 2 and 3, you will notice that multiplication and division were evaluated from left to right according to Rule 2. Similarly, addition and subtraction were evaluated from left to right, according to Rule 3.
When two or more operations occur inside a set of parentheses, these operations should be evaluated according to Rules 2 and 3. This is done in Example 4 below.
Example 4: Evaluate 150 ÷ (6 + 3 x 8) - 5 using the order of operations.
Solution:
Step 1: | 150 ÷ (6 + 3 x 8) - 5 | = | 150 ÷ (6 + 24) - 5 | Multiplication inside Parentheses |
Step 2: | 150 ÷(6 + 24) - 5 | = | 150 ÷ 30 - 5 | Addition inside Parentheses |
Step 3: | 150 ÷ 30 - 5 | = | 5 - 5 | Division |
Step 4: | 5 - 5 | = | 0 | Subtraction |
Example 5: Evaluate the arithmetic expression below:
Solution: This problem includes a fraction bar (also called a vinculum), which means we must divide the numerator by the denominator. However, we must first perform all calculations above and below the fraction bar BEFORE dividing.
Thus
Evaluating this expression, we get:
Example 6: Write an arithmetic expression for this problem. Then evaluate the expression using the order of operations.
Mr. Smith charged Jill $32 for parts and $15 per hour for labor to repair her bicycle. If he spent 3 hours repairing her bike, how much does Jill owe him?
Solution: 32 + 3 x 15 = 32 + 3 x 15 = 32 + 45 = 77
Jill owes Mr. Smith $77.
Summary: When evaluating arithmetic expressions, the order of operations is:
- Simplify all operations inside parentheses.
- Perform all multiplications and divisions, working from left to right.
- Perform all additions and subtractions, working from left to right.
If a problem includes a fraction bar, perform all calculations above and below the fraction bar before dividing the numerator by the denominator.
Exercises
Directions: Complete each exercise by applying the rules for order of operations. Click once in an ANSWER BOX and type in your answer; then click ENTER. After you click ENTER, a message will appear in the RESULTS BOX to indicate whether your answer is correct or incorrect. To start over, click CLEAR.
1. | 9 + 6 x (8 - 5) |
2. | (14 - 5) ÷ (9 - 6) |
3. | 5 x 8 + 6 ÷ 6 - 12 x 2 |
3 5 X 3 4
4. |
3 4 X 4 5
5. | A caterer charges a setup fee of $50, plus $20 per person. How much will the caterer charge if 35 people attend the party, and the customer has a coupon for $100 off the total? |