Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

r""" 

Free module automorphisms 

 

Given a free module `M` of finite rank over a commutative ring `R`, an 

*automorphism* of `M` is a map 

 

.. MATH:: 

 

\phi:\ M \longrightarrow M 

 

that is linear (i.e. is a module homomorphism) and bijective. 

 

Automorphisms of a free module of finite rank are implemented via the class 

:class:`FreeModuleAutomorphism`. 

 

AUTHORS: 

 

- Eric Gourgoulhon (2015): initial version 

 

REFERENCES: 

 

- Chaps. 15, 24 of R. Godement: *Algebra* [God1968]_ 

 

""" 

#****************************************************************************** 

# Copyright (C) 2015 Eric Gourgoulhon <eric.gourgoulhon@obspm.fr> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# as published by the Free Software Foundation; either version 2 of 

# the License, or (at your option) any later version. 

# http://www.gnu.org/licenses/ 

#****************************************************************************** 

from __future__ import absolute_import 

from six import itervalues 

 

from sage.structure.element import MultiplicativeGroupElement 

from sage.tensor.modules.free_module_tensor import FreeModuleTensor 

 

class FreeModuleAutomorphism(FreeModuleTensor, MultiplicativeGroupElement): 

r""" 

Automorphism of a free module of finite rank over a commutative ring. 

 

This is a Sage *element* class, the corresponding *parent* class being 

:class:`~sage.tensor.modules.free_module_linear_group.FreeModuleLinearGroup`. 

 

This class inherits from the classes 

:class:`~sage.tensor.modules.free_module_tensor.FreeModuleTensor` 

and 

:class:`~sage.structure.element.MultiplicativeGroupElement`. 

 

INPUT: 

 

- ``fmodule`` -- free module `M` of finite rank over a commutative ring 

`R`, as an instance of 

:class:`~sage.tensor.modules.finite_rank_free_module.FiniteRankFreeModule` 

- ``name`` -- (default: ``None``) name given to the automorphism 

- ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the 

automorphism; if none is provided, the LaTeX symbol is set to ``name`` 

- ``is_identity`` -- (default: ``False``) determines whether the 

constructed object is the identity automorphism, i.e. the identity map 

of `M` considered as an automorphism (the identity element of the 

general linear group) 

 

EXAMPLES: 

 

Automorphism of a rank-2 free module over `\ZZ`:: 

 

sage: M = FiniteRankFreeModule(ZZ, 2, name='M', start_index=1) 

sage: a = M.automorphism(name='a', latex_name=r'\alpha') ; a 

Automorphism a of the Rank-2 free module M over the Integer Ring 

sage: a.parent() 

General linear group of the Rank-2 free module M over the Integer Ring 

sage: a.parent() is M.general_linear_group() 

True 

sage: latex(a) 

\alpha 

 

Setting the components of ``a`` w.r.t. a basis of module ``M``:: 

 

sage: e = M.basis('e') ; e 

Basis (e_1,e_2) on the Rank-2 free module M over the Integer Ring 

sage: a[:] = [[1,2],[1,3]] 

sage: a.matrix(e) 

[1 2] 

[1 3] 

sage: a(e[1]).display() 

a(e_1) = e_1 + e_2 

sage: a(e[2]).display() 

a(e_2) = 2 e_1 + 3 e_2 

 

Actually, the components w.r.t. a given basis can be specified at the 

construction of the object:: 

 

sage: a = M.automorphism(matrix=[[1,2],[1,3]], basis=e, name='a', 

....: latex_name=r'\alpha') ; a 

Automorphism a of the Rank-2 free module M over the Integer Ring 

sage: a.matrix(e) 

[1 2] 

[1 3] 

 

Since e is the module's default basis, it can be omitted in the argument 

list:: 

 

sage: a == M.automorphism(matrix=[[1,2],[1,3]], name='a', 

....: latex_name=r'\alpha') 

True 

 

The matrix of the automorphism can be obtained in any basis:: 

 

sage: f = M.basis('f', from_family=(3*e[1]+4*e[2], 5*e[1]+7*e[2])) ; f 

Basis (f_1,f_2) on the Rank-2 free module M over the Integer Ring 

sage: a.matrix(f) 

[2 3] 

[1 2] 

 

Automorphisms are tensors of type `(1,1)`:: 

 

sage: a.tensor_type() 

(1, 1) 

sage: a.tensor_rank() 

2 

 

In particular, they can be displayed as such:: 

 

sage: a.display(e) 

a = e_1*e^1 + 2 e_1*e^2 + e_2*e^1 + 3 e_2*e^2 

sage: a.display(f) 

a = 2 f_1*f^1 + 3 f_1*f^2 + f_2*f^1 + 2 f_2*f^2 

 

The automorphism acting on a module element:: 

 

sage: v = M([-2,3], name='v') ; v 

Element v of the Rank-2 free module M over the Integer Ring 

sage: a(v) 

Element a(v) of the Rank-2 free module M over the Integer Ring 

sage: a(v).display() 

a(v) = 4 e_1 + 7 e_2 

 

A second automorphism of the module ``M``:: 

 

sage: b = M.automorphism([[0,1],[-1,0]], name='b') ; b 

Automorphism b of the Rank-2 free module M over the Integer Ring 

sage: b.matrix(e) 

[ 0 1] 

[-1 0] 

sage: b(e[1]).display() 

b(e_1) = -e_2 

sage: b(e[2]).display() 

b(e_2) = e_1 

 

The composition of automorphisms is performed via the multiplication 

operator:: 

 

sage: s = a*b ; s 

Automorphism of the Rank-2 free module M over the Integer Ring 

sage: s(v) == a(b(v)) 

True 

sage: s.matrix(f) 

[ 11 19] 

[ -7 -12] 

sage: s.matrix(f) == a.matrix(f) * b.matrix(f) 

True 

 

It is not commutative:: 

 

sage: a*b != b*a 

True 

 

In other words, the parent of ``a`` and ``b``, i.e. the group 

`\mathrm{GL}(M)`, is not abelian:: 

 

sage: M.general_linear_group() in CommutativeAdditiveGroups() 

False 

 

The neutral element for the composition law is the module identity map:: 

 

sage: id = M.identity_map() ; id 

Identity map of the Rank-2 free module M over the Integer Ring 

sage: id.parent() 

General linear group of the Rank-2 free module M over the Integer Ring 

sage: id(v) == v 

True 

sage: id.matrix(f) 

[1 0] 

[0 1] 

sage: id*a == a 

True 

sage: a*id == a 

True 

 

The inverse of an automorphism is obtained via the method :meth:`inverse`, 

or the operator ~, or the exponent -1:: 

 

sage: a.inverse() 

Automorphism a^(-1) of the Rank-2 free module M over the Integer Ring 

sage: a.inverse() is ~a 

True 

sage: a.inverse() is a^(-1) 

True 

sage: (a^(-1)).matrix(e) 

[ 3 -2] 

[-1 1] 

sage: a*a^(-1) == id 

True 

sage: a^(-1)*a == id 

True 

sage: a^(-1)*s == b 

True 

sage: (a^(-1))(a(v)) == v 

True 

 

The module's changes of basis are stored as automorphisms:: 

 

sage: M.change_of_basis(e,f) 

Automorphism of the Rank-2 free module M over the Integer Ring 

sage: M.change_of_basis(e,f).parent() 

General linear group of the Rank-2 free module M over the Integer Ring 

sage: M.change_of_basis(e,f).matrix(e) 

[3 5] 

[4 7] 

sage: M.change_of_basis(f,e) == M.change_of_basis(e,f).inverse() 

True 

 

The opposite of an automorphism is still an automorphism:: 

 

sage: -a 

Automorphism -a of the Rank-2 free module M over the Integer Ring 

sage: (-a).parent() 

General linear group of the Rank-2 free module M over the Integer Ring 

sage: (-a).matrix(e) == - (a.matrix(e)) 

True 

 

Adding two automorphisms results in a generic type-`(1,1)` tensor:: 

 

sage: s = a + b ; s 

Type-(1,1) tensor a+b on the Rank-2 free module M over the Integer Ring 

sage: s.parent() 

Free module of type-(1,1) tensors on the Rank-2 free module M over the 

Integer Ring 

sage: a[:], b[:], s[:] 

( 

[1 2] [ 0 1] [1 3] 

[1 3], [-1 0], [0 3] 

) 

 

To get the result as an endomorphism, one has to explicitely convert it via 

the parent of endomorphisms, `\mathrm{End}(M)`:: 

 

sage: s = End(M)(a+b) ; s 

Generic endomorphism of Rank-2 free module M over the Integer Ring 

sage: s(v) == a(v) + b(v) 

True 

sage: s.matrix(e) == a.matrix(e) + b.matrix(e) 

True 

sage: s.matrix(f) == a.matrix(f) + b.matrix(f) 

True 

 

""" 

def __init__(self, fmodule, name=None, latex_name=None, is_identity=False): 

r""" 

TESTS:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M') 

sage: e = M.basis('e') 

sage: from sage.tensor.modules.free_module_automorphism import FreeModuleAutomorphism 

sage: a = FreeModuleAutomorphism(M, name='a') 

sage: a[e,:] = [[-1,0,0],[0,1,2],[0,1,3]] 

sage: TestSuite(a).run(skip="_test_category") # see below 

 

In the above test suite, _test_category fails because a is not an 

instance of a.parent().category().element_class. Actually automorphism 

must be constructed via FreeModuleLinearGroup.element_class and 

not by a direct call to FreeModuleAutomorphism:: 

 

sage: a = M.general_linear_group().element_class(M, name='a') 

sage: a[e,:] = [[-1,0,0],[0,1,2],[0,1,3]] 

sage: TestSuite(a).run() 

 

Test suite on the identity map:: 

 

sage: id = M.general_linear_group().one() 

sage: TestSuite(id).run() 

 

Test suite on the automorphism obtained as GL.an_element():: 

 

sage: b = M.general_linear_group().an_element() 

sage: TestSuite(b).run() 

 

""" 

if is_identity: 

if name is None: 

name = 'Id' 

if latex_name is None: 

if name == 'Id': 

latex_name = r'\mathrm{Id}' 

else: 

latex_name = name 

FreeModuleTensor.__init__(self, fmodule, (1,1), name=name, 

latex_name=latex_name, 

parent=fmodule.general_linear_group()) 

# MultiplicativeGroupElement attributes: 

# - none 

# Local attributes: 

self._is_identity = is_identity 

self._inverse = None # inverse automorphism not set yet 

self._matrices = {} 

 

#### SageObject methods #### 

 

def _repr_(self): 

r""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: M = FiniteRankFreeModule(QQ, 3, name='M') 

sage: M.automorphism() 

Automorphism of the 3-dimensional vector space M over the Rational Field 

sage: M.automorphism(name='a') 

Automorphism a of the 3-dimensional vector space M over the Rational Field 

sage: M.identity_map() 

Identity map of the 3-dimensional vector space M over the Rational Field 

 

""" 

if self._is_identity: 

description = "Identity map " 

else: 

description = "Automorphism " 

if self._name is not None: 

description += self._name + " " 

description += "of the {}".format(self._fmodule) 

return description 

 

#### End of SageObject methods #### 

 

#### FreeModuleTensor methods #### 

 

def _new_instance(self): 

r""" 

Create an instance of the same class as ``self``. 

 

EXAMPLES:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M') 

sage: a = M.automorphism(name='a') 

sage: a._new_instance() 

Automorphism of the Rank-3 free module M over the Integer Ring 

sage: Id = M.identity_map() 

sage: Id._new_instance() 

Automorphism of the Rank-3 free module M over the Integer Ring 

 

""" 

return self.__class__(self._fmodule) 

 

def _del_derived(self): 

r""" 

Delete the derived quantities. 

 

EXAMPLES:: 

 

sage: M = FiniteRankFreeModule(QQ, 3, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism(name='a') 

sage: a[e,:] = [[1,0,-1], [0,3,0], [0,0,2]] 

sage: b = a.inverse() 

sage: a._inverse 

Automorphism a^(-1) of the 3-dimensional vector space M over the 

Rational Field 

sage: a._del_derived() 

sage: a._inverse # has been reset to None 

 

""" 

# First delete the derived quantities pertaining to FreeModuleTensor: 

FreeModuleTensor._del_derived(self) 

# Then reset the inverse automorphism to None: 

if self._inverse is not None: 

self._inverse._inverse = None # (it was set to self) 

self._inverse = None 

# and delete the matrices: 

self._matrices.clear() 

 

def _new_comp(self, basis): 

r""" 

Create some (uninitialized) components of ``self`` in a given basis. 

 

INPUT: 

 

- ``basis`` -- basis of the free module on which ``self`` is defined 

 

OUTPUT: 

 

- an instance of :class:`~sage.tensor.modules.comp.Components` or, 

if ``self`` is the identity, of the subclass 

:class:`~sage.tensor.modules.comp.KroneckerDelta` 

 

EXAMPLES:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism() 

sage: a._new_comp(e) 

2-indices components w.r.t. Basis (e_0,e_1,e_2) on the Rank-3 free 

module M over the Integer Ring 

sage: id = M.identity_map() 

sage: id._new_comp(e) 

Kronecker delta of size 3x3 

sage: type(id._new_comp(e)) 

<class 'sage.tensor.modules.comp.KroneckerDelta'> 

 

""" 

from .comp import KroneckerDelta 

if self._is_identity: 

fmodule = self._fmodule 

return KroneckerDelta(fmodule._ring, basis, 

start_index=fmodule._sindex, 

output_formatter=fmodule._output_formatter) 

return FreeModuleTensor._new_comp(self, basis) 

 

 

def components(self, basis=None, from_basis=None): 

r""" 

Return the components of ``self`` w.r.t to a given module basis. 

 

If the components are not known already, they are computed by the 

tensor change-of-basis formula from components in another basis. 

 

INPUT: 

 

- ``basis`` -- (default: ``None``) basis in which the components are 

required; if none is provided, the components are assumed to refer 

to the module's default basis 

- ``from_basis`` -- (default: ``None``) basis from which the 

required components are computed, via the tensor change-of-basis 

formula, if they are not known already in the basis ``basis``; 

if none, a basis from which both the components and a change-of-basis 

to ``basis`` are known is selected. 

 

OUTPUT: 

 

- components in the basis ``basis``, as an instance of the 

class :class:`~sage.tensor.modules.comp.Components`, 

or, for the identity automorphism, of the subclass 

:class:`~sage.tensor.modules.comp.KroneckerDelta` 

 

EXAMPLES: 

 

Components of an automorphism on a rank-3 free `\ZZ`-module:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M', start_index=1) 

sage: e = M.basis('e') 

sage: a = M.automorphism([[-1,0,0],[0,1,2],[0,1,3]], name='a') 

sage: a.components(e) 

2-indices components w.r.t. Basis (e_1,e_2,e_3) on the Rank-3 free 

module M over the Integer Ring 

sage: a.components(e)[:] 

[-1 0 0] 

[ 0 1 2] 

[ 0 1 3] 

 

Since e is the module's default basis, it can be omitted:: 

 

sage: a.components() is a.components(e) 

True 

 

A shortcut is ``a.comp()``:: 

 

sage: a.comp() is a.components() 

True 

sage: a.comp(e) is a.components() 

True 

 

Components in another basis:: 

 

sage: f1 = -e[2] 

sage: f2 = 4*e[1] + 3*e[3] 

sage: f3 = 7*e[1] + 5*e[3] 

sage: f = M.basis('f', from_family=(f1,f2,f3)) 

sage: a.components(f) 

2-indices components w.r.t. Basis (f_1,f_2,f_3) on the Rank-3 free 

module M over the Integer Ring 

sage: a.components(f)[:] 

[ 1 -6 -10] 

[ -7 83 140] 

[ 4 -48 -81] 

 

Some check of the above matrix:: 

 

sage: a(f[1]).display(f) 

a(f_1) = f_1 - 7 f_2 + 4 f_3 

sage: a(f[2]).display(f) 

a(f_2) = -6 f_1 + 83 f_2 - 48 f_3 

sage: a(f[3]).display(f) 

a(f_3) = -10 f_1 + 140 f_2 - 81 f_3 

 

Components of the identity map:: 

 

sage: id = M.identity_map() 

sage: id.components(e) 

Kronecker delta of size 3x3 

sage: id.components(e)[:] 

[1 0 0] 

[0 1 0] 

[0 0 1] 

sage: id.components(f) 

Kronecker delta of size 3x3 

sage: id.components(f)[:] 

[1 0 0] 

[0 1 0] 

[0 0 1] 

 

""" 

if self._is_identity: 

if basis is None: 

basis = self._fmodule._def_basis 

if basis not in self._components: 

self._components[basis] = self._new_comp(basis) 

return self._components[basis] 

else: 

return FreeModuleTensor.components(self, basis=basis, 

from_basis=from_basis) 

 

comp = components 

 

def set_comp(self, basis=None): 

r""" 

Return the components of ``self`` w.r.t. a given module basis for 

assignment. 

 

The components with respect to other bases are deleted, in order to 

avoid any inconsistency. To keep them, use the method :meth:`add_comp` 

instead. 

 

INPUT: 

 

- ``basis`` -- (default: ``None``) basis in which the components are 

defined; if none is provided, the components are assumed to refer to 

the module's default basis 

 

OUTPUT: 

 

- components in the given basis, as an instance of the 

class :class:`~sage.tensor.modules.comp.Components`; if such 

components did not exist previously, they are created. 

 

EXAMPLES: 

 

Setting the components of an automorphism of a rank-3 free 

`\ZZ`-module:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism(name='a') 

sage: a.set_comp(e) 

2-indices components w.r.t. Basis (e_0,e_1,e_2) on the Rank-3 free 

module M over the Integer Ring 

sage: a.set_comp(e)[:] = [[1,0,0],[0,1,2],[0,1,3]] 

sage: a.matrix(e) 

[1 0 0] 

[0 1 2] 

[0 1 3] 

 

Since ``e`` is the module's default basis, one has:: 

 

sage: a.set_comp() is a.set_comp(e) 

True 

 

The method :meth:`set_comp` can be used to modify a single component:: 

 

sage: a.set_comp(e)[0,0] = -1 

sage: a.matrix(e) 

[-1 0 0] 

[ 0 1 2] 

[ 0 1 3] 

 

A short cut to :meth:`set_comp` is the bracket operator, with the basis 

as first argument:: 

 

sage: a[e,:] = [[1,0,0],[0,-1,2],[0,1,-3]] 

sage: a.matrix(e) 

[ 1 0 0] 

[ 0 -1 2] 

[ 0 1 -3] 

sage: a[e,0,0] = -1 

sage: a.matrix(e) 

[-1 0 0] 

[ 0 -1 2] 

[ 0 1 -3] 

 

The call to :meth:`set_comp` erases the components previously defined 

in other bases; to keep them, use the method :meth:`add_comp` instead:: 

 

sage: f = M.basis('f', from_family=(-e[0], 3*e[1]+4*e[2], 

....: 5*e[1]+7*e[2])) ; f 

Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer 

Ring 

sage: a._components 

{Basis (e_0,e_1,e_2) on the Rank-3 free module M over the Integer 

Ring: 2-indices components w.r.t. Basis (e_0,e_1,e_2) on the 

Rank-3 free module M over the Integer Ring} 

sage: a.set_comp(f)[:] = [[-1,0,0], [0,1,0], [0,0,-1]] 

 

The components w.r.t. basis ``e`` have been erased:: 

 

sage: a._components 

{Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer 

Ring: 2-indices components w.r.t. Basis (f_0,f_1,f_2) on the 

Rank-3 free module M over the Integer Ring} 

 

Of course, they can be computed from those in basis ``f`` by means of 

a change-of-basis formula, via the method :meth:`comp` or 

:meth:`matrix`:: 

 

sage: a.matrix(e) 

[ -1 0 0] 

[ 0 41 -30] 

[ 0 56 -41] 

 

For the identity map, it is not permitted to set components:: 

 

sage: id = M.identity_map() 

sage: id.set_comp(e) 

Traceback (most recent call last): 

... 

TypeError: the components of the identity map cannot be changed 

 

Indeed, the components are automatically set by a call to 

:meth:`comp`:: 

 

sage: id.comp(e) 

Kronecker delta of size 3x3 

sage: id.comp(f) 

Kronecker delta of size 3x3 

 

""" 

if self._is_identity: 

raise TypeError("the components of the identity map cannot be " + 

"changed") 

else: 

return FreeModuleTensor.set_comp(self, basis=basis) 

 

def add_comp(self, basis=None): 

r""" 

 

Return the components of ``self`` w.r.t. a given module basis for 

assignment, keeping the components w.r.t. other bases. 

 

To delete the components w.r.t. other bases, use the method 

:meth:`set_comp` instead. 

 

INPUT: 

 

- ``basis`` -- (default: ``None``) basis in which the components are 

defined; if none is provided, the components are assumed to refer to 

the module's default basis 

 

.. WARNING:: 

 

If the automorphism has already components in other bases, it 

is the user's responsability to make sure that the components 

to be added are consistent with them. 

 

OUTPUT: 

 

- components in the given basis, as an instance of the 

class :class:`~sage.tensor.modules.comp.Components`; 

if such components did not exist previously, they are created 

 

EXAMPLES: 

 

Adding components to an automorphism of a rank-3 free 

`\ZZ`-module:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism(name='a') 

sage: a[e,:] = [[1,0,0],[0,-1,2],[0,1,-3]] 

sage: f = M.basis('f', from_family=(-e[0], 3*e[1]+4*e[2], 

....: 5*e[1]+7*e[2])) ; f 

Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer 

Ring 

sage: a.add_comp(f)[:] = [[1,0,0], [0, 80, 143], [0, -47, -84]] 

 

The components in basis ``e`` have been kept:: 

 

sage: a._components # random (dictionary output) 

{Basis (e_0,e_1,e_2) on the Rank-3 free module M over the Integer 

Ring: 2-indices components w.r.t. Basis (e_0,e_1,e_2) on the 

Rank-3 free module M over the Integer Ring, 

Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer 

Ring: 2-indices components w.r.t. Basis (f_0,f_1,f_2) on the 

Rank-3 free module M over the Integer Ring} 

 

For the identity map, it is not permitted to invoke :meth:`add_comp`:: 

 

sage: id = M.identity_map() 

sage: id.add_comp(e) 

Traceback (most recent call last): 

... 

TypeError: the components of the identity map cannot be changed 

 

Indeed, the components are automatically set by a call to 

:meth:`comp`:: 

 

sage: id.comp(e) 

Kronecker delta of size 3x3 

sage: id.comp(f) 

Kronecker delta of size 3x3 

 

""" 

if self._is_identity: 

raise TypeError("the components of the identity map cannot be " + 

"changed") 

else: 

return FreeModuleTensor.add_comp(self, basis=basis) 

 

def __call__(self, *arg): 

r""" 

Redefinition of :meth:`FreeModuleTensor.__call__` to allow for a single 

argument (module element). 

 

EXAMPLES: 

 

Call with a single argument: return a module element:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M', start_index=1) 

sage: e = M.basis('e') 

sage: a = M.automorphism([[-1,0,0],[0,1,2],[0,1,3]], name='a') 

sage: v = M([2,1,4], name='v') 

sage: s = a.__call__(v) ; s 

Element a(v) of the Rank-3 free module M over the Integer Ring 

sage: s.display() 

a(v) = -2 e_1 + 9 e_2 + 13 e_3 

sage: s == a(v) 

True 

sage: s == a.contract(v) 

True 

 

Call with two arguments (:class:`FreeModuleTensor` behaviour): return a 

scalar:: 

 

sage: b = M.linear_form(name='b') 

sage: b[:] = 7, 0, 2 

sage: a.__call__(b,v) 

12 

sage: a(b,v) == a.__call__(b,v) 

True 

sage: a(b,v) == s(b) 

True 

 

Identity map with a single argument: return a module element:: 

 

sage: id = M.identity_map() 

sage: s = id.__call__(v) ; s 

Element v of the Rank-3 free module M over the Integer Ring 

sage: s == v 

True 

sage: s == id(v) 

True 

sage: s == id.contract(v) 

True 

 

Identity map with two arguments (:class:`FreeModuleTensor` behaviour): 

return a scalar:: 

 

sage: id.__call__(b,v) 

22 

sage: id(b,v) == id.__call__(b,v) 

True 

sage: id(b,v) == b(v) 

True 

 

""" 

from .free_module_element import FiniteRankFreeModuleElement 

if len(arg) > 1: 

# The automorphism acting as a type-(1,1) tensor on a pair 

# (linear form, module element), returning a scalar: 

if self._is_identity: 

if len(arg) != 2: 

raise TypeError("wrong number of arguments") 

linform = arg[0] 

if linform._tensor_type != (0,1): 

raise TypeError("the first argument must be a linear form") 

vector = arg[1] 

if not isinstance(vector, FiniteRankFreeModuleElement): 

raise TypeError("the second argument must be a module" + 

" element") 

return linform(vector) 

else: # self is not the identity automorphism: 

return FreeModuleTensor.__call__(self, *arg) 

# The automorphism acting as such, on a module element, returning a 

# module element: 

vector = arg[0] 

if not isinstance(vector, FiniteRankFreeModuleElement): 

raise TypeError("the argument must be an element of a free module") 

if self._is_identity: 

return vector 

basis = self.common_basis(vector) 

t = self._components[basis] 

v = vector._components[basis] 

fmodule = self._fmodule 

result = vector._new_instance() 

for i in fmodule.irange(): 

res = 0 

for j in fmodule.irange(): 

res += t[[i,j]]*v[[j]] 

result.set_comp(basis)[i] = res 

# Name of the output: 

result._name = None 

if self._name is not None and vector._name is not None: 

result._name = self._name + "(" + vector._name + ")" 

# LaTeX symbol for the output: 

result._latex_name = None 

if self._latex_name is not None and vector._latex_name is not None: 

result._latex_name = self._latex_name + r"\left(" + \ 

vector._latex_name + r"\right)" 

return result 

 

#### End of FreeModuleTensor methods #### 

 

#### MultiplicativeGroupElement methods #### 

 

def __invert__(self): 

r""" 

Return the inverse automorphism. 

 

OUTPUT: 

 

- instance of :class:`FreeModuleAutomorphism` representing the 

automorphism that is the inverse of ``self``. 

 

EXAMPLES: 

 

Inverse of an automorphism of a rank-3 free module:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism(name='a') 

sage: a[e,:] = [[1,0,0],[0,-1,2],[0,1,-3]] 

sage: a.inverse() 

Automorphism a^(-1) of the Rank-3 free module M over the Integer 

Ring 

sage: a.inverse().parent() 

General linear group of the Rank-3 free module M over the Integer 

Ring 

 

Check that ``a.inverse()`` is indeed the inverse automorphism:: 

 

sage: a.inverse() * a 

Identity map of the Rank-3 free module M over the Integer Ring 

sage: a * a.inverse() 

Identity map of the Rank-3 free module M over the Integer Ring 

sage: a.inverse().inverse() == a 

True 

 

Another check is:: 

 

sage: a.inverse().matrix(e) 

[ 1 0 0] 

[ 0 -3 -2] 

[ 0 -1 -1] 

sage: a.inverse().matrix(e) == (a.matrix(e))^(-1) 

True 

 

The inverse is cached (as long as ``a`` is not modified):: 

 

sage: a.inverse() is a.inverse() 

True 

 

If ``a`` is modified, the inverse is automatically recomputed:: 

 

sage: a[0,0] = -1 

sage: a.matrix(e) 

[-1 0 0] 

[ 0 -1 2] 

[ 0 1 -3] 

sage: a.inverse().matrix(e) # compare with above 

[-1 0 0] 

[ 0 -3 -2] 

[ 0 -1 -1] 

 

Shortcuts for :meth:`inverse` are the operator ``~`` and the exponent 

``-1``:: 

 

sage: ~a is a.inverse() 

True 

sage: a^(-1) is a.inverse() 

True 

 

The inverse of the identity map is of course itself:: 

 

sage: id = M.identity_map() 

sage: id.inverse() is id 

True 

 

and we have:: 

 

sage: a*a^(-1) == id 

True 

sage: a^(-1)*a == id 

True 

 

""" 

from sage.matrix.constructor import matrix 

from .comp import Components 

if self._is_identity: 

return self 

if self._inverse is None: 

if self._name is None: 

inv_name = None 

else: 

inv_name = self._name + '^(-1)' 

if self._latex_name is None: 

inv_latex_name = None 

else: 

inv_latex_name = self._latex_name + r'^{-1}' 

fmodule = self._fmodule 

si = fmodule._sindex 

nsi = fmodule._rank + si 

self._inverse = self.__class__(fmodule, inv_name, inv_latex_name) 

for basis in self._components: 

try: 

mat = self.matrix(basis) 

except (KeyError, ValueError): 

continue 

mat_inv = mat.inverse() 

cinv = Components(fmodule._ring, basis, 2, start_index=si, 

output_formatter=fmodule._output_formatter) 

for i in range(si, nsi): 

for j in range(si, nsi): 

cinv[i, j] = mat_inv[i-si,j-si] 

self._inverse._components[basis] = cinv 

self._inverse._inverse = self 

return self._inverse 

 

inverse = __invert__ 

 

def _mul_(self, other): 

r""" 

Automorphism composition. 

 

This implements the group law of GL(M), M being the module of ``self``. 

 

INPUT: 

 

- ``other`` -- an automorphism of the same module as ``self`` 

 

OUTPUT: 

 

- the automorphism resulting from the composition of ``other`` and 

``self.`` 

 

EXAMPLES:: 

 

sage: M = FiniteRankFreeModule(ZZ, 2, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism([[1,2],[1,3]]) 

sage: b = M.automorphism([[3,4],[5,7]]) 

sage: c = a._mul_(b) ; c 

Automorphism of the Rank-2 free module M over the Integer Ring 

sage: c.matrix() 

[13 18] 

[18 25] 

 

TESTS:: 

 

sage: c.parent() is a.parent() 

True 

sage: c.matrix() == a.matrix() * b.matrix() 

True 

sage: c(e[0]) == a(b(e[0])) 

True 

sage: c(e[1]) == a(b(e[1])) 

True 

sage: a.inverse()._mul_(c) == b 

True 

sage: c._mul_(b.inverse()) == a 

True 

sage: id = M.identity_map() 

sage: id._mul_(a) == a 

True 

sage: a._mul_(id) == a 

True 

sage: a._mul_(a.inverse()) == id 

True 

sage: a.inverse()._mul_(a) == id 

True 

 

""" 

# No need for consistency check since self and other are guaranted 

# to have the same parent. In particular, they are defined on the same 

# free module. 

# 

# Special cases: 

if self._is_identity: 

return other 

if other._is_identity: 

return self 

if other is self._inverse or self is other._inverse: 

return self._fmodule.identity_map() 

# General case: 

fmodule = self._fmodule 

resu = self.__class__(fmodule) 

basis = self.common_basis(other) 

if basis is None: 

raise ValueError("no common basis for the composition") 

# The composition is performed as a tensor contraction of the last 

# index of self (position=1) and the first index of other (position=0): 

resu._components[basis] = self._components[basis].contract(1, 

other._components[basis],0) 

return resu 

 

#### End of MultiplicativeGroupElement methods #### 

 

def __mul__(self, other): 

r""" 

Redefinition of 

:meth:`~sage.tensor.modules.free_module_tensor.FreeModuleTensor.__mul__` 

so that * dispatches either to automorphism composition or to the 

tensor product. 

 

EXAMPLES: 

 

Automorphism composition:: 

 

sage: M = FiniteRankFreeModule(ZZ, 2, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism([[1,2],[1,3]]) 

sage: b = M.automorphism([[3,4],[5,7]]) 

sage: s = a*b ; s 

Automorphism of the Rank-2 free module M over the Integer Ring 

sage: s.matrix() 

[13 18] 

[18 25] 

sage: s.matrix() == a.matrix() * b.matrix() 

True 

sage: s(e[0]) == a(b(e[0])) 

True 

sage: s(e[1]) == a(b(e[1])) 

True 

sage: s.display() 

13 e_0*e^0 + 18 e_0*e^1 + 18 e_1*e^0 + 25 e_1*e^1 

 

Tensor product:: 

 

sage: c = M.tensor((1,1)) ; c 

Type-(1,1) tensor on the Rank-2 free module M over the Integer Ring 

sage: c[:] = [[3,4],[5,7]] 

sage: c[:] == b[:] # c and b have the same components 

True 

sage: s = a*c ; s 

Type-(2,2) tensor on the Rank-2 free module M over the Integer Ring 

sage: s.display() 

3 e_0*e_0*e^0*e^0 + 4 e_0*e_0*e^0*e^1 + 6 e_0*e_0*e^1*e^0 

+ 8 e_0*e_0*e^1*e^1 + 5 e_0*e_1*e^0*e^0 + 7 e_0*e_1*e^0*e^1 

+ 10 e_0*e_1*e^1*e^0 + 14 e_0*e_1*e^1*e^1 + 3 e_1*e_0*e^0*e^0 

+ 4 e_1*e_0*e^0*e^1 + 9 e_1*e_0*e^1*e^0 + 12 e_1*e_0*e^1*e^1 

+ 5 e_1*e_1*e^0*e^0 + 7 e_1*e_1*e^0*e^1 + 15 e_1*e_1*e^1*e^0 

+ 21 e_1*e_1*e^1*e^1 

 

TESTS:: 

 

sage: M = FiniteRankFreeModule(ZZ, 2, name='M', start_index=1) 

sage: e = M.basis('e') 

sage: a = M.automorphism([[1,2],[1,3]], name='a') 

sage: b = M.automorphism([[0,1],[-1,0]], name='b') 

sage: mat_a0 = a.matrix(e) 

sage: a *= b 

sage: a.matrix(e) == mat_a0 * b.matrix(e) 

True 

""" 

if isinstance(other, FreeModuleAutomorphism): 

return self._mul_(other) # general linear group law 

else: 

return FreeModuleTensor.__mul__(self, other) # tensor product 

 

def matrix(self, basis1=None, basis2=None): 

r""" 

Return the matrix of ``self`` w.r.t to a pair of bases. 

 

If the matrix is not known already, it is computed from the matrix in 

another pair of bases by means of the change-of-basis formula. 

 

INPUT: 

 

- ``basis1`` -- (default: ``None``) basis of the free module on which 

``self`` is defined; if none is provided, the module's default basis 

is assumed 

- ``basis2`` -- (default: ``None``) basis of the free module on which 

``self`` is defined; if none is provided, ``basis2`` is set to 

``basis1`` 

 

OUTPUT: 

 

- the matrix representing the automorphism ``self`` w.r.t 

to bases ``basis1`` and ``basis2``; more precisely, the columns of 

this matrix are formed by the components w.r.t. ``basis2`` of 

the images of the elements of ``basis1``. 

 

EXAMPLES: 

 

Matrices of an automorphism of a rank-3 free `\ZZ`-module:: 

 

sage: M = FiniteRankFreeModule(ZZ, 3, name='M', start_index=1) 

sage: e = M.basis('e') 

sage: a = M.automorphism([[-1,0,0],[0,1,2],[0,1,3]], name='a') 

sage: a.matrix(e) 

[-1 0 0] 

[ 0 1 2] 

[ 0 1 3] 

sage: a.matrix() 

[-1 0 0] 

[ 0 1 2] 

[ 0 1 3] 

sage: f = M.basis('f', from_family=(-e[2], 4*e[1]+3*e[3], 7*e[1]+5*e[3])) ; f 

Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring 

sage: a.matrix(f) 

[ 1 -6 -10] 

[ -7 83 140] 

[ 4 -48 -81] 

 

Check of the above matrix:: 

 

sage: a(f[1]).display(f) 

a(f_1) = f_1 - 7 f_2 + 4 f_3 

sage: a(f[2]).display(f) 

a(f_2) = -6 f_1 + 83 f_2 - 48 f_3 

sage: a(f[3]).display(f) 

a(f_3) = -10 f_1 + 140 f_2 - 81 f_3 

 

Check of the change-of-basis formula:: 

 

sage: P = M.change_of_basis(e,f).matrix(e) 

sage: a.matrix(f) == P^(-1) * a.matrix(e) * P 

True 

 

Check that the matrix of the product of two automorphisms is the 

product of their matrices:: 

 

sage: b = M.change_of_basis(e,f) ; b 

Automorphism of the Rank-3 free module M over the Integer Ring 

sage: b.matrix(e) 

[ 0 4 7] 

[-1 0 0] 

[ 0 3 5] 

sage: (a*b).matrix(e) == a.matrix(e) * b.matrix(e) 

True 

 

Check that the matrix of the inverse automorphism is the inverse of the 

automorphism's matrix:: 

 

sage: (~a).matrix(e) 

[-1 0 0] 

[ 0 3 -2] 

[ 0 -1 1] 

sage: (~a).matrix(e) == ~(a.matrix(e)) 

True 

 

Matrices of the identity map:: 

 

sage: id = M.identity_map() 

sage: id.matrix(e) 

[1 0 0] 

[0 1 0] 

[0 0 1] 

sage: id.matrix(f) 

[1 0 0] 

[0 1 0] 

[0 0 1] 

 

""" 

from sage.matrix.constructor import matrix 

fmodule = self._fmodule 

if basis1 is None: 

basis1 = fmodule.default_basis() 

elif basis1 not in fmodule.bases(): 

raise TypeError("{} is not a basis on the {}".format(basis1, 

fmodule)) 

if basis2 is None: 

basis2 = basis1 

elif basis2 not in fmodule.bases(): 

raise TypeError("{} is not a basis on the {}".format(basis2, 

fmodule)) 

if (basis1, basis2) not in self._matrices: 

if basis2 == basis1: 

comp = self.components(basis1) 

mat = [[comp[[i,j]] for j in fmodule.irange()] 

for i in fmodule.irange()] 

self._matrices[(basis1, basis1)] = matrix(mat) 

else: 

# 1/ determine the matrix w.r.t. basis1: 

self.matrix(basis1) 

# 2/ perform the change (basis1, basis1) --> (basis1, basis2): 

raise NotImplementedError("basis1 != basis2 not implemented yet") 

return self._matrices[(basis1, basis2)] 

 

def det(self): 

r""" 

Return the determinant of ``self``. 

 

OUTPUT: 

 

- element of the base ring of the module on which ``self`` is defined, 

equal to the determinant of ``self``. 

 

EXAMPLES: 

 

Determinant of an automorphism on a `\ZZ`-module of rank 2:: 

 

sage: M = FiniteRankFreeModule(ZZ, 2, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism([[4,7],[3,5]], name='a') 

sage: a.matrix(e) 

[4 7] 

[3 5] 

sage: a.det() 

-1 

sage: det(a) 

-1 

sage: ~a.det() # determinant of the inverse automorphism 

-1 

sage: id = M.identity_map() 

sage: id.det() 

1 

 

""" 

self.matrix() # forces the update of the matrix in the module's default 

# basis, to make sure that the dictionary self._matrices 

# is not empty 

return next(itervalues(self._matrices)).det() # pick a random value in the 

# dictionary self._matrices 

# and compute the determinant 

 

def trace(self): 

r""" 

Return the trace of ``self``. 

 

OUTPUT: 

 

- element of the base ring of the module on which ``self`` is defined, 

equal to the trace of ``self``. 

 

EXAMPLES: 

 

Trace of an automorphism on a `\ZZ`-module of rank 2:: 

 

sage: M = FiniteRankFreeModule(ZZ, 2, name='M') 

sage: e = M.basis('e') 

sage: a = M.automorphism([[4,7],[3,5]], name='a') 

sage: a.matrix(e) 

[4 7] 

[3 5] 

sage: a.trace() 

9 

sage: id = M.identity_map() 

sage: id.trace() 

2 

 

""" 

self.matrix() # forces the update of the matrix in the module's default 

# basis, to make sure that the dictionary self._matrices 

# is not empty 

return next(itervalues(self._matrices)).trace() # pick a random value in the 

# dictionary self._matrices 

# and compute the trace