code: def truncated_moment(op, rv, *inputs):
      *rv_inputs, lower, upper, rng = inputs
  
      # recreate untruncated rv and respective moment
      untruncated_rv = op.base_rv_op.make_node(
          rng, *rv_inputs
      ).default_output()
      untruncated_moment = moment(untruncated_rv)
  
      fallback_moment = pt.switch(
          pt.and_(
              pt.bitwise_not(pt.isinf(lower)),
              pt.bitwise_not(pt.isinf(upper)),
          ),
          (upper - lower) / 2,  # lower and upper are finite
          pt.switch(
              pt.isinf(upper),
              lower + 1,  # only lower is finite
              upper - 1,  # only upper is finite
          ),
      )
  
      return pt.switch(
          pt.and_(
              pt.ge(untruncated_moment, lower),
              pt.le(untruncated_moment, upper),
          ),
          untruncated_moment,  # untruncated moment is between lower and upper
          fallback_moment,
      )
  
imports: from functools import singledispatch
  import numpy
  import pytensor
  import pytensor.tensor
  from pytensor import scan
  from pytensor.graph import Op
  from pytensor.graph.basic import Node
  from pytensor.raise_op import CheckAndRaise
  from pytensor.scan import until
  from pytensor.tensor import TensorConstant, TensorVariable
  from pytensor.tensor.random.basic import NormalRV
  from pytensor.tensor.random.op import RandomVariable
  from pymc.distributions.continuous import TruncatedNormal, bounded_cont_transform
  from pymc.distributions.dist_math import check_parameters
  from pymc.distributions.distribution import Distribution, SymbolicRandomVariable, _moment, moment
  from pymc.distributions.shape_utils import _change_dist_size, change_dist_size, to_tuple
  from pymc.distributions.transforms import _default_transform
  from pymc.exceptions import TruncationError
  from pymc.logprob.abstract import _logcdf, _logprob
  from pymc.logprob.basic import icdf, logcdf
  from pymc.math import logdiffexp
  from pymc.util import check_dist_not_registered
label_desc: Use image node_id 3 for calling a global function with example usage: truncated_moment(op, rv) and returns: pt