code: def main_integrate(expr, facets, hp_params, max_degree=None):
      """Function to translate the problem of integrating univariate/bivariate
      polynomials over a 2-Polytope to integrating over its boundary facets.
      This is done using Generalized Stokes's Theorem and Euler's Theorem.
  
      Parameters
      ==========
  
      expr :
          The input polynomial.
      facets :
          Facets(Line Segments) of the 2-Polytope.
      hp_params :
          Hyperplane Parameters of the facets.
      max_degree : optional
          The maximum degree of any monomial of the input polynomial.
  
      >>> from sympy.abc import x, y
      >>> from sympy.integrals.intpoly import main_integrate,\
      hyperplane_parameters
      >>> from sympy import Point, Polygon
      >>> triangle = Polygon(Point(0, 3), Point(5, 3), Point(1, 1))
      >>> facets = triangle.sides
      >>> hp_params = hyperplane_parameters(triangle)
      >>> main_integrate(x**2 + y**2, facets, hp_params)
      325/6
      """
      dims = (x, y)
      dim_length = len(dims)
      result = {}
  
      if max_degree:
          grad_terms = [[0, 0, 0, 0]] + gradient_terms(max_degree)
  
          for facet_count, hp in enumerate(hp_params):
              a, b = hp[0], hp[1]
              x0 = facets[facet_count].points[0]
  
              for i, monom in enumerate(grad_terms):
                  #  Every monomial is a tuple :
                  #  (term, x_degree, y_degree, value over boundary)
                  m, x_d, y_d, _ = monom
                  value = result.get(m, None)
                  degree = S.Zero
                  if b.is_zero:
                      value_over_boundary = S.Zero
                  else:
                      degree = x_d + y_d
                      value_over_boundary = (
                          integration_reduction_dynamic(
                              facets,
                              facet_count,
                              a,
                              b,
                              m,
                              degree,
                              dims,
                              x_d,
                              y_d,
                              max_degree,
                              x0,
                              grad_terms,
                              i,
                          )
                      )
                  monom[3] = value_over_boundary
                  if value is not None:
                      result[m] += (
                          value_over_boundary
                          * (b / norm(a))
                          / (dim_length + degree)
                      )
                  else:
                      result[m] = (
                          value_over_boundary
                          * (b / norm(a))
                          / (dim_length + degree)
                      )
          return result
      else:
          if not isinstance(expr, list):
              polynomials = decompose(expr)
              return _polynomial_integrate(
                  polynomials, facets, hp_params
              )
          else:
              return {
                  e: _polynomial_integrate(
                      decompose(e), facets, hp_params
                  )
                  for e in expr
              }
  
imports: from functools import cmp_to_key
  from sympy.abc import x, y, z
  from sympy.core import S, diff, Expr, Symbol
  from sympy.core.sympify import _sympify
  from sympy.geometry import Segment2D, Polygon, Point, Point2D
  from sympy.polys.polytools import LC, gcd_list, degree_list, Poly
  from sympy.simplify.simplify import nsimplify
label_desc: Use image node_id 5 for calling a global function with example usage: main_integrate(expr, facets, hp_params, max_degree) and returns: result, _polynomial_integrate, unknown