User:Colin.champion/sandbox

Comments on this article
Edgeworth box I’ve always had an outsider’s interest in these theorems, but I haven’t had any source of information other than this article, and I can see that there are reasons not to trust it: it has a visible free market bias and makes some statements which I find incredible, especially in the attempt to defuse the possible redistributional consequences of the second theorem (while it says nothing about the serious limitation in the theorem discussed on ppxxx of Mas-Colell et al).

A few weeks ago I got hold of Mas-Colell et al. and have tried to make progress through it, with the thought in the back of my mind that I might attempt changes to the article. But rather than venture into the lion’s den, I’ve extended the article on the Edgeworth box to cover the welfare theorems.

Here are some conclusions.


 * Mas-Colell is a heap of formalist claptrap, giving you the algebraic structure inhabited by everything and the meaning of nothing.


 * ‘The shortcoming is that for the theorem to hold, the transfers have to be lump-sum...’ This is no shortcoming. In Mas-Colell et al’s terminology everything is a lump sum: everything that is normally a flow is treated as a stock (see the definition on pxxx). In the case of distortionary taxes, the standard remedy of a flow of money from the government to consumers is designated a ‘lump sum’. In the case of the second fundamental theorem the authors imply that whether something counts as a lump sum depends on the grounds for making the transfer (what nonsense!) but no definition is ever given. Nonetheless any transfer that would ever be considered as a means of redistributing income would count as a lump sum in their terminology.


 * What possible reason can a person have for expecting the economy to be in equilibrium if getting there requires the solution of a global optimisation problem?

hicks
In microeconomics, the Hicksian demand function (or compensated demand function) is a function which specifies how much of each of a number of commodities a consumer will buy, for a given set of prices, to obtain a given level of utility at minimum expense. If the minimum expense can be attained in more than one way, then we have a multivalued function and refer to the Hicksian demand correspondence.

In mathematical notation, let $$\underset{\sim}{p}$$ be a vector of prices, $$\underset{\sim}{x}$$ be a vector of demands (ie. of quantities purchased), $$u(\underset{\sim}{x})$$ be a function expressing the utility to the consumer of $$\underset{\sim}{x}$$, and let $$u_0$$ be some real-valued utility. Then the value $$\underset{\sim}{h}(\underset{\sim}{p},u_0)$$ of the Hicksian demand function is that $$\underset{\sim}{x}$$ satisfying $$u(\underset{\sim}{x})\geq u_0$$ which minimises $$\underset{\sim}{p}\cdot \underset{\sim}{x}$$. In other words
 * $$\underset{\sim}{h}(\underset{\sim}{p},u_0) = \arg \min_{\underset{\sim}{x}} \underset{\sim}{p}\cdot \underset{\sim}{x} \qquad \textrm{subject}\,\,\textrm{to}\qquad u(\underset{\sim}{x})\geq u_0.$$

draft
A little while ago I attempted to correct the definition in the lead para and had the change reverted on the grounds that the article was ‘more accurate before; BI differs in that everyone is paid regardless of wealth’. I had floated the change in advance, citing references for what I believe to be the correct definition, and giving people a chance to respond if they had evidence to the contrary. My references are here. It seems to me unconstructive to ignore the references I provided and then revert my change without adequate justification.

In particular I do not believe it to be true that NIT is characterised by payments whose size depends on wealth. The name is due to Friedman and therefore his own use of the term has a certain priority. If you read the first few pages of his ‘view from the right’ you see that he looks at a conventional system with a break-even point of $3000 and a tax rate of 50% and says that currently a worker’s take-home pay would be y&#8239;–&#8239;&frac12;&#8239;max((y–$3000),0) where y is his pre-tax pay, and that he proposes to replace this by the simpler formula y&#8239;&#8239;–&frac12;&#8239;(y–$3000), which, when the pre-tax pay is 0, gives the worker a ‘negative tax’ of $1500. But this second formula is equivalent to $1500+y&#8239;/2 – ie. a stipend of $1500 independent of wealth together with a 50% tax on all income. Have people not understood this simple point or is there something I am missing? Admittedly Friedman only looks at the ‘first tax bracket’ but the same argument applies through the entire range.

He also refers to the change being ‘directed specifically at poverty’ but this doesn’t mean that he’s adopted a formula which introduces a dependence on wealth: rather he has changed a previously existing formula in a way which only leads to different results at low incomes.

Now Friedman was only concerned with the net transfer between the government and a citizen. The same net transfer can be described by infinitely many different formulae for the stipend so long as the tax formula is modified to compensate. For this reason, even if he had proposed a non-constant formula for the stipend, it wouldn’t make sense to view the formula as the defining property as NIT. But in the case of his specific proposal, there is no reasonable way of describing it except in terms of a fixed stipend.

So I have reverted the reversion. I’ll be happy to go back to the words as they originally stood if people can provide sufficient justification for doing so.

pbi
A partial basic income (PBI) is an unconditional basic income paid to all members of a society which is set at a level insufficient to meet an individual’s basic needs.

Its consequences differ between different groups of recipients.
 * People who prefer not to work receive a payment, though at a lower level than in full basic income. The ethical questions are discussed below.
 * For unemployed people seeking work, the payment needs to be supplemented by other benefits. See Guaranteed minimum income for the concepts involved.
 * For people in work, PBI has the same effect as a wage subsidy.

Cost and benefits of basic income systems
If a society decides to pay a fixed stipend per capita, it has the choice of making the payment unconditional or conditional (usually meaning that it is limited it to people in work, varyingly understood), and of making a full income payment (ie. enough to live on) or just a partial subsidy (which needs to be supplemented by income from another source). Most governments do none of these things, but instead pay benefits in cases of need. The various options can be illustrated in a diagram.

The cell with a question mark has no agreed name.

Various factors determine the desirability of moving in different ways in the diagram.


 * Moving to the left reduces income inequality; this is discussed in the article on economic inequality.
 * Moving away from tax-and-benefit towards a stipend system reduces or eliminates the welfare trap, which is widely seen as a cause of unemployment. Moving further to the left (from partial to full income support) brings little additional benefit, and moving further up (to unconditional payments) is likely to be counterproductive. This topic is discussed in the article on the wage subsidy.
 * The desirability of making a stipend unconditional is a moral/political question discussed below in the sections on freedom and gender equality.
 * Milton Friedman ‘supported the negative income tax [ ie. basic income ] as a substitute for present welfare programs... with a sharp reduction in bureaucracy’. The claimed savings in administrative costs are specific to the top-left cell in the diagram, and are discussed below in the section on transparency and administrative efficiency.

There are two main costs.
 * The basic income needs to be funded from earnings by direct or indirect taxation. The cost is particularly high, but also relatively easy to estimate (because there is little flexibility in the size of the stipend), for full basic income systems. The costing is described below.
 * If the basic income is unconditional, then economic output may be reduced owing to people choosing not to work. This is discussed under withdrawal from the workforce.

talk
[ ''Disclaimer: my personal interest is more in wage subsidy than in basic income. I’ve written an article on the former topic, but would also like to see consistency of terminology, at any rate, across related articles. I intend to propose a merger of Negative income tax into Basic income since I believe there has been a content split – see a comment on the List of models talk page – and part of my current interest is in making this possible.'' ]

I’m sorry to recommend removal of material people have put effort into, but in my view this article would benefit from some pruning. In particular the ‘Perspectives’ section accumulates an excessive number of observations of unequal importance. Most writers concentrate on a few salient properties: incentive effects (including incentives to take employment), distribution effects, and administrative efficiency. There is an entry here for ‘Reduction of medical costs’ which I’d have said was scraping the barrel, but which has a box calling for expansion. On the other hand the ethics of funding the voluntarily unwaged is a topic of interest in its own right.

Likewise the list of prominent advocates seems out of place. Most other ‘ideas’ pages don’t have such a list. Not do I see the need for a list of critics: when someone has made a significant criticism of UBI it should be mentioned in its place.

The list of Payments with Similarities is probably legitimately within scope, but since there’s a similar list on another page it isn’t really needed.

I’m not sure that the sections on Opinions and Polls are justified. You wouldn’t expect to find such a thing on Keynesian Economics or Climate Change. The whole article gives the impression of trying to browbeat the reader by accumulating factors (which may themselves be neutrally presented) whose tendency is favourable to UBI.

The History section is unusually long and thorough, but everything in it seems justifiable. I wonder whether it should come after the theoretical discussion, assuming that this can be made reasonably concise.

On a technical level, it seems to me that some of the ‘perspectives’ are specific to full basic income (eg. administrative efficiency), some apply equally to the partial case (eg. freedom), and some need to be considered separately in the two cases (eg. welfare trap). When you consider payments to people in the workforce (ie. working or seeking paid work), PBI is equivalent to the wage subsidy, whereas when you consider payments to people outside the workforce, it belongs naturally alongside full UBI. It would make sense to split the discussion of basic income into two parts: (i) the desirability of state funding for the voluntarily unemployed, and (ii) the effects of full UBI on the workforce, leaving the effects of PBI on the workforce to be discussed by the wage subsidy article which covers the same ground anyway.

Lead (externality)
In economics, an externality is the cost or benefit associated with a transaction which is not reflected in the market mechanisms governing its price. The commonest example is pollution, as when the price of coal is determined by the costs of its extraction and sale without taking account of the pollution it causes. Pollution has the further property that the costs are borne by a large number of people (possibly including future generations), so that an unbounded number of transactions would be introduced if the costs were ‘internalized’ (brought into the market). External costs can also be negative (i.e. be benefits), as when the purchaser of a tree isn’t rewarded for the benefits it confers on other people.

Externalities are important in economics because their existence is one of the ways in which the assumption of market completeness can be violated. According to the First Theorem of Welfare Economics, market completeness is a condition for competitive markets to yield a Pareto optimal solution to economic problems, so the existence of externalities is an indication that markets may behave harmfully. Since the absence of transaction costs is another condition, the simple solution of internalizing all costs is likely to substitute one inefficiency for another. An alternative solution is the imposition of Pigovian taxes, which require a polluter to pay a sum through taxes equal to the price his pollution would incur if it was charged through the market.

MMT
The article tells us that MMT offers a recipe for curing unemployment. The lead para refers to ‘currency... effects on employment’ and then says that ‘government could use fiscal policy to achieve full employment, creating new money.’ Presumably ‘fiscal’ is an error for ‘monetary’, but it could be that ‘creating new money’ is an error for ‘raising taxes’. Under ‘policy implications’ Stephanie Kelton says that ‘fiscal policy (i.e., government taxing and spending decisions) is the primary means of achieving full employment’ but John Harvey recommends ‘creating money to... achieve full employment’. Subsequently we read that ‘MMT economists advocate a government-funded job guarantee scheme to eliminate involuntary unemployment’.

Yet though at least 3 cures for unemployment are offered, no theoretical link is mentioned between any government policy and the level of employment, nor is anything said about the factual assumptions such a model would need, notably the response of the wage rate to government actions. Similarly inflation is often mentioned, but no theoretical connection is referred to between the money supply and the price level. The article presents a lot of random assertions about money (eg. ‘the central bank buys bonds by simply creating money — it is not financed in any way’), a lot of random policy recommendations (eg. that taxation exists ‘to drive demand for the currency’) and no logical connections between anything.

Stock and shares
Defining ‘stock’ in terms of ‘shares’ seems to me circular: shares are shares of stock. In ‘The Wealth of Nations’, stock is what we would now term capital equipment. I think the correct definition is something like this: Corporations are legal entities owning property, all of which may be considered capital or stock, and a share is a title to ownership of a proportion of the corporation, and thus indirectly of the corporation’s property. In older usage the term capital is limited to liquid assets (cash in hand) and stock is limited to plant and equipment.

Externalities
Why are externalities important? Economists model human actions as selfish. Before Adam Smith’s time selfish actions were seen as inherently harmful. Smith and his contemporaries showed that, on the contrary, in a competitive market in many cases selfishness worked for the general good, and that attempts to replace it by altruism would make the world poorer. This was seen as a paradoxical and even immoral conclusion.

Eventually it came to be accepted, but economists also began to analyse the conditions in which a profit-seeking competitive market will come to the optimal solution of economic problems. One of these is the absence of externalities: if the person performing an economic action can externalise its costs, then he will not be restrained from causing damage which far outweighs his personal benefit; so we return to the position of the pre-Enlightenment moralists who saw selfishness as socially harmful.

Smith’s conclusion, of course, has been seized on by supporters of laisser faire and by everyone seeking a philosophical justification for selfishness. They would be able to get round the difficulty posed by external costs were it not for the fact that in many cases externalities are associated with two other distinctive properties: diffuseness and intertemporality of costs.

Diffuseness arises when a transaction involving a small number of people has consequences affecting a much larger number. Intertemporailty arises when the costs are borne later than the benefits are materialised. Both of these properties arise in connection with environmental damage, in which one person’s coal fire spreads pollution into the atmosphere, and in which nuclear waste poses a threat over tens of millennia while affording only a transient benefit.

The free market solution to external costs is to internalise them: to bring them into the market. Diffuseness and intertemporality make this absurd or impossible for the most important external costs. If a price tag was attached to each lungful of air, then the price mechanism might impose a control on pollution; but the cost of tracing each contamination to its source would outweigh the benefits; and this is recognised through the conditions of market optimality, since one of these is precisely that transaction costs should be insignificant.

=Distance from a point to a line= The distance (or perpendicular distance) from a point to a line is the shortest distance from a fixed point to any point on a fixed infinite line in Euclidean geometry. It is the length of the line segment which joins the point to the line and is perpendicular to the line. The formula for calculating it can be derived and expressed in several ways.

To find the distance from a point to a line segment consider the line obtained by extending the segment infinitely in both directions. Then the distance to the segment is either&#x202f; the distance to the line (if the perpendicular to the line falls within the segment) or else&#x202f; the distance to the closer of the endpoints.

Knowing the shortest distance from a point to a line can be useful in various situations&mdash;for example, finding the shortest distance to reach a road, quantifying the scatter on a graph, etc.

Line defined by an equation in Cartesian coordinates
In the case of a line in the plane given by the equation ax + by + c = 0, where a, b and c are real constants with a and b not both zero, the distance from the line to a point (x0,y0) is


 * $$\operatorname{distance}(ax+by+c=0, (x_0, y_0)) = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}. $$

The point on this line which is closest to (x0,y0) has coordinates:
 * $$x = \frac{b(bx_0 - ay_0)-ac}{a^2 + b^2} \text{ and } y = \frac{a(-bx_0 + ay_0) - bc}{a^2+b^2}.$$

Horizontal and vertical lines

In the general equation of a line, ax + by + c = 0, a and b cannot both be zero unless c is also zero, in which case the equation does not define a line. If a = 0 and b $≠$ 0, the line is horizontal and has equation y = -c/b. The distance from (x0, y0) to this line is measured along a vertical line segment of length |y0 - (-c/b)| = |by0 + c| / |b| in accordance with the formula. Similarly, for vertical lines (b = 0) the distance between the same point and the line is |ax0 + c| / |a|, as measured along a horizontal line segment.

Line defined by two points
If the line passes through two points P1=(x1,y1) and P2=(x2,y2) then the distance of (x0,y0) from the line is:
 * $$\operatorname{distance}(P_1, P_2, (x_0, y_0)) = \frac{|(y_2-y_1)x_0-(x_2-x_1)y_0+x_2 y_1-y_2 x_1|}{\sqrt{(y_2-y_1)^2+(x_2-x_1)^2}}. $$

The denominator of this expression is d12, the distance between P1 and P2. The numerator is twice the area of the triangle with its vertices at the three points, (x0,y0), P1 and P2. See:. The expression is equivalent to $h=\frac{2A}{b}$, which can be obtained by rearranging the standard formula for the area of a triangle: $A=\frac{1}{2} bh$ , where b is the length of a side, and h is the perpendicular height from the opposite vertex.

Since (assuming non-coincident points) $$cos \theta = u = \frac{d_{01}^2+d_{12}^2-d_{02}^2}{2 d_{01} d_{12}}$$ (see Law of cosines), and twice the area of the triangle is $$d_{12} d_{01} sin \theta = d_{12} d_{01} \sqrt{1-u^2}$$, we get the formula:
 * $$\operatorname{distance}(P_1, P_2, (x_0, y_0)) = d_{01} \sqrt{1-u^2}.$$

Distance from a point to a segment
Using the notation of the previous section we let q denote the signed distance from P1 in the direction of P2 to the intercept with the perpendicular; hence $$q=d_{01} u$$, and the value of q&#x202f; determines whether the intercept falls within the segment.

The following procedure gives the distance from P0 to the segment P1&#x202f;–&#x202f;P2 in all cases (including coincident points):
 * If d&#x202f;01&#x202f;=&#x202f;0 or d&#x202f;02&#x202f;=&#x202f;0 then the distance is 0;
 * Else if d12&#x202f;=&#x202f;0 then the distance is d&#x202f;01;
 * Else, letting $$u = \frac{d_{01}^2+d_{12}^2-d_{02}^2}{2 d_{01} d_{12}}$$, if u&#x202f;&le;&#x202f;0 then the distance is d&#x202f;01;
 * Else if d&#x202f;01u&#x202f;&ge;&#x202f;d12 then the distance is d&#x202f;02;
 * Else the distance is $$d_{01} \sqrt{1-u^2}$$.

An algebraic proof
This proof is only valid if the line is neither vertical nor horizontal, that is, we assume that neither a nor b in the equation of the line is zero.

The line with equation ax + by + c = 0 has slope -a/b, so any line perpendicular to it will have slope b/a (the negative reciprocal). Let (m, n) be the point of intersection of the line ax + by + c = 0 and the line perpendicular to it which passes through the point (x0, y0). The line through these two points is perpendicular to the original line, so
 * $$\frac{y_0 - n}{x_0 - m}=\frac{b}{a}.$$

Thus, $$a(y_0 -n) - b(x_0 - m) = 0,$$ and by squaring this equation we obtain:
 * $$a^2(y_0 - n)^2 + b^2(x_0 - m)^2 = 2ab(y_0 - n)(x_0 - m).$$

Now consider,
 * $$ (a(x_0 - m) + b(y_0 - n))^2 = a^2(x_0 - m)^2 + 2ab(y_0 -n)(x_0 - m) + b^2(y_0 - n)^2 = (a^2 + b^2)((x_0 - m)^2 + (y_0 - n)^2)$$

using the above squared equation. But we also have,
 * $$ (a(x_0 - m) + b(y_0 - n))^2 = (ax_0 + by_0 - am -bn )^2 = (ax_0 + by_0 + c)^2$$

since (m, n) is on ax + by + c = 0. Thus,
 * $$(a^2 + b^2)((x_0 - m)^2 + (y_0 - n)^2) = (ax_0 + by_0 + c)^2 $$

and we obtain the length of the line segment determined by these two points,
 * $$d=\sqrt{(x_0 - m)^2+(y_0 - n)^2}= \frac{|ax_0+ by_0 +c|}{\sqrt{a^2+b^2}}.$$

A geometric proof


This proof is valid only if the line is not horizontal or vertical.

Drop a perpendicular from the point P with coordinates (x0, y0) to the line with equation Ax + By + C = 0. Label the foot of the perpendicular R. Draw the vertical line through P and label its intersection with the given line S. At any point T on the line, draw a right triangle TVU whose sides are horizontal and vertical line segments with hypotenuse TU on the given line and horizontal side of length |B| (see diagram). The vertical side of ∆TVU will have length |A| since the line has slope -A/B.

∆PRS and ∆TVU are similar triangles, since they are both right triangles and ∠PSR ≅ ∠TUV since they are corresponding angles of a transversal to the parallel lines PS and UV (both are vertical lines). Corresponding sides of these triangles are in the same ratio, so:
 * $$\frac{|\overline{PR}|}{|\overline{PS}|} = \frac{|\overline{TV}|}{|\overline{TU}|}.$$

If point S has coordinates (x0,m) then |PS| = |y0 - m| and the distance from P to the line is:
 * $$ |\overline{PR} | = \frac{|y_0 - m||B|}{\sqrt{A^2 + B^2}}.$$

Since S is on the line, we can find the value of m,
 * $$m = \frac{-Ax_0 - C}{B},$$

and finally obtain:
 * $$ |\overline{PR}| = \frac{|Ax_0 + By_0 + C|}{\sqrt{A^2 + B^2}}.$$

A variation of this proof is to place V at P and compute the area of the triangle ∆UVT two ways to obtain that $$D|\overline{TU}| = |\overline{VU}||\overline{VT}|$$ where D is the altitude of ∆UVT drawn to the hypoteneuse of ∆UVT from P. The distance formula can then used to express $$|\overline{TU}|$$, $$|\overline{VU}|$$, and $$|\overline{VT}|$$in terms of the coordinates of P and the coefficients of the equation of the line to get the indicated formula.

A vector projection proof


Let P be the point with coordinates (x0, y0) and let the given line have equation ax + by + c = 0. Also, let Q = (x1, y1) be any point on this line and n the vector (a, b) starting at point Q. The vector n is perpendicular to the line, and the distance d from point P to the line is equal to the length of the orthogonal projection of $$\overrightarrow{QP}$$ on n. The length of this projection is given by:
 * $$d = \frac{|\overrightarrow{QP} \cdot \mathbf{n}|}{\| \mathbf{n}\|}.$$

Now,
 * $$ \overrightarrow{QP} = (x_0 - x_1, y_0 - y_1),$$ so $$ \overrightarrow{QP} \cdot \mathbf{n} = a(x_0 - x_1) + b(y_0 - y_1)$$ and $$ \| \mathbf{n} \| = \sqrt{a^2 + b^2},$$

thus
 * $$ d = \frac{|a(x_0 - x_1) + b(y_0 - y_1)|}{\sqrt{a^2 + b^2}}.$$

Since Q is a point on the line, $$c = -ax_1 - by_1$$, and so,
 * $$ d = \frac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}}.$$

Another formula
It is possible to produce another expression to find the shortest distance of a point to a line. This derivation also requires that the line is not vertical or horizontal.

The point P is given with coordinates ($$x_0, y_0$$). The equation of a line is given by $$y=mx+k$$. The equation of the normal of that line which passes through the point P is given $$y=\frac{x_0-x}{m}+y_0$$.

The point at which these two lines intersect is the closest point on the original line to the point P. Hence:
 * $$mx+k=\frac{x_0-x}{m}+y_0.$$

We can solve this equation for x,
 * $$x=\frac{x_0+my_0-mk}{m^2+1}.$$

The y coordinate of the point of intersection can be found by substituting this value of x into the equation of the original line,
 * $$y=m\frac{(x_0+my_0-mk)}{m^2+1}+k.$$

Using the equation for finding the distance between 2 points, $$d=\sqrt{(X_2-X_1)^2+(Y_2-Y_1)^2}$$, we can deduce that the formula to find the shortest distance between a line and a point is the following:


 * $$d=\sqrt{ \left( {\frac{x_0 + m y_0-mk}{m^2+1}-x_0 } \right) ^2 + \left( {m\frac{x_0+m y_0-mk}{m^2+1}+k-y_0 }\right) ^2 } = \frac{|k + m x_0 - y_0|}\sqrt{1 + m^2} .$$

Recalling that m = -a/b and k = - c/b for the line with equation ax + by + c = 0, a little algebraic simplification reduces this to the standard expression.

Vector formulation


The equation of a line can be given in vector form:


 * $$ \mathbf{x} = \mathbf{a} + t\mathbf{n}$$

Here $a$ is the position of a point on the line, and $n$ is a unit vector in the direction of the line. Then as scalar t varies, $x$ gives the locus of the line.

The distance of an arbitrary point $p$ to this line is given by


 * $$\operatorname{distance}(\mathbf{x} = \mathbf{a} + t\mathbf{n}, \mathbf{p}) = \| (\mathbf{a}-\mathbf{p}) - ((\mathbf{a}-\mathbf{p}) \cdot \mathbf{n})\mathbf{n} \|. $$

This formula can be derived as follows: $$\mathbf{a}-\mathbf{p}$$ is a vector from $p$ to the point $a$ on the line. Then $$(\mathbf{a} - \mathbf{p}) \cdot \mathbf{n}$$ is the projected length onto the line and so
 * $$((\mathbf{a} - \mathbf{p}) \cdot \mathbf{n})\mathbf{n}$$

is a vector that is the projection of $$\mathbf{a}-\mathbf{p}$$ onto the line. Thus
 * $$(\mathbf{a}-\mathbf{p}) - ((\mathbf{a}-\mathbf{p}) \cdot \mathbf{n})\mathbf{n}$$

is the component of $$\mathbf{a}-\mathbf{p}$$ perpendicular to the line. The distance from the point to the line is then just the norm of that vector. This more general formula is not restricted to two dimensions.

Another vector formulation
If the vector space is orthonormal and if the line (l ) goes through point A and has a direction vector $$\vec u$$, the distance between point P and line (l) is
 * $$d(\mathrm{P}, (l))= \frac{\left\|\overrightarrow{\mathrm{AP}} \times\vec u\right\|}{\|\vec u\|}$$

where $$\overrightarrow{\mathrm{AP}} \times\vec u$$ is the cross product of the vectors $$\overrightarrow{\mathrm{AP}}$$ and $$\vec u$$ and where $$\|\vec u\|$$ is the vector norm of $$\vec u$$.

Note that cross products only exist in dimensions 3 and 7.

Determining whether two segments cross
Let the segments be P00–P01 and P10–P11 of lengths d&#x202f;0 and d&#x202f;1, and let the distances between the endpoints of the different segments be the dij&#x202f; as shown. Let O&#x202f; be the point of intersection of the lines&#x202f; extending the segments in each direction: the segments cross if O&#x202f; lies in both of them.

Let h&#x202f;0 and h&#x202f;1 be the signed&#x202f; distances from P00 and P10 to O&#x202f; in the directions of P01 and P11. Then the segments cross if and only if 0&le;h&#x202f;0&le;d&#x202f;0 and 0&le;h&#x202f;1&le;d&#x202f;1.

We may apply the Law of cosines to the angle &#x03B8; subtended by P00–P10 at O to obtain the equation:
 * $$\cos \theta = \frac{h_0^2+h_1^2-d_{00}^2}{2 h_0 h_1},$$

with 3 similar equations obtained from the other triangles. This leads to a redundant set of 4 equations in the 3 variables h&#x202f;0, h&#x202f;1, and cos&#x202f;&#x03B8;.

The solution tells us that
 * $$\cos \theta = C = \frac{d_{01}^2+d_{10}^2-d_{00}^2-d_{11}^2}{2 d_0 d_1}$$

from which it follows that the segments are parallel if and only if |C&#x202f;|&#x202f;=&#x202f;1. h&#x202f;0 and h&#x202f;1 are given by the equations
 * $$2 h_0(1-C^2) = \frac{d_{00}^2+d_{0}^2-d_{10}^2}{d_0} + C \frac{d_{00}^2+d_{1}^2-d_{01}^2}{d_1},$$
 * $$2 h_1(1-C^2) = \frac{d_{00}^2+d_{1}^2-d_{01}^2}{d_1} + C \frac{d_{00}^2+d_{0}^2-d_{10}^2}{d_0}.$$

So if we define
 * $$A = \frac{d_{00}^2-d_{10}^2}{d_0},\qquad B = \frac{d_{00}^2-d_{01}^2}{d_1}$$

it follows that that the criterion for the segments to cross is that the following two relations should be jointly satisfied:
 * $$\left|A + B C + d_1 C + d_0 C^2\right| \leq d_0 (1-C^2)$$, and  $$\left|B + A C + d_0 C + d_1 C^2\right| \leq d_1 (1-C^2)$$.

Finding the minimum distance between two line segments
Use the notation of the diagram.
 * If&#x202f; d&#x202f;0=0 then the distance is the distance of P&#x202f;00 from the segment P&#x202f;10–P&#x202f;11;
 * Else if&#x202f; d&#x202f;1=0 then the distance is the distance of P&#x202f;10 from the segment P&#x202f;00–P&#x202f;01;
 * Else, letting $$C = (d_{01}^2+d_{10}^2-d_{00}^2-d_{11}^2)/(2 d_0 d_1)$$, if&#x202f; $$C=\pm 1$$ then the distance is d&#x202f;00;
 * Else if&#x202f; the criterion for intersection above is satisfied, then the distance is 0;
 * Else the distance is the smallest of the 4 distances from an endpoint of one segment to the other segment.