Convention for numbering of carbons
Your initial example showing derivatives of glucose and fructose might be misleading since the nomenclature of natural product parent compounds does not necessarily follow the usual nomenclature rules of general organic chemistry.

In particular, 


  P-102.2.2 Numbering parent structures
  
  The carbon atoms of a monosaccharide are numbered consecutively in such a
  way that:
  
  (1) a (potential) aldehyde group receives the locant 1 (even if a more senior
  characteristic group is present);
  
  (…)


(This rule is probably easier to understand if you draw the monosaccharides in their acyclic form.)

Generally, however, nomenclature of organic chemistry has different rules for the numbering. The most important simplified criteria for the numbering are:


lower locants for the group that is expressed as suffix
lower locants for multiple bonds
lower locants for prefixes
lower locants for substituents cited first as a prefix in the name


The corresponding actual wording in the current version of Nomenclature of Organic Chemistry – IUPAC Recommendations and Preferred Names 2013 (Blue Book) reads as follows:


  P-14.4 NUMBERING
  
  When several structural features appear in cyclic and acyclic compounds, low locants are assigned to them in the following decreasing order of seniority:
  
  (…)
  
  (c) principal characteristic groups and free valences (suffixes);
  
  (…)
  
  (e) saturation/unsaturation:
  
  (i) low locants are given to hydro/dehydro prefixes (…) and ‘ene’ and ‘yne’ endings;
  
  (ii) low locants are given first to multiple bonds as a set and then to double bonds (…);
  
  (f) detachable alphabetized prefixes, all considered together in a series of increasing numerical order;
  
  (g) lowest locants for the substituent cited first as a prefix in the name;
  
  (…)


Therefore, the numbering in your own example corresponds to the name 3-phosphinopropanoic acid since the acid group is the principal characteristic group of this compound.