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

r""" 

Function Field Elements 

  

AUTHORS: 

  

- William Stein: initial version 

  

- Robert Bradshaw (2010-05-27): cythonize function field elements 

  

- Julian Rueth (2011-06-28): treat zero correctly 

  

- Maarten Derickx (2011-09-11): added doctests, fixed pickling 

""" 

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

# Copyright (C) 2010 William Stein <wstein@gmail.com> 

# Copyright (C) 2010 Robert Bradshaw <robertwb@math.washington.edu> 

# Copyright (C) 2011 Julian Rueth <julian.rueth@gmail.com> 

# Copyright (C) 2011 Maarten Derickx <m.derickx.student@gmail.com> 

# 

# 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.structure.element cimport FieldElement, RingElement, ModuleElement, Element 

from sage.misc.cachefunc import cached_method 

from sage.structure.richcmp cimport richcmp, richcmp_not_equal 

  

  

def is_FunctionFieldElement(x): 

""" 

Return True if x is any type of function field element. 

  

EXAMPLES:: 

  

sage: t = FunctionField(QQ,'t').gen() 

sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(t) 

True 

sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(0) 

False 

""" 

if isinstance(x, FunctionFieldElement): return True 

from .function_field import is_FunctionField 

return is_FunctionField(x.parent()) 

  

def make_FunctionFieldElement(parent, element_class, representing_element): 

""" 

Used for unpickling FunctionFieldElement objects (and subclasses). 

  

EXAMPLES:: 

  

sage: from sage.rings.function_field.function_field_element import make_FunctionFieldElement 

sage: K.<x> = FunctionField(QQ) 

sage: make_FunctionFieldElement(K, K._element_class, (x+1)/x) 

(x + 1)/x 

""" 

return element_class(parent, representing_element, reduce=False) 

  

cdef class FunctionFieldElement(FieldElement): 

""" 

The abstract base class for function field elements. 

  

EXAMPLES:: 

  

sage: t = FunctionField(QQ,'t').gen() 

sage: isinstance(t, sage.rings.function_field.function_field_element.FunctionFieldElement) 

True 

""" 

  

cdef readonly object _x 

cdef readonly object _matrix 

  

def __reduce__(self): 

""" 

EXAMPLES:: 

  

sage: K = FunctionField(QQ,'x') 

sage: f = K.random_element() 

sage: loads(f.dumps()) == f 

True 

""" 

return (make_FunctionFieldElement, 

(self._parent, type(self), self._x)) 

  

cdef FunctionFieldElement _new_c(self): 

cdef type t = type(self) 

cdef FunctionFieldElement x = <FunctionFieldElement>t.__new__(t) 

x._parent = self._parent 

return x 

  

def __pari__(self): 

r""" 

Coerce this element to PARI. 

  

PARI does not know about general function field elements, so this 

raises an Exception. 

  

TESTS: 

  

Check that :trac:`16369` has been resolved:: 

  

sage: K.<a> = FunctionField(QQ) 

sage: R.<b> = K[] 

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

sage: b.__pari__() 

Traceback (most recent call last): 

... 

NotImplementedError: PARI does not support general function field elements. 

  

""" 

raise NotImplementedError("PARI does not support general function field elements.") 

  

def _latex_(self): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: latex((t+1)/t) 

\frac{t + 1}{t} 

sage: latex((t+1)/t^67) 

\frac{t + 1}{t^{67}} 

sage: latex((t+1/2)/t^67) 

\frac{t + \frac{1}{2}}{t^{67}} 

""" 

return self._x._latex_() 

  

@cached_method 

def matrix(self, base=None): 

r""" 

Return the matrix of multiplication by this element, interpreting this 

element as an element of a vector space over ``base``. 

  

INPUT: 

  

- ``base`` -- a function field (default: ``None``), if ``None``, then 

the matrix is formed over the base field of this function field. 

  

EXAMPLES: 

  

A rational function field:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: t.matrix() 

[t] 

sage: (1/(t+1)).matrix() 

[1/(t + 1)] 

  

Now an example in a nontrivial extension of a rational function field:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: y.matrix() 

[ 0 1] 

[-4*x^3 x] 

sage: y.matrix().charpoly('Z') 

Z^2 - x*Z + 4*x^3 

  

An example in a relative extension, where neither function 

field is rational:: 

  

sage: K.<x> = FunctionField(QQ) 

sage: R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: M.<T> = L[] 

sage: Z.<alpha> = L.extension(T^3 - y^2*T + x) 

sage: alpha.matrix() 

[ 0 1 0] 

[ 0 0 1] 

[ -x x*y - 4*x^3 0] 

sage: alpha.matrix(K) 

[ 0 0 1 0 0 0] 

[ 0 0 0 1 0 0] 

[ 0 0 0 0 1 0] 

[ 0 0 0 0 0 1] 

[ -x 0 -4*x^3 x 0 0] 

[ 0 -x -4*x^4 -4*x^3 + x^2 0 0] 

sage: alpha.matrix(Z) 

[alpha] 

  

We show that this matrix does indeed work as expected when making a 

vector space from a function field:: 

  

sage: K.<x> = FunctionField(QQ) 

sage: R.<y> = K[] 

sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x)) 

sage: V, from_V, to_V = L.vector_space() 

sage: y5 = to_V(y^5); y5 

((x^4 + 1)/x, 2*x, 0, 0, 0) 

sage: y4y = to_V(y^4) * y.matrix(); y4y 

((x^4 + 1)/x, 2*x, 0, 0, 0) 

sage: y5 == y4y 

True 

""" 

# multiply each element of the vector space isomorphic to the parent 

# with this element; make matrix whose rows are the coefficients of the 

# result, and transpose 

V, f, t = self.parent().vector_space(base) 

rows = [ t(self*f(b)) for b in V.basis() ] 

from sage.matrix.matrix_space import MatrixSpace 

MS = MatrixSpace(V.base_field(), V.dimension()) 

ret = MS(rows) 

ret.transpose() 

ret.set_immutable() 

return ret 

  

def trace(self): 

""" 

Return the trace of this function field element. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: y.trace() 

x 

""" 

return self.matrix().trace() 

  

def norm(self): 

""" 

Return the norm of this function field element. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: y.norm() 

4*x^3 

  

The norm is relative:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3); R.<z> = L[] 

sage: M.<z> = L.extension(z^3 - y^2*z + x) 

sage: z.norm() 

-x 

sage: z.norm().parent() 

Function field in y defined by y^2 - x*y + 4*x^3 

""" 

return self.matrix().determinant() 

  

def characteristic_polynomial(self, *args, **kwds): 

""" 

Return the characteristic polynomial of this function field 

element. Give an optional input string to name the variable 

in the characteristic polynomial. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3); R.<z> = L[] 

sage: M.<z> = L.extension(z^3 - y^2*z + x) 

sage: x.characteristic_polynomial('W') 

W - x 

sage: y.characteristic_polynomial('W') 

W^2 - x*W + 4*x^3 

sage: z.characteristic_polynomial('W') 

W^3 + (-x*y + 4*x^3)*W + x 

""" 

return self.matrix().characteristic_polynomial(*args, **kwds) 

  

charpoly = characteristic_polynomial 

  

def minimal_polynomial(self, *args, **kwds): 

""" 

Return the minimal polynomial of this function field element. 

Give an optional input string to name the variable in the 

characteristic polynomial. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3); R.<z> = L[] 

sage: M.<z> = L.extension(z^3 - y^2*z + x) 

sage: x.minimal_polynomial('W') 

W - x 

sage: y.minimal_polynomial('W') 

W^2 - x*W + 4*x^3 

sage: z.minimal_polynomial('W') 

W^3 + (-x*y + 4*x^3)*W + x 

""" 

return self.matrix().minimal_polynomial(*args, **kwds) 

  

minpoly = minimal_polynomial 

  

def is_integral(self): 

r""" 

Determine if self is integral over the maximal order of the base field. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: y.is_integral() 

True 

sage: (y/x).is_integral() 

True 

sage: (y/x)^2 - (y/x) + 4*x 

0 

sage: (y/x^2).is_integral() 

False 

sage: (y/x).minimal_polynomial('W') 

W^2 - W + 4*x 

""" 

R = self.parent().base_field().maximal_order() 

return all([a in R for a in self.minimal_polynomial()]) 

  

cdef class FunctionFieldElement_polymod(FunctionFieldElement): 

""" 

Elements of a finite extension of a function field. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: x*y + 1/x^3 

x*y + 1/x^3 

""" 

def __init__(self, parent, x, reduce=True): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: type(y) 

<type 'sage.rings.function_field.function_field_element.FunctionFieldElement_polymod'> 

""" 

FieldElement.__init__(self, parent) 

if reduce: 

self._x = x % self._parent.polynomial() 

else: 

self._x = x 

  

def element(self): 

""" 

Return the underlying polynomial that represents this element. 

  

EXAMPLES:: 

sage: K.<x> = FunctionField(QQ); R.<T> = K[] 

sage: L.<y> = K.extension(T^2 - x*T + 4*x^3) 

sage: f = y/x^2 + x/(x^2+1); f 

1/x^2*y + x/(x^2 + 1) 

sage: f.element() 

1/x^2*y + x/(x^2 + 1) 

sage: type(f.element()) 

<class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class'> 

""" 

return self._x 

  

def _repr_(self): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: y._repr_() 

'y' 

""" 

return self._x._repr(name=self.parent().variable_name()) 

  

def __nonzero__(self): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: bool(y) 

True 

sage: bool(L(0)) 

False 

sage: bool(L.coerce(L.polynomial())) 

False 

""" 

return not not self._x 

  

def __hash__(self): 

""" 

TESTS:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: len({hash(y^i+x^j) for i in [-2..2] for j in [-2..2]}) == 25 

True 

""" 

return hash(self._x) 

  

cpdef _richcmp_(self, other, int op): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: L(0) == 0 

True 

sage: y != L(2) 

True 

""" 

cdef FunctionFieldElement left = <FunctionFieldElement>self 

cdef FunctionFieldElement right = <FunctionFieldElement>other 

return richcmp(left._x, right._x, op) 

  

cpdef _add_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: (2*y + x/(1+x^3)) + (3*y + 5*x*y) # indirect doctest 

(5*x + 5)*y + x/(x^3 + 1) 

sage: (y^2 - x*y + 4*x^3)==0 # indirect doctest 

True 

sage: -y+y 

0 

""" 

cdef FunctionFieldElement res = self._new_c() 

res._x = self._x + (<FunctionFieldElement>right)._x 

return res 

  

cpdef _sub_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: (2*y + x/(1+x^3)) - (3*y + 5*x*y) # indirect doctest 

(-5*x - 1)*y + x/(x^3 + 1) 

sage: y-y 

0 

""" 

cdef FunctionFieldElement res = self._new_c() 

res._x = self._x - (<FunctionFieldElement>right)._x 

return res 

  

cpdef _mul_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: y * (3*y + 5*x*y) # indirect doctest 

(5*x^2 + 3*x)*y - 20*x^4 - 12*x^3 

""" 

cdef FunctionFieldElement res = self._new_c() 

res._x = (self._x * (<FunctionFieldElement>right)._x) % self._parent.polynomial() 

return res 

  

cpdef _div_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: (2*y + x/(1+x^3)) / (2*y + x/(1+x^3)) # indirect doctest 

1 

sage: 1 / (y^2 - x*y + 4*x^3) # indirect doctest 

Traceback (most recent call last): 

... 

ZeroDivisionError: Cannot invert 0 

""" 

return self * ~right 

  

def __invert__(self): 

""" 

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: a = ~(2*y + 1/x); a # indirect doctest 

(-x^2/(8*x^5 + x^2 + 1/2))*y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) 

sage: a*(2*y + 1/x) 

1 

""" 

if self.is_zero(): 

raise ZeroDivisionError("Cannot invert 0") 

P = self._parent 

return P(self._x.xgcd(P._polynomial)[1]) 

  

def list(self): 

""" 

Return a list of coefficients of self, i.e., if self is an element of 

a function field K[y]/(f(y)), then return the coefficients of the 

reduced presentation as a polynomial in K[y]. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ); R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x*y + 4*x^3) 

sage: a = ~(2*y + 1/x); a 

(-x^2/(8*x^5 + x^2 + 1/2))*y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) 

sage: a.list() 

[(2*x^3 + x)/(16*x^5 + 2*x^2 + 1), -x^2/(8*x^5 + x^2 + 1/2)] 

sage: (x*y).list() 

[0, x] 

""" 

return self._x.padded_list(self.parent().degree()) 

  

cdef class FunctionFieldElement_rational(FunctionFieldElement): 

""" 

Elements of a rational function field. 

  

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ); K 

Rational function field in t over Rational Field 

""" 

def __init__(self, parent, x, reduce=True): 

""" 

EXAMPLES:: 

  

sage: FunctionField(QQ,'t').gen()^3 

t^3 

""" 

FieldElement.__init__(self, parent) 

self._x = x 

  

def __pari__(self): 

r""" 

Coerce this element to PARI. 

  

EXAMPLES:: 

  

sage: K.<a> = FunctionField(QQ) 

sage: ((a+1)/(a-1)).__pari__() 

(a + 1)/(a - 1) 

  

""" 

return self.element().__pari__() 

  

def element(self): 

""" 

Return the underlying fraction field element that represents this element. 

  

EXAMPLES:: 

  

sage: K.<t> = FunctionField(GF(7)) 

sage: t.element() 

t 

sage: type(t.element()) 

<type 'sage.rings.fraction_field_FpT.FpTElement'> 

  

sage: K.<t> = FunctionField(GF(131101)) 

sage: t.element() 

t 

sage: type(t.element()) 

<class 'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'> 

""" 

return self._x 

  

def list(self): 

""" 

Return a list of coefficients of self, i.e., if self is an element of 

a function field K[y]/(f(y)), then return the coefficients of the 

reduced presentation as a polynomial in K[y]. 

Since self is a member of a rational function field, this simply returns 

the list `[self]` 

  

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: t.list() 

[t] 

""" 

return [self] 

  

def _repr_(self): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: t._repr_() 

't' 

""" 

return repr(self._x) 

  

def __nonzero__(self): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: bool(t) 

True 

sage: bool(K(0)) 

False 

sage: bool(K(1)) 

True 

""" 

return not not self._x 

  

def __hash__(self): 

""" 

TESTS: 

  

It would be nice if the following would produce a list of 

15 distinct hashes:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: len({hash(t^i+t^j) for i in [-2..2] for j in [i..2]}) 

10 

""" 

return hash(self._x) 

  

cpdef _richcmp_(self, other, int op): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: t > 0 

True 

sage: t < t^2 

True 

""" 

cdef FunctionFieldElement left 

cdef FunctionFieldElement right 

try: 

left = <FunctionFieldElement?>self 

right = <FunctionFieldElement?>other 

lp = left._parent 

rp = right._parent 

if lp != rp: 

return richcmp_not_equal(lp, rp, op) 

return richcmp(left._x, right._x, op) 

except TypeError: 

return NotImplemented 

  

cpdef _add_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: t + (3*t^3) # indirect doctest 

3*t^3 + t 

""" 

cdef FunctionFieldElement res = self._new_c() 

res._x = self._x + (<FunctionFieldElement>right)._x 

return res 

  

cpdef _sub_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: t - (3*t^3) # indirect doctest 

-3*t^3 + t 

""" 

cdef FunctionFieldElement res = self._new_c() 

res._x = self._x - (<FunctionFieldElement>right)._x 

return res 

  

cpdef _mul_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: (t+1) * (t^2-1) # indirect doctest 

t^3 + t^2 - t - 1 

""" 

cdef FunctionFieldElement res = self._new_c() 

res._x = self._x * (<FunctionFieldElement>right)._x 

return res 

  

cpdef _div_(self, right): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: (t+1) / (t^2 - 1) # indirect doctest 

1/(t - 1) 

""" 

cdef FunctionFieldElement res = self._new_c() 

res._parent = self._parent.fraction_field() 

res._x = self._x / (<FunctionFieldElement>right)._x 

return res 

  

def numerator(self): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: f = (t+1) / (t^2 - 1/3); f 

(t + 1)/(t^2 - 1/3) 

sage: f.numerator() 

t + 1 

""" 

return self._x.numerator() 

  

def denominator(self): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: f = (t+1) / (t^2 - 1/3); f 

(t + 1)/(t^2 - 1/3) 

sage: f.denominator() 

t^2 - 1/3 

""" 

return self._x.denominator() 

  

def valuation(self, v): 

""" 

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: f = (t-1)^2 * (t+1) / (t^2 - 1/3)^3 

sage: f.valuation(t-1) 

2 

sage: f.valuation(t) 

0 

sage: f.valuation(t^2 - 1/3) 

-3 

""" 

R = self._parent._ring 

return self._x.valuation(R(self._parent(v)._x)) 

  

def is_square(self): 

""" 

Returns whether self is a square. 

  

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: t.is_square() 

False 

sage: (t^2/4).is_square() 

True 

sage: f = 9 * (t+1)^6 / (t^2 - 2*t + 1); f.is_square() 

True 

  

sage: K.<t> = FunctionField(GF(5)) 

sage: (-t^2).is_square() 

True 

sage: (-t^2).sqrt() 

2*t 

""" 

return self._x.is_square() 

  

def sqrt(self, all=False): 

""" 

Returns the square root of self. 

  

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: f = t^2 - 2 + 1/t^2; f.sqrt() 

(t^2 - 1)/t 

sage: f = t^2; f.sqrt(all=True) 

[t, -t] 

  

TESTS:: 

  

sage: K(4/9).sqrt() 

2/3 

sage: K(0).sqrt(all=True) 

[0] 

""" 

if all: 

return [self._parent(r) for r in self._x.sqrt(all=True)] 

else: 

return self._parent(self._x.sqrt()) 

  

def factor(self): 

""" 

Factor this rational function. 

  

EXAMPLES:: 

  

sage: K.<t> = FunctionField(QQ) 

sage: f = (t+1) / (t^2 - 1/3) 

sage: f.factor() 

(t + 1) * (t^2 - 1/3)^-1 

sage: (7*f).factor() 

(7) * (t + 1) * (t^2 - 1/3)^-1 

sage: ((7*f).factor()).unit() 

7 

sage: (f^3).factor() 

(t + 1)^3 * (t^2 - 1/3)^-3 

""" 

P = self.parent() 

F = self._x.factor() 

from sage.structure.factorization import Factorization 

return Factorization([(P(a),e) for a,e in F], unit=F.unit()) 

  

def inverse_mod(self, I): 

r""" 

Return an inverse of self modulo the integral ideal `I`, if 

defined, i.e., if `I` and self together generate the unit 

ideal. 

  

EXAMPLES:: 

  

sage: K.<x> = FunctionField(QQ) 

sage: O = K.maximal_order(); I = O.ideal(x^2+1) 

sage: t = O(x+1).inverse_mod(I); t 

-1/2*x + 1/2 

sage: (t*(x+1) - 1) in I 

True 

""" 

assert len(I.gens()) == 1 

f = I.gens()[0]._x 

assert f.denominator() == 1 

assert self._x.denominator() == 1 

return self.parent()(self._x.numerator().inverse_mod(f.numerator()))