nodes: 0, module; 1, function_definition; 2, function_name:addDiscreteOutcomeConstantMean; 3, parameters; 4, block; 5, identifier:distribution; 6, identifier:x; 7, identifier:p; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:sort; 15, False; 16, string; 17, assignment; 18, assignment; 19, identifier:sort; 20, block; 21, parenthesized_expression; 22, string_content:Adds a discrete outcome of x with probability p to an existing distribution,
      holding constant the relative probabilities of other outcomes and overall mean.
  
      Parameters
      ----------
      distribution : [np.array]
          Two element list containing a list of probabilities and a list of outcomes.
      x : float
          The new value to be added to the distribution.
      p : float
          The probability of the discrete outcome x occuring.
      sort: bool
          Whether or not to sort X before returning it
  
      Returns
      -------
      X : np.array
          Discrete points for discrete probability mass function.
      pmf : np.array
          Probability associated with each point in X.
  
      Written by Matthew N. White
      Latest update: 08 December 2015 by David Low; 23, identifier:X; 24, call; 25, identifier:pmf; 26, call; 27, expression_statement; 28, expression_statement; 29, expression_statement; 30, list; 31, attribute; 32, argument_list; 33, attribute; 34, argument_list; 35, assignment; 36, assignment; 37, assignment; 38, identifier:pmf; 39, identifier:X; 40, identifier:np; 41, identifier:append; 42, identifier:x; 43, binary_operator:distribution[1]*(1-p*x)/(1-p); 44, identifier:np; 45, identifier:append; 46, identifier:p; 47, binary_operator:distribution[0]*(1-p); 48, identifier:indices; 49, call; 50, identifier:X; 51, subscript; 52, identifier:pmf; 53, subscript; 54, binary_operator:distribution[1]*(1-p*x); 55, parenthesized_expression; 56, subscript; 57, parenthesized_expression; 58, attribute; 59, argument_list; 60, identifier:X; 61, identifier:indices; 62, identifier:pmf; 63, identifier:indices; 64, subscript; 65, parenthesized_expression; 66, binary_operator:1-p; 67, identifier:distribution; 68, integer:0; 69, binary_operator:1-p; 70, identifier:np; 71, identifier:argsort; 72, identifier:X; 73, identifier:distribution; 74, integer:1; 75, binary_operator:1-p*x; 76, integer:1; 77, identifier:p; 78, integer:1; 79, identifier:p; 80, integer:1; 81, binary_operator:p*x; 82, identifier:p; 83, identifier:x
code: def addDiscreteOutcomeConstantMean(distribution, x, p, sort = False):
      '''
      Adds a discrete outcome of x with probability p to an existing distribution,
      holding constant the relative probabilities of other outcomes and overall mean.
  
      Parameters
      ----------
      distribution : [np.array]
          Two element list containing a list of probabilities and a list of outcomes.
      x : float
          The new value to be added to the distribution.
      p : float
          The probability of the discrete outcome x occuring.
      sort: bool
          Whether or not to sort X before returning it
  
      Returns
      -------
      X : np.array
          Discrete points for discrete probability mass function.
      pmf : np.array
          Probability associated with each point in X.
  
      Written by Matthew N. White
      Latest update: 08 December 2015 by David Low
      '''
      X   = np.append(x,distribution[1]*(1-p*x)/(1-p))
      pmf = np.append(p,distribution[0]*(1-p))
  
      if sort:
          indices = np.argsort(X)
          X       = X[indices]
          pmf     = pmf[indices]
  
      return([pmf,X])