Difference between revisions of "Functor"

From Conservapedia
Jump to navigation Jump to search
(rewrite, add example)
(Computer science use of the term. Should there be a disambiguation page?)
Line 1: Line 1:
 +
The term '''functor''' has two distinct meanings.
 +
 +
==In Pure Mathematics==
 
In [[category theory]], a '''functor''' is a map between categories satisfying certain relations.  Functors, in a sense, provide for categories what group [[homomorphism|homomorphisms]] do for groups.  To be precise, a function <math>F : \mathcal C \to \mathcal D</math> between two categories associates to each object <math>X \in \textrm{Ob } \mathcal C</math> an object <math>F(X) \in \textrm{Ob } \mathcal D</math>, and to each morphism <math>f \in \mathcal C(X,Y)</math> a morphism <math>F(f) \in \mathcal D(FX,FY)</math> such that:
 
In [[category theory]], a '''functor''' is a map between categories satisfying certain relations.  Functors, in a sense, provide for categories what group [[homomorphism|homomorphisms]] do for groups.  To be precise, a function <math>F : \mathcal C \to \mathcal D</math> between two categories associates to each object <math>X \in \textrm{Ob } \mathcal C</math> an object <math>F(X) \in \textrm{Ob } \mathcal D</math>, and to each morphism <math>f \in \mathcal C(X,Y)</math> a morphism <math>F(f) \in \mathcal D(FX,FY)</math> such that:
:<math>F(\textrm{id}_X) = id_{F(X)}</math>
+
:<math>F(\textrm{id}_X) = id_{F(X)}\,</math>
 
:<math>F(g \circ f) = F(g) \circ F(f)</math>.
 
:<math>F(g \circ f) = F(g) \circ F(f)</math>.
 
Functors are the fundamental objects used to relate structures between different categories.
 
Functors are the fundamental objects used to relate structures between different categories.
  
== Examples ==
+
=== Examples ===
Algebraic topology was the first field in which the usefulness of the notion of a functor was recognized.  A basic example is the [[fundamental group]] functor <math>\pi_1 : \textbf{Top}* \to \textbf{Grp}</math>.  The action on objects is defined by sending a topological space to its fundamental group <math>\pi_1(X)</math>.  Recall that a map between two topological spaces <math>f : X \to Y</math> induces a map <math>f_* : \pi_1(X) \to \pi(Y)</math> by <math>f_*([\gamma]) = [f \circ \gamma]</math>.  Set <math>\pi_1(f) = f_*</math> so defined.  The functoriality of <math>\pi_1</math> boils down to the fact that <math>F(\textrm{id}_X) = \textrm{id}_{\pi_1(X)}</math>, that is, the identity map on a topological space induces the identity map on its fundamental group, together with the fact that <math>F(g \circ f) = F(g) \circ F(f)</math>, explained at [[fundamental group]].
+
Algebraic topology was the first field in which the usefulness of the notion of a functor was recognized.  A basic example is the [[fundamental group]] functor <math>\pi_1 : \textbf{Top}* \to \textbf{Grp}</math>.  The action on objects is defined by sending a topological space to its fundamental group <math>\pi_1(X)</math>.  Recall that a map between two topological spaces <math>f : X \to Y</math> induces a map <math>f_* : \pi_1(X) \to \pi(Y)</math> by <math>f_*([\gamma]) = [f \circ \gamma]</math>.  Set <math>\pi_1(f) = f_*\,</math> so defined.  The functoriality of <math>\pi_1</math> boils down to the fact that <math>F(\textrm{id}_X) = \textrm{id}_{\pi_1(X)}</math>, that is, the identity map on a topological space induces the identity map on its fundamental group, together with the fact that <math>F(g \circ f) = F(g) \circ F(f)</math>, explained at [[fundamental group]].
 +
 
 +
==In Computer Science==
 +
In computer science, the term "functor" is short for "function operator", also called a "function object".  It is essentially a class method with no name.  Many modern programming languages support this.  For example, in [[C++]] one can define a function object with the "operator()" notation, that is, a definition of what parentheses mean after an object.
 +
  class C {
 +
  public:
 +
    int operator()(int i, int j) { return k+i*j; }
 +
    int k;
 +
    .....
 +
  };
 +
 
 +
  .....
 +
  C MyObject;
 +
  MyObject.k = 3;
 +
  int r = MyObject(4,5);
 +
  .....
 +
 
 +
We have effectively defined a nameless method for class C.  Instead of making a named invocation like "MyObject.func(4,5)", we just write "MyObject(4,5)".
  
 
[[Category:Mathematics]]
 
[[Category:Mathematics]]
 +
[[Category:Computer Science]]

Revision as of 19:23, October 1, 2009

The term functor has two distinct meanings.

In Pure Mathematics

In category theory, a functor is a map between categories satisfying certain relations. Functors, in a sense, provide for categories what group homomorphisms do for groups. To be precise, a function <math>F : \mathcal C \to \mathcal D</math> between two categories associates to each object <math>X \in \textrm{Ob } \mathcal C</math> an object <math>F(X) \in \textrm{Ob } \mathcal D</math>, and to each morphism <math>f \in \mathcal C(X,Y)</math> a morphism <math>F(f) \in \mathcal D(FX,FY)</math> such that:

<math>F(\textrm{id}_X) = id_{F(X)}\,</math>
<math>F(g \circ f) = F(g) \circ F(f)</math>.

Functors are the fundamental objects used to relate structures between different categories.

Examples

Algebraic topology was the first field in which the usefulness of the notion of a functor was recognized. A basic example is the fundamental group functor <math>\pi_1 : \textbf{Top}* \to \textbf{Grp}</math>. The action on objects is defined by sending a topological space to its fundamental group <math>\pi_1(X)</math>. Recall that a map between two topological spaces <math>f : X \to Y</math> induces a map <math>f_* : \pi_1(X) \to \pi(Y)</math> by <math>f_*([\gamma]) = [f \circ \gamma]</math>. Set <math>\pi_1(f) = f_*\,</math> so defined. The functoriality of <math>\pi_1</math> boils down to the fact that <math>F(\textrm{id}_X) = \textrm{id}_{\pi_1(X)}</math>, that is, the identity map on a topological space induces the identity map on its fundamental group, together with the fact that <math>F(g \circ f) = F(g) \circ F(f)</math>, explained at fundamental group.

In Computer Science

In computer science, the term "functor" is short for "function operator", also called a "function object". It is essentially a class method with no name. Many modern programming languages support this. For example, in C++ one can define a function object with the "operator()" notation, that is, a definition of what parentheses mean after an object.

 class C {
 public:
    int operator()(int i, int j) { return k+i*j; }
    int k;
    .....
  };
  
  .....
  C MyObject;
  MyObject.k = 3;
  int r = MyObject(4,5);
  .....

We have effectively defined a nameless method for class C. Instead of making a named invocation like "MyObject.func(4,5)", we just write "MyObject(4,5)".