back to playlist

In multilinear algebra and tensor analysis, **covariance** and **contravariance** describe how the quantitative description of certain geometric or physical entities changes with a change of basis. In physics, a basis is sometimes thought of as a set of reference axes. A change of scale on the reference axes corresponds to a change of units in the problem. For instance, in changing scale from meters to centimeters (that is, *dividing* the scale of the reference axes by 100), the components of a measured velocity vector will *multiply* by 100. Vectors exhibit this behavior of changing scale *inversely* to changes in scale to the reference axes: they are *contravariant*. As a result, vectors often have units of distance or distance times some other unit (like the velocity).

This page contains text from Wikipedia, the Free Encyclopedia - https://wn.com/Covariance_and_contravariance_of_vectors

**Covariance and contravariance** may refer to:

This page contains text from Wikipedia, the Free Encyclopedia - https://wn.com/Covariance_and_contravariance

The type system of many programming languages support subtyping. For instance, if `Cat`

is subtype of `Animal`

, then an expression of type `Cat`

can be used whenever an expression of type `Animal`

could. **Variance** refers to how subtyping between more complex types (list of `Cat`

s versus list of `Animal`

s, function returning `Cat`

versus function returning `Animal`

, ...) relates to subtyping between their components. Depending on the variance of the type constructor, the subtyping relation may be either preserved, reversed, or ignored. For example, in C#:

`IEnumerable<Cat>`

is a subtype of `IEnumerable<Animal>`

. The subtyping is preserved because `IEnumerable<T>`

is `T`

.`Action<Animal>`

is a subtype of `Action<Cat>`

. The subtyping is reversed because `Action<T>`

is `T`

.`IList<Cat>`

nor `IList<Animal>`

is a subtype of the other, because `IList<T>`

is `T`

.The variance of a C# interface is determined by `in`

/`out`

annotations on its type parameters; the above interfaces are declared as `IEnumerable<out T>`

, `Action<in T>`

, and `IList<T>`

. Types with more than one type parameter may specify different variances on each type parameter. For example, the delegate type `Func<in T, out TResult>`

represents a function with a **contravariant** input parameter of type `T`

and a **covariant** return value of type `TResult`

.

This page contains text from Wikipedia, the Free Encyclopedia - https://wn.com/Covariance_and_contravariance_(computer_science)

back

Help |
About WN |
Privacy Policy |
Contact |
Feedback |
Jobs |
Students |
Email this page |
Newsletter |

© WN 2021 All Rights Reserved, World News Inc

© WN 2021 All Rights Reserved, World News Inc

- Connect:
- CHAT

×

Share this video with your family and friends