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

# -*- coding: utf-8 -*- 

r""" 

Spaces of valuations 

 

This module provides spaces of exponential pseudo-valuations on integral 

domains. It currently only provides support for such valuations if they are 

discrete, i.e., their image is a discrete additive subgroup of the rational 

numbers extended by `\infty`. 

 

AUTHORS: 

 

- Julian Rüth (2016-10-14): initial version 

 

EXAMPLES:: 

 

sage: QQ.valuation(2).parent() 

Discrete pseudo-valuations on Rational Field 

 

.. NOTE:: 

 

Note that many tests not only in this module do not create instances of 

valuations directly since this gives the wrong inheritance structure on 

the resulting objects:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: from sage.rings.valuation.trivial_valuation import TrivialDiscretePseudoValuation 

sage: H = DiscretePseudoValuationSpace(QQ) 

sage: v = TrivialDiscretePseudoValuation(H) 

sage: v._test_category() 

Traceback (most recent call last): 

... 

AssertionError: False is not true 

 

Instead, the valuations need to be created through the 

``__make_element_class__`` of the containing space:: 

 

sage: from sage.rings.valuation.trivial_valuation import TrivialDiscretePseudoValuation 

sage: v = H.__make_element_class__(TrivialDiscretePseudoValuation)(H) 

sage: v._test_category() 

 

The factories such as ``TrivialPseudoValuation`` provide the right 

inheritance structure:: 

 

sage: v = valuations.TrivialPseudoValuation(QQ) 

sage: v._test_category() 

 

""" 

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

# Copyright (C) 2016-2017 Julian Rüth <julian.rueth@fsfe.org> 

# 

# 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 sage.categories.homset import Homset 

from sage.misc.lazy_attribute import lazy_attribute 

from sage.misc.abstract_method import abstract_method 

from sage.structure.unique_representation import UniqueRepresentation 

from sage.misc.cachefunc import cached_method 

 

class DiscretePseudoValuationSpace(UniqueRepresentation, Homset): 

r""" 

The space of discrete pseudo-valuations on ``domain``. 

 

EXAMPLES:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: H = DiscretePseudoValuationSpace(QQ) 

sage: QQ.valuation(2) in H 

True 

 

.. NOTE:: 

 

We do not distinguish between the space of discrete valuations and the 

space of discrete pseudo-valuations. This is entirely for practical 

reasons: We would like to model the fact that every discrete valuation 

is also a discrete pseudo-valuation. At first, it seems to be 

sufficient to make sure that the ``in`` operator works which can 

essentially be achieved by overriding ``_element_constructor_`` of 

the space of discrete pseudo-valuations to accept discrete valuations 

by just returning them. Currently, however, if one does not change the 

parent of an element in ``_element_constructor_`` to ``self``, then 

one can not register that conversion as a coercion. Consequently, the 

operators ``<=`` and ``>=`` can not be made to work between discrete 

valuations and discrete pseudo-valuations on the same domain (because 

the implementation only calls ``_richcmp`` if both operands have the 

same parent.) Of course, we could override ``__ge__`` and ``__le__`` 

but then we would likely run into other surprises. 

So in the end, we went for a single homspace for all discrete 

valuations (pseudo or not) as this makes the implementation much 

easier. 

 

.. TODO:: 

 

The comparison problem might be fixed by :trac:`22029` or similar. 

 

TESTS:: 

 

sage: TestSuite(H).run() # long time 

 

""" 

def __init__(self, domain): 

r""" 

TESTS:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: isinstance(QQ.valuation(2).parent(), DiscretePseudoValuationSpace) 

True 

 

""" 

from .value_group import DiscreteValuationCodomain 

# A valuation is a map from an additive semigroup to an additive semigroup, however, it 

# does not preserve that structure. It is therefore only a morphism in the category of sets. 

from sage.categories.all import Sets 

 

UniqueRepresentation.__init__(self) 

Homset.__init__(self, domain, DiscreteValuationCodomain(), category = Sets()) 

 

from sage.categories.domains import Domains 

if domain not in Domains(): 

raise ValueError("domain must be an integral domain") 

 

@lazy_attribute 

def _abstract_element_class(self): 

r""" 

Return an abstract base class for all valuations in this space. 

 

This is used to extend every valuation with a number of generic methods 

that are independent of implementation details. 

 

Usually, extensions of this kind would be done by implementing an 

appropriate class ``MorphismMethods`` in the category of this homset. 

However, there is no category whose arrows are the valuations, so we 

need to move this magic down to the level of the actual homset. 

 

EXAMPLES:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: isinstance(QQ.valuation(2), DiscretePseudoValuationSpace.ElementMethods) # indirect doctest 

True 

 

""" 

class_name = "%s._abstract_element_class"%self.__class__.__name__ 

from sage.structure.dynamic_class import dynamic_class 

return dynamic_class(class_name, (super(DiscretePseudoValuationSpace,self)._abstract_element_class, self.__class__.ElementMethods)) 

 

def _get_action_(self, S, op, self_on_left): 

r""" 

Return the ``op`` action of ``S`` on elements in this space. 

 

EXAMPLES:: 

 

sage: v = QQ.valuation(2) 

sage: from operator import mul 

sage: v.parent().get_action(ZZ, mul) # indirect doctest 

Right action by Integer Ring on Discrete pseudo-valuations on Rational Field 

 

""" 

from operator import mul, div 

from sage.rings.all import QQ, InfinityRing, ZZ 

if op == mul and (S is InfinityRing or S is QQ or S is ZZ): 

return ScaleAction(S, self, not self_on_left, op) 

return None 

 

def _an_element_(self): 

r""" 

Return a trivial valuation in this space. 

 

EXAMPLES:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: DiscretePseudoValuationSpace(QQ).an_element() # indirect doctest 

Trivial pseudo-valuation on Rational Field 

 

""" 

from .trivial_valuation import TrivialPseudoValuation 

return TrivialPseudoValuation(self.domain()) 

 

def _repr_(self): 

r""" 

Return a printable representation of this space. 

 

EXAMPLES:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: DiscretePseudoValuationSpace(QQ) # indirect doctest 

Discrete pseudo-valuations on Rational Field 

 

""" 

return "Discrete pseudo-valuations on %r"%(self.domain(),) 

 

def __contains__(self, x): 

r""" 

Return whether ``x`` is a valuation in this space. 

 

EXAMPLES:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: H = DiscretePseudoValuationSpace(QQ) 

sage: H.an_element() in H 

True 

sage: QQ.valuation(2) in H 

True 

 

""" 

# override the logic from Homset with the original implementation for Parent 

# which entirely relies on a proper implementation of 

# _element_constructor_ and coercion maps 

from sage.structure.parent import Parent 

return Parent.__contains__(self, x) 

 

def __call__(self, x): 

r""" 

Create an element in this space from ``x``. 

 

EXAMPLES:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: H = DiscretePseudoValuationSpace(QQ) 

sage: H(QQ.valuation(2)) 

2-adic valuation 

 

""" 

# override the logic from Homset with the original implementation for Parent 

# which entirely relies on a proper implementation of 

# _element_constructor_ and coercion maps 

from sage.structure.parent import Parent 

return Parent.__call__(self, x) 

 

def _element_constructor_(self, x): 

r""" 

Create an element in this space from ``x``, 

 

EXAMPLES: 

 

We try to convert valuations defined on different domains by changing 

their base ring:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: Z = DiscretePseudoValuationSpace(ZZ) 

sage: Q = DiscretePseudoValuationSpace(QQ) 

sage: v = ZZ.valuation(2) 

sage: v in Q 

False 

sage: Q(v) in Q 

True 

sage: Q(v) in Z 

False 

sage: Z(Q(v)) in Z 

True 

 

""" 

if isinstance(x.parent(), DiscretePseudoValuationSpace): 

if x.domain() is not self.domain(): 

try: 

return self(x.change_domain(self.domain())) 

except NotImplementedError: 

pass 

else: 

return x 

raise ValueError("element can not be converted into the space of %r"%(self,)) 

 

class ElementMethods: 

r""" 

Provides methods for discrete pseudo-valuations that are added 

automatically to valuations in this space. 

 

EXAMPLES: 

 

Here is an example of a method that is automagically added to a 

discrete valuation:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: H = DiscretePseudoValuationSpace(QQ) 

sage: QQ.valuation(2).is_discrete_pseudo_valuation() # indirect doctest 

True 

 

The methods will be provided even if the concrete type is not created 

with ``__make_element_class__``:: 

 

sage: from sage.rings.valuation.valuation import DiscretePseudoValuation 

sage: m = DiscretePseudoValuation(H) 

sage: m.parent() is H 

True 

sage: m.is_discrete_pseudo_valuation() 

True 

 

However, the category framework advises you to use inheritance:: 

 

sage: m._test_category() 

Traceback (most recent call last): 

... 

AssertionError: False is not true 

 

Using ``__make_element_class__``, makes your concrete valuation inherit 

from this class:: 

 

sage: m = H.__make_element_class__(DiscretePseudoValuation)(H) 

sage: m._test_category() 

 

""" 

def is_discrete_pseudo_valuation(self): 

r""" 

Return whether this valuation is a discrete pseudo-valuation. 

 

EXAMPLES:: 

 

sage: QQ.valuation(2).is_discrete_pseudo_valuation() 

True 

 

""" 

return True 

 

@abstract_method 

def is_discrete_valuation(self): 

r""" 

Return whether this valuation is a discrete valuation, i.e., 

whether it is a :meth:`discrete pseudo valuation 

<is_discrete_pseudo_valuation>` that only sends zero to `\infty`. 

 

EXAMPLES:: 

 

sage: QQ.valuation(2).is_discrete_valuation() 

True 

 

""" 

 

def is_negative_pseudo_valuation(self): 

r""" 

Return whether this valuation is a discrete pseudo-valuation that 

does attain `-\infty`, i.e., it is non-trivial and its domain 

contains an element with valuation `\infty` that has an inverse. 

 

EXAMPLES:: 

 

sage: QQ.valuation(2).is_negative_pseudo_valuation() 

False 

 

""" 

from sage.categories.all import Fields 

if self.is_discrete_valuation(): 

return False 

elif self.domain() in Fields(): 

return True 

raise NotImplementedError 

 

@cached_method 

def is_trivial(self): 

r""" 

Return whether this valuation is trivial, i.e., whether it is 

constant `\infty` or constant zero for everything but the zero 

element. 

 

Subclasses need to override this method if they do not implement 

:meth:`uniformizer`. 

 

EXAMPLES:: 

 

sage: QQ.valuation(7).is_trivial() 

False 

 

""" 

from sage.rings.all import infinity 

if self(self.domain().one()) is infinity: 

# the constant infinity 

return True 

if self(self.uniformizer()) != 0: 

# not constant on the non-zero elements 

return False 

return True 

 

@abstract_method 

def uniformizer(self): 

r""" 

Return an element in the domain which has positive valuation and 

generates the value group of this valuation. 

 

EXAMPLES:: 

 

sage: QQ.valuation(11).uniformizer() 

11 

 

Trivial valuations have no uniformizer:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: v = DiscretePseudoValuationSpace(QQ).an_element() 

sage: v.is_trivial() 

True 

sage: v.uniformizer() 

Traceback (most recent call last): 

... 

ValueError: Trivial valuations do not define a uniformizing element 

 

""" 

 

@cached_method 

def value_group(self): 

r""" 

Return the value group of this discrete pseudo-valuation, the 

discrete additive subgroup of the rational numbers which is 

generated by the valuation of the :meth:`uniformizer`. 

 

EXAMPLES:: 

 

sage: QQ.valuation(2).value_group() 

Additive Abelian Group generated by 1 

 

A pseudo-valuation that is `\infty` everywhere, does not have a 

value group:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: v = DiscretePseudoValuationSpace(QQ).an_element() 

sage: v.value_group() 

Traceback (most recent call last): 

... 

ValueError: The trivial pseudo-valuation that is infinity everywhere does not have a value group. 

 

""" 

from .value_group import DiscreteValueGroup 

return DiscreteValueGroup(self(self.uniformizer())) 

 

def value_semigroup(self): 

r""" 

Return the value semigroup of this discrete pseudo-valuation, the 

additive subsemigroup of the rational numbers which is generated by 

the valuations of the elements in the domain. 

 

EXAMPLES: 

 

Most commonly, in particular over fields, the semigroup is the 

group generated by the valuation of the uniformizer:: 

 

sage: G = QQ.valuation(2).value_semigroup(); G 

Additive Abelian Semigroup generated by -1, 1 

sage: G in AdditiveMagmas().AdditiveAssociative().AdditiveUnital().AdditiveInverse() 

True 

 

If the domain is a discrete valuation ring, then the semigroup 

consists of the positive elements of the :meth:`value_group`:: 

 

sage: Zp(2).valuation().value_semigroup() 

Additive Abelian Semigroup generated by 1 

 

The semigroup can have a more complicated structure when the 

uniformizer is not in the domain:: 

 

sage: v = ZZ.valuation(2) 

sage: R.<x> = ZZ[] 

sage: w = GaussValuation(R, v) 

sage: u = w.augmentation(x, 5/3) 

sage: u.value_semigroup() 

Additive Abelian Semigroup generated by 1, 5/3 

 

""" 

from sage.categories.fields import Fields 

if self.domain() in Fields(): 

from .value_group import DiscreteValueSemigroup 

# return the semigroup generated by the elements of the group 

return DiscreteValueSemigroup([]) + self.value_group() 

raise NotImplementedError("can not determine value semigroup of %r"%(self,)) 

 

def element_with_valuation(self, s): 

r""" 

Return an element in the domain of this valuation with valuation 

``s``. 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: v.element_with_valuation(10) 

1024 

 

""" 

from sage.rings.all import QQ, ZZ, infinity 

s = QQ.coerce(s) 

if s not in self.value_semigroup(): 

raise ValueError("s must be in the value semigroup of this valuation but %r is not in %r"%(s, self.value_semigroup())) 

if s == 0: 

return self.domain().one() 

exp = s/self.value_group().gen() 

if exp not in ZZ: 

raise NotImplementedError("s must be a multiple of %r but %r is not"%(self.value_group().gen(), s)) 

ret = self.domain()(self.uniformizer() ** ZZ(exp)) 

return self.simplify(ret, error=s) 

 

@abstract_method 

def residue_ring(self): 

r""" 

Return the residue ring of this valuation, i.e., the elements of 

non-negative valuation modulo the elements of positive valuation. 

EXAMPLES:: 

 

sage: QQ.valuation(2).residue_ring() 

Finite Field of size 2 

sage: valuations.TrivialValuation(QQ).residue_ring() 

Rational Field 

 

Note that a residue ring always exists, even when a residue field 

may not:: 

 

sage: valuations.TrivialPseudoValuation(QQ).residue_ring() 

Quotient of Rational Field by the ideal (1) 

sage: valuations.TrivialValuation(ZZ).residue_ring() 

Integer Ring 

sage: GaussValuation(ZZ['x'], ZZ.valuation(2)).residue_ring() 

Univariate Polynomial Ring in x over Finite Field of size 2 (using ...) 

 

 

""" 

 

def residue_field(self): 

r""" 

Return the residue field of this valuation, i.e., the field of 

fractions of the :meth:`residue_ring`, the elements of non-negative 

valuation modulo the elements of positive valuation. 

 

EXAMPLES:: 

 

sage: QQ.valuation(2).residue_field() 

Finite Field of size 2 

sage: valuations.TrivialValuation(QQ).residue_field() 

Rational Field 

 

sage: valuations.TrivialValuation(ZZ).residue_field() 

Rational Field 

sage: GaussValuation(ZZ['x'], ZZ.valuation(2)).residue_field() 

Rational function field in x over Finite Field of size 2 

 

""" 

ret = self.residue_ring() 

from sage.categories.fields import Fields 

if ret in Fields(): 

return ret 

from sage.rings.polynomial.polynomial_ring import is_PolynomialRing 

if is_PolynomialRing(ret): 

from sage.rings.function_field.all import FunctionField 

return FunctionField(ret.base_ring().fraction_field(), names=(ret.variable_name(),)) 

return ret.fraction_field() 

 

 

@abstract_method 

def reduce(self, x): 

r""" 

Return the image of ``x`` in the :meth:`residue_ring` of this 

valuation. 

 

EXAMPLES:: 

 

sage: v = QQ.valuation(2) 

sage: v.reduce(2) 

0 

sage: v.reduce(1) 

1 

sage: v.reduce(1/3) 

1 

sage: v.reduce(1/2) 

Traceback (most recent call last): 

... 

ValueError: reduction is only defined for elements of non-negative valuation 

 

""" 

 

@abstract_method 

def lift(self, X): 

r""" 

Return a lift of ``X`` in the domain which reduces down to ``X`` 

again via :meth:`reduce`. 

 

EXAMPLES:: 

 

sage: v = QQ.valuation(2) 

sage: v.lift(v.residue_ring().one()) 

1 

 

""" 

 

def extension(self, ring): 

r""" 

Return the unique extension of this valuation to ``ring``. 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: w = v.extension(QQ) 

sage: w.domain() 

Rational Field 

 

""" 

extensions = self.extensions(ring) 

assert(len(extensions)) 

if len(extensions) > 1: 

raise ValueError("there is no unique extension of %r from %r to %r"%(self, self.domain(), ring)) 

return extensions[0] 

 

def extensions(self, ring): 

r""" 

Return the extensions of this valuation to ``ring``. 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: v.extensions(QQ) 

[2-adic valuation] 

 

""" 

if ring is self.domain(): 

return [self] 

raise NotImplementedError("extending %r from %r to %r not implemented"%(self, self.domain(), ring)) 

 

def restriction(self, ring): 

r""" 

Return the restriction of this valuation to ``ring``. 

 

EXAMPLES:: 

 

sage: v = QQ.valuation(2) 

sage: w = v.restriction(ZZ) 

sage: w.domain() 

Integer Ring 

 

""" 

if ring is self.domain(): 

return self 

raise NotImplementedError("restricting %r from %r to %r not implemented"%(self, self.domain(), ring)) 

 

def change_domain(self, ring): 

r""" 

Return this valuation over ``ring``. 

 

Unlike :meth:`extension` or :meth:`restriction`, this might not be 

completely sane mathematically. It is essentially a conversion of 

this valuation into another space of valuations. 

 

EXAMPLES:: 

 

sage: v = QQ.valuation(3) 

sage: v.change_domain(ZZ) 

3-adic valuation 

 

""" 

if ring is self.domain(): 

return self 

if self.domain().is_subring(ring): 

return self.extension(ring) 

if ring.is_subring(self.domain()): 

return self.restriction(ring) 

raise NotImplementedError("changing %r from %r to %r not implemented"%(self, self.domain(), ring)) 

 

def scale(self, scalar): 

r""" 

Return this valuation scaled by ``scalar``. 

 

INPUT: 

 

- ``scalar`` -- a non-negative rational number or infinity 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(3) 

sage: w = v.scale(3) 

sage: w(3) 

3 

 

Scaling can also be done through multiplication with a scalar:: 

 

sage: w/3 == v 

True 

 

Multiplication by zero produces the trivial discrete valuation:: 

 

sage: w = 0*v 

sage: w(3) 

0 

sage: w(0) 

+Infinity 

 

Multiplication by infinity produces the trivial discrete 

pseudo-valuation:: 

 

sage: w = infinity*v 

sage: w(3) 

+Infinity 

sage: w(0) 

+Infinity 

 

""" 

from sage.rings.all import infinity 

if scalar is infinity: 

from .trivial_valuation import TrivialPseudoValuation 

return TrivialPseudoValuation(self.domain()) 

if scalar == 0: 

from .trivial_valuation import TrivialValuation 

return TrivialValuation(self.domain()) 

if scalar == 1: 

return self 

if scalar < 0: 

raise ValueError("scalar must be non-negative") 

if self.is_trivial(): 

return self 

 

from .scaled_valuation import ScaledValuation_generic 

if isinstance(self, ScaledValuation_generic): 

return self._base_valuation.scale(scalar * self._scale) 

 

from .scaled_valuation import ScaledValuation 

return ScaledValuation(self, scalar) 

 

def separating_element(self, others): 

r""" 

Return an element in the domain of this valuation which has 

positive valuation with respect to this valuation but negative 

valuation with respect to the valuations in ``others``. 

 

EXAMPLES:: 

 

sage: v2 = QQ.valuation(2) 

sage: v3 = QQ.valuation(3) 

sage: v5 = QQ.valuation(5) 

sage: v2.separating_element([v3,v5]) 

4/15 

 

""" 

try: 

iter(others) 

except TypeError: 

raise ValueError("others must be a list of valuations") 

 

for other in others + [self]: 

if other.parent() is not self.parent(): 

raise ValueError("all valuations must be valuations on %r but %r is a valuation on %r"%(self.domain(), other, other.domain())) 

if not other.is_discrete_valuation(): 

raise ValueError("all valuationss must be discrete valuations but %r is not"%(other,)) 

if other.is_trivial(): 

raise ValueError("all valuations must be non-trivial but %r is not"%(other,)) 

 

if len(others)==0: 

return self.uniformizer() 

 

# see the proof of Lemma 6.9 in http://www1.spms.ntu.edu.sg/~frederique/antchap6.pdf 

ret = self._strictly_separating_element(others[0]) 

for i in range(1, len(others)): 

# ret is an element which separates self and others[:i] 

if others[i](ret) < 0: 

# it also separates self and others[i] 

continue 

 

delta = self._strictly_separating_element(others[i]) 

if others[i](ret) == 0: 

# combining powers of ret and delta, we produce a 

# separating element for self and others[:i+1] 

factor = ret 

ret = delta 

while any(other(ret) >= 0 for other in others[:i]): 

assert(others[i](ret) < 0) 

ret *= factor 

else: # others[i](ret) > 0 

# construct an element which approximates a unit with respect to others[i] 

# and has negative valuation with respect to others[:i] 

from sage.rings.all import NN 

for r in iter(NN): 

# When we enter this loop we are essentially out of 

# luck. The size of the coefficients is likely going 

# through the roof here and this is not going to 

# terminate in reasonable time. 

factor = (ret**r)/(1+ret**r) 

ret = factor * delta 

if all([other(ret) < 0 for other in others[:i+1]]): 

break 

return ret 

 

def _strictly_separating_element(self, other): 

r""" 

Return an element in the domain of this valuation which has 

positive valuation with respect to this valuation but negative 

valuation with respect to ``other``. 

 

.. NOTE:: 

 

Overriding this method tends to be a nuisance as you need to 

handle all possible types (as in Python type) of valuations. 

This is essentially the same problem that you have when 

implementing operators such as ``+`` or ``>=``. A sufficiently 

fancy multimethod implementation could solve that here but 

there is currently nothing like that in Sage/Python. 

 

EXAMPLES:: 

 

sage: v2 = QQ.valuation(2) 

sage: v3 = QQ.valuation(3) 

sage: v2._strictly_separating_element(v3) 

2/3 

 

""" 

from sage.rings.all import ZZ, NN, infinity 

 

numerator = self._weakly_separating_element(other) 

n = self(numerator) 

nn = other(numerator) 

assert(n > 0) 

assert(nn is not infinity) 

if (nn < 0): 

return numerator 

 

denominator = other._weakly_separating_element(self) 

d = self(denominator) 

dd = other(denominator) 

assert(dd > 0) 

assert(d is not infinity) 

if d < 0: 

# The following may fail if denominator is not inverible in the domain, 

# but we don't have a better option this generically. 

return self.domain()(~denominator) 

 

# We need non-negative integers a and b such that 

# a*n - b*d > 0 and a*nn - b*dd < 0 

if nn == 0: 

# the above becomes b != 0 and a/b > d/n 

b = 1 

a = (d/n + 1).floor() 

else: 

# Since n,nn,d,dd are all non-negative this is essentially equivalent to 

# a/b > d/n and b/a > nn/dd 

# which is  

# dd/nn > a/b > d/n 

assert(dd/nn > d/n) 

from sage.rings.continued_fraction import continued_fraction 

ab_cf = [] 

dn_cf = continued_fraction(d/n) 

ddnn_cf = continued_fraction(dd/nn) 

for i, (x,y) in enumerate(zip(dn_cf, ddnn_cf)): 

if x == y: 

ab_cf.append(x) 

elif x < y: 

if y > x+1 or len(ddnn_cf) > i+1: 

ab_cf.append(x+1) 

else: 

# the expansion of dd/nn is ending, so we can't append x+1 

ab_cf.extend([x,1,1]) 

elif y < x: 

if x > y+1 or len(dn_cf) > i+1: 

ab_cf.append(y+1) 

else: 

ab_cf.extend([y,1,1]) 

ab = continued_fraction(ab_cf).value() 

a,b = ab.numerator(), ab.denominator() 

 

ret = self.domain()(numerator**a / denominator**b) 

assert(self(ret) > 0) 

assert(other(ret) < 0) 

return ret 

 

def _weakly_separating_element(self, other): 

r""" 

Return an element in the domain of this valuation which has 

positive valuation with respect to this valuation and higher 

valuation with respect to this valuation than with respect to 

``other``. 

 

.. NOTE:: 

 

Overriding this method tends to be a nuisance as you need to 

handle all possible types (as in Python type) of valuations. 

This is essentially the same problem that you have when 

implementing operators such as ``+`` or ``>=``. A sufficiently 

fancy multimethod implementation could solve that here but 

there is currently nothing like that in Sage/Python. 

 

EXAMPLES:: 

 

sage: v2 = QQ.valuation(2) 

sage: v3 = QQ.valuation(3) 

sage: v2._weakly_separating_element(v3) 

2 

 

""" 

ret = self.uniformizer() 

if self(ret) > other(ret): 

return ret 

raise NotImplementedError("weakly separating element for %r and %r"%(self, other)) 

 

def shift(self, x, s): 

r""" 

Shift ``x`` in its expansion with respect to :meth:`uniformizer` by 

``s`` "digits". 

 

For non-negative ``s``, this just returns ``x`` multiplied by a 

power of the uniformizer `\pi`. 

 

For negative ``s``, it does the same but when not over a field, it 

drops coefficients in the `\pi`-adic expension which have negative 

valuation. 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: v.shift(1, 10) 

1024 

sage: v.shift(11, -1) 

5 

 

For some rings, there is no clear `\pi`-adic expansion. In this 

case, this method performs negative shifts by iterated division by 

the uniformizer and substraction of a lift of the reduction:: 

 

sage: R.<x> = ZZ[] 

sage: v = ZZ.valuation(2) 

sage: w = GaussValuation(R, v) 

sage: w.shift(x, 1) 

2*x 

sage: w.shift(2*x, -1) 

x 

sage: w.shift(x + 2*x^2, -1) 

x^2 

 

""" 

from sage.rings.all import ZZ 

x = self.domain().coerce(x) 

s = self.value_group()(s) 

if s == 0: 

return x 

 

s = ZZ(s / self.value_group().gen()) 

if s > 0: 

return x * self.uniformizer()**s 

else: # s < 0 

if ~self.uniformizer() in self.domain(): 

return self.domain()(x / self.uniformizer()**(-s)) 

else: 

for i in range(-s): 

if self(x) < 0: 

raise NotImplementedError("can not compute general shifts over non-fields which contain elements of negative valuation") 

x -= self.lift(self.reduce(x)) 

x //= self.uniformizer() 

return x 

 

def simplify(self, x, error=None, force=False): 

r""" 

Return a simplified version of ``x``. 

 

Produce an element which differs from ``x`` by an element of 

valuation strictly greater than the valuation of ``x`` (or strictly 

greater than ``error`` if set.) 

 

If ``force`` is not set, then expensive simplifications may be avoided. 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: v.simplify(6, force=True) 

2 

sage: v.simplify(6, error=0, force=True) 

0 

 

""" 

x = self.domain().coerce(x) 

 

if error is not None and self(x) > error: 

return self.domain().zero() 

return x 

 

def lower_bound(self, x): 

r""" 

Return a lower bound of this valuation at ``x``. 

 

Use this method to get an approximation of the valuation of ``x`` 

when speed is more important than accuracy. 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: v.lower_bound(2^10) 

10 

 

""" 

return self(x) 

 

def upper_bound(self, x): 

r""" 

Return an upper bound of this valuation at ``x``. 

 

Use this method to get an approximation of the valuation of ``x`` 

when speed is more important than accuracy. 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: v.upper_bound(2^10) 

10 

 

""" 

return self(x) 

 

def inverse(self, x, precision): 

r""" 

Return an approximate inverse of ``x``. 

 

The element returned is such that the product differs from 1 by an 

element of valuation at least ``precision``. 

 

INPUT: 

 

- ``x`` -- an element in the domain of this valuation 

 

- ``precision`` -- a rational or infinity 

 

EXAMPLES:: 

 

sage: v = ZZ.valuation(2) 

sage: x = 3 

sage: y = v.inverse(3, 2); y 

3 

sage: x*y - 1 

8 

 

This might not be possible for elements of positive valuation:: 

 

sage: v.inverse(2, 2) 

Traceback (most recent call last): 

... 

ValueError: element has no approximate inverse in this ring 

 

Of course this always works over fields:: 

 

sage: v = QQ.valuation(2) 

sage: v.inverse(2, 2) 

1/2 

 

""" 

try: 

return x.inverse_of_unit() 

except: 

raise NotImplementedError("can not compute approximate inverse with respect to this valuation") 

 

def _relative_size(self, x): 

r""" 

Return an estimate on the coefficient size of ``x``. 

 

The number returned is an estimate on the factor between the number of 

Bits used by ``x`` and the minimal number of bits used by an element 

congruent to ``x``. 

 

This is used by :meth:`simplify` to decide whether simplification of 

coefficients is going to lead to a significant shrinking of the 

coefficients of ``x``. 

 

EXAMPLES::  

 

sage: v = Qp(2).valuation() 

sage: v._relative_size(2) 

1 

 

Some valuations do not overwrite this method because simplification 

does not increase the speed of valuations, e.g., some `p`-adic 

valuations:: 

 

sage: v._relative_size(2**20) 

1 

 

""" 

return 1 

 

def _test_is_negative_pseudo_valuation(self, **options): 

r""" 

Check that :meth:`is_negative_pseudo_valuation` works correctly. 

 

TESTS:: 

 

sage: v = ZZ.valuation(3) 

sage: v._test_is_negative_pseudo_valuation() 

 

""" 

tester = self._tester(**options) 

 

if self.is_discrete_valuation(): 

tester.assertFalse(self.is_negative_pseudo_valuation()) 

return 

 

if not self.is_negative_pseudo_valuation(): 

X = self.domain().some_elements() 

for x in tester.some_elements(X): 

from sage.rings.all import infinity 

tester.assertNotEqual(self(x), -infinity) 

 

def _test_bounds(self, **options): 

r""" 

Check that :meth:`lower_bound` and :meth:`upper_bound` work 

correctly. 

 

TESTS:: 

 

sage: v = ZZ.valuation(3) 

sage: v._test_bounds() 

 

""" 

tester = self._tester(**options) 

 

X = self.domain().some_elements() 

for x in tester.some_elements(X): 

tester.assertGreaterEqual(self.upper_bound(x), self(x)) 

tester.assertLessEqual(self.lower_bound(x), self(x)) 

 

def _test_simplify(self, **options): 

r""" 

Check that :meth:`simplify` works correctly. 

 

TESTS:: 

 

sage: v = ZZ.valuation(3) 

sage: v._test_simplify() 

 

""" 

tester = self._tester(**options) 

 

try: 

k = self.residue_ring() 

has_residue_ring = True 

except NotImplementedError: 

# over non-fields (and especially polynomial rings over 

# non-fields) computation of the residue ring is often 

# difficult and not very interesting 

from sage.categories.fields import Fields 

if self.domain() not in Fields(): 

return 

raise 

 

X = self.domain().some_elements() 

for x in tester.some_elements(X): 

y = self.simplify(x) 

tester.assertEqual(self(x), self(y)) 

if self(x) >= 0 and has_residue_ring: 

tester.assertEqual(self.reduce(x), self.reduce(y)) 

 

if self.is_trivial() and not self.is_discrete_valuation(): 

return 

 

S = self.value_group().some_elements() 

from itertools import product 

for x,s in tester.some_elements(product(X, S)): 

y = self.simplify(x, error=s) 

if self.domain().is_exact(): 

tester.assertGreaterEqual(self(x-y), s) 

elif hasattr(y, 'precision_absolute'): 

tester.assertGreaterEqual(self(x-y), min(s, y.precision_absolute())) 

 

def _test_shift(self, **options): 

r""" 

Check that :meth:`shift` works correctly. 

 

TESTS:: 

 

sage: v = ZZ.valuation(3) 

sage: v._test_shift() 

 

""" 

if self.is_trivial() and not self.is_discrete_valuation(): 

return 

 

try: 

self.residue_ring() 

except Exception: 

# it is not clear what a shift should be in this case 

return 

 

tester = self._tester(**options) 

X = self.domain().some_elements() 

S = self.value_group().some_elements() 

from itertools import product 

for x,s in tester.some_elements(product(X, S)): 

if self(x) < 0 and ~self.uniformizer() not in self.domain(): 

# it is not clear what a shift should be in this case 

continue 

y = self.shift(x, s) 

if s >= 0: 

tester.assertGreaterEqual(self(y),self(x)) 

from sage.categories.all import Fields 

if self.domain().is_exact() and self.domain() in Fields(): 

# the shift here sometimes fails if elements implement 

# __floordiv__ incorrectly, see #23971 

tester.assertEqual(x, self.shift(y, -s)) 

 

def _test_scale(self, **options): 

r""" 

Check that :meth:`scale` works correctly. 

 

TESTS:: 

 

sage: v = ZZ.valuation(3) 

sage: v._test_scale() 

 

""" 

tester = self._tester(**options) 

 

from sage.rings.all import infinity, QQ 

from .trivial_valuation import TrivialValuation, TrivialPseudoValuation 

 

tester.assertEqual(QQ(0)*self, TrivialValuation(self.domain())) 

tester.assertEqual(infinity*self, TrivialPseudoValuation(self.domain())) 

 

for s in tester.some_elements(QQ.some_elements()): 

if s < 0: 

with tester.assertRaises(ValueError): 

s * self 

continue 

if s == 0: 

continue 

 

scaled = s * self 

 

tester.assertEqual(self.is_trivial(), scaled.is_trivial()) 

if not self.is_trivial(): 

tester.assertEqual(self.uniformizer(), scaled.uniformizer()) 

tester.assertEqual(scaled(self.uniformizer()), s * self(self.uniformizer())) 

unscaled = scaled / s 

tester.assertEqual(self, unscaled) 

 

def _test_add(self, **options): 

r""" 

Check that the (strict) triangle equality is satisfied for the 

valuation of this ring. 

 

TESTS:: 

 

sage: v = ZZ.valuation(3) 

sage: v._test_add() 

 

""" 

tester = self._tester(**options) 

S = self.domain().some_elements() 

from itertools import product 

for x,y in tester.some_elements(product(S,S)): 

tester.assertGreaterEqual(self(x+y),min(self(x),self(y))) 

if self(x) != self(y): 

tester.assertEqual(self(x+y),min(self(x),self(y))) 

 

def _test_infinite_zero(self, **options): 

r""" 

Check that zero is sent to infinity. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_infinite_zero() 

 

""" 

tester = self._tester(**options) 

from sage.rings.all import infinity 

tester.assertEqual(self(self.domain().zero()), infinity) 

 

def _test_mul(self, **options): 

r""" 

Check that multiplication translates to addition of valuations. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_mul() 

 

""" 

tester = self._tester(**options) 

S = self.domain().some_elements() 

from itertools import product 

for x,y in tester.some_elements(product(S,S)): 

from sage.rings.all import infinity 

if set([self(x), self(y)]) == set([infinity, -infinity]): 

continue 

tester.assertEqual(self(x*y),self(x)+self(y)) 

 

def _test_no_infinite_units(self, **options): 

r""" 

Checks that no units are sent to infinity. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_no_infinite_units() 

 

As multiplication translates to addition, pseudo-valuations which 

send a unit to infinity are necessarily trivial:: 

 

sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace 

sage: v = DiscretePseudoValuationSpace(QQ).an_element() 

sage: v(1) 

+Infinity 

sage: v.is_trivial() 

True 

 

""" 

if not self.is_discrete_valuation() and self.is_trivial(): 

return 

if self.is_negative_pseudo_valuation(): 

return 

 

from sage.rings.all import infinity 

tester = self._tester(**options) 

for x in tester.some_elements(self.domain().some_elements()): 

if self(x) is infinity: 

tester.assertFalse(x.is_unit()) 

 

def _test_value_group(self, **options): 

r""" 

Check correctness of the value group. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_value_group() 

 

""" 

from sage.rings.all import infinity 

tester = self._tester(**options) 

# check consistency of trivial valuations first 

if self.is_trivial(): 

if self(self.domain().one()) is infinity: 

# a trivial pseudo-valuation that sends everything to infinity 

with tester.assertRaises(ValueError): 

self.value_group() 

return 

 

# check that all valuations are in the value group 

for x in tester.some_elements(self.domain().some_elements()): 

if self(x) is not infinity and self(x) is not -infinity: 

tester.assertIn(self(x), self.value_group()) 

 

if not self.is_trivial(): 

# check that the uniformizer generates the value group 

tester.assertEqual(self.value_group().gen(), self(self.uniformizer())) 

 

def _test_value_semigroup(self, **options): 

r""" 

Check correctness of the value semigroup. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_value_semigroup() 

 

""" 

tester = self._tester(**options) 

 

if self.is_trivial() and not self.is_discrete_valuation(): 

# the trivial pseudo-valuation does not have a value semigroup 

return 

 

for s in tester.some_elements(self.value_semigroup().some_elements()): 

tester.assertIn(s, self.value_group()) 

 

def _test_element_with_valuation(self, **options): 

r""" 

Check correctness of :meth:`element_with_valuation`. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_element_with_valuation() 

 

""" 

tester = self._tester(**options) 

 

if self.is_trivial() and not self.is_discrete_valuation(): 

# the trivial pseudo-valuation does not have a value semigroup 

return 

 

for s in tester.some_elements(self.value_semigroup().some_elements()): 

tester.assertEqual(self(self.element_with_valuation(s)), s) 

 

def _test_residue_ring(self, **options): 

r""" 

Check the correctness of residue rings. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_residue_ring() 

 

""" 

tester = self._tester(**options) 

 

try: 

r = self.residue_ring() 

except NotImplementedError: 

# over non-fields (and especially polynomial rings over 

# non-fields) computation of the residue ring is often 

# difficult and not very interesting 

from sage.categories.fields import Fields 

if self.domain() not in Fields(): 

return 

raise 

 

if r.zero() == r.one(): 

# residue ring is the zero rng 

tester.assertGreater(self(1), 0) 

return 

 

c = self.residue_ring().characteristic() 

if c != 0: 

tester.assertGreater(self(c), 0) 

 

def _test_reduce(self, **options): 

r""" 

Check the correctness of reductions. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_reduce() 

 

""" 

tester = self._tester(**options) 

 

try: 

k = self.residue_ring() 

except NotImplementedError: 

# over non-fields (and especially polynomial rings over 

# non-fields) computation of the residue ring is often 

# difficult and not very interesting 

from sage.categories.fields import Fields 

if self.domain() not in Fields(): 

return 

raise 

 

for x in tester.some_elements(self.domain().some_elements()): 

if self(x) < 0: 

with tester.assertRaises((ValueError, ArithmeticError)): 

self.reduce(x) 

continue 

if self(x) == 0: 

y = self.reduce(x) 

tester.assertIn(y, self.residue_ring()) 

tester.assertNotEqual(y, 0) 

if x.is_unit() and ~x in self.domain(): 

tester.assertTrue(y.is_unit()) 

tester.assertIn(~y, self.residue_ring()) 

tester.assertEqual(~y, self.reduce(self.domain()(~x))) 

if self(x) > 0: 

tester.assertEqual(self.reduce(x), 0) 

 

def _test_lift(self, **options): 

r""" 

Check the correctness of lifts. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_lift() 

 

""" 

tester = self._tester(**options) 

 

try: 

k = self.residue_ring() 

except NotImplementedError: 

# over non-fields (and especially polynomial rings over 

# non-fields) computation of the residue ring is often 

# difficult and not very interesting 

from sage.categories.fields import Fields 

if self.domain() not in Fields(): 

return 

raise 

 

for X in tester.some_elements(self.residue_ring().some_elements()): 

x = self.lift(X) 

y = self.reduce(x) 

tester.assertEqual(X, y) 

if X != 0: 

tester.assertEqual(self(x), 0) 

 

def _test_restriction(self, **options): 

r""" 

Check the correctness of reductions. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_restriction() 

 

""" 

tester = self._tester(**options) 

 

tester.assertEqual(self.restriction(self.domain()), self) 

 

def _test_extension(self, **options): 

r""" 

Check the correctness of extensions. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_extension() 

 

""" 

tester = self._tester(**options) 

 

tester.assertEqual(self.extension(self.domain()), self) 

tester.assertEqual(self.extensions(self.domain()), [self]) 

 

def _test_change_domain(self, **options): 

r""" 

Check the correctness of :meth:`change_domain`. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_change_domain() 

 

""" 

tester = self._tester(**options) 

 

tester.assertEqual(self.change_domain(self.domain()), self) 

 

def _test_no_infinite_nonzero(self, **options): 

r""" 

Check that only zero is sent to infinity. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_no_infinite_nonzero() 

 

""" 

if not self.is_discrete_valuation(): 

return 

 

from sage.rings.all import infinity 

tester = self._tester(**options) 

for x in tester.some_elements(self.domain().some_elements()): 

if self(x) is infinity: 

tester.assertEqual(x, 0) 

 

def _test_residue_field(self, **options): 

r""" 

Check the correctness of residue fields. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_residue_field() 

 

""" 

if not self.is_discrete_valuation(): 

return 

 

tester = self._tester(**options) 

try: 

k = self.residue_field() 

except ValueError: 

from sage.categories.fields import Fields 

# a discrete valuation on a field has a residue field 

tester.assertFalse(self.domain() in Fields()) 

return 

except NotImplementedError: 

# over non-fields (and especially polynomial rings over 

# non-fields) computation of the residue ring is often 

# difficult and not very interesting 

from sage.categories.fields import Fields 

if self.domain() not in Fields(): 

return 

raise 

 

c = self.residue_field().characteristic() 

if c != 0: 

tester.assertGreater(self(c), 0) 

 

def _test_ge(self, **options): 

r""" 

Check the correctness of the ``>=`` operator. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_ge() 

 

""" 

tester = self._tester(**options) 

 

tester.assertGreaterEqual(self, self) 

 

if self.is_negative_pseudo_valuation(): 

return 

 

from .trivial_valuation import TrivialPseudoValuation, TrivialValuation 

tester.assertGreaterEqual(self, TrivialValuation(self.domain())) 

tester.assertLessEqual(self, TrivialPseudoValuation(self.domain())) 

 

def _test_le(self, **options): 

r""" 

Check the correctness of the ``<=`` operator. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_le() 

 

""" 

tester = self._tester(**options) 

 

tester.assertGreaterEqual(self, self) 

 

if self.is_negative_pseudo_valuation(): 

return 

 

from .trivial_valuation import TrivialPseudoValuation, TrivialValuation 

tester.assertLessEqual(TrivialValuation(self.domain()), self) 

tester.assertGreaterEqual(TrivialPseudoValuation(self.domain()), self) 

 

def _test_inverse(self, **options): 

r""" 

Check the correctness of :meth:`inverse`. 

 

TESTS:: 

 

sage: v = QQ.valuation(5) 

sage: v._test_inverse() 

 

""" 

tester = self._tester(**options) 

 

for x in tester.some_elements(self.domain().some_elements()): 

from sage.rings.all import infinity 

for prec in (0, 1, 42, infinity): 

try: 

y = self.inverse(x, prec) 

except NotImplementedError: 

continue 

except ValueError: 

if prec is not infinity: 

tester.assertNotEqual(self(x), 0) 

tester.assertFalse(x.is_unit()) 

continue 

 

tester.assertTrue(y.parent() is self.domain()) 

if self.domain().is_exact(): 

tester.assertGreaterEqual(self(x*y - 1), prec) 

 

 

from sage.categories.action import Action 

class ScaleAction(Action): 

r""" 

Action of integers, rationals and the infinity ring on valuations by 

scaling it. 

 

EXAMPLES:: 

 

sage: v = QQ.valuation(5) 

sage: from operator import mul 

sage: v.parent().get_action(ZZ, mul, self_on_left=False) 

Left action by Integer Ring on Discrete pseudo-valuations on Rational Field 

 

""" 

def _call_(self, s, v): 

r""" 

Let ``s`` act on ``v``. 

 

EXAMPLES:: 

 

sage: v = QQ.valuation(5) 

sage: 3*v # indirect doctest 

3 * 5-adic valuation 

 

""" 

if not self.is_left(): 

# for a right action, the parameters are swapped 

s,v = v,s 

return v.scale(s)