Repository: sympy/sympy

Issue:
Configurable symbol for `Adjoint`
Now, the LaTeX-printer (and probably others) print `Adjoint` using a dagger. This is common in quantum physics, but it would be nice to allow using H or * as well, see https://en.wikipedia.org/wiki/Conjugate_transpose

Discussion:

Patch:
diff --git a/sympy/functions/combinatorial/numbers.py b/sympy/functions/combinatorial/numbers.py
index a70d7ac739..e8da3b719e 100644
--- a/sympy/functions/combinatorial/numbers.py
+++ b/sympy/functions/combinatorial/numbers.py
@@ -88,14 +88,14 @@ class carmichael(Function):
     Examples
     ========
 
-    >>> from sympy.ntheory.factor_ import find_first_n_carmichaels, find_carmichael_numbers_in_range
-    >>> find_first_n_carmichaels(5)
+    >>> from sympy import carmichael
+    >>> carmichael.find_first_n_carmichaels(5)
     [561, 1105, 1729, 2465, 2821]
-    >>> find_carmichael_numbers_in_range(0, 562)
+    >>> carmichael.find_carmichael_numbers_in_range(0, 562)
     [561]
-    >>> find_carmichael_numbers_in_range(0,1000)
+    >>> carmichael.find_carmichael_numbers_in_range(0,1000)
     [561]
-    >>> find_carmichael_numbers_in_range(0,2000)
+    >>> carmichael.find_carmichael_numbers_in_range(0,2000)
     [561, 1105, 1729]
 
     References
diff --git a/sympy/ntheory/factor_.py b/sympy/ntheory/factor_.py
index fc57c5f53c..a05caa32d2 100644
--- a/sympy/ntheory/factor_.py
+++ b/sympy/ntheory/factor_.py
@@ -1967,7 +1967,7 @@ def totient(n):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import totient
+    >>> from sympy.ntheory import totient
     >>> totient(1)
     1
     >>> totient(25)
@@ -2011,7 +2011,7 @@ def reduced_totient(n):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import reduced_totient
+    >>> from sympy.ntheory import reduced_totient
     >>> reduced_totient(1)
     1
     >>> reduced_totient(8)
@@ -2079,7 +2079,7 @@ def divisor_sigma(n, k=1):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import divisor_sigma
+    >>> from sympy.ntheory import divisor_sigma
     >>> divisor_sigma(18, 0)
     6
     >>> divisor_sigma(39, 1)
@@ -2233,7 +2233,7 @@ def udivisor_sigma(n, k=1):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import udivisor_sigma
+    >>> from sympy.ntheory.factor_ import udivisor_sigma
     >>> udivisor_sigma(18, 0)
     4
     >>> udivisor_sigma(74, 1)
@@ -2286,7 +2286,7 @@ def primenu(n):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import primenu
+    >>> from sympy.ntheory.factor_ import primenu
     >>> primenu(1)
     0
     >>> primenu(30)
@@ -2335,7 +2335,7 @@ def primeomega(n):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import primeomega
+    >>> from sympy.ntheory.factor_ import primeomega
     >>> primeomega(1)
     0
     >>> primeomega(20)
diff --git a/sympy/ntheory/partitions_.py b/sympy/ntheory/partitions_.py
index ea3019c330..2a64fcd167 100644
--- a/sympy/ntheory/partitions_.py
+++ b/sympy/ntheory/partitions_.py
@@ -264,8 +264,8 @@ def npartitions(n, verbose=False):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import partition
-    >>> partition(25)
+    >>> from sympy.ntheory import npartitions
+    >>> npartitions(25)
     1958
 
     References
diff --git a/sympy/ntheory/residue_ntheory.py b/sympy/ntheory/residue_ntheory.py
index aa43ae8cdc..5a8da52058 100644
--- a/sympy/ntheory/residue_ntheory.py
+++ b/sympy/ntheory/residue_ntheory.py
@@ -1106,7 +1106,7 @@ def legendre_symbol(a, p):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import legendre_symbol
+    >>> from sympy.ntheory import legendre_symbol
     >>> [legendre_symbol(i, 7) for i in range(7)]
     [0, 1, 1, -1, 1, -1, -1]
     >>> sorted(set([i**2 % 7 for i in range(7)]))
@@ -1168,7 +1168,7 @@ def jacobi_symbol(m, n):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import jacobi_symbol, legendre_symbol
+    >>> from sympy.ntheory import jacobi_symbol, legendre_symbol
     >>> from sympy import S
     >>> jacobi_symbol(45, 77)
     -1
@@ -1226,7 +1226,7 @@ def mobius(n):
     Examples
     ========
 
-    >>> from sympy.functions.combinatorial.numbers import mobius
+    >>> from sympy.ntheory import mobius
     >>> mobius(13*7)
     1
     >>> mobius(1)
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index 7b70e294e6..834c57626b 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -167,6 +167,7 @@ class LatexPrinter(Printer):
         "min": None,
         "max": None,
         "diff_operator": "d",
+        "adjoint_style": "dagger",
     }
 
     def __init__(self, settings=None):
@@ -1755,17 +1756,23 @@ def _print_Trace(self, expr):
         return r"\operatorname{tr}\left(%s \right)" % self._print(mat)
 
     def _print_Adjoint(self, expr):
+        style_to_latex = {
+            "dagger"   : r"\dagger",
+            "star"     : r"\ast",
+            "hermitian": r"\mathsf{H}"
+        }
+        adjoint_style = style_to_latex.get(self._settings["adjoint_style"], r"\dagger")
         mat = expr.arg
         from sympy.matrices import MatrixSymbol, BlockMatrix
         if (not isinstance(mat, MatrixSymbol) and
             not isinstance(mat, BlockMatrix) and mat.is_MatrixExpr):
-            return r"\left(%s\right)^{\dagger}" % self._print(mat)
+            return r"\left(%s\right)^{%s}" % (self._print(mat), adjoint_style)
         else:
             s = self.parenthesize(mat, precedence_traditional(expr), True)
             if '^' in s:
-                return r"\left(%s\right)^{\dagger}" % s
+                return r"\left(%s\right)^{%s}" % (s, adjoint_style)
             else:
-                return r"%s^{\dagger}" % s
+                return r"%s^{%s}" % (s, adjoint_style)
 
     def _print_MatMul(self, expr):
         from sympy import MatMul
@@ -3045,6 +3052,9 @@ def latex(expr, **settings):
     diff_operator: string, optional
         String to use for differential operator. Default is ``'d'``, to print in italic
         form. ``'rd'``, ``'td'`` are shortcuts for ``\mathrm{d}`` and ``\text{d}``.
+    adjoint_style: string, optional
+        String to use for the adjoint symbol. Defined options are ``'dagger'``
+        (default),``'star'``, and ``'hermitian'``.
 
     Notes
     =====


Test patch:
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index e8b4c5f757..1000e9b412 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -2115,6 +2115,13 @@ def test_Adjoint():
     Mx = MatrixSymbol('M^x', 2, 2)
     assert latex(Adjoint(Mx)) == r'\left(M^{x}\right)^{\dagger}'
 
+    # adjoint style
+    assert latex(Adjoint(X), adjoint_style="star") == r'X^{\ast}'
+    assert latex(Adjoint(X + Y), adjoint_style="hermitian") == r'\left(X + Y\right)^{\mathsf{H}}'
+    assert latex(Adjoint(X) + Adjoint(Y), adjoint_style="dagger") == r'X^{\dagger} + Y^{\dagger}'
+    assert latex(Adjoint(Y)*Adjoint(X)) == r'Y^{\dagger} X^{\dagger}'
+    assert latex(Adjoint(X**2), adjoint_style="star") == r'\left(X^{2}\right)^{\ast}'
+    assert latex(Adjoint(X)**2, adjoint_style="hermitian") == r'\left(X^{\mathsf{H}}\right)^{2}'
 
 def test_Transpose():
     from sympy.matrices import Transpose, MatPow, HadamardPower