example of monotonic function

onypiecewise_monotony := PIECEWISE ( constant_piece_definition | functional_piece_definition)The pieces can be defined either by a set of constants or by another monotonic function, in which the pieces are defined by distinct values of the piece-defining function.

Things SQL needs: sargability of monotonic functions

Things SQL needs: sargability of monotonic functionswith 5 comments Image by ndevil I'm going to write a series of articles about the things SQL needs to work faster and more efficienly. With these things implemented, most of the tricks I explain in my blog will become redundant and I'll finally have some more time to spend with the family.

Ever wondered why a condition like this: WHERE TRUNC (mydate) = TRUNC (SYSDATE), which searches for the current day's records, is so elegant but so slow?

Of course this is because even if you create an index on mydate, this index cannot be used. The expression in the left part of the equality is not a mydate. The database engine cannot find a way to use an index to search for it. It is said that this expression is not sargable.

Now, a little explanation about the indexes and sargability. If you are familiar with these, you can skip this chapter. But beware that this chapter is the only one illustrated, so skipping it will make the article too boring to read.

Ahem. To locate a record in a B-Tree index, the keys of the index should be compared to the value being searched for. Let's consider this sample B-Tree index: As you can see, this structure maintains the record order.

Within one page, records are just sorted; the links between the pages obey the sorting order too. A binary search can be used to locate the record on a page; if the search resulted in a pair of adjacent records and the search expression is within the range of these records, then we just follow the link between them. All records behind this link will belong to the range, no matter how deep is the tree. This works well when we search for the exact field that was indexed.

But what happens when we search for a derived expression?view source print?1. SELECT *2. FROM mytable3.

WHERE value % 3 = 1The B-Tree itself of course does not change. But, being casted to the expression we are searching for, the values stored will look like that: As you can see, there is no order anymore. The records are neither ordered within one page, nor the links follow the order. A 1 we are searching for can appear anywhere in the tree. There is no other way than to traverse the whole tree and compare each record. It is said that this expression is unsargable: the index can not be used to search for this expression.

But let's consider another example:view source print?1. SELECT *2. FROM mytable3. WHERE value + 3 = 10Here's how the B-Tree looks now from the point of view of the expression in the WHERE clause Now, we have a perfectly valid B-Tree: everything stays in order and the search algorithms can still be used.

Another example ( DIV is the integer division operator):view source print?1. SELECT *2. FROM mytable3. WHERE value DIV 3 = 3Here's the B-Tree as seen from the expression's side: The order persists. This B-Tree is a little bit harder to traverse, since the key values are not unique anymore. But the same values of the keys are still contiguous, and the order between the different keys is still maintained.

Is this case, the algorithm should be changed just a little. When a key is found in the database, we should just continue searching to the left until we find the very first occurrence of the key with lower value. Then we continue searching to the right and return all the records with the correct value of the key.

This problem is of course well known and has long since been solved by all database systems: you can create an index on a non-unique field. Finally, let's consider one more expression, a very simple one:view source print?1. SELECT *2. FROM mytable3.

WHERE 20 - value = 10and how it sees the B-Tree: In this case, the order is reversed. But there still is the order. The only difference is that the values are sorted right to left, not left to right, and all traversals should be made according to these new directions.

We see that some expressions break the B-Tree order, while the other ones maintain it. What is the difference between the two?

For an expression to maintain the B-Tree order, it is necessary and sufficient for this expression to be a monotonic function of the argument being indexed.

Here's the definition of the monotonic function from Wikipedia: In calculus, a function f defined on a subset of the real numbers with real values is called monotonic (also monotonically increasing, increasing or non-decreasing), if for all x and y such that x ≤ y one has f (x) ≤ f (y), so f preserves the order. Likewise, a function is called monotonically decreasing (also decreasing, or non-increasing) if, whenever x ≤ y, then f (x) ≥ f (y), so it reverses the order.

By definition, the monotonic function preserves (or reverses) the order, but does not break it. This means that if an index is built over an expression, it also can be used to search over any monotonic function of this expression.

However, most query optimizers do not take this fact into account, while this behavior is relatively easy to implement. Sample implementation There will be many new keywords. I will introduce them all at the beginning and explain them later in the article. Also, there will be many fake functions, like NEXT_COLLATION_CHARACTER or EXTRACT (calendar_date), which are absent in the actual engines but their name easily tells their purpose (and it's quite simple to implement them anyway).

These functions are used to demonstrate the concept. A sargable function, as I shown above, needs to expose some monotony:function ( arg1, …) monotony_declaration Function of two or more arguments can be sargable by some or all of it's arguments:monotony_declaration := MONOTONIC ( monotony_domain | OVER ( arg1) monotony_domain [, …])When the function is a single-argument function, OVER clause should be omitted.monotony_domain := ( monotony | PIECEWISE piecewise_monotony)Monotony defines the direction and uniqueness of the function on the given range of the function's domain:monotony := (STRICTLY INCREASING | INCREASING | STRICTLY DECREASING | DECREASING | UNDEFINED ) [ inversion_clause ]If monotony is STRICTLY INCREASING, it can be used for the B-Tree searches without changing the search order.

A UNIQUE set of values is mapped to a UNIQUE set of the results of the function. The cardinality of the function over the indexed expression is the same as that of the expression. If monotony is INCREASING, it can be used for the B-Tree searches without changing the search order. A UNIQUE set of values may be mapped to a non-unique set of the results, and no assumptions should be made about the uniqueness of the results. The cardinality of the function over the indexed expression may be not the same as that of the expression.

If monotony is STRICTLY DECREASING, it can be used for the B-Tree searches, changing the search order. A UNIQUE set of values is mapped to a UNIQUE set of the results of the function. The same algorithms that are used for scanning the index in the opposite order should be applied.

The cardinality of the function over the indexed expression is the same as that of the expression. If monotony is STRICTLY DECREASING, it can be used for the B-Tree searches, changing the search order.

A UNIQUE set of values is mapped to a UNIQUE set of the results of the function. The same algorithms that are used for scanning the index in the opposite order should be applied. The cardinality of the function over the indexed expression may be not the same as that of the expression.

There is one more flavor, UNDEFINED, which states that the function is not monotonic or its monotony should not be relied upon. This has no sense as such, but can be used in the complex constructs we shall discuss below. If the function is monotonic over the whole domain, then monotony is provided right after the keyword MONOTONIC. However, a function can be piecewise monotonic. Its domain may consist of several (possibly infinite) number of pieces, with the function being monotonic over each piece but not across them. Piecewise monot

onypiecewise_monotony := PIECEWISE ( constant_piece_definition | functional_piece_definition)The pieces can be defined either by a set of constants or by another monotonic function, in which the pieces are defined by distinct values of the piece-defining function.

constant_piece_definition := WHEN VALUE [STRICTLY] LESS THAN const monotony, [ … ], WHEN VALUE LESS THAN MAXVALUE monotony Each const should be greater than the previous, and the last clause should be WHEN VALUE THEN MAXVALUE.

The const comparison can be declared as strict: this may be important for handling discontinuities.functional_piece_definition := DEFINED BY piece_defining_function ( arg) CASE ( (WHEN expression (PIECE) THEN monotony) [ (…) | ELSE monotony ] ) ENDPiece-defining function should itself be a monotonic function (but not a strict monotonic) over all domain of the original function. The point of having this function is to split the domain into several pieces which themselves are sargable (hence the requirement for non-strict monotony), and then define the monotony within each piece.

The monotony for each piece is defined by SQL 's standard CASE WHEN … THEN … ELSE … END control flow construct (which of course returns monotonies instead of values). Two or more arguments A function of two or more arguments can be sargable too, as defined by monotony_declaration.

Each OVER clause defines monotony over one of the fuction's arguments. If an indexed field is used as a corresponding argument to this function and the other arguments are provided as constants or values from the leading table in the join, then the function is sargable.

Superpositions When dealing with the superposition of functions, some assumptions can be made: A superposition of any number of STRICTLY MONOTONIC functions is STRICTLY MONOTONICA superposition of any number of STRICTLY MONOTONIC functions and at least one MONOTONIC function is MONOTONIC (as opposed to STRICTLY MONOTONIC )A superposition of an INCREASING and a DECREASING function is DECREASINGA superposition of an INCREASING and an INCREASING functions, or that of a DECREASING function and a DECREASING function is INCREASINGThis only concerns functions monotonic over all domain (that is without PIECEWISE expressions).

Inversionsinversion_clause := INVERSE ( inverse_expression | FROM inverse_expression [ EXACT [ EXCLUDE ] ] TO inverse_expression [ EXACT [ EXCLUDE ] ] )inverse_expression := sql_expression ( [ PIECE ], [ RESULT ], [ non-over-arg1 [ ,… ] ])Each monotony may be provided with an inversion_clause, which maps the results back to the values of the arguments. These expressions can accept the following arguments: RESULT. This is the result of the function which needs to be mapped back to the value of the argument PIECE.

This is the value defined by the piece-defining function. This only makes sense in a function-defined piecewise monotonynon-over-arg.

This is the argument to the function not used in the OVER clause. This only makes sense for multiple-argument functions. Inversion clause may come in two forms: scalar inversion and range inversion. A scalar inversion maps the function result to the single value of the argument.

If the monotony is strict, then the value of the expression is treated as a unique mapping. The decision on whether to return the value or not is made solely on the basis of the inverse result: function is not applied to the values taken from the index for more fine filtering. If the monotony is not strict, them the value of the expression is treated as a reference point. Key reads back and forward to this reference point should be made with the function being applied to the result of each key read.

A range inversion maps the function result back to the range of values that are guaranteed to yield the RESULT, being provided as an argument to the function. The first expression provides the start value of the range, the second expression provides the end value.

Within the range, the results are returned from the index without any additional checking. If any of the range expressions is marked as EXACT, then no values are returned outside the range in the corresponding direction.

Otherwise, key reads are made in this direction and the function is applied to the results of the key reads to do the fine checking. With EXACT clause, it is also possible to provide EXCLUDE clause. Depending on its presence, the corresponding range will be treated as including or not including the boundary. The point of allowing inexact inverse functions is to deal with the rounding errors introduced by floating point operations.

Even if in theory the function can uniquely map back to a single value or a range of values, in practice, this may be not the case.

The B-Tree search is possible even without providing inverse functions at all. However, if inverse functions are provided, the number of the function evaluations is kept to the minimum: the function is only evaluated for several keys outside of the guaranteed range. Examples EXP (arg FLOAT) MONOTONIC INCREASING INVERSE LN (RESULT)Exponent function is increasing over the whole set of natural numbers. Its inverse function is natural logarithm. Due to possible rounding errors, this function cannot be declared as strict.

YEAR (arg DATETIME) MONOTONIC INCREASING INVERSE FROM DATE_TRUNC ('year', RESULT) EXACT TO DATE_TRUNC ('year', RESULT) + INTERVAL 1 YEAR EXACT EXCLUDEYEAR is an increasing function but not a strictly increasing one: two distinct dates can share the same year.

That's why we provide two inverse functions: the first one provides the minimal possible date for a given year, the second one provides the maximal possible one.

The latter function is marked as EXCLUDE, since the first date of the next year does not belong to the current year's domain piece, but any value strictly less than it (and greater than the year's beginning date) does.

ABS (arg INT) MONOTONIC PIECEWISE ON VALUES STRICTLY LESS THAN 0 STRICTLY DECREASING INVERSE -RESULT, VALUES LESS THAN MAXVALUE STRICTLY INCREASING INVERSE RESULTThe absolute value function is piecewise monotonic: it is strictly decreasing for the values below zero and strictly increasing for the values of zero and above. The inverse functions for each piece are the negation of the result and result itself, accordingly.

FLOOR (arg FLOAT) MONOTONIC INCREASING INVERSE FROM RESULT EXACT TO RESULT + 1 EXACT EXCLUDEThe nearest lower integer function is monotonically increasing, almost the same as YEAR described above.

OPERATOR_DIVISION (arg1 FLOAT, arg2 FLOAT) MONOTONIC OVER (arg1) CASE WHEN arg2 > 0 THEN INCREASING INVERSE RESULT * arg2 WHEN arg2 = 0 THEN UNDEFINED WHEN arg2 < 0 THEN DECREASING INVERSE RESULT * arg2 ENDThis function defines division operator.

It is monotonic over the first argument. This means that the second argument should be provided as the run-time constant for it to be sargable: no field from the table being searched for can be used as a second argument to this function.

This function is monotonic over the whole domain of arg1, but the monotony depends on the value of arg2. In theory, this function is strictly monotonic, but in practice, rounding errors can make the function yield same results for different values of arg1. That's why this function should be declared non-strict and a single inverse expression should be provided.

OPERATOR_PLUS (arg1 FLOAT, arg2 FLOAT) MONOTONIC OVER (arg1) STRICTLY INCREASING INVERSE RESULT - arg2, OVER (arg2) STRICTLY INCREASING INVERSE RESULT - arg1This function defines the + operator. This is quite simple: the function is strictly increasing over both arguments, and the inverse function is just a subtraction. MONTH (arg DATETIME) MONOTONIC PIECEWISE DEFINED BY DATE_TRUNC ('year', arg) INCREASING INVERSE FROM PIECE + INTERVAL RESULT - 1 MONTH EXACT TO PIECE + INTERVAL RESULT MONTH EXACT EXCLUDEMONTH returns the month number within a year.

This function is piecewise monotonic: within a year, higher dates always return same of higher months.

Whenever the year changes, monotony breaks. DATE_TRUNC is monotonic and not strict, and, hence, can be used to define the pieces. The reverse functions use both PIECE and RESULT arguments. The PIECE argument defines the current year, the RESULT is used to find the beginning of the current and the next months.

COS (arg FLOAT) MONOTONIC PIECEWISE DEFINED BY FLOOR (arg / PI ()) CASE PIECE % 2 WHEN 0 THEN DECREASING INVERSE PIECE * PI () + ACOS (RESULT) ELSE INCREASING INVERSE (PIECE + 1) * PI () - ACOS (RESULT) ENDCosine is piecewise monotonic too.

The pieces are defined by the cosine half-waves. Depending on the piece, it can be increasing or decreasing. The half-wave number is defined by FLOOR (arg / PI ()). This piece-defining function, being a superposition of increasing functions, is increasing too.

On the even half-waves, the function is decreasing; on the odd half-waves, it is increasing. In principle, the function monotony is strict, but due to the possible rounding errors, it is marked as non-strict and only one inverse function provided. SIN (arg FLOAT) MONOTONIC PIECEWISE DEFINED BY FLOOR (arg / PI () - 0.5) CASE PIECE % 2 WHEN 0 THEN DECREASING INVERSE PIECE * PI () + ASIN (RESULT) ELSE INCREASING INVERSE PIECE * PI () - ASIN (RESULT) ENDSame as cosine above, with a π / 2 shift.

LEFT (arg VARCHAR, length INT) MONOTONIC OVER (arg) INCREASING INVERSE FROM LEFT (arg, length) EXACT TO LEFT (arg, length - 1) || NEXT_COLLATION_CHARACTER (SUBSTRING (arg, length, 1)) EXACT EXCLUDEFunction LEFT takes the leading characters from the string.

It is sargable over the first argument: in the string is indexed, you can always search for a leading substring. I had to make up the function NEXT_COLLATION_CHARACTER, which would take next possible alphabet character according to the current collation.

Note that SQL Server and My SQL have traces of such optimization. In both systems, LIKE predicate is sargable if the search string does not contain the leading wildcards. If you build a plan for a predicate like column LIKE 'test%', you will see that is will use the index seek in this range:column >= 'test' AND column < 'tes U'This behavior is exactly like described above.

Search algorithm To select the values matching this condition:function (col1 [ , arg2, … ]) = const, the following procedures should be made: If the function is not sargable against the first argument, then just do the full table or index scan.

If the function is sargable against the first argument, check its monotony. If the function is monotonic over all domain: If no inversion function is defined, then locate the values in the B-Tree using the B-Tree search algorithm and applying the function to each key before the comparison. The monotony direction (increasing or declreasing) should of course be taken into account. If the function is strictly monotonic and a single inverse function is defined, apply the inverse function to the value of const, find the corresponding value of col1 and locate it in the index using B-Tree search algorithm.

If the function is monotonic, but not strictly, check the inversion type: If a scalar inverse expression is defined, then: Apply the inverse function to const and find the key values in the B-Tree closest to the value of inverse_expression (const)Starting from inverse_expression (const), iterate through the index back and forward, applying function to the each key found until the function exceeds (or falls short of) const, returning the records found.

If a range inverse expression is defined, then: Find the beginning and the ending values of the col1 range that yields const If the beginning of range is not exact, iterate keys backwards, applying the function to each key found until the function equals to const. Iterate the keys forward, returning the records found, until the end of the range is reached. If the range end is not exact, then iterate keys beyond the range, applying the function to the keys found, until the function value exceeds or falls short of const If the function is piecewise monotonic: If the pieces are defined by a set of constants, split the domain into the pieces, then apply the steps above to each piece separately with respect to the monotony of each piece.

If the pieces are defined by a function: Use loose index scan to build a distinct list of the function's values (each defining a piece).

The loose index scan will jump over the B-Tree, starting from the minimal (or maximal) value of the function and recursively searching for the greater (or the lesser value). Each distinct value will reveal the least and the greatest value of the col1 belonging to its piece. Within the range defined by these values, apply the steps above, with respect to the monotony of each piece. If for any of the pieces the monotony is UNDEFINED, then just apply the function to every key in the piece's range, filtering the results.

User-defined functions All examples above were applied to the built-in functions. In fact, they don't need declaration and all clauses above were added only to demonstrate the point.

However, with a little effort, the user-defined functions can be made sargable too. Here are some suggestions on how to make it: To be sargable, a user-defined function should be strictly deterministic, that is its result should depend on and only on the values of the arguments (specifically, it should not depend on the database state)If a function is a superposition of the monotonic functions (with the additional constraints stated above), it should be automatically treated as monotonic.

If a function is declared as monotonic by a user, special algorithms should be used to check its monotony (and hence sargability): Sargability of a monotonic user-defined function should be a property of index-function pair. Function's declared monotony is a necessary but not sufficient condition for sargability. By default, sargability of index-function pair is unknown.

Whenever a query is issued which could be satisfied by using the index to search for the function values, the index-function pair is marked as potentially sargable.

This property can be made dynamic: say, 10 or 100 queries should be issued before the sargability of the index-function pair can be checked. When the query threshold is reached (this means that the certain number of queries which possibly could use the index had been run), the index checking process is initiated.

The database job which is responsible for collecting the index statistics, runs over the index and checks the declared monotony of the function over the given argument: within each piece, higher values of argument should map to higher (or lower, or not higher, or not lower) values of the function.

If the function is piecewise monotonic with pieces defined by a user-defined function as well, the monotony of the piece-defined function should also be checked in the same routine. If the check succeeds, the index-function is marked as sargable both for the function and its piece-defining function (if any).

At the same time, the statistics routine should collect the additional statistics for the function as if it was the index over the function's values.

If an index is marked as usable for any given function, all DML operations against this index should perform an additional validation for the function monotony: Whenever a new record is inserted into the index, the function should be applied to the values of the key inserted and both of its neighbors.

The value of the function over the key inserted should be between (or, depending on the function's monotony, strictly between) the values of the function over the neighboring keys. If the function is declared as piecewise monotonic with a piece defining function, the latter is checked first.

If any of the neighboring keys belongs to a piece different to that of the key being inserted, that neighboring key will not participate in the check. A failure to prove the function's monotony invalidates the function's usage in all indexes and also invalidates the sargability of all functions that use it as a piece-defining function.

Additionally, the values of the arguments which are proven to violate the function's monotony are recorded with the function's metadata. Any change to the function's definition invalidates all sargability information linked with this function, as well as linked with the functions that uses it to define the pieces.

For any index-function pair, the validation and statistics collection process can be initiated manually. The database engine should provide means for that. Points of interest Function sargability may be used to improve many queries, specifically: Searching for dates within a given period (month, date, year) without a need to calculate the ranges manually:view source print?1.

SELECT *2. FROM mytable3. WHERE EXTRACT (YEAR_MONTH FROM col1) = '201002'Searching for birthdates and calendar events:view source print?1.

SELECT *2. FROM mytable3. WHERE EXTRACT (calendar_date FROM mydate) = '0310'Searching for the substrings:view source print?1. SELECT *2. FROM mytable3. WHERE LEFT (value, 10) = 'abcdefghij'Searching for the COALESCE 'd values:view source print?1. SELECT *2. FROM mytable3. WHERE COALESCE (value, 'test') = 'test'and many others. I really hope that this will be added to the major database engines in the nearest future.

Share this: Facebook Twitter Written by Quassnoi February 19th, 2010 at 11:00 pm Posted in Miscellaneous« Tags in nested sets: efficient indexing Sargability of monotonic functions: example »5 Responses to 'Things SQL needs: sargability of monotonic functions'Subscribe to comments with RSSFirst, this was an excellent article.

Second, I’ll be reviewing what parts of your suggestions I can easily introduce into the Drizzle optimizer. Finally, I’d just say that perhaps the reason that many RDBMS have yet to implement such optimizations is because in many (all?) cases where a monotonic function might be inlined within the optimizer into a sargable parameter, the SQL statement can be rewritten in such a way as to manually perform the translation.

Simple example would be rewriting this My SQLish SQL SELECT statement (assume an index on t1 (date_col)): SELECT * FROM t1 WHERE TO_DAYS (date_col) > TO_DAYS (NOW ()) – 8;to SELECT * FROM t1 WHERE date_col > NOW () – INTERVAL 8 DAY;Cheers, and nice blog!

:)-jay Jay Pipes20 Feb 10 at 05:51@Jay: with a function monotonic over all its domain, it’s easy to rewrite the condition.

However, the point of SQL (as we have been told for the decades) is that you give the idea, we handle the details, and this proposal is to make this statement more true. Rewriting the conditions, though, may be not easy as it seems. Say, col1 / y = z is not the same as col1 = z * y (due to the rounding errors). This requires extra handling too. And what about functions that are piecewise monotonic? Like get all records of Jan 1st of any year? This is not so easy to rewrite as a sargable condition. So having these things handled automatically in Drizzle would be very nice :)Quassnoi20 Feb 10 at 10:07Absolutely agree with you Quassnoi :)Jay Pipes20 Feb 10 at 19:04Hi,Very good write! I also wrote a bit earlier on monotonic functions: on how to utilize the fact we have a monotonic function, to cover for a missing index: Monotonic functions, SQL and My SQLRegards Shlomi Noach19 Mar 10 at 14:52@Shlomi: great minds think alike!Quassnoi19 Mar 10 at 15:17Leave a Reply Name (required)Mail (will not be published) (required)Website Notify me of follow-up comments by email. Notify me of new posts by email.

The MONOTONIC function is an undocumented SAS function. It needs no input parameters and if any input parameters are provided, these are ingnored. The function counts the number of times it is called and returns an ascending sequence of integers, starting at 1.

MONOTONIC function

This is a work in progress. Please feel free to contribute to this article.

The function can be used in an expressions and is syntatically valid in both a DATA Step and an SQL procedure.

However, it may produce unexpected results in some circumstances. Contents [ hide ]1 Syntax2 Usage2.1 Alternatives to the MONOTONIC function2.1.1 In a DATA step2.1.2 In a SQL procedure3 Further reading3.1 sas Community articles3.1.1 Tips using the MONOTONIC function3.2 SAS Papers3.3 SAS Documentation Syntaxvariable = MONOTONIC ();Usage

The MONOTONIC function is often presented as a means of adding sequence numbers to table rows. Several papers present it as a solution to this programming problem. However, the function is undocumented and has some limitations, including:

MONOTONIC function

A is the efficacy of A and PAR is the proportion of the receptors occupied. The effect of the drug on the cell or tissue is given by Effect = f (S), where f is an unspecified monotonic function that is dependent upon the nature of the receptor and its interaction with the cell or tissue.

Efficacy definition in pharmacodynamics

Efficacy definition in pharmacodynamics Author: Flavio Guzman, MD. The following pharmacology definition has been taken from the Pharmacology and Experimental Therapeutics Department Glossary at Boston University School of Medicine.

Efficacy: Broadly, efficacy refers to the capacity of a drug to produce an alteration in a target cell/organ after binding to its receptor. A competitive antagonist, that occupies a binding site without producing any alteration in the receptor, is considered to have an efficacy of zero. Efficacy is generally independent of potency /affinity, and is related to the maximum effect that a particular drug is capable of producing.

As originally formulated by Stephenson (1956), binding of an agonist A to its receptor R is considered to result in a “stimulus” S=? A x P AR where ?

Efficacy is both agonist and tissue-dependent. Efficacy is related to Intrinsic Activity, which was originally defined by Furchgott (1966) as e=?/R T , i.e.

as the efficacy per receptor. In practice, the two terms are sometimes loosely used synonymously The copyright of the text is hold by Trustees of Boston University. Permission has been granted for its use in this blog. Filed Under: Definitions, Pharmacodynamics

]The first derivative test examines a function's monotonic properties (where the function is increasing or decreasing) focusing on a particular point in its domain. If the function ""switches"" from increasing to decreasing at the point, then the function will achieve a highest value at that point.

Derivative test

"Derivative test From Wikipedia, the free encyclopedia (Redirected from Second derivative test)navigation search In calculus, a derivative test uses the derivatives of a function to locate the critical points of a function and determine whether each point is a local maximum, a local minimum, or a saddle point.

Derivative tests can also give information about the concavity of a function. The usefulness of derivatives to find extrema is proved mathematically by Fermat's theorem of stationary points. Contents [ hide ]1 First derivative test1.1 Precise statement of monotonicity properties1.2 Precise statement of first derivative test1.3 Applications2 Second derivative test (single variable)2.1 Proof of the second derivative test2.2 Concavity test2.3 Higher-order derivative test2.4 Example3 Multivariable case4 See also5 References First derivative test [ edit

Similarly, if the function ""switches"" from decreasing to increasing at the point, then it will achieve a least value at that point. If the function fails to ""switch"", and remains increasing or remains decreasing, then no highest or least value is achieved. One can examine a function's monotonicity without calculus. However, calculus is usually helpful because there are sufficient conditions that guarantee the monotonicity properties above, and these conditions apply to the vast majority of functions one would encounter.

Precise statement of monotonicity properties [ edit]Stated precisely, suppose f is a real-valued function of a real variable, defined on some interval containing the point x.

If there exists a positive number r such that f is weakly increasing on ( x − r, x] and weakly decreasing on [ x, x + r ), then f has a local maximum at x. If there exists a positive number r such that f is strictly increasing on ( x − r, x] and strictly increasing on [ x, x + r ), then f is strictly increasing on ( x − r, x + r) and does not have a local maximum or minimum at x.

Note that in the first two cases, f is not required to be strictly increasing or strictly decreasing to the left or right of x, while in the last two cases, f is required to be strictly increasing or strictly decreasing.

The reason is that in the definition of local maximum and minimum, the inequality is not required to be strict: e.g.

every value of a constant function is considered both a local maximum and a local minimum. Precise statement of first derivative test [ edit]The first derivative test depends on the ""increasing-decreasing test"", which is itself ultimately a consequence of the mean value theorem. Suppose f is a real-valued function of a real variable defined on some interval containing the critical point a.

Further suppose that f is continuous at a and differentiable on some open interval containing a, except possibly at a itself. If there exists a positive number r such that for every x in ( a − r, a) we have f ′ ( x) ≥ 0, and for every x in ( a, a + r) we have f ′ ( x) ≤ 0, then f has a local maximum at a.

If there exists a positive number r such that for every x in ( a − r, a) ∪ ( a, a + r) we have f ′ ( x) > 0, then f is strictly increasing at a and has neither a local maximum nor a local minimum there.

If none of the above conditions hold, then the test fails. (Such a condition is not vacuous; there are functions that satisfy none of the first three conditions such as f ( x) = x 2 ⋅sin (1/ x ).

Again, corresponding to the comments in the section on monotonicity properties, note that in the first two cases, the inequality is not required to be strict, while in the next two, strict inequality is required.

Applications [ edit]The first derivative test is helpful in solving optimization problems in physics, economics, and engineering. In conjunction with the extreme value theorem, it can be used to find the absolute maximum and minimum of a real-valued function defined on a closed, bounded interval.

In conjunction with other information such as concavity, inflection points, and asymptotes, it can be used to sketch the graph of a function. Second derivative test (single variable) [ edit]After establishing the critical points of a function, the second derivative test uses the value of the second derivative at those points to determine whether such points are a local maximum or a local minimum. If the function f is twice differentiable at a critical point x (i.e. f ′ (x) = 0 ), then: If then has a local maximum at.

If then has a local minimum at. If, the test is inconclusive. In the last case, Taylor's Theorem may be used to determine the behavior of f near x using higher derivatives. Proof of the second derivative test [ edit]Suppose we have (the proof for is analogous). By assumption,.

Then Thus, for h sufficiently small we getwhich means that if h < 0 (intuitively, f is decreasing as it approaches x from the left), and that if h > 0 (intuitively, f is increasing as we go right from x ).

Now, by the first derivative test, has a local minimum at. Concavity test [ edit]A related but distinct use of second derivatives is to determine whether a function is concave up or concave down at a point. It does not, however, provide information about inflection points. Specifically, a twice-differentiable function f is concave up if and concave down if.

Note that if, then has zero second derivative, yet is not an inflection point, so the second derivative alone does not give enough information to determine if a given point is an inflection point. Higher-order derivative test [ edit]The higher-order derivative test or general derivative test is able to determine whether a function's critical points are maxima, minima, or points of inflection for a wider variety of functions than the second-order derivative test.

As shown below, the second derivative test is mathematically identical to the special case of n=1 in the higher-order derivative test.

Let f be a real-valued, sufficiently differentiable function on the interval and an integer. Also let all the derivatives of f at c be zero up to and including the n th derivative, but with the ( n +1)th derivative being non-zero:. There are four possibilities, the first two cases where c is an extremum, the second two where c is a (local) saddle point: If n is odd and, then c is a local maximum.

If n is odd and, then c is a local minimum. If n is even and, then c is a strictly decreasing point of inflection. If n is even and, then c is a strictly increasing point of inflection. Since n must be either odd or even, this analytical test classifies any stationary point of f, so long as a nonzero derivative shows up eventually.

Example [ edit]Say we want to perform the general derivative test on the function at the point. To do this, we calculate the derivatives of the function and then evaluate them at the point of interest until the result is nonzero.,,,,,,As shown above, at the point, the function has all of its derivatives at 0 equal to 0 except for the 6th derivative, which is positive.

Thus n=5, and by the test, there is a local minimum at 0. Multivariable case [ edit]Main article: Second partial derivative test For a function of more than one variable, the second derivative test generalizes to a test based on the eigenvalues of the function's Hessian matrix at the critical point.

In particular, assuming that all second order partial derivatives of f are continuous on a neighbourhood of a critical point x, then if the eigenvalues of the Hessian at x are all positive, then x is a local minimum. If the eigenvalues are all negative, then x is a local maximum, and if some are positive and some negative, then the point is a saddle point. If the Hessian matrix is singular, then the second derivative test is inconclusive. See also [ edit]Fermat's theorem (stationary points)Maxima and minima Karush–Kuhn–Tucker conditions Phase line – virtually identical diagram, used in the study of ordinary differential equations Bordered Hessian Optimization (mathematics)Differentiability Convex function Second partial derivative test Saddle point Inflection point Stationary point References [ edit]""Second Derivative Test"" at Mathworld Concavity and the Second Derivative Test Thomas Simpson's use of Second Derivative Test to Find Maxima and Minima at Convergence Stewart, James (2008). Calculus: Early Transcendentals, 6th ed., Brooks Cole Cengage Learning. ISBN 978-0-495-01166-8Categories: Differential calculus "

on To solidify our understanding of what a monotonic function is, let's consider what a non-monotonic function is. A non-monotonic function is a function that is increasing and decreasing on different intervals of its domain. For example, consider our initial example f ( x) equals x 2.

Monotonic Function: Definition & Examples

Your next lesson will play in 10 seconds Add to Timeline Autoplay 44K views Create an account to start this course today Try it free for 5 days!Create An Account Recommended Lessons and Courses for You Related Lessons Related Courses Rolle's Theorem: A Special Case of the Mean Value Theorem Probability Density Function: Definition, Formula & Examples The Relationship Between Continuity & Differentiability Indefinite Integral: Definition, Rules & Examples Lesson Transcript Instructor: Laura Pennington Laura has taught collegiate mathematics and holds a master's degree in pure mathematics.

In this lesson, we will learn about monotonic functions, explore these types of functions, and discover how to identify them. After you have finished the lesson, you can test your knowledge with a quiz. Monotonicity The monotonicity of a function tells us if the function is increasing or decreasing.

A function is increasing when its graph rises from left to right. In technical terms, a function is increasing on an interval I if for any x 1 and x 2 in I, x 1 is less than x 2 implies that f ( x 1) is less than f ( x 2).

Basically, this says that when x 1 is less than x 2, then the function evaluated at x 1 is less than the function evaluated at x 2.

A function is decreasing when its graph falls from left to right. Again, the technical definition says that a function is decreasing on an interval I if for any x 1 and x 2 in I, x 1 is less than x 2 implies that f ( x 1) is greater than f ( x 2).

In other words, a function is decreasing on an interval I when it is the case that whenever x 1 is less than x 2, f ( x 1) is greater than f ( x 2).

The monotonicity of a function is directly related to the function's derivative. A function is increasing when its derivative is positive, and a function is decreasing when its derivative is negative.

For example, consider the function f ( x) = x 2. The derivative is f ' ( x) equals 2 x. Now consider where 2 x is positive and negative.2 x is greater than 0. Divide both sides by 2. x is greater than 0. Therefore, f is positive when x is greater than 0, so f is increasing on the interval x is greater than 0. Similarly, consider where 2 x is negative:2 x is less than 0 Divide both sides by 2 x is less than 0Thus, f ' is negative when x is less than 0, and f is decreasing on the interval x is less than 0

. Montonic Function When a function is increasing on its entire domain or decreasing on its entire domain, we say that the function is strictly monotonic, and we call it a monotonic function. For example, consider the function g ( x) equals x 3: Notice the graph of g is increasing everywhere. Therefore, this is a monotonic function.

We can also observe this by looking at the derivative of g. The derivative of g ( x) equals x 3 is g ' ( x) equals 3 x 2.

Notice that no matter what we plug in for x in the derivative, it gets squared, making it positive. Thus, the derivative is always positive, so g is always increasing. Therefore, g is a monotonic function. Non-Monotonic Functi

The textbook says it's a way of transforming a set of numbers into another set that preserves the order. But I don't understand what that means. Here are a few examples. The question was: do these functions represent a monotonic transformation. u = 2v - 13 (yes) u = -1/v 2 (no) u = ln (v) (yes) u = v 2 (no)

Homework Help: What is monotonic transformation? (economics)

I have no clue what you're supposed to look for.

Likewise, a function is called monotonically decreasing (also decreasing or non-increasing [3]) if, whenever, then, so it reverses the order (see Figure 2). If the order in the definition of monotonicity is replaced by the strict order, then one obtains a stronger requirement.

Monotonic function

"From Wikipedia, the free encyclopedianavigation search""Monotonicity"" redirects here. For information on monotonicity as it pertains to voting systems, see monotonicity criterion. For information on monotonicity as it pertains to logical systems, see Monotonicity of entailment.

""Monotonic"" redirects here. For other uses, see Monotone (disambiguation). Figure 1. A monotonically increasing function. Figure 2. A monotonically decreasing function Figure 3. A function that is not monotonic In mathematics, a monotonic function [1] [2] (or monotone function [3]) is a function between ordered sets that preserves or reverses the given order.

This concept first arose in calculus, and was later generalized to the more abstract setting of order theory.

Contents [ hide ]1 Monotonicity in calculus and analysis1.1 Monotonic transformation1.2 Some basic applications and results2 Monotonicity in topology3 Monotonicity in functional analysis4 Monotonicity in order theory5 Monotonicity in the context of search algorithms6 Boolean functions7 See also8 Notes9 Bibliography10 External links Monotonicity in calculus and analysis [ edit]In calculus, a function defined on a subset of the real numbers with real values is called monotonic if and only if it is either entirely non-increasing, or entirely non-decreasing.

[2] That is, as per Fig. 1, a function that increases monotonically does not exclusively have to increase, it simply must not decrease. A function is called monotonically increasing (also increasing or non-decreasing [3] ), if for all and such that one has, so preserves the order (see Figure 1).

A function with this property is called strictly increasing [3]. Again, by inverting the order symbol, one finds a corresponding concept called strictly decreasing [3]. Functions that are strictly increasing or decreasing are one-to-one (because for not equal to, either or and so, by monotonicity, either or, thus is not equal to .

)When functions between discrete sets are considered in combinatorics, it is not always obvious that ""increasing"" and ""decreasing"" are taken to include the possibility of repeating the same value at successive arguments, so one finds the terms weakly increasing and weakly decreasing to stress this possibility.

The terms ""non-decreasing"" and ""non-increasing"" should not be confused with the (much weaker) negative qualifications ""not decreasing"" and ""not increasing"". For example, the function of figure 3 first falls, then rises, then falls again. It is therefore not decreasing and not increasing, but it is neither non-decreasing nor non-increasing.

A function is said to be absolutely monotonic over an interval if the derivatives of all orders of are nonnegative or all nonpositive at all points on the interval. Monotonic transformation [ edit]The term monotonic transformation (or monotone transformation) can also possibly cause some confusion because it refers to a transformation by a strictly increasing function.

This is the case in economics with respect to the ordinal properties of a utility function being preserved across a monotonic transform (see also monotone preferences ). [4] In this context, what we are calling a ""monotonic transformation"" is, more accurately, called a ""positive monotonic transformation"", in order to distinguish it from a “negative monotonic transformation,” which reverses the order of the numbers.

[5]Some basic applications and results [ edit]The following properties are true for a monotonic function:has limits from the right and from the left at every point of its domain;has a limit at positive or negative infinity ( ) of either a real number,, or.can only have jump discontinuities;can only have countably many discontinuities in its domain. The discontinuities, however, do not necessarily consist of isolated points and may even be dense in an interval ( a, b ).

These properties are the reason why monotonic functions are useful in technical work in analysis. Two facts about these functions are:if is a monotonic function defined on an interval, then is differentiable almost everywhere on, i.e. the set of numbers in such that is not differentiable in has Lebesgue measure zero. In addition, this result cannot be improved to countable: see Cantor function.if is a monotonic function defined on an interval, then is Riemann integrable.

An important application of monotonic functions is in probability theory. If is a random variable, its cumulative distribution function is a monotonically increasing function. A function is unimodal if it is monotonically increasing up to some point (the mode) and then monotonically decreasing. When is a strictly monotonic function, then is injective on its domain, and if is the range of, then there is an inverse function on for.

Monotonic function

Spearman’s rank correlation coefficient is a non parametric variable that gives a relation between two variables . It basically gives the measure of monotonicity of the relation between two variables i.e. how well the relation between two variables could be represented using a monotonic function .

What is Spearman's rank correlation test?

The value of spearman constant varies from -1 to +1 , both inclusive . A value of +1 or -1 represents that the relationship between the two variables could be represented by perfectly monotonous functions .

For finding the value of Spearman's coefficient , first the raw data is converted into ranked data for both the variables X and Y and the following formula is applied to the ranked variables .

Where Xavg. and Yavg. are the mean of X and Y data values . (ranked data values ) A spearman correlation of 1 results when the two variables are monotonically related , even if their relationship is non-linear . This means that all data points with greater x-values than that of a given data-point will have a greater y-value as well .

If one wants to check for a linear relationship between 2 variables X and Y , the same formula of Spearman's test can be applied to the raw data instead of the ranked column data .436 Views