Skip to content

Commit 6302046

Browse files
GlenHertzLilithHafner
authored andcommitted
Improve cis and cispi docs (JuliaLang#40859)
* Improve `cis` and `cispi` docs * Fix whitespace error * Fix escaping of \\pi * Add suggestions * Add sincos refs (more discoverable) * Typo fix * Tweaks * More wordsmithing * Fix whitespace at EOL * wordsmithing * More wordsmithing * More wordsmithing * Use larger value of cispi(x) to show accuracy in example
1 parent 4173b74 commit 6302046

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

base/complex.jl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -535,42 +535,42 @@ end
535535
# return Complex(abs(iz)/r/2, copysign(r,iz))
536536
# end
537537

538-
# compute exp(im*theta)
539-
function cis(theta::Real)
540-
s, c = sincos(theta)
541-
Complex(c, s)
542-
end
543-
544538
"""
545-
cis(z)
539+
cis(x)
546540
547-
Return ``\\exp(iz)``.
541+
More efficient method for `exp(im*x)` by using Euler's formula: ``cos(x) + i sin(x) = \\exp(i x)``.
548542
549-
See also [`cispi`](@ref), [`angle`](@ref).
543+
See also [`cispi`](@ref), [`sincos`](@ref), [`exp`](@ref), [`angle`](@ref).
550544
551545
# Examples
552546
```jldoctest
553547
julia> cis(π) ≈ -1
554548
true
555549
```
556550
"""
551+
function cis end
552+
function cis(theta::Real)
553+
s, c = sincos(theta)
554+
Complex(c, s)
555+
end
556+
557557
function cis(z::Complex)
558558
v = exp(-imag(z))
559559
s, c = sincos(real(z))
560560
Complex(v * c, v * s)
561561
end
562562

563-
cispi(theta::Real) = Complex(reverse(sincospi(theta))...)
564-
565563
"""
566-
cispi(z)
564+
cispi(x)
567565
568-
Compute ``\\exp(i\\pi x)`` more accurately than `cis(pi*x)`, especially for large `x`.
566+
More accurate method for `cis(pi*x)` (especially for large `x`).
567+
568+
See also [`cis`](@ref), [`sincospi`](@ref), [`exp`](@ref), [`angle`](@ref).
569569
570570
# Examples
571571
```jldoctest
572-
julia> cispi(1)
573-
-1.0 + 0.0im
572+
julia> cispi(10000)
573+
1.0 + 0.0im
574574
575575
julia> cispi(0.25 + 1im)
576576
0.030556854645952924 + 0.030556854645952924im
@@ -579,6 +579,9 @@ julia> cispi(0.25 + 1im)
579579
!!! compat "Julia 1.6"
580580
This function requires Julia 1.6 or later.
581581
"""
582+
function cispi end
583+
cispi(theta::Real) = Complex(reverse(sincospi(theta))...)
584+
582585
function cispi(z::Complex)
583586
sipi, copi = sincospi(z)
584587
return complex(real(copi) - imag(sipi), imag(copi) + real(sipi))

stdlib/LinearAlgebra/src/dense.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,10 @@ exp(A::Transpose{<:Any,<:AbstractMatrix}) = transpose(exp(parent(A)))
565565
"""
566566
cis(A::AbstractMatrix)
567567
568-
Compute ``\\exp(i A)`` for a square matrix ``A``.
568+
More efficient method for `exp(im*A)` of square matrix `A`
569+
(especially if `A` is `Hermitian` or real-`Symmetric`).
570+
571+
See also [`cispi`](@ref), [`sincos`](@ref), [`exp`](@ref).
569572
570573
!!! compat "Julia 1.7"
571574
Support for using `cis` with matrices was added in Julia 1.7.

0 commit comments

Comments
 (0)