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

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

""" 

Local Generic Element 

  

This file contains a common superclass for `p`-adic elements and power 

series elements. 

  

AUTHORS: 

  

- David Roe: initial version 

  

- Julian Rueth (2012-10-15, 2014-06-25, 2017-08-04): added inverse_of_unit(); improved 

add_bigoh(); added _test_expansion() 

""" 

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

# Copyright (C) 2007-2017 David Roe <roed@math.harvard.edu> 

# 2012-2017 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 sage.rings.infinity import infinity 

from sage.structure.element cimport ModuleElement, RingElement, CommutativeRingElement 

from sage.structure.element import coerce_binop 

from itertools import islice 

  

cdef class LocalGenericElement(CommutativeRingElement): 

#cpdef _add_(self, right): 

# raise NotImplementedError 

  

cpdef _div_(self, right): 

r""" 

Returns the quotient of ``self`` by ``right``. 

  

INPUT: 

  

- ``self`` -- a `p`-adic element. 

  

- ``right`` -- a `p`-adic element distinguishable from zero. 

In a fixed-modulus ring, this element must be a unit. 

  

EXAMPLES:: 

  

sage: R = Zp(7, 4, 'capped-rel', 'series'); R(3)/R(5) 

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

sage: R(2/3) / R(1/3) #indirect doctest 

2 + O(7^4) 

sage: R(49) / R(7) 

7 + O(7^5) 

sage: R = Zp(7, 4, 'capped-abs', 'series'); 1/R(7) 

7^-1 + O(7^2) 

sage: R = Zp(7, 4, 'fixed-mod'); 1/R(7) 

Traceback (most recent call last): 

... 

ValueError: cannot invert non-unit 

""" 

# this doctest doesn't actually test the function, since it's overridden. 

return self * ~right 

  

def inverse_of_unit(self): 

r""" 

Returns the inverse of ``self`` if ``self`` is a unit. 

  

OUTPUT: 

  

- an element in the same ring as ``self`` 

  

EXAMPLES:: 

  

sage: R = ZpCA(3,5) 

sage: a = R(2); a 

2 + O(3^5) 

sage: b = a.inverse_of_unit(); b 

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

  

A ``ZeroDivisionError`` is raised if an element has no inverse in the 

ring:: 

  

sage: R(3).inverse_of_unit() 

Traceback (most recent call last): 

... 

ZeroDivisionError: Inverse does not exist. 

  

Unlike the usual inverse of an element, the result is in the same ring 

as ``self`` and not just in its fraction field:: 

  

sage: c = ~a; c 

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

sage: a.parent() 

3-adic Ring with capped absolute precision 5 

sage: b.parent() 

3-adic Ring with capped absolute precision 5 

sage: c.parent() 

3-adic Field with capped relative precision 5 

  

For fields this does of course not make any difference:: 

  

sage: R = QpCR(3,5) 

sage: a = R(2) 

sage: b = a.inverse_of_unit() 

sage: c = ~a 

sage: a.parent() 

3-adic Field with capped relative precision 5 

sage: b.parent() 

3-adic Field with capped relative precision 5 

sage: c.parent() 

3-adic Field with capped relative precision 5 

  

TESTS: 

  

Test that this works for all kinds of p-adic base elements:: 

  

sage: ZpCA(3,5)(2).inverse_of_unit() 

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

sage: ZpCR(3,5)(2).inverse_of_unit() 

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

sage: ZpFM(3,5)(2).inverse_of_unit() 

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

sage: QpCR(3,5)(2).inverse_of_unit() 

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

  

Over unramified extensions:: 

  

sage: R = ZpCA(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 + 1 ) 

sage: t.inverse_of_unit() 

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

  

sage: R = ZpCR(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 + 1 ) 

sage: t.inverse_of_unit() 

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

  

sage: R = ZpFM(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 + 1 ) 

sage: t.inverse_of_unit() 

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

  

sage: R = QpCR(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 + 1 ) 

sage: t.inverse_of_unit() 

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

  

Over Eisenstein extensions:: 

  

sage: R = ZpCA(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 - 3 ) 

sage: (t - 1).inverse_of_unit() 

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

  

sage: R = ZpCR(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 - 3 ) 

sage: (t - 1).inverse_of_unit() 

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

  

sage: R = ZpFM(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 - 3 ) 

sage: (t - 1).inverse_of_unit() 

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

  

sage: R = QpCR(3,5); S.<t> = R[]; W.<t> = R.extension( t^2 - 3 ) 

sage: (t - 1).inverse_of_unit() 

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

  

""" 

if not self.is_unit(): 

raise ZeroDivisionError("Inverse does not exist.") 

return self.parent()(~self) 

  

#def __getitem__(self, n): 

# raise NotImplementedError 

  

def __iter__(self): 

""" 

Local elements should not be iterable, so this method correspondingly 

raises a ``TypeError``. 

  

.. NOTE:: 

  

Typically, local elements provide a implementation for 

``__getitem__``. If they do not provide a method ``__iter__``, then 

iterating over them is realized by calling ``__getitem__``, 

starting from index 0. However, there are several issues with this. 

For example, terms with negative valuation would be excluded from 

the iteration, and an exact value of zero would lead to an infinite 

iterable. 

  

There doesn't seem to be an obvious behaviour that iteration over 

such elements should produce, so it is disabled; see :trac:`13592`. 

  

TESTS:: 

  

sage: x = Qp(3).zero() 

sage: for v in x: pass 

Traceback (most recent call last): 

... 

TypeError: this local element is not iterable 

  

""" 

raise TypeError("this local element is not iterable") 

  

def slice(self, i, j, k = 1, lift_mode='simple'): 

r""" 

Returns the sum of the `p^{i + l \cdot k}` terms of the series 

expansion of this element, for `i + l \cdot k` between ``i`` and 

``j-1`` inclusive, and nonnegative integers `l`. Behaves analogously to 

the slice function for lists. 

  

INPUT: 

  

- ``i`` -- an integer; if set to ``None``, the sum will start with the 

first non-zero term of the series. 

  

- ``j`` -- an integer; if set to ``None`` or `\infty`, this method 

behaves as if it was set to the absolute precision of this element. 

  

- ``k`` -- (default: 1) a positive integer 

  

EXAMPLES:: 

  

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

sage: a = R(1/2); a 

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

sage: a.slice(2, 4) 

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

sage: a.slice(1, 6, 2) 

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

  

The step size ``k`` has to be positive:: 

  

sage: a.slice(0, 3, 0) 

Traceback (most recent call last): 

... 

ValueError: slice step must be positive 

sage: a.slice(0, 3, -1) 

Traceback (most recent call last): 

... 

ValueError: slice step must be positive 

  

If ``i`` exceeds ``j``, then the result will be zero, with the 

precision given by ``j``:: 

  

sage: a.slice(5, 4) 

O(5^4) 

sage: a.slice(6, 5) 

O(5^5) 

  

However, the precision can not exceed the precision of the element:: 

  

sage: a.slice(101,100) 

O(5^6) 

sage: a.slice(0,5,2) 

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

sage: a.slice(0,6,2) 

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

sage: a.slice(0,7,2) 

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

  

If start is left blank, it is set to the valuation:: 

  

sage: K = Qp(5, 6) 

sage: x = K(1/25 + 5); x 

5^-2 + 5 + O(5^4) 

sage: x.slice(None, 3) 

5^-2 + 5 + O(5^3) 

sage: x[:3] 

doctest:warning 

... 

DeprecationWarning: __getitem__ is changing to match the behavior of number fields. Please use expansion instead. 

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

5^-2 + 5 + O(5^3) 

  

TESTS: 

  

Test that slices also work over fields:: 

  

sage: a = K(1/25); a 

5^-2 + O(5^4) 

sage: b = K(25); b 

5^2 + O(5^8) 

  

sage: a.slice(2, 4) 

O(5^4) 

sage: b.slice(2, 4) 

5^2 + O(5^4) 

sage: a.slice(-3, -1) 

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

sage: b.slice(-1, 1) 

O(5) 

sage: b.slice(-3, -1) 

O(5^-1) 

sage: b.slice(101, 100) 

O(5^8) 

sage: b.slice(0,7,2) 

5^2 + O(5^7) 

sage: b.slice(0,8,2) 

5^2 + O(5^8) 

sage: b.slice(0,9,2) 

5^2 + O(5^8) 

  

Verify that :trac:`14106` has been fixed:: 

  

sage: R = Zp(5,7) 

sage: a = R(300) 

sage: a 

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

sage: a[:5] 

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

sage: a.slice(None, 5, None) 

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

  

""" 

if i is None: 

i = self.valuation() 

if j is None or j is infinity: 

j = self.precision_absolute() 

if k is None: 

k = 1 

  

if k<=0: 

raise ValueError("slice step must be positive") 

  

start = i 

stop = j 

  

# for fields, self.list() contains only the coefficients starting from 

# self.valuation(), so we have to shift the indices around to make up 

# for this 

if self.parent().is_field(): 

start -= self.valuation() 

stop -= self.valuation() 

  

# make sure that start and stop are non-negative 

if start<0: 

i += -start # fix the value of ppow below 

start = 0 

stop = max(stop, 0) 

  

# the increase of the p-power in every step 

pk = self.parent().uniformizer_pow(k) 

# the p-power of the first term 

ppow = self.parent().uniformizer_pow(i) 

  

# construct the return value 

ans = self.parent().zero() 

for c in islice(self.expansion(lift_mode=lift_mode), start, stop, k): 

ans += ppow * c 

ppow *= pk 

  

# fix the precision of the return value 

if j < ans.precision_absolute() or self.precision_absolute() < ans.precision_absolute(): 

ans = ans.add_bigoh(min(j,self.precision_absolute())) 

  

return ans 

  

def _latex_(self): 

""" 

Returns a latex representation of self. 

  

EXAMPLES:: 

  

sage: R = Zp(5); a = R(17) 

sage: latex(a) #indirect doctest 

2 + 3 \cdot 5 + O(5^{20}) 

""" 

# TODO: add a bunch more documentation of latexing elements 

return self._repr_(do_latex = True) 

  

#def __mod__(self, right): 

# raise NotImplementedError 

  

#cpdef _mul_(self, right): 

# raise NotImplementedError 

  

#cdef _neg_(self): 

# raise NotImplementedError 

  

#def __pow__(self, right): 

# raise NotImplementedError 

  

cpdef _sub_(self, right): 

r""" 

Returns the difference between ``self`` and ``right``. 

  

EXAMPLES:: 

  

sage: R = Zp(7, 4, 'capped-rel', 'series'); a = R(12); b = R(5); a - b 

7 + O(7^4) 

sage: R(4/3) - R(1/3) #indirect doctest 

1 + O(7^4) 

""" 

# this doctest doesn't actually test this function, since _sub_ is overridden. 

return self + (-right) 

  

def add_bigoh(self, absprec): 

""" 

Return a copy of this element with ablsolute precision decreased to 

``absprec``. 

  

INPUT: 

  

- ``absprec`` -- an integer or positive infinity 

  

EXAMPLES:: 

  

sage: K = QpCR(3,4) 

sage: o = K(1); o 

1 + O(3^4) 

sage: o.add_bigoh(2) 

1 + O(3^2) 

sage: o.add_bigoh(-5) 

O(3^-5) 

  

One cannot use ``add_bigoh`` to lift to a higher precision; this 

can be accomplished with :meth:`lift_to_precision`:: 

  

sage: o.add_bigoh(5) 

1 + O(3^4) 

  

Negative values of ``absprec`` return an element in the fraction field 

of the element's parent:: 

  

sage: R = ZpCA(3,4) 

sage: R(3).add_bigoh(-5) 

O(3^-5) 

  

For fixed-mod elements this method truncates the element:: 

  

sage: R = ZpFM(3,4) 

sage: R(3).add_bigoh(1) 

O(3^4) 

  

If ``absprec`` exceeds the precision of the element, then this method 

has no effect:: 

  

sage: R(3).add_bigoh(5) 

3 + O(3^4) 

  

A negative value for ``absprec`` returns an element in the fraction field:: 

  

sage: R(3).add_bigoh(-1).parent() 

3-adic Field with floating precision 4 

  

TESTS: 

  

Test that this also works for infinity:: 

  

sage: R = ZpCR(3,4) 

sage: R(3).add_bigoh(infinity) 

3 + O(3^5) 

sage: R(0).add_bigoh(infinity) 

0 

  

""" 

parent = self.parent() 

if absprec >= self.precision_absolute(): 

return self 

if absprec < 0: 

parent = parent.fraction_field() 

return parent(self, absprec=absprec) 

  

#def copy(self): 

# raise NotImplementedError 

  

#def exp(self): 

# raise NotImplementedError 

  

def is_integral(self): 

""" 

Returns whether self is an integral element. 

  

INPUT: 

  

- ``self`` -- a local ring element 

  

OUTPUT: 

  

- boolean -- whether ``self`` is an integral element. 

  

EXAMPLES:: 

  

sage: R = Qp(3,20) 

sage: a = R(7/3); a.is_integral() 

False 

sage: b = R(7/5); b.is_integral() 

True 

""" 

return self.valuation() >= 0 

  

#def is_square(self): 

# raise NotImplementedError 

  

def is_padic_unit(self): 

""" 

Returns whether self is a `p`-adic unit. That is, whether it has zero valuation. 

  

INPUT: 

  

- ``self`` -- a local ring element 

  

OUTPUT: 

  

- boolean -- whether ``self`` is a unit 

  

EXAMPLES:: 

  

sage: R = Zp(3,20,'capped-rel'); K = Qp(3,20,'capped-rel') 

sage: R(0).is_padic_unit() 

False 

sage: R(1).is_padic_unit() 

True 

sage: R(2).is_padic_unit() 

True 

sage: R(3).is_padic_unit() 

False 

sage: Qp(5,5)(5).is_padic_unit() 

False 

  

TESTS:: 

  

sage: R(4).is_padic_unit() 

True 

sage: R(6).is_padic_unit() 

False 

sage: R(9).is_padic_unit() 

False 

sage: K(0).is_padic_unit() 

False 

sage: K(1).is_padic_unit() 

True 

sage: K(2).is_padic_unit() 

True 

sage: K(3).is_padic_unit() 

False 

sage: K(4).is_padic_unit() 

True 

sage: K(6).is_padic_unit() 

False 

sage: K(9).is_padic_unit() 

False 

sage: K(1/3).is_padic_unit() 

False 

sage: K(1/9).is_padic_unit() 

False 

sage: Qq(3^2,5,names='a')(3).is_padic_unit() 

False 

""" 

return self.valuation() == 0 

  

def is_unit(self): 

""" 

Returns whether self is a unit 

  

INPUT: 

  

- ``self`` -- a local ring element 

  

OUTPUT: 

  

- boolean -- whether ``self`` is a unit 

  

NOTES: 

  

For fields all nonzero elements are units. For DVR's, only those elements of valuation 0 are. An older implementation ignored the case of fields, and returned always the negation of self.valuation()==0. This behavior is now supported with self.is_padic_unit(). 

  

EXAMPLES:: 

  

sage: R = Zp(3,20,'capped-rel'); K = Qp(3,20,'capped-rel') 

sage: R(0).is_unit() 

False 

sage: R(1).is_unit() 

True 

sage: R(2).is_unit() 

True 

sage: R(3).is_unit() 

False 

sage: Qp(5,5)(5).is_unit() # Note that 5 is invertible in `QQ_5`, even if it has positive valuation! 

True 

sage: Qp(5,5)(5).is_padic_unit() 

False 

  

TESTS:: 

  

sage: R(4).is_unit() 

True 

sage: R(6).is_unit() 

False 

sage: R(9).is_unit() 

False 

sage: K(0).is_unit() 

False 

sage: K(1).is_unit() 

True 

sage: K(2).is_unit() 

True 

sage: K(3).is_unit() 

True 

sage: K(4).is_unit() 

True 

sage: K(6).is_unit() 

True 

sage: K(9).is_unit() 

True 

sage: K(1/3).is_unit() 

True 

sage: K(1/9).is_unit() 

True 

sage: Qq(3^2,5,names='a')(3).is_unit() 

True 

sage: R(0,0).is_unit() 

False 

sage: K(0,0).is_unit() 

False 

""" 

if self.is_zero(): 

return False 

if self.parent().is_field(): 

return True 

return self.valuation() == 0 

  

#def is_zero(self, prec): 

# raise NotImplementedError 

  

#def is_equal_to(self, right, prec): 

# raise NotImplementedError 

  

#def lift(self): 

# raise NotImplementedError 

  

#def list(self): 

# raise NotImplementedError 

  

#def log(self): 

# raise NotImplementedError 

  

#def multiplicative_order(self, prec): 

# raise NotImplementedError 

  

#def padded_list(self): 

# raise NotImplementedError 

  

#def precision_absolute(self): 

# raise NotImplementedError 

  

#def precision_relative(self): 

# raise NotImplementedError 

  

#def residue(self, prec): 

# raise NotImplementedError 

  

def sqrt(self, extend = True, all = False): 

r""" 

TODO: document what "extend" and "all" do 

  

INPUT: 

  

- ``self`` -- a local ring element 

  

OUTPUT: 

  

- local ring element -- the square root of ``self`` 

  

EXAMPLES:: 

  

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

sage: a = sqrt(R(-1)); a * a 

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

sage: sqrt(R(4)) 

2 + O(13^10) 

sage: sqrt(R(4/9)) * 3 

2 + O(13^10) 

""" 

return self.square_root(extend, all) 

  

#def square_root(self, extend = True, all = False): 

# raise NotImplementedError 

  

#def unit_part(self): 

# raise NotImplementedError 

  

#def valuation(self): 

# raise NotImplementedError 

  

def normalized_valuation(self): 

r""" 

Returns the normalized valuation of this local ring element, 

i.e., the valuation divided by the absolute ramification index. 

  

INPUT: 

  

``self`` -- a local ring element. 

  

OUTPUT: 

  

rational -- the normalized valuation of ``self``. 

  

EXAMPLES:: 

  

sage: Q7 = Qp(7) 

sage: R.<x> = Q7[] 

sage: F.<z> = Q7.ext(x^3+7*x+7) 

sage: z.normalized_valuation() 

1/3 

""" 

F = self.parent() 

return self.valuation()/F.ramification_index() 

  

def _min_valuation(self): 

r""" 

Returns the valuation of this local ring element. 

  

This function only differs from valuation for lazy elements. 

  

INPUT: 

  

- ``self`` -- a local ring element. 

  

OUTPUT: 

  

- integer -- the valuation of ``self``. 

  

EXAMPLES:: 

  

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

sage: R(7)._min_valuation() 

1 

sage: R(1/7)._min_valuation() 

-1 

""" 

return self.valuation() 

  

def euclidean_degree(self): 

r""" 

Return the degree of this element as an element of an Euclidean domain. 

  

EXAMPLES: 

  

For a field, this is always zero except for the zero element:: 

  

sage: K = Qp(2) 

sage: K.one().euclidean_degree() 

0 

sage: K.gen().euclidean_degree() 

0 

sage: K.zero().euclidean_degree() 

Traceback (most recent call last): 

... 

ValueError: euclidean degree not defined for the zero element 

  

For a ring which is not a field, this is the valuation of the element:: 

  

sage: R = Zp(2) 

sage: R.one().euclidean_degree() 

0 

sage: R.gen().euclidean_degree() 

1 

sage: R.zero().euclidean_degree() 

Traceback (most recent call last): 

... 

ValueError: euclidean degree not defined for the zero element 

""" 

if self.is_zero(): 

raise ValueError("euclidean degree not defined for the zero element") 

  

from sage.categories.fields import Fields 

if self.parent() in Fields(): 

from sage.rings.all import Integer 

return Integer(0) 

return self.valuation() 

  

@coerce_binop 

def quo_rem(self, other): 

r""" 

Return the quotient with remainder of the division of this element by 

``other``. 

  

INPUT: 

  

- ``other`` -- an element in the same ring 

  

EXAMPLES:: 

  

sage: R = Zp(3, 5) 

sage: R(12).quo_rem(R(2)) 

(2*3 + O(3^6), 0) 

sage: R(2).quo_rem(R(12)) 

(0, 2 + O(3^5)) 

  

sage: K = Qp(3, 5) 

sage: K(12).quo_rem(K(2)) 

(2*3 + O(3^6), 0) 

sage: K(2).quo_rem(K(12)) 

(2*3^-1 + 1 + 3 + 3^2 + 3^3 + O(3^4), 0) 

""" 

if other.is_zero(): 

raise ZeroDivisionError 

  

from sage.categories.fields import Fields 

if self.parent() in Fields(): 

return (self / other, self.parent().zero()) 

if self.valuation() < other.valuation(): 

return (self.parent().zero(), self) 

return ( (self>>other.valuation())*other.unit_part().inverse_of_unit(), 

self.parent().zero() ) 

  

def _test_trivial_powers(self, **options): 

r""" 

Check that taking trivial powers of elements works as expected. 

  

EXAMPLES:: 

  

sage: x = Zp(3, 5).zero() 

sage: x._test_trivial_powers() 

  

""" 

tester = self._tester(**options) 

  

x = self**1 

tester.assertEqual(x, self) 

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

  

z = self**0 

one = self.parent().one() 

tester.assertEqual(z, one) 

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

  

def _test_expansion(self, **options): 

r""" 

Check that ``expansion`` works as expected. 

  

EXAMPLES:: 

  

sage: x = Zp(3, 5).zero() 

sage: x._test_expansion() 

  

""" 

tester = self._tester(**options) 

  

shift = self.parent().one() 

v = 0 

# so that this test doesn't take too long for large precision cap 

prec_cutoff = min((10000 / (1 + self.precision_relative())).ceil(), 100) 

  

from sage.categories.all import Fields 

if self.parent() in Fields(): 

v = self.valuation() 

from sage.rings.all import infinity 

if self.valuation() is not infinity: 

shift = shift << v 

  

if self.parent().is_lattice_prec(): 

modes = ['simple'] 

else: 

modes = ['simple', 'smallest', 'teichmuller'] 

for mode in modes: 

expansion = self.expansion(lift_mode=mode) 

expansion_sum = sum(self.parent().maximal_unramified_subextension()(c) * 

(self.parent().one()<<i) 

for i,c in enumerate(islice(expansion, prec_cutoff))) * shift 

  

tester.assertEqual(self.add_bigoh(prec_cutoff), expansion_sum.add_bigoh(prec_cutoff)) 

  

for i,c in enumerate(islice(expansion, prec_cutoff)): 

tester.assertEqual(c, self.expansion(lift_mode=mode, n=i+v)) 

  

if mode == 'teichmuller': 

q = self.parent().residue_field().cardinality() 

for c in islice(expansion, prec_cutoff): 

tester.assertEqual(c, c**q)