You are on page 1of 9

# Absolute Value Functions

An absolute value function is a function that contains an algebraic expression within absolute value symbols. Recall that the absolute value of a number is its distance from 0 on the number line. The absolute value parent function, written as f(x) !x!, is defined as

To graph an absolute value function, choose several values of x and find some ordered pairs.

## "lot the points on a coordinate plane and connect them.

#bserve that the graph is \$%shaped. (&) The vertex of the graph is (0, 0). (') The axis of symmetry ( x halves. 0 or y %axis) is the line that divides the graph into two congruent

(() The domain is the set of all real numbers. ()) The range is the set of al real numbers greater than or e*ual to 0. (+) The x%intercept and the y%intercept are both 0. .

Vertical Shift
To translate the absolute value function f(x) g(x) f(x) , k . !x! vertically, you can use the function

## -hen k / 0, the graph of g(x) translated k units down.

Horizontal Shift
To translate the absolute value function f(x) g(x) f(x , k). !x! hori0ontally, you can use the function

-hen k . 0, the graph of g(x) translated k units left. -hen k / 0, the graph of g(x) translated k units right.

## Definition of Greatest Integer Function

The greatest integer function of a real number x is represented by [x] or |_x_|. For all real numbers x, the greatest integer function returns the largest integer less than or equal to x. In other words, the greatest integer function rounds down a real number to the nearest integer.

## More about Greatest Integer Function

reatest integer functions are piece!wise defined. The domain of the greatest integer function is the set of real numbers which is divided into a number of intervals like [-4, 3),[-3, 2), [-2, 1), [-1, 0), [0, 1), [1, 2), [2, 3), [3, 4) and so on. Hint: [a, b) is just an interval notation which means a x < b, where x is a real number in the interval [a, b). hen the interval is of the form [n, n ! 1), where n is an integer, the value of the greatest integer function is n. "or e#am\$le, the value of the greatest integer function is 4 in the interval [4, 3). The gra\$h of a greatest integer function is not continuous. "or e#am\$le, the following is the gra\$h of the greatest integer function f %#& ' ()x)(.

The graph abo"e loo#s li#e a stair case \$a series of steps%. &o, the greatest integer function is sometimes called a step function. 'ne endpoint in each step is closed \$blac# dot% to indicate that the point is a part of the graph and the other endpoint is open \$open circle% to indicate that the points is (ot a part of the graph. 'bser"e in the graph abo"e that in each interval, the function f\$)% is constant. *ithin an inter"al, the "alue of the function remains constant. For e)ample, in the interval [5, 4) the "alue of the function f\$)% remains + ,.

In different inter"als, howe"er, the function f\$)% can ta#e different constant "alues. reatest integer function is also called floor function.

*iecewise "unction
- piecewise function is a function that is defined on a sequence of inter"als. - common e)ample is the absolute "alue,

.iecewise functions are implemented in Mathematica as Piecewise[ val1, cond1 , val2, cond2 , ... ]. -dditional piecewise functions include the /ea"iside step function, rectangle function, and triangle function. &emicolons and commas are sometimes used at the end of either the left or the right column, with particular usage apparently depending on the author. The words 0if0 and 0for0 are sometimes used in the right column, as is 0otherwise0 for the final \$default% case. For e)ample, 1nuth \$2334, pp. 25, and 267% uses the notations

both with and without the left!column commas. &imilarly, -rf#en \$236,, pp. 866!863% uses

which lac#s semicolons but only sometimes lac#s right!column commas. In this wor#, commas and semicolons are not used.

LOOP Statements
statements e#ecute a se+uence of statements multi\$le times. The ,--* and ./0 ,--* ke1words enclose the statements. *,234, \$rovides four kinds of loo\$ statements5 basic loo\$, WHILE loo\$, FOR loo\$, and cursor FOR loo\$. "or usage information, see 67ontrolling ,oo\$ 8terations5 ,--* and .98T 3tatements6.
LOOP

Syntax
loop statement ::=

## eywor! an! Parameter "escription

#asic\$loop\$statement
: loo\$ that e#ecutes an unlimited number of times. 8t encloses a se+uence of statements between the ke1words LOOP and END LOOP. ith each iteration, the se+uence of statements is e#ecuted, then control resumes at the to\$ of the loo\$. :n EXIT, GOTO, or RAISE statement branches out of the loo\$. : raised e#ce\$tion also ends the loo\$.

#oolean\$expression
:n e#\$ression that returns the ;oolean value TRUE, FALSE, or NULL. 8t is associated with a se+uence of statements, which is e#ecuted onl1 if the e#\$ression returns TRUE. "or the s1nta# of boolean_expression, see 6.#\$ression 0efinition6.

cursor\$for\$loop\$statement
8ssues a 34, +uer1 and loo\$s through the rows in the result set. This is a convenient techni+ue that makes \$rocessing a +uer1 as sim\$le as reading lines of te#t in other \$rogramming languages. : cursor FOR loo\$ im\$licitl1 declares its loo\$ inde# as a ROWT!PE record, o\$ens a cursor, re\$eatedl1 fetches rows of values from the result set into fields in the record, and closes the cursor when all rows have been \$rocessed.

cursor\$name
:n e#\$licit cursor \$reviousl1 declared within the current sco\$e. hen the cursor FOR loo\$ is entered, c"rsor_na#e cannot refer to a cursor alread1 o\$ened b1 an OPEN statement or an enclosing cursor FOR loo\$.

cursor\$parameter\$name

: variable declared as the formal \$arameter of a cursor. "or the s1nta# of c"rsor_para#e\$er_%eclara\$ion, see 67ursor 0eclaration6. : cursor \$arameter can a\$\$ear in a +uer1 wherever a constant can a\$\$ear. The formal \$arameters of a cursor must be IN \$arameters.

for\$loop\$statement
/umeric FOR_LOOP loo\$s iterate over a s\$ecified range of integers. The range is \$art of an iteration scheme, which is enclosed b1 the ke1words FOR and LOOP. The range is evaluated when the FOR loo\$ is first entered and is never reevaluated. The loo\$ bod1 is e#ecuted once for each integer in the range defined b1lower_bo"n%&&"pper_bo"n%. :fter each iteration, the loo\$ inde# is incremented.

in!ex\$name
:n undeclared identifier that names the loo\$ inde# %sometimes called a loo\$ counter&. 8ts sco\$e is the loo\$ itself< 1ou cannot reference the inde# outside the loo\$. The im\$licit declaration of in%ex_na#e overrides an1 other declaration outside the loo\$. To refer to another variable with the same name, use a label. 3ee.#am\$le 4-1=, 6>sing a ,abel for ?eferencing @ariables -utside a ,oo\$6. 8nside a loo\$, the inde# is treated like a constant5 it can a\$\$ear in e#\$ressions, but cannot be assigned a value.

la#el\$name
:n o\$tional undeclared identifier that labels a loo\$. label_na#e must be enclosed b1 double angle brackets and must a\$\$ear at the beginning of the loo\$. -\$tionall1, label_na#e %not enclosed in angle brackets& can also a\$\$ear at the end of the loo\$. Aou can use label_na#e in an EXIT statement to e#it the loo\$ labelled b1 label_na#e. Aou can e#it not onl1 the current loo\$, but an1 enclosing loo\$. Aou cannot reference the inde# of a FOR loo\$ from a nested FOR loo\$ if both inde#es have the same name, unless the outer loo\$ is labeled b1 label_na#e and 1ou use dot notation. 3ee .#am\$le 4-1B, 6>sing ,abels on ,oo\$s for ?eferencing6.

lower\$#oun! %% upper\$#oun!
.#\$ressions that return numbers. -therwise, *,234, raises the \$redefined e#ce\$tion 'ALUE_ERROR. The e#\$ressions are evaluated onl1 when the loo\$ is first entered. The lower bound need not be 1, it can be a negative integer as in FOR(i(IN()*&&+,. The loo\$ counter increment %or decrement& must be 1.

8nternall1, *,234, assigns the values of the bounds to tem\$orar1 PLS_INTEGER variables, and, if necessar1, rounds the values to the nearest integer. The magnitude range of a PLS_INTEGER is -214C4D3B4D to 214C4D3B4C, re\$resented in 32 bits. 8f a bound evaluates to a number outside that range, 1ou get anumeric overflow error when *,234, attem\$ts the assignment. 3ee 6*,3)8/T.E.? 0atat1\$e6. ;1 default, the loo\$ inde# is assigned the value of lower_bo"n%. 8f that value is not greater than the value of "pper_bo"n%, the se+uence of statements in the loo\$ is e#ecuted, then the inde# is incremented. 8f the value of the inde# is still not greater than the value of "pper_bo"n%, the se+uence of statements is e#ecuted again. This \$rocess re\$eats until the value of the inde# is greater than the value of "pper_bo"n%. :t that \$oint, the loo\$ com\$letes.

recor!\$name
:n im\$licitl1 declared record. The record has the same structure as a row retrieved b1 c"rsor_na#e or selec\$_s\$a\$e#en\$. The record is defined onl1 inside the loo\$. Aou cannot refer to its fields outside the loo\$. The im\$licit declaration of recor%_na#e overrides an1 other declaration outside the loo\$. Aou cannot refer to another record with the same name inside the loo\$ unless 1ou +ualif1 the reference using a block label. "ields in the record store column values from the im\$licitl1 fetched row. The fields have the same names and datat1\$es as their corres\$onding columns. To access field values, 1ou use dot notation, as follows5
recor%_na#e&-iel%_na#e

3elect-items fetched from the FOR loo\$ cursor must have sim\$le names or, if the1 are e#\$ressions, must have aliases. 8n the following e#am\$le, wa.es is an alias for the select item salar/0N'L1co##ission_pc\$2,34+,,,5
5URSOR(c+(IS(SELE5T(e#plo/ee_i%2 salar/(0(N'L1co##ission_pc\$2,3(4(+,,,(wa.es(FRO6(e#plo/ees(&&&

&'('&S'
;1 default, iteration \$roceeds u\$ward from the lower bound to the u\$\$er bound. 8f 1ou use the ke1word RE'ERSE, iteration \$roceeds downward from the u\$\$er bound to the lower bound. :n e#am\$le follows5
7EGIN ((FOR(i(IN(RE'ERSE(+&&+,(LOOP(())(i(s\$ar\$s(a\$(+,2(en%s(a\$(+ (((D76S_OUTPUT&PUT_LINE1i38())(s\$a\$e#en\$s(9ere(exec"\$e(+,(\$i#es ((END(LOOP8 END8 :

The loo\$ inde# is assigned the value of "pper_bo"n%. 8f that value is not less than the value of lower_bo"n%, the se+uence of statements in the loo\$ is e#ecuted, then the inde# is decremented. 8f the value of the inde# is still not less than the value of lower_bo"n%, the se+uence of statements is e#ecuted again. This \$rocess re\$eats until the value of the inde# is less than the value of lower_bo"n%. :t that \$oint, the loo\$ com\$letes.

select\$statement
: +uer1 associated with an internal cursor unavailable to 1ou. 8ts s1nta# is like that of selec\$_in\$o_s\$a\$e#en\$ without the INTO clause. 3ee 63.,.7T 8/T3tatement6. *,234, automaticall1 declares, o\$ens, fetches from, and closes the internal cursor. ;ecause selec\$_s\$a\$e#en\$ is not an inde\$endent statement, the im\$licit cursor S;L does not a\$\$l1 to it.

while\$loop\$statement
The WHILE)LOOP statement associates a ;oolean e#\$ression with a se+uence of statements enclosed b1 the ke1words LOOP and END LOOP. ;efore each iteration of the loo\$, the e#\$ression is evaluated. 8f the e#\$ression returns TRUE, the se+uence of statements is e#ecuted, then control resumes at the to\$ of the loo\$. 8f the e#\$ression returns FALSE or NULL, the loo\$ is b1\$assed and control \$asses to the ne#t statement.

)sa*e +otes
Aou can use the EXIT WHEN statement to e#it an1 loo\$ \$rematurel1. 8f the ;oolean e#\$ression in the WHEN clause returns TRUE, the loo\$ is e#ited immediatel1. hen 1ou e#it a cursor FOR loo\$, the cursor is closed automaticall1 even if 1ou use an EXIT or GOTO statement to e#it the loo\$ \$rematurel1. The cursor is also closed automaticall1 if an e#ce\$tion is raised inside the loo\$.