+
    iQ                     |   R t . R#Ot^ R
IHt ^ RIHtHt ^ RIHt ^ RI	H
t
Ht ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt  ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R	]4      tR$R lt R t!R t"R t#]#t$R  t%R! t&R"# )%a  
Gaussian optics.

The module implements:

- Ray transfer matrices for geometrical and gaussian optics.

  See RayTransferMatrix, GeometricRay and BeamParameter

- Conjugation relations for geometrical and gaussian optics.

  See geometric_conj*, gauss_conj and conjugate_gauss_beams

The conventions for the distances are as follows:

focal distance
    positive for convergent lenses
object distance
    positive for real objects
image distance
    positive for real images
RayTransferMatrix	FreeSpaceFlatRefractionCurvedRefraction
FlatMirrorCurvedMirrorThinLensGeometricRayBeamParameter)Expr)Ipi)sympify)imre)sqrt)atan2)MatrixMutableDenseMatrix)together)
filldedentc                   p   a  ] tR t^;t o RtR tR t]R 4       t]R 4       t	]R 4       t
]R 4       tRtV tR	# )
r   aB  
Base class for a Ray Transfer Matrix.

It should be used if there is not already a more specific subclass mentioned
in See Also.

Parameters
==========

parameters :
    A, B, C and D or 2x2 matrix (Matrix(2, 2, [A, B, C, D]))

Examples
========

>>> from sympy.physics.optics import RayTransferMatrix, ThinLens
>>> from sympy import Symbol, Matrix

>>> mat = RayTransferMatrix(1, 2, 3, 4)
>>> mat
Matrix([
[1, 2],
[3, 4]])

>>> RayTransferMatrix(Matrix([[1, 2], [3, 4]]))
Matrix([
[1, 2],
[3, 4]])

>>> mat.A
1

>>> f = Symbol('f')
>>> lens = ThinLens(f)
>>> lens
Matrix([
[   1, 0],
[-1/f, 1]])

>>> lens.C
-1/f

See Also
========

GeometricRay, BeamParameter,
FreeSpace, FlatRefraction, CurvedRefraction,
FlatMirror, CurvedMirror, ThinLens

References
==========

.. [1] https://en.wikipedia.org/wiki/Ray_transfer_matrix_analysis
c                ~   \        V4      ^8X  d&   V^ ,          V^,          3V^,          V^,          33pMs\        V4      ^8X  d@   \        V^ ,          \        4      '       d#   V^ ,          P                  R8X  d   V^ ,          pM$\	        \        R\        V4      ,          4      4      h\        P                  ! W4      # )   z`
                Expecting 2x2 Matrix or the 4 elements of
                the Matrix but got %s)   r   len
isinstancer   shape
ValueErrorr   str__new__clsargstemps   &* }/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/physics/optics/gaussopt.pyr!   RayTransferMatrix.__new__s   s    t9>!Wd1g&a$q'(:;DY!^47F++GMMV+7DZ ))+.t9)5 6 7 7 ~~c((    c           	     X   \        V\        4      '       d%   \        \        V 4      \        V4      ,          4      # \        V\        4      '       d%   \        \        V 4      \        V4      ,          4      # \        V\        4      '       d   \        V 4      \        VP
                  3R34      ,          pV^ ,          V^,          ,          P                  RR7      p\	        VP                  \        \        V4      4      \        \        V4      4      R7      # \        P                  ! W4      # )   T)complex)z_rr*   )r   r   r   r	   r
   qexpandwavelenr   r   r   __mul__)selfotherr%   r.   s   &&  r&   r1   RayTransferMatrix.__mul__   s    e.//$VD\&-%?@@|,,tVE] :;;}--$<
D'9 ::Daa(((6A !)"Q%%-be_6 6 >>$..r(   c                    V R,          # )z
The A parameter of the Matrix.

Examples
========

>>> from sympy.physics.optics import RayTransferMatrix
>>> mat = RayTransferMatrix(1, 2, 3, 4)
>>> mat.A
1
)    r6    r2   s   &r&   ARayTransferMatrix.A        Dzr(   c                    V R,          # )z
The B parameter of the Matrix.

Examples
========

>>> from sympy.physics.optics import RayTransferMatrix
>>> mat = RayTransferMatrix(1, 2, 3, 4)
>>> mat.B
2
)r6   r*   r7   r8   s   &r&   BRayTransferMatrix.B   r;   r(   c                    V R,          # )z
The C parameter of the Matrix.

Examples
========

>>> from sympy.physics.optics import RayTransferMatrix
>>> mat = RayTransferMatrix(1, 2, 3, 4)
>>> mat.C
3
)r*   r6   r7   r8   s   &r&   CRayTransferMatrix.C   r;   r(   c                    V R,          # )z
The D parameter of the Matrix.

Examples
========

>>> from sympy.physics.optics import RayTransferMatrix
>>> mat = RayTransferMatrix(1, 2, 3, 4)
>>> mat.D
4
)r*   r*   r7   r8   s   &r&   DRayTransferMatrix.D   r;   r(   r7   N)__name__
__module____qualname____firstlineno____doc__r!   r1   propertyr9   r=   r@   rC   __static_attributes____classdictcell____classdict__s   @r&   r   r   ;   se     5n)/        r(   c                   *   a  ] tR t^t o RtR tRtV tR# )r   a  
Ray Transfer Matrix for free space.

Parameters
==========

distance

See Also
========

RayTransferMatrix

Examples
========

>>> from sympy.physics.optics import FreeSpace
>>> from sympy import symbols
>>> d = symbols('d')
>>> FreeSpace(d)
Matrix([
[1, d],
[0, 1]])
c                4    \         P                  V ^V^ ^4      # r-   r   r!   )r#   ds   &&r&   r!   FreeSpace.__new__        ((aAq99r(   r7   NrE   rF   rG   rH   rI   r!   rK   rL   rM   s   @r&   r   r      s     0: :r(   c                   *   a  ] tR t^t o RtR tRtV tR# )r   ax  
Ray Transfer Matrix for refraction.

Parameters
==========

n1 :
    Refractive index of one medium.
n2 :
    Refractive index of other medium.

See Also
========

RayTransferMatrix

Examples
========

>>> from sympy.physics.optics import FlatRefraction
>>> from sympy import symbols
>>> n1, n2 = symbols('n1 n2')
>>> FlatRefraction(n1, n2)
Matrix([
[1,     0],
[0, n1/n2]])
c                f    \        \        W34      w  r\        P                  V ^^ ^ W,          4      # r-   mapr   r   r!   )r#   n1n2s   &&&r&   r!   FlatRefraction.__new__  s-    Wrh' ((aAru==r(   r7   NrU   rM   s   @r&   r   r      s     6> >r(   c                   *   a  ] tR tRt o RtR tRtV tR# )r   i
  a  
Ray Transfer Matrix for refraction on curved interface.

Parameters
==========

R :
    Radius of curvature (positive for concave).
n1 :
    Refractive index of one medium.
n2 :
    Refractive index of other medium.

See Also
========

RayTransferMatrix

Examples
========

>>> from sympy.physics.optics import CurvedRefraction
>>> from sympy import symbols
>>> R, n1, n2 = symbols('R n1 n2')
>>> CurvedRefraction(R, n1, n2)
Matrix([
[               1,     0],
[(n1 - n2)/(R*n2), n1/n2]])
c                    \        \        WV34      w  rp\        P                  V ^^ W#,
          V,          V,          W#,          4      # r-   rX   )r#   RrZ   r[   s   &&&&r&   r!   CurvedRefraction.__new__(  s;    !-	r ((aRWaKNBEJJr(   r7   NrU   rM   s   @r&   r   r   
  s     :K Kr(   c                   *   a  ] tR tRt o RtR tRtV tR# )r   i-  z
Ray Transfer Matrix for reflection.

See Also
========

RayTransferMatrix

Examples
========

>>> from sympy.physics.optics import FlatMirror
>>> FlatMirror()
Matrix([
[1, 0],
[0, 1]])
c                4    \         P                  V ^^ ^ ^4      # r-   rQ   )r#   s   &r&   r!   FlatMirror.__new__?  rT   r(   r7   NrU   rM   s   @r&   r   r   -  s     ": :r(   c                   *   a  ] tR tRt o RtR tRtV tR# )r   iC  aS  
Ray Transfer Matrix for reflection from curved surface.

Parameters
==========

R : radius of curvature (positive for concave)

See Also
========

RayTransferMatrix

Examples
========

>>> from sympy.physics.optics import CurvedMirror
>>> from sympy import symbols
>>> R = symbols('R')
>>> CurvedMirror(R)
Matrix([
[   1, 0],
[-2/R, 1]])
c                X    \        V4      p\        P                  V ^^ RV,          ^4      # )r*   r   r   r!   )r#   r_   s   &&r&   r!   CurvedMirror.__new__\  (    AJ ((aBqD!<<r(   r7   NrU   rM   s   @r&   r   r   C  s     0= =r(   c                   *   a  ] tR tRt o RtR tRtV tR# )r   ia  a%  
Ray Transfer Matrix for a thin lens.

Parameters
==========

f :
    The focal distance.

See Also
========

RayTransferMatrix

Examples
========

>>> from sympy.physics.optics import ThinLens
>>> from sympy import symbols
>>> f = symbols('f')
>>> ThinLens(f)
Matrix([
[   1, 0],
[-1/f, 1]])
c                X    \        V4      p\        P                  V ^^ RV,          ^4      # )r*   rg   )r#   fs   &&r&   r!   ThinLens.__new__{  ri   r(   r7   NrU   rM   s   @r&   r   r   a  s     2= =r(   c                   J   a  ] tR tRt o RtR t]R 4       t]R 4       tRt	V t
R# )r	   i  aV  
Representation for a geometric ray in the Ray Transfer Matrix formalism.

Parameters
==========

h : height, and
angle : angle, or
matrix : a 2x1 matrix (Matrix(2, 1, [height, angle]))

Examples
========

>>> from sympy.physics.optics import GeometricRay, FreeSpace
>>> from sympy import symbols, Matrix
>>> d, h, angle = symbols('d, h, angle')

>>> GeometricRay(h, angle)
Matrix([
[    h],
[angle]])

>>> FreeSpace(d)*GeometricRay(h, angle)
Matrix([
[angle*d + h],
[      angle]])

>>> GeometricRay( Matrix( ((h,), (angle,)) ) )
Matrix([
[    h],
[angle]])

See Also
========

RayTransferMatrix

c                ^   \        V4      ^8X  d@   \        V^ ,          \        4      '       d#   V^ ,          P                  R8X  d   V^ ,          pMI\        V4      ^8X  d   V^ ,          3V^,          33pM$\	        \        R\        V4      ,          4      4      h\        P                  ! W4      # )r*   z`
                Expecting 2x1 Matrix or the 2 elements of
                the Matrix but got %s)r   r*   r   r"   s   &* r&   r!   GeometricRay.__new__  s    t9>ja&99GMMV+7DY!^!WJa
+DZ ))+.t9)5 6 7 7 ~~c((r(   c                    V ^ ,          # )z
The distance from the optical axis.

Examples
========

>>> from sympy.physics.optics import GeometricRay
>>> from sympy import symbols
>>> h, angle = symbols('h, angle')
>>> gRay = GeometricRay(h, angle)
>>> gRay.height
h
r7   r8   s   &r&   heightGeometricRay.height       Awr(   c                    V ^,          # )z
The angle with the optical axis.

Examples
========

>>> from sympy.physics.optics import GeometricRay
>>> from sympy import symbols
>>> h, angle = symbols('h, angle')
>>> gRay = GeometricRay(h, angle)
>>> gRay.angle
angle
r7   r8   s   &r&   angleGeometricRay.angle  ru   r(   r7   N)rE   rF   rG   rH   rI   r!   rJ   rs   rw   rK   rL   rM   s   @r&   r	   r	     s8     %N
)     r(   c                      a  ] tR tRt o RtRR lt]R 4       t]R 4       t]R 4       t	]R 4       t
]R	 4       t]R
 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       tRtV tR# )r
   i  a&  
Representation for a gaussian ray in the Ray Transfer Matrix formalism.

Parameters
==========

wavelen : the wavelength,
z : the distance to waist, and
w : the waist, or
z_r : the rayleigh range.
n : the refractive index of medium.

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.q
1 + 1.88679245283019*I*pi

>>> p.q.n()
1.0 + 5.92753330865999*I
>>> p.w_0.n()
0.00100000000000000
>>> p.z_r.n()
5.92753330865999

>>> from sympy.physics.optics import FreeSpace
>>> fs = FreeSpace(10)
>>> p1 = fs*p
>>> p.w.n()
0.00101413072159615
>>> p1.w.n()
0.00210803120913829

See Also
========

RayTransferMatrix

References
==========

.. [1] https://en.wikipedia.org/wiki/Complex_beam_parameter
.. [2] https://en.wikipedia.org/wiki/Gaussian_beam
Nc                    \        V4      p\        V4      p\        V4      pVe   Vf   \        V4      pM1Ve   Vf   \        \        V4      W4      pMVf   Vf   \        R4      h\        P                  ! WW#V4      # )NzMust specify one of w and z_r.)r   waist2rayleighr   r   r!   )r#   r0   zr,   wns   &&&&&&r&   r!   BeamParameter.__new__  sq    '"AJAJ?qy#,C]s{ W8C[QY=>>||C!!44r(   c                (    V P                   ^ ,          # )r6   r$   r8   s   &r&   r0   BeamParameter.wavelen       yy|r(   c                (    V P                   ^,          # r-   r   r8   s   &r&   r|   BeamParameter.z$  r   r(   c                (    V P                   ^,          # )r   r   r8   s   &r&   r,   BeamParameter.z_r(  r   r(   c                (    V P                   ^,          # )   r   r8   s   &r&   r~   BeamParameter.n,  r   r(   c                R    V P                   \        V P                  ,          ,           # )z
The complex parameter representing the beam.

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.q
1 + 1.88679245283019*I*pi
)r|   r   r,   r8   s   &r&   r.   BeamParameter.q0  s     vv$((
""r(   c                z    V P                   ^V P                  V P                   ,          ^,          ,           ,          # )z
The radius of curvature of the phase front.

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.radius
1 + 3.55998576005696*pi**2
)r|   r,   r8   s   &r&   radiusBeamParameter.radius?  s)     vvqDHHTVVOa//00r(   c                    V P                   \        ^V P                  V P                  ,          ^,          ,           4      ,          # )aC  
The radius of the beam w(z), at any position z along the beam.
The beam radius at `1/e^2` intensity (axial value).

See Also
========

w_0 :
    The minimal radius of beam.

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.w
0.001*sqrt(0.2809/pi**2 + 1)
)w_0r   r|   r,   r8   s   &r&   r}   BeamParameter.wN  s.    ( xxQ$&&/A!55666r(   c                    \        V P                  \        V P                  ,          ,          V P                  ,          4      # )a  
 The minimal radius of beam at `1/e^2` intensity (peak value).

See Also
========

w : the beam radius at `1/e^2` intensity (axial value).

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.w_0
0.00100000000000000
)r   r,   r   r~   r0   r8   s   &r&   r   BeamParameter.w_0d  s)    $ DHHbi(566r(   c                R    V P                   \        ,          V P                  ,          # )z
Half of the total angular spread.

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.divergence
0.00053/pi
)r0   r   r   r8   s   &r&   
divergenceBeamParameter.divergencex  s     ||Btxx''r(   c                B    \        V P                  V P                  4      # )z
The Gouy phase.

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.gouy
atan(0.53/pi)
)r   r|   r,   r8   s   &r&   gouyBeamParameter.gouy  s     TVVTXX&&r(   c                >    ^V P                   ,          \        ,          # )as  
The minimal waist for which the gauss beam approximation is valid.

Explanation
===========

The gauss beam is a solution to the paraxial equation. For curvatures
that are too great it is not a valid approximation.

Examples
========

>>> from sympy.physics.optics import BeamParameter
>>> p = BeamParameter(530e-9, 1, w=1e-3)
>>> p.waist_approximation_limit
1.06e-6/pi
)r0   r   r8   s   &r&   waist_approximation_limit'BeamParameter.waist_approximation_limit  s    & ~b  r(   r7   )NNr*   )rE   rF   rG   rH   rI   r!   rJ   r0   r|   r,   r~   r.   r   r}   r   r   r   r   rK   rL   rM   s   @r&   r
   r
     s     -d5         # # 1 1 7 7* 7 7& ( ( ' ' ! !r(   c                l    \        \        W34      w  rV ^,          V,          \        ,          V,          # )a.  
Calculate the rayleigh range from the waist of a gaussian beam.

See Also
========

rayleigh2waist, BeamParameter

Examples
========

>>> from sympy.physics.optics import waist2rayleigh
>>> from sympy import symbols
>>> w, wavelen = symbols('w wavelen')
>>> waist2rayleigh(w, wavelen)
pi*w**2/wavelen
)rY   r   r   )r}   r0   r~   s   &&&r&   r{   r{     s+    $ Wql+JAa46"9Wr(   c                b    \        \        W34      w  r\        V \        ,          V,          4      # )a>  Calculate the waist from the rayleigh range of a gaussian beam.

See Also
========

waist2rayleigh, BeamParameter

Examples
========

>>> from sympy.physics.optics import rayleigh2waist
>>> from sympy import symbols
>>> z_r, wavelen = symbols('z_r wavelen')
>>> rayleigh2waist(z_r, wavelen)
sqrt(wavelen*z_r)/sqrt(pi)
)rY   r   r   r   )r,   r0   s   &&r&   rayleigh2waistr     s'    " w/LCBwr(   c                    \        \        W34      w  rV P                  '       g   VP                  '       d   VP                  '       d   V # T# W,          W,           ,          # )a  
Conjugation relation for geometrical beams under paraxial conditions.

Explanation
===========

Takes the distances to the optical element and returns the needed
focal distance.

See Also
========

geometric_conj_af, geometric_conj_bf

Examples
========

>>> from sympy.physics.optics import geometric_conj_ab
>>> from sympy import symbols
>>> a, b = symbols('a b')
>>> geometric_conj_ab(a, b)
a*b/(a + b)
)rY   r   is_infinite)abs   &&r&   geometric_conj_abr     sF    0 wDA}}}MMMq(q(sAE{r(   c                B    \        \        W34      w  r\        W) 4      ) # )aE  
Conjugation relation for geometrical beams under paraxial conditions.

Explanation
===========

Takes the object distance (for geometric_conj_af) or the image distance
(for geometric_conj_bf) to the optical element and the focal distance.
Then it returns the other distance needed for conjugation.

See Also
========

geometric_conj_ab

Examples
========

>>> from sympy.physics.optics.gaussopt import geometric_conj_af, geometric_conj_bf
>>> from sympy import symbols
>>> a, b, f = symbols('a b f')
>>> geometric_conj_af(a, f)
a*f/(a - f)
>>> geometric_conj_bf(b, f)
b*f/(b - f)
)rY   r   r   )r   rm   s   &&r&   geometric_conj_afr     s$    6 wDAa$$$r(   c                z   \        \        WV34      w  rp^RW^,          W,
          ,          ,           ,          ^V,          ,           ,          p^\        ^W,          ^,          ,
          W,          ^,          ,           4      ,          pV^W,          ^,          ,
          W,          ^,          ,           ,          pW5V3# )a]  
Conjugation relation for gaussian beams.

Parameters
==========

s_in :
    The distance to optical element from the waist.
z_r_in :
    The rayleigh range of the incident beam.
f :
    The focal length of the optical element.

Returns
=======

a tuple containing (s_out, z_r_out, m)
s_out :
    The distance between the new waist and the optical element.
z_r_out :
    The rayleigh range of the emergent beam.
m :
    The ration between the new and the old waists.

Examples
========

>>> from sympy.physics.optics import gaussian_conj
>>> from sympy import symbols
>>> s_in, z_r_in, f = symbols('s_in z_r_in f')

>>> gaussian_conj(s_in, z_r_in, f)[0]
1/(-1/(s_in + z_r_in**2/(-f + s_in)) + 1/f)

>>> gaussian_conj(s_in, z_r_in, f)[1]
z_r_in/(1 - s_in**2/f**2 + z_r_in**2/f**2)

>>> gaussian_conj(s_in, z_r_in, f)[2]
1/sqrt(1 - s_in**2/f**2 + z_r_in**2/f**2)
rl   )rY   r   r   )s_inz_r_inrm   s_outmz_r_outs   &&&   r&   gaussian_conjr     s    R 'D!#45OD!"dQY112QqS8:E	$TVaKFHq=0
11Adfq[VXM9:GAr(   c                   \        \        WV34      w  rpW!,          p\        W4      p\        V4      ^8w  d   \	        R4      hRV9   d   \        \        R4      4      hRV9   dj   \        VR,          4      pV^\        ^V^,          ,          V^,          V^,          ,          ,
          4      ,
          ,          p\        WuV4      ^ ,          pM/RV9   d   \        \        R4      4      h\	        \        R4      4      hWxV3# )a  
Find the optical setup conjugating the object/image waists.

Parameters
==========

wavelen :
    The wavelength of the beam.
waist_in and waist_out :
    The waists to be conjugated.
f :
    The focal distance of the element used in the conjugation.

Returns
=======

a tuple containing (s_in, s_out, f)
s_in :
    The distance before the optical element.
s_out :
    The distance after the optical element.
f :
    The focal distance of the optical element.

Examples
========

>>> from sympy.physics.optics import conjugate_gauss_beams
>>> from sympy import symbols, factor
>>> l, w_i, w_o, f = symbols('l w_i w_o f')

>>> conjugate_gauss_beams(l, w_i, w_o, f=f)[0]
f*(1 - sqrt(w_i**2/w_o**2 - pi**2*w_i**4/(f**2*l**2)))

>>> factor(conjugate_gauss_beams(l, w_i, w_o, f=f)[1])
f*w_o**2*(w_i**2/w_o**2 - sqrt(w_i**2/w_o**2 -
          pi**2*w_i**4/(f**2*l**2)))/w_i**2

>>> conjugate_gauss_beams(l, w_i, w_o, f=f)[2]
f
z,The function expects only one named argumentdistzD
            Currently only focal length is supported as a parameterrm   r   zG
            The functions expects the focal length as a named argument)	rY   r   r{   r   r   NotImplementedErrorr   r   r   )	r0   waist_in	waist_outkwargsr   r|   rm   r   r   s	   &&&,     r&   conjugate_gauss_beamsr   K  s   V $'wI0N#O GyAx)A
6{aGHH	6	!* .G #H I 	I	F3K AQq!tVad1a4i/001dq)!,	6	!* .G #H I 	I  %J K L 	Lr(   N)r   r   r   r   r   r   r   r	   r
   r{   r   r   r   geometric_conj_bfr   r   r-   )'rI   __all__sympy.core.exprr   sympy.core.numbersr   r   sympy.core.sympifyr   $sympy.functions.elementary.complexesr   r   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   sympy.matrices.denser   r   sympy.polys.rationaltoolsr   sympy.utilities.miscr   r   r   r   r   r   r   r   r	   r
   r{   r   r   r   r   r   r   r7   r(   r&   <module>r      s   .( ! & & 9 9 : ; . +N* Nb:! ::>& >B K(  KF:" :,=$ =<=  =FT% TvJ!D J!b, *>%< & -`=r(   