text: Title: lowering error during jitting a sympy expression
  Body: ## Reporting a bug
  
  <!--
  
  Before submitting a bug report please ensure that you can check off these boxes:
  
  -->
  
  - [x] I have tried using the latest released version of Numba (most recent is
   visible in the change log (https://github.com/numba/numba/blob/main/CHANGE_LOG).
  - [x] I have included a self contained code sample to reproduce the problem.
    i.e. it's possible to run as 'python bug.py'.
  
  The numba version I used is 0.57.1 and the sympy is 1.12 .
  
  
  In the following code I derive derivative expressions using sympy and wrap it using numba.
  
  
  ```python
  import numpy as np
  from numba import jit, njit, float64
  from sympy import *
  
  els = symbols('p f g h k l')
  p, f, g, h, k, l = els
  mu = symbols('mu')
  
  w = 1 + f * cos(l) + g * sin(l)
  c = 1 + h ** 2 + k ** 2
  z = h * sin(l) - k * cos(l)
  B = sqrt(p / mu) * Matrix([
      [0, 2 * p / w, 0],
      [sin(l), cos(l) + (f + cos(l)) / w, -z * g / w],
      [-cos(l), sin(l) + (g + sin(l)) / w, z * f / w],
      [0, 0, c * cos(l) / (2 * w)],
      [0, 0, c * sin(l) / (2 * w)],
      [0, 0, z / w]
  ])
  
  _els = np.array([
      9.99708536e-01, -3.76678695e-03,  
      1.62868327e-02, -7.70205129e-06,
      6.18315849e-07,  7.87870723e+00,
  ])
  _mu = 1
  
  # wrap dB/dp, works fine
  exp1 = lambdify((els, mu), B.diff(p), 'numpy')
  print(njit(exp1)(_els, _mu))
  
  # wrap dB/dh, raise an error
  exp2 = lambdify((els, mu), B.diff(h), 'numpy')
  print(njit(exp2)(_els, _mu))
  ```
  
  For wrapping exp1, it works fine and print the following result
  ```
  [[ 0.00000000e+00  2.95123633e+00  0.00000000e+00]
   [ 4.99920029e-01 -2.63808126e-02  6.15781340e-08]
   [ 1.23633402e-02  9.99799150e-01  1.42416709e-08]
   [ 0.00000000e+00  0.00000000e+00 -6.08207624e-03]
   [ 0.00000000e+00  0.00000000e+00  2.45932868e-01]
   [ 0.00000000e+00  0.00000000e+00 -3.78085384e-06]]
  ```
  
  For exp2, however, it will produce **AssertionError: Failed in nopython mode pipeline (step: native lowering)**. See the following for the full output.
  
  <details>
  
  ```pytb
  ---------------------------------------------------------------------------
  AssertionError                            Traceback (most recent call last)
  Cell In[24], line 2
        1 exp2 = lambdify((els, mu), B.diff(h), 'numpy')
  ----> 2 print(njit(exp2)(_els, _mu))
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:487](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:487), in _DispatcherBase._compile_for_args(self, *args, **kws)
      485             e.patch_message('\n'.join((str(e).rstrip(), help_msg)))
      486     # ignore the FULL_TRACEBACKS config, this needs reporting!
  --> 487     raise e
      488 finally:
      489     self._types_active_call = []
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:420](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:420), in _DispatcherBase._compile_for_args(self, *args, **kws)
      418 return_val = None
      419 try:
  --> 420     return_val = self.compile(tuple(argtypes))
      421 except errors.ForceLiteralArg as e:
      422     # Received request for compiler re-entry with the list of arguments
      423     # indicated by e.requested_args.
      424     # First, check if any of these args are already Literal-ized
      425     already_lit_pos = [i for i in e.requested_args
      426                        if isinstance(args[i], types.Literal)]
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:965](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:965), in Dispatcher.compile(self, sig)
      963 with ev.trigger_event("numba:compile", data=ev_details):
      964     try:
  --> 965         cres = self._compiler.compile(args, return_type)
      966     except errors.ForceLiteralArg as e:
      967         def folded(args, kws):
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:125](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:125), in _FunctionCompiler.compile(self, args, return_type)
      124 def compile(self, args, return_type):
  --> 125     status, retval = self._compile_cached(args, return_type)
      126     if status:
      127         return retval
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:139](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:139), in _FunctionCompiler._compile_cached(self, args, return_type)
      136     pass
      138 try:
  --> 139     retval = self._compile_core(args, return_type)
      140 except errors.TypingError as e:
      141     self._failed_cache[key] = e
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:152](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/dispatcher.py:152), in _FunctionCompiler._compile_core(self, args, return_type)
      149 flags = self._customize_flags(flags)
      151 impl = self._get_implementation(args, {})
  --> 152 cres = compiler.compile_extra(self.targetdescr.typing_context,
      153                               self.targetdescr.target_context,
      154                               impl,
      155                               args=args, return_type=return_type,
      156                               flags=flags, locals=self.locals,
      157                               pipeline_class=self.pipeline_class)
      158 # Check typing error if object mode is used
      159 if cres.typing_error is not None and not flags.enable_pyobject:
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:762](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:762), in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
      738 """Compiler entry point
      739 
      740 Parameter
     (...)
      758     compiler pipeline
      759 """
      760 pipeline = pipeline_class(typingctx, targetctx, library,
      761                           args, return_type, flags, locals)
  --> 762 return pipeline.compile_extra(func)
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:460](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:460), in CompilerBase.compile_extra(self, func)
      458 self.state.lifted = ()
      459 self.state.lifted_from = None
  --> 460 return self._compile_bytecode()
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:528](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:528), in CompilerBase._compile_bytecode(self)
      524 """
      525 Populate and run pipeline for bytecode input
      526 """
      527 assert self.state.func_ir is None
  --> 528 return self._compile_core()
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:507](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:507), in CompilerBase._compile_core(self)
      505         self.state.status.fail_reason = e
      506         if is_final_pipeline:
  --> 507             raise e
      508 else:
      509     raise CompilerError("All available pipelines exhausted")
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:494](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler.py:494), in CompilerBase._compile_core(self)
      492 res = None
      493 try:
  --> 494     pm.run(self.state)
      495     if self.state.cr is not None:
      496         break
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:368](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:368), in PassManager.run(self, state)
      365 msg = "Failed in %s mode pipeline (step: %s)" % \
      366     (self.pipeline_name, pass_desc)
      367 patched_exception = self._patch_error(msg, e)
  --> 368 raise patched_exception
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:356](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:356), in PassManager.run(self, state)
      354 pass_inst = _pass_registry.get(pss).pass_inst
      355 if isinstance(pass_inst, CompilerPass):
  --> 356     self._runPass(idx, pass_inst, state)
      357 else:
      358     raise BaseException("Legacy pass in use")
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_lock.py:35](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_lock.py:35), in _CompilerLock.__call__.._acquire_compile_lock(*args, **kwargs)
       32 @functools.wraps(func)
       33 def _acquire_compile_lock(*args, **kwargs):
       34     with self:
  ---> 35         return func(*args, **kwargs)
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:311](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:311), in PassManager._runPass(self, index, pss, internal_state)
      309     mutated |= check(pss.run_initialization, internal_state)
      310 with SimpleTimer() as pass_time:
  --> 311     mutated |= check(pss.run_pass, internal_state)
      312 with SimpleTimer() as finalize_time:
      313     mutated |= check(pss.run_finalizer, internal_state)
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:273](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/compiler_machinery.py:273), in PassManager._runPass..check(func, compiler_state)
      272 def check(func, compiler_state):
  --> 273     mangled = func(compiler_state)
      274     if mangled not in (True, False):
      275         msg = ("CompilerPass implementations should return True/False. "
      276                "CompilerPass with name '%s' did not.")
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/typed_passes.py:466](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/typed_passes.py:466), in BaseNativeLowering.run_pass(self, state)
      463 with targetctx.push_code_library(library):
      464     lower = self.lowering_class(targetctx, library, fndesc, interp,
      465                                 metadata=metadata)
  --> 466     lower.lower()
      467     if not flags.no_cpython_wrapper:
      468         lower.create_cpython_wrapper(flags.release_gil)
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:187](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:187), in BaseLower.lower(self)
      185 if self.generator_info is None:
      186     self.genlower = None
  --> 187     self.lower_normal_function(self.fndesc)
      188 else:
      189     self.genlower = self.GeneratorLower(self)
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:241](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:241), in BaseLower.lower_normal_function(self, fndesc)
      239 # Init argument values
      240 self.extract_function_arguments()
  --> 241 entry_block_tail = self.lower_function_body()
      243 # Close tail of entry block, do not emit debug metadata else the
      244 # unconditional jump gets associated with the metadata from the function
      245 # body end.
      246 with debuginfo.suspend_emission(self.builder):
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:271](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:271), in BaseLower.lower_function_body(self)
      269     self.builder.position_at_end(bb)
      270     self.debug_print(f"# lower block: {offset}")
  --> 271     self.lower_block(block)
      272 self.post_lower()
      273 return entry_block_tail
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:285](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:285), in BaseLower.lower_block(self, block)
      282     defaulterrcls = partial(LoweringError, loc=self.loc)
      283     with new_error_context('lowering "{inst}" at {loc}', inst=inst,
      284                            loc=self.loc, errcls_=defaulterrcls):
  --> 285         self.lower_inst(inst)
      286 self.post_block(block)
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:463](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:463), in Lower.lower_inst(self, inst)
      461 if isinstance(inst, ir.Assign):
      462     ty = self.typeof(inst.target.name)
  --> 463     val = self.lower_assign(ty, inst)
      464     argidx = None
      465     # If this is a store from an arg, like x = arg.x then tell debuginfo
      466     # that this is the arg
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:675](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:675), in Lower.lower_assign(self, ty, inst)
      672     return res
      674 elif isinstance(value, ir.Expr):
  --> 675     return self.lower_expr(ty, value)
      677 elif isinstance(value, ir.Var):
      678     val = self.loadvar(value.name)
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:1371](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:1371), in Lower.lower_expr(self, resty, expr)
     1369         return tup
     1370     else:
  -> 1371         castvals = [self.context.cast(self.builder, val, fromty,
     1372                                       resty.dtype)
     1373                     for val, fromty in zip(itemvals, itemtys)]
     1374         return self.context.build_list(self.builder, resty, castvals)
     1376 elif expr.op == "build_set":
     1377     # Insert in reverse order, as Python does
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:1371](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/lowering.py:1371), in (.0)
     1369         return tup
     1370     else:
  -> 1371         castvals = [self.context.cast(self.builder, val, fromty,
     1372                                       resty.dtype)
     1373                     for val, fromty in zip(itemvals, itemtys)]
     1374         return self.context.build_list(self.builder, resty, castvals)
     1376 elif expr.op == "build_set":
     1377     # Insert in reverse order, as Python does
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/base.py:699](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/core/base.py:699), in BaseContext.cast(self, builder, val, fromty, toty)
      697 try:
      698     impl = self._casts.find((fromty, toty))
  --> 699     return impl(self, builder, fromty, toty, val)
      700 except errors.NumbaNotImplementedError:
      701     raise errors.NumbaNotImplementedError(
      702         "Cannot cast %s to %s: %s" % (fromty, toty, val))
  
  File [~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/cpython/listobj.py:1131](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225365727665725f584832227d.vscode-resource.vscode-cdn.net/data/wtgao/projects/gtoc/low_thrust_traj_opt/~/miniconda3/envs/traj/lib/python3.9/site-packages/numba/cpython/listobj.py:1131), in list_to_list(context, builder, fromty, toty, val)
     1128 @lower_cast(types.List, types.List)
     1129 def list_to_list(context, builder, fromty, toty, val):
     1130     # Casting from non-reflected to reflected
  -> 1131     assert fromty.dtype == toty.dtype
     1132     return val
  
  AssertionError: Failed in nopython mode pipeline (step: native lowering)
  ```
  
  </details>
  