code: def entropy(expr, condition=None, **kwargs):
      """
      Calculuates entropy of a probability distribution.
  
      Parameters
      ==========
  
      expression : the random expression whose entropy is to be calculated
      condition : optional, to specify conditions on random expression
      b: base of the logarithm, optional
         By default, it is taken as Euler's number
  
      Returns
      =======
  
      result : Entropy of the expression, a constant
  
      Examples
      ========
  
      >>> from sympy.stats import Normal, Die, entropy
      >>> X = Normal('X', 0, 1)
      >>> entropy(X)
      log(2)/2 + 1/2 + log(pi)/2
  
      >>> D = Die('D', 4)
      >>> entropy(D)
      log(4)
  
      References
      ==========
  
      .. [1] https://en.wikipedia.org/wiki/Entropy_%28information_theory%29
      .. [2] https://www.crmarsh.com/static/pdf/Charles_Marsh_Continuous_Entropy.pdf
      .. [3] https://kconrad.math.uconn.edu/blurbs/analysis/entropypost.pdf
      """
      pdf = density(expr, condition, **kwargs)
      base = kwargs.get("b", exp(1))
      if isinstance(pdf, dict):
          return sum([-prob * log(prob, base) for prob in pdf.values()])
      return expectation(-log(pdf(expr), base))
  
imports: from sympy.sets import FiniteSet
  from sympy.core.numbers import Rational
  from sympy.core.relational import Eq
  from sympy.core.symbol import Dummy
  from sympy.functions.combinatorial.factorials import FallingFactorial
  from sympy.functions.elementary.exponential import exp, log
  from sympy.functions.elementary.miscellaneous import sqrt
  from sympy.functions.elementary.piecewise import piecewise_fold
  from sympy.integrals.integrals import Integral
  from sympy.solvers.solveset import solveset
  from .rv import probability, expectation, density, where, given, pspace, cdf, PSpace, characteristic_function, sample, sample_iter, random_symbols, independent, dependent, sampling_density, moment_generating_function, quantile, is_random, sample_stochastic_process
label_desc: Use image node_id 4 for calling a global function with example usage: entropy(expr, condition) and returns: expectation, sum