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

""" 

p-Adic Generic 

 

A generic superclass for all p-adic parents. 

 

AUTHORS: 

 

- David Roe 

- Genya Zaytman: documentation 

- David Harvey: doctests 

- Julian Rueth (2013-03-16): test methods for basic arithmetic 

 

""" 

 

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

# Copyright (C) 2007-2013 David Roe <roed.math@gmail.com> 

# William Stein <wstein@gmail.com> 

# Julian Rueth <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 print_function 

from __future__ import absolute_import 

 

from sage.misc.prandom import sample 

from sage.misc.misc import some_tuples 

from copy import copy 

 

from sage.structure.richcmp import richcmp 

from sage.categories.principal_ideal_domains import PrincipalIdealDomains 

from sage.categories.morphism import Morphism 

from sage.categories.fields import Fields 

from sage.rings.infinity import infinity 

from .local_generic import LocalGeneric 

from sage.rings.ring import PrincipalIdealDomain 

from sage.rings.integer import Integer 

from sage.rings.padics.padic_printing import pAdicPrinter 

from sage.rings.padics.precision_error import PrecisionError 

from sage.misc.cachefunc import cached_method 

from sage.structure.richcmp import richcmp_not_equal 

 

 

class pAdicGeneric(PrincipalIdealDomain, LocalGeneric): 

def __init__(self, base, p, prec, print_mode, names, element_class, category=None): 

""" 

Initialization. 

 

INPUT: 

 

- base -- Base ring. 

- p -- prime 

- print_mode -- dictionary of print options 

- names -- how to print the uniformizer 

- element_class -- the class for elements of this ring 

 

EXAMPLES:: 

 

sage: R = Zp(17) #indirect doctest 

""" 

if category is None: 

if self.is_field(): 

category = Fields() 

else: 

category = PrincipalIdealDomains() 

category = category.Metric().Complete() 

LocalGeneric.__init__(self, base, prec, names, element_class, category) 

self._printer = pAdicPrinter(self, print_mode) 

 

def some_elements(self): 

r""" 

Returns a list of elements in this ring. 

 

This is typically used for running generic tests (see :class:`TestSuite`). 

 

EXAMPLES:: 

 

sage: Zp(2,4).some_elements() 

[0, 1 + O(2^4), 2 + O(2^5), 1 + 2^2 + 2^3 + O(2^4), 2 + 2^2 + 2^3 + 2^4 + O(2^5)] 

""" 

p = self(self.prime()) 

a = self.gen() 

one = self.one() 

L = [self.zero(), one, p, (one+p+p).inverse_of_unit(), p-p**2] 

if a != p: 

L.extend([a, (one + a + p).inverse_of_unit()]) 

if self.is_field(): 

L.extend([~(p-p-a),p**(-20)]) 

return L 

 

def _modified_print_mode(self, print_mode): 

""" 

Returns a dictionary of print options, starting with self's 

print options but modified by the options in the dictionary 

print_mode. 

 

INPUT: 

 

- print_mode -- dictionary with keys in ['mode', 'pos', 'ram_name', 'unram_name', 'var_name', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet'] 

 

EXAMPLES:: 

 

sage: R = Zp(5) 

sage: R._modified_print_mode({'mode': 'bars'})['ram_name'] 

'5' 

""" 

if print_mode is None: 

print_mode = {} 

elif isinstance(print_mode, str): 

print_mode = {'mode': print_mode} 

for option in ['mode', 'pos', 'ram_name', 'unram_name', 'var_name', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet', 'show_prec']: 

if option not in print_mode: 

print_mode[option] = self._printer.dict()[option] 

return print_mode 

 

def ngens(self): 

""" 

Returns the number of generators of self. 

 

We conventionally define this as 1: for base rings, we take a 

uniformizer as the generator; for extension rings, we take a 

root of the minimal polynomial defining the extension. 

 

EXAMPLES:: 

 

sage: Zp(5).ngens() 

1 

sage: Zq(25,names='a').ngens() 

1 

""" 

return 1 

 

def gens(self): 

""" 

Returns a list of generators. 

 

EXAMPLES:: 

 

sage: R = Zp(5); R.gens() 

[5 + O(5^21)] 

sage: Zq(25,names='a').gens() 

[a + O(5^20)] 

sage: S.<x> = ZZ[]; f = x^5 + 25*x -5; W.<w> = R.ext(f); W.gens() 

[w + O(w^101)] 

""" 

return [self.gen()] 

 

def __richcmp__(self, other, op): 

""" 

Return 0 if self == other, and 1 or -1 otherwise. 

 

We consider two p-adic rings or fields to be equal if they are 

equal mathematically, and also have the same precision cap and 

printing parameters. 

 

EXAMPLES:: 

 

sage: R = Qp(7) 

sage: S = Qp(7,print_mode='val-unit') 

sage: R == S 

False 

sage: S = Qp(7,type='capped-rel') 

sage: R == S 

True 

sage: R is S 

True 

""" 

if not isinstance(other, pAdicGeneric): 

return NotImplemented 

 

lx = self.prime() 

rx = other.prime() 

if lx != rx: 

return richcmp_not_equal(lx, rx, op) 

 

lx = self.precision_cap() 

rx = other.precision_cap() 

if lx != rx: 

return richcmp_not_equal(lx, rx, op) 

 

return self._printer.richcmp_modes(other._printer, op) 

 

#def ngens(self): 

# return 1 

 

#def gen(self, n = 0): 

# if n != 0: 

# raise IndexError, "only one generator" 

# return self(self.prime()) 

 

def print_mode(self): 

r""" 

Returns the current print mode as a string. 

 

INPUT: 

 

self -- a p-adic field 

 

OUTPUT: 

 

string -- self's print mode 

 

EXAMPLES:: 

 

sage: R = Qp(7,5, 'capped-rel') 

sage: R.print_mode() 

'series' 

""" 

return self._printer._print_mode() 

 

def characteristic(self): 

r""" 

Returns the characteristic of self, which is always 0. 

 

INPUT: 

 

self -- a p-adic parent 

 

OUTPUT: 

 

integer -- self's characteristic, i.e., 0 

 

EXAMPLES:: 

 

sage: R = Zp(3, 10,'fixed-mod'); R.characteristic() 

0 

""" 

return Integer(0) 

 

def prime(self): 

""" 

Returns the prime, ie the characteristic of the residue field. 

 

INPUT: 

 

self -- a p-adic parent 

 

OUTPUT: 

 

integer -- the characteristic of the residue field 

 

EXAMPLES:: 

 

sage: R = Zp(3,5,'fixed-mod') 

sage: R.prime() 

3 

""" 

return self.prime_pow._prime() 

 

def uniformizer_pow(self, n): 

""" 

Returns p^n, as an element of self. 

 

If n is infinity, returns 0. 

 

EXAMPLES:: 

 

sage: R = Zp(3, 5, 'fixed-mod') 

sage: R.uniformizer_pow(3) 

3^3 + O(3^5) 

sage: R.uniformizer_pow(infinity) 

O(3^5) 

""" 

if n is infinity: 

return self(0) 

return self(self.prime_pow.pow_Integer_Integer(n)) 

 

def _unram_print(self): 

""" 

For printing. Will be None if the unramified subextension of self is of degree 1 over Z_p or Q_p. 

 

EXAMPLES:: 

 

sage: Zp(5)._unram_print() 

""" 

return None 

 

def residue_characteristic(self): 

""" 

Return the prime, i.e., the characteristic of the residue field. 

 

OUTPUT: 

 

integer -- the characteristic of the residue field 

 

EXAMPLES:: 

 

sage: R = Zp(3,5,'fixed-mod') 

sage: R.residue_characteristic() 

3 

""" 

return self.prime() 

 

def residue_class_field(self): 

""" 

Returns the residue class field. 

 

INPUT: 

 

self -- a p-adic ring 

 

OUTPUT: 

 

the residue field 

 

EXAMPLES:: 

 

sage: R = Zp(3,5,'fixed-mod') 

sage: k = R.residue_class_field() 

sage: k 

Finite Field of size 3 

""" 

from sage.rings.finite_rings.finite_field_constructor import GF 

return GF(self.prime()) 

 

def residue_field(self): 

""" 

Returns the residue class field. 

 

INPUT: 

 

self -- a p-adic ring 

 

OUTPUT: 

 

the residue field 

 

EXAMPLES:: 

 

sage: R = Zp(3,5,'fixed-mod') 

sage: k = R.residue_field() 

sage: k 

Finite Field of size 3 

""" 

return self.residue_class_field() 

 

def residue_ring(self, n): 

""" 

Returns the quotient of the ring of integers by the nth power of the maximal ideal. 

 

EXAMPLES:: 

 

sage: R = Zp(11) 

sage: R.residue_ring(3) 

Ring of integers modulo 1331 

""" 

from sage.rings.finite_rings.integer_mod_ring import Zmod 

return Zmod(self.prime()**n) 

 

def residue_system(self): 

""" 

Returns a list of elements representing all the residue classes. 

 

INPUT: 

 

self -- a p-adic ring 

 

OUTPUT: 

 

list of elements -- a list of elements representing all the residue classes 

 

EXAMPLES:: 

 

sage: R = Zp(3, 5,'fixed-mod') 

sage: R.residue_system() 

[O(3^5), 1 + O(3^5), 2 + O(3^5)] 

""" 

return [self(i) for i in self.residue_class_field()] 

 

def _fraction_field_key(self, print_mode=None): 

""" 

Changes print_mode from a dictionary to a tuple and raises a deprecation warning if it is present. 

 

EXAMPLES:: 

 

sage: Zp(5)._fraction_field_key() 

sage: Zp(5)._fraction_field_key({"pos":False}) 

doctest:warning 

... 

DeprecationWarning: Use the change method if you want to change print options in fraction_field() 

See http://trac.sagemath.org/23227 for details. 

(('pos', False),) 

""" 

if print_mode is not None: 

from sage.misc.superseded import deprecation 

deprecation(23227, "Use the change method if you want to change print options in fraction_field()") 

return tuple(sorted(print_mode.items())) 

 

@cached_method(key=_fraction_field_key) 

def fraction_field(self, print_mode=None): 

r""" 

Returns the fraction field of this ring or field. 

 

For `\ZZ_p`, this is the `p`-adic field with the same options, 

and for extensions, it is just the extension of the fraction 

field of the base determined by the same polynomial. 

 

The fraction field of a capped absolute ring is capped relative, 

and that of a fixed modulus ring is floating point. 

 

INPUT: 

 

- ``print_mode`` -- a dictionary containing print options. 

Defaults to the same options as this ring. 

 

OUTPUT: 

 

- the fraction field of this ring. 

 

EXAMPLES:: 

 

sage: R = Zp(5, print_mode='digits') 

sage: K = R.fraction_field(); repr(K(1/3))[3:] 

'31313131313131313132' 

sage: L = R.fraction_field({'max_ram_terms':4}); repr(L(1/3))[3:] 

doctest:warning 

... 

DeprecationWarning: Use the change method if you want to change print options in fraction_field() 

See http://trac.sagemath.org/23227 for details. 

'3132' 

sage: U.<a> = Zq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) 

sage: U.fraction_field() 

Unramified Extension in a defined by x^4 + 7*x^2 + 10*x + 3 with capped relative precision 6 over 17-adic Field 

sage: U.fraction_field({"pos":False}) == U.fraction_field() 

False 

 

TESTS:: 

 

sage: R = ZpLC(2); R 

doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. 

See http://trac.sagemath.org/23505 for details. 

2-adic Ring with lattice-cap precision 

sage: K = R.fraction_field(); K 

2-adic Field with lattice-cap precision 

 

sage: K = QpLC(2); K2 = K.fraction_field({'mode':'terse'}) 

sage: K2 is K 

False 

sage: K = QpLC(2, label='test'); K 

2-adic Field with lattice-cap precision (label: test) 

sage: K.fraction_field() 

2-adic Field with lattice-cap precision (label: test) 

sage: K.fraction_field({'mode':'series'}) is K 

True 

""" 

if self.is_field() and print_mode is None: 

return self 

if print_mode is None: 

return self.change(field=True) 

else: 

return self.change(field=True, **print_mode) 

 

def integer_ring(self, print_mode=None): 

r""" 

Returns the ring of integers of this ring or field. 

 

For `\QQ_p`, this is the `p`-adic ring with the same options, 

and for extensions, it is just the extension of the ring 

of integers of the base determined by the same polynomial. 

 

INPUT: 

 

- ``print_mode`` -- a dictionary containing print options. 

Defaults to the same options as this ring. 

 

OUTPUT: 

 

- the ring of elements of this field with nonnegative valuation. 

 

EXAMPLES:: 

 

sage: K = Qp(5, print_mode='digits') 

sage: R = K.integer_ring(); repr(R(1/3))[3:] 

'31313131313131313132' 

sage: S = K.integer_ring({'max_ram_terms':4}); repr(S(1/3))[3:] 

doctest:warning 

... 

DeprecationWarning: Use the change method if you want to change print options in integer_ring() 

See http://trac.sagemath.org/23227 for details. 

'3132' 

sage: U.<a> = Qq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) 

sage: U.integer_ring() 

Unramified Extension in a defined by x^4 + 7*x^2 + 10*x + 3 with capped relative precision 6 over 17-adic Ring 

sage: U.fraction_field({"print_mode":"terse"}) == U.fraction_field() 

doctest:warning 

... 

DeprecationWarning: Use the change method if you want to change print options in fraction_field() 

See http://trac.sagemath.org/23227 for details. 

False 

 

TESTS:: 

 

sage: K = QpLC(2); K 

2-adic Field with lattice-cap precision 

sage: R = K.integer_ring(); R 

2-adic Ring with lattice-cap precision 

 

sage: R = ZpLC(2); R2 = R.integer_ring({'mode':'terse'}) 

sage: R2 is R 

False 

sage: R = ZpLC(2, label='test'); R 

2-adic Ring with lattice-cap precision (label: test) 

sage: R.integer_ring() 

2-adic Ring with lattice-cap precision (label: test) 

sage: R.integer_ring({'mode':'series'}) is R 

True 

""" 

#Currently does not support fields with non integral defining polynomials. This should change when the padic_general_extension framework gets worked out. 

if not self.is_field() and print_mode is None: 

return self 

if print_mode is None: 

return self.change(field=False) 

else: 

from sage.misc.superseded import deprecation 

deprecation(23227, "Use the change method if you want to change print options in integer_ring()") 

return self.change(field=False, **print_mode) 

 

def teichmuller(self, x, prec = None): 

r""" 

Returns the teichmuller representative of x. 

 

INPUT: 

 

- self -- a p-adic ring 

- x -- something that can be cast into self 

 

OUTPUT: 

 

- element -- the teichmuller lift of x 

 

EXAMPLES:: 

 

sage: R = Zp(5, 10, 'capped-rel', 'series') 

sage: R.teichmuller(2) 

2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + O(5^10) 

sage: R = Qp(5, 10,'capped-rel','series') 

sage: R.teichmuller(2) 

2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + O(5^10) 

sage: R = Zp(5, 10, 'capped-abs', 'series') 

sage: R.teichmuller(2) 

2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + O(5^10) 

sage: R = Zp(5, 10, 'fixed-mod', 'series') 

sage: R.teichmuller(2) 

2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + O(5^10) 

sage: R = Zp(5,5) 

sage: S.<x> = R[] 

sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 

sage: W.<w> = R.ext(f) 

sage: y = W.teichmuller(3); y 

3 + 3*w^5 + w^7 + 2*w^9 + 2*w^10 + 4*w^11 + w^12 + 2*w^13 + 3*w^15 + 2*w^16 + 3*w^17 + w^18 + 3*w^19 + 3*w^20 + 2*w^21 + 2*w^22 + 3*w^23 + 4*w^24 + O(w^25) 

sage: y^5 == y 

True 

sage: g = x^3 + 3*x + 3 

sage: A.<a> = R.ext(g) 

sage: b = A.teichmuller(1 + 2*a - a^2); b 

(4*a^2 + 2*a + 1) + 2*a*5 + (3*a^2 + 1)*5^2 + (a + 4)*5^3 + (a^2 + a + 1)*5^4 + O(5^5) 

sage: b^125 == b 

True 

 

We check that :trac:`23736` is resolved:: 

 

sage: R.teichmuller(GF(5)(2)) 

2 + 5 + 2*5^2 + 5^3 + 3*5^4 + O(5^5) 

 

AUTHORS: 

 

- Initial version: David Roe 

- Quadratic time version: Kiran Kedlaya <kedlaya@math.mit.edu> (3/27/07) 

""" 

ans = self(x) if prec is None else self(x, prec) 

# Since teichmuller representatives are defined at infinite precision, 

# we can lift to precision prec, as long as the absolute precision of ans is positive. 

if ans.precision_absolute() <= 0: 

raise ValueError("Not enough precision to determine Teichmuller representative") 

if ans.valuation() > 0: 

return self(0) if prec is None else self(0, prec) 

ans = ans.lift_to_precision(prec) 

if ans is x: 

ans = copy(ans) 

ans._teichmuller_set_unsafe() 

return ans 

 

def teichmuller_system(self): 

r""" 

Returns a set of teichmuller representatives for the invertible elements of `\ZZ / p\ZZ`. 

 

INPUT: 

 

- self -- a p-adic ring 

 

OUTPUT: 

 

- list of elements -- a list of teichmuller representatives for the invertible elements of `\ZZ / p\ZZ` 

 

EXAMPLES:: 

 

sage: R = Zp(3, 5,'fixed-mod', 'terse') 

sage: R.teichmuller_system() 

[1 + O(3^5), 242 + O(3^5)] 

 

Check that :trac:`20457` is fixed:: 

 

sage: F.<a> = Qq(5^2,6) 

sage: F.teichmuller_system()[3] 

(2*a + 2) + (4*a + 1)*5 + 4*5^2 + (2*a + 1)*5^3 + (4*a + 1)*5^4 + (2*a + 3)*5^5 + O(5^6) 

 

NOTES: 

 

Should this return 0 as well? 

""" 

R = self.residue_class_field() 

prec = self.precision_cap() 

return [self.teichmuller(self(i).lift_to_precision(prec)) for i in R if i != 0] 

 

# def different(self): 

# raise NotImplementedError 

 

# def automorphisms(self): 

# r""" 

# Returns the group of automorphisms of `\ZZ_p`, i.e. the trivial group. 

# """ 

# raise NotImplementedError 

 

# def galois_group(self): 

# r""" 

# Returns the Galois group of `\ZZ_p`, i.e. the trivial group. 

# """ 

# raise NotImplementedError 

 

# def hasGNB(self): 

# r""" 

# Returns whether or not `\ZZ_p` has a Gauss Normal Basis. 

# """ 

# raise NotImplementedError 

 

def extension(self, modulus, prec = None, names = None, print_mode = None, implementation='FLINT', **kwds): 

""" 

Create an extension of this p-adic ring. 

 

EXAMPLES:: 

 

sage: k = Qp(5) 

sage: R.<x> = k[] 

sage: l.<w> = k.extension(x^2-5); l 

Eisenstein Extension in w defined by x^2 - 5 with capped relative precision 40 over 5-adic Field 

 

sage: F = list(Qp(19)['x'](cyclotomic_polynomial(5)).factor())[0][0] 

sage: L = Qp(19).extension(F, names='a') 

sage: L 

Unramified Extension in a defined by x^2 + 8751674996211859573806383*x + 1 with capped relative precision 20 over 19-adic Field 

""" 

from sage.rings.padics.factory import ExtensionFactory 

if print_mode is None: 

print_mode = {} 

elif isinstance(print_mode, str): 

print_mode = {'print_mode': print_mode} 

else: 

if not isinstance(print_mode, dict): 

print_mode = dict(print_mode) 

for option in ['mode', 'pos', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet']: 

if option in print_mode: 

print_mode["print_" + option] = print_mode[option] 

del print_mode[option] 

elif "print_" + option not in print_mode: 

if "print_" + option in kwds: 

print_mode["print_" + option] = kwds["print_" + option] 

else: 

print_mode["print_" + option] = self._printer.dict()[option] 

for option in ['ram_name', 'unram_name', 'var_name']: 

if option not in print_mode: 

if option in kwds: 

print_mode[option] = kwds[option] 

else: 

print_mode[option] = self._printer.dict()[option] 

return ExtensionFactory(base=self, modulus=modulus, prec=prec, names=names, check = True, implementation=implementation, **print_mode) 

 

def _test_add(self, **options): 

""" 

Test addition of elements of this ring. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_add() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

 

""" 

tester = self._tester(**options) 

elements = tester.some_elements() 

 

for x in elements: 

y = x + self.zero() 

tester.assertEqual(y,x) 

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

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

 

for x,y in some_tuples(elements, 2, tester._max_runs): 

z = x + y 

tester.assertIs(z.parent(), self) 

zprec = min(x.precision_absolute(), y.precision_absolute()) 

if self.is_lattice_prec(): 

tester.assertGreaterEqual(z.precision_absolute(), zprec) 

elif not self.is_floating_point(): 

tester.assertEqual(z.precision_absolute(), zprec) 

tester.assertGreaterEqual(z.valuation(), min(x.valuation(),y.valuation())) 

if x.valuation() != y.valuation(): 

tester.assertEqual(z.valuation(), min(x.valuation(),y.valuation())) 

tester.assertTrue(y.is_equal_to(z-x,zprec)) 

tester.assertTrue(x.is_equal_to(z-y,zprec)) 

 

def _test_sub(self, **options): 

""" 

Test subtraction on elements of this ring. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_sub() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

 

""" 

tester = self._tester(**options) 

 

elements = list(tester.some_elements()) 

for x in elements: 

y = x - self.zero() 

tester.assertEqual(y, x) 

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

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

 

for x,y in some_tuples(elements, 2, tester._max_runs): 

z = x - y 

tester.assertIs(z.parent(), self) 

zprec = min(x.precision_absolute(), y.precision_absolute()) 

if self.is_lattice_prec(): 

tester.assertGreaterEqual(z.precision_absolute(), zprec) 

elif not self.is_floating_point(): 

tester.assertEqual(z.precision_absolute(), zprec) 

tester.assertGreaterEqual(z.valuation(), min(x.valuation(),y.valuation())) 

if x.valuation() != y.valuation(): 

tester.assertEqual(z.valuation(), min(x.valuation(),y.valuation())) 

tester.assertTrue((-y).is_equal_to(z - x,zprec)) 

tester.assertTrue(x.is_equal_to(z + y,zprec)) 

 

def _test_invert(self, **options): 

""" 

Test multiplicative inversion of elements of this ring. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_invert() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

 

""" 

tester = self._tester(**options) 

 

elements = tester.some_elements() 

for x in elements: 

try: 

y = ~x 

except (ZeroDivisionError, PrecisionError, ValueError): 

tester.assertFalse(x.is_unit()) 

if not self.is_fixed_mod(): tester.assertTrue(x.is_zero()) 

else: 

try: 

e = y * x 

except ZeroDivisionError: 

tester.assertTrue(self.is_floating_point() and (x.is_zero() or y.is_zero())) 

else: 

tester.assertFalse(x.is_zero()) 

tester.assertIs(y.parent(), self if self.is_fixed_mod() else self.fraction_field()) 

tester.assertTrue(e.is_one()) 

tester.assertEqual(e.precision_relative(), x.precision_relative()) 

tester.assertEqual(y.valuation(), -x.valuation()) 

 

def _test_mul(self, **options): 

""" 

Test multiplication of elements of this ring. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_mul() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

 

""" 

tester = self._tester(**options) 

 

elements = list(tester.some_elements()) 

for x,y in some_tuples(elements, 2, tester._max_runs): 

z = x * y 

tester.assertIs(z.parent(), self) 

if self.is_capped_relative() or self.is_floating_point(): 

tester.assertEqual(z.precision_relative(), min(x.precision_relative(), y.precision_relative())) 

else: 

tester.assertLessEqual(z.precision_relative(), min(x.precision_relative(), y.precision_relative())) 

if not z.is_zero(): 

tester.assertEqual(z.valuation(), x.valuation() + y.valuation()) 

 

def _test_div(self, **options): 

""" 

Test division of elements of this ring. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_div() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

 

""" 

tester = self._tester(**options) 

 

elements = list(tester.some_elements()) 

for x,y in some_tuples(elements, 2, tester._max_runs): 

try: 

z = x / y 

except (ZeroDivisionError, PrecisionError, ValueError): 

if self.is_fixed_mod(): tester.assertFalse(y.is_unit()) 

else: tester.assertTrue(y.is_zero()) 

else: 

try: 

xx = z*y 

except ZeroDivisionError: 

tester.assertTrue(self.is_floating_point() and (z.is_zero() or y.is_zero())) 

else: 

tester.assertFalse(y.is_zero()) 

tester.assertIs(z.parent(), self if self.is_fixed_mod() else self.fraction_field()) 

# The following might be false if there is an absolute cap 

# tester.assertEqual(z.precision_relative(), min(x.precision_relative(), y.precision_relative())) 

if not x.is_zero(): 

tester.assertEqual(z.valuation(), x.valuation() - y.valuation()) 

tester.assertEqual(xx, x) 

 

def _test_neg(self, **options): 

""" 

Test the negation operator on elements of this ring. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_neg() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

""" 

tester = self._tester(**options) 

for x in tester.some_elements(): 

y = -x 

tester.assertIs(y.parent(), self) 

tester.assertTrue((x+y).is_zero()) 

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

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

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

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

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

 

def _test_log(self, **options): 

""" 

Test the log operator on elements of this ring. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_log() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

""" 

tester = self._tester(**options) 

for x in tester.some_elements(): 

if x.is_zero(): continue 

l = x.log(p_branch=0) 

tester.assertIs(l.parent(), self) 

tester.assertGreater(l.valuation(), 0) 

if self.is_capped_absolute() or self.is_capped_relative(): 

tester.assertEqual(x.precision_relative(), l.precision_absolute()) 

 

if self.is_capped_absolute() or self.is_capped_relative(): 

# In the fixed modulus setting, rounding errors may occur 

elements = list(tester.some_elements()) 

for x, y, b in some_tuples(elements, 3, tester._max_runs): 

if x.is_zero() or y.is_zero(): continue 

r1 = x.log(pi_branch=b) + y.log(pi_branch=b) 

r2 = (x*y).log(pi_branch=b) 

tester.assertEqual(r1, r2) 

 

p = self.prime() 

for x in tester.some_elements(): 

if x.is_zero(): continue 

if p == 2: 

a = 4 * x.unit_part() 

else: 

a = p * x.unit_part() 

b = a.exp().log() 

c = (1+a).log().exp() 

tester.assertEqual(a, b) 

tester.assertEqual(1+a, c) 

 

def _test_teichmuller(self, **options): 

""" 

Test Teichmuller lifts. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_teichmuller() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

""" 

tester = self._tester(**options) 

 

for x in tester.some_elements(): 

try: 

y = self.teichmuller(x) 

except ValueError: 

tester.assertTrue(x.valuation() < 0 or x.precision_absolute()==0) 

else: 

try: 

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

except (NotImplementedError, AttributeError): 

pass 

tester.assertEqual(y**self.residue_field().order(), y) 

 

def _test_convert_residue_field(self, **options): 

r""" 

Test that conversion of residue field elements back to this ring works. 

 

INPUT: 

 

- ``options`` -- any keyword arguments accepted by :meth:`_tester`. 

 

EXAMPLES:: 

 

sage: Zp(3)._test_convert_residue_field() 

 

.. SEEALSO:: 

 

:class:`TestSuite` 

""" 

tester = self._tester(**options) 

 

for x in tester.some_elements(): 

if x.valuation() < 0: 

continue 

if x.precision_absolute() <= 0: 

continue 

y = x.residue() 

z = self(y) 

tester.assertEqual(z.residue(), y) 

 

@cached_method 

def _log_unit_part_p(self): 

""" 

Compute the logarithm of the unit-part of `p`. 

 

If `\pi` is the uniformizer in this ring, then we can uniquely write 

`p=\pi^e u` where `u` is a `\pi`-adic unit. This method computes the 

logarithm of `u`. 

 

This is a helper method for 

:meth:`sage.rings.padics.padic_generic_element.pAdicGenericElement.log`. 

 

TESTS:: 

 

sage: R = Qp(3,5) 

sage: R._log_unit_part_p() 

O(3^5) 

 

sage: S.<x> = ZZ[] 

sage: W.<pi> = R.extension(x^3-3) 

sage: W._log_unit_part_p() 

O(pi^15) 

 

sage: W.<pi> = R.extension(x^3-3*x-3) 

sage: W._log_unit_part_p() 

2 + pi + 2*pi^2 + pi^4 + pi^5 + 2*pi^7 + 2*pi^8 + pi^9 + 2*pi^10 + pi^11 + pi^12 + 2*pi^14 + O(pi^15) 

 

""" 

return self(self.prime()).unit_part().log() 

 

def frobenius_endomorphism(self, n=1): 

""" 

INPUT: 

 

- ``n`` -- an integer (default: 1) 

 

OUTPUT: 

 

The `n`-th power of the absolute arithmetic Frobenius 

endomorphism on this field. 

 

EXAMPLES:: 

 

sage: K.<a> = Qq(3^5) 

sage: Frob = K.frobenius_endomorphism(); Frob 

Frobenius endomorphism on Unramified Extension ... lifting a |--> a^3 on the residue field 

sage: Frob(a) == a.frobenius() 

True 

 

We can specify a power:: 

 

sage: K.frobenius_endomorphism(2) 

Frobenius endomorphism on Unramified Extension ... lifting a |--> a^(3^2) on the residue field 

 

The result is simplified if possible:: 

 

sage: K.frobenius_endomorphism(6) 

Frobenius endomorphism on Unramified Extension ... lifting a |--> a^3 on the residue field 

sage: K.frobenius_endomorphism(5) 

Identity endomorphism of Unramified Extension ... 

 

Comparisons work:: 

 

sage: K.frobenius_endomorphism(6) == Frob 

True 

""" 

from .morphism import FrobeniusEndomorphism_padics 

return FrobeniusEndomorphism_padics(self, n) 

 

def _test_elements_eq_transitive(self, **options): 

""" 

The operator ``==`` is not transitive for `p`-adic numbers. We disable 

the check of the category framework by overriding this method. 

 

EXAMPLES: 

 

sage: R = Zp(3) 

sage: R(3) == R(0,1) 

True 

sage: R(0,1) == R(6) 

True 

sage: R(3) == R(6) 

False 

sage: R._test_elements_eq_transitive() 

 

""" 

pass 

 

def valuation(self): 

r""" 

Return the `p`-adic valuation on this ring. 

 

OUTPUT: 

 

a valuation that is normalized such that the rational prime `p` has 

valuation 1. 

 

EXAMPLES:: 

 

sage: K = Qp(3) 

sage: R.<a> = K[] 

sage: L.<a> = K.extension(a^3 - 3) 

sage: v = L.valuation(); v 

3-adic valuation 

sage: v(3) 

1 

sage: L(3).valuation() 

3 

 

The normalization is chosen such that the valuation restricts to the 

valuation on the base ring:: 

 

sage: v(3) == K.valuation()(3) 

True 

sage: v.restriction(K) == K.valuation() 

True 

 

.. SEEALSO:: 

 

:meth:`NumberField_generic.valuation() <sage.rings.number_field.number_field.NumberField_generic.valuation>`, 

:meth:`Order.valuation() <sage.rings.number_field.order.Order.valuation>` 

 

""" 

from sage.rings.padics.padic_valuation import pAdicValuation 

return pAdicValuation(self) 

 

class ResidueReductionMap(Morphism): 

""" 

Reduction map from a p-adic ring or field to its residue field or ring. 

 

These maps must be created using the :meth:`_create_` method in order 

to support categories correctly. 

 

EXAMPLES:: 

 

sage: from sage.rings.padics.padic_generic import ResidueReductionMap 

sage: R.<a> = Zq(125); k = R.residue_field() 

sage: f = ResidueReductionMap._create_(R, k); f 

Reduction morphism: 

From: Unramified Extension in a defined by x^3 + 3*x + 3 with capped relative precision 20 over 5-adic Ring 

To: Finite Field in a0 of size 5^3 

""" 

@staticmethod 

def _create_(R, k): 

""" 

Initialization. We have to implement this as a static method 

in order to call ``__make_element_class__``. 

 

INPUT: 

 

- ``R`` -- a `p`-adic ring or field. 

- ``k`` -- the residue field of ``R``, or a residue ring of ``R``. 

 

EXAMPLES:: 

 

sage: f = Zmod(49).convert_map_from(Zp(7)) 

sage: TestSuite(f).run() 

sage: K.<a> = Qq(125); k = K.residue_field(); f = k.convert_map_from(K) 

sage: TestSuite(f).run() 

""" 

if R.is_field(): 

from sage.categories.sets_with_partial_maps import SetsWithPartialMaps 

cat = SetsWithPartialMaps() 

else: 

from sage.categories.rings import Rings 

cat = Rings() 

from sage.categories.homset import Hom 

kfield = R.residue_field() 

N = k.cardinality() 

q = kfield.cardinality() 

n = N.exact_log(q) 

if N != q**n: 

raise RuntimeError("N must be a power of q") 

H = Hom(R, k, cat) 

f = H.__make_element_class__(ResidueReductionMap)(H) 

f._n = n 

if kfield is k: 

f._field = True 

else: 

f._field = False 

return f 

 

def is_surjective(self): 

""" 

The reduction map is surjective. 

 

EXAMPLES:: 

 

sage: GF(7).convert_map_from(Qp(7)).is_surjective() 

True 

""" 

return True 

 

def is_injective(self): 

""" 

The reduction map is far from injective. 

 

EXAMPLES:: 

 

sage: GF(5).convert_map_from(ZpCA(5)).is_injective() 

False 

""" 

return False 

 

def _call_(self, x): 

""" 

Evaluate this morphism. 

 

EXAMPLES:: 

 

sage: R.<a> = Zq(125); k = R.residue_field() 

sage: f = k.convert_map_from(R) 

sage: f(15) 

0 

sage: f(1/(1+a)) 

a0^2 + 4*a0 + 4 

 

sage: Zmod(121).convert_map_from(Qp(11))(3/11) 

Traceback (most recent call last): 

... 

ValueError: element must have non-negative valuation in order to compute residue. 

""" 

return x.residue(self._n, field=self._field, check_prec=self._field) 

 

def section(self): 

""" 

Returns the section from the residue ring or field 

back to the p-adic ring or field. 

 

EXAMPLES:: 

 

sage: GF(3).convert_map_from(Zp(3)).section() 

Lifting morphism: 

From: Finite Field of size 3 

To: 3-adic Ring with capped relative precision 20 

""" 

return ResidueLiftingMap._create_(self.codomain(), self.domain()) 

 

def _repr_type(self): 

""" 

Type of morphism, for printing. 

 

EXAMPLES:: 

 

sage: GF(3).convert_map_from(Zp(3))._repr_type() 

'Reduction' 

""" 

return "Reduction" 

 

def _richcmp_(self, other, op): 

r""" 

Compare this element to ``other`` with respect to ``op``. 

 

EXAMPLES:: 

 

sage: from sage.rings.padics.padic_generic import ResidueReductionMap 

sage: f = ResidueReductionMap._create_(Zp(3), GF(3)) 

sage: g = ResidueReductionMap._create_(Zp(3), GF(3)) 

sage: f is g 

False 

sage: f == g 

True 

""" 

if type(self) != type(other): 

return NotImplemented 

return richcmp((self.domain(), self.codomain()), (other.domain(), other.codomain()), op) 

 

# A class for the Teichmuller lift would also be reasonable.... 

 

class ResidueLiftingMap(Morphism): 

""" 

Lifting map to a p-adic ring or field from its residue field or ring. 

 

These maps must be created using the :meth:`_create_` method in order 

to support categories correctly. 

 

EXAMPLES:: 

 

sage: from sage.rings.padics.padic_generic import ResidueLiftingMap 

sage: R.<a> = Zq(125); k = R.residue_field() 

sage: f = ResidueLiftingMap._create_(k, R); f 

Lifting morphism: 

From: Finite Field in a0 of size 5^3 

To: Unramified Extension in a defined by x^3 + 3*x + 3 with capped relative precision 20 over 5-adic Ring 

""" 

@staticmethod 

def _create_(k, R): 

""" 

Initialization. We have to implement this as a static method 

in order to call ``__make_element_class__``. 

 

INPUT: 

 

- ``k`` -- the residue field of ``R``, or a residue ring of ``R``. 

- ``R`` -- a `p`-adic ring or field. 

 

EXAMPLES:: 

 

sage: f = Zp(3).convert_map_from(Zmod(81)) 

sage: TestSuite(f).run() 

""" 

from sage.categories.sets_cat import Sets 

from sage.categories.homset import Hom 

kfield = R.residue_field() 

N = k.cardinality() 

q = kfield.cardinality() 

n = N.exact_log(q) 

if N != q**n: 

raise RuntimeError("N must be a power of q") 

H = Hom(k, R, Sets()) 

f = H.__make_element_class__(ResidueLiftingMap)(H) 

f._n = n 

return f 

 

def _call_(self, x): 

""" 

Evaluate this morphism. 

 

EXAMPLES:: 

 

sage: R.<a> = Zq(27); k = R.residue_field(); a0 = k.gen() 

sage: f = R.convert_map_from(k); f 

Lifting morphism: 

From: Finite Field in a0 of size 3^3 

To: Unramified Extension in a defined by x^3 + 2*x + 1 with capped relative precision 20 over 3-adic Ring 

sage: f(a0 + 1) 

(a + 1) + O(3) 

 

sage: Zp(3)(Zmod(81)(0)) 

O(3^4) 

""" 

R = self.codomain() 

if R.degree() == 1: 

return R.element_class(R, x, self._n) 

elif R.f() == 1: 

return R([x], self._n) 

elif R.e() == 1: 

return R(x.polynomial().list(), self._n) 

else: 

raise NotImplementedError 

 

def _call_with_args(self, x, args=(), kwds={}): 

""" 

Evaluate this morphism with extra arguments. 

 

EXAMPLES:: 

 

sage: f = Zp(2).convert_map_from(Zmod(128)) 

sage: f(7, 5) # indirect doctest 

1 + 2 + 2^2 + O(2^5) 

""" 

R = self.codomain() 

if args: 

args = (min(args[0], self._n),) + args[1:] 

else: 

kwds['absprec'] = min(kwds.get('absprec', self._n), self._n) 

if R.degree() == 1: 

return R.element_class(R, x, *args, **kwds) 

elif R.f() == 1: 

return R([x], *args, **kwds) 

elif R.e() == 1: 

return R(x.polynomial().list(), *args, **kwds) 

else: 

raise NotImplementedError 

 

def _repr_type(self): 

""" 

Type of morphism, for printing. 

 

EXAMPLES:: 

 

sage: Zp(3).convert_map_from(GF(3))._repr_type() 

'Lifting' 

""" 

return "Lifting" 

 

def _richcmp_(self, other, op): 

r""" 

Compare this element to ``other`` with respect to ``op``. 

 

EXAMPLES:: 

 

sage: from sage.rings.padics.padic_generic import ResidueLiftingMap 

sage: f = ResidueLiftingMap._create_(GF(3), Zp(3)) 

sage: g = ResidueLiftingMap._create_(GF(3), Zp(3)) 

sage: f is g 

False 

sage: f == g 

True 

""" 

if type(self) != type(other): 

return NotImplemented 

return richcmp((self.domain(), self.codomain()), (other.domain(), other.codomain()), op) 

 

def local_print_mode(obj, print_options, pos = None, ram_name = None): 

r""" 

Context manager for safely temporarily changing the print_mode 

of a p-adic ring/field. 

 

EXAMPLES:: 

 

sage: R = Zp(5) 

sage: R(45) 

4*5 + 5^2 + O(5^21) 

sage: with local_print_mode(R, 'val-unit'): 

....: print(R(45)) 

5 * 9 + O(5^21) 

 

.. NOTE:: 

 

For more documentation see ``localvars`` in parent_gens.pyx 

""" 

if isinstance(print_options, str): 

print_options = {'mode': print_options} 

elif not isinstance(print_options, dict): 

raise TypeError("print_options must be a dictionary or a string") 

if pos is not None: 

print_options['pos'] = pos 

if ram_name is not None: 

print_options['ram_name'] = ram_name 

for option in ['mode', 'pos', 'ram_name', 'unram_name', 'var_name', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet']: 

if option not in print_options: 

print_options[option] = obj._printer.dict()[option] 

return pAdicPrinter(obj, print_options)