code: def cholesky_ldotlt(fgraph, node):
      """
      rewrite cholesky(dot(L, L.T), lower=True) = L, where L is lower triangular,
      or cholesky(dot(U.T, U), upper=True) = U where U is upper triangular.
  
      Also works with matmul.
  
      This utilizes a boolean `lower_triangular` or `upper_triangular` tag on matrices.
      """
      if not isinstance(node.op.core_op, Cholesky):
          return
  
      A = node.inputs[0]
      if not (
          A.owner is not None
          and (
              (
                  isinstance(A.owner.op, (Dot, Dot22))
                  # This rewrite only applies to matrix Dot
                  and A.owner.inputs[0].type.ndim == 2
              )
              or (A.owner.op == _matrix_matrix_matmul)
          )
      ):
          return
  
      l, r = A.owner.inputs
  
      # cholesky(dot(L,L.T)) case
      if (
          getattr(l.tag, "lower_triangular", False)
          and is_matrix_transpose(r)
          and r.owner.inputs[0] == l
      ):
          if node.op.core_op.lower:
              return [l]
          return [r]
  
      # cholesky(dot(U.T,U)) case
      if (
          getattr(r.tag, "upper_triangular", False)
          and is_matrix_transpose(l)
          and l.owner.inputs[0] == r
      ):
          if node.op.core_op.lower:
              return [l]
          return [r]
  
imports: import logging
  from typing import cast
  from pytensor.graph.rewriting.basic import copy_stack_trace, node_rewriter
  from pytensor.tensor.basic import TensorVariable, diagonal, swapaxes
  from pytensor.tensor.blas import Dot22
  from pytensor.tensor.blockwise import Blockwise
  from pytensor.tensor.elemwise import DimShuffle
  from pytensor.tensor.math import Dot, Prod, _matrix_matrix_matmul, log, prod
  from pytensor.tensor.nlinalg import MatrixInverse, det
  from pytensor.tensor.rewriting.basic import register_canonicalize, register_specialize, register_stabilize
  from pytensor.tensor.slinalg import Cholesky, Solve, SolveBase, cholesky, solve, solve_triangular
label_desc: Use image node_id 9 for calling a global function with example usage: cholesky_ldotlt(fgraph, node) and returns: list, list, list, list