nodes: 0, module; 1, function_definition; 2, function_name:orth_ttr; 3, parameters; 4, block; 5, identifier:order; 6, identifier:dist; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, dictionary_splat_pattern; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, if_statement; 17, expression_statement; 18, if_statement; 19, return_statement; 20, identifier:normed; 21, False; 22, identifier:sort; 23, string:"GR"; 24, identifier:retall; 25, False; 26, identifier:cross_truncation; 27, float:1.; 28, identifier:kws; 29, comment:"""
      Create orthogonal polynomial expansion from three terms recursion formula.
  
      Args:
          order (int):
              Order of polynomial expansion.
          dist (Dist):
              Distribution space where polynomials are orthogonal If dist.ttr
              exists, it will be used. Must be stochastically independent.
          normed (bool):
              If True orthonormal polynomials will be used.
          sort (str):
              Polynomial sorting. Same as in basis.
          retall (bool):
              If true return numerical stabilized norms as well. Roughly the same
              as ``cp.E(orth**2, dist)``.
          cross_truncation (float):
              Use hyperbolic cross truncation scheme to reduce the number of
              terms in expansion. only include terms where the exponents ``K``
              satisfied the equation
              ``order >= sum(K**(1/cross_truncation))**cross_truncation``.
  
      Returns:
          (Poly, numpy.ndarray):
              Orthogonal polynomial expansion and norms of the orthogonal
              expansion on the form ``E(orth**2, dist)``. Calculated using
              recurrence coefficients for stability.
  
      Examples:
          >>> Z = chaospy.Normal()
          >>> print(chaospy.around(chaospy.orth_ttr(4, Z), 4))
          [1.0, q0, q0^2-1.0, q0^3-3.0q0, q0^4-6.0q0^2+3.0]
      """; 30, assignment; 31, identifier:normed; 32, block; 33, assignment; 34, comparison_operator:dim > 1; 35, block; 36, else_clause; 37, assignment; 38, identifier:retall; 39, block; 40, identifier:polynomials; 41, pattern_list; 42, call; 43, for_statement; 44, expression_statement; 45, identifier:dim; 46, call; 47, identifier:dim; 48, integer:1; 49, expression_statement; 50, expression_statement; 51, expression_statement; 52, for_statement; 53, if_statement; 54, block; 55, identifier:polynomials; 56, call; 57, return_statement; 58, identifier:polynomials; 59, identifier:norms; 60, identifier:_; 61, identifier:_; 62, attribute; 63, argument_list; 64, pattern_list; 65, call; 66, block; 67, assignment; 68, identifier:len; 69, argument_list; 70, assignment; 71, assignment; 72, assignment; 73, identifier:index; 74, identifier:indices; 75, block; 76, identifier:retall; 77, block; 78, expression_statement; 79, expression_statement; 80, attribute; 81, argument_list; 82, expression_list; 83, attribute; 84, identifier:generate_stieltjes; 85, keyword_argument; 86, keyword_argument; 87, keyword_argument; 88, dictionary_splat; 89, identifier:idx; 90, identifier:poly; 91, identifier:enumerate; 92, argument_list; 93, expression_statement; 94, identifier:norms; 95, binary_operator:norms**0; 96, identifier:dist; 97, identifier:mv_polynomials; 98, list; 99, identifier:mv_norms; 100, list; 101, identifier:indices; 102, call; 103, expression_statement; 104, for_statement; 105, expression_statement; 106, for_statement; 107, assignment; 108, assignment; 109, attribute; 110, identifier:flatten; 111, call; 112, identifier:polynomials; 113, call; 114, identifier:chaospy; 115, identifier:quad; 116, identifier:dist; 117, identifier:dist; 118, identifier:order; 119, call; 120, identifier:retall; 121, True; 122, identifier:kws; 123, identifier:polynomials; 124, assignment; 125, identifier:norms; 126, integer:0; 127, attribute; 128, argument_list; 129, assignment; 130, identifier:idx; 131, call; 132, block; 133, call; 134, identifier:index; 135, identifier:indices; 136, block; 137, identifier:mv_norms; 138, subscript; 139, identifier:mv_polynomials; 140, identifier:polynomials; 141, identifier:chaospy; 142, identifier:poly; 143, attribute; 144, argument_list; 145, attribute; 146, argument_list; 147, attribute; 148, argument_list; 149, subscript; 150, binary_operator:poly / numpy.sqrt(norms[:, idx]); 151, attribute; 152, identifier:bindex; 153, keyword_argument; 154, keyword_argument; 155, keyword_argument; 156, keyword_argument; 157, keyword_argument; 158, identifier:poly; 159, subscript; 160, identifier:range; 161, argument_list; 162, expression_statement; 163, attribute; 164, argument_list; 165, expression_statement; 166, identifier:norms; 167, integer:0; 168, attribute; 169, identifier:Poly; 170, identifier:mv_polynomials; 171, identifier:numpy; 172, identifier:array; 173, identifier:mv_norms; 174, identifier:numpy; 175, identifier:max; 176, identifier:order; 177, identifier:polynomials; 178, identifier:idx; 179, identifier:poly; 180, call; 181, identifier:chaospy; 182, identifier:bertran; 183, identifier:start; 184, integer:0; 185, identifier:stop; 186, identifier:order; 187, identifier:dim; 188, identifier:dim; 189, identifier:sort; 190, identifier:sort; 191, identifier:cross_truncation; 192, identifier:cross_truncation; 193, subscript; 194, integer:0; 195, integer:1; 196, identifier:dim; 197, assignment; 198, identifier:mv_polynomials; 199, identifier:append; 200, identifier:poly; 201, call; 202, identifier:chaospy; 203, identifier:poly; 204, attribute; 205, argument_list; 206, identifier:polynomials; 207, subscript; 208, identifier:poly; 209, binary_operator:poly * polynomials[index[idx]][idx]; 210, attribute; 211, argument_list; 212, identifier:numpy; 213, identifier:sqrt; 214, subscript; 215, identifier:index; 216, integer:0; 217, identifier:poly; 218, subscript; 219, identifier:mv_norms; 220, identifier:append; 221, call; 222, identifier:norms; 223, slice; 224, identifier:idx; 225, subscript; 226, identifier:idx; 227, attribute; 228, argument_list; 229, identifier:polynomials; 230, subscript; 231, identifier:numpy; 232, identifier:prod; 233, list_comprehension; 234, identifier:index; 235, identifier:idx; 236, subscript; 237, for_in_clause; 238, identifier:norms; 239, identifier:idx; 240, subscript; 241, identifier:idx; 242, call; 243, identifier:index; 244, identifier:idx; 245, identifier:range; 246, argument_list; 247, identifier:dim
code: def orth_ttr(
          order, dist, normed=False, sort="GR", retall=False,
          cross_truncation=1., **kws):
      """
      Create orthogonal polynomial expansion from three terms recursion formula.
  
      Args:
          order (int):
              Order of polynomial expansion.
          dist (Dist):
              Distribution space where polynomials are orthogonal If dist.ttr
              exists, it will be used. Must be stochastically independent.
          normed (bool):
              If True orthonormal polynomials will be used.
          sort (str):
              Polynomial sorting. Same as in basis.
          retall (bool):
              If true return numerical stabilized norms as well. Roughly the same
              as ``cp.E(orth**2, dist)``.
          cross_truncation (float):
              Use hyperbolic cross truncation scheme to reduce the number of
              terms in expansion. only include terms where the exponents ``K``
              satisfied the equation
              ``order >= sum(K**(1/cross_truncation))**cross_truncation``.
  
      Returns:
          (Poly, numpy.ndarray):
              Orthogonal polynomial expansion and norms of the orthogonal
              expansion on the form ``E(orth**2, dist)``. Calculated using
              recurrence coefficients for stability.
  
      Examples:
          >>> Z = chaospy.Normal()
          >>> print(chaospy.around(chaospy.orth_ttr(4, Z), 4))
          [1.0, q0, q0^2-1.0, q0^3-3.0q0, q0^4-6.0q0^2+3.0]
      """
      polynomials, norms, _, _ = chaospy.quad.generate_stieltjes(
          dist=dist, order=numpy.max(order), retall=True, **kws)
  
      if normed:
          for idx, poly in enumerate(polynomials):
              polynomials[idx] = poly / numpy.sqrt(norms[:, idx])
          norms = norms**0
  
      dim = len(dist)
      if dim > 1:
          mv_polynomials = []
          mv_norms = []
          indices = chaospy.bertran.bindex(
              start=0, stop=order, dim=dim, sort=sort,
              cross_truncation=cross_truncation,
          )
  
          for index in indices:
              poly = polynomials[index[0]][0]
              for idx in range(1, dim):
                  poly = poly * polynomials[index[idx]][idx]
              mv_polynomials.append(poly)
  
          if retall:
              for index in indices:
                  mv_norms.append(
                      numpy.prod([norms[idx, index[idx]] for idx in range(dim)]))
  
      else:
          mv_norms = norms[0]
          mv_polynomials = polynomials
  
      polynomials = chaospy.poly.flatten(chaospy.poly.Poly(mv_polynomials))
  
      if retall:
          return polynomials, numpy.array(mv_norms)
      return polynomials