-
Notifications
You must be signed in to change notification settings - Fork 56
/
group.jl
1280 lines (1114 loc) · 37.1 KB
/
group.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@doc raw"""
AbstractGroupOperation
Abstract type for smooth binary operations ``∘`` on elements of a Lie group ``\mathcal{G}``:
```math
∘ : \mathcal{G} × \mathcal{G} → \mathcal{G}
```
An operation can be either defined for a specific group manifold over
number system `𝔽` or in general, by defining for an operation `Op` the following methods:
identity_element!(::AbstractDecoratorManifold, q, q)
inv!(::AbstractDecoratorManifold, q, p)
_compose!(::AbstractDecoratorManifold, x, p, q)
Note that a manifold is connected with an operation by wrapping it with a decorator,
[`AbstractDecoratorManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/decorator.html#ManifoldsBase.AbstractDecoratorManifold)
using the [`IsGroupManifold`](@ref) to specify the operation.
For a concrete case the concrete wrapper [`GroupManifold`](@ref) can be used.
"""
abstract type AbstractGroupOperation end
"""
IsGroupManifold{O<:AbstractGroupOperation} <: AbstractTrait
A trait to declare an [`AbstractManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/types.html#ManifoldsBase.AbstractManifold) as a manifold with group structure
with operation of type `O`.
Using this trait you can turn a manifold that you implement _implictly_ into a Lie group.
If you wish to decorate an existing manifold with one (or different) [`AbstractGroupAction`](@ref)s,
see [`GroupManifold`](@ref).
# Constructor
IsGroupManifold(op::AbstractGroupOperation)
"""
struct IsGroupManifold{O<:AbstractGroupOperation} <: AbstractTrait
op::O
end
"""
AbstractInvarianceTrait <: AbstractTrait
A common supertype for anz [`AbstractTrait`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/decorator.html#ManifoldsBase.AbstractTrait) related to metric invariance
"""
abstract type AbstractInvarianceTrait <: AbstractTrait end
"""
HasLeftInvariantMetric <: AbstractInvarianceTrait
Specify that the default metric functions for the left-invariant metric on a [`GroupManifold`](@ref)
are to be used.
"""
struct HasLeftInvariantMetric <: AbstractInvarianceTrait end
direction_and_side(::HasLeftInvariantMetric) = LeftForwardAction()
direction_and_side(::Type{HasLeftInvariantMetric}) = LeftForwardAction()
"""
HasRightInvariantMetric <: AbstractInvarianceTrait
Specify that the default metric functions for the right-invariant metric on a [`GroupManifold`](@ref)
are to be used.
"""
struct HasRightInvariantMetric <: AbstractInvarianceTrait end
direction_and_side(::HasRightInvariantMetric) = RightBackwardAction()
direction_and_side(::Type{HasRightInvariantMetric}) = RightBackwardAction()
"""
HasBiinvariantMetric <: AbstractInvarianceTrait
Specify that the default metric functions for the bi-invariant metric on a [`GroupManifold`](@ref)
are to be used.
"""
struct HasBiinvariantMetric <: AbstractInvarianceTrait end
function parent_trait(::HasBiinvariantMetric)
return ManifoldsBase.TraitList(HasLeftInvariantMetric(), HasRightInvariantMetric())
end
"""
is_group_manifold(G::GroupManifold)
is_group_manifold(G::AbstractManifold, o::AbstractGroupOperation)
returns whether an [`AbstractDecoratorManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/decorator.html#ManifoldsBase.AbstractDecoratorManifold)
is a group manifold with [`AbstractGroupOperation`](@ref) `o`.
For a [`GroupManifold`](@ref) `G` this checks whether the right operations is stored within `G`.
"""
is_group_manifold(::AbstractManifold, ::AbstractGroupOperation) = false
@trait_function is_group_manifold(M::AbstractDecoratorManifold, op::AbstractGroupOperation)
function is_group_manifold(
::TraitList{<:IsGroupManifold{<:O}},
::AbstractDecoratorManifold,
::O,
) where {O<:AbstractGroupOperation}
return true
end
@trait_function is_group_manifold(M::AbstractDecoratorManifold)
is_group_manifold(::AbstractManifold) = false
function is_group_manifold(
t::TraitList{<:IsGroupManifold{<:AbstractGroupOperation}},
M::AbstractDecoratorManifold,
)
return is_group_manifold(M, t.head.op)
end
base_group(M::MetricManifold) = decorated_manifold(M)
base_group(M::ConnectionManifold) = decorated_manifold(M)
base_group(M::AbstractDecoratorManifold) = M
"""
ActionDirection
Direction of action on a manifold, either [`LeftAction`](@ref) or [`RightAction`](@ref).
"""
abstract type ActionDirection end
@doc raw"""
LeftAction()
Left action of a group on a manifold. For a forward action ``α: G × X → X`` it is characterized by
```math
α(g, α(h, x)) = α(gh, x)
```
for all ``g, h ∈ G`` and ``x ∈ X``.
"""
struct LeftAction <: ActionDirection end
"""
RightAction()
Right action of a group on a manifold. For a forward action ``α: G × X → X`` it is characterized by
```math
α(g, α(h, x)) = α(hg, x)
```
for all ``g, h ∈ G`` and ``x ∈ X``.
Note that a right action may act from either left or right side in an expression.
"""
struct RightAction <: ActionDirection end
"""
GroupActionSide
Side of action on a manifold, either [`LeftSide`](@ref) or [`RightSide`](@ref).
"""
abstract type GroupActionSide end
"""
LeftSide()
An action of a group on a manifold that acts from the left side, i.e. ``α: G × X → X``.
"""
struct LeftSide <: GroupActionSide end
"""
RightSide()
An action of a group on a manifold that acts from the right side, i.e. ``α: X × G → X``.
"""
struct RightSide <: GroupActionSide end
"""
switch_direction(::ActionDirection)
Returns type of action between left and right.
This function does not affect side of action, see [`switch_side`](@ref).
"""
switch_direction(::ActionDirection)
switch_direction(::LeftAction) = RightAction()
switch_direction(::RightAction) = LeftAction()
"""
switch_side(::GroupActionSide)
Returns side of action between left and right.
This function does not affect the action being left or right, see [`switch_direction`](@ref).
"""
switch_side(::GroupActionSide)
switch_side(::LeftSide) = RightSide()
switch_side(::RightSide) = LeftSide()
const ActionDirectionAndSide = Tuple{ActionDirection,GroupActionSide}
const LeftForwardAction = Tuple{LeftAction,LeftSide}
const LeftBackwardAction = Tuple{LeftAction,RightSide}
const RightForwardAction = Tuple{RightAction,LeftSide}
const RightBackwardAction = Tuple{RightAction,RightSide}
LeftForwardAction() = (LeftAction(), LeftSide())
LeftBackwardAction() = (LeftAction(), RightSide())
RightForwardAction() = (RightAction(), LeftSide())
RightBackwardAction() = (RightAction(), RightSide())
@doc raw"""
Identity{O<:AbstractGroupOperation}
Represent the group identity element ``e ∈ \mathcal{G}`` on a Lie group ``\mathcal G``
with [`AbstractGroupOperation`](@ref) of type `O`.
Similar to the philosophy that points are agnostic of their group at hand, the identity
does not store the group `g` it belongs to. However it depends on the type of the [`AbstractGroupOperation`](@ref) used.
See also [`identity_element`](@ref) on how to obtain the corresponding [`AbstractManifoldPoint`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/types.html#ManifoldsBase.AbstractManifoldPoint) or array representation.
# Constructors
Identity(G::AbstractDecoratorManifold{𝔽})
Identity(o::O)
Identity(::Type{O})
create the identity of the corresponding subtype `O<:`[`AbstractGroupOperation`](@ref)
"""
struct Identity{O<:AbstractGroupOperation} end
@trait_function Identity(M::AbstractDecoratorManifold)
function Identity(
::TraitList{<:IsGroupManifold{O}},
::AbstractDecoratorManifold,
) where {O<:AbstractGroupOperation}
return Identity{O}()
end
Identity(::O) where {O<:AbstractGroupOperation} = Identity(O)
Identity(::Type{O}) where {O<:AbstractGroupOperation} = Identity{O}()
# To ensure allocate_result_type works in general if idenitty apears in the tuple
number_eltype(::Identity) = Bool
@doc raw"""
identity_element(G::AbstractDecoratorManifold)
Return a point representation of the [`Identity`](@ref) on the [`IsGroupManifold`](@ref) `G`.
By default this representation is the default array or number representation.
It should return the corresponding default representation of ``e`` as a point on `G` if
points are not represented by arrays.
"""
identity_element(G::AbstractDecoratorManifold)
@trait_function identity_element(G::AbstractDecoratorManifold)
function identity_element(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold)
BG = base_group(G)
q = allocate_result(BG, identity_element)
return identity_element!(BG, q)
end
@trait_function identity_element!(G::AbstractDecoratorManifold, p)
function allocate_result(G::AbstractDecoratorManifold, ::typeof(identity_element))
return zeros(representation_size(G)...)
end
@doc raw"""
identity_element(G::AbstractDecoratorManifold, p)
Return a point representation of the [`Identity`](@ref) on the [`IsGroupManifold`](@ref) `G`,
where `p` indicates the type to represent the identity.
"""
identity_element(G::AbstractDecoratorManifold, p)
@trait_function identity_element(G::AbstractDecoratorManifold, p)
function identity_element(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, p)
BG = base_group(G)
q = allocate_result(BG, identity_element, p)
return identity_element!(BG, q)
end
Base.adjoint(e::Identity) = e
function check_size(
::TraitList{<:IsGroupManifold{O}},
M::AbstractDecoratorManifold,
::Identity{O},
) where {O<:AbstractGroupOperation}
return nothing
end
function check_size(::EmptyTrait, M::AbstractDecoratorManifold, e::Identity)
return DomainError(0, "$M seems to not be a group manifold with $e.")
end
@doc raw"""
is_identity(G::AbstractDecoratorManifold, q; kwargs)
Check whether `q` is the identity on the [`IsGroupManifold`](@ref) `G`, i.e. it is either
the [`Identity`](@ref)`{O}` with the corresponding [`AbstractGroupOperation`](@ref) `O`, or
(approximately) the correct point representation.
"""
is_identity(G::AbstractDecoratorManifold, q)
@trait_function is_identity(G::AbstractDecoratorManifold, q; kwargs...)
function is_identity(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
q;
kwargs...,
)
BG = base_group(G)
return isapprox(BG, identity_element(BG), q; kwargs...)
end
function is_identity(
::TraitList{<:IsGroupManifold{O}},
G::AbstractDecoratorManifold,
::Identity{O};
kwargs...,
) where {O<:AbstractGroupOperation}
return true
end
function is_identity(
::TraitList{<:IsGroupManifold},
::AbstractDecoratorManifold,
::Identity;
kwargs...,
)
return false
end
@inline function isapprox(
::TraitList{<:IsGroupManifold{O}},
G::AbstractDecoratorManifold,
p::Identity{O},
q;
kwargs...,
) where {O<:AbstractGroupOperation}
return is_identity(G, q; kwargs...)
end
@inline function isapprox(
::TraitList{<:IsGroupManifold{O}},
G::AbstractDecoratorManifold,
p,
q::Identity{O};
kwargs...,
) where {O<:AbstractGroupOperation}
BG = base_group(G)
return is_identity(BG, p; kwargs...)
end
function isapprox(
::TraitList{<:IsGroupManifold{O}},
G::AbstractDecoratorManifold,
p::Identity{O},
q::Identity{O};
kwargs...,
) where {O<:AbstractGroupOperation}
return true
end
function isapprox(
::TraitList{<:IsGroupManifold{O}},
G::AbstractDecoratorManifold,
p::Identity{O},
q::Identity;
kwargs...,
) where {O<:AbstractGroupOperation}
return false
end
function isapprox(
::TraitList{<:IsGroupManifold{O}},
G::AbstractDecoratorManifold,
p::Identity,
q::Identity{O};
kwargs...,
) where {O<:AbstractGroupOperation}
return false
end
@inline function isapprox(
::TraitList{IsGroupManifold{O}},
G::AbstractDecoratorManifold,
p::Identity{O},
X,
Y;
kwargs...,
) where {O<:AbstractGroupOperation}
BG = base_group(G)
return isapprox(BG, identity_element(BG), X, Y; kwargs...)
end
function isapprox(
::TraitList{<:IsGroupManifold},
::AbstractDecoratorManifold,
::Identity,
::Identity;
kwargs...,
)
return false
end
function Base.show(io::IO, ::Identity{O}) where {O<:AbstractGroupOperation}
return print(io, "Identity($O)")
end
function is_point(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
e::Identity;
error::Symbol=:none,
kwargs...,
)
ie = is_identity(G, e; kwargs...)
if !ie
s = "The provided identity is not a point on $G."
(error === :error) && throw(DomainError(e, s))
(error === :info) && @info s
(error === :warn) && @warn s
end
return ie
end
function is_vector(
t::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
e::Identity,
X,
cbp::Bool=true;
error::Symbol=:none,
kwargs...,
)
if cbp
# pass te down so this throws an error if error=:error
# if error is not `:error` and is_point was false -> return false, otherwise continue
(!is_point(G, e; error=error, kwargs...)) && return false
end
return is_vector(
next_trait(t),
G,
identity_element(G),
X,
false;
error=error,
kwargs...,
)
end
@doc raw"""
adjoint_action(G::AbstractDecoratorManifold, p, X)
Adjoint action of the element `p` of the Lie group `G` on the element `X`
of the corresponding Lie algebra.
It is defined as the differential of the group authomorphism ``Ψ_p(q) = pqp⁻¹`` at
the identity of `G`.
The formula reads
````math
\operatorname{Ad}_p(X) = dΨ_p(e)[X]
````
where ``e`` is the identity element of `G`.
Note that the adjoint representation of a Lie group isn't generally faithful.
Notably the adjoint representation of SO(2) is trivial.
"""
adjoint_action(G::AbstractDecoratorManifold, p, X)
@trait_function adjoint_action(G::AbstractDecoratorManifold, p, Xₑ)
function adjoint_action(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, p, Xₑ)
Xₚ = translate_diff(G, p, Identity(G), Xₑ, LeftForwardAction())
Y = inverse_translate_diff(G, p, p, Xₚ, RightBackwardAction())
return Y
end
@trait_function adjoint_action!(G::AbstractDecoratorManifold, Y, p, Xₑ)
function adjoint_action!(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
Y,
p,
Xₑ,
)
Xₚ = translate_diff(G, p, Identity(G), Xₑ, LeftForwardAction())
inverse_translate_diff!(G, Y, p, p, Xₚ, RightBackwardAction())
return Y
end
function ManifoldDiff.differential_exp_argument_lie_approx!(
M::AbstractManifold,
Z,
p,
X,
Y;
n=20,
)
tmp = copy(M, p, Y)
a = -1.0
zero_vector!(M, Z, p)
for k in 0:n
a *= -1 // (k + 1)
Z .+= a .* tmp
if k < n
copyto!(tmp, lie_bracket(M, X, tmp))
end
end
q = exp(M, p, X)
translate_diff!(M, Z, q, Identity(M), Z)
return Z
end
@doc raw"""
inv(G::AbstractDecoratorManifold, p)
Inverse ``p^{-1} ∈ \mathcal{G}`` of an element ``p ∈ \mathcal{G}``, such that
``p \circ p^{-1} = p^{-1} \circ p = e ∈ \mathcal{G}``, where ``e`` is the [`Identity`](@ref)
element of ``\mathcal{G}``.
"""
inv(::AbstractDecoratorManifold, ::Any...)
@trait_function Base.inv(G::AbstractDecoratorManifold, p)
function Base.inv(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, p)
q = allocate_result(G, inv, p)
BG = base_group(G)
return inv!(BG, q, p)
end
function Base.inv(
::TraitList{IsGroupManifold{O}},
::AbstractDecoratorManifold,
e::Identity{O},
) where {O<:AbstractGroupOperation}
return e
end
@trait_function inv!(G::AbstractDecoratorManifold, q, p)
function inv!(
::TraitList{IsGroupManifold{O}},
G::AbstractDecoratorManifold,
q,
::Identity{O},
) where {O<:AbstractGroupOperation}
BG = base_group(G)
return identity_element!(BG, q)
end
function inv!(
::TraitList{IsGroupManifold{O}},
G::AbstractDecoratorManifold,
::Identity{O},
e::Identity{O},
) where {O<:AbstractGroupOperation}
return e
end
@doc raw"""
inv_diff(G::AbstractDecoratorManifold, p, X)
Compute the value of differential of inverse ``p^{-1} ∈ \mathcal{G}`` of an element
``p ∈ \mathcal{G}`` at tangent vector `X` at `p`. The result is a tangent vector at ``p^{-1}``.
"""
inv_diff(G::AbstractDecoratorManifold, p)
@trait_function inv_diff(G::AbstractDecoratorManifold, p, X)
function inv_diff(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, p, X)
Y = allocate_result(G, inv_diff, X, p)
return inv_diff!(G, Y, p, X)
end
@trait_function inv_diff!(G::AbstractDecoratorManifold, Y, p, X)
function Base.copyto!(
::TraitList{IsGroupManifold{O}},
::AbstractDecoratorManifold,
e::Identity{O},
::Identity{O},
) where {O<:AbstractGroupOperation}
return e
end
function Base.copyto!(
::TraitList{IsGroupManifold{O}},
G::AbstractDecoratorManifold,
p,
::Identity{O},
) where {O<:AbstractGroupOperation}
BG = base_group(G)
return identity_element!(BG, p)
end
@doc raw"""
compose(G::AbstractDecoratorManifold, p, q)
Compose elements ``p,q ∈ \mathcal{G}`` using the group operation ``p \circ q``.
For implementing composition on a new group manifold, please overload `_compose`
instead so that methods with [`Identity`](@ref) arguments are not ambiguous.
"""
compose(::AbstractDecoratorManifold, ::Any...)
@trait_function compose(G::AbstractDecoratorManifold, p, q)
function compose(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, p, q)
return _compose(base_group(G), p, q)
end
function compose(
::AbstractDecoratorManifold,
::Identity{O},
p,
) where {O<:AbstractGroupOperation}
return p
end
function compose(
::AbstractDecoratorManifold,
p,
::Identity{O},
) where {O<:AbstractGroupOperation}
return p
end
function compose(
::AbstractDecoratorManifold,
e::Identity{O},
::Identity{O},
) where {O<:AbstractGroupOperation}
return e
end
function _compose(G::AbstractDecoratorManifold, p, q)
x = allocate_result(G, compose, p, q)
return _compose!(G, x, p, q)
end
@trait_function compose!(M::AbstractDecoratorManifold, x, p, q)
function compose!(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, x, q, p)
return _compose!(base_group(G), x, q, p)
end
function compose!(
G::AbstractDecoratorManifold,
q,
p,
::Identity{O},
) where {O<:AbstractGroupOperation}
return copyto!(G, q, p)
end
function compose!(
G::AbstractDecoratorManifold,
q,
::Identity{O},
p,
) where {O<:AbstractGroupOperation}
return copyto!(G, q, p)
end
function compose!(
G::AbstractDecoratorManifold,
q,
::Identity{O},
e::Identity{O},
) where {O<:AbstractGroupOperation}
return identity_element!(G, q)
end
function compose!(
::AbstractDecoratorManifold,
e::Identity{O},
::Identity{O},
::Identity{O},
) where {O<:AbstractGroupOperation}
return e
end
Base.transpose(e::Identity) = e
@trait_function hat(M::AbstractDecoratorManifold, e::Identity, X)
@trait_function hat!(M::AbstractDecoratorManifold, Y, e::Identity, X)
@doc raw"""
hat(M::AbstractDecoratorManifold{𝔽,O}, ::Identity{O}, Xⁱ) where {𝔽,O<:AbstractGroupOperation}
Given a basis ``e_i`` on the tangent space at a the [`Identity`](@ref) and tangent
component vector ``X^i``, compute the equivalent vector representation
``X=X^i e_i**, where Einstein summation notation is used:
````math
∧ : X^i ↦ X^i e_i
````
For array manifolds, this converts a vector representation of the tangent
vector to an array representation. The [`vee`](@ref) map is the `hat` map's
inverse.
"""
function hat(
::TraitList{IsGroupManifold{O}},
M::AbstractDecoratorManifold,
::Identity{O},
X,
) where {O<:AbstractGroupOperation}
return get_vector_lie(M, X, VeeOrthogonalBasis())
end
function hat!(
::TraitList{IsGroupManifold{O}},
M::AbstractDecoratorManifold,
Y,
::Identity{O},
X,
) where {O<:AbstractGroupOperation}
return get_vector_lie!(M, Y, X, VeeOrthogonalBasis())
end
function hat(M::AbstractManifold, e::Identity, ::Any)
return throw(ErrorException("On $M there exsists no identity $e"))
end
function hat!(M::AbstractManifold, c, e::Identity, X)
return throw(ErrorException("On $M there exsists no identity $e"))
end
@trait_function vee(M::AbstractDecoratorManifold, e::Identity, X)
@trait_function vee!(M::AbstractDecoratorManifold, Y, e::Identity, X)
@doc raw"""
vee(M::AbstractManifold, p, X)
Given a basis ``e_i`` on the tangent space at a point `p` and tangent
vector `X`, compute the vector components ``X^i``, such that ``X = X^i e_i``, where
Einstein summation notation is used:
````math
\vee : X^i e_i ↦ X^i
````
For array manifolds, this converts an array representation of the tangent
vector to a vector representation. The [`hat`](@ref) map is the `vee` map's
inverse.
"""
function vee(
::TraitList{IsGroupManifold{O}},
M::AbstractDecoratorManifold,
::Identity{O},
X,
) where {O<:AbstractGroupOperation}
return get_coordinates_lie(M, X, VeeOrthogonalBasis())
end
function vee!(
::TraitList{IsGroupManifold{O}},
M::AbstractDecoratorManifold,
Y,
::Identity{O},
X,
) where {O<:AbstractGroupOperation}
return get_coordinates_lie!(M, Y, X, VeeOrthogonalBasis())
end
function vee(M::AbstractManifold, e::Identity, X)
return throw(ErrorException("On $M there exsists no identity $e"))
end
function vee!(M::AbstractManifold, c, e::Identity, X)
return throw(ErrorException("On $M there exsists no identity $e"))
end
"""
lie_bracket(G::AbstractDecoratorManifold, X, Y)
Lie bracket between elements `X` and `Y` of the Lie algebra corresponding to
the Lie group `G`, cf. [`IsGroupManifold`](@ref).
This can be used to compute the adjoint representation of a Lie algebra.
Note that this representation isn't generally faithful. Notably the adjoint
representation of 𝔰𝔬(2) is trivial.
"""
lie_bracket(G::AbstractDecoratorManifold, X, Y)
@trait_function lie_bracket(M::AbstractDecoratorManifold, X, Y)
@trait_function lie_bracket!(M::AbstractDecoratorManifold, Z, X, Y)
_action_order(BG::AbstractDecoratorManifold, p, q, ::LeftForwardAction) = (p, q)
_action_order(BG::AbstractDecoratorManifold, p, q, ::LeftBackwardAction) = (q, inv(BG, p))
_action_order(BG::AbstractDecoratorManifold, p, q, ::RightForwardAction) = (inv(BG, p), q)
_action_order(BG::AbstractDecoratorManifold, p, q, ::RightBackwardAction) = (q, p)
@doc raw"""
translate(G::AbstractDecoratorManifold, p, q, conv::ActionDirectionAndSide=LeftForwardAction()])
Translate group element ``q`` by ``p`` with the translation ``τ_p`` with the specified
`conv`ention, either left forward (``L_p``), left backward (``R'_p``), right backward (``R_p``)
or right forward (``L'_p``), defined as
```math
\begin{aligned}
L_p &: q ↦ p \circ q\\
L'_p &: q ↦ p^{-1} \circ q\\
R_p &: q ↦ q \circ p\\
R'_p &: q ↦ q \circ p^{-1}.
\end{aligned}
```
"""
translate(::AbstractDecoratorManifold, ::Any...)
@trait_function translate(
G::AbstractDecoratorManifold,
p,
q,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
function translate(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
p,
q,
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return compose(BG, _action_order(BG, p, q, conv)...)
end
@trait_function translate!(
G::AbstractDecoratorManifold,
X,
p,
q,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
function translate!(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
X,
p,
q,
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return compose!(BG, X, _action_order(BG, p, q, conv)...)
end
@doc raw"""
inverse_translate(G::AbstractDecoratorManifold, p, q, conv::ActionDirectionAndSide=LeftForwardAction())
Inverse translate group element ``q`` by ``p`` with the translation ``τ_p^{-1}``
with the specified `conv`ention, either left forward (``L_p^{-1}``), left backward
(``R'_p^{-1}``), right backward (``R_p^{-1}``) or right forward (``L'_p^{-1}``), defined as
```math
\begin{aligned}
L_p^{-1} &: q ↦ p^{-1} \circ q\\
L'_p^{-1} &: q ↦ p \circ q\\
R_p^{-1} &: q ↦ q \circ p^{-1}\\
R'_p^{-1} &: q ↦ q \circ p.
\end{aligned}
"""
inverse_translate(::AbstractDecoratorManifold, ::Any...)
@trait_function inverse_translate(
G::AbstractDecoratorManifold,
p,
q,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
function inverse_translate(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
p,
q,
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return translate(BG, inv(BG, p), q, conv)
end
@trait_function inverse_translate!(
G::AbstractDecoratorManifold,
X,
p,
q,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
function inverse_translate!(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
X,
p,
q,
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return translate!(BG, X, inv(BG, p), q, conv)
end
@doc raw"""
translate_diff(G::AbstractDecoratorManifold, p, q, X, conv::ActionDirectionAndSide=LeftForwardAction())
For group elements ``p, q ∈ \mathcal{G}`` and tangent vector ``X ∈ T_q \mathcal{G}``, compute
the action of the differential of the translation ``τ_p`` by ``p`` on ``X``, with the specified
left or right `conv`ention. The differential transports vectors:
```math
(\mathrm{d}τ_p)_q : T_q \mathcal{G} → T_{τ_p q} \mathcal{G}\\
```
"""
translate_diff(::AbstractDecoratorManifold, ::Any...)
@trait_function translate_diff(
G::AbstractDecoratorManifold,
p,
q,
X,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
function translate_diff(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
p,
q,
X,
conv::ActionDirectionAndSide,
)
Y = allocate_result(G, translate_diff, X, p, q)
BG = base_group(G)
translate_diff!(BG, Y, p, q, X, conv)
return Y
end
@trait_function translate_diff!(
G::AbstractDecoratorManifold,
Y,
p,
q,
X,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
@doc raw"""
inverse_translate_diff(G::AbstractDecoratorManifold, p, q, X, conv::ActionDirectionAndSide=LeftForwardAction())
For group elements ``p, q ∈ \mathcal{G}`` and tangent vector ``X ∈ T_q \mathcal{G}``, compute
the action on ``X`` of the differential of the inverse translation ``τ_p`` by ``p``, with the
specified left or right `conv`ention. The differential transports vectors:
```math
(\mathrm{d}τ_p^{-1})_q : T_q \mathcal{G} → T_{τ_p^{-1} q} \mathcal{G}\\
```
"""
inverse_translate_diff(::AbstractDecoratorManifold, ::Any...)
@trait_function inverse_translate_diff(
G::AbstractDecoratorManifold,
p,
q,
X,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
function inverse_translate_diff(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
p,
q,
X,
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return translate_diff(BG, inv(BG, p), q, X, conv)
end
@trait_function inverse_translate_diff!(
G::AbstractDecoratorManifold,
Y,
p,
q,
X,
conv::ActionDirectionAndSide=LeftForwardAction(),
)
function inverse_translate_diff!(
::TraitList{<:IsGroupManifold},
G::AbstractDecoratorManifold,
Y,
p,
q,
X,
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return translate_diff!(BG, Y, inv(BG, p), q, X, conv)
end
@doc raw"""
exp_lie(G, X)
exp_lie!(G, q, X)
Compute the group exponential of the Lie algebra element `X`. It is equivalent to the
exponential map defined by the [`CartanSchoutenMinus`](@ref) connection.
Given an element ``X ∈ 𝔤 = T_e \mathcal{G}``, where ``e`` is the [`Identity`](@ref) element of
the group ``\mathcal{G}``, and ``𝔤`` is its Lie algebra, the group exponential is the map
````math
\exp : 𝔤 → \mathcal{G},
````
such that for ``t,s ∈ ℝ``, ``γ(t) = \exp (t X)`` defines a one-parameter subgroup with the
following properties. Note that one-parameter subgroups are commutative (see [Suhubi:2013](@cite),
section 3.5), even if the Lie group itself is not commutative.
````math
\begin{aligned}
γ(t) &= γ(-t)^{-1}\\
γ(t + s) &= γ(t) \circ γ(s) = γ(s) \circ γ(t)\\
γ(0) &= e\\
\lim_{t → 0} \frac{d}{dt} γ(t) &= X.
\end{aligned}
````
!!! note
In general, the group exponential map is distinct from the Riemannian exponential map
[`exp`](@ref).
For example for the [`MultiplicationOperation`](@ref) and either `Number` or `AbstractMatrix`
the Lie exponential is the numeric/matrix exponential.
````math
\exp X = \operatorname{Exp} X = \sum_{n=0}^∞ \frac{1}{n!} X^n.
````
Since this function also depends on the group operation, make sure to implement
the corresponding trait version `exp_lie(::TraitList{<:IsGroupManifold}, G, X)`.
"""
exp_lie(G::AbstractManifold, X)
@trait_function exp_lie(M::AbstractDecoratorManifold, X)
function exp_lie(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, X)
BG = base_group(G)
q = allocate_result(BG, exp_lie, X)
return exp_lie!(BG, q, X)
end
@trait_function exp_lie!(M::AbstractDecoratorManifold, q, X)
@doc raw"""
log_lie(G, q)
log_lie!(G, X, q)
Compute the Lie group logarithm of the Lie group element `q`. It is equivalent to the
logarithmic map defined by the [`CartanSchoutenMinus`](@ref) connection.