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

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

"Genus" 

 

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

# Copyright (C) 2007 David Kohel <kohel@maths.usyd.edu.au> 

# Gabriele Nebe <nebe@math.rwth-aachen.de> 

# 

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

# 

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

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

from __future__ import print_function 

 

from sage.misc.all import prod 

from sage.arith.all import LCM 

from sage.matrix.matrix_space import MatrixSpace 

from sage.rings.integer_ring import IntegerRing 

from sage.rings.rational_field import RationalField 

from sage.rings.integer import Integer 

from sage.rings.finite_rings.finite_field_constructor import FiniteField 

import copy 

 

def Genus(A): 

r""" 

Given a nonsingular symmetric matrix `A`, return the genus of `A`. 

 

INPUT: 

 

- `A` -- a symmetric matrix with coefficients in `\ZZ` 

 

OUTPUT: 

 

A ``GenusSymbol_global_ring`` object, encoding the Conway-Sloane 

genus symbol of the quadratic form whose Gram matrix is `A`. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import Genus 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: Genus(A) 

Genus of 

[1 1] 

[1 2] 

Genus symbol at 2: [1^2]_2 

""" 

return GenusSymbol_global_ring(A) 

 

 

def LocalGenusSymbol(A,p): 

""" 

Given a nonsingular symmetric matrix A, return the local symbol of A at the prime p. 

 

INPUT: 

 

- A -- a symmetric matrix with coefficients in ZZ 

- p -- an integer prime p > 0 

 

OUTPUT: 

 

A Genus_Symbol_p_adic_ring object, encoding the Conway-Sloane 

genus symbol at p of the quadratic form whose Gram matrix is A. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import LocalGenusSymbol 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: LocalGenusSymbol(A, 2) 

Genus symbol at 2: [1^2]_2 

sage: LocalGenusSymbol(A, 3) 

Genus symbol at 3: 1^2 

 

sage: A = Matrix(ZZ, 2, 2, [1,0,0,2]) 

sage: LocalGenusSymbol(A, 2) 

Genus symbol at 2: [1^1 2^1]_2 

sage: LocalGenusSymbol(A, 3) 

Genus symbol at 3: 1^-2 

""" 

val = A.determinant().valuation(p) 

symbol = p_adic_symbol(A, p, val = val) 

return Genus_Symbol_p_adic_ring(p, symbol) 

 

 

 

def is_GlobalGenus(G): 

""" 

Given a genus symbol G (specified by a collection of local symbols), return 

True in G represents the genus of a global quadratic form or lattice. 

 

INPUT: 

 

- G -- GenusSymbol_global_ring object 

 

OUTPUT: 

 

boolean 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import GenusSymbol_global_ring 

sage: from sage.quadratic_forms.genera.genus import Genus, is_GlobalGenus 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: G = Genus(A) 

sage: is_GlobalGenus(G) 

True 

 

sage: from sage.quadratic_forms.genera.genus import Genus,is_GlobalGenus 

sage: G=Genus(matrix.diagonal([2,2,2,2])) 

sage: G._local_symbols[0]._symbol=[[0,2,3,0,0],[1,2,5,1,0]] 

sage: G._representative=None 

sage: is_GlobalGenus(G) 

False 

 

""" 

D = G.determinant() 

r, s = G.signature_pair_of_matrix() 

oddity = r - s 

for loc in G._local_symbols: 

p = loc._prime 

sym = loc._symbol 

v = sum([ s[0]*s[1] for s in sym ]) 

a = D // (p**v) 

b = Integer(prod([ s[2] for s in sym ])) 

if p == 2: 

if not is_2_adic_genus(sym): 

# print "False in is_2_adic_genus(sym)" 

return False 

if (a*b).kronecker(p) != 1: 

# print "False in (%s*%s).kronecker(%s)"%(a,b,p) 

return False 

oddity -= loc.excess() 

else: 

if a.kronecker(p) != b: 

# print "False in %s.kronecker(%s) != *%s"%(a,p,b) 

return False 

oddity += loc.excess() 

if oddity%8 != 0: 

# print "False in oddity" 

return False 

return True 

 

 

 

def is_2_adic_genus(genus_symbol_quintuple_list): 

""" 

Given a 2-adic local symbol (as the underlying list of quintuples) 

check whether it is the 2-adic symbol of a 2-adic form. 

 

INPUT: 

 

- genus_symbol_quintuple_list -- a quintuple of integers (with certain 

restrictions). 

 

OUTPUT: 

 

boolean 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import LocalGenusSymbol 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: G2 = LocalGenusSymbol(A, 2) 

sage: is_2_adic_genus(G2.symbol_tuple_list()) 

True 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: G3 = LocalGenusSymbol(A, 3) 

sage: is_2_adic_genus(G3.symbol_tuple_list()) ## This raises an error 

Traceback (most recent call last): 

... 

TypeError: The genus symbols are not quintuples, so it's not a genus symbol for the prime p=2. 

 

sage: A = Matrix(ZZ, 2, 2, [1,0,0,2]) 

sage: G2 = LocalGenusSymbol(A, 2) 

sage: is_2_adic_genus(G2.symbol_tuple_list()) 

True 

""" 

## TO DO: Add explicit checking for the prime p here to ensure it's p=2... not just the quintuple checking below 

 

for s in genus_symbol_quintuple_list: 

 

## Check that we have a quintuple (i.e. that p=2 and not p >2) 

if len(s) != 5: 

raise TypeError("The genus symbols are not quintuples, so it's not a genus symbol for the prime p=2.") 

 

## Check the Conway-Sloane conditions 

if s[1] == 1: 

if s[3] == 0 or s[2] != s[4]: 

return False 

if s[1] == 2 and s[3] == 1: 

if s[2]%8 in (1,7): 

if not s[4] in (0,2,6): 

return False 

if s[2]%8 in (3,5): 

if not s[4] in (2,4,6): 

return False 

if (s[1] - s[4])% 2 == 1: 

return False 

if s[3] == 0 and s[4] != 0: 

return False 

return True 

 

 

 

def canonical_2_adic_compartments(genus_symbol_quintuple_list): 

""" 

Given a 2-adic local symbol (as the underlying list of quintuples) 

this returns a list of lists of indices of the 

genus_symbol_quintuple_list which are in the same compartment. A 

compartment is defined to be a maximal interval of Jordan 

components all (scaled) of type I (i.e. odd). 

 

INPUT: 

 

- genus_symbol_quintuple_list -- a quintuple of integers (with certain 

restrictions). 

 

OUTPUT: 

 

a list of lists of integers. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import LocalGenusSymbol 

sage: from sage.quadratic_forms.genera.genus import canonical_2_adic_compartments 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 2, 1, 1, 2]] 

sage: canonical_2_adic_compartments(G2.symbol_tuple_list()) 

[[0]] 

 

sage: A = Matrix(ZZ, 2, 2, [1,0,0,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 1, 1, 1, 1], [1, 1, 1, 1, 1]] 

sage: canonical_2_adic_compartments(G2.symbol_tuple_list()) 

[[0, 1]] 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]] 

sage: canonical_2_adic_compartments(G2.symbol_tuple_list()) 

[[0, 1, 2]] 

 

sage: A = Matrix(ZZ, 2, 2, [2,1,1,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 2, 3, 0, 0]] 

sage: canonical_2_adic_compartments(G2.symbol_tuple_list()) ## No compartments here! 

[] 

 

NOTES: 

 

See Conway-Sloane 3rd edition, pp. 381-382 for definitions and examples. 

""" 

symbol = genus_symbol_quintuple_list 

compartments = [] 

i = 0 

r = len(symbol) 

while i < r: 

s = symbol[i] 

if s[3] == 1: 

v = s[0] 

c = [] 

while i < r and symbol[i][3] == 1 and symbol[i][0] == v: 

c.append(i) 

i += 1 

v += 1 

compartments.append(c) 

else: 

i += 1 

return compartments 

 

def canonical_2_adic_trains(genus_symbol_quintuple_list, compartments=None): 

""" 

Given a 2-adic local symbol (as the underlying list of quintuples) 

this returns a list of lists of indices of the 

genus_symbol_quintuple_list which are in the same train. A train 

is defined to be a maximal interval of Jordan components so that 

at least one of each adjacent pair (allowing zero-dimensional 

Jordan components) is (scaled) of type I (i.e. odd). 

Note that an interval of length one respects this condition as 

there is no pair in this interval. 

In particular, every Jordan component is part of a train. 

 

INPUT: 

 

- ``genus_symbol_quintuple_list`` -- a quintuple of integers (with certain 

restrictions). 

- ``compartments`` -- this argument is deprecated 

 

OUTPUT: 

 

a list of lists of distinct integers. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import LocalGenusSymbol 

sage: from sage.quadratic_forms.genera.genus import canonical_2_adic_compartments 

sage: from sage.quadratic_forms.genera.genus import canonical_2_adic_trains 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 2, 1, 1, 2]] 

sage: canonical_2_adic_trains(G2.symbol_tuple_list()) 

[[0]] 

 

sage: A = Matrix(ZZ, 2, 2, [1,0,0,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 1, 1, 1, 1], [1, 1, 1, 1, 1]] 

sage: canonical_2_adic_compartments(G2.symbol_tuple_list()) 

[[0, 1]] 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]] 

sage: canonical_2_adic_trains(G2.symbol_tuple_list()) 

[[0, 1, 2]] 

 

sage: A = Matrix(ZZ, 2, 2, [2,1,1,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 2, 3, 0, 0]] 

sage: canonical_2_adic_trains(G2.symbol_tuple_list()) 

[[0]] 

sage: symbol = [[0, 1, 1, 1, 1],[1, 2, -1, 0, 0],[2, 1, 1, 1, 1],[3, 1, 1, 1, 1],[4, 1, 1, 1, 1],[5, 2, -1, 0, 0],[7, 1, 1, 1, 1],[10, 1, 1, 1, 1],[11, 1, 1, 1, 1],[12, 1, 1, 1, 1]] 

sage: canonical_2_adic_trains(symbol) 

[[0, 1, 2, 3, 4, 5], [6], [7, 8, 9]] 

 

Check that :trac:`24818` is fixed:: 

 

sage: symbol = [[0, 1, 1, 1, 1],[1, 3, 1, 1, 1]] 

sage: canonical_2_adic_trains(symbol) 

[[0, 1]] 

 

.. NOTE:: 

 

See [Co1999]_, pp. 381-382 for definitions and examples. 

 

""" 

if compartments is not None: 

from sage.misc.superseded import deprecation 

deprecation(23955, "the compartments keyword has been deprecated") 

 

# avoid a special case for the end of symbol 

# if a jordan component has rank zero it is considered even. 

symbol = genus_symbol_quintuple_list 

symbol.append([symbol[-1][0]+1, 0, 1, 0, 0]) #We have just modified the input globally! 

# Hence, we have to remove the last entry of symbol at the end. 

try: 

 

trains = [] 

new_train = [0] 

for i in range(1,len(symbol)-1): 

# start a new train if there are two adjacent even symbols 

prev, cur = symbol[i-1:i+1] 

if cur[0] - prev[0] > 2: 

trains.append(new_train) 

new_train = [i] # create a new train starting at 

elif (cur[0] - prev[0] == 2) and cur[3]*prev[3] == 0: 

trains.append(new_train) 

new_train = [i] 

elif prev[3] == 0 and cur[3] == 0: 

trains.append(new_train) 

new_train = [i] 

else: 

# there is an odd jordan block adjacent to this jordan block 

# the train continues 

new_train.append(i) 

# the last train was never added. 

trains.append(new_train) 

return trains 

finally: 

#revert the input list to its original state 

symbol.pop() 

 

def canonical_2_adic_reduction(genus_symbol_quintuple_list): 

""" 

Given a 2-adic local symbol (as the underlying list of quintuples) 

this returns a canonical 2-adic symbol (again as a raw list of 

quintuples of integers) which has at most one minus sign per train 

and this sign appears on the smallest dimensional Jordan component 

in each train. This results from applying the "sign-walking" and 

"oddity fusion" equivalences. 

 

INPUT: 

 

- genus_symbol_quintuple_list -- a quintuple of integers (with certain 

restrictions). 

- compartments -- a list of lists of distinct integers (optional) 

 

OUTPUT: 

 

a list of lists of distinct integers. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import LocalGenusSymbol 

sage: from sage.quadratic_forms.genera.genus import canonical_2_adic_reduction 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 2, 1, 1, 2]] 

sage: canonical_2_adic_reduction(G2.symbol_tuple_list()) 

[[0, 2, 1, 1, 2]] 

 

sage: A = Matrix(ZZ, 2, 2, [1,0,0,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 1, 1, 1, 1], [1, 1, 1, 1, 1]] 

sage: canonical_2_adic_reduction(G2.symbol_tuple_list()) ## Oddity fusion occurred here! 

[[0, 1, 1, 1, 2], [1, 1, 1, 1, 0]] 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]] 

sage: canonical_2_adic_reduction(G2.symbol_tuple_list()) ## Oddity fusion occurred here! 

[[1, 2, -1, 1, 6], [2, 1, 1, 1, 0], [3, 1, 1, 1, 0]] 

 

sage: A = Matrix(ZZ, 2, 2, [2,1,1,2]) 

sage: G2 = LocalGenusSymbol(A, 2); G2.symbol_tuple_list() 

[[0, 2, 3, 0, 0]] 

sage: canonical_2_adic_reduction(G2.symbol_tuple_list()) 

[[0, 2, -1, 0, 0]] 

 

.. NOTE:: 

 

See Conway-Sloane 3rd edition, pp. 381-382 for definitions and examples. 

 

.. TODO:: 

 

Add an example where sign walking occurs! 

""" 

# Protect the input from unwanted modification 

genus_symbol_quintuple_list = copy.deepcopy(genus_symbol_quintuple_list) 

canonical_symbol = genus_symbol_quintuple_list 

# Canonical determinants: 

for i in range(len(genus_symbol_quintuple_list)): 

d = genus_symbol_quintuple_list[i][2] 

if d in (1,7): 

canonical_symbol[i][2] = 1 

else: 

canonical_symbol[i][2] = -1 

# Oddity fusion: 

compartments = canonical_2_adic_compartments(genus_symbol_quintuple_list) 

for compart in compartments: 

oddity = sum([ genus_symbol_quintuple_list[i][4] for i in compart ]) % 8 

for i in compart: 

genus_symbol_quintuple_list[i][4] = 0 

genus_symbol_quintuple_list[compart[0]][4] = oddity 

#print "End oddity fusion:", canonical_symbol 

# Sign walking: 

trains = canonical_2_adic_trains(genus_symbol_quintuple_list) 

for train in trains: 

t = len(train) 

for i in range(t-1): 

t1 = train[t-i-1] 

if canonical_symbol[t1][2] == -1: 

canonical_symbol[t1][2] = 1 

canonical_symbol[t1-1][2] *= -1 

for compart in compartments: 

if t1-1 in compart or t1 in compart: 

o = canonical_symbol[compart[0]][4] 

canonical_symbol[compart[0]][4] = (o+4) % 8 

#print "End sign walking:", canonical_symbol 

return canonical_symbol 

 

 

 

 

 

def basis_complement(B): 

""" 

Given an echelonized basis matrix (over a field), calculate a 

matrix whose rows form a basis complement (to the rows of B). 

 

INPUT: 

 

- B -- matrix over a field in row echelon form 

 

OUTPUT: 

 

a rectangular matrix over a field 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import basis_complement 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,1]) 

sage: B = A.kernel().echelonized_basis_matrix(); B 

[ 1 -1] 

sage: basis_complement(B) 

[0 1] 

""" 

F = B.parent().base_ring() 

m = B.nrows() 

n = B.ncols() 

C = MatrixSpace(F,n-m,n,sparse=True)(0) 

k = 0 

l = 0 

for i in range(m): 

for j in range(k,n): 

if B[i,j] == 0: 

C[l,j] = 1 

l += 1 

else: 

k = j+1 

break 

for j in range(k,n): 

C[l+j-k,j] = 1 

return C 

 

 

 

def signature_pair_of_matrix(A): 

""" 

Computes the signature pair (p, n) of a non-degenerate symmetric 

matrix, where 

 

- p = number of positive eigenvalues of A 

- n = number of negative eigenvalues of A 

 

INPUT: 

 

- A -- symmetric matrix (assumed to be non-degenerate) 

 

OUTPUT: 

 

a pair (tuple) of integers. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import signature_pair_of_matrix 

 

sage: A = Matrix(ZZ, 2, 2, [-1,0,0,3]) 

sage: signature_pair_of_matrix(A) 

(1, 1) 

 

sage: A = Matrix(ZZ, 2, 2, [-1,1,1,7]) 

sage: signature_pair_of_matrix(A) 

(1, 1) 

 

sage: A = Matrix(ZZ, 2, 2, [3,1,1,7]) 

sage: signature_pair_of_matrix(A) 

(2, 0) 

 

sage: A = Matrix(ZZ, 2, 2, [-3,1,1,-11]) 

sage: signature_pair_of_matrix(A) 

(0, 2) 

 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,1]) 

sage: signature_pair_of_matrix(A) 

Traceback (most recent call last): 

... 

ArithmeticError: given matrix is not invertible 

""" 

from sage.quadratic_forms.quadratic_form import QuadraticForm 

s_vec = QuadraticForm(A.base_extend(A.base_ring().fraction_field())).signature_vector() 

 

# Check that the matrix is non-degenerate (i.e. no zero eigenvalues) 

if s_vec[2]: 

raise ArithmeticError("given matrix is not invertible") 

 

# Return the pair (p,n) 

return s_vec[:2] 

 

 

def p_adic_symbol(A, p, val): 

""" 

Given a symmetric matrix A and prime p, return the genus symbol at p. 

 

val = valuation of the maximal elementary divisor of A 

needed to obtain enough precision 

calculation is modulo p to the val+3 

 

.. TODO:: 

 

Some description of the definition of the genus symbol. 

 

INPUT: 

 

- A -- symmetric matrix with integer coefficients 

- p -- prime number > 0 

- val -- integer >= 0 

 

OUTPUT: 

 

a list of lists of integers 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p_adic_symbol(A, 2, 2) 

[[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]] 

 

sage: p_adic_symbol(A, 3, 1) 

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

 

""" 

if p % 2 == 0: 

return two_adic_symbol(A, val) 

m0 = min([ c.valuation(p) for c in A.list() ]) 

q = p**m0 

n = A.nrows() 

A = MatrixSpace(IntegerRing(),n,n)([ c // q for c in A.list() ]) 

A_p = MatrixSpace(FiniteField(p),n,n)(A) 

B_p = A_p.kernel().echelonized_basis_matrix() 

if B_p.nrows() == 0: 

e0 = Integer(A_p.det()).kronecker(p) 

n0 = A.nrows() 

return [ [m0,n0,e0] ] 

else: 

C_p = basis_complement(B_p) 

e0 = Integer((C_p*A_p*C_p.transpose()).det()).kronecker(p) 

n0 = C_p.nrows() 

sym = [ [0,n0,e0] ] 

r = B_p.nrows() 

B = MatrixSpace(IntegerRing(),r,n)(B_p) 

C = MatrixSpace(IntegerRing(),n-r,n)(C_p) 

# Construct the blocks for the Jordan decomposition [F,X;X,A_new] 

F = MatrixSpace(RationalField(),n-r,n-r)(C*A*C.transpose()) 

U = F**-1 

d = LCM([ c.denominator() for c in U.list() ]) 

R = IntegerRing().quotient_ring(Integer(p)**(val+3)) 

u = R(d)**-1 

MatR = MatrixSpace(R,n-r,n-r) 

MatZ = MatrixSpace(IntegerRing(),n-r,n-r) 

U = MatZ(MatR(MatZ(U*d))*u) 

# X = C*A*B.transpose() 

# A = B*A*B.transpose() - X.transpose()*U*X 

X = C*A 

A = B*(A - X.transpose()*U*X)*B.transpose() 

return [ [s[0]+m0] + s[1:] for s in sym + p_adic_symbol(A, p, val) ] 

 

 

 

def is_even_matrix(A): 

""" 

Determines if the integral symmetric matrix A is even 

(i.e. represents only even numbers). If not, then it returns the 

index of an odd diagonal entry. If it is even, then we return the 

index -1. 

 

INPUT: 

 

- A -- symmetric integer matrix 

 

OUTPUT: 

 

a pair of the form (boolean, integer) 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import is_even_matrix 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,1]) 

sage: is_even_matrix(A) 

(False, 0) 

 

sage: A = Matrix(ZZ, 2, 2, [2,1,1,2]) 

sage: is_even_matrix(A) 

(True, -1) 

""" 

for i in range(A.nrows()): 

if A[i,i]%2 == 1: 

return False, i 

return True, -1 

 

 

 

def split_odd(A): 

""" 

Given a non-degenerate Gram matrix A (mod 8), return a splitting [u] + B 

such that u is odd and B is not even. 

 

INPUT: 

 

- A -- an odd symmetric matrix with integer coefficients (which admits a 

splitting as above). 

 

OUTPUT: 

 

a pair (u, B) consisting of an odd integer u and an odd 

integral symmetric matrix B. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import is_even_matrix 

sage: from sage.quadratic_forms.genera.genus import split_odd 

 

sage: A = Matrix(ZZ, 2, 2, [1,2,2,3]) 

sage: is_even_matrix(A) 

(False, 0) 

sage: split_odd(A) 

(1, [-1]) 

 

sage: A = Matrix(ZZ, 2, 2, [1,2,2,5]) 

sage: split_odd(A) 

(1, [1]) 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,1]) 

sage: is_even_matrix(A) 

(False, 0) 

sage: split_odd(A) ## This fails because no such splitting exists. =( 

Traceback (most recent call last): 

... 

RuntimeError: The matrix A does not admit a non-even splitting. 

 

sage: A = Matrix(ZZ, 2, 2, [1,2,2,6]) 

sage: split_odd(A) ## This fails because no such splitting exists. =( 

Traceback (most recent call last): 

... 

RuntimeError: The matrix A does not admit a non-even splitting. 

 

""" 

n0 = A.nrows() 

if n0 == 1: 

return A[0,0], MatrixSpace(IntegerRing(),0,A.ncols())([]) 

even, i = is_even_matrix(A) 

R = A.parent().base_ring() 

C = MatrixSpace(R,n0-1,n0)(0) 

u = A[i,i] 

for j in range(n0-1): 

if j < i: 

C[j,j] = 1 

C[j,i] = -A[j,i]*u 

else: 

C[j,j+1] = 1 

C[j,i] = -A[j+1,i]*u 

B = C*A*C.transpose() 

even, j = is_even_matrix(B) 

if even: 

I = A.parent()(1) 

# TODO: we could manually (re)construct the kernel here... 

if i == 0: 

I[1,0] = 1 - A[1,0]*u 

i = 1 

else: 

I[0,i] = 1 - A[0,i]*u 

i = 0 

A = I*A*I.transpose() 

u = A[i,i] 

C = MatrixSpace(R,n0-1,n0)(0) 

for j in range(n0-1): 

if j < i: 

C[j,j] = 1 

C[j,i] = -A[j,i]*u 

else: 

C[j,j+1] = 1 

C[j,i] = -A[j+1,i]*u 

B = C*A*C.transpose() 

even, j = is_even_matrix(B) 

if even: 

print("B:") 

print(B) 

raise RuntimeError("The matrix A does not admit a non-even splitting.") 

return u, B 

 

 

 

def trace_diag_mod_8(A): 

""" 

Return the trace of the diagonalised form of A of an integral 

symmetric matrix which is diagonalizable mod 8. (Note that since 

the Jordan decomposition into blocks of size <= 2 is not unique 

here, this is not the same as saying that A is always diagonal in 

any 2-adic Jordan decomposition!) 

 

INPUT: 

 

- A -- symmetric matrix with coefficients in Z which is odd in Z/2Z and has 

determinant not divisible by 8. 

 

OUTPUT: 

 

an integer 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import is_even_matrix 

sage: from sage.quadratic_forms.genera.genus import split_odd 

sage: from sage.quadratic_forms.genera.genus import trace_diag_mod_8 

 

sage: A = Matrix(ZZ, 2, 2, [1,2,2,3]) 

sage: is_even_matrix(A) 

(False, 0) 

sage: split_odd(A) 

(1, [-1]) 

sage: trace_diag_mod_8(A) 

0 

 

sage: A = Matrix(ZZ, 2, 2, [1,2,2,5]) 

sage: split_odd(A) 

(1, [1]) 

sage: trace_diag_mod_8(A) 

2 

""" 

tr = 0 

while A.nrows() > 0: 

u, A = split_odd(A) 

tr += u 

return IntegerRing()(tr) 

 

 

 

def two_adic_symbol(A, val): 

""" 

Given a symmetric matrix A and prime p, return the genus symbol at p. 

 

val = valuation of maximal 2-elementary divisor 

 

The genus symbol of a component 2^m*f is of the form (m,n,s,d[,o]), 

where 

 

- m = valuation of the component 

- n = dimension of f 

- d = det(f) in {1,3,5,7} 

- s = 0 (or 1) if even (or odd) 

- o = oddity of f (= 0 if s = 0) in Z/8Z 

 

INPUT: 

 

- A -- symmetric matrix with integer coefficients 

- val -- integer >=0 

 

OUTPUT: 

 

a list of lists of integers (representing a Conway-Sloane 2-adic symbol) 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import two_adic_symbol 

 

sage: A = diagonal_matrix(ZZ, [1,2,3,4]) 

sage: two_adic_symbol(A, 2) 

[[0, 2, 3, 1, 4], [1, 1, 1, 1, 1], [2, 1, 1, 1, 1]] 

 

""" 

m0 = min([ c.valuation(2) for c in A.list() ]) 

q = 2**m0 

A = A.parent()([ c // q for c in A.list() ]) 

ZZ = IntegerRing() 

n = A.nrows() 

A_2 = MatrixSpace(FiniteField(2),n,n)(A) 

K_2 = A_2.kernel() 

R_8 = ZZ.quotient_ring(Integer(8)) 

 

## Deal with the matrix being non-degenerate mod 2. 

if K_2.dimension() == 0: 

A_8 = MatrixSpace(R_8,n)(A) 

n0 = A.nrows() 

# d0 = ZZ(A_8.determinant()) # no determinant over Z/8Z 

d0 = ZZ(R_8(MatrixSpace(ZZ,n)(A_8).determinant())) 

if d0 == 0: ## SANITY CHECK: The mod 8 determinant shouldn't be zero. 

print("A:") 

print(A) 

assert False 

even, i = is_even_matrix(A_2) ## Determine whether the matrix is even or odd. 

if even: 

return [ [m0,n0,d0,0,0] ] 

else: 

tr8 = trace_diag_mod_8(A_8) ## Here we already know that A_8 is odd and diagonalizable mod 8. 

return [ [m0,n0,d0,1,tr8] ] 

 

## Deal with the matrix being degenerate mod 2. 

else: 

B_2 = K_2.echelonized_basis_matrix() 

C_2 = basis_complement(B_2) 

n0 = C_2.nrows() 

C = MatrixSpace(ZZ,n0,n)(C_2) 

A_new = C*A*C.transpose() 

# compute oddity modulo 8: 

A_8 = MatrixSpace(R_8,n0,n0)(A_new) 

# d0 = A_8.det() # no determinant over Z/8Z 

d0 = ZZ(R_8(MatrixSpace(ZZ,n0,n0)(A_8).determinant())) 

if d0 == 0: 

print("A:") 

print(A_new) 

assert False 

even, i = is_even_matrix(A_new) 

if even: 

sym = [ [0,n0,d0,0,0] ] 

else: 

tr8 = trace_diag_mod_8(A_8) 

sym = [ [0,n0,d0,1,tr8] ] 

r = B_2.nrows() 

B = MatrixSpace(ZZ,r,n)(B_2) 

C = MatrixSpace(IntegerRing(),n-r,n)(C_2) 

F = MatrixSpace(RationalField(),n-r,n-r)(C*A*C.transpose()) 

U = F**-1 

d = LCM([ c.denominator() for c in U.list() ]) 

R = IntegerRing().quotient_ring(Integer(2)**(val+3)) 

u = R(d)**-1 

MatR = MatrixSpace(R,n-r,n-r) 

MatZ = MatrixSpace(IntegerRing(),n-r,n-r) 

U = MatZ(MatR(MatZ(U*d))*u) 

X = C*A 

A = B*(A - X.transpose()*U*X)*B.transpose() 

return [ [s[0]+m0] + s[1:] for s in sym + two_adic_symbol(A, val) ] 

 

 

class Genus_Symbol_p_adic_ring(object): 

""" 

Local genus symbol over a p-adic ring. 

""" 

def __init__(self, prime, symbol, check = True): 

""" 

Create the local genus symbol of given prime and local invariants. 

 

The genus symbol of a component p^m*A for odd prime = p is of the 

form (m,n,d), where 

 

- m = valuation of the component 

- n = rank of A 

- d = det(A) in {1,u} for normalized quadratic non-residue u. 

 

The genus symbol of a component 2^m*A is of the form (m,n,s,d,o), 

where 

 

- m = valuation of the component 

- n = rank of A 

- d = det(A) in {1,3,5,7} 

- s = 0 (or 1) if even (or odd) 

- o = oddity of A (= 0 if s = 0) in Z/8Z 

= the trace of the diagonalization of A 

 

The genus symbol is a list of such symbols (ordered by m) for each 

of the Jordan blocks A_1,...,A_t. 

 

Reference: Conway and Sloane 3rd edition, Chapter 15, Section 7. 

 

 

WARNING/NOTE: This normalization seems non-standard, and we 

should review this entire class to make sure that we have our 

doubling conventions straight throughout! This is especially 

noticeable in the determinant and excess methods!! 

 

INPUT: 

 

- prime -- a prime integer > 0 

- symbol -- the list of invariants for Jordan blocks A_t,...,A_t given 

as a list of lists of integers 

 

OUTPUT: 

 

None 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = diagonal_matrix(ZZ, [1,2,3,4]) 

sage: p = 2 

sage: s2 = p_adic_symbol(A, p, 2); s2 

[[0, 2, 3, 1, 4], [1, 1, 1, 1, 1], [2, 1, 1, 1, 1]] 

sage: G = Genus_Symbol_p_adic_ring(p,s2);G 

Genus symbol at 2: [1^-2 2^1 4^1]_6 

sage: G == loads(dumps(G)) 

True 

 

sage: A = diagonal_matrix(ZZ, [1,2,3,4]) 

sage: p = 3 

sage: s3 = p_adic_symbol(A, p, 1); s3 

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

sage: G = Genus_Symbol_p_adic_ring(p,s3);G 

Genus symbol at 3: 1^-3 3^1 

sage: G == loads(dumps(G)) 

True 

 

 

""" 

if check: 

pass 

self._prime = prime 

self._symbol = symbol 

self._canonical_symbol = None 

 

def __repr__(self): 

r""" 

String representation for the p-adic genus symbol 

 

INPUT: 

 

None 

 

OUTPUT: 

 

a string 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

sage: symbol = [[0, 4, -1, 0, 0],[1, 2, 1, 1, 2],[2, 1, 1, 1, 1],[4, 4, 1, 0, 0],[5, 1, 1, 1, 1]] 

sage: g = Genus_Symbol_p_adic_ring(2,symbol) 

sage: g._canonical_symbol = [[0, 4, 1, 0, 0],[1, 2, 1, 1, 3],[2, 1, 1, 1, 0],[4, 4, 1, 0, 0],[5, 1, 1, 1, 1]] 

sage: g 

Genus symbol at 2: 1^4 [2^2 4^1]_1 :16^4 [32^1]_1 

 

 

 

""" 

p=self._prime 

CS_string = "" 

if p==2: 

CS = self.canonical_symbol() 

for train in self.trains(): 

#mark the beginning of a train with a colon 

CS_string += " :" 

#collect the indices where compartments begin and end 

compartment_begins = [] 

compartment_ends = [] 

for comp in self.compartments(): 

compartment_begins.append(comp[0]) 

compartment_ends.append(comp[-1]) 

 

for block_index in train: 

if block_index in compartment_begins: 

#mark the beginning of this compartment with [ 

CS_string += "[" 

block = CS[block_index] 

block_string = "%s^%s " % (p**block[0],block[2]*block[1]) 

CS_string += block_string 

if block_index in compartment_ends: 

#close this compartment with ] and remove a space 

CS_string = CS_string[:-1] + "]" 

#the oddity belongs to the compartment 

oddity = CS[comp[0]][4] 

CS_string +="_%s" % oddity 

#remove the first colon 

CS_string = CS_string[2:] 

 

else: 

for s in self._symbol: 

CS_string += " %s^%s" % (p**s[0], s[2]*s[1]) 

return "Genus symbol at %s: %s" % (p, CS_string) 

 

def _latex_(self): 

""" 

The LaTeX representation of this local genus symbol. 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

sage: symbol = [[0, 4, -1, 0, 0],[1, 2, 1, 1, 2],[2, 1, 1, 1, 1],[4, 4, 1, 0, 0],[5, 1, 1, 1, 1]] 

sage: g = Genus_Symbol_p_adic_ring(2,symbol) 

sage: g._canonical_symbol = [[0, 4, 1, 0, 0],[1, 2, 1, 1, 3],[2, 1, 1, 1, 0],[4, 4, 1, 0, 0],[5, 1, 1, 1, 1]] 

sage: g._latex_() 

'\\mbox{Genus symbol at } 2\\mbox{: }1^{4} [2^{2} 4^{1}]_{1} :16^{4} [32^{1}]_{1}' 

 

 

""" 

p=self._prime 

CS_string = "" 

if p==2: 

CS = self.canonical_symbol() 

for train in self.trains(): 

#mark the beginning of a train with a colon 

CS_string += " :" 

#collect the indices where compartments begin and end 

compartment_begins = [] 

compartment_ends = [] 

for comp in self.compartments(): 

compartment_begins.append(comp[0]) 

compartment_ends.append(comp[-1]) 

 

for block_index in train: 

if block_index in compartment_begins: 

#mark the beginning of this compartment with [ 

CS_string += "[" 

block = CS[block_index] 

block_string = "%s^{%s} " % (p**block[0],block[2]*block[1]) 

CS_string += block_string 

if block_index in compartment_ends: 

#close this compartment with ] and remove a space 

CS_string = CS_string[:-1] + "]" 

#the oddity belongs to the compartment 

oddity = CS[comp[0]][4] 

CS_string +="_{%s}" % oddity 

#remove the first colon 

CS_string = CS_string[2:] 

 

else: 

for s in self._symbol: 

CS_string += " {%s}^{%s}" % (p**s[0], s[2]*s[1]) 

return "\\mbox{Genus symbol at } %s\mbox{: }%s" % (p,CS_string) 

 

 

 

def __eq__(self, other): 

""" 

Determines if two genus symbols are equal (not just equivalent!). 

 

INPUT: 

 

a Genus_Symbol_p_adic_ring object 

 

OUTPUT: 

 

boolean 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = diagonal_matrix(ZZ, [1,2,3,4]) 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)) 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 1)) 

 

sage: G2 == G3 

False 

sage: G3 == G2 

False 

sage: G2 == G2 

True 

sage: G3 == G3 

True 

 

""" 

p = self._prime 

if p != other._prime: 

return False 

return self.canonical_symbol() == other.canonical_symbol() 

 

 

def __ne__(self, other): 

""" 

Determines if two genus symbols are unequal (not just inequivalent!). 

 

INPUT: 

 

a ``Genus_Symbol_p_adic_ring`` object 

 

OUTPUT: 

 

boolean 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = diagonal_matrix(ZZ, [1,2,3,4]) 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)) 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 1)) 

 

sage: G2 != G3 

True 

sage: G3 != G2 

True 

sage: G2 != G2 

False 

sage: G3 != G3 

False 

 

""" 

return not self == other 

 

 

## Added these two methods to make this class iterable... 

#def __getitem__(self, i): 

# return self._symbol[i] 

# 

#def len(self): 

# return len(self._symbol) 

## ------------------------------------------------------ 

 

def canonical_symbol(self): 

""" 

Return (and cache) the canonical p-adic genus symbol. This is 

only really affects the 2-adic symbol, since when p > 2 the 

symbol is already canonical. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

a list of lists of integers 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = Matrix(ZZ, 2, 2, [1,1,1,2]) 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2.symbol_tuple_list() 

[[0, 2, 1, 1, 2]] 

sage: G2.canonical_symbol() 

[[0, 2, 1, 1, 2]] 

 

sage: A = Matrix(ZZ, 2, 2, [1,0,0,2]) 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2.symbol_tuple_list() 

[[0, 1, 1, 1, 1], [1, 1, 1, 1, 1]] 

sage: G2.canonical_symbol() ## Oddity fusion occurred here! 

[[0, 1, 1, 1, 2], [1, 1, 1, 1, 0]] 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2.symbol_tuple_list() 

[[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]] 

sage: G2.canonical_symbol() ## Oddity fusion occurred here! 

[[1, 2, -1, 1, 6], [2, 1, 1, 1, 0], [3, 1, 1, 1, 0]] 

 

sage: A = Matrix(ZZ, 2, 2, [2,1,1,2]) 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2.symbol_tuple_list() 

[[0, 2, 3, 0, 0]] 

sage: G2.canonical_symbol() 

[[0, 2, -1, 0, 0]] 

 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G3.symbol_tuple_list() 

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

sage: G3.canonical_symbol() 

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

 

.. NOTE:: 

 

See Conway-Sloane 3rd edition, pp. 381-382 for definitions and examples. 

 

.. TODO:: 

 

Add an example where sign walking occurs! 

""" 

symbol = self._symbol 

if self._prime == 2: 

if self._canonical_symbol is None: 

self._canonical_symbol = canonical_2_adic_reduction(symbol) 

return self._canonical_symbol 

else: 

return self._symbol 

 

 

 

def symbol_tuple_list(self): 

""" 

Returns the underlying list of lists of integers defining the genus symbol. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

list of lists of integers 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G3 

Genus symbol at 3: 1^3 3^-1 

sage: G3.symbol_tuple_list() 

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

sage: type(G3.symbol_tuple_list()) 

<... 'list'> 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

sage: G2.symbol_tuple_list() 

[[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]] 

sage: type(G2.symbol_tuple_list()) 

<... 'list'> 

 

""" 

return self._symbol 

 

 

 

def number_of_blocks(self): 

""" 

Returns the number of positive dimensional symbols/Jordan blocks 

 

INPUT: 

 

None 

 

OUTPUT: 

 

integer >= 0 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2.symbol_tuple_list() 

[[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]] 

sage: G2.number_of_blocks() 

3 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G3.symbol_tuple_list() 

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

sage: G3.number_of_blocks() 

2 

 

""" 

return len(self._symbol) 

 

 

def determinant(self): 

""" 

Returns the (p-part of the) determinant (square-class) of the 

Hessian matrix of the quadratic form (given by regarding the 

integral symmetric matrix which generated this genus symbol as 

the Gram matrix of Q) associated to this local genus symbol. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

an integer 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

sage: G2.determinant() 

128 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G3 

Genus symbol at 3: 1^3 3^-1 

sage: G3.determinant() 

3 

""" 

p = self._prime 

return prod([ p**(s[0]*s[1]) for s in self._symbol ]) 

 

 

def rank(self): 

""" 

Returns the dimension of a quadratic form associated to this genus symbol. 

 

.. TODO:: 

 

DELETE THIS METHOD IN FAVOR OF THE dimension() METHOD BELOW! 

 

INPUT: 

 

None 

 

OUTPUT: 

 

an integer >= 0 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

sage: G2.rank() 

4 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G3 

Genus symbol at 3: 1^3 3^-1 

sage: G3.rank() 

4 

 

""" 

return sum([ s[1] for s in self._symbol ]) 

 

def dimension(self): 

""" 

Returns the dimension of a quadratic form associated to this genus symbol. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

an integer >= 0 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

sage: G2.dimension() 

4 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 3 

sage: G3 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G3 

Genus symbol at 3: 1^3 3^-1 

sage: G3.dimension() 

4 

 

""" 

return self.rank() 

 

 

def excess(self): 

""" 

Returns the p-excess of the quadratic form whose Hessian 

matrix is the symmetric matrix A. When p = 2 the p-excess is 

called the oddity. 

 

WARNING/NOTE: This normalization seems non-standard, and we 

should review this entire class to make sure that we have our 

doubling conventions straight throughout! 

 

REFERENCE: 

 

Conway and Sloane Book, 3rd edition, pp 370-371. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

an integer 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: AC = diagonal_matrix(ZZ, [1,3,-3]) 

sage: p=2; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

1 

sage: p=3; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

sage: p=5; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

sage: p=7; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

sage: p=11; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

 

sage: AC = 2 * diagonal_matrix(ZZ, [1,3,-3]) 

sage: p=2; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

1 

sage: p=3; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

sage: p=5; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

sage: p=7; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

sage: p=11; Genus_Symbol_p_adic_ring(p, p_adic_symbol(AC, p, 2)).excess() 

0 

 

sage: A = 2*diagonal_matrix(ZZ, [1,2,3,4]) 

sage: p=2; Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)).excess() 

2 

sage: p=3; Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)).excess() 

6 

sage: p=5; Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)).excess() 

0 

sage: p=7; Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)).excess() 

0 

sage: p=11; Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)).excess() 

0 

 

""" 

p = self._prime 

if self._prime == 2: 

k = 0 

for s in self._symbol: 

if s[0]%2 == 1 and s[2] in (3,5): 

k += 1 

return Integer(sum([ s[4] for s in self._symbol ]) + 4*k).mod(8) 

else: 

k = 0 

for s in self._symbol: 

if s[0]%2 == 1 and s[2] == -1: 

k += 1 

return Integer(sum([ s[1]*(p**s[0]-1) for s in self._symbol ]) + 4*k).mod(8) 

 

 

 

def trains(self): 

""" 

Compute the indices for each of the trains in this local genus 

symbol if it is associated to the prime p=2 (and raise an 

error for all other primes). 

 

INPUT: 

 

None 

 

OUTPUT: 

 

a list of integers >= 0 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

sage: G2.trains() 

[[0, 1, 2]] 

 

""" 

## Check that p = 2 

if self._prime != 2: 

raise TypeError("trains() only makes sense when the prime of the p_adic_Genus_Symbol is p=2") 

symbol = self._symbol 

return canonical_2_adic_trains(symbol) 

 

 

def compartments(self): 

""" 

Compute the indices for each of the compartments in this local genus 

symbol if it is associated to the prime p=2 (and raise an 

error for all other primes). 

 

INPUT: 

 

None 

 

OUTPUT: 

 

a list of integers >= 0 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import p_adic_symbol 

sage: from sage.quadratic_forms.genera.genus import Genus_Symbol_p_adic_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: p = 2 

sage: G2 = Genus_Symbol_p_adic_ring(p, p_adic_symbol(A, p, 2)); G2 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

sage: G2.compartments() 

[[0, 1, 2]] 

 

""" 

## Check that p = 2 

if self._prime != 2: 

raise TypeError("compartments() only makes sense when the prime of the p_adic_Genus_Symbol is p=2") 

symbol = self._symbol 

return canonical_2_adic_compartments(symbol) 

 

class GenusSymbol_global_ring(object): 

""" 

This represents a collection of local genus symbols (at primes) 

and signature information which represent the genus of a 

non-degenerate integral lattice. 

""" 

 

def __init__(self, A, max_elem_divisors=None): 

""" 

Initialize a global genus symbol from a non-degenerate 

integral gram matrix (and possibly information about its 

largest elementary divisors). 

 

INPUT: 

 

- A -- a symmetric matrix with integer coefficients 

- max_elem_divisors -- the input precision for valuation of maximal 

p-elementary divisor. (OPTIONAL) 

 

OUTPUT: 

 

None 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import GenusSymbol_global_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: G = GenusSymbol_global_ring(A);G 

Genus of 

[2 0 0 0] 

[0 4 0 0] 

[0 0 6 0] 

[0 0 0 8] 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

Genus symbol at 3: 1^3 3^-1 

sage: G == loads(dumps(G)) 

True 

 

""" 

D = A.determinant() 

D = 2*D 

prms = [ p[0] for p in D.factor() ] 

self._representative = A 

self._signature = signature_pair_of_matrix(A) 

self._local_symbols = [] 

for p in prms: 

if max_elem_divisors is None: 

val = D.valuation(p) 

symbol = p_adic_symbol(A, p, val = val) 

G = Genus_Symbol_p_adic_ring(p, symbol) 

self._local_symbols.append(G) 

 

 

def __repr__(self): 

r""" 

Returns a string representing the global genus symbol. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

a string 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import GenusSymbol_global_ring 

sage: A = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: GS = GenusSymbol_global_ring(A) 

sage: GS 

Genus of 

[2 0 0 0] 

[0 4 0 0] 

[0 0 6 0] 

[0 0 0 8] 

Genus symbol at 2: [2^-2 4^1 8^1]_6 

Genus symbol at 3: 1^3 3^-1 

 

sage: A2 = Matrix(ZZ,2,2,[2,-1,-1,2]) 

sage: GenusSymbol_global_ring(A2) 

Genus of 

[ 2 -1] 

[-1 2] 

Genus symbol at 2: 1^-2 

Genus symbol at 3: 1^-1 3^-1 

 

""" 

local_symbols = "" 

for s in self._local_symbols: 

local_symbols += "\n" + s.__repr__() 

return "Genus of\n%s\n%s" % (self._representative,local_symbols[1:]) 

 

def _latex_(self): 

""" 

The Latex representation of this lattice. 

 

EXAMPLES:: 

 

sage: D4=QuadraticForm(Matrix(ZZ,4,4,[2,0,0,-1,0,2,0,-1,0,0,2,-1,-1,-1,-1,2])) 

sage: G=D4.global_genus_symbol() 

sage: G._latex_() 

'\\mbox{Genus of}\\\\\\left(\\begin{array}{rrrr}\n2 & 0 & 0 & -1 \\\\\n0 & 2 & 0 & -1 \\\\\n0 & 0 & 2 & -1 \\\\\n-1 & -1 & -1 & 2\n\\end{array}\\right)\\\\\\\\\\mbox{Genus symbol at } 2\\mbox{: }1^{-2} :2^{-2} ' 

""" 

local_symbols = "" 

for s in self._local_symbols: 

local_symbols += "\\\\" + s._latex_() 

return "\\mbox{Genus of}\\\\%s\\\\%s" % (self._representative._latex_(),local_symbols) 

 

 

 

def __eq__(self, other): 

""" 

Determines if two global genus symbols are equal (not just equivalent!). 

 

INPUT: 

 

a ``GenusSymbol_global_ring`` object 

 

OUTPUT: 

 

boolean 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import GenusSymbol_global_ring 

 

sage: A1 = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: GS1 = GenusSymbol_global_ring(A1) 

sage: A2 = DiagonalQuadraticForm(ZZ, [1,2,3,5]).Hessian_matrix() 

sage: GS2 = GenusSymbol_global_ring(A2) 

 

sage: GS1 == GS2 

False 

 

sage: GS2 == GS1 

False 

 

sage: GS1 == GS1 

True 

 

sage: GS2 == GS2 

True 

 

TESTS:: 

 

sage: D4=QuadraticForm(Matrix(ZZ,4,4,[2,0,0,-1,0,2,0,-1,0,0,2,-1,-1,-1,-1,2])) 

sage: G=D4.global_genus_symbol() 

sage: sage.quadratic_forms.genera.genus.is_GlobalGenus(G) 

True 

sage: G==deepcopy(G) 

True 

sage: sage.quadratic_forms.genera.genus.is_GlobalGenus(G) 

True 

""" 

if self is other: 

return True 

t = len(self._local_symbols) 

if t != len(other._local_symbols): 

return False 

for i in range(t): 

if self._local_symbols[i] != other._local_symbols[i]: 

return False 

return True 

 

 

 

def __ne__(self, other): 

""" 

Determines if two global genus symbols are unequal (not just inequivalent!). 

 

INPUT: 

 

a ``GenusSymbol_global_ring`` object 

 

OUTPUT: 

 

boolean 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import GenusSymbol_global_ring 

 

sage: A1 = DiagonalQuadraticForm(ZZ, [1,2,3,4]).Hessian_matrix() 

sage: GS1 = GenusSymbol_global_ring(A1) 

sage: A2 = DiagonalQuadraticForm(ZZ, [1,2,3,5]).Hessian_matrix() 

sage: GS2 = GenusSymbol_global_ring(A2) 

 

sage: GS1 != GS2 

True 

 

sage: GS2 != GS1 

True 

 

sage: GS1 != GS1 

False 

 

sage: GS2 != GS2 

False 

 

""" 

return not self == other 

 

 

def signature_pair_of_matrix(self): 

""" 

Returns the signature pair (p, n) of the (non-degenerate) 

global genus symbol, where p is the number of positive 

eigenvalues and n is the number of negative eigenvalues. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

a pair of integers (p, n) each >= 0 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import GenusSymbol_global_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,-2,3,4,8,-11]).Hessian_matrix() 

sage: GS = GenusSymbol_global_ring(A) 

sage: GS.signature_pair_of_matrix() 

(4, 2) 

 

""" 

return self._signature 

 

 

def determinant(self): 

""" 

Returns the determinant of this genus, where the determinant 

is the Hessian determinant of the quadratic form whose Gram 

matrix is the Gram matrix giving rise to this global genus 

symbol. 

 

INPUT: 

 

None 

 

OUTPUT: 

 

an integer 

 

EXAMPLES:: 

 

sage: from sage.quadratic_forms.genera.genus import GenusSymbol_global_ring 

 

sage: A = DiagonalQuadraticForm(ZZ, [1,-2,3,4]).Hessian_matrix() 

sage: GS = GenusSymbol_global_ring(A) 

sage: GS.determinant() 

-384 

 

""" 

r, s = self.signature_pair_of_matrix() 

return (-1)**s*prod([ G.determinant() for G in self._local_symbols ])