Skip to content

Commit a277aca

Browse files
authored
Merge some docstrings from module-components and the api (#303)
This picks off most of the very easy docstrings, include the wrapper functions that just forward to a multivector method. A couple of methods in printer.py got proper `sphinx.ext.napoleon` docstrings, and a few others got docstrings for the first time.
1 parent 9b66077 commit a277aca

File tree

4 files changed

+103
-75
lines changed

4 files changed

+103
-75
lines changed

doc/module-components.rst

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -466,106 +466,60 @@ If we can instantiate multivectors we can use all the multivector class function
466466
Basic Multivector Functions
467467
---------------------------
468468

469-
.. function:: com(A,B)
469+
.. automethod:: galgebra.ga.Ga.com
470470
:noindex:
471471

472-
Calculate commutator of multivectors :math:`A` and :math:`B`. Returns :math:`(AB-BA)/2`.
473-
474-
Additionally, commutator and anti-commutator operators are defined by
475-
476-
.. math::
477-
478-
$\begin{aligned}
479-
\texttt{A >> B} \equiv & {\displaystyle\frac{AB - BA}{2}} \\
480-
\texttt{A << B} \equiv & {\displaystyle\frac{AB + BA}{2}}.
481-
\end{aligned}
482-
483-
.. function:: cross(v1,v2)
472+
.. autofunction:: galgebra.mv.cross
484473
:noindex:
485474

486-
If ``v1`` and ``v2`` are 3-dimensional Euclidean vectors the vector cross product is returned, :math:`v_{1}\times v_{2} = -I{\lp {v_{1}{\wedge}v_{2}} \rp }`.
487-
488-
.. function:: printer.def_prec(gd,op_ord='<>|,^,*')
475+
.. autofunction:: galgebra.printer.def_prec
489476
:noindex:
490477

491-
This is used with the ``GAeval()`` function to evaluate a string representing a multivector expression with a revised operator precedence. ``def_prec()`` redefines the operator precedence for multivectors. ``def_prec()`` must be called in the main program an the argument ``gd`` must be ``globals()``. The argument ``op_ord`` defines the order of operator precedence from high to low with groups of equal precedence separated by commas. the default precedence ``op_ord='<>|,^,\*'`` is that used by
492-
Hestenes (:cite:`Hestenes`,p7,:cite:`Doran`,p38).
493-
494-
.. function:: dual(A,mode='I+')
478+
.. autofunction:: galgebra.mv.dual
495479
:noindex:
496480

497-
Return the dual of the multivector ``A``. The default operation is :math:`AI`. For other modes see member function ``Mv.dual(mode)``
498-
499-
.. function:: even(A)
481+
.. autofunction:: galgebra.mv.even
500482
:noindex:
501483

502-
Return even part of :math:`A`.
503-
504-
.. function:: exp(A,hint='-')
484+
.. autofunction:: galgebra.mv.exp
505485
:noindex:
506486

507-
If :math:`A` is a multivector then ``A.exp(hint)`` is returned. If :math:`A` is a *sympy* expression the *sympy* expression :math:`e^{A}` is returned (see ``sympy.exp(A)`` member function).
508-
509-
.. function:: printer.GAeval(s,pstr=False)
487+
.. autofunction:: galgebra.printer.GAeval
510488
:noindex:
511489

512-
Returns multivector expression for string ``s`` with operator precedence for string ``s`` defined by inputs to function ``def_prec()``. if ``pstr=True`` ``s`` and ``s`` with parenthesis added to enforce operator precedence are printed.
513-
514-
.. function:: grade(A,r=0)
490+
.. autofunction:: galgebra.mv.grade
515491
:noindex:
516492

517-
If :math:`A` is a multivector :math:`{\left < {A} \right >}_{r}` is returned.
518-
519-
.. function:: inv(A)
493+
.. autofunction:: galgebra.mv.inv
520494
:noindex:
521495

522-
If :math:`A` is a multivector and :math:`AA^{{\dagger}}` is a non-zero scalar then :math:`A^{-1} = A^{{\dagger}}/(AA^{{\dagger}})` is returned otherwise an exception is returned.
523-
524-
.. function:: Nga(x,prec=5)
496+
.. autofunction:: galgebra.mv.Nga
525497
:noindex:
526498

527-
If ``x`` is a multivector with coefficients that contain floating point numbers, ``Nga()`` rounds all these numbers to a precision of ``prec`` and returns the rounded multivector.
528-
529-
.. function:: norm(A,hint='-')
499+
.. autofunction:: galgebra.mv.norm
530500
:noindex:
531501

532-
If :math:`A` is a multivector and :math:`AA^{{\dagger}}` is a number (not a scalar function) then :math:`\sqrt{{\left |{AA^{{\dagger}}}\right |}}` is returned. If :math:`AA^{{\dagger}}` is a scalar *sympy* expression, but not a number, and ``hint='-'`` then return :math:`\sqrt{-AA^{{\dagger}}}` otherwise return :math:`\sqrt{AA^{{\dagger}}}`.
533-
534-
.. function:: norm2(A)
502+
.. autofunction:: galgebra.mv.norm2
535503
:noindex:
536504

537-
If :math:`A` is a multivector and :math:`AA^{{\dagger}}` is a scalar return :math:`{\left |{AA^{{\dagger}}}\right |}`.
538-
539-
.. function:: odd(A)
505+
.. autofunction:: galgebra.mv.odd
540506
:noindex:
541507

542-
Return odd part of :math:`A`.
543-
544-
.. function:: proj(B,A)
508+
.. autofunction:: galgebra.mv.proj
545509
:noindex:
546510

547-
Project blade ``A`` on blade ``B`` returning :math:`{\lp {A\rfloor B} \rp }B^{-1}`.
548-
549-
.. function:: ReciprocalFrame(basis,mode='norm')
511+
.. automethod:: galgebra.ga.Ga.ReciprocalFrame(basis,mode='norm')
550512
:noindex:
551513

552-
If ``basis`` is a list/tuple of vectors, ``ReciprocalFrame()`` returns a tuple of reciprocal vectors. If ``mode=norm`` the vectors are normalized. If ``mode`` is anything other than ``norm`` the vectors are unnormalized and the normalization coefficient is added to the end of the tuple. One must divide by this coefficient to normalize the vectors.
553-
554-
.. function:: refl(B,A)
514+
.. autofunction:: galgebra.mv.refl(B,A)
555515
:noindex:
556516

557-
Reflect multivector :math:`A` in blade :math:`B`. If :math:`s` is grade of :math:`B` returns :math:`\sum_{r}(-1)^{s(r+1)}B{\left < {A} \right >}_{r}B^{-1}`.
558-
559-
.. function:: rev(A)
517+
.. autofunction:: galgebra.mv.rev(A)
560518
:noindex:
561519

562-
If :math:`A` is a multivector return :math:`A^{{\dagger}}`.
563-
564-
.. function:: rot(itheta,A,hint='-')
520+
.. autofunction:: galgebra.mv.rot(itheta,A,hint='-')
565521
:noindex:
566522

567-
If ``A`` is a multivector return ``A.rotate_multivector(itheta,hint)`` where ``itheta`` is the bi-vector blade defining the rotation. For the use of ``hint`` see the member function ``Mv.rotate_multivector(self,itheta,hint)``.
568-
569523
.. _makeMVD:
570524

571525
Multivector Derivatives

galgebra/ga.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,18 @@ def dual_mode(mode='I+'):
361361

362362
@staticmethod
363363
def com(A, B):
364+
r"""
365+
Calculate commutator of multivectors :math:`A` and :math:`B`. Returns :math:`(AB-BA)/2`.
366+
367+
Additionally, commutator and anti-commutator operators are defined by
368+
369+
.. math::
370+
371+
\begin{aligned}
372+
\texttt{A >> B} \equiv & {\displaystyle\frac{AB - BA}{2}} \\
373+
\texttt{A << B} \equiv & {\displaystyle\frac{AB + BA}{2}}.
374+
\end{aligned}
375+
"""
364376
return half * (A * B - B * A)
365377

366378
@staticmethod
@@ -1965,6 +1977,14 @@ def connection(self, rbase, key_base, mode, left):
19651977
return C
19661978

19671979
def ReciprocalFrame(self, basis, mode='norm'):
1980+
"""
1981+
If ``basis`` is a list/tuple of vectors, ``ReciprocalFrame()`` returns a tuple of reciprocal vectors.
1982+
1983+
If ``mode=norm`` the vectors are normalized.
1984+
If ``mode`` is anything other than ``norm`` the vectors are unnormalized
1985+
and the normalization coefficient is added to the end of the tuple.
1986+
One must divide by this coefficient to normalize the vectors.
1987+
"""
19681988
dim = len(basis)
19691989

19701990
indexes = tuple(range(dim))

galgebra/mv.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,13 @@ def _eval_derivative_n_times(self, x, n):
18281828

18291829

18301830
def Nga(x, prec=5):
1831+
"""
1832+
Like :func:`sympy.N`, but also works on multivectors
1833+
1834+
For multivectors with coefficients that contain floating point numbers, this
1835+
rounds all these numbers to a precision of ``prec`` and returns the rounded
1836+
multivector.
1837+
"""
18311838
if isinstance(x, Mv):
18321839
return Mv(Nsympy(x.obj, prec), ga=x.Ga)
18331840
else:
@@ -1905,94 +1912,123 @@ def correlation(u, v, dec=3): # Compute the correlation coefficient of vectors
19051912

19061913

19071914
def cross(v1, v2):
1915+
r"""
1916+
If ``v1`` and ``v2`` are 3-dimensional Euclidean vectors, compute the vector
1917+
cross product :math:`v_{1}\times v_{2} = -I{\lp {v_{1}{\wedge}v_{2}} \rp }`.
1918+
"""
19081919
if v1.is_vector() and v2.is_vector() and v1.Ga == v2.Ga and v1.Ga.n == 3:
19091920
return -v1.Ga.I() * (v1 ^ v2)
19101921
else:
19111922
raise ValueError(str(v1) + ' and ' + str(v2) + ' not compatible for cross product.')
19121923

19131924

19141925
def dual(A):
1926+
""" Equivalent to :meth:`Mv.dual` """
19151927
if isinstance(A, Mv):
19161928
return A.dual()
19171929
else:
19181930
raise ValueError('A not a multivector in dual(A)')
19191931

19201932

19211933
def even(A):
1934+
""" Equivalent to :meth:`Mv.even` """
19221935
if not isinstance(A, Mv):
19231936
raise ValueError('A = ' + str(A) + ' not a multivector in even(A).')
19241937
return A.even()
19251938

19261939

19271940
def odd(A):
1941+
""" Equivalent to :meth:`Mv.odd` """
19281942
if not isinstance(A, Mv):
19291943
raise ValueError('A = ' + str(A) + ' not a multivector in even(A).')
19301944
return A.odd()
19311945

19321946

19331947
def exp(A, hint='-'):
1948+
"""
1949+
If ``A`` is a multivector then ``A.exp(hint)`` is returned.
1950+
If ``A`` is a *sympy* expression the *sympy* expression :math:`e^{A}` is returned (see :func:`sympy.exp`).
1951+
"""
19341952
if isinstance(A, Mv):
19351953
return A.exp(hint)
19361954
else:
19371955
return sympy_exp(A)
19381956

19391957

19401958
def grade(A, r=0):
1959+
""" Equivalent to :meth:`Mv.grade` """
19411960
if isinstance(A, Mv):
19421961
return A.grade(r)
19431962
else:
19441963
raise ValueError('A not a multivector in grade(A, r)')
19451964

19461965

19471966
def inv(A):
1967+
""" Equivalent to :meth:`Mv.inv` """
19481968
if not isinstance(A, Mv):
19491969
raise ValueError('A = ' + str(A) + ' not a multivector in inv(A).')
19501970
return A.inv()
19511971

19521972

19531973
def norm(A, hint='+'):
1974+
""" Equivalent to :meth:`Mv.norm` """
19541975
if isinstance(A, Mv):
19551976
return A.norm(hint=hint)
19561977
else:
19571978
raise ValueError('A not a multivector in norm(A)')
19581979

19591980

19601981
def norm2(A):
1982+
""" Equivalent to :meth:`Mv.norm2` """
19611983
if isinstance(A, Mv):
19621984
return A.norm2()
19631985
else:
19641986
raise ValueError('A not a multivector in norm(A)')
19651987

19661988

1967-
def proj(B, A): # Project on the blade B the multivector A
1989+
def proj(B, A):
1990+
""" Equivalent to :meth:`Mv.project_in_blade` """
19681991
if isinstance(A, Mv):
19691992
return A.project_in_blade(B)
19701993
else:
19711994
raise ValueError('A not a multivector in proj(B, A)')
19721995

19731996

1974-
def rot(itheta, A, hint='-'): # Rotate by the 2-blade itheta the multivector A
1997+
def rot(itheta, A, hint='-'):
1998+
"""
1999+
Equivalent to ``A.rotate_multivector(itheta, hint)`` where ``itheta`` is the bi-vector blade defining the rotation.
2000+
For the use of ``hint`` see the method :meth:`Mv.rotate_multivector`.
2001+
"""
19752002
if isinstance(A, Mv):
19762003
return A.rotate_multivector(itheta, hint)
19772004
else:
19782005
raise ValueError('A not a multivector in rotate(A, itheta)')
19792006

19802007

1981-
def refl(B, A): # Project on the blade B the multivector A
2008+
def refl(B, A):
2009+
r"""
2010+
Reflect multivector :math:`A` in blade :math:`B`.
2011+
2012+
If :math:`s` is grade of :math:`B` returns :math:`\sum_{r}(-1)^{s(r+1)}B{\left < {A} \right >}_{r}B^{-1}`.
2013+
2014+
Equivalent to :meth:`Mv.reflect_in_blade`
2015+
"""
19822016
if isinstance(A, Mv):
19832017
return A.reflect_in_blade(B)
19842018
else:
19852019
raise ValueError('A not a multivector in reflect(B, A)')
19862020

19872021

19882022
def rev(A):
2023+
""" Equivalent to :meth:`Mv.rev` """
19892024
if isinstance(A, Mv):
19902025
return A.rev()
19912026
else:
19922027
raise ValueError('A not a multivector in rev(A)')
19932028

19942029

19952030
def scalar(A):
2031+
""" Equivalent to :meth:`Mv.scalar` """
19962032
if not isinstance(A, Mv):
19972033
raise ValueError('A = ' + str(A) + ' not a multivector in inv(A).')
19982034
return A.scalar()

galgebra/printer.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,18 @@ def Print_Function():
11951195
'*': r'(([A-Za-z0-9\_\#]+)[\*]{1}([A-Za-z0-9\_\#]+)([\*]{1}([A-Za-z0-9\_\#]+))*)'}
11961196

11971197

1198-
def def_prec(gd, op_ord='<>|,^,*'): # Default is Doran and Lasenby convention
1198+
def def_prec(gd: dict, op_ord: str = '<>|,^,*') -> None:
1199+
"""
1200+
This is used with the ``GAeval()`` function to evaluate a string representing a multivector expression with a revised operator precedence.
1201+
1202+
Parameters
1203+
----------
1204+
gd :
1205+
The ``globals()`` dictionary to lookup variable names in.
1206+
op_ord :
1207+
The order of operator precedence from high to low with groups of equal precedence separated by commas.
1208+
The default precedence, ``'<>|,^,*'``, is that used by Hestenes (:cite:`Hestenes`, p7, :cite:`Doran`, p38).
1209+
"""
11991210
global global_dict, op_dict, op_lst
12001211
global_dict = gd
12011212
op_lst = op_ord.split(',')
@@ -1351,14 +1362,21 @@ def parse_line(line):
13511362
return line
13521363

13531364

1354-
def GAeval(s, pstr=False):
1365+
def GAeval(s: str, pstr: bool = False):
13551366
"""
1356-
GAeval converts a string to a multivector expression where the
1357-
user can control the precedence of the of the multivector operators so
1358-
that one does not need to put parenthesis around every multivector
1359-
operation. The default precedence used (high to low) is <,>, and | have
1360-
an have the highest precedence, then comes ^, and finally *. The
1361-
default precedence can be changed with the def_prec function.
1367+
Evaluate a multivector expression string ``s``.
1368+
1369+
The operator precedence and variable values within the string are
1370+
controlled by :func:`def_prec`. The documentation for that function
1371+
describes the default precedence.
1372+
1373+
Parameters
1374+
----------
1375+
s :
1376+
The string to evaluate.
1377+
pstr :
1378+
If ``True``, the values of ``s`` and ``s`` with parenthesis added to
1379+
enforce operator precedence are printed.
13621380
"""
13631381

13641382
seval = parse_line(s)

0 commit comments

Comments
 (0)