ChatZilla:Message Filter: Difference between revisions

m
No edit summary
 
(16 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Calculus I INTRODUCTION
[[ChatZilla]] > Message Filter


Calculus, branch of mathematics concerned with rates of change, gradients of curves, maximum and minimum values of functions, and the calculation of lengths, areas, and volumes. It is widely used, especially in science and engineering, wherever continuously varying quantities occur.  
== Aims ==
*Allow the user to specify exactly where any message should go, by use of a system based on filters, similar to mail/news.
*Make a default set of filters to mimic current behaviour. Keep this around in order to be able to switch back to it. You don't want users to mess stuff up and find themselves unable to return to a normally working state.
*Allow filters to specify whether the system should continue to look into other filters that may match.
*Save the filters using Silver's system for javascript object storage.


II HISTORICAL DEVELOPMENT
A more technical draft can be found here: [[ChatZilla:Message Filter:Implementation Details]].


Calculus derives from ancient Greek geometry. Democritus calculated the volumes of pyramids and cones, probably by regarding them as consisting of infinitely many cross-sections of infinitesimal (infinitely small) thickness, and Eudoxus and Archimedes used the “method of exhaustion�?, finding the area of a circle by approximating it arbitrarily closely with inscribed polygons. However, difficulties with irrational numbers and the paradoxes of Zeno prevented a systematic theory developing. In the early 17th century Cavalieri and Torricelli extended the use of infinitesimals, while Descartes and Fermat used algebra for determining areas and tangents (integration and differentiation, in modern terms). Fermat and Barrow knew these two processes were closely related, and Newton (in the 1660s) and Leibniz (in the 1670s) proved the Fundamental Theorem of Calculus, that they are mutually inverse. Newton's discoveries, motivated by his theory of gravitation, preceded Leibniz's, but his delays in publishing them caused bitter priority disputes, and Leibniz's notation was eventually adopted.  
== Filter properties ==
Each filter has rules and actions associated with them. The actions will be executed when all the rules match the message. When there are no rules, the filter always matches. Apart from rules and actions, there are a few flags that can be set on filters:
* Stop processing. This means that if this filter matches, all its actions will be carried out, and then filter processing will stop (meaning, it will not try and use any of the filters after this one).
* Create tabs if necessary. This means that if this filter has an action specified to set a tab to a specific state, or display something on a tab, that the tab that this would happen on will get created if it isn't there yet. If this flag is not specified, the display or set tab state action will go down the list of tabs it gets, and set a tab state or display something on the first tab that does exist. If none of the specified tabs exist, no action will take place.
* Match all rules vs. Match any rule. Whether or not one rule matching is enough for the filter to match.


The 18th century saw widespread applications of calculus, but imprecise use of infinite and infinitesimal quantities and geometric intuition still caused confusion and controversy about its foundations, the philosopher Berkeley being a notable critic. The 19th-century analysts replaced these vague notions with firm foundations based on finite quantities: Bolzano and Cauchy defined limits and derivatives precisely, Cauchy and Riemann did likewise for integrals, and Dedekind and Weierstrass for real numbers. For instance, it was now understood that differentiable functions are continuous, and continuous functions integrable, but both converses fail. In the 20th century, non-standard analysis belatedly legitimized infinitesimals, while the development of computers increased the applicability of calculus.  
== Filter rules ==
The user should be given an option to have all rules match, or just one (AND/OR difference)
The filter rule system should be based on 4 fields:
#The Type of the rule (see below)
#The type of match done. This can be any of:
#*An exact match. This is easiest.
#* Starts with. Slightly harder, but still easy compared to others.
#* Ends with. Slightly unusual, but should be easy to do when the previous type is supported, and besides, don't kill people who don't understand regular expressions!
#* Contains. Simple, and expected by normal users
#* Regular Expression. Expected by power users.
#* Function match. Used by the client itself and obviously also by plugins/scripts.
#The text or regular expression we're matching to.
#Optional negation field. Easier than adding 'Does not' entries for everything mentioned in field 2.


III DIFFERENTIAL CALCULUS
=== Types of rules ===


Differential calculus is concerned with rates of change. Suppose that two variables x and y are related by an equation y = f(x) for some function f, indicating how the value of y depends on the value of x. For instance, x could represent time, and y the distance travelled by some moving object at time x. A small change h in x, from a value x0 to x 0 + h, induces a change k in y from y 0 = f(x0) to y0 + k = f(x0 + h); thus k = f( x0 + h) - f(x0), and the ratio k/h represents the average rate of change of y as x increases from x0 to x0 + h. The graph of the function y = f(x) is a curve in the xy-plane, and k/h is the gradient of the line AB through the points A = (x 0,y0) and B = (x0 + h,y 0 + k) on this curve; this is shown in Figure 1, where h = AC and k = CB, so k/h is the tangent of the angle BAC.  
What you can possibly match:
* Source Network name.
* Target channelname.
* Target username (you, but remember that you can have various nicks! You could use this, for example, to make a 'beep' when people use your name, *except* when it contains "sleep". Nifty, eh?)
* Source username
* Message contents
* Message types (INFO, JOIN, PART, QUIT, etc., and we need a way to get nice names for all those stupid response codes (end of list, whatever))
* Current away message.
* Use a function to match based on all available data.


If h approaches 0, with x0 fixed, then k/h approaches the instantaneous rate of change of y at x0; geometrically, B approaches A along the graph of y = f(x), and the line AB approaches the tangent AT to the graph at A, so k/h approaches the gradient of the tangent (and hence of the curve) at A. We therefore define the derivative f′(x0) of the function y = f(x) at x0 to be the value (or limit) which k/h approaches as h approaches 0, written:
== Filter Actions ==


This represents both the rate of change of y and the gradient of the graph at A. When x is time and y is distance, for example, the derivative represents instantaneous velocity. Positive, negative, or zero values of f′(x0) respectively indicate that f(x) is increasing, decreasing, or stationary at x 0. The derivative is a new function f′(x) of x, sometimes denoted by dy/dx, df/dx or Df. For example, let y = f(x) = x2, so the graph is a parabola. Then
Somewhat surprisingly, we probably want 3 fields on 'what to do now'.
So, suppose we matched a filter. What can the user tell us to do from the first field?


so k/h = 2x0 + h, which approaches 2x 0 as h→ 0. Thus the gradient when x = x0 is 2x0, and the derivative of f(x) = x2 is f′(x) = 2 x. Similarly xm has derivative mxm-1 for each fixed m. The derivatives of all commonly occurring functions are known: see the table for some examples.  
*Replace text within the message
*Display on:
** the target tab (passed in by the caller, usually server / channel / user)
** the source tab (for example, the user who sent the message)
** the current tab. (whatever's current when display is called)
** the handling tab. (the tab display was called on)
** the parent of the handling tab. This is the network/server tab for users/channels/dcc, and the client tab for networks/servers.
** the client tab. Plain, simple.
*Get Attention. Will flash the window. Ignores other fields.
*Set the tab state. Will use the other field to pick a state for this, and a list of views to try and set (same options as the display action).
*Play sound. Takes the second field into account: beep or url to sound file
*Dispatch. Takes the second field as the parameter.
*Run function.


Some words of caution are needed here. Firstly, to find the derivative we make h small (positive or negative), but never zero: this would give k/h = 0/0, which is meaningless. Secondly, not every function f has a derivative at each x0, since k/h need not approach a limit as h→ 0. For instance, f(x) = | x| has no derivative at x0 = 0, since k/h is 1 or -1 as h> 0 or h< 0; geometrically, the graph has a corner (and hence no tangent) at A = (0,0). Thirdly, although the notation dy/dx suggests the ratio of two numbers dy and dx (denoting infinitesimal changes in y and x), it is really a single number, the limit of a ratio k/h as both terms approach 0.


Differentiation is the process of calculating derivatives. If a function f is formed by combining two functions u and v, its derivative f′ can be obtained from u and v by simple rules; for instance the derivative of a sum is the sum of their derivatives, that is, if f = u + v (meaning that f(x) = u(x) + v(x) for all x) then f′ = u′ + v′, and a similar rule (u - v)′ = u′ - v′ applies to differences. If a function is multiplied by a constant, then so is its derivative, that is, (cu)′ = cu′ for any constant c. The rules for products and quotients are less obvious: if f = uv then f′ = uv′ + u′v, and if f = u/v then f′ = ( u′v-uv′)/v2 provided v(x) ≠ 0.


Using these rules, quite complicated functions can be differentiated: for instance x2 and x5 have derivatives 2 x and 5x4, so the function 3x2 - 4x5 has derivative (3x2 - 4x 5)′ = (3x2)′ - (4x5)′ = 3.( x2)′ - 4.(x5)′ = 3.(2x) - 4.(5 x4) = 6x - 20x4. More generally, any polynomial f(x) = a0 + a1x + ... + anxn has derivative f′(x) = a1 + 2a2 x + ... + nanxn-1; in particular, constant functions have derivative 0.
== Existing things that could be done using filters ==
*The stalk list
*Sound preferences (when to play sound)
*? (I'm fairly sure there are more, but can't think of any at 7.16 in the morning. This is a wiki, feel free to add them.)


If y = u(z) and z = v(x), so that y depends on z and z depends on x, then y = u(v(x)), so y depends on x, written y = f(x) where f is the composition of u and v; the chain rule states that dy/dx = (dy/dz).(dz/dx), or equivalently f′(x) = u′(v(x)). v′(x). For instance, if y = ez where e = 2.718 ... is the exponential constant, and z = ax where a is any constant, then y = eax; now dy/dz = ez (see table) and dz/dx = a, so dy/dx = aeax.
The question is, what do we want to do with those existing things? Can we/Should we dynamically move them to some filter? Create a filter based on the lists/preferences? Opinions please! :-)


Many problems can be formulated and solved using derivatives. For example, let y be the amount present in a sample of radioactive material at time x. According to theory and observation, the sample decays at a rate proportional to the amount remaining, that is, dy/dx = ay for some negative constant a. To find y in terms of x, we therefore need a function y = f(x) such that dy/dx = ay for all x. The most general such function is y = ce ax where c is a constant. Since e0 = 1 we have y = c when x = 0, so c is the initial amount present (at time x = 0). Since a<0 we have eax→ 0 as x increases, so y→ 0, confirming that the sample gradually decays to nothing. This is an example of exponential decay, shown in figure 3a. If a is a positive constant, we obtain the same solution y = ceax, but as time progresses y now increases rapidly (since eax does when a>0); this is exponential growth, shown in figure 3b and observed in nuclear explosions and certain animal communities, where growth-rate is proportional to population.
--[[User:Eyalroz|Eyalroz]] 07:30, 2 Jan 2006 (PST) says: Don't forget proper documentation and structuring of this filter system so that other people can write fixes for dependent bugs if necessary.
: [[User:GijsKruitbosch|GijsKruitbosch]] 06:45, 7 Jan 2006 (PST) says: The current idea is that I write a documentation/spec kind of thing first (what should happen where, why, what should it do) and then actually code it. Coding it without thinking about what happens where is not going to go anywhere. So that should take care of this (although of course, I/we am/are likely to encounter problems when actually doing the coding)


IV INTEGRAL CALCULUS
[[category:ChatZilla|Message Filter]]
 
Integral calculus involves the inverse process to differentiation, called integration. Given a function f, we seek a function F with derivative F′ = f; this is an integral or antiderivative of f, written F(x) = ∫ f(x)dx or simply F = ∫f dx (a notation we will explain later). Tables of derivatives can be used for integration: thus x2 has derivative 2x, so 2x has x2 as an integral. If F is any integral of f, the most general integral of f is F + c, where c is an arbitrary constant called the constant of integration; this is because a constant has derivative 0, so ( F + c)′ = F′ + c′ = f + 0 = f. Thus ∫2xdx = x2 + c, for instance.
 
The basic rules for integrating compound functions resemble those for differentiation. The integral of a sum or difference is the sum or difference of their integrals, and likewise for multiplication by a constant. Thus x = y.2x has integral yx2, and similarly ∫xm dx = xm+1/(m + 1) for any m≠ -1. (We exclude m = -1 to avoid dividing by 0; the natural logarithm ln|x| is an integral of x-1 = 1/x for any x≠ 0.) Integration is generally harder than differentiation, but many of the more familiar functions can be integrated by these and other rules (see the table).
 
A classic application of integration is to calculate areas. Let A be the area of the region between the graph of a function y = f(x) and the x-axis, for a≤x≤b. For simplicity, assume that f(x) ≥ 0 between a and b. For each x≥a, let L(x) be the area of this region to the left of x, so we need to find A = L(b). First we differentiate L(x). If h is a small change in x, the region below the graph between x and x + h is approximately a rectangle of height f(x) and width h (see figure 4); the corresponding change k = L(x + h) - L(x) in area is therefore approximately f(x)h, so k/h is approximately f(x). As h→ 0 these approximations become more exact, so k/h→ f(x) and hence L′(x) = f(x). Thus L is an integral of f, so if we know any integral F of f then L = F + c for some constant c. Now L(a) = 0 (since the region to the left of x vanishes when x = a), so c = -F(a) and hence L(x) = F(x) - F(a) for all x≥a. In particular, A = L(b) = F(b) - F(a), written
 
This is the Fundamental Theorem of Calculus, valid whenever f is continuous between a and b, provided we assign negative areas to any regions below the x-axis, where f(x) < 0. (Continuity means that f(x) → f(x0) as x→x0, so f has an unbroken graph.) For example f(x) = x2 has integral F( x) = x3/3, so
 
and with this formula it is possible to work out a large number of useful quantities. For example, the volume of a cone of height h and radius r can be found by evaluating the expression ∫p (rx / h)2 dx between the limits x = 0 and x = 1; this is because the radius at a distance x below the apex of the cone is rx / h and the cross-sectional area is p (rx / h)2. The result is p r2 h / 3.
 
Here is a definite integral of f; this is a number, whereas the indefinite integral ∫f(x)dx is a function F(x) (more precisely, a set of functions F(x) + c). The symbol ∫ (a 17th-century S) suggests summation of areas f(x)dx of infinitely many rectangles of height f(x) and infinitesimal width dx; more precisely, is the limit of a sum of finitely many rectangular areas, as their widths approach 0.
 
The derivative dy/dx = f′(x) of a function y = f(x) can be differentiated again to obtain a second derivative, denoted by d2y/dx 2, f′′(x) or D2f. If x is time and y is distance travelled, for instance, so that dy/dx is velocity v, then d2y/dx2 = dv/dx is rate of change of velocity, that is, acceleration. By Newton's second law of motion, a body of constant mass m subject to a force F undergoes an acceleration a satisfying F = ma. For example, if the body falls under the gravitational force F = mg (where g is the gravitational field strength) then ma = F = mg implies a = g, so dv/dx = g. Integrating, we have v = gx + c where c is constant; putting x = 0 shows that c is the initial velocity. Integrating dy/dx = v = gx + c, we have y = ygx2 + cx + b where b is constant; putting x = 0 shows that b is the initial value of y.
 
Higher derivatives f(n)(x) = dn y/dxn = Dnf of f( x) are found by successively differentiating n times. Taylor's Theorem states that if f(x) can be represented as a power series f(x) = a0 + a1x + a2x2 + ... + anx n + ... (where a0,a1, ... are constants), then an = f(n)(0)/n! where 0!=1 and n!= 1 × 2 × 3 × ... × n for all n≥ 1. Most commonly used functions can be represented as power series; for instance if f(x) = ex then f(n)(x) = ex for all n, so f(n)(0) = e0 = 1 and hence:
 
 
 
 
V PARTIAL DERIVATIVES
 
Functions of several variables can also have derivatives. Let z = f(x,y), so z depends on x and y. Temporarily holding y constant we can regard z as a function of x, and differentiating this gives the partial derivative ¶z/¶x = ¶f/¶x; similarly, keeping x constant and differentiating with respect to y we obtain ¶z/¶y = ¶f/¶y. For instance, if z = x2 -xy + 3y2 then ¶z/¶x=2x-y and ¶z/¶y= -x+6y. Geometrically, an equation z = f(x,y) defines a surface in three-dimensional space; if the x- and y-axes are horizontal and the z-axis is vertical, then ¶z/¶x and ¶z/¶y represent the gradients of this surface at the point (x,y,z) in the directions of the x- and y-axes. Partial derivatives can also be calculated for functions of more than two variables, by keeping all but one variable temporarily constant; higher partial derivatives can be defined by repeating this operation. Partial derivatives are important in applied mathematics, where functions often depend on several variables such as space and time.
242

edits