Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

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

""" 

Function Fields 

 

AUTHORS: 

 

- William Stein (2010): initial version 

 

- Robert Bradshaw (2010-05-30): added is_finite() 

 

- Julian Rüth (2011-06-08, 2011-09-14, 2014-06-23, 2014-06-24, 2016-11-13): 

fixed hom(), extension(); use @cached_method; added derivation(); added 

support for relative vector spaces; fixed conversion to base fields 

 

- Maarten Derickx (2011-09-11): added doctests 

 

- Syed Ahmad Lavasani (2011-12-16): added genus(), is_RationalFunctionField() 

 

- Simon King (2014-10-29): Use the same generator names for a function field 

extension and the underlying polynomial ring. 

 

EXAMPLES: 

 

We create an extension of a rational function fields, and do some 

simple arithmetic in it:: 

 

sage: K.<x> = FunctionField(GF(5^2,'a')); K 

Rational function field in x over Finite Field in a of size 5^2 

sage: R.<y> = K[] 

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

Function field in y defined by y^3 + 3*x*y + (4*x^4 + 4)/x 

sage: y^2 

y^2 

sage: y^3 

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

sage: a = 1/y; a 

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

sage: a * y 

1 

 

We next make an extension of the above function field, illustrating 

that arithmetic with a tower of 3 fields is fully supported:: 

 

sage: S.<t> = L[] 

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

sage: M 

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

sage: t^2 

x*y 

sage: 1/t 

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

sage: M.base_field() 

Function field in y defined by y^3 + 3*x*y + (4*x^4 + 4)/x 

sage: M.base_field().base_field() 

Rational function field in x over Finite Field in a of size 5^2 

 

It is also possible to construct function fields over an imperfect base field:: 

 

sage: N.<u> = FunctionField(K) 

 

and function fields as inseparable extensions:: 

 

sage: R.<v> = K[] 

sage: O.<v> = K.extension(v^5 - x) 

 

TESTS:: 

 

sage: TestSuite(K).run(max_runs=1024) # long time (5s) 

sage: TestSuite(L).run(max_runs=64) # long time (10s) 

sage: TestSuite(M).run(max_runs=32) # long time (30s) 

sage: TestSuite(N).run(max_runs=64, skip = '_test_derivation') # long time (8s) 

sage: TestSuite(O).run(max_runs=128, skip = '_test_derivation') # long time (8s) 

 

sage: TestSuite(R).run() 

sage: TestSuite(S).run() # long time (3s) 

""" 

from __future__ import absolute_import 

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

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

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

# Copyright (C) 2011-2017 Julian Rüth <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 sage.rings.ring import Field 

from .function_field_element import FunctionFieldElement, FunctionFieldElement_rational, FunctionFieldElement_polymod 

 

from sage.misc.cachefunc import cached_method 

 

#is needed for genus computation 

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 

from sage.interfaces.all import singular 

 

from sage.categories.function_fields import FunctionFields 

CAT = FunctionFields() 

 

def is_FunctionField(x): 

""" 

Return True if ``x`` is of function field type. 

 

EXAMPLES:: 

 

sage: from sage.rings.function_field.function_field import is_FunctionField 

sage: is_FunctionField(QQ) 

False 

sage: is_FunctionField(FunctionField(QQ,'t')) 

True 

""" 

if isinstance(x, FunctionField): return True 

return x in FunctionFields() 

 

class FunctionField(Field): 

""" 

The abstract base class for all function fields. 

 

EXAMPLES:: 

 

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

sage: isinstance(K, sage.rings.function_field.function_field.FunctionField) 

True 

""" 

def __init__(self, base_field, names, category = CAT): 

r""" 

TESTS:: 

 

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

sage: from sage.rings.function_field.function_field import FunctionField 

sage: isinstance(K, FunctionField) 

True 

 

""" 

Field.__init__(self, base_field, names=names, category=category) 

 

# allow conversion into the constant base field 

from sage.categories.homset import Hom 

from .maps import FunctionFieldConversionToConstantBaseField 

to_constant_base_field = FunctionFieldConversionToConstantBaseField(Hom(self, self.constant_base_field())) 

# the conversion map must not keep this field alive if that is the only reference to it 

to_constant_base_field._make_weak_references() 

self.constant_base_field().register_conversion(to_constant_base_field) 

 

def is_perfect(self): 

r""" 

Return whether this field is perfect, i.e., its characteristic is `p=0` 

or every element has a `p`-th root. 

 

EXAMPLES:: 

 

sage: FunctionField(QQ, 'x').is_perfect() 

True 

sage: FunctionField(GF(2), 'x').is_perfect() 

False 

 

""" 

return self.characteristic() == 0 

 

def some_elements(self): 

""" 

Return some elemnts in this function field. 

 

EXAMPLES:: 

 

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

sage: K.some_elements() 

[1, 

x, 

2*x, 

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

1/x^2, 

x/(x^2 - 1), 

x/(x^2 + 1), 

x/(2*x^2 + 2), 

0, 

1/x, 

...] 

 

:: 

 

sage: R.<y> = K[] 

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

sage: L.some_elements() 

[1, 

y, 

1/x*y, 

((1/4*x + 1/4)/(1/4*x^2 - 1/2*x + 1/4))*y - 1/2*x/(1/4*x^2 - 1/2*x + 1/4), 

-1/-x, 

(1/(x - 1))*y, 

(1/(x + 1))*y, 

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

0, 

...] 

 

""" 

elements = [] 

 

polynomials = [self(f) for f in self._ring.some_elements()] 

 

for numerator in polynomials: 

for denominator in polynomials: 

if denominator: 

some_element = numerator/denominator 

if some_element not in elements: 

elements.append(some_element) 

 

return elements 

 

def characteristic(self): 

""" 

Return the characteristic of this function field. 

 

EXAMPLES:: 

 

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

sage: K.characteristic() 

0 

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

sage: K.characteristic() 

7 

sage: R.<y> = K[] 

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

sage: L.characteristic() 

7 

""" 

return self.constant_base_field().characteristic() 

 

def is_finite(self): 

""" 

Return whether this function field is finite, which it is not. 

 

EXAMPLES:: 

 

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

sage: R.is_finite() 

False 

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

sage: R.is_finite() 

False 

""" 

return False 

 

def extension(self, f, names=None): 

""" 

Create an extension L = K[y]/(f(y)) of a function field, 

defined by a univariate polynomial in one variable over this 

function field K. 

 

INPUT: 

 

- ``f`` -- a univariate polynomial over self 

- ``names`` -- None or string or length-1 tuple 

 

OUTPUT: 

 

- a function field 

 

EXAMPLES:: 

 

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

sage: K.extension(y^5 - x^3 - 3*x + x*y) 

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

 

A nonintegral defining polynomial:: 

 

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

sage: K.extension(y^3 + (1/t)*y + t^3/(t+1)) 

Function field in y defined by y^3 + 1/t*y + t^3/(t + 1) 

 

The defining polynomial need not be monic or integral:: 

 

sage: K.extension(t*y^3 + (1/t)*y + t^3/(t+1)) 

Function field in y defined by t*y^3 + 1/t*y + t^3/(t + 1) 

""" 

from .constructor import FunctionField_polymod as FunctionField_polymod_Constructor 

return FunctionField_polymod_Constructor(f, names) 

 

def order_with_basis(self, basis, check=True): 

""" 

Return the order with given basis over the maximal order of 

the base field. 

 

INPUT: 

 

- ``basis`` -- a list of elements of self 

- ``check`` -- bool (default: True); if True, check that 

the basis is really linearly independent and that the 

module it spans is closed under multiplication, and 

contains the identity element. 

 

OUTPUT: 

 

- an order in this function field 

 

EXAMPLES:: 

 

sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<y> = K.extension(y^3 + x^3 + 4*x + 1) 

sage: O = L.order_with_basis([1, y, y^2]); O 

Order in Function field in y defined by y^3 + x^3 + 4*x + 1 

sage: O.basis() 

(1, y, y^2) 

 

Note that 1 does not need to be an element of the basis, as long it is in the module spanned by it:: 

 

sage: O = L.order_with_basis([1+y, y, y^2]); O 

Order in Function field in y defined by y^3 + x^3 + 4*x + 1 

sage: O.basis() 

(y + 1, y, y^2) 

 

The following error is raised when the module spanned by the basis is not closed under multiplication:: 

 

sage: O = L.order_with_basis([1, x^2 + x*y, (2/3)*y^2]); O 

Traceback (most recent call last): 

... 

ValueError: The module generated by basis [1, x*y + x^2, 2/3*y^2] must be closed under multiplication 

 

and this happens when the identity is not in the module spanned by the basis:: 

 

sage: O = L.order_with_basis([x, x^2 + x*y, (2/3)*y^2]) 

Traceback (most recent call last): 

... 

ValueError: The identity element must be in the module spanned by basis [x, x*y + x^2, 2/3*y^2] 

""" 

from .function_field_order import FunctionFieldOrder_basis 

return FunctionFieldOrder_basis([self(a) for a in basis], check=check) 

 

def order(self, x, check=True): 

""" 

Return the order in this function field generated over the 

maximal order by x or the elements of x if x is a list. 

 

INPUT: 

 

- ``x`` -- element of self, or a list of elements of self 

- ``check`` -- bool (default: True); if True, check that 

x really generates an order 

 

EXAMPLES:: 

 

sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<y> = K.extension(y^3 + x^3 + 4*x + 1) 

sage: O = L.order(y); O 

Order in Function field in y defined by y^3 + x^3 + 4*x + 1 

sage: O.basis() 

(1, y, y^2) 

 

sage: Z = K.order(x); Z 

Order in Rational function field in x over Rational Field 

sage: Z.basis() 

(1,) 

 

Orders with multiple generators, not yet supported:: 

 

sage: Z = K.order([x,x^2]); Z 

Traceback (most recent call last): 

... 

NotImplementedError 

""" 

if not isinstance(x, (list, tuple)): 

x = [x] 

if len(x) == 1: 

g = x[0] 

basis = [self(1)] 

for i in range(self.degree()-1): 

basis.append(basis[-1]*g) 

else: 

raise NotImplementedError 

return self.order_with_basis(basis, check=check) 

 

def _coerce_map_from_(self, source): 

""" 

Return True if there is a coerce map from R to self. 

 

EXAMPLES:: 

 

sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<y> = K.extension(y^3 + x^3 + 4*x + 1) 

sage: L.equation_order() 

Order in Function field in y defined by y^3 + x^3 + 4*x + 1 

sage: L._coerce_map_from_(L.equation_order()) 

Conversion map: 

From: Order in Function field in y defined by y^3 + x^3 + 4*x + 1 

To: Function field in y defined by y^3 + x^3 + 4*x + 1 

sage: L._coerce_map_from_(GF(7)) 

 

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

sage: L.<x> = FunctionField(GaussianIntegers().fraction_field()) 

sage: L.has_coerce_map_from(K) 

True 

 

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

sage: R.<y> = K[] 

sage: L.<y> = K.extension(y^3 + 1) 

sage: K.<x> = FunctionField(GaussianIntegers().fraction_field()) 

sage: R.<y> = K[] 

sage: M.<y> = K.extension(y^3 + 1) 

sage: M.has_coerce_map_from(L) # not tested (the constant field including into a function field is not yet known to be injective) 

True 

 

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

sage: R.<I> = K[] 

sage: L.<I> = K.extension(I^2 + 1) 

sage: M.<x> = FunctionField(GaussianIntegers().fraction_field()) 

sage: M.has_coerce_map_from(L) 

True 

""" 

from .function_field_order import FunctionFieldOrder 

if isinstance(source, FunctionFieldOrder): 

K = source.fraction_field() 

if K is self: 

return self._generic_coerce_map(source) 

source_to_K = K.coerce_map_from(source) 

K_to_self = self.coerce_map_from(K) 

if source_to_K and K_to_self: 

return K_to_self * source_to_K 

from sage.categories.function_fields import FunctionFields 

if source in FunctionFields(): 

if source.base_field() is source: 

if self.base_field() is self: 

# source and self are rational function fields 

if source.variable_name() == self.variable_name(): 

# ... in the same variable 

base_coercion = self.constant_field().coerce_map_from(source.constant_field()) 

if base_coercion is not None: 

return source.hom([self.gen()], base_morphism=base_coercion) 

else: 

# source is an extensions of rational function fields 

base_coercion = self.coerce_map_from(source.base_field()) 

if base_coercion is not None and base_coercion.is_injective(): 

# the base field of source coerces into the base field of self 

self_polynomial = source.polynomial().map_coefficients(base_coercion) 

# try to find a root of the defining polynomial in self 

if self_polynomial(self.gen()) == 0: 

# The defining polynomial of source has a root in self, 

# therefore there is a map. To be sure that it is 

# canonical, we require a root of the defining polynomial 

# of self to be a root of the defining polynomial of 

# source (and that the variables are named equally): 

if source.variable_name() == self.variable_name(): 

return source.hom([self.gen()], base_morphism=base_coercion) 

 

try: 

sourcegen_in_self = self(source.variable_name()) 

except TypeError: 

pass 

else: 

if self_polynomial(sourcegen_in_self) == 0: 

# The defining polynomial of source has a root in self, 

# therefore there is a map. To be sure that it is 

# canonical, we require the names of the roots to match 

return source.hom([sourcegen_in_self], base_morphism=base_coercion) 

 

def _test_derivation(self, **options): 

""" 

Test the correctness of the derivations of the function field. 

 

EXAMPLES:: 

 

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

sage: TestSuite(K).run() # indirect doctest 

""" 

tester = self._tester(**options) 

S = tester.some_elements() 

K = self.constant_base_field().some_elements() 

d = self.derivation() 

from itertools import product 

# Leibniz's law 

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

tester.assertTrue(d(x*y) == x*d(y) + d(x)*y) 

# Linearity 

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

tester.assertTrue(d(x+y) == d(x) + d(y)) 

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

tester.assertTrue(d(c*x) == c*d(x)) 

# Constants map to zero 

for c in tester.some_elements(K): 

tester.assertTrue(d(c) == 0) 

 

def _convert_map_from_(self, R): 

r""" 

Return a conversion from ``R`` to this function field if one exists. 

 

EXAMPLES:: 

 

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

sage: R.<y> = K[] 

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

sage: K(L(x)) # indirect doctest 

x 

 

""" 

if isinstance(R, FunctionField_polymod): 

base_conversion = self.convert_map_from(R.base_field()) 

if base_conversion is not None: 

from sage.categories.morphism import SetMorphism 

return base_conversion * SetMorphism(R.Hom(R.base_field()), R._to_base_field) 

 

def _intermediate_fields(self, base): 

r""" 

Return the fields which lie in between ``base`` and this field in the 

tower of function fields. 

 

INPUT: 

 

- ``base`` -- a function field, either this field or a field from which 

this field has been created as an extension 

 

OUTPUT: 

 

A list of fields. The first entry is ``base``, the last entry is this field. 

 

EXAMPLES:: 

 

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

sage: K._intermediate_fields(K) 

[Rational function field in x over Rational Field] 

 

sage: R.<y> = K[] 

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

sage: L._intermediate_fields(K) 

[Function field in y defined by y^2 - x, Rational function field in x over Rational Field] 

 

sage: R.<z> = L[] 

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

sage: M._intermediate_fields(L) 

[Function field in z defined by z^2 - y, Function field in y defined by y^2 - x] 

sage: M._intermediate_fields(K) 

[Function field in z defined by z^2 - y, Function field in y defined by y^2 - x, Rational function field in x over Rational Field] 

 

TESTS:: 

 

sage: K._intermediate_fields(M) 

Traceback (most recent call last): 

... 

ValueError: field has not been constructed as a finite extension of base 

sage: K._intermediate_fields(QQ) 

Traceback (most recent call last): 

... 

TypeError: base must be a function field 

 

""" 

if not is_FunctionField(base): 

raise TypeError("base must be a function field") 

 

ret = [self] 

while ret[-1] is not base: 

ret.append(ret[-1].base_field()) 

if ret[-1] is ret[-2]: 

raise ValueError("field has not been constructed as a finite extension of base") 

return ret 

 

def rational_function_field(self): 

r""" 

Return the rational function field from which this field has been 

created as an extension. 

 

EXAMPLES:: 

 

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

sage: K.rational_function_field() 

Rational function field in x over Rational Field 

 

sage: R.<y> = K[] 

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

sage: L.rational_function_field() 

Rational function field in x over Rational Field 

 

sage: R.<z> = L[] 

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

sage: M.rational_function_field() 

Rational function field in x over Rational Field 

""" 

return self if is_RationalFunctionField(self) else self.base_field().rational_function_field() 

 

def valuation(self, prime): 

r""" 

Return the discrete valuation on this function field defined by 

``prime``. 

 

INPUT: 

 

- ``prime`` -- a place of the function field, a valuation on a subring, 

or a valuation on another function field together with information 

for isomorphisms to and from that function field 

 

EXAMPLES: 

 

We create valuations that correspond to finite rational places of a 

function field:: 

 

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

sage: v = K.valuation(1); v 

(x - 1)-adic valuation 

sage: v(x) 

0 

sage: v(x - 1) 

1 

 

A place can also be specified with an irreducible polynomial:: 

 

sage: v = K.valuation(x - 1); v 

(x - 1)-adic valuation 

 

Similarly, for a finite non-rational place:: 

 

sage: v = K.valuation(x^2 + 1); v 

(x^2 + 1)-adic valuation 

sage: v(x^2 + 1) 

1 

sage: v(x) 

0 

 

Or for the infinite place:: 

 

sage: v = K.valuation(1/x); v 

Valuation at the infinite place 

sage: v(x) 

-1 

 

Instead of specifying a generator of a place, we can define a valuation on a 

rational function field by giving a discrete valuation on the underlying 

polynomial ring:: 

 

sage: R.<x> = QQ[] 

sage: w = valuations.GaussValuation(R, valuations.TrivialValuation(QQ)).augmentation(x - 1, 1) 

sage: v = K.valuation(w); v 

(x - 1)-adic valuation 

 

Note that this allows us to specify valuations which do not correspond to a 

place of the function field:: 

 

sage: w = valuations.GaussValuation(R, QQ.valuation(2)) 

sage: v = K.valuation(w); v 

2-adic valuation 

 

The same is possible for valuations with `v(1/x) > 0` by passing in an 

extra pair of parameters, an isomorphism between this function field and an 

isomorphic function field. That way you can, for example, indicate that the 

valuation is to be understood as a valuation on `K[1/x]`, i.e., after 

applying the substitution `x \mapsto 1/x` (here, the inverse map is also `x 

\mapsto 1/x`):: 

 

sage: w = valuations.GaussValuation(R, QQ.valuation(2)).augmentation(x, 1) 

sage: w = K.valuation(w) 

sage: v = K.valuation((w, K.hom([~K.gen()]), K.hom([~K.gen()]))); v 

Valuation on rational function field induced by [ Gauss valuation induced by 2-adic valuation, v(x) = 1 ] (in Rational function field in x over Rational Field after x |--> 1/x) 

 

Note that classical valuations at finite places or the infinite place are 

always normalized such that the uniformizing element has valuation 1:: 

 

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

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

sage: v = M.valuation(x^3 - t) 

sage: v(x^3 - t) 

1 

 

However, if such a valuation comes out of a base change of the ground 

field, this is not the case anymore. In the example below, the unique 

extension of ``v`` to ``L`` still has valuation 1 on `x^3 - t` but it has 

valuation ``1/3`` on its uniformizing element `x - w`:: 

 

sage: R.<w> = K[] 

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

sage: N.<x> = FunctionField(L) 

sage: w = v.extension(N) # missing factorization, :trac:`16572` 

Traceback (most recent call last): 

... 

NotImplementedError 

sage: w(x^3 - t) # not tested 

1 

sage: w(x - w) # not tested 

1/3 

 

There are several ways to create valuations on extensions of rational 

function fields:: 

 

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

sage: R.<y> = K[] 

sage: L.<y> = K.extension(y^2 - x); L 

Function field in y defined by y^2 - x 

 

A place that has a unique extension can just be defined downstairs:: 

 

sage: v = L.valuation(x); v 

(x)-adic valuation 

 

""" 

from sage.rings.function_field.function_field_valuation import FunctionFieldValuation 

return FunctionFieldValuation(self, prime) 

 

 

class FunctionField_polymod(FunctionField): 

""" 

A function field defined by a univariate polynomial, as an 

extension of the base field. 

 

EXAMPLES: 

 

We make a function field defined by a degree 5 polynomial over the 

rational function field over the rational numbers:: 

 

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

sage: R.<y> = K[] 

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

Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

 

We next make a function field over the above nontrivial function 

field L:: 

 

sage: S.<z> = L[] 

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

Function field in z defined by z^2 + y*z + y 

sage: 1/z 

((x/(-x^4 - 1))*y^4 - 2*x^2/(-x^4 - 1))*z - 1 

sage: z * (1/z) 

1 

 

We drill down the tower of function fields:: 

 

sage: M.base_field() 

Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

sage: M.base_field().base_field() 

Rational function field in x over Rational Field 

sage: M.base_field().base_field().constant_field() 

Rational Field 

sage: M.constant_base_field() 

Rational Field 

 

.. WARNING:: 

 

It is not checked if the polynomial used to define this function field is irreducible 

Hence it is not guaranteed that this object really is a field! 

This is illustrated below. 

 

:: 

 

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

sage: R.<y> = K[] 

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

sage: (y-x)*(y+x) 

0 

sage: 1/(y-x) 

1 

sage: y-x==0; y+x==0 

False 

False 

""" 

def __init__(self, polynomial, names, 

element_class = FunctionFieldElement_polymod, 

category=CAT): 

""" 

Create a function field defined as an extension of another 

function field by adjoining a root of a univariate polynomial. 

 

INPUT: 

 

- ``polynomial`` -- a univariate polynomial over a function field 

- ``names`` -- variable names (as a tuple of length 1 or string) 

- ``category`` -- a category (defaults to category of function fields) 

 

EXAMPLES: 

 

We create an extension of a function field:: 

 

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

sage: L = K.extension(y^5 - x^3 - 3*x + x*y); L 

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

 

Note the type:: 

 

sage: type(L) 

<class 'sage.rings.function_field.function_field.FunctionField_polymod_with_category'> 

 

We can set the variable name, which doesn't have to be y:: 

 

sage: L.<w> = K.extension(y^5 - x^3 - 3*x + x*y); L 

Function field in w defined by w^5 + x*w - x^3 - 3*x 

 

TESTS: 

 

Test that :trac:`17033` is fixed:: 

 

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

sage: R.<x> = QQ[] 

sage: M.<z> = K.extension(x^7-x-t) 

sage: M(x) 

z 

sage: M('z') 

z 

sage: M('x') 

Traceback (most recent call last): 

... 

TypeError: unable to evaluate 'x' in Fraction Field of Univariate Polynomial Ring in t over Rational Field 

""" 

from sage.rings.polynomial.polynomial_element import is_Polynomial 

if polynomial.parent().ngens()>1 or not is_Polynomial(polynomial): 

raise TypeError("polynomial must be univariate a polynomial") 

if names is None: 

names = (polynomial.variable_name(), ) 

elif names != polynomial.variable_name(): 

polynomial = polynomial.change_variable_name(names) 

if polynomial.degree() <= 0: 

raise ValueError("polynomial must have positive degree") 

base_field = polynomial.base_ring() 

if not isinstance(base_field, FunctionField): 

raise TypeError("polynomial must be over a FunctionField") 

self._element_class = element_class 

self._base_field = base_field 

self._polynomial = polynomial 

 

FunctionField.__init__(self, base_field, names=names, category = category) 

 

self._hash = hash(polynomial) 

self._ring = self._polynomial.parent() 

self._populate_coercion_lists_(coerce_list=[base_field, self._ring]) 

self._gen = self(self._ring.gen()) 

 

def __reduce__(self): 

""" 

Returns the arguments which were used to create this instance. The rationale for this is explained in the documentation of ``UniqueRepresentation``. 

 

EXAMPLES:: 

 

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

sage: L = K.extension(y^2 - x) 

sage: clazz,args = L.__reduce__() 

sage: clazz(*args) 

Function field in y defined by y^2 - x 

""" 

from .constructor import FunctionField_polymod as FunctionField_polymod_Constructor 

return FunctionField_polymod_Constructor, (self._polynomial, self._names) 

 

def __hash__(self): 

""" 

Return hash of this function field. 

 

The hash value is equal to the hash of the defining polynomial. 

 

EXAMPLES:: 

 

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

sage: L = K.extension(y^5 - x^3 - 3*x + x*y) 

sage: hash(L) == hash(L.polynomial()) 

True 

 

""" 

return self._hash 

 

def _to_base_field(self, f): 

r""" 

Return ``f`` as an element of the :meth:`base_field`. 

 

INPUT: 

 

- ``f`` -- an element of this function field which lies in the base 

field. 

 

EXAMPLES:: 

 

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

sage: R.<y> = K[] 

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

sage: L._to_base_field(L(x)) 

x 

sage: L._to_base_field(y) 

Traceback (most recent call last): 

... 

ValueError: y is not an element of the base field 

 

TESTS: 

 

Verify that :trac:`21872` has been resolved:: 

 

sage: R.<z> = L[] 

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

 

sage: M(1) in QQ 

True 

sage: M(y) in L 

True 

sage: M(x) in K 

True 

sage: z in K 

False 

 

""" 

K = self.base_field() 

if f.element().is_constant(): 

return K(f.element()) 

raise ValueError("%r is not an element of the base field"%(f,)) 

 

def _to_constant_base_field(self, f): 

r""" 

Return ``f`` as an element of the :meth:`constant_base_field`. 

 

INPUT: 

 

- ``f`` -- an element of this rational function field which is a 

constant 

 

EXAMPLES:: 

 

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

sage: R.<y> = K[] 

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

sage: L._to_constant_base_field(L(1)) 

1 

sage: L._to_constant_base_field(y) 

Traceback (most recent call last): 

... 

ValueError: y is not an element of the base field 

 

TESTS: 

 

Verify that :trac:`21872` has been resolved:: 

 

sage: L(1) in QQ 

True 

sage: y in QQ 

False 

 

""" 

return self.base_field()._to_constant_base_field(self._to_base_field(f)) 

 

def monic_integral_model(self, names=None): 

""" 

Return a function field isomorphic to this field but which is an 

extension of a rational function field with defining polynomial that is 

monic and integral over the constant base field. 

 

INPUT: 

 

- ``names`` -- a string or a tuple of up to two strings (default: 

``None``), the name of the generator of the field, and the name of 

the generator of the underlying rational function field (if a tuple); 

if not given, then the names are chosen automatically. 

 

OUTPUT: 

 

A triple ``(F,f,t)`` where ``F`` is a function field, ``f`` is an 

isomorphism from ``F`` to this field, and ``t`` is the inverse of 

``f``. 

 

EXAMPLES:: 

 

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

sage: R.<y> = K[] 

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

Function field in y defined by x^2*y^5 - 1/x 

sage: A, from_A, to_A = L.monic_integral_model('z') 

sage: A 

Function field in z defined by z^5 - x^12 

sage: from_A 

Function Field morphism: 

From: Function field in z defined by z^5 - x^12 

To: Function field in y defined by x^2*y^5 - 1/x 

Defn: z |--> x^3*y 

x |--> x 

sage: to_A 

Function Field morphism: 

From: Function field in y defined by x^2*y^5 - 1/x 

To: Function field in z defined by z^5 - x^12 

Defn: y |--> 1/x^3*z 

x |--> x 

sage: to_A(y) 

1/x^3*z 

sage: from_A(to_A(y)) 

y 

sage: from_A(to_A(1/y)) 

x^3*y^4 

sage: from_A(to_A(1/y)) == 1/y 

True 

 

This also works for towers of function fields:: 

 

sage: R.<z> = L[] 

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

sage: M.monic_integral_model() 

(Function field in z_ defined by z_^10 - x^18, Function Field morphism: 

From: Function field in z_ defined by z_^10 - x^18 

To: Function field in z defined by y*z^2 - 1/x 

Defn: z_ |--> x^2*z 

x |--> x, Function Field morphism: 

From: Function field in z defined by y*z^2 - 1/x 

To: Function field in z_ defined by z_^10 - x^18 

Defn: z |--> 1/x^2*z_ 

y |--> 1/x^15*z_^8 

x |--> x) 

 

TESTS: 

 

If the field is already a monic integral extension, then it is returned 

unchanged:: 

 

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

sage: R.<y> = K[] 

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

sage: L.monic_integral_model() 

(Function field in y defined by y^2 - x, Function Field endomorphism of Function field in y defined by y^2 - x 

Defn: y |--> y 

x |--> x, Function Field endomorphism of Function field in y defined by y^2 - x 

Defn: y |--> y 

x |--> x) 

 

unless ``names`` does not match with the current names:: 

 

sage: L.monic_integral_model(names=('yy','xx')) 

(Function field in yy defined by yy^2 - xx, Function Field morphism: 

From: Function field in yy defined by yy^2 - xx 

To: Function field in y defined by y^2 - x 

Defn: yy |--> y 

xx |--> x, Function Field morphism: 

From: Function field in y defined by y^2 - x 

To: Function field in yy defined by yy^2 - xx 

Defn: y |--> yy 

x |--> xx) 

 

""" 

if names: 

if not isinstance(names, tuple): 

names = (names,) 

if len(names) > 2: 

raise ValueErorr("names must contain at most 2 entries") 

 

if self.base_field() is not self.rational_function_field(): 

L,from_L,to_L = self.simple_model() 

ret,ret_to_L,L_to_ret = L.monic_integral_model(names) 

from_ret = ret.hom( [from_L(ret_to_L(ret.gen())), from_L(ret_to_L(ret.base_field().gen()))] ) 

to_ret = self.hom( [L_to_ret(to_L(k.gen())) for k in self._intermediate_fields(self.rational_function_field())] ) 

return ret, from_ret, to_ret 

else: 

if self.polynomial().is_monic() and all([c.denominator().is_one() for c in self.polynomial()]): 

# self is already monic and integral 

if names is None or names == (): 

names = (self.variable_name(),) 

return self.change_variable_name(names) 

else: 

if not names: 

names = (self.variable_name()+"_",) 

if len(names) == 1: 

names = (names[0], self.rational_function_field().variable_name()) 

 

g, d = self._make_monic_integral(self.polynomial()) 

K,from_K,to_K = self.base_field().change_variable_name(names[1]) 

g = g.map_coefficients(to_K) 

ret = K.extension(g, names=names[0]) 

from_ret = ret.hom([self.gen() * d, self.base_field().gen()]) 

to_ret = self.hom([ret.gen() / d, ret.base_field().gen()]) 

return ret, from_ret, to_ret 

 

def _make_monic_integral(self, f): 

r""" 

Let y be a root of ``f``. This function returns a monic 

integral polynomial g and an element d of the base field such 

that g(y*d)=0. 

 

EXAMPLES:: 

 

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

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

sage: g, d = L._make_monic_integral(L.polynomial()); g,d 

(y^5 - x^12, x^3) 

sage: (y*d).is_integral() 

True 

sage: g.is_monic() 

True 

sage: g(y*d) 

0 

""" 

R = f.base_ring() 

if not isinstance(R, RationalFunctionField): 

raise NotImplementedError 

 

# make f monic 

n = f.degree() 

c = f.leading_coefficient() 

if c != 1: 

f = f / c 

 

# find lcm of denominators 

from sage.arith.all import lcm 

# would be good to replace this by minimal... 

d = lcm([b.denominator() for b in f.list() if b]) 

if d != 1: 

x = f.parent().gen() 

g = (d**n) * f(x/d) 

else: 

g = f 

return g, d 

 

def constant_field(self): 

""" 

Return the algebraic closure of the constant field of the base 

field in this function field. 

 

EXAMPLES:: 

 

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

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

sage: L.constant_field() 

Traceback (most recent call last): 

... 

NotImplementedError 

""" 

raise NotImplementedError 

 

def constant_base_field(self): 

""" 

Return the constant field of the base rational function field. 

 

EXAMPLES:: 

 

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

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

Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

sage: L.constant_base_field() 

Rational Field 

sage: S.<z> = L[] 

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

sage: M.constant_base_field() 

Rational Field 

""" 

return self.base_field().constant_base_field() 

 

@cached_method(key=lambda self, base: self.base_field() if base is None else base) 

def degree(self, base=None): 

""" 

Return the degree of this function field over the function field 

``base``. 

 

INPUT: 

 

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

function field from which this field has been constructed as a finite 

extension. 

 

EXAMPLES:: 

 

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

sage: R.<y> = K[] 

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

Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

sage: L.degree() 

5 

sage: L.degree(L) 

1 

 

sage: R.<z> = L[] 

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

sage: M.degree(L) 

2 

sage: M.degree(K) 

10 

 

TESTS:: 

 

sage: L.degree(M) 

Traceback (most recent call last): 

... 

ValueError: base must be None or the rational function field 

 

""" 

if base is None: 

base = self.base_field() 

if base is self: 

from sage.rings.integer_ring import ZZ 

return ZZ(1) 

return self._polynomial.degree() * self.base_field().degree(base) 

 

def _repr_(self): 

""" 

Return string representation of this function field. 

 

EXAMPLES:: 

 

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

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

sage: L._repr_() 

'Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x' 

""" 

return "Function field in %s defined by %s"%(self.variable_name(), self._polynomial) 

 

def base_field(self): 

""" 

Return the base field of this function field. This function 

field is presented as L = K[y]/(f(y)), and the base field is 

by definition the field K. 

 

EXAMPLES:: 

 

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

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

sage: L.base_field() 

Rational function field in x over Rational Field 

""" 

return self._base_field 

 

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

""" 

Create a random element of this function field. Parameters 

are passed onto the random_element method of the base_field. 

 

EXAMPLES:: 

 

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

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

sage: L.random_element() # random 

((x^2 - x + 2/3)/(x^2 + 1/3*x - 1))*y^2 + ((-1/4*x^2 + 1/2*x - 1)/(-5/2*x + 2/3))*y + (-1/2*x^2 - 4)/(-12*x^2 + 1/2*x - 1/95) 

""" 

return self(self._ring.random_element(degree=self.degree(), *args, **kwds)) 

 

def polynomial(self): 

""" 

Return the univariate polynomial that defines this function 

field, i.e., the polynomial f(y) so that this function field 

is of the form K[y]/(f(y)). 

 

EXAMPLES:: 

 

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

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

sage: L.polynomial() 

y^5 - 2*x*y + (-x^4 - 1)/x 

""" 

return self._polynomial 

 

def is_separable(self): 

r""" 

Return whether the defining polynomial of the function field is 

separable, i.e., whether the gcd of the defining polynomial and its 

derivative is constant. 

 

EXAMPLES:: 

 

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

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

sage: L.is_separable() 

True 

 

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

sage: L.<y> = K.extension(y^5 - 1) 

sage: L.is_separable() 

False 

 

""" 

f = self.polynomial() 

g = self.polynomial().derivative() 

return f.gcd(g).degree() == 0 

 

def polynomial_ring(self): 

""" 

Return the polynomial ring used to represent elements of this 

function field. If we view this function field as being presented 

as K[y]/(f(y)), then this function returns the ring K[y]. 

 

EXAMPLES:: 

 

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

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

sage: L.polynomial_ring() 

Univariate Polynomial Ring in y over Rational function field in x over Rational Field 

""" 

return self._ring 

 

@cached_method(key=lambda self, base: self.base_field() if base is None else base) 

def vector_space(self, base=None): 

""" 

Return a vector space `V` and isomorphisms from this field to `V` and 

from `V` to this field. 

 

This function allows us to identify the elements of this field with 

elements of a vector space over the base field, which is useful for 

representation and arithmetic with orders, ideals, etc. 

 

INPUT: 

 

- ``base`` -- a function field (default: ``None``), the returned vector 

space is over ``base`` which defaults to the base field of this 

function field. 

 

OUTPUT: 

 

- ``V`` -- a vector space over base field 

- ``from_V`` -- an isomorphism from V to this field 

- ``to_V`` -- an isomorphism from this field to V 

 

EXAMPLES: 

 

We define a function field:: 

 

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

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

Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

 

We get the vector spaces, and maps back and forth:: 

 

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

sage: V 

Vector space of dimension 5 over Rational function field in x over Rational Field 

sage: from_V 

Isomorphism morphism: 

From: Vector space of dimension 5 over Rational function field in x over Rational Field 

To: Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

sage: to_V 

Isomorphism morphism: 

From: Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

To: Vector space of dimension 5 over Rational function field in x over Rational Field 

 

We convert an element of the vector space back to the function field:: 

 

sage: from_V(V.1) 

y 

 

We define an interesting element of the function field:: 

 

sage: a = 1/L.0; a 

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

 

We convert it to the vector space, and get a vector over the base field:: 

 

sage: to_V(a) 

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

 

We convert to and back, and get the same element:: 

 

sage: from_V(to_V(a)) == a 

True 

 

In the other direction:: 

 

sage: v = x*V.0 + (1/x)*V.1 

sage: to_V(from_V(v)) == v 

True 

 

And we show how it works over an extension of an extension field:: 

 

sage: R2.<z> = L[]; M.<z> = L.extension(z^2 -y) 

sage: M.vector_space() 

(Vector space of dimension 2 over Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x, Isomorphism morphism: 

From: Vector space of dimension 2 over Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x 

To: Function field in z defined by z^2 - y, Isomorphism morphism: 

From: Function field in z defined by z^2 - y 

To: Vector space of dimension 2 over Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x) 

 

We can also get the vector space of ``M`` over ``K``:: 

 

sage: M.vector_space(K) 

(Vector space of dimension 10 over Rational function field in x over Rational Field, Isomorphism morphism: 

From: Vector space of dimension 10 over Rational function field in x over Rational Field 

To: Function field in z defined by z^2 - y, Isomorphism morphism: 

From: Function field in z defined by z^2 - y 

To: Vector space of dimension 10 over Rational function field in x over Rational Field) 

 

""" 

from .maps import MapVectorSpaceToFunctionField, MapFunctionFieldToVectorSpace 

if base is None: 

base = self.base_field() 

degree = self.degree(base) 

V = base**degree; 

from_V = MapVectorSpaceToFunctionField(V, self) 

to_V = MapFunctionFieldToVectorSpace(self, V) 

return (V, from_V, to_V) 

 

def maximal_order(self): 

""" 

Return the maximal_order of self. If we view self as L = 

K[y]/(f(y)), then this is the ring of elements of L that are 

integral over K. 

 

EXAMPLES: 

 

This is not yet implemented...:: 

 

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

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

sage: L.maximal_order() 

Traceback (most recent call last): 

... 

NotImplementedError 

""" 

raise NotImplementedError 

 

def _element_constructor_(self, x): 

r""" 

Make ``x`` into an element of this function field, possibly not canonically. 

 

INPUT: 

 

- ``x`` -- the element 

 

OUTPUT: 

 

``x``, as an element of this function field 

 

TESTS:: 

 

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

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

sage: L._element_constructor_(L.polynomial_ring().gen()) 

y 

""" 

if isinstance(x, FunctionFieldElement): 

return FunctionFieldElement_polymod(self, self._ring(x.element())) 

return FunctionFieldElement_polymod(self, self._ring(x)) 

 

def gen(self, n=0): 

""" 

Return the ``n``-th generator of this function field. By default ``n`` is 0; any other 

value of ``n`` leads to an error. The generator is the class of y, if we view 

self as being presented as K[y]/(f(y)). 

 

EXAMPLES:: 

 

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

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

sage: L.gen() 

y 

sage: L.gen(1) 

Traceback (most recent call last): 

... 

IndexError: Only one generator. 

""" 

if n != 0: raise IndexError("Only one generator.") 

return self._gen 

 

def ngens(self): 

""" 

Return the number of generators of this function field over 

its base field. This is by definition 1. 

 

EXAMPLES:: 

 

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

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

sage: L.ngens() 

1 

""" 

return 1 

 

def equation_order(self): 

""" 

If we view self as being presented as K[y]/(f(y)), then this 

function returns the order generated by the class of y. If f 

is not monic, then :meth:`_make_monic_integral` is called, and instead we 

get the order generated by some integral multiple of a root of f. 

 

EXAMPLES:: 

 

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

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

sage: O = L.equation_order() 

sage: O.basis() 

(1, x*y, x^2*y^2, x^3*y^3, x^4*y^4) 

 

We try an example, in which the defining polynomial is not 

monic and is not integral:: 

 

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

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

Function field in y defined by x^2*y^5 - 1/x 

sage: O = L.equation_order() 

sage: O.basis() 

(1, x^3*y, x^6*y^2, x^9*y^3, x^12*y^4) 

""" 

d = self._make_monic_integral(self.polynomial())[1] 

return self.order(d*self.gen(), check=False) 

 

def hom(self, im_gens, base_morphism=None): 

""" 

Create a homomorphism from self to another function field. 

 

INPUT: 

 

- ``im_gens`` -- a list of images of the generators of self 

and of successive base rings. 

 

- ``base_morphism`` -- (default: None) a homomorphism of 

the base ring, after the im_gens are used. Thus if 

im_gens has length 2, then base_morphism should be a morphism 

from self.base_ring().base_ring(). 

 

EXAMPLES: 

 

We create a rational function field, and a quadratic extension of it:: 

 

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

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

 

We make the field automorphism that sends y to -y:: 

 

sage: f = L.hom(-y); f 

Function Field endomorphism of Function field in y defined by y^2 - x^3 - 1 

Defn: y |--> -y 

 

Evaluation works:: 

 

sage: f(y*x - 1/x) 

-x*y - 1/x 

 

We try to define an invalid morphism:: 

 

sage: f = L.hom(y+1) 

Traceback (most recent call last): 

... 

ValueError: invalid morphism 

 

We make a morphism of the base rational function field:: 

 

sage: phi = K.hom(x+1); phi 

Function Field endomorphism of Rational function field in x over Rational Field 

Defn: x |--> x + 1 

sage: phi(x^3 - 3) 

x^3 + 3*x^2 + 3*x - 2 

sage: (x+1)^3-3 

x^3 + 3*x^2 + 3*x - 2 

 

We make a morphism by specifying where the generators and the 

base generators go:: 

 

sage: L.hom([-y, x]) 

Function Field endomorphism of Function field in y defined by y^2 - x^3 - 1 

Defn: y |--> -y 

x |--> x 

 

You can also specify a morphism on the base:: 

 

sage: R1.<r> = K[] 

sage: L1.<r> = K.extension(r^2 - (x+1)^3 - 1) 

sage: L.hom(r, base_morphism=phi) 

Function Field morphism: 

From: Function field in y defined by y^2 - x^3 - 1 

To: Function field in r defined by r^2 - x^3 - 3*x^2 - 3*x - 2 

Defn: y |--> r 

x |--> x + 1 

 

We make another extension of a rational function field:: 

 

sage: K2.<t> = FunctionField(QQ); R2.<w> = K2[] 

sage: L2.<w> = K2.extension((4*w)^2 - (t+1)^3 - 1) 

 

We define a morphism, by giving the images of generators:: 

 

sage: f = L.hom([4*w, t+1]); f 

Function Field morphism: 

From: Function field in y defined by y^2 - x^3 - 1 

To: Function field in w defined by 16*w^2 - t^3 - 3*t^2 - 3*t - 2 

Defn: y |--> 4*w 

x |--> t + 1 

 

Evaluation works, as expected:: 

 

sage: f(y+x) 

4*w + t + 1 

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

(4*t + 4)*w + (t + 1)/(t^2 + 2*t + 2) 

 

We make another extension of a rational function field:: 

 

sage: K3.<yy> = FunctionField(QQ); R3.<xx> = K3[] 

sage: L3.<xx> = K3.extension(yy^2 - xx^3 - 1) 

 

This is the function field L with the generators exchanged. We define a morphism to L:: 

 

sage: g = L3.hom([x,y]); g 

Function Field morphism: 

From: Function field in xx defined by -xx^3 + yy^2 - 1 

To: Function field in y defined by y^2 - x^3 - 1 

Defn: xx |--> x 

yy |--> y 

 

""" 

if not isinstance(im_gens, (list,tuple)): 

im_gens = [im_gens] 

if len(im_gens) == 0: 

raise ValueError("no images specified") 

 

if len(im_gens) > 1: 

base_morphism = self.base_field().hom(im_gens[1:], base_morphism) 

 

# the codomain of this morphism is the field containing all the im_gens 

codomain = im_gens[0].parent(); 

if base_morphism is not None: 

from sage.categories.pushout import pushout 

codomain = pushout(codomain, base_morphism.codomain()) 

 

from .maps import FunctionFieldMorphism_polymod 

return FunctionFieldMorphism_polymod(self.Hom(codomain), im_gens[0], base_morphism) 

 

@cached_method 

def genus(self): 

""" 

Return the genus of this function field 

For now, the genus is computed using singular 

 

EXAMPLES:: 

 

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

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

sage: L.genus() 

3 

""" 

# unfortunately singular can not compute the genus with the 

# polynomial_ring()._singular_ object because genus method 

# only accepts a ring of transcendental degree 2 over a prime 

# field not a ring of transcendental degree 1 over a rational 

# function field of one variable 

 

if is_RationalFunctionField(self._base_field) and self._base_field.constant_field().is_prime_field(): 

 

#Making the auxiliary ring which only has polynomials with integral coefficients. 

tmpAuxRing = PolynomialRing(self._base_field.constant_field(), str(self._base_field.gen())+','+str(self._ring.gen())) 

intMinPoly, d = self._make_monic_integral(self._polynomial) 

curveIdeal = tmpAuxRing.ideal(intMinPoly) 

 

singular.lib('normal.lib') #loading genus method in singular 

return int(curveIdeal._singular_().genus()) 

 

else: 

raise NotImplementedError("Computation of genus over this rational function field not implemented yet") 

 

@cached_method 

def derivation(self): 

r""" 

Return a derivation of the function field over the constant base field. 

 

A derivation on `R` is a map `R\to R` satisfying 

`D(\alpha+\beta)=D(\alpha)+D(\beta)` and `D(\alpha\beta)=\beta 

D(\alpha)+\alpha D(\beta)` for all `\alpha, \beta \in R`. For a 

function field which is a finite extension of `K(x)` with `K` perfect, 

the derivations form a one-dimensional `K`-vector space generated by 

the derivation returned by this method. 

 

OUTPUT: 

 

- a derivation of the function field 

 

EXAMPLES:: 

 

sage: K.<x> = FunctionField(GF(3)) 

sage: R.<y> = K[] 

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

sage: d = L.derivation(); d 

Derivation map: 

From: Function field in y defined by y^2 + 2*x 

To: Function field in y defined by y^2 + 2*x 

Defn: y |--> 2/x*y 

sage: d(x) 

1 

sage: d(x^3) 

0 

sage: d(x*y) 

0 

sage: d(y) 

2/x*y 

 

Derivations are linear and satisfy Leibniz's law:: 

 

sage: d(x+y) == d(x) + d(y) 

True 

sage: d(x*y) == x*d(y) + y*d(x) 

True 

 

If the field is a separable extension of the base field, the derivation 

extending a derivation of the base function field is uniquely 

determined. Proposition 11 of [GT1996]_ describes how to compute the 

extension. We apply the formula described there to the generator 

of the space of derivations on the base field. 

 

The general inseparable case is not implemented yet (see :trac:`16562`, 

:trac:`16564`.)` 

""" 

from .maps import FunctionFieldDerivation_separable 

if self.polynomial().gcd(self.polynomial().derivative()).is_one(): 

return FunctionFieldDerivation_separable(self, self.base_ring().derivation()) 

else: 

raise NotImplementedError("construction of separable models not implemented") 

 

def _simple_model(self, name='v'): 

r""" 

Return a finite extension `N/K(x)` isomorphic to the tower of 

extensions `M/L/K(x)` with `K` perfect. 

 

Helper method for :meth:`simple_model`. 

 

INPUT: 

 

- ``name`` -- a string, the name of the generator of `N` 

 

ALGORITHM: 

 

Since `K` is perfect, the extension `M/K(x)` is simple, i.e., generated 

by a single element [BM1940]_. Therefore, there are only finitely many 

intermediate fields (Exercise 3.6.7 in [Bo2009]_). 

Let `a` be a generator of `M/L` and let `b` be a generator of `L/K(x)`. 

For some `i` the field `N_i=K(x)(a+x^ib)` is isomorphic to `M` and so 

it is enough to test for all terms of the form `a+x^ib` whether they 

generate a field of the right degree. 

Indeed, suppose for contradiction that for all `i` we had `N_i\neq M`. 

Then `N_i=N_j` for some `i,j`. Thus `(a+x^ib)-(a+x^jb)=b(x^i-x^j)\in 

N_j` and so `b\in N_j`. Similarly, 

`a+x^ib-x^{i-j}(a+x^jb)=a(1+x^{i-j})\in N_j` and so `a\in N_j`. 

Therefore, `N_j=M`. 

 

TESTS:: 

 

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

sage: R.<y> = K[] 

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

sage: R.<z> = L[] 

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

sage: M._simple_model() 

(Function field in v defined by v^4 - x, 

Function Field morphism: 

From: Function field in v defined by v^4 - x 

To: Function field in z defined by z^2 - y 

Defn: v |--> z, 

Function Field morphism: 

From: Function field in z defined by z^2 - y 

To: Function field in v defined by v^4 - x 

Defn: z |--> v 

y |--> v^2) 

 

Check that this also works for inseparable extensions:: 

 

sage: K.<x> = FunctionField(GF(2)) 

sage: R.<y> = K[] 

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

sage: R.<z> = L[] 

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

sage: M._simple_model() 

(Function field in v defined by v^4 + x, 

Function Field morphism: 

From: Function field in v defined by v^4 + x 

To: Function field in z defined by z^2 + y 

Defn: v |--> z, 

Function Field morphism: 

From: Function field in z defined by z^2 + y 

To: Function field in v defined by v^4 + x 

Defn: z |--> v 

y |--> v^2) 

 

An example where the generator of the last extension does not generate 

the extension of the rational function field:: 

 

sage: K.<x> = FunctionField(GF(2)) 

sage: R.<y> = K[] 

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

sage: R.<z> = L[] 

sage: M.<z> = L.extension(z^3-1) 

sage: M._simple_model() 

(Function field in v defined by v^6 + x*v^4 + x^2*v^2 + x^3 + 1, 

Function Field morphism: 

From: Function field in v defined by v^6 + x*v^4 + x^2*v^2 + x^3 + 1 

To: Function field in z defined by z^3 + 1 

Defn: v |--> z + y, 

Function Field morphism: 

From: Function field in z defined by z^3 + 1 

To: Function field in v defined by v^6 + x*v^4 + x^2*v^2 + x^3 + 1 

Defn: z |--> v^4 + x^2 

y |--> v^4 + v + x^2) 

 

""" 

M = self 

L = M.base_field() 

K = L.base_field() 

 

assert(is_RationalFunctionField(K)) 

assert(K is not L) 

assert(L is not M) 

 

if not K.constant_field().is_perfect(): 

raise NotImplementedError("simple_model() only implemented over perfect constant fields") 

 

x = K.gen() 

b = L.gen() 

a = M.gen() 

 

# using a+x^i*b tends to lead to huge powers of x in the minimal 

# polynomial of the resulting field; it is better to try terms of 

# the form a+i*b first (but in characteristic p>0 there are only 

# finitely many of these) 

# We systematically try elements of the form a+b*factor*x^exponent 

factor = self.constant_base_field().zero() 

exponent = 0 

while True: 

v = M(a+b*factor*x**exponent) 

minpoly = v.matrix(K).minpoly() 

if minpoly.degree() == M.degree()*L.degree(): 

break 

factor += 1 

if factor == 0: 

factor = self.constant_base_field().one() 

exponent += 1 

 

N = K.extension(minpoly, names=(name,)) 

 

# the morphism N -> M, v |-> v 

N_to_M = N.hom(v) 

 

# the morphism M -> N, b |-> M_b, a |-> M_a 

V, V_to_M, M_to_V = M.vector_space(K) 

V, V_to_N, N_to_V = N.vector_space(K) 

from sage.matrix.matrix_space import MatrixSpace 

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

# the power basis of v over K 

B = [M_to_V(v**i) for i in range(V.dimension())] 

B = MS(B) 

M_b = V_to_N(B.solve_left(M_to_V(b))) 

M_a = V_to_N(B.solve_left(M_to_V(a))) 

M_to_N = M.hom([M_a,M_b]) 

 

return N, N_to_M, M_to_N 

 

@cached_method 

def simple_model(self, name=None): 

""" 

Return a function field isomorphic to this field which is a simple 

extension of a rational function field. 

 

INPUT: 

 

- ``name`` -- a string (default: ``None``), the name of generator of 

the simple extension. If ``None``, then the name of the generator 

will be the same as the name of the generator of this function field. 

 

OUTPUT: 

 

A triple ``(F,f,t)`` where ``F`` is a field isomorphic to this field, 

``f`` is an isomorphism from ``F`` to this function field and ``t`` is 

the inverse of ``f``. 

 

EXAMPLES: 

 

A tower of four function fields:: 

 

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

sage: L.<z> = K.extension(z^2-x); R.<u> = L[] 

sage: M.<u> = L.extension(u^2-z); R.<v> = M[] 

sage: N.<v> = M.extension(v^2-u) 

 

The fields N and M as simple extensions of K:: 

 

sage: N.simple_model() 

(Function field in v defined by v^8 - x, 

Function Field morphism: 

From: Function field in v defined by v^8 - x 

To: Function field in v defined by v^2 - u 

Defn: v |--> v, 

Function Field morphism: 

From: Function field in v defined by v^2 - u 

To: Function field in v defined by v^8 - x 

Defn: v |--> v 

u |--> v^2 

z |--> v^4 

x |--> x) 

sage: M.simple_model() 

(Function field in u defined by u^4 - x, 

Function Field morphism: 

From: Function field in u defined by u^4 - x 

To: Function field in u defined by u^2 - z 

Defn: u |--> u, 

Function Field morphism: 

From: Function field in u defined by u^2 - z 

To: Function field in u defined by u^4 - x 

Defn: u |--> u 

z |--> u^2 

x |--> x) 

 

An optional parameter ``name`` can be used to set the name of the 

generator of the simple extension:: 

 

sage: M.simple_model(name='t') 

(Function field in t defined by t^4 - x, Function Field morphism: 

From: Function field in t defined by t^4 - x 

To: Function field in u defined by u^2 - z 

Defn: t |--> u, Function Field morphism: 

From: Function field in u defined by u^2 - z 

To: Function field in t defined by t^4 - x 

Defn: u |--> t 

z |--> t^2 

x |--> x) 

 

An example with higher degrees:: 

 

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

sage: L.<y> = K.extension(y^5-x); R.<z> = L[] 

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

sage: M.simple_model() 

(Function field in z defined by z^15 + x*z^12 + x^2*z^9 + 2*x^3*z^6 + 2*x^4*z^3 + 2*x^5 + 2*x^3, 

Function Field morphism: 

From: Function field in z defined by z^15 + x*z^12 + x^2*z^9 + 2*x^3*z^6 + 2*x^4*z^3 + 2*x^5 + 2*x^3 

To: Function field in z defined by z^3 + 2*x 

Defn: z |--> z + y, 

Function Field morphism: 

From: Function field in z defined by z^3 + 2*x 

To: Function field in z defined by z^15 + x*z^12 + x^2*z^9 + 2*x^3*z^6 + 2*x^4*z^3 + 2*x^5 + 2*x^3 

Defn: z |--> 2/x*z^6 + 2*z^3 + z + 2*x 

y |--> 1/x*z^6 + z^3 + x 

x |--> x) 

 

This also works for inseparable extensions:: 

 

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

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

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

sage: M.simple_model() 

(Function field in z defined by z^4 + x, Function Field morphism: 

From: Function field in z defined by z^4 + x 

To: Function field in z defined by z^2 + y 

Defn: z |--> z, Function Field morphism: 

From: Function field in z defined by z^2 + y 

To: Function field in z defined by z^4 + x 

Defn: z |--> z 

y |--> z^2 

x |--> x) 

""" 

if name is None: 

name = self.variable_name() 

 

if is_RationalFunctionField(self.base_field()): 

# the extension is simple already 

if name == self.variable_name(): 

from sage.categories.homset import Hom 

id = Hom(self,self).identity() 

return self, id, id 

else: 

ret = self.base_field().extension(self.polynomial(), names=(name,)) 

f = ret.hom(self.gen()) 

t = self.hom(ret.gen()) 

return ret, f, t 

else: 

# recursively collapse the tower of fields 

base = self.base_field() 

base_, from_base_, to_base_ = base.simple_model() 

self_ = base_.extension(self.polynomial().map_coefficients(to_base_), names=(name,)) 

gens_in_base_ = [to_base_(k.gen()) 

for k in base._intermediate_fields(base.rational_function_field())] 

to_self_ = self.hom([self_.gen()]+gens_in_base_) 

from_self_ = self_.hom([self.gen(),from_base_(base_.gen())]) 

 

# now collapse self_/base_/K(x) 

ret, ret_to_self_, self__to_ret = self_._simple_model(name) 

ret_to_self = ret.hom(from_self_(ret_to_self_(ret.gen()))) 

gens_in_ret = [self__to_ret(to_self_(k.gen())) 

for k in self._intermediate_fields(self.rational_function_field())] 

self_to_ret = self.hom(gens_in_ret) 

return ret, ret_to_self, self_to_ret 

 

@cached_method 

def primitive_element(self): 

r""" 

Return a primitive element over the underlying rational function field. 

 

If this is a finite extension of a rational function field `K(x)` with 

`K` perfect, then this is a simple extension of `K(x)`, i.e., there is 

a primitive element `y` which generates this field over `K(x)`. This 

method returns such an element `y`. 

 

EXAMPLES:: 

 

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

sage: R.<y> = K[] 

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

sage: R.<z> = L[] 

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

sage: R.<z> = L[] 

sage: N.<u> = L.extension(z^2-x-1) 

sage: N.primitive_element() 

u + y 

sage: M.primitive_element() 

z 

sage: L.primitive_element() 

y 

 

This also works for inseparable extensions:: 

 

sage: K.<x> = FunctionField(GF(2)) 

sage: R.<Y> = K[] 

sage: L.<y> = K.extension(Y^2-x) 

sage: R.<Z> = L[] 

sage: M.<z> = L.extension(Z^2-y) 

sage: M.primitive_element() 

z 

""" 

N, f, t = self.simple_model() 

return f(N.gen()) 

 

def change_variable_name(self, name): 

r""" 

Return a field isomorphic to this field with variable(s) ``name``. 

 

INPUT: 

 

- ``name`` -- a string or a tuple consisting of a strings, the names of 

the new variables starting with a generator of this field and going 

down to the rational function field. 

 

OUTPUT: 

 

A triple ``F,f,t`` where ``F`` is a function field, ``f`` is an 

isomorphism from ``F`` to this field, and ``t`` is the inverse of 

``f``. 

 

EXAMPLES:: 

 

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

sage: R.<y> = K[] 

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

sage: R.<z> = L[] 

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

 

sage: M.change_variable_name('zz') 

(Function field in zz defined by zz^2 - y, 

Function Field morphism: 

From: Function field in zz defined by zz^2 - y 

To: Function field in z defined by z^2 - y 

Defn: zz |--> z 

y |--> y 

x |--> x, 

Function Field morphism: 

From: Function field in z defined by z^2 - y 

To: Function field in zz defined by zz^2 - y 

Defn: z |--> zz 

y |--> y 

x |--> x) 

sage: M.change_variable_name(('zz','yy')) 

(Function field in zz defined by zz^2 - yy, Function Field morphism: 

From: Function field in zz defined by zz^2 - yy 

To: Function field in z defined by z^2 - y 

Defn: zz |--> z 

yy |--> y 

x |--> x, Function Field morphism: 

From: Function field in z defined by z^2 - y 

To: Function field in zz defined by zz^2 - yy 

Defn: z |--> zz 

y |--> yy 

x |--> x) 

sage: M.change_variable_name(('zz','yy','xx')) 

(Function field in zz defined by zz^2 - yy, 

Function Field morphism: 

From: Function field in zz defined by zz^2 - yy 

To: Function field in z defined by z^2 - y 

Defn: zz |--> z 

yy |--> y 

xx |--> x, 

Function Field morphism: 

From: Function field in z defined by z^2 - y 

To: Function field in zz defined by zz^2 - yy 

Defn: z |--> zz 

y |--> yy 

x |--> xx) 

 

""" 

if not isinstance(name, tuple): 

name = (name,) 

if len(name) == 0: 

raise ValueError("name must contain at least one string") 

elif len(name) == 1: 

base = self.base_field() 

from sage.categories.homset import Hom 

from_base = to_base = Hom(base,base).identity() 

else: 

base, from_base, to_base = self.base_field().change_variable_name(name[1:]) 

 

ret = base.extension(self.polynomial().map_coefficients(to_base), names=(name[0],)) 

f = ret.hom( [k.gen() for k in self._intermediate_fields(self.rational_function_field())] ) 

t = self.hom( [k.gen() for k in ret._intermediate_fields(ret.rational_function_field())] ) 

return ret, f, t 

 

def is_RationalFunctionField(x): 

""" 

Return ``True`` if ``x`` is of rational function field type. 

 

EXAMPLES:: 

 

sage: from sage.rings.function_field.function_field import is_RationalFunctionField 

sage: is_RationalFunctionField(QQ) 

False 

sage: is_RationalFunctionField(FunctionField(QQ,'t')) 

True 

""" 

return isinstance(x, RationalFunctionField) 

 

class RationalFunctionField(FunctionField): 

""" 

A rational function field K(t) in one variable, over an arbitrary 

base field. 

 

EXAMPLES:: 

 

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

Rational function field in t over Finite Field of size 3 

sage: K.gen() 

t 

sage: 1/t + t^3 + 5 

(t^4 + 2*t + 1)/t 

 

There are various ways to get at the underlying fields and rings 

associated to a rational function field:: 

 

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

sage: K.base_field() 

Rational function field in t over Finite Field of size 7 

sage: K.field() 

Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 7 

sage: K.constant_field() 

Finite Field of size 7 

sage: K.maximal_order() 

Maximal order in Rational function field in t over Finite Field of size 7 

 

We define a morphism:: 

 

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

sage: L = FunctionField(QQ, 'tbar') # give variable name as second input 

sage: K.hom(L.gen()) 

Function Field morphism: 

From: Rational function field in t over Rational Field 

To: Rational function field in tbar over Rational Field 

Defn: t |--> tbar 

""" 

def __init__(self, constant_field, names, 

element_class = FunctionFieldElement_rational, 

category=CAT): 

""" 

Create a rational function field in one variable. 

 

INPUT: 

 

- ``constant_field`` -- an arbitrary field 

- ``names`` -- a string or tuple of length 1 

- ``category`` -- default: FunctionFields() 

 

EXAMPLES:: 

 

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

Rational function field in t over Complex Field with 53 bits of precision 

sage: K.category() 

Category of function fields 

sage: FunctionField(QQ[I], 'alpha') 

Rational function field in alpha over Number Field in I with defining polynomial x^2 + 1 

 

Must be over a field:: 

 

sage: FunctionField(ZZ, 't') 

Traceback (most recent call last): 

... 

TypeError: constant_field must be a field 

""" 

if names is None: 

raise ValueError("variable name must be specified") 

elif not isinstance(names, tuple): 

names = (names, ) 

if not constant_field.is_field(): 

raise TypeError("constant_field must be a field") 

self._element_class = element_class 

self._constant_field = constant_field 

FunctionField.__init__(self, self, names=names, category = category) 

R = constant_field[names[0]] 

self._hash = hash((constant_field, names)) 

self._ring = R 

 

self._field = R.fraction_field() 

from sage.categories.all import Hom 

hom = Hom(self._field, self) 

from .maps import FractionFieldToFunctionField 

self.register_coercion(hom.__make_element_class__(FractionFieldToFunctionField)(hom.domain(), hom.codomain())) 

 

from sage.categories.sets_with_partial_maps import SetsWithPartialMaps 

from sage.categories.morphism import SetMorphism 

R.register_conversion(SetMorphism(self.Hom(R, SetsWithPartialMaps()), self._to_polynomial)) 

 

self._gen = self(R.gen()) 

 

def __reduce__(self): 

""" 

Returns the arguments which were used to create this instance. The rationale for this is explained in the documentation of ``UniqueRepresentation``. 

 

EXAMPLES:: 

 

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

sage: clazz,args = K.__reduce__() 

sage: clazz(*args) 

Rational function field in x over Rational Field 

""" 

from .constructor import FunctionField 

return FunctionField, (self._constant_field, self._names) 

 

def __hash__(self): 

""" 

Return hash of this function field. 

 

The hash is formed from the constant field and the variable names. 

 

EXAMPLES:: 

 

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

sage: hash(K) == hash((K.constant_base_field(), K.variable_names())) 

True 

 

""" 

return self._hash 

 

def _repr_(self): 

""" 

Return string representation of this function field. 

 

EXAMPLES:: 

 

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

sage: K._repr_() 

'Rational function field in t over Rational Field' 

""" 

return "Rational function field in %s over %s"%( 

self.variable_name(), self._constant_field) 

 

def _element_constructor_(self, x): 

r""" 

Coerce ``x`` into an element of this function field, possibly not canonically. 

 

INPUT: 

 

- ``x`` -- the element 

 

OUTPUT: 

 

``x``, as an element of this function field 

 

EXAMPLES:: 

 

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

sage: a = K._element_constructor_(K.maximal_order().gen()); a 

t 

sage: a.parent() 

Rational function field in t over Rational Field 

 

TESTS: 

 

Conversion of a string:: 

 

sage: K('t') 

t 

sage: K('1/t') 

1/t 

 

Conversion of a constant polynomial over the function field:: 

 

sage: K(K.polynomial_ring().one()) 

1 

 

Some indirect test of conversion:: 

 

sage: S.<x, y> = K[] 

sage: I = S*[x^2 - y^2, y-t] 

sage: I.groebner_basis() 

[x^2 - t^2, y - t] 

 

""" 

if isinstance(x, FunctionFieldElement): 

return FunctionFieldElement_rational(self, self._field(x._x)) 

try: 

x = self._field(x) 

except TypeError as Err: 

try: 

if x.parent() is self.polynomial_ring(): 

return x[0] 

except AttributeError: 

pass 

raise Err 

return FunctionFieldElement_rational(self, x) 

 

def _to_constant_base_field(self, f): 

r""" 

Return ``f`` as an element of the :meth:`constant_base_field`. 

 

INPUT: 

 

- ``f`` -- an element of this rational function field which is a 

constant of the underlying rational function field. 

 

EXAMPLES:: 

 

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

sage: K._to_constant_base_field(K(1)) 

1 

sage: K._to_constant_base_field(K(x)) 

Traceback (most recent call last): 

... 

ValueError: only constants can be converted into the constant base field but x is not a constant 

 

TESTS: 

 

Verify that :trac:`21872` has been resolved:: 

 

sage: K(1) in QQ 

True 

sage: x in QQ 

False 

 

""" 

K = self.constant_base_field() 

if f.denominator() in K and f.numerator() in K: 

# When K is not exact, f.denominator() might not be an exact 1, so 

# we need to divide explicitly to get the correct precision 

return K(f.numerator()) / K(f.denominator()) 

raise ValueError("only constants can be converted into the constant base field but %r is not a constant"%(f,)) 

 

def _to_polynomial(self, f): 

""" 

If ``f`` is integral, return it as a polynomial. 

 

INPUT: 

 

- ``f`` -- an element of this rational function field whose denominator is a constant. 

 

EXAMPLES:: 

 

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

sage: K._ring(x) # indirect doctest 

x 

""" 

K = f.parent().constant_base_field() 

if f.denominator() in K: 

return f.numerator()/K(f.denominator()) 

raise ValueError("Only polynomials can be converted to the underlying polynomial ring") 

 

def _to_bivariate_polynomial(self, f): 

""" 

Convert ``f`` from a univariate polynomial over the rational function 

field into a bivariate polynomial and a denominator. 

 

INPUT: 

 

- ``f`` -- a univariate polynomial over self. 

 

OUTPUT: 

 

- bivariate polynomial, denominator 

 

EXAMPLES:: 

 

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

sage: S.<X> = R[] 

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

sage: R._to_bivariate_polynomial(f) 

(X^7*t^2 - X^4*t^5 - X^3 + t^3, t^3) 

""" 

v = f.list() 

from sage.arith.all import LCM 

denom = LCM([a.denominator() for a in v]) 

S = denom.parent() 

x,t = S.base_ring()['%s,%s'%(f.parent().variable_name(),self.variable_name())].gens() 

phi = S.hom([t]) 

return sum([phi((denom * v[i]).numerator()) * x**i for i in range(len(v))]), denom 

 

def _factor_univariate_polynomial(self, f, proof=True): 

""" 

Factor the univariate polynomial ``f`` over self. 

 

EXAMPLES:: 

 

We do a factorization over the function field over the rationals:: 

 

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

sage: S.<X> = R[] 

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

sage: f.factor() # indirect doctest 

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

sage: f.factor().prod() == f 

True 

 

We do a factorization over a finite prime field:: 

 

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

sage: S.<X> = R[] 

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

sage: f.factor() 

(1/t) * (X + 3*t) * (X + 5*t) * (X + 6*t) * (X^2 + 1/t) * (X^2 + 6/t) 

sage: f.factor().prod() == f 

True 

 

Factoring over a function field over a non-prime finite field:: 

 

sage: k.<a> = GF(9) 

sage: R.<t> = FunctionField(k) 

sage: S.<X> = R[] 

sage: f = (1/t)*(X^3 - a*t^3) 

sage: f.factor() 

(1/t) * (X + (a + 2)*t)^3 

sage: f.factor().prod() == f 

True 

 

We check that ``proof`` parameter is passed to the underlying 

polynomial (see :trac:`24510`). However, factoring over a function 

field over a tower of finite fields does not work yet (see 

:trac:`24533`):: 

 

sage: k = GF(4) 

sage: k.<a> = GF(4) 

sage: R.<b> = k[] 

sage: l.<b> = k.extension(a^2 + a + b) 

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

sage: R.<t> = K[] 

sage: F = t*x 

sage: F.factor(proof=False) 

Traceback (most recent call last): 

... 

TypeError: no conversion of this ring to a Singular ring defined 

 

""" 

old_variable_name = f.variable_name() 

# the variables of the bivariate polynomial must be distinct 

if self.variable_name() == f.variable_name(): 

# replace x with xx to make the variable names distinct 

f = f.change_variable_name(old_variable_name + old_variable_name) 

 

F, d = self._to_bivariate_polynomial(f) 

fac = F.factor(proof=proof) 

x = f.parent().gen() 

t = f.parent().base_ring().gen() 

phi = F.parent().hom([x, t]) 

v = [(phi(P),e) for P, e in fac] 

unit = phi(fac.unit())/d 

w = [] 

for a, e in v: 

c = a.leading_coefficient() 

a = a/c 

# undo any variable substitution that we introduced for the bivariate polynomial 

if old_variable_name != a.variable_name(): 

a = a.change_variable_name(old_variable_name) 

unit *= (c**e) 

w.append((a,e)) 

from sage.structure.factorization import Factorization 

return Factorization(w, unit=unit) 

 

@cached_method 

def polynomial_ring(self, var='x'): 

""" 

Return a polynomial ring in one variable over this rational function field. 

 

INPUT: 

 

- ``var`` -- a string (default: 'x') 

 

EXAMPLES:: 

 

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

sage: K.polynomial_ring() 

Univariate Polynomial Ring in x over Rational function field in x over Rational Field 

sage: K.polynomial_ring('T') 

Univariate Polynomial Ring in T over Rational function field in x over Rational Field 

""" 

return self[var] 

 

@cached_method 

def vector_space(self): 

""" 

Return a vector space V and isomorphisms self --> V and V --> self. 

 

OUTPUT: 

 

- ``V`` -- a vector space over the rational numbers 

- ``from_V`` -- an isomorphism from V to self 

- ``to_V`` -- an isomorphism from self to V 

 

EXAMPLES:: 

 

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

sage: K.vector_space() 

(Vector space of dimension 1 over Rational function field in x over Rational Field, Isomorphism morphism: 

From: Vector space of dimension 1 over Rational function field in x over Rational Field 

To: Rational function field in x over Rational Field, Isomorphism morphism: 

From: Rational function field in x over Rational Field 

To: Vector space of dimension 1 over Rational function field in x over Rational Field) 

""" 

V = self.base_field()**1 

from .maps import MapVectorSpaceToFunctionField, MapFunctionFieldToVectorSpace 

from_V = MapVectorSpaceToFunctionField(V, self) 

to_V = MapFunctionFieldToVectorSpace(self, V) 

return (V, from_V, to_V) 

 

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

""" 

Create a random element of this rational function field. 

 

Parameters are passed to the random_element method of the 

underlying fraction field. 

 

EXAMPLES:: 

 

sage: FunctionField(QQ,'alpha').random_element() # random 

(-1/2*alpha^2 - 4)/(-12*alpha^2 + 1/2*alpha - 1/95) 

""" 

return self(self._field.random_element(*args, **kwds)) 

 

def degree(self, base=None): 

""" 

Return the degree over the base field of this rational 

function field. Since the base field is the rational function 

field itself, the degree is 1. 

 

INPUT: 

 

- ``base`` -- the base field of the vector space; must be the function 

field itself (the default) 

 

EXAMPLES:: 

 

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

sage: K.degree() 

1 

""" 

if base is None: 

base = self 

if base is not self: 

raise ValueError("base must be None or the rational function field") 

from sage.rings.integer_ring import ZZ 

return ZZ(1) 

 

def gen(self, n=0): 

""" 

Return the ``n``-th generator of this function field. If ``n`` is not 

0, then an IndexError is raised. 

 

EXAMPLES:: 

 

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

t 

sage: K.gen().parent() 

Rational function field in t over Rational Field 

sage: K.gen(1) 

Traceback (most recent call last): 

... 

IndexError: Only one generator. 

""" 

if n != 0: 

raise IndexError("Only one generator.") 

return self._gen 

 

def ngens(self): 

""" 

Return the number of generators, which is 1. 

 

EXAMPLES:: 

 

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

sage: K.ngens() 

1 

""" 

return 1 

 

def base_field(self): 

""" 

Return the base field of this rational function field, which is just 

this function field itself. 

 

EXAMPLES:: 

 

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

sage: K.base_field() 

Rational function field in t over Finite Field of size 7 

""" 

return self 

 

def hom(self, im_gens, base_morphism=None): 

""" 

Create a homomorphism from self to another ring. 

 

INPUT: 

 

- ``im_gens`` -- exactly one element of some ring. It must be invertible and transcendental over 

the image of ``base_morphism``; this is not checked. 

- ``base_morphism`` -- a homomorphism from the base field into the other ring. 

If ``None``, try to use a coercion map. 

 

OUTPUT: 

 

- a map between function fields 

 

EXAMPLES: 

 

We make a map from a rational function field to itself:: 

 

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

sage: K.hom( (x^4 + 2)/x) 

Function Field endomorphism of Rational function field in x over Finite Field of size 7 

Defn: x |--> (x^4 + 2)/x 

 

We construct a map from a rational function field into a 

non-rational extension field:: 

 

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

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

sage: f = K.hom(y^2 + y + 2); f 

Function Field morphism: 

From: Rational function field in x over Finite Field of size 7 

To: Function field in y defined by y^3 + 6*x^3 + x 

Defn: x |--> y^2 + y + 2 

sage: f(x) 

y^2 + y + 2 

sage: f(x^2) 

5*y^2 + (x^3 + 6*x + 4)*y + 2*x^3 + 5*x + 4 

""" 

from sage.structure.category_object import CategoryObject 

if isinstance(im_gens, CategoryObject): 

return self.Hom(im_gens).natural_map() 

if not isinstance(im_gens, (list,tuple)): 

im_gens = [im_gens] 

if len(im_gens) != 1: 

raise ValueError("there must be exactly one generator") 

x = im_gens[0] 

R = x.parent() 

if base_morphism is None and not R.has_coerce_map_from(self.constant_field()): 

raise ValueError("You must specify a morphism on the base field") 

from .maps import FunctionFieldMorphism_rational 

return FunctionFieldMorphism_rational(self.Hom(R), x, base_morphism) 

 

def field(self): 

""" 

Return the underlying field, forgetting the function field 

structure. 

 

EXAMPLES:: 

 

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

sage: K.field() 

Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 7 

 

.. SEEALSO:: 

 

:meth:`sage.rings.fraction_field.FractionField_1poly_field.function_field` 

 

""" 

return self._field 

 

@cached_method 

def maximal_order(self): 

""" 

Return the maximal order of this function field. Since this 

is a rational function field it is of the form K(t), and the 

maximal order is by definition K[t]. 

 

EXAMPLES:: 

 

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

sage: K.maximal_order() 

Maximal order in Rational function field in t over Rational Field 

sage: K.equation_order() 

Maximal order in Rational function field in t over Rational Field 

""" 

from .function_field_order import FunctionFieldOrder_rational 

return FunctionFieldOrder_rational(self) 

 

equation_order = maximal_order 

 

def constant_base_field(self): 

""" 

Return the field that this rational function field is a 

transcendental extension of. 

 

EXAMPLES:: 

 

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

sage: K.constant_field() 

Rational Field 

 

""" 

return self._constant_field 

 

constant_field = constant_base_field 

 

def genus(self): 

""" 

Return the genus of this function field 

This is always equal 0 for a rational function field 

 

EXAMPLES:: 

 

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

sage: K.genus() 

0 

""" 

return 0 

 

@cached_method(key=lambda self, base: None) 

def vector_space(self, base=None): 

""" 

Return a vector space `V` and isomorphisms from this field to `V` and 

from `V` to this field. 

 

This function allows us to identify the elements of this field with 

elements of a one-dimensional vector space over the field itself. This 

method exists so that all function fields (rational or not) have the 

same interface. 

 

INPUT: 

 

- ``base`` -- the base field of the vector space; must be the function 

field itself (the default) 

 

OUTPUT: 

 

- ``V`` -- a vector space over base field 

- ``from_V`` -- an isomorphism from V to this field 

- ``to_V`` -- an isomorphism from this field to V 

 

EXAMPLES:: 

 

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

sage: K.vector_space() 

(Vector space of dimension 1 over Rational function field in x over Rational Field, Isomorphism morphism: 

From: Vector space of dimension 1 over Rational function field in x over Rational Field 

To: Rational function field in x over Rational Field, Isomorphism morphism: 

From: Rational function field in x over Rational Field 

To: Vector space of dimension 1 over Rational function field in x over Rational Field) 

 

TESTS:: 

 

sage: K.vector_space() 

(Vector space of dimension 1 over Rational function field in x over Rational Field, Isomorphism morphism: 

From: Vector space of dimension 1 over Rational function field in x over Rational Field 

To: Rational function field in x over Rational Field, Isomorphism morphism: 

From: Rational function field in x over Rational Field 

To: Vector space of dimension 1 over Rational function field in x over Rational Field) 

 

""" 

from .maps import MapVectorSpaceToFunctionField, MapFunctionFieldToVectorSpace 

if base is None: 

base = self 

if base is not self: 

raise ValueError("base must be the rational function field or None") 

V = base**1 

from_V = MapVectorSpaceToFunctionField(V, self) 

to_V = MapFunctionFieldToVectorSpace(self, V) 

return (V, from_V, to_V) 

 

def change_variable_name(self, name): 

r""" 

Return a field isomorphic to this field with variable ``name``. 

 

INPUT: 

 

- ``name`` -- a string or a tuple consisting of a single string, the 

name of the new variable 

 

OUTPUT: 

 

A triple ``F,f,t`` where ``F`` is a rational function field, ``f`` is 

an isomorphism from ``F`` to this field, and ``t`` is the inverse of 

``f``. 

 

EXAMPLES:: 

 

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

sage: L,f,t = K.change_variable_name('y') 

sage: L,f,t 

(Rational function field in y over Rational Field, 

Function Field morphism: 

From: Rational function field in y over Rational Field 

To: Rational function field in x over Rational Field 

Defn: y |--> x, 

Function Field morphism: 

From: Rational function field in x over Rational Field 

To: Rational function field in y over Rational Field 

Defn: x |--> y) 

sage: L.change_variable_name('x')[0] is K 

True 

 

""" 

if isinstance(name, tuple): 

if len(name) != 1: 

raise ValueError("names must be a tuple with a single string") 

name = name[0] 

if name == self.variable_name(): 

from sage.categories.homset import Hom 

id = Hom(self,self).identity() 

return self,id,id 

else: 

from .constructor import FunctionField 

ret = FunctionField(self.constant_base_field(), name) 

return ret, ret.hom(self.gen()), self.hom(ret.gen()) 

 

@cached_method 

def derivation(self): 

r""" 

Return a derivation of the rational function field over the constant 

base field. 

 

OUTPUT: 

 

- a derivation of the rational function field 

 

The derivation maps the generator of the rational function field to 1. 

 

EXAMPLES:: 

 

sage: K.<x> = FunctionField(GF(3)) 

sage: m = K.derivation(); m 

Derivation map: 

From: Rational function field in x over Finite Field of size 3 

To: Rational function field in x over Finite Field of size 3 

sage: m(x) 

1 

 

TESTS:: 

 

sage: L.<y> = FunctionField(K) 

sage: L.derivation() 

Traceback (most recent call last): 

... 

NotImplementedError: not implemented for non-perfect base fields 

""" 

from .maps import FunctionFieldDerivation_rational 

if not self.constant_base_field().is_perfect(): 

raise NotImplementedError("not implemented for non-perfect base fields") 

return FunctionFieldDerivation_rational(self, self.one())