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

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349

3350

3351

3352

3353

3354

3355

3356

3357

3358

3359

3360

3361

3362

3363

3364

3365

3366

3367

3368

3369

3370

3371

3372

3373

3374

3375

3376

3377

3378

3379

3380

3381

3382

3383

3384

3385

3386

3387

3388

3389

3390

3391

3392

3393

3394

3395

3396

3397

3398

3399

3400

3401

3402

3403

3404

3405

3406

3407

3408

3409

3410

3411

3412

3413

3414

3415

3416

3417

3418

3419

3420

3421

3422

3423

3424

3425

3426

3427

3428

3429

3430

3431

3432

3433

3434

3435

3436

3437

3438

3439

3440

3441

3442

3443

3444

3445

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3456

3457

3458

3459

3460

3461

3462

3463

3464

3465

3466

3467

3468

3469

3470

3471

3472

3473

3474

3475

3476

3477

3478

3479

3480

3481

3482

3483

3484

3485

3486

3487

3488

3489

3490

3491

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518

3519

3520

3521

3522

3523

3524

3525

3526

3527

3528

3529

3530

3531

3532

3533

3534

3535

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550

3551

3552

3553

3554

3555

3556

3557

3558

3559

3560

3561

3562

3563

3564

3565

3566

3567

3568

3569

3570

3571

3572

3573

3574

3575

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588

3589

3590

3591

3592

3593

3594

3595

3596

3597

3598

3599

3600

3601

3602

3603

3604

3605

3606

3607

3608

3609

3610

3611

3612

3613

3614

3615

3616

3617

3618

3619

3620

3621

3622

3623

3624

3625

3626

3627

3628

3629

3630

3631

3632

3633

3634

3635

3636

3637

3638

3639

3640

3641

3642

3643

3644

3645

3646

3647

3648

3649

3650

3651

3652

3653

3654

3655

3656

3657

3658

3659

3660

3661

3662

3663

3664

3665

3666

3667

3668

3669

3670

3671

3672

3673

3674

3675

3676

3677

3678

3679

3680

3681

3682

3683

3684

3685

3686

3687

3688

3689

3690

3691

3692

3693

3694

3695

3696

3697

3698

3699

3700

3701

3702

3703

3704

3705

3706

3707

3708

3709

3710

3711

3712

3713

3714

3715

3716

3717

3718

3719

3720

3721

3722

3723

3724

3725

3726

3727

3728

3729

3730

3731

3732

3733

3734

3735

3736

3737

3738

3739

3740

3741

3742

3743

3744

3745

3746

3747

3748

3749

3750

3751

3752

3753

3754

3755

3756

3757

3758

3759

3760

3761

3762

3763

3764

3765

3766

3767

3768

3769

3770

3771

3772

3773

3774

3775

3776

3777

3778

3779

3780

3781

3782

3783

3784

3785

3786

3787

3788

3789

3790

3791

3792

3793

3794

3795

3796

3797

3798

3799

3800

3801

3802

3803

3804

3805

3806

3807

3808

3809

3810

3811

3812

3813

3814

3815

3816

3817

3818

3819

3820

3821

3822

3823

3824

3825

3826

3827

3828

3829

3830

3831

3832

3833

3834

3835

3836

3837

3838

3839

3840

3841

3842

3843

3844

3845

3846

3847

3848

3849

3850

3851

3852

3853

3854

3855

3856

3857

3858

3859

3860

3861

3862

3863

3864

3865

3866

3867

3868

3869

3870

3871

3872

3873

3874

3875

3876

3877

3878

3879

3880

3881

3882

3883

3884

3885

3886

3887

3888

3889

3890

3891

3892

3893

3894

3895

3896

3897

3898

3899

3900

3901

3902

3903

3904

3905

3906

3907

3908

3909

3910

3911

3912

3913

3914

3915

3916

3917

3918

3919

3920

3921

3922

3923

3924

3925

3926

3927

3928

3929

3930

3931

3932

3933

3934

3935

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947

3948

3949

3950

3951

3952

3953

3954

3955

3956

3957

3958

3959

3960

3961

3962

3963

3964

3965

3966

3967

3968

3969

3970

3971

3972

3973

3974

3975

3976

3977

3978

3979

3980

3981

3982

3983

3984

3985

3986

3987

3988

3989

3990

3991

3992

3993

3994

3995

3996

3997

3998

3999

4000

4001

4002

4003

4004

4005

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015

4016

4017

4018

4019

4020

4021

4022

4023

4024

4025

4026

4027

4028

4029

4030

4031

4032

4033

4034

4035

4036

4037

4038

4039

4040

4041

4042

4043

4044

4045

4046

4047

4048

4049

4050

4051

4052

4053

4054

4055

4056

4057

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070

4071

4072

4073

4074

4075

4076

4077

4078

4079

4080

4081

4082

4083

4084

4085

4086

4087

4088

4089

4090

4091

4092

4093

4094

4095

4096

4097

4098

4099

4100

4101

4102

4103

4104

4105

4106

4107

4108

4109

4110

4111

4112

4113

4114

4115

4116

4117

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127

4128

4129

4130

4131

4132

4133

4134

4135

4136

4137

4138

4139

4140

4141

4142

4143

4144

4145

4146

4147

4148

4149

4150

4151

4152

4153

4154

4155

4156

4157

4158

4159

4160

4161

4162

4163

4164

4165

4166

4167

4168

4169

4170

4171

4172

4173

4174

4175

4176

4177

4178

4179

4180

4181

4182

4183

4184

4185

4186

4187

4188

4189

4190

4191

4192

4193

4194

4195

4196

4197

4198

4199

4200

4201

4202

4203

4204

4205

4206

4207

4208

4209

4210

4211

4212

4213

4214

4215

4216

4217

4218

4219

4220

4221

4222

4223

4224

4225

4226

4227

4228

4229

4230

4231

4232

4233

4234

4235

4236

4237

4238

4239

4240

4241

4242

4243

4244

4245

4246

4247

4248

4249

4250

4251

4252

4253

4254

4255

4256

4257

4258

4259

4260

4261

4262

4263

4264

4265

4266

4267

4268

4269

4270

4271

4272

4273

4274

4275

4276

4277

4278

4279

4280

4281

4282

4283

4284

4285

4286

4287

4288

4289

4290

4291

4292

4293

4294

4295

4296

4297

4298

4299

4300

4301

4302

4303

4304

4305

4306

4307

4308

4309

4310

4311

4312

4313

4314

4315

4316

4317

4318

4319

4320

4321

4322

4323

4324

4325

4326

4327

4328

4329

4330

4331

4332

4333

4334

4335

4336

4337

4338

4339

4340

4341

4342

4343

4344

4345

4346

4347

4348

4349

4350

4351

4352

4353

4354

4355

4356

4357

4358

4359

4360

4361

4362

4363

4364

4365

4366

4367

4368

4369

4370

4371

4372

4373

4374

4375

4376

4377

4378

4379

4380

4381

4382

4383

4384

4385

4386

4387

4388

4389

4390

4391

4392

4393

4394

4395

4396

4397

4398

4399

4400

4401

4402

4403

4404

4405

4406

4407

4408

4409

4410

4411

4412

4413

4414

4415

4416

4417

4418

4419

4420

4421

4422

4423

4424

4425

4426

4427

4428

4429

4430

4431

4432

4433

4434

4435

4436

4437

4438

4439

4440

4441

4442

4443

4444

4445

4446

4447

4448

4449

4450

4451

4452

4453

4454

4455

4456

4457

4458

4459

4460

4461

4462

4463

4464

4465

4466

4467

4468

4469

4470

4471

4472

4473

4474

4475

4476

4477

4478

4479

4480

4481

4482

4483

4484

4485

4486

4487

4488

4489

4490

4491

4492

4493

4494

4495

4496

4497

4498

4499

4500

4501

4502

4503

4504

4505

4506

4507

4508

4509

4510

4511

4512

4513

4514

4515

4516

4517

4518

4519

4520

4521

4522

4523

4524

4525

4526

4527

4528

4529

4530

4531

4532

4533

4534

4535

4536

4537

4538

4539

4540

4541

4542

4543

4544

4545

4546

4547

4548

4549

4550

4551

4552

4553

4554

4555

4556

4557

4558

4559

4560

4561

4562

4563

4564

4565

4566

4567

4568

4569

4570

4571

4572

4573

4574

4575

4576

4577

4578

4579

4580

4581

4582

4583

4584

4585

4586

4587

4588

4589

4590

4591

4592

4593

4594

4595

4596

4597

4598

4599

4600

4601

4602

4603

4604

4605

4606

4607

4608

4609

4610

4611

4612

4613

4614

4615

4616

4617

4618

4619

4620

4621

4622

4623

4624

4625

4626

4627

4628

4629

4630

4631

4632

4633

4634

4635

4636

4637

4638

4639

4640

4641

4642

4643

4644

4645

4646

4647

4648

4649

4650

4651

4652

4653

4654

4655

4656

4657

4658

4659

4660

4661

4662

4663

4664

4665

4666

4667

4668

4669

4670

4671

4672

4673

4674

4675

4676

4677

4678

4679

4680

4681

4682

4683

4684

4685

4686

4687

4688

4689

4690

4691

4692

4693

4694

4695

4696

4697

4698

4699

4700

4701

4702

4703

4704

4705

4706

4707

4708

4709

4710

4711

4712

4713

4714

4715

4716

4717

4718

4719

4720

4721

4722

4723

4724

4725

4726

4727

4728

4729

4730

4731

4732

4733

4734

4735

4736

4737

4738

4739

4740

4741

4742

4743

4744

4745

4746

4747

4748

4749

4750

4751

4752

4753

4754

4755

4756

4757

4758

4759

4760

4761

4762

4763

4764

4765

4766

4767

4768

4769

4770

4771

4772

4773

4774

4775

4776

4777

4778

4779

4780

4781

4782

4783

4784

4785

4786

4787

4788

4789

4790

4791

4792

4793

4794

4795

4796

4797

4798

4799

4800

4801

4802

4803

4804

4805

4806

4807

4808

4809

4810

4811

4812

4813

4814

4815

4816

4817

4818

4819

4820

4821

4822

4823

4824

4825

4826

4827

4828

4829

4830

4831

4832

4833

4834

4835

4836

4837

4838

4839

4840

4841

4842

4843

4844

4845

4846

4847

4848

4849

4850

4851

4852

4853

4854

4855

4856

4857

4858

4859

4860

4861

4862

4863

4864

4865

4866

4867

4868

4869

4870

4871

4872

4873

4874

4875

4876

4877

4878

4879

4880

4881

4882

4883

4884

4885

4886

4887

4888

4889

4890

4891

4892

4893

4894

4895

4896

4897

4898

4899

4900

4901

4902

4903

4904

4905

4906

4907

4908

4909

4910

4911

4912

4913

4914

4915

4916

4917

4918

4919

4920

4921

4922

4923

4924

4925

4926

4927

4928

4929

4930

4931

4932

4933

4934

4935

4936

4937

4938

4939

4940

4941

4942

4943

4944

4945

4946

4947

4948

4949

4950

4951

4952

4953

4954

4955

4956

4957

4958

4959

4960

4961

4962

4963

4964

4965

4966

4967

4968

4969

4970

4971

4972

4973

4974

4975

4976

4977

4978

4979

4980

4981

4982

4983

4984

4985

4986

4987

4988

4989

4990

4991

4992

4993

4994

4995

4996

4997

4998

4999

5000

5001

5002

5003

5004

5005

5006

5007

5008

5009

5010

5011

5012

5013

5014

5015

5016

5017

5018

5019

5020

5021

5022

5023

5024

5025

5026

5027

5028

5029

5030

5031

5032

5033

5034

5035

5036

5037

5038

5039

5040

5041

5042

5043

5044

5045

5046

5047

5048

5049

5050

5051

5052

5053

5054

5055

5056

5057

5058

5059

5060

5061

5062

5063

5064

5065

5066

5067

5068

5069

5070

5071

5072

5073

5074

5075

5076

5077

5078

5079

5080

5081

5082

5083

5084

5085

5086

5087

5088

5089

5090

5091

5092

5093

5094

5095

5096

5097

5098

5099

5100

5101

5102

5103

5104

5105

5106

5107

5108

5109

5110

5111

5112

5113

5114

5115

5116

5117

5118

5119

5120

5121

5122

5123

5124

5125

5126

5127

5128

5129

5130

5131

5132

5133

5134

5135

5136

5137

5138

5139

5140

5141

5142

5143

5144

5145

5146

5147

5148

5149

5150

5151

5152

5153

5154

5155

5156

5157

5158

5159

5160

5161

5162

5163

5164

5165

5166

5167

5168

5169

5170

5171

5172

5173

5174

5175

5176

5177

5178

5179

5180

5181

5182

5183

5184

5185

5186

5187

5188

5189

5190

5191

5192

5193

5194

5195

5196

5197

5198

5199

5200

5201

5202

5203

5204

5205

5206

5207

5208

5209

5210

5211

5212

5213

5214

5215

5216

5217

5218

5219

5220

5221

5222

5223

5224

5225

5226

5227

5228

5229

5230

5231

5232

5233

5234

5235

5236

5237

5238

5239

5240

5241

5242

5243

5244

5245

5246

5247

5248

5249

5250

5251

5252

5253

5254

5255

5256

5257

5258

5259

5260

5261

5262

5263

5264

5265

5266

5267

5268

5269

5270

5271

5272

5273

5274

5275

5276

5277

5278

5279

5280

5281

5282

5283

5284

5285

5286

5287

5288

5289

5290

5291

5292

5293

5294

5295

5296

5297

5298

5299

5300

5301

5302

5303

5304

5305

5306

5307

5308

5309

5310

5311

5312

5313

5314

5315

5316

5317

5318

5319

5320

5321

5322

5323

5324

5325

5326

5327

5328

5329

5330

5331

5332

5333

5334

5335

5336

5337

5338

5339

5340

5341

5342

5343

5344

5345

5346

5347

5348

5349

5350

5351

5352

5353

5354

5355

5356

5357

5358

5359

5360

5361

5362

5363

5364

5365

5366

5367

5368

5369

5370

5371

5372

5373

5374

5375

5376

5377

5378

5379

5380

5381

5382

5383

5384

5385

5386

5387

5388

5389

5390

5391

5392

5393

5394

5395

5396

5397

5398

5399

5400

5401

5402

5403

5404

5405

5406

5407

5408

5409

5410

5411

5412

5413

5414

5415

5416

5417

5418

5419

5420

5421

5422

5423

5424

5425

5426

5427

5428

5429

5430

5431

5432

5433

5434

5435

5436

5437

5438

5439

5440

5441

5442

5443

5444

5445

5446

5447

5448

5449

5450

5451

5452

5453

5454

5455

5456

5457

5458

5459

5460

5461

5462

5463

5464

5465

5466

5467

5468

5469

5470

5471

5472

5473

5474

5475

5476

5477

5478

5479

5480

5481

5482

5483

5484

5485

5486

5487

5488

5489

5490

5491

5492

5493

5494

5495

5496

5497

5498

5499

5500

5501

5502

5503

5504

5505

5506

5507

5508

5509

5510

5511

5512

5513

5514

5515

5516

5517

5518

5519

5520

5521

5522

5523

5524

5525

5526

5527

5528

5529

5530

5531

5532

5533

5534

5535

5536

5537

5538

5539

5540

5541

5542

5543

5544

5545

5546

5547

5548

5549

5550

5551

5552

5553

5554

5555

5556

5557

5558

5559

5560

5561

5562

5563

5564

5565

5566

5567

5568

5569

5570

5571

5572

5573

5574

5575

5576

5577

5578

5579

5580

5581

5582

5583

5584

5585

5586

5587

5588

5589

5590

5591

5592

5593

5594

5595

5596

5597

5598

5599

5600

5601

5602

5603

5604

5605

5606

5607

5608

5609

5610

5611

5612

5613

5614

5615

5616

5617

5618

5619

5620

5621

5622

5623

5624

5625

5626

5627

5628

5629

5630

5631

5632

5633

5634

5635

5636

5637

5638

5639

5640

5641

5642

5643

5644

5645

5646

5647

5648

5649

5650

5651

5652

5653

5654

5655

5656

5657

5658

5659

5660

5661

5662

5663

5664

5665

5666

5667

5668

5669

5670

5671

5672

5673

5674

5675

5676

5677

5678

5679

5680

5681

5682

5683

5684

5685

5686

5687

5688

5689

5690

5691

5692

5693

5694

5695

5696

5697

5698

5699

5700

5701

5702

5703

5704

5705

5706

5707

5708

5709

5710

5711

5712

5713

5714

5715

5716

5717

5718

5719

5720

5721

5722

5723

5724

5725

5726

5727

5728

5729

5730

5731

5732

5733

5734

5735

5736

5737

5738

5739

5740

5741

5742

5743

5744

5745

5746

5747

5748

5749

5750

5751

5752

5753

5754

5755

5756

5757

5758

5759

5760

5761

5762

5763

5764

5765

5766

5767

5768

5769

5770

5771

5772

5773

5774

5775

5776

5777

5778

5779

5780

5781

5782

5783

5784

5785

5786

5787

5788

5789

5790

5791

5792

5793

5794

5795

5796

5797

5798

5799

5800

5801

5802

5803

5804

5805

5806

5807

5808

5809

5810

5811

5812

5813

5814

5815

5816

5817

5818

5819

5820

5821

5822

5823

5824

5825

5826

5827

5828

5829

5830

5831

5832

5833

5834

5835

5836

5837

5838

5839

5840

5841

5842

5843

5844

5845

5846

5847

5848

5849

5850

5851

5852

5853

5854

5855

5856

5857

5858

5859

5860

5861

5862

5863

5864

5865

5866

5867

5868

5869

5870

5871

5872

5873

5874

5875

5876

5877

5878

5879

5880

5881

5882

5883

5884

5885

5886

5887

5888

5889

5890

5891

5892

5893

5894

5895

5896

5897

5898

5899

5900

5901

5902

5903

5904

5905

5906

5907

5908

5909

5910

5911

5912

5913

5914

5915

5916

5917

5918

5919

5920

5921

5922

5923

5924

5925

5926

5927

5928

5929

5930

5931

5932

5933

5934

5935

5936

5937

5938

5939

5940

5941

5942

5943

5944

5945

5946

5947

5948

5949

5950

5951

5952

5953

5954

5955

5956

5957

5958

5959

5960

5961

5962

5963

5964

5965

5966

5967

5968

5969

5970

5971

5972

5973

5974

5975

5976

5977

5978

5979

5980

5981

5982

5983

5984

5985

5986

5987

5988

5989

5990

5991

5992

5993

5994

5995

5996

5997

5998

5999

6000

6001

6002

6003

6004

6005

6006

6007

6008

6009

6010

6011

6012

6013

6014

6015

6016

6017

6018

6019

6020

6021

6022

6023

6024

6025

6026

6027

6028

6029

6030

6031

6032

6033

6034

6035

6036

6037

6038

6039

6040

6041

6042

6043

6044

6045

6046

6047

6048

6049

6050

6051

6052

6053

6054

6055

6056

6057

6058

6059

6060

6061

6062

6063

6064

6065

6066

6067

6068

6069

6070

6071

6072

6073

6074

6075

6076

6077

6078

6079

6080

6081

6082

6083

6084

6085

6086

6087

6088

6089

6090

6091

6092

6093

6094

6095

6096

6097

6098

6099

6100

6101

6102

6103

6104

6105

6106

6107

6108

6109

6110

6111

6112

6113

6114

6115

6116

6117

6118

6119

6120

6121

6122

6123

6124

6125

6126

6127

6128

6129

6130

6131

6132

6133

6134

6135

6136

6137

6138

6139

6140

6141

6142

6143

6144

6145

6146

6147

6148

6149

6150

6151

6152

6153

6154

6155

6156

6157

6158

6159

6160

6161

6162

6163

6164

6165

6166

6167

6168

6169

6170

6171

6172

6173

6174

6175

6176

6177

6178

6179

6180

6181

6182

6183

6184

6185

6186

6187

6188

6189

6190

6191

6192

6193

6194

6195

6196

6197

6198

6199

6200

6201

6202

6203

6204

6205

6206

6207

6208

6209

6210

6211

6212

6213

6214

6215

6216

6217

6218

6219

6220

6221

6222

6223

6224

6225

6226

6227

6228

6229

6230

6231

6232

6233

6234

6235

6236

6237

6238

6239

6240

6241

6242

6243

6244

6245

6246

6247

6248

6249

6250

6251

6252

6253

6254

6255

6256

6257

6258

6259

6260

6261

6262

6263

6264

6265

6266

6267

6268

6269

6270

6271

6272

6273

6274

6275

6276

6277

6278

6279

6280

6281

6282

6283

6284

6285

6286

6287

6288

6289

6290

6291

6292

6293

6294

6295

6296

6297

6298

6299

6300

6301

6302

6303

6304

6305

6306

6307

6308

6309

6310

6311

6312

6313

6314

6315

6316

6317

6318

6319

6320

6321

6322

6323

6324

6325

6326

6327

6328

6329

6330

6331

6332

6333

6334

6335

6336

6337

6338

6339

6340

6341

6342

6343

6344

6345

6346

6347

6348

6349

6350

6351

6352

6353

6354

6355

6356

6357

6358

6359

6360

6361

6362

6363

6364

6365

6366

6367

6368

6369

6370

6371

6372

6373

6374

6375

6376

6377

6378

6379

6380

6381

6382

6383

6384

6385

6386

6387

6388

6389

6390

6391

6392

6393

6394

6395

6396

6397

6398

6399

6400

6401

6402

6403

6404

6405

6406

6407

6408

6409

6410

6411

6412

6413

6414

6415

6416

6417

6418

6419

6420

6421

6422

6423

6424

6425

6426

6427

6428

6429

6430

6431

6432

6433

6434

6435

6436

6437

6438

6439

6440

6441

6442

6443

6444

6445

6446

6447

6448

6449

6450

6451

6452

6453

6454

6455

6456

6457

6458

6459

6460

6461

6462

6463

6464

6465

6466

6467

6468

6469

6470

6471

6472

6473

6474

6475

6476

6477

6478

6479

6480

6481

6482

6483

6484

6485

6486

6487

6488

6489

6490

6491

6492

6493

6494

6495

6496

6497

6498

6499

6500

6501

6502

6503

6504

6505

6506

6507

6508

6509

6510

6511

6512

6513

6514

6515

6516

6517

6518

6519

6520

6521

6522

6523

6524

6525

6526

6527

6528

6529

6530

6531

6532

6533

6534

6535

6536

6537

6538

6539

6540

6541

6542

6543

6544

6545

6546

6547

6548

6549

6550

6551

6552

6553

6554

6555

6556

6557

6558

6559

6560

6561

6562

6563

6564

6565

6566

6567

6568

6569

6570

6571

6572

6573

6574

6575

6576

6577

6578

6579

6580

6581

6582

6583

6584

6585

6586

6587

6588

6589

6590

6591

6592

6593

6594

6595

6596

6597

6598

6599

6600

6601

6602

6603

6604

6605

6606

6607

6608

6609

6610

6611

6612

6613

6614

6615

6616

6617

6618

6619

6620

6621

6622

6623

6624

6625

6626

6627

6628

6629

6630

6631

6632

6633

6634

6635

6636

6637

6638

6639

6640

6641

6642

6643

6644

6645

6646

6647

6648

6649

6650

6651

6652

6653

6654

6655

6656

6657

6658

6659

6660

6661

6662

6663

6664

6665

6666

6667

6668

6669

6670

6671

6672

6673

6674

6675

6676

6677

6678

6679

6680

6681

6682

6683

6684

6685

6686

6687

6688

6689

6690

6691

6692

6693

6694

6695

6696

6697

6698

6699

6700

6701

6702

6703

6704

6705

6706

6707

6708

6709

6710

6711

6712

6713

6714

6715

6716

6717

6718

6719

6720

6721

6722

6723

6724

6725

6726

6727

6728

6729

6730

6731

6732

6733

6734

6735

6736

6737

6738

6739

6740

6741

6742

6743

6744

6745

6746

6747

6748

6749

6750

6751

6752

6753

6754

6755

6756

6757

6758

6759

6760

6761

6762

6763

6764

6765

6766

6767

6768

6769

6770

6771

6772

6773

6774

6775

6776

6777

6778

6779

6780

6781

6782

6783

6784

6785

6786

6787

6788

6789

6790

6791

6792

6793

6794

6795

6796

6797

6798

6799

6800

6801

6802

6803

6804

6805

6806

6807

6808

6809

6810

6811

6812

6813

6814

6815

6816

6817

6818

6819

6820

6821

6822

6823

6824

6825

6826

6827

6828

6829

6830

6831

6832

6833

6834

6835

6836

6837

6838

6839

6840

6841

6842

6843

6844

6845

6846

6847

6848

6849

6850

6851

6852

6853

6854

6855

6856

6857

6858

6859

6860

6861

6862

6863

6864

6865

6866

6867

6868

6869

6870

6871

6872

6873

6874

6875

6876

6877

6878

6879

6880

6881

6882

6883

6884

6885

6886

6887

6888

6889

6890

6891

6892

6893

6894

6895

6896

6897

6898

6899

6900

6901

6902

6903

6904

6905

6906

6907

6908

6909

6910

6911

6912

6913

6914

6915

6916

6917

6918

6919

6920

6921

6922

6923

6924

6925

6926

6927

6928

6929

6930

6931

6932

6933

6934

6935

6936

6937

6938

6939

6940

6941

6942

6943

6944

6945

6946

6947

6948

6949

6950

6951

6952

6953

6954

6955

6956

6957

6958

6959

6960

6961

6962

6963

6964

6965

6966

6967

6968

6969

6970

6971

6972

6973

6974

6975

6976

6977

6978

6979

6980

6981

6982

6983

6984

6985

6986

6987

6988

6989

6990

6991

6992

6993

6994

6995

6996

6997

6998

6999

7000

7001

7002

7003

7004

7005

7006

7007

7008

7009

7010

7011

7012

7013

7014

7015

7016

7017

7018

7019

7020

7021

7022

7023

7024

7025

7026

7027

7028

7029

7030

7031

7032

7033

7034

7035

7036

7037

7038

7039

7040

7041

7042

7043

7044

7045

7046

7047

7048

7049

7050

7051

7052

7053

7054

7055

7056

7057

7058

7059

7060

7061

7062

7063

7064

7065

7066

7067

7068

7069

7070

7071

7072

7073

7074

7075

7076

7077

7078

7079

7080

7081

7082

7083

7084

7085

7086

7087

7088

7089

7090

7091

7092

7093

7094

7095

7096

7097

7098

7099

7100

7101

7102

7103

7104

7105

7106

7107

7108

7109

7110

7111

7112

7113

7114

7115

7116

7117

7118

7119

7120

7121

7122

7123

7124

7125

7126

7127

7128

7129

7130

7131

7132

7133

7134

7135

7136

7137

7138

7139

7140

7141

7142

7143

7144

7145

7146

7147

7148

7149

7150

7151

7152

7153

7154

7155

7156

7157

7158

7159

7160

7161

7162

7163

7164

7165

7166

7167

7168

7169

7170

7171

7172

7173

7174

7175

7176

7177

7178

7179

7180

7181

7182

7183

7184

7185

7186

7187

7188

7189

7190

7191

7192

7193

7194

7195

7196

7197

7198

7199

7200

7201

7202

7203

7204

7205

7206

7207

7208

7209

7210

7211

7212

7213

7214

7215

7216

7217

7218

7219

7220

7221

7222

7223

7224

7225

7226

7227

7228

7229

7230

7231

7232

7233

7234

7235

7236

7237

7238

7239

7240

7241

7242

7243

7244

7245

7246

7247

7248

7249

7250

7251

7252

7253

7254

7255

7256

7257

7258

7259

7260

7261

7262

7263

7264

7265

7266

7267

7268

7269

7270

7271

7272

7273

7274

7275

7276

7277

7278

7279

7280

7281

7282

7283

7284

7285

7286

7287

7288

7289

7290

7291

7292

7293

7294

7295

7296

7297

7298

7299

7300

7301

7302

7303

7304

7305

7306

7307

7308

7309

7310

7311

7312

7313

7314

7315

7316

7317

7318

7319

7320

7321

7322

7323

7324

7325

7326

7327

7328

7329

7330

7331

7332

7333

7334

7335

7336

7337

7338

7339

7340

7341

7342

7343

7344

7345

7346

7347

7348

7349

7350

7351

7352

7353

7354

7355

7356

7357

7358

7359

7360

7361

7362

7363

7364

7365

7366

7367

7368

7369

7370

7371

7372

7373

7374

7375

7376

7377

7378

7379

7380

7381

7382

7383

7384

7385

7386

7387

7388

7389

7390

7391

7392

7393

7394

7395

7396

7397

7398

7399

7400

7401

7402

7403

7404

7405

7406

7407

7408

7409

7410

7411

7412

7413

7414

7415

7416

7417

7418

7419

7420

7421

7422

7423

7424

7425

7426

7427

7428

7429

7430

7431

7432

7433

7434

7435

7436

7437

7438

7439

7440

7441

7442

7443

7444

7445

7446

7447

7448

7449

7450

7451

7452

7453

7454

7455

7456

7457

7458

7459

7460

7461

7462

7463

7464

7465

7466

7467

7468

7469

7470

7471

7472

7473

7474

7475

7476

7477

7478

7479

7480

7481

7482

7483

7484

7485

7486

7487

7488

7489

7490

7491

7492

7493

7494

7495

7496

7497

7498

7499

7500

7501

7502

7503

7504

7505

7506

7507

7508

7509

7510

7511

7512

7513

7514

7515

7516

7517

7518

7519

7520

7521

7522

7523

7524

7525

7526

7527

7528

7529

7530

7531

7532

7533

7534

7535

7536

7537

7538

7539

7540

7541

7542

7543

7544

7545

7546

7547

7548

7549

7550

7551

7552

7553

7554

7555

7556

7557

7558

7559

7560

7561

7562

7563

7564

7565

7566

7567

7568

7569

7570

7571

7572

7573

7574

7575

7576

7577

7578

7579

7580

7581

7582

7583

7584

7585

7586

7587

7588

7589

7590

7591

7592

7593

7594

7595

7596

7597

7598

7599

7600

7601

7602

7603

7604

7605

7606

7607

7608

7609

7610

7611

7612

7613

7614

7615

7616

7617

7618

7619

7620

7621

7622

7623

7624

7625

7626

7627

7628

7629

7630

7631

7632

7633

7634

7635

7636

7637

7638

7639

7640

7641

7642

7643

7644

7645

7646

7647

7648

7649

7650

7651

7652

7653

7654

7655

7656

7657

7658

7659

7660

7661

7662

7663

7664

7665

7666

7667

7668

7669

7670

7671

7672

7673

7674

7675

7676

7677

7678

7679

7680

7681

7682

7683

7684

7685

7686

7687

7688

7689

7690

7691

7692

7693

7694

7695

7696

7697

7698

7699

7700

7701

7702

7703

7704

7705

7706

7707

7708

7709

7710

7711

7712

7713

7714

7715

7716

7717

7718

7719

7720

7721

7722

7723

7724

7725

7726

7727

7728

7729

7730

7731

7732

7733

7734

7735

7736

7737

7738

7739

7740

7741

7742

7743

7744

7745

7746

7747

7748

7749

7750

7751

7752

7753

7754

7755

7756

7757

7758

7759

7760

7761

7762

7763

7764

7765

7766

7767

7768

7769

7770

7771

7772

7773

7774

7775

7776

7777

7778

7779

7780

7781

7782

7783

7784

7785

7786

7787

7788

7789

7790

7791

7792

7793

7794

7795

7796

7797

7798

7799

7800

7801

7802

7803

7804

7805

7806

7807

7808

7809

7810

7811

7812

7813

7814

7815

7816

7817

7818

7819

7820

7821

7822

7823

7824

7825

7826

7827

7828

7829

7830

7831

7832

7833

7834

7835

7836

7837

7838

7839

7840

7841

7842

7843

7844

7845

7846

7847

7848

7849

7850

7851

7852

7853

7854

7855

7856

7857

7858

7859

7860

7861

7862

7863

7864

7865

7866

7867

7868

7869

7870

7871

7872

7873

7874

7875

7876

7877

7878

7879

7880

7881

7882

7883

7884

7885

7886

7887

7888

7889

7890

7891

7892

7893

7894

7895

7896

7897

7898

7899

7900

7901

7902

7903

7904

7905

7906

7907

7908

7909

7910

7911

7912

7913

7914

7915

7916

7917

7918

7919

7920

7921

7922

7923

7924

7925

7926

7927

7928

7929

7930

7931

7932

7933

7934

7935

7936

7937

7938

7939

7940

7941

7942

7943

7944

7945

7946

7947

7948

7949

7950

7951

7952

7953

7954

7955

7956

7957

7958

7959

7960

7961

7962

7963

7964

7965

7966

7967

7968

7969

7970

7971

7972

7973

7974

7975

7976

7977

7978

7979

7980

7981

7982

7983

7984

7985

7986

7987

7988

7989

7990

7991

7992

7993

7994

7995

7996

7997

7998

7999

8000

8001

8002

8003

8004

8005

8006

8007

8008

8009

8010

8011

8012

8013

8014

8015

8016

8017

8018

8019

8020

8021

8022

8023

8024

8025

8026

8027

8028

8029

8030

8031

8032

8033

8034

8035

8036

8037

8038

8039

8040

8041

8042

8043

8044

8045

8046

8047

8048

8049

8050

8051

8052

8053

8054

8055

8056

8057

8058

8059

8060

8061

8062

8063

8064

8065

8066

8067

8068

8069

8070

8071

8072

8073

8074

8075

8076

8077

8078

8079

8080

8081

8082

8083

8084

8085

8086

8087

8088

8089

8090

8091

8092

8093

8094

8095

8096

8097

8098

8099

8100

8101

8102

8103

8104

8105

8106

8107

8108

8109

8110

8111

8112

8113

8114

8115

8116

8117

8118

8119

8120

8121

8122

8123

8124

8125

8126

8127

8128

8129

8130

8131

8132

8133

8134

8135

8136

8137

8138

8139

8140

8141

8142

8143

8144

8145

8146

8147

8148

8149

8150

8151

8152

8153

8154

8155

8156

8157

8158

8159

8160

8161

8162

8163

8164

8165

8166

8167

8168

8169

8170

8171

8172

8173

8174

8175

8176

8177

8178

8179

8180

8181

8182

8183

8184

8185

8186

8187

8188

8189

8190

8191

8192

8193

8194

8195

8196

8197

8198

8199

8200

8201

8202

8203

8204

8205

8206

8207

8208

8209

8210

8211

8212

8213

8214

8215

8216

8217

8218

8219

8220

8221

8222

8223

8224

8225

8226

8227

8228

8229

8230

8231

8232

8233

8234

8235

8236

8237

8238

8239

8240

8241

8242

8243

8244

8245

8246

8247

8248

8249

8250

8251

8252

8253

8254

8255

8256

8257

8258

8259

8260

8261

8262

8263

8264

8265

8266

8267

8268

8269

8270

8271

8272

8273

8274

8275

8276

8277

8278

8279

8280

8281

8282

8283

8284

8285

8286

8287

8288

8289

8290

8291

8292

8293

8294

8295

8296

8297

8298

8299

8300

8301

8302

8303

8304

8305

8306

8307

8308

8309

8310

8311

8312

8313

8314

8315

8316

8317

8318

8319

8320

8321

8322

8323

8324

8325

8326

8327

8328

8329

8330

8331

8332

8333

8334

8335

8336

8337

8338

8339

8340

8341

8342

8343

8344

8345

8346

8347

8348

8349

8350

8351

8352

8353

8354

8355

8356

8357

8358

8359

8360

8361

8362

8363

8364

8365

8366

8367

8368

8369

8370

8371

8372

8373

8374

8375

8376

8377

8378

8379

8380

8381

8382

8383

8384

8385

8386

8387

8388

8389

8390

8391

8392

8393

8394

8395

8396

8397

8398

8399

8400

8401

8402

8403

8404

8405

8406

8407

8408

8409

8410

8411

8412

8413

8414

8415

8416

8417

8418

8419

8420

8421

8422

8423

8424

8425

8426

8427

8428

8429

8430

8431

8432

8433

8434

8435

8436

8437

8438

8439

8440

8441

8442

8443

8444

8445

8446

8447

8448

8449

8450

8451

8452

8453

8454

8455

8456

8457

8458

8459

8460

8461

8462

8463

8464

8465

8466

8467

8468

8469

8470

8471

8472

8473

8474

8475

8476

8477

8478

8479

8480

8481

8482

8483

8484

8485

8486

8487

8488

8489

8490

8491

8492

8493

8494

8495

8496

8497

8498

8499

8500

8501

8502

8503

8504

8505

8506

8507

8508

8509

8510

8511

8512

8513

8514

8515

8516

8517

8518

8519

8520

8521

8522

8523

8524

8525

8526

8527

8528

8529

8530

8531

8532

8533

8534

8535

8536

8537

8538

8539

8540

8541

8542

8543

8544

8545

8546

8547

8548

8549

8550

8551

8552

8553

8554

8555

8556

8557

8558

8559

8560

8561

8562

8563

8564

8565

8566

8567

8568

8569

8570

8571

8572

8573

8574

8575

8576

8577

8578

8579

8580

8581

8582

8583

8584

8585

8586

8587

8588

8589

8590

8591

8592

8593

8594

8595

8596

8597

8598

8599

8600

8601

8602

8603

8604

8605

8606

8607

8608

8609

8610

8611

8612

8613

8614

8615

8616

8617

8618

8619

8620

8621

8622

8623

8624

8625

8626

8627

8628

8629

8630

8631

8632

8633

8634

8635

8636

8637

8638

8639

8640

8641

8642

8643

8644

8645

8646

8647

8648

8649

8650

8651

8652

8653

8654

8655

8656

8657

8658

8659

8660

8661

8662

8663

8664

8665

8666

8667

8668

8669

8670

8671

8672

8673

8674

8675

8676

8677

8678

8679

8680

8681

8682

8683

8684

8685

8686

8687

8688

8689

8690

8691

8692

8693

8694

8695

8696

8697

8698

8699

8700

8701

8702

8703

8704

8705

8706

8707

8708

8709

8710

8711

8712

8713

8714

8715

8716

8717

8718

8719

8720

8721

8722

8723

8724

8725

8726

8727

8728

8729

8730

8731

8732

8733

8734

8735

8736

8737

8738

8739

8740

8741

8742

8743

8744

8745

8746

8747

8748

8749

8750

8751

8752

8753

8754

8755

8756

8757

8758

8759

8760

8761

8762

8763

8764

8765

8766

8767

8768

8769

8770

8771

8772

8773

8774

8775

8776

8777

8778

8779

8780

8781

8782

8783

8784

8785

8786

8787

8788

8789

8790

8791

8792

8793

8794

8795

8796

8797

8798

8799

8800

8801

8802

8803

8804

8805

8806

8807

8808

8809

8810

8811

8812

8813

8814

8815

8816

8817

8818

8819

8820

8821

8822

8823

8824

8825

8826

8827

8828

8829

8830

8831

8832

8833

8834

8835

8836

8837

8838

8839

8840

8841

8842

8843

8844

8845

8846

8847

8848

8849

8850

8851

8852

8853

8854

8855

8856

8857

8858

8859

8860

8861

8862

8863

8864

8865

8866

8867

8868

8869

8870

8871

8872

8873

8874

8875

8876

8877

8878

8879

8880

8881

8882

8883

8884

8885

8886

8887

8888

8889

8890

8891

8892

8893

8894

8895

8896

8897

8898

8899

8900

8901

8902

8903

8904

8905

8906

8907

8908

8909

8910

8911

8912

8913

8914

8915

8916

8917

8918

8919

8920

8921

8922

8923

8924

8925

8926

8927

8928

8929

8930

8931

8932

8933

8934

8935

8936

8937

8938

8939

8940

8941

8942

8943

8944

8945

8946

8947

8948

8949

8950

8951

8952

8953

8954

8955

8956

8957

8958

8959

8960

8961

8962

8963

8964

8965

8966

8967

8968

8969

8970

8971

8972

8973

8974

8975

8976

8977

8978

8979

8980

8981

8982

8983

8984

8985

8986

8987

8988

8989

8990

8991

8992

8993

8994

8995

8996

8997

8998

8999

9000

9001

9002

9003

9004

9005

9006

9007

9008

9009

9010

9011

9012

9013

9014

9015

9016

9017

9018

9019

9020

9021

9022

9023

9024

9025

9026

9027

9028

9029

9030

9031

9032

9033

9034

9035

9036

9037

9038

9039

9040

9041

9042

9043

9044

9045

9046

9047

9048

9049

9050

9051

9052

9053

9054

9055

9056

9057

9058

9059

9060

9061

9062

9063

9064

9065

9066

9067

9068

9069

9070

9071

9072

9073

9074

9075

9076

9077

9078

9079

9080

9081

9082

9083

9084

9085

9086

9087

9088

9089

9090

9091

9092

9093

9094

9095

9096

9097

9098

9099

9100

9101

9102

9103

9104

9105

9106

9107

9108

9109

9110

9111

9112

9113

9114

9115

9116

9117

9118

9119

9120

9121

9122

9123

9124

9125

9126

9127

9128

9129

9130

9131

9132

9133

9134

9135

9136

9137

9138

9139

9140

9141

9142

9143

9144

9145

9146

9147

9148

9149

9150

9151

9152

9153

9154

9155

9156

9157

9158

9159

9160

9161

9162

9163

9164

9165

9166

9167

9168

9169

9170

9171

9172

9173

9174

9175

9176

9177

9178

9179

9180

9181

9182

9183

9184

9185

9186

9187

9188

9189

9190

9191

9192

9193

9194

9195

9196

9197

9198

9199

9200

9201

9202

9203

9204

9205

9206

9207

9208

9209

9210

9211

9212

9213

9214

9215

9216

9217

9218

9219

9220

9221

9222

9223

9224

9225

9226

9227

9228

9229

9230

9231

9232

9233

9234

9235

9236

9237

9238

9239

9240

9241

9242

9243

9244

9245

9246

9247

9248

9249

9250

9251

9252

9253

9254

9255

9256

9257

9258

9259

9260

9261

9262

9263

9264

9265

9266

9267

9268

9269

9270

9271

9272

9273

9274

9275

9276

9277

9278

9279

9280

9281

9282

9283

9284

9285

9286

9287

9288

9289

9290

9291

9292

9293

9294

9295

9296

9297

9298

9299

9300

9301

9302

9303

9304

9305

9306

9307

9308

9309

9310

9311

9312

9313

9314

9315

9316

9317

9318

9319

9320

9321

9322

9323

9324

9325

9326

9327

9328

9329

9330

9331

9332

9333

9334

9335

9336

9337

9338

9339

9340

9341

9342

9343

9344

9345

9346

9347

9348

9349

9350

9351

9352

9353

9354

9355

9356

9357

9358

9359

9360

9361

9362

9363

9364

9365

9366

9367

9368

9369

9370

9371

9372

9373

9374

9375

9376

9377

9378

9379

9380

9381

9382

9383

9384

9385

9386

9387

9388

9389

9390

9391

9392

9393

9394

9395

9396

9397

9398

9399

9400

9401

9402

9403

9404

9405

9406

9407

9408

9409

9410

9411

9412

9413

9414

9415

9416

9417

9418

9419

9420

9421

9422

9423

9424

9425

9426

9427

9428

9429

9430

9431

9432

9433

9434

9435

9436

9437

9438

9439

9440

9441

9442

9443

9444

9445

9446

9447

9448

9449

9450

9451

9452

9453

9454

9455

9456

9457

9458

9459

9460

9461

9462

9463

9464

9465

9466

9467

9468

9469

9470

9471

9472

9473

9474

9475

9476

9477

9478

9479

9480

9481

9482

9483

9484

9485

9486

9487

9488

9489

9490

9491

9492

9493

9494

9495

9496

9497

9498

9499

9500

9501

9502

9503

9504

9505

9506

9507

9508

9509

9510

9511

9512

9513

9514

9515

9516

9517

9518

9519

9520

9521

9522

9523

9524

9525

9526

9527

9528

9529

9530

9531

9532

9533

9534

9535

9536

9537

9538

9539

9540

9541

9542

9543

9544

9545

9546

9547

9548

9549

9550

9551

9552

9553

9554

9555

9556

9557

9558

9559

9560

9561

9562

9563

9564

9565

9566

9567

9568

9569

9570

9571

9572

9573

9574

9575

9576

9577

9578

9579

9580

9581

9582

9583

9584

9585

9586

9587

9588

9589

9590

9591

9592

9593

9594

9595

9596

9597

9598

9599

9600

9601

9602

9603

9604

9605

9606

9607

9608

9609

9610

9611

9612

9613

9614

9615

9616

9617

9618

9619

9620

9621

9622

9623

9624

9625

9626

9627

9628

9629

9630

9631

9632

9633

9634

9635

9636

9637

9638

9639

9640

9641

9642

9643

9644

9645

9646

9647

9648

9649

9650

9651

9652

9653

9654

9655

9656

9657

9658

9659

9660

9661

9662

9663

9664

9665

9666

9667

9668

9669

9670

9671

9672

9673

9674

9675

9676

9677

9678

9679

9680

9681

9682

9683

9684

9685

9686

9687

9688

9689

9690

9691

9692

9693

9694

9695

9696

9697

9698

9699

9700

9701

9702

9703

9704

9705

9706

9707

9708

9709

9710

9711

9712

9713

9714

9715

9716

9717

9718

9719

9720

9721

9722

9723

9724

9725

9726

9727

9728

9729

9730

9731

9732

9733

9734

9735

9736

9737

9738

9739

9740

9741

9742

9743

9744

9745

9746

9747

9748

9749

9750

9751

9752

9753

9754

9755

9756

9757

9758

9759

9760

9761

9762

9763

9764

9765

9766

9767

9768

9769

9770

9771

9772

9773

9774

9775

9776

9777

9778

9779

9780

9781

9782

9783

9784

9785

9786

9787

9788

9789

9790

9791

9792

9793

9794

9795

9796

9797

9798

9799

9800

9801

9802

9803

9804

9805

9806

9807

9808

9809

9810

9811

9812

9813

9814

9815

9816

9817

9818

9819

9820

9821

9822

9823

9824

9825

9826

9827

9828

9829

9830

9831

9832

9833

9834

9835

9836

9837

9838

9839

9840

9841

9842

9843

9844

9845

9846

9847

9848

9849

9850

9851

9852

9853

9854

9855

9856

9857

9858

9859

9860

9861

9862

9863

9864

9865

9866

9867

9868

9869

9870

9871

9872

9873

9874

9875

9876

9877

9878

9879

9880

9881

9882

9883

9884

9885

9886

9887

9888

9889

9890

9891

9892

9893

9894

9895

9896

9897

9898

9899

9900

9901

9902

9903

9904

9905

9906

9907

9908

9909

9910

9911

9912

9913

9914

9915

9916

9917

9918

9919

9920

9921

9922

9923

9924

9925

9926

9927

9928

9929

9930

9931

9932

9933

9934

9935

9936

9937

9938

9939

9940

9941

9942

9943

9944

9945

9946

9947

9948

9949

9950

9951

9952

9953

9954

9955

9956

9957

9958

9959

9960

9961

9962

9963

9964

9965

9966

9967

9968

9969

9970

9971

9972

9973

9974

9975

9976

9977

9978

9979

9980

9981

9982

9983

9984

9985

9986

9987

9988

9989

9990

9991

9992

9993

9994

9995

9996

9997

9998

9999

10000

10001

10002

10003

10004

10005

10006

10007

10008

10009

10010

10011

10012

10013

10014

10015

10016

10017

10018

10019

10020

10021

10022

10023

10024

10025

10026

10027

10028

10029

10030

10031

10032

10033

10034

10035

10036

10037

10038

10039

10040

10041

10042

10043

10044

10045

10046

10047

10048

10049

10050

10051

10052

10053

10054

10055

10056

10057

10058

10059

10060

10061

10062

10063

10064

10065

10066

10067

10068

10069

10070

10071

10072

10073

10074

10075

10076

10077

10078

10079

10080

10081

10082

10083

10084

10085

10086

10087

10088

10089

10090

10091

10092

10093

10094

10095

10096

10097

10098

10099

10100

10101

10102

10103

10104

10105

10106

10107

10108

10109

10110

10111

10112

10113

10114

10115

10116

10117

10118

10119

10120

10121

10122

10123

10124

10125

10126

10127

10128

10129

10130

10131

10132

10133

10134

10135

10136

10137

10138

10139

10140

10141

10142

10143

10144

10145

10146

10147

10148

10149

10150

10151

10152

10153

10154

10155

10156

10157

10158

10159

10160

10161

10162

10163

10164

10165

10166

10167

10168

10169

10170

10171

10172

10173

10174

10175

10176

10177

10178

10179

10180

10181

10182

10183

10184

10185

10186

10187

10188

10189

10190

10191

10192

10193

10194

10195

10196

10197

10198

10199

10200

10201

10202

10203

10204

10205

10206

10207

10208

10209

10210

10211

10212

10213

10214

10215

10216

10217

10218

10219

10220

10221

10222

10223

10224

10225

10226

10227

10228

10229

10230

10231

10232

10233

10234

10235

10236

10237

10238

10239

10240

10241

10242

10243

10244

10245

10246

10247

10248

10249

10250

10251

10252

10253

10254

10255

10256

10257

10258

10259

10260

10261

10262

10263

10264

10265

10266

10267

10268

10269

10270

10271

10272

10273

10274

10275

10276

10277

10278

10279

10280

10281

10282

10283

10284

10285

10286

10287

10288

10289

10290

10291

10292

10293

10294

10295

10296

10297

10298

10299

10300

10301

10302

10303

10304

10305

10306

10307

10308

10309

10310

10311

10312

10313

10314

10315

10316

10317

10318

10319

10320

10321

10322

10323

10324

10325

10326

10327

10328

10329

10330

10331

10332

10333

10334

10335

10336

10337

10338

10339

10340

10341

10342

10343

10344

10345

10346

10347

10348

10349

10350

10351

10352

10353

10354

10355

10356

10357

10358

10359

10360

10361

10362

10363

10364

10365

10366

10367

10368

10369

10370

10371

10372

10373

10374

10375

10376

10377

10378

10379

10380

10381

10382

10383

10384

10385

10386

10387

10388

10389

10390

10391

10392

10393

10394

10395

10396

10397

10398

10399

10400

10401

10402

10403

10404

10405

10406

10407

10408

10409

10410

10411

10412

10413

10414

10415

10416

10417

10418

10419

10420

10421

10422

10423

10424

10425

10426

10427

10428

10429

10430

10431

10432

10433

10434

10435

10436

10437

10438

10439

10440

10441

10442

10443

10444

10445

10446

10447

10448

10449

10450

10451

10452

10453

10454

10455

10456

10457

10458

10459

10460

10461

10462

10463

10464

10465

10466

10467

10468

10469

10470

10471

10472

10473

10474

10475

10476

10477

10478

10479

10480

10481

10482

10483

10484

10485

10486

10487

10488

10489

10490

10491

10492

10493

10494

10495

10496

10497

10498

10499

10500

10501

10502

10503

10504

10505

10506

10507

10508

10509

10510

10511

10512

10513

10514

10515

10516

10517

10518

10519

10520

10521

10522

10523

10524

10525

10526

10527

10528

10529

10530

10531

10532

10533

10534

10535

10536

10537

10538

10539

10540

10541

10542

10543

10544

10545

10546

10547

10548

10549

10550

10551

10552

10553

10554

10555

10556

10557

10558

10559

10560

10561

10562

10563

10564

10565

10566

10567

10568

10569

10570

10571

10572

10573

10574

10575

10576

10577

10578

10579

10580

10581

10582

10583

10584

10585

10586

10587

10588

10589

10590

10591

10592

10593

10594

10595

10596

10597

10598

10599

10600

10601

10602

10603

10604

10605

10606

10607

10608

10609

10610

10611

10612

10613

10614

10615

10616

10617

10618

10619

10620

10621

10622

10623

10624

10625

10626

10627

10628

10629

10630

10631

10632

10633

10634

10635

10636

10637

10638

10639

10640

10641

10642

10643

10644

10645

10646

10647

10648

10649

10650

10651

10652

10653

10654

10655

10656

10657

10658

10659

10660

10661

10662

10663

10664

10665

10666

10667

10668

10669

10670

10671

10672

10673

10674

10675

10676

10677

10678

10679

10680

10681

10682

10683

10684

10685

10686

10687

10688

10689

10690

10691

10692

10693

10694

10695

10696

10697

10698

10699

10700

10701

10702

10703

10704

10705

10706

10707

10708

10709

10710

10711

10712

10713

10714

10715

10716

10717

10718

10719

10720

10721

10722

10723

10724

10725

10726

10727

10728

10729

10730

10731

10732

10733

10734

10735

10736

10737

10738

10739

10740

10741

10742

10743

10744

10745

10746

10747

10748

10749

10750

10751

10752

10753

10754

10755

10756

10757

10758

10759

10760

10761

10762

10763

10764

10765

10766

10767

10768

10769

10770

10771

10772

10773

10774

10775

10776

10777

10778

10779

10780

10781

10782

10783

10784

10785

10786

10787

10788

10789

10790

10791

10792

10793

10794

10795

10796

10797

10798

10799

10800

10801

10802

10803

10804

10805

10806

10807

10808

10809

10810

10811

10812

10813

10814

10815

10816

10817

10818

10819

10820

10821

10822

10823

10824

10825

10826

10827

10828

10829

10830

10831

10832

10833

10834

10835

10836

10837

10838

10839

10840

10841

10842

10843

10844

10845

10846

10847

10848

10849

10850

10851

10852

10853

10854

10855

10856

10857

10858

10859

10860

10861

10862

10863

10864

10865

10866

10867

10868

10869

10870

10871

10872

10873

10874

10875

10876

10877

10878

10879

10880

10881

10882

10883

10884

10885

10886

10887

10888

10889

10890

10891

10892

10893

10894

10895

10896

10897

10898

10899

10900

10901

10902

10903

10904

10905

10906

10907

10908

10909

10910

10911

10912

10913

10914

10915

10916

10917

10918

10919

10920

10921

10922

10923

10924

10925

10926

10927

10928

10929

10930

10931

10932

10933

10934

10935

10936

10937

10938

10939

10940

10941

10942

10943

10944

10945

10946

10947

10948

10949

10950

10951

10952

10953

10954

10955

10956

10957

10958

10959

10960

10961

10962

10963

10964

10965

10966

10967

10968

10969

10970

10971

10972

10973

10974

10975

10976

10977

10978

10979

10980

10981

10982

10983

10984

10985

10986

10987

10988

10989

10990

10991

10992

10993

10994

10995

10996

10997

10998

10999

11000

11001

11002

11003

11004

11005

11006

11007

11008

11009

11010

11011

11012

11013

11014

11015

11016

11017

11018

11019

11020

11021

11022

11023

11024

11025

11026

11027

11028

11029

11030

11031

11032

11033

11034

11035

11036

11037

11038

11039

11040

11041

11042

11043

11044

11045

11046

11047

11048

11049

11050

11051

11052

11053

11054

11055

11056

11057

11058

11059

11060

11061

11062

11063

11064

11065

11066

11067

11068

11069

11070

11071

11072

11073

11074

11075

11076

11077

11078

11079

11080

11081

11082

11083

11084

11085

11086

11087

11088

11089

11090

11091

11092

11093

11094

11095

11096

11097

11098

11099

11100

11101

11102

11103

11104

11105

11106

11107

11108

11109

11110

11111

11112

11113

11114

11115

11116

11117

11118

11119

11120

11121

11122

11123

11124

11125

11126

11127

11128

11129

11130

11131

11132

11133

11134

11135

11136

11137

11138

11139

11140

11141

11142

11143

11144

11145

11146

11147

11148

11149

11150

11151

11152

11153

11154

11155

11156

11157

11158

11159

11160

11161

11162

11163

11164

11165

11166

11167

11168

11169

11170

11171

11172

11173

11174

11175

11176

11177

11178

11179

11180

11181

11182

11183

11184

11185

11186

11187

11188

11189

11190

11191

11192

11193

11194

11195

11196

11197

11198

11199

11200

11201

11202

11203

11204

11205

11206

11207

11208

11209

11210

11211

11212

11213

11214

11215

11216

11217

11218

11219

11220

11221

11222

11223

11224

11225

11226

11227

11228

11229

11230

11231

11232

11233

11234

11235

11236

11237

11238

11239

11240

11241

11242

11243

11244

11245

11246

11247

11248

11249

11250

11251

11252

11253

11254

11255

11256

11257

11258

11259

11260

11261

11262

11263

11264

11265

11266

11267

11268

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

r""" 

Number Fields 

 

AUTHORS: 

 

- William Stein (2004, 2005): initial version 

 

- Steven Sivek (2006-05-12): added support for relative extensions 

 

- William Stein (2007-09-04): major rewrite and documentation 

 

- Robert Bradshaw (2008-10): specified embeddings into ambient fields 

 

- Simon King (2010-05): Improve coercion from GAP 

 

- Jeroen Demeyer (2010-07, 2011-04): Upgrade PARI (:trac:`9343`, :trac:`10430`, :trac:`11130`) 

 

- Robert Harron (2012-08): added is_CM(), complex_conjugation(), and 

maximal_totally_real_subfield() 

 

- Christian Stump (2012-11): added conversion to universal cyclotomic field 

 

- Julian Rueth (2014-04-03): absolute number fields are unique parents 

 

- Vincent Delecroix (2015-02): comparisons/floor/ceil using embeddings 

 

- Kiran Kedlaya (2016-05): relative number fields hash based on relative polynomials 

 

- Peter Bruin (2016-06): make number fields fully satisfy unique representation 

 

- John Jones (2017-07): improve check for is_galois(), add is_abelian(), building on work in patch by Chris Wuthrich 

 

 

.. note:: 

 

Unlike in PARI/GP, class group computations *in Sage* do *not* by default 

assume the Generalized Riemann Hypothesis. To do class groups computations 

not provably correctly you must often pass the flag ``proof=False`` to 

functions or call the function ``proof.number_field(False)``. It can easily 

take 1000's of times longer to do computations with ``proof=True`` (the 

default). 

 

This example follows one in the Magma reference manual:: 

 

sage: K.<y> = NumberField(x^4 - 420*x^2 + 40000) 

sage: z = y^5/11; z 

420/11*y^3 - 40000/11*y 

sage: R.<y> = PolynomialRing(K) 

sage: f = y^2 + y + 1 

sage: L.<a> = K.extension(f); L 

Number Field in a with defining polynomial y^2 + y + 1 over its base field 

sage: KL.<b> = NumberField([x^4 - 420*x^2 + 40000, x^2 + x + 1]); KL 

Number Field in b0 with defining polynomial x^4 - 420*x^2 + 40000 over its base field 

 

We do some arithmetic in a tower of relative number fields:: 

 

sage: K.<cuberoot2> = NumberField(x^3 - 2) 

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

sage: S.<sqrt2> = L.extension(x^2 - 2) 

sage: S 

Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field 

sage: sqrt2 * cuberoot3 

cuberoot3*sqrt2 

sage: (sqrt2 + cuberoot3)^5 

(20*cuberoot3^2 + 15*cuberoot3 + 4)*sqrt2 + 3*cuberoot3^2 + 20*cuberoot3 + 60 

sage: cuberoot2 + cuberoot3 

cuberoot3 + cuberoot2 

sage: cuberoot2 + cuberoot3 + sqrt2 

sqrt2 + cuberoot3 + cuberoot2 

sage: (cuberoot2 + cuberoot3 + sqrt2)^2 

(2*cuberoot3 + 2*cuberoot2)*sqrt2 + cuberoot3^2 + 2*cuberoot2*cuberoot3 + cuberoot2^2 + 2 

sage: cuberoot2 + sqrt2 

sqrt2 + cuberoot2 

sage: a = S(cuberoot2); a 

cuberoot2 

sage: a.parent() 

Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field 

 

.. warning:: 

 

Doing arithmetic in towers of relative fields that depends on 

canonical coercions is currently VERY SLOW. It is much better to 

explicitly coerce all elements into a common field, then do 

arithmetic with them there (which is quite fast). 

""" 

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

# Copyright (C) 2004, 2005, 2006, 2007 William Stein <wstein@gmail.com> 

# 2014 Julian Rueth <julian.rueth@fsfe.org> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# as published by the Free Software Foundation; either version 2 of 

# the License, or (at your option) any later version. 

# http://www.gnu.org/licenses/ 

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

 

from __future__ import absolute_import, print_function 

from six.moves import range 

from six import integer_types 

 

from sage.structure.parent_gens import localvars 

from sage.misc.cachefunc import cached_method 

 

import sage.libs.ntl.all as ntl 

import sage.interfaces.gap 

 

import sage.rings.complex_field 

from sage.rings.polynomial.polynomial_element import is_Polynomial 

import sage.rings.real_mpfr 

import sage.rings.real_mpfi 

import sage.rings.complex_double 

import sage.rings.real_double 

import sage.rings.real_lazy 

 

from sage.rings.finite_rings.integer_mod import mod 

 

from sage.misc.fast_methods import WithEqualityById 

from sage.misc.functional import is_odd, lift 

 

from sage.misc.misc_c import prod 

from sage.categories.homset import End 

from sage.rings.all import Infinity 

from sage.categories.number_fields import NumberFields 

 

import sage.rings.ring 

from sage.misc.latex import latex_variable_name 

from sage.misc.misc import union 

 

from .unit_group import UnitGroup 

from .class_group import ClassGroup 

from .class_group import SClassGroup 

 

from sage.structure.element import is_Element 

from sage.structure.sequence import Sequence 

 

from sage.structure.category_object import normalize_names 

import sage.structure.parent_gens 

import sage.structure.coerce_exceptions 

 

from sage.structure.proof.proof import get_flag 

from . import maps 

from . import structure 

from . import number_field_morphisms 

from itertools import count 

from builtins import zip 

from sage.misc.superseded import deprecated_function_alias 

 

_NumberFields = NumberFields() 

 

def is_NumberFieldHomsetCodomain(codomain): 

""" 

Returns whether ``codomain`` is a valid codomain for a number 

field homset. This is used by NumberField._Hom_ to determine 

whether the created homsets should be a 

:class:`sage.rings.number_field.morphism.NumberFieldHomset`. 

 

EXAMPLES: 

 

This currently accepts any parent (CC, RR, ...) in :class:`Fields`:: 

 

sage: from sage.rings.number_field.number_field import is_NumberFieldHomsetCodomain 

sage: is_NumberFieldHomsetCodomain(QQ) 

True 

sage: is_NumberFieldHomsetCodomain(NumberField(x^2 + 1, 'x')) 

True 

sage: is_NumberFieldHomsetCodomain(ZZ) 

False 

sage: is_NumberFieldHomsetCodomain(3) 

False 

sage: is_NumberFieldHomsetCodomain(MatrixSpace(QQ, 2)) 

False 

sage: is_NumberFieldHomsetCodomain(InfinityRing) 

False 

 

Question: should, for example, QQ-algebras be accepted as well? 

 

Caveat: Gap objects are not (yet) in :class:`Fields`, and therefore 

not accepted as number field homset codomains:: 

 

sage: is_NumberFieldHomsetCodomain(gap.Rationals) 

False 

""" 

from sage.categories.fields import Fields 

return codomain in Fields() 

 

from sage.rings.number_field.morphism import RelativeNumberFieldHomomorphism_from_abs 

 

def proof_flag(t): 

""" 

Used for easily determining the correct proof flag to use. 

 

Returns t if t is not None, otherwise returns the system-wide 

proof-flag for number fields (default: True). 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import proof_flag 

sage: proof_flag(True) 

True 

sage: proof_flag(False) 

False 

sage: proof_flag(None) 

True 

sage: proof_flag("banana") 

'banana' 

""" 

return get_flag(t, "number_field") 

 

 

import weakref 

 

from sage.misc.latex import latex 

 

import sage.arith.all as arith 

import sage.rings.rational_field as rational_field 

import sage.rings.integer_ring as integer_ring 

import sage.rings.infinity as infinity 

from sage.rings.rational import Rational 

from sage.rings.integer import Integer 

import sage.rings.polynomial.polynomial_element as polynomial_element 

import sage.rings.complex_field 

import sage.groups.abelian_gps.abelian_group 

import sage.rings.complex_interval_field 

 

from sage.structure.parent_gens import ParentWithGens 

from sage.structure.factory import UniqueFactory 

from . import number_field_element 

from . import number_field_element_quadratic 

from .number_field_ideal import is_NumberFieldIdeal, NumberFieldFractionalIdeal 

from sage.libs.pari.all import pari, pari_gen 

 

from sage.rings.rational_field import QQ 

from sage.rings.integer_ring import ZZ 

RIF = sage.rings.real_mpfi.RealIntervalField() 

CIF = sage.rings.complex_interval_field.ComplexIntervalField() 

from sage.rings.real_double import RDF 

from sage.rings.complex_double import CDF 

from sage.rings.real_lazy import RLF, CLF 

 

def NumberField(polynomial, name=None, check=True, names=None, embedding=None, latex_name=None, assume_disc_small=False, maximize_at_primes=None, structure=None): 

r""" 

Return *the* number field (or tower of number fields) defined by the 

irreducible ``polynomial``. 

 

INPUT: 

 

- ``polynomial`` - a polynomial over `\QQ` or a number field, or a list 

of such polynomials. 

- ``name`` - a string or a list of strings, the names of the generators 

- ``check`` - a boolean (default: ``True``); do type checking and 

irreducibility checking. 

- ``embedding`` - ``None``, an element, or a list of elements, the 

images of the generators in an ambient field (default: ``None``) 

- ``latex_name`` - ``None``, a string, or a list of strings (default: 

``None``), how the generators are printed for latex output 

- ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, 

assume that no square of a prime greater than PARI's primelimit 

(which should be 500000); only applies for absolute fields at 

present. 

- ``maximize_at_primes`` -- ``None`` or a list of primes (default: 

``None``); if not ``None``, then the maximal order is computed by 

maximizing only at the primes in this list, which completely avoids 

having to factor the discriminant, but of course can lead to wrong 

results; only applies for absolute fields at present. 

- ``structure`` -- ``None``, a list or an instance of 

:class:`structure.NumberFieldStructure` (default: ``None``), 

internally used to pass in additional structural information, e.g., 

about the field from which this field is created as a subfield. 

 

EXAMPLES:: 

 

sage: z = QQ['z'].0 

sage: K = NumberField(z^2 - 2,'s'); K 

Number Field in s with defining polynomial z^2 - 2 

sage: s = K.0; s 

s 

sage: s*s 

2 

sage: s^2 

2 

 

Constructing a relative number field:: 

 

sage: K.<a> = NumberField(x^2 - 2) 

sage: R.<t> = K[] 

sage: L.<b> = K.extension(t^3+t+a); L 

Number Field in b with defining polynomial t^3 + t + a over its base field 

sage: L.absolute_field('c') 

Number Field in c with defining polynomial x^6 + 2*x^4 + x^2 - 2 

sage: a*b 

a*b 

sage: L(a) 

a 

sage: L.lift_to_base(b^3 + b) 

-a 

 

Constructing another number field:: 

 

sage: k.<i> = NumberField(x^2 + 1) 

sage: R.<z> = k[] 

sage: m.<j> = NumberField(z^3 + i*z + 3) 

sage: m 

Number Field in j with defining polynomial z^3 + i*z + 3 over its base field 

 

Number fields are globally unique:: 

 

sage: K.<a> = NumberField(x^3 - 5) 

sage: a^3 

5 

sage: L.<a> = NumberField(x^3 - 5) 

sage: K is L 

True 

 

Equality of number fields depends on the variable name of the 

defining polynomial:: 

 

sage: x = polygen(QQ, 'x'); y = polygen(QQ, 'y') 

sage: k.<a> = NumberField(x^2 + 3) 

sage: m.<a> = NumberField(y^2 + 3) 

sage: k 

Number Field in a with defining polynomial x^2 + 3 

sage: m 

Number Field in a with defining polynomial y^2 + 3 

sage: k == m 

False 

 

In case of conflict of the generator name with the name given by the preparser, the name given by the preparser takes precedence:: 

 

sage: K.<b> = NumberField(x^2 + 5, 'a'); K 

Number Field in b with defining polynomial x^2 + 5 

 

One can also define number fields with specified embeddings, may be used 

for arithmetic and deduce relations with other number fields which would 

not be valid for an abstract number field. :: 

 

sage: K.<a> = NumberField(x^3-2, embedding=1.2) 

sage: RR.coerce_map_from(K) 

Composite map: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Real Field with 53 bits of precision 

Defn: Generic morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Real Lazy Field 

Defn: a -> 1.259921049894873? 

then 

Conversion via _mpfr_ method map: 

From: Real Lazy Field 

To: Real Field with 53 bits of precision 

sage: RR(a) 

1.25992104989487 

sage: 1.1 + a 

2.35992104989487 

sage: b = 1/(a+1); b 

1/3*a^2 - 1/3*a + 1/3 

sage: RR(b) 

0.442493334024442 

sage: L.<b> = NumberField(x^6-2, embedding=1.1) 

sage: L(a) 

b^2 

sage: a + b 

b^2 + b 

 

Note that the image only needs to be specified to enough precision 

to distinguish roots, and is exactly computed to any needed 

precision:: 

 

sage: RealField(200)(a) 

1.2599210498948731647672106072782283505702514647015079800820 

 

One can embed into any other field:: 

 

sage: K.<a> = NumberField(x^3-2, embedding=CC.gen()-0.6) 

sage: CC(a) 

-0.629960524947436 + 1.09112363597172*I 

sage: L = Qp(5) 

sage: f = polygen(L)^3 - 2 

sage: K.<a> = NumberField(x^3-2, embedding=f.roots()[0][0]) 

sage: a + L(1) 

4 + 2*5^2 + 2*5^3 + 3*5^4 + 5^5 + 4*5^6 + 2*5^8 + 3*5^9 + 4*5^12 + 4*5^14 + 4*5^15 + 3*5^16 + 5^17 + 5^18 + 2*5^19 + O(5^20) 

sage: L.<b> = NumberField(x^6-x^2+1/10, embedding=1) 

sage: K.<a> = NumberField(x^3-x+1/10, embedding=b^2) 

sage: a+b 

b^2 + b 

sage: CC(a) == CC(b)^2 

True 

sage: K.coerce_embedding() 

Generic morphism: 

From: Number Field in a with defining polynomial x^3 - x + 1/10 

To: Number Field in b with defining polynomial x^6 - x^2 + 1/10 

Defn: a -> b^2 

 

The ``QuadraticField`` and ``CyclotomicField`` constructors 

create an embedding by default unless otherwise specified:: 

 

sage: K.<zeta> = CyclotomicField(15) 

sage: CC(zeta) 

0.913545457642601 + 0.406736643075800*I 

sage: L.<sqrtn3> = QuadraticField(-3) 

sage: K(sqrtn3) 

2*zeta^5 + 1 

sage: sqrtn3 + zeta 

2*zeta^5 + zeta + 1 

 

Comparison depends on the (real) embedding specified (or the one selected by default). 

Note that the codomain of the embedding must be `QQbar` or `AA` for this to work 

(see :trac:`20184`):: 

 

sage: N.<g> = NumberField(x^3+2,embedding=1) 

sage: 1 < g 

False 

sage: g > 1 

False 

sage: RR(g) 

-1.25992104989487 

 

If no embedding is specified or is complex, the comparison is not returning something 

meaningful.:: 

 

sage: N.<g> = NumberField(x^3+2) 

sage: 1 < g 

False 

sage: g > 1 

True 

 

Since SageMath 6.9, number fields may be defined by polynomials 

that are not necessarily integral or monic. The only notable 

practical point is that in the PARI interface, a monic integral 

polynomial defining the same number field is computed and used:: 

 

sage: K.<a> = NumberField(2*x^3 + x + 1) 

sage: K.pari_polynomial() 

x^3 - x^2 - 2 

 

Elements and ideals may be converted to and from PARI as follows:: 

 

sage: pari(a) 

Mod(-1/2*y^2 + 1/2*y, y^3 - y^2 - 2) 

sage: K(pari(a)) 

a 

sage: I = K.ideal(a); I 

Fractional ideal (a) 

sage: I.pari_hnf() 

[1, 0, 0; 0, 1, 0; 0, 0, 1/2] 

sage: K.ideal(I.pari_hnf()) 

Fractional ideal (a) 

 

Here is an example where the field has non-trivial class group:: 

 

sage: L.<b> = NumberField(3*x^2 - 1/5) 

sage: L.pari_polynomial() 

x^2 - 15 

sage: J = L.primes_above(2)[0]; J 

Fractional ideal (2, 15*b + 1) 

sage: J.pari_hnf() 

[2, 1; 0, 1] 

sage: L.ideal(J.pari_hnf()) 

Fractional ideal (2, 15*b + 1) 

 

An example involving a variable name that defines a function in 

PARI:: 

 

sage: theta = polygen(QQ, 'theta') 

sage: M.<z> = NumberField([theta^3 + 4, theta^2 + 3]); M 

Number Field in z0 with defining polynomial theta^3 + 4 over its base field 

 

TESTS:: 

 

sage: x = QQ['x'].gen() 

sage: y = ZZ['y'].gen() 

sage: K = NumberField(x^3 + x + 3, 'a'); K 

Number Field in a with defining polynomial x^3 + x + 3 

sage: K.defining_polynomial().parent() 

Univariate Polynomial Ring in x over Rational Field 

 

:: 

 

sage: L = NumberField(y^3 + y + 3, 'a'); L 

Number Field in a with defining polynomial y^3 + y + 3 

sage: L.defining_polynomial().parent() 

Univariate Polynomial Ring in y over Rational Field 

 

:: 

 

sage: W1 = NumberField(x^2+1,'a') 

sage: K.<x> = CyclotomicField(5)[] 

sage: W.<a> = NumberField(x^2 + 1); W 

Number Field in a with defining polynomial x^2 + 1 over its base field 

 

The following has been fixed in :trac:`8800`:: 

 

sage: P.<x> = QQ[] 

sage: K.<a> = NumberField(x^3-5,embedding=0) 

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

sage: F, R = L.construction() 

sage: F(R) == L # indirect doctest 

True 

 

Check that :trac:`11670` has been fixed:: 

 

sage: K.<a> = NumberField(x^2 - x - 1) 

sage: loads(dumps(K)) is K 

True 

sage: K.<a> = NumberField(x^3 - x - 1) 

sage: loads(dumps(K)) is K 

True 

sage: K.<a> = CyclotomicField(7) 

sage: loads(dumps(K)) is K 

True 

 

Another problem that was found while working on :trac:`11670`, 

``maximize_at_primes`` and ``assume_disc_small`` were lost when pickling:: 

 

sage: K.<a> = NumberField(x^3-2, assume_disc_small=True, maximize_at_primes=[2], latex_name='\\alpha', embedding=2^(1/3)) 

sage: L = loads(dumps(K)) 

sage: L._assume_disc_small 

True 

sage: L._maximize_at_primes 

(2,) 

 

It is an error not to specify the generator:: 

 

sage: K = NumberField(x^2-2) 

Traceback (most recent call last): 

... 

TypeError: You must specify the name of the generator. 

 

Check that we can construct morphisms to matrix space (:trac:`23418`):: 

 

sage: t = polygen(QQ) 

sage: K = NumberField(t^4 - 2, 'a') 

sage: K.hom([K.gen().matrix()]) 

Ring morphism: 

From: Number Field in a with defining polynomial x^4 - 2 

To: Full MatrixSpace of 4 by 4 dense matrices over Rational Field 

Defn: a |--> [0 1 0 0] 

[0 0 1 0] 

[0 0 0 1] 

[2 0 0 0] 

""" 

if names is not None: 

name = names 

if isinstance(polynomial, (list,tuple)): 

return NumberFieldTower(polynomial, names=name, check=check, embeddings=embedding, latex_names=latex_name, assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structures=structure) 

 

return NumberField_version2(polynomial=polynomial, name=name, check=check, embedding=embedding, latex_name=latex_name, assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structure=structure) 

 

class NumberFieldFactory(UniqueFactory): 

r""" 

Factory for number fields. 

 

This should usually not be called directly, use :meth:`NumberField` 

instead. 

 

INPUT: 

 

- ``polynomial`` - a polynomial over `\QQ` or a number field. 

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

- ``check`` - a boolean (default: ``True``); do type checking and 

irreducibility checking. 

- ``embedding`` - ``None`` or an element, the images of the generator 

in an ambient field (default: ``None``) 

- ``latex_name`` - ``None`` or a string (default: ``None``), how the 

generator is printed for latex output 

- ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, 

assume that no square of a prime greater than PARI's primelimit 

(which should be 500000); only applies for absolute fields at 

present. 

- ``maximize_at_primes`` -- ``None`` or a list of primes (default: 

``None``); if not ``None``, then the maximal order is computed by 

maximizing only at the primes in this list, which completely avoids 

having to factor the discriminant, but of course can lead to wrong 

results; only applies for absolute fields at present. 

- ``structure`` -- ``None`` or an instance of 

:class:`structure.NumberFieldStructure` (default: ``None``), 

internally used to pass in additional structural information, e.g., 

about the field from which this field is created as a subfield. 

 

TESTS:: 

 

sage: from sage.rings.number_field.number_field import NumberFieldFactory 

sage: nff = NumberFieldFactory("number_field_factory") 

sage: R.<x> = QQ[] 

sage: nff(x^2 + 1, name='a', check=False, embedding=None, latex_name=None, assume_disc_small=False, maximize_at_primes=None, structure=None) 

Number Field in a with defining polynomial x^2 + 1 

 

Pickling preserves the ``structure()`` of a number field:: 

 

sage: K.<a> = QuadraticField(2) 

sage: L.<b> = K.change_names() 

sage: M = loads(dumps(L)) 

sage: M.structure() 

(Isomorphism given by variable name change map: 

From: Number Field in b with defining polynomial x^2 - 2 

To: Number Field in a with defining polynomial x^2 - 2, 

Isomorphism given by variable name change map: 

From: Number Field in a with defining polynomial x^2 - 2 

To: Number Field in b with defining polynomial x^2 - 2) 

 

""" 

def create_key_and_extra_args(self, polynomial, name, check, embedding, latex_name, assume_disc_small, maximize_at_primes, structure): 

r""" 

Create a unique key for the number field specified by the parameters. 

 

TESTS:: 

 

sage: from sage.rings.number_field.number_field import NumberFieldFactory 

sage: nff = NumberFieldFactory("number_field_factory") 

sage: R.<x> = QQ[] 

sage: nff.create_key_and_extra_args(x^2+1, name='a', check=False, embedding=None, latex_name=None, assume_disc_small=False, maximize_at_primes=None, structure=None) 

((Rational Field, x^2 + 1, ('a',), None, 'a', None, False, None), 

{'check': False}) 

 

""" 

if name is None: 

raise TypeError("You must specify the name of the generator.") 

name = normalize_names(1, name) 

 

if not is_Polynomial(polynomial): 

try: 

polynomial = polynomial.polynomial(QQ) 

except (AttributeError, TypeError): 

raise TypeError("polynomial (=%s) must be a polynomial." % polynomial) 

 

# convert polynomial to a polynomial over a field 

polynomial = polynomial.change_ring(polynomial.base_ring().fraction_field()) 

 

# normalize embedding 

if isinstance(embedding, (list,tuple)): 

if len(embedding) != 1: 

raise TypeError("embedding must be a list of length 1") 

embedding = embedding[0] 

if embedding is not None: 

x = number_field_morphisms.root_from_approx(polynomial, embedding) 

embedding = (x.parent(), x) 

 

# normalize latex_name 

if isinstance(latex_name, (list, tuple)): 

if len(latex_name) != 1: 

raise TypeError("latex_name must be a list of length 1") 

latex_name = latex_name[0] 

 

if latex_name is None: 

latex_name = latex_variable_name(name[0]) 

 

if maximize_at_primes is not None: 

maximize_at_primes = tuple(maximize_at_primes) 

 

# normalize structure 

if isinstance(structure, (list, tuple)): 

if len(structure) != 1: 

raise TypeError("structure must be a list of length 1") 

structure = structure[0] 

 

return (polynomial.base_ring(), polynomial, name, embedding, latex_name, maximize_at_primes, assume_disc_small, structure), {"check":check} 

 

def create_object(self, version, key, check): 

r""" 

Create the unique number field defined by ``key``. 

 

TESTS:: 

 

sage: from sage.rings.number_field.number_field import NumberFieldFactory 

sage: nff = NumberFieldFactory("number_field_factory") 

sage: R.<x> = QQ[] 

sage: nff.create_object(None, (QQ, x^2 + 1, ('a',), None, None, None, False, None), check=False) 

Number Field in a with defining polynomial x^2 + 1 

 

""" 

base, polynomial, name, embedding, latex_name, maximize_at_primes, assume_disc_small, structure = key 

 

if isinstance(base, NumberField_generic): 

from sage.rings.number_field.number_field_rel import NumberField_relative 

# Relative number fields do not support embeddings. 

return NumberField_relative(base, polynomial, name[0], latex_name, 

check=check, embedding=None, 

structure=structure) 

if polynomial.degree() == 2: 

return NumberField_quadratic(polynomial, name, latex_name, check, embedding, assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structure=structure) 

else: 

return NumberField_absolute(polynomial, name, latex_name, check, embedding, assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structure=structure) 

 

NumberField_version2 = NumberFieldFactory("sage.rings.number_field.number_field.NumberField_version2") 

 

def NumberFieldTower(polynomials, names, check=True, embeddings=None, latex_names=None, assume_disc_small=False, maximize_at_primes=None, structures=None): 

""" 

Create the tower of number fields defined by the polynomials in the list 

``polynomials``. 

 

INPUT: 

 

- ``polynomials`` - a list of polynomials. Each entry must be polynomial 

which is irreducible over the number field generated by the roots of the 

following entries. 

- ``names`` - a list of strings or a string, the names of the generators of 

the relative number fields. If a single string, then names are generated 

from that string. 

- ``check`` - a boolean (default: ``True``), whether to check that the 

polynomials are irreducible 

- ``embeddings`` - a list of elements or ``None`` (default: ``None``), 

embeddings of the relative number fields in an ambient field. 

- ``latex_names`` - a list of strings or ``None`` (default: ``None``), names 

used to print the generators for latex output. 

- ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, 

assume that no square of a prime greater than PARI's primelimit 

(which should be 500000); only applies for absolute fields at 

present. 

- ``maximize_at_primes`` -- ``None`` or a list of primes (default: 

``None``); if not ``None``, then the maximal order is computed by 

maximizing only at the primes in this list, which completely avoids 

having to factor the discriminant, but of course can lead to wrong 

results; only applies for absolute fields at present. 

- ``structures`` -- ``None`` or a list (default: ``None``), internally used 

to provide additional information about the number field such as the 

field from which it was created. 

 

OUTPUT: 

 

Returns the relative number field generated by a root of the first entry of 

``polynomials`` over the relative number field generated by root of the 

second entry of ``polynomials`` ... over the number field over which the 

last entry of ``polynomials`` is defined. 

 

EXAMPLES:: 

 

sage: k.<a,b,c> = NumberField([x^2 + 1, x^2 + 3, x^2 + 5]); k # indirect doctest 

Number Field in a with defining polynomial x^2 + 1 over its base field 

sage: a^2 

-1 

sage: b^2 

-3 

sage: c^2 

-5 

sage: (a+b+c)^2 

(2*b + 2*c)*a + 2*c*b - 9 

 

The Galois group is a product of 3 groups of order 2:: 

 

sage: k.galois_group(type="pari") 

Galois group PARI group [8, 1, 3, "E(8)=2[x]2[x]2"] of degree 8 of the Number Field in a with defining polynomial x^2 + 1 over its base field 

 

Repeatedly calling base_field allows us to descend the internally 

constructed tower of fields:: 

 

sage: k.base_field() 

Number Field in b with defining polynomial x^2 + 3 over its base field 

sage: k.base_field().base_field() 

Number Field in c with defining polynomial x^2 + 5 

sage: k.base_field().base_field().base_field() 

Rational Field 

 

In the following example the second polynomial is reducible over 

the first, so we get an error:: 

 

sage: v = NumberField([x^3 - 2, x^3 - 2], names='a') 

Traceback (most recent call last): 

... 

ValueError: defining polynomial (x^3 - 2) must be irreducible 

 

We mix polynomial parent rings:: 

 

sage: k.<y> = QQ[] 

sage: m = NumberField([y^3 - 3, x^2 + x + 1, y^3 + 2], 'beta') 

sage: m 

Number Field in beta0 with defining polynomial y^3 - 3 over its base field 

sage: m.base_field () 

Number Field in beta1 with defining polynomial x^2 + x + 1 over its base field 

 

A tower of quadratic fields:: 

 

sage: K.<a> = NumberField([x^2 + 3, x^2 + 2, x^2 + 1]) 

sage: K 

Number Field in a0 with defining polynomial x^2 + 3 over its base field 

sage: K.base_field() 

Number Field in a1 with defining polynomial x^2 + 2 over its base field 

sage: K.base_field().base_field() 

Number Field in a2 with defining polynomial x^2 + 1 

 

A bigger tower of quadratic fields:: 

 

sage: K.<a2,a3,a5,a7> = NumberField([x^2 + p for p in [2,3,5,7]]); K 

Number Field in a2 with defining polynomial x^2 + 2 over its base field 

sage: a2^2 

-2 

sage: a3^2 

-3 

sage: (a2+a3+a5+a7)^3 

((6*a5 + 6*a7)*a3 + 6*a7*a5 - 47)*a2 + (6*a7*a5 - 45)*a3 - 41*a5 - 37*a7 

 

The function can also be called by name:: 

 

sage: NumberFieldTower([x^2 + 1, x^2 + 2], ['a','b']) 

Number Field in a with defining polynomial x^2 + 1 over its base field 

""" 

try: 

names = normalize_names(len(polynomials), names) 

except IndexError: 

names = normalize_names(1, names) 

if len(polynomials) > 1: 

names = ['%s%s'%(names[0], i) for i in range(len(polynomials))] 

 

if embeddings is None: 

embeddings = [None] * len(polynomials) 

if latex_names is None: 

latex_names = [None] * len(polynomials) 

if structures is None: 

structures = [None] * len(polynomials) 

 

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

raise TypeError("polynomials must be a list or tuple") 

 

if len(polynomials) == 0: 

return QQ 

if len(polynomials) == 1: 

return NumberField(polynomials[0], names=names, check=check, embedding=embeddings[0], latex_name=latex_names[0], assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structure=structures[0]) 

 

# create the relative number field defined by f over the tower defined by polynomials[1:] 

f = polynomials[0] 

name = names[0] 

w = NumberFieldTower(polynomials[1:], names=names[1:], check=check, embeddings=embeddings[1:], latex_names=latex_names[1:], assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structures=structures[1:]) 

var = f.variable_name() if is_Polynomial(f) else 'x' 

 

R = w[var] # polynomial ring 

return w.extension(R(f), name, check=check, embedding=embeddings[0], structure=structures[0]) # currently, extension does not accept assume_disc_small, or maximize_at_primes 

 

def QuadraticField(D, name='a', check=True, embedding=True, latex_name='sqrt', **args): 

r""" 

Return a quadratic field obtained by adjoining a square root of 

`D` to the rational numbers, where `D` is not a 

perfect square. 

 

INPUT: 

 

- ``D`` - a rational number 

 

- ``name`` - variable name (default: 'a') 

 

- ``check`` - bool (default: True) 

 

- ``embedding`` - bool or square root of D in an 

ambient field (default: True) 

 

- ``latex_name`` - latex variable name (default: \sqrt{D}) 

 

 

OUTPUT: A number field defined by a quadratic polynomial. Unless 

otherwise specified, it has an embedding into `\RR` or 

`\CC` by sending the generator to the positive 

or upper-half-plane root. 

 

EXAMPLES:: 

 

sage: QuadraticField(3, 'a') 

Number Field in a with defining polynomial x^2 - 3 

sage: K.<theta> = QuadraticField(3); K 

Number Field in theta with defining polynomial x^2 - 3 

sage: RR(theta) 

1.73205080756888 

sage: QuadraticField(9, 'a') 

Traceback (most recent call last): 

... 

ValueError: D must not be a perfect square. 

sage: QuadraticField(9, 'a', check=False) 

Number Field in a with defining polynomial x^2 - 9 

 

Quadratic number fields derive from general number fields. 

 

:: 

 

sage: from sage.rings.number_field.number_field import is_NumberField 

sage: type(K) 

<class 'sage.rings.number_field.number_field.NumberField_quadratic_with_category'> 

sage: is_NumberField(K) 

True 

 

Quadratic number fields are cached:: 

 

sage: QuadraticField(-11, 'a') is QuadraticField(-11, 'a') 

True 

 

By default, quadratic fields come with a nice latex representation:: 

 

sage: K.<a> = QuadraticField(-7) 

sage: latex(K) 

\Bold{Q}(\sqrt{-7}) 

sage: latex(a) 

\sqrt{-7} 

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

-\frac{1}{8} \sqrt{-7} + \frac{1}{8} 

sage: K.latex_variable_name() 

'\\sqrt{-7}' 

 

We can provide our own name as well:: 

 

sage: K.<a> = QuadraticField(next_prime(10^10), latex_name=r'\sqrt{D}') 

sage: 1+a 

a + 1 

sage: latex(1+a) 

\sqrt{D} + 1 

sage: latex(QuadraticField(-1, 'a', latex_name=None).gen()) 

a 

 

The name of the generator does not interfere with Sage preparser, see :trac:`1135`:: 

 

sage: K1 = QuadraticField(5, 'x') 

sage: K2.<x> = QuadraticField(5) 

sage: K3.<x> = QuadraticField(5, 'x') 

sage: K1 is K2 

True 

sage: K1 is K3 

True 

sage: K1 

Number Field in x with defining polynomial x^2 - 5 

 

 

Note that, in presence of two different names for the generator, 

the name given by the preparser takes precedence:: 

 

sage: K4.<y> = QuadraticField(5, 'x'); K4 

Number Field in y with defining polynomial x^2 - 5 

sage: K1 == K4 

False 

 

TESTS:: 

 

sage: QuadraticField(-11, 'a') is QuadraticField(-11, 'a', latex_name='Z') 

False 

sage: QuadraticField(-11, 'a') is QuadraticField(-11, 'a', latex_name=None) 

False 

""" 

D = QQ(D) 

if check: 

if D.is_square(): 

raise ValueError("D must not be a perfect square.") 

R = QQ['x'] 

f = R([-D, 0, 1]) 

if embedding is True: 

if D > 0: 

embedding = RLF(D).sqrt() 

else: 

embedding = CLF(D).sqrt() 

if latex_name == 'sqrt': 

latex_name = r'\sqrt{%s}' % D 

return NumberField(f, name, check=False, embedding=embedding, latex_name=latex_name, **args) 

 

def is_AbsoluteNumberField(x): 

""" 

Return True if x is an absolute number field. 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import is_AbsoluteNumberField 

sage: is_AbsoluteNumberField(NumberField(x^2+1,'a')) 

True 

sage: is_AbsoluteNumberField(NumberField([x^3 + 17, x^2+1],'a')) 

False 

 

The rationals are a number field, but they're not of the absolute 

number field class. 

 

:: 

 

sage: is_AbsoluteNumberField(QQ) 

False 

""" 

return isinstance(x, NumberField_absolute) 

 

def is_QuadraticField(x): 

r""" 

Return True if x is of the quadratic *number* field type. 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import is_QuadraticField 

sage: is_QuadraticField(QuadraticField(5,'a')) 

True 

sage: is_QuadraticField(NumberField(x^2 - 5, 'b')) 

True 

sage: is_QuadraticField(NumberField(x^3 - 5, 'b')) 

False 

 

A quadratic field specially refers to a number field, not a finite 

field:: 

 

sage: is_QuadraticField(GF(9,'a')) 

False 

""" 

return isinstance(x, NumberField_quadratic) 

 

class CyclotomicFieldFactory(UniqueFactory): 

r""" 

Return the `n`-th cyclotomic field, where n is a positive integer, 

or the universal cyclotomic field if ``n==0``. 

 

For the documentation of the universal cyclotomic field, see 

:class:`~sage.rings.universal_cyclotomic_field.UniversalCyclotomicField`. 

 

INPUT: 

 

- ``n`` - a nonnegative integer, default:``0`` 

 

- ``names`` - name of generator (optional - defaults to zetan) 

 

- ``bracket`` - Defines the brackets in the case of ``n==0``, and 

is ignored otherwise. Can be any even length string, with ``"()"`` being the default. 

 

- ``embedding`` - bool or n-th root of unity in an 

ambient field (default True) 

 

EXAMPLES: 

 

If called without a parameter, we get the :class:`universal cyclotomic 

field<sage.rings.universal_cyclotomic_field.UniversalCyclotomicField>`:: 

 

sage: CyclotomicField() 

Universal Cyclotomic Field 

 

We create the `7`\th cyclotomic field 

`\QQ(\zeta_7)` with the default generator name. 

 

:: 

 

sage: k = CyclotomicField(7); k 

Cyclotomic Field of order 7 and degree 6 

sage: k.gen() 

zeta7 

 

The default embedding sends the generator to the complex primitive 

`n^{th}` root of unity of least argument. 

 

:: 

 

sage: CC(k.gen()) 

0.623489801858734 + 0.781831482468030*I 

 

Cyclotomic fields are of a special type. 

 

:: 

 

sage: type(k) 

<class 'sage.rings.number_field.number_field.NumberField_cyclotomic_with_category'> 

 

We can specify a different generator name as follows. 

 

:: 

 

sage: k.<z7> = CyclotomicField(7); k 

Cyclotomic Field of order 7 and degree 6 

sage: k.gen() 

z7 

 

The `n` must be an integer. 

 

:: 

 

sage: CyclotomicField(3/2) 

Traceback (most recent call last): 

... 

TypeError: no conversion of this rational to integer 

 

The degree must be nonnegative. 

 

:: 

 

sage: CyclotomicField(-1) 

Traceback (most recent call last): 

... 

ValueError: n (=-1) must be a positive integer 

 

The special case `n=1` does *not* return the rational 

numbers:: 

 

sage: CyclotomicField(1) 

Cyclotomic Field of order 1 and degree 1 

 

Due to their default embedding into `\CC`, 

cyclotomic number fields are all compatible. 

 

:: 

 

sage: cf30 = CyclotomicField(30) 

sage: cf5 = CyclotomicField(5) 

sage: cf3 = CyclotomicField(3) 

sage: cf30.gen() + cf5.gen() + cf3.gen() 

zeta30^6 + zeta30^5 + zeta30 - 1 

sage: cf6 = CyclotomicField(6) ; z6 = cf6.0 

sage: cf3 = CyclotomicField(3) ; z3 = cf3.0 

sage: cf3(z6) 

zeta3 + 1 

sage: cf6(z3) 

zeta6 - 1 

sage: cf9 = CyclotomicField(9) ; z9 = cf9.0 

sage: cf18 = CyclotomicField(18) ; z18 = cf18.0 

sage: cf18(z9) 

zeta18^2 

sage: cf9(z18) 

-zeta9^5 

sage: cf18(z3) 

zeta18^3 - 1 

sage: cf18(z6) 

zeta18^3 

sage: cf18(z6)**2 

zeta18^3 - 1 

sage: cf9(z3) 

zeta9^3 

""" 

def create_key(self, n=0, names=None, embedding=True): 

r""" 

Create the unique key for the cyclotomic field specified by the 

parameters. 

 

TESTS:: 

 

sage: CyclotomicField.create_key() 

(0, None, True) 

""" 

n = ZZ(n) 

if n < 0: 

raise ValueError("n (=%s) must be a positive integer" % n) 

if n > 0: 

bracket = None 

if embedding is True: 

embedding = (CLF, (2 * CLF.pi() * CLF.gen() / n).exp()) 

elif embedding is not None: 

x = number_field_morphisms.root_from_approx(QQ['x'].cyclotomic_polynomial(n), embedding) 

embedding = (x.parent(), x) 

if names is None: 

names = "zeta%s"%n 

names = normalize_names(1, names) 

 

return n, names, embedding 

 

def create_object(self, version, key, **extra_args): 

r""" 

Create the unique cyclotomic field defined by ``key``. 

 

TESTS:: 

 

sage: CyclotomicField.create_object(None, (0, None, True)) 

Universal Cyclotomic Field 

""" 

n, names, embedding = key 

if n == 0: 

from sage.rings.universal_cyclotomic_field import UniversalCyclotomicField 

return UniversalCyclotomicField() 

else: 

return NumberField_cyclotomic(n, names, embedding=embedding) 

 

CyclotomicField = CyclotomicFieldFactory("sage.rings.number_field.number_field.CyclotomicField") 

 

def is_CyclotomicField(x): 

""" 

Return True if x is a cyclotomic field, i.e., of the special 

cyclotomic field class. This function does not return True for a 

number field that just happens to be isomorphic to a cyclotomic 

field. 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import is_CyclotomicField 

sage: is_CyclotomicField(NumberField(x^2 + 1,'zeta4')) 

False 

sage: is_CyclotomicField(CyclotomicField(4)) 

True 

sage: is_CyclotomicField(CyclotomicField(1)) 

True 

sage: is_CyclotomicField(QQ) 

False 

sage: is_CyclotomicField(7) 

False 

""" 

return isinstance(x, NumberField_cyclotomic) 

 

from . import number_field_base 

 

is_NumberField = number_field_base.is_NumberField 

 

class NumberField_generic(WithEqualityById, number_field_base.NumberField): 

""" 

Generic class for number fields defined by an irreducible 

polynomial over `\\QQ`. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 - 2); K 

Number Field in a with defining polynomial x^3 - 2 

sage: TestSuite(K).run() 

 

TESTS:: 

 

sage: k.<a> = NumberField(x^3 + 2); m.<b> = NumberField(x^3 + 2) 

sage: k == QQ 

False 

sage: k.<a> = NumberField(x^3 + 2); m.<a> = NumberField(x^3 + 2) 

sage: k is m 

True 

sage: loads(dumps(k)) is k 

True 

 

sage: x = QQ['x'].gen() 

sage: y = ZZ['y'].gen() 

sage: K = NumberField(x^3 + x + 3, 'a'); K 

Number Field in a with defining polynomial x^3 + x + 3 

sage: K.defining_polynomial().parent() 

Univariate Polynomial Ring in x over Rational Field 

 

sage: L = NumberField(y^3 + y + 3, 'a'); L 

Number Field in a with defining polynomial y^3 + y + 3 

sage: L.defining_polynomial().parent() 

Univariate Polynomial Ring in y over Rational Field 

sage: L == K 

False 

 

sage: NumberField(ZZ['x'].0^4 + 23, 'a') == NumberField(ZZ['y'].0^4 + 23, 'a') 

False 

sage: NumberField(ZZ['x'].0^4 + 23, 'a') == NumberField(QQ['y'].0^4 + 23, 'a') 

False 

sage: NumberField(QQ['x'].0^4 + 23, 'a') == NumberField(QQ['y'].0^4 + 23, 'a') 

False 

 

sage: x = polygen(QQ); y = ZZ['y'].gen() 

sage: NumberField(x^3 + x + 5, 'a') == NumberField(y^3 + y + 5, 'a') 

False 

sage: NumberField(x^3 + x + 5, 'a') == NumberField(y^4 + y + 5, 'a') 

False 

sage: NumberField(x^3 + x + 5, 'a') == NumberField(x^3 + x + 5, 'b') 

False 

sage: QuadraticField(2, 'a', embedding=2) == QuadraticField(2, 'a', embedding=-2) 

False 

 

sage: K.<a> = QuadraticField(2) 

sage: R.<x> = K[] 

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

sage: M.<b> = L.absolute_field() 

sage: M == L 

False 

sage: M['x'] == L['x'] 

False 

 

sage: R.<x> = QQ[] 

sage: R.<y> = QQ[] 

sage: K.<a> = NumberField(x^2+1) 

sage: L.<a> = NumberField(y^2+1) 

sage: K == L 

False 

sage: hash(K) == hash(L) 

False 

 

Two relative number fields which are isomorphic as absolute 

fields, but which are not presented the same way, are not 

considered equal (see :trac:`18942`):: 

 

sage: F.<omega> = NumberField(x^2 + x + 1) 

sage: y = polygen(F) 

sage: K = F.extension(y^3 + 3*omega + 2, 'alpha') 

sage: L = F.extension(y^3 - 3*omega - 1, 'alpha') 

sage: K == L 

False 

sage: K.is_isomorphic(L) 

True 

sage: hash(K) == hash(L) 

False 

 

This example illustrates the issue resolved in :trac:`18942`:: 

 

sage: F.<omega> = NumberField(x^2+x+1) 

sage: xx = polygen(F) 

sage: ps = [p for p, _ in F(7).factor()] 

sage: for mu in ps: 

....: K = F.extension(xx^3 - mu, 'alpha') 

....: print(K.defining_polynomial().roots(K)) 

[(alpha, 1), ((-omega - 1)*alpha, 1), (omega*alpha, 1)] 

[(alpha, 1), (omega*alpha, 1), ((-omega - 1)*alpha, 1)] 

sage: for mu in ps: 

....: K = F.extension(xx^3 - mu, 'alpha') 

....: print(K.defining_polynomial().roots(K)) 

[(alpha, 1), ((-omega - 1)*alpha, 1), (omega*alpha, 1)] 

[(alpha, 1), (omega*alpha, 1), ((-omega - 1)*alpha, 1)] 

 

This example was suggested on sage-nt; see :trac:`18942`:: 

 

sage: G = DirichletGroup(80) 

sage: for chi in G: 

....: D = ModularSymbols(chi, 2, -1).cuspidal_subspace().new_subspace().decomposition() 

....: for f in D: 

....: elt = f.q_eigenform(10, 'alpha')[3] 

....: assert elt.is_integral() 

 

""" 

def __init__(self, polynomial, name, latex_name, 

check=True, embedding=None, category=None, 

assume_disc_small=False, maximize_at_primes=None, structure=None): 

""" 

Create a number field. 

 

EXAMPLES:: 

 

sage: NumberField(x^97 - 19, 'a') 

Number Field in a with defining polynomial x^97 - 19 

 

The defining polynomial must be irreducible:: 

 

sage: K.<a> = NumberField(x^2 - 1) 

Traceback (most recent call last): 

... 

ValueError: defining polynomial (x^2 - 1) must be irreducible 

 

If you use check=False, you avoid checking irreducibility of the 

defining polynomial, which can save time. 

 

:: 

 

sage: K.<a> = NumberField(x^2 - 1, check=False) 

 

It can also be dangerous:: 

 

sage: (a-1)*(a+1) 

0 

 

The constructed object is in the category of number fields:: 

 

sage: NumberField(x^2 + 3, 'a').category() 

Category of number fields 

sage: category(NumberField(x^2 + 3, 'a')) 

Category of number fields 

 

The special types of number fields, e.g., quadratic fields, do 

not have (yet?) their own category:: 

 

sage: QuadraticField(2,'d').category() 

Category of number fields 

 

TESTS:: 

 

sage: NumberField(ZZ['x'].0^4 + 23, 'a') 

Number Field in a with defining polynomial x^4 + 23 

sage: NumberField(QQ['x'].0^4 + 23, 'a') 

Number Field in a with defining polynomial x^4 + 23 

sage: NumberField(GF(7)['x'].0^4 + 23, 'a') 

Traceback (most recent call last): 

... 

TypeError: polynomial must be defined over rational field 

""" 

self._assume_disc_small = assume_disc_small 

self._maximize_at_primes = maximize_at_primes 

self._structure = structure 

default_category = _NumberFields 

if category is None: 

category = default_category 

else: 

assert category.is_subcategory(default_category), "%s is not a subcategory of %s"%(category, default_category) 

 

ParentWithGens.__init__(self, QQ, name, category=category) 

if not isinstance(polynomial, polynomial_element.Polynomial): 

raise TypeError("polynomial (=%s) must be a polynomial"%repr(polynomial)) 

 

if check: 

if not polynomial.parent().base_ring() == QQ: 

raise TypeError("polynomial must be defined over rational field") 

if not polynomial.is_irreducible(): 

raise ValueError("defining polynomial (%s) must be irreducible"%polynomial) 

 

self._assign_names(name) 

self.__latex_variable_name = latex_name 

self.__polynomial = polynomial 

self._pari_bnf_certified = False 

self._integral_basis_dict = {} 

if embedding is not None: 

# Since Trac #20827, an embedding is specified as a pair 

# (parent, x) with x the image of the distinguished 

# generator (previously, it was just given as x). This 

# allows the UniqueFactory to distinguish embeddings into 

# different fields with images of the generator that 

# compare equal. 

# We allow both formats to support old pickles. 

if isinstance(embedding, tuple): 

parent, x = embedding 

else: 

parent, x = embedding.parent(), embedding 

embedding = number_field_morphisms.NumberFieldEmbedding(self, parent, x) 

self._populate_coercion_lists_(embedding=embedding, convert_method_name='_number_field_') 

 

def _convert_map_from_(self, other): 

r""" 

Additional conversion maps from ``other`` may be defined by 

:meth:`structure`. 

 

.. SEEALSO:: 

 

:meth:`structure.NumberFieldStructure.create_structure` 

 

TESTS:: 

 

sage: K.<i> = QuadraticField(-1) 

sage: L.<j> = K.change_names() 

sage: L(i) 

j 

sage: K(j) 

i 

 

This also works for relative number fields and their absolute fields:: 

 

sage: K.<a> = QuadraticField(2) 

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

sage: M.<b> = L.absolute_field() 

sage: M(i) 

1/6*b^3 + 1/6*b 

sage: L(b) 

i - a 

 

""" 

from sage.categories.map import is_Map 

if self._structure is not None: 

structure = self.structure() 

if len(structure) >= 2: 

to_self = structure[1] 

if is_Map(to_self) and to_self.domain() is other: 

return to_self 

if isinstance(other, NumberField_generic) and other._structure is not None: 

structure = other.structure() 

if len(structure) >= 1: 

from_other = structure[0] 

if is_Map(from_other) and from_other.codomain() is self: 

return from_other 

 

@cached_method 

def _magma_polynomial_(self, magma): 

""" 

Return Magma version of the defining polynomial of this number field. 

 

EXAMPLES:: 

 

sage: R.<x> = QQ[] # optional - magma 

sage: K.<a> = NumberField(x^3+2) # optional - magma 

sage: K._magma_polynomial_(magma) # optional - magma 

x^3 + 2 

sage: magma2=Magma() # optional - magma 

sage: K._magma_polynomial_(magma2) # optional - magma 

x^3 + 2 

sage: K._magma_polynomial_(magma) is K._magma_polynomial_(magma) # optional - magma 

True 

sage: K._magma_polynomial_(magma) is K._magma_polynomial_(magma2) # optional - magma 

False 

""" 

# NB f must not be garbage-collected, otherwise the 

# return value of this function is invalid 

return magma(self.defining_polynomial()) 

 

def _magma_init_(self, magma): 

""" 

Return a Magma version of this number field. 

 

EXAMPLES:: 

 

sage: R.<t> = QQ[] 

sage: K.<a> = NumberField(t^2 + 1) 

sage: K._magma_init_(magma) # optional - magma 

'SageCreateWithNames(NumberField(_sage_[...]),["a"])' 

sage: L = magma(K) # optional - magma 

sage: L # optional - magma 

Number Field with defining polynomial t^2 + 1 over the Rational Field 

sage: L.sage() # optional - magma 

Number Field in a with defining polynomial t^2 + 1 

sage: L.sage() is K # optional - magma 

True 

sage: L.1 # optional - magma 

a 

sage: L.1^2 # optional - magma 

-1 

sage: m = magma(a+1/2); m # optional - magma 

1/2*(2*a + 1) 

sage: m.sage() # optional - magma 

a + 1/2 

 

A relative number field:: 

 

sage: S.<u> = K[] 

sage: M.<b> = NumberField(u^3+u+a) 

sage: L = magma(M) # optional - magma 

sage: L # optional - magma 

Number Field with defining polynomial u^3 + u + a over its ground field 

sage: L.sage() is M # optional - magma 

True 

""" 

# Get magma version of defining polynomial of this number field 

f = self._magma_polynomial_(magma) 

s = 'NumberField(%s)'%f.name() 

return magma._with_names(s, self.variable_names()) 

 

def construction(self): 

r""" 

Construction of self 

 

EXAMPLES:: 

 

sage: K.<a>=NumberField(x^3+x^2+1,embedding=CC.gen()) 

sage: F,R = K.construction() 

sage: F 

AlgebraicExtensionFunctor 

sage: R 

Rational Field 

 

The construction functor respects distinguished embeddings:: 

 

sage: F(R) is K 

True 

sage: F.embeddings 

[0.2327856159383841? + 0.7925519925154479?*I] 

 

TESTS:: 

 

sage: K.<a> = NumberField(x^3+x+1) 

sage: R.<t> = ZZ[] 

sage: a+t # indirect doctest 

t + a 

sage: (a+t).parent() 

Univariate Polynomial Ring in t over Number Field in a with defining polynomial x^3 + x + 1 

 

The construction works for non-absolute number fields as well:: 

 

sage: K.<a,b,c>=NumberField([x^3+x^2+1,x^2+1,x^7+x+1]) 

sage: F,R = K.construction() 

sage: F(R) == K 

True 

 

:: 

 

sage: P.<x> = QQ[] 

sage: K.<a> = NumberField(x^3-5,embedding=0) 

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

sage: a*b 

a*b 

 

""" 

from sage.categories.pushout import AlgebraicExtensionFunctor 

from sage.all import QQ 

names = self.variable_names() 

polys = [] 

embeddings = [] 

structures = [] 

K = self 

while K is not QQ: 

polys.append(K.relative_polynomial()) 

embeddings.append(None if K.coerce_embedding() is None else K.coerce_embedding()(K.gen())) 

structures.append(K._structure) 

K = K.base_field() 

return (AlgebraicExtensionFunctor(polys, names, embeddings, structures), QQ) 

 

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

r""" 

Convert ``x`` into an element of this number field. 

 

INPUT: 

 

- ``x`` -- Sage (or Python) object 

 

OUTPUT: 

 

A :class:`~number_field_element.NumberFieldElement` 

constructed from ``x``. 

 

TESTS:: 

 

sage: K.<a> = NumberField(x^3 + 17) 

sage: K(a) is a # indirect doctest 

True 

sage: K('a^2 + 2/3*a + 5') 

a^2 + 2/3*a + 5 

sage: K('1').parent() 

Number Field in a with defining polynomial x^3 + 17 

sage: K(3/5).parent() 

Number Field in a with defining polynomial x^3 + 17 

sage: K.<a> = NumberField(polygen(QQ)^2 - 5) 

sage: F.<b> = K.extension(polygen(K)) 

sage: F([a]) 

a 

 

We can create number field elements from PARI:: 

 

sage: K.<a> = NumberField(x^3 - 17) 

sage: K(pari(42)) 

42 

sage: K(pari("5/3")) 

5/3 

sage: K(pari("[3/2, -5, 0]~")) # Uses Z-basis 

-5/3*a^2 + 5/3*a - 1/6 

 

From a PARI polynomial or ``POLMOD``, note that the variable 

name does not matter:: 

 

sage: K(pari("-5/3*q^2 + 5/3*q - 1/6")) 

-5/3*a^2 + 5/3*a - 1/6 

sage: K(pari("Mod(-5/3*q^2 + 5/3*q - 1/6, q^3 - 17)")) 

-5/3*a^2 + 5/3*a - 1/6 

sage: K(pari("x^5/17")) 

a^2 

 

An error is raised when a PARI element with an incorrect 

modulus is given: 

 

sage: K(pari("Mod(-5/3*q^2 + 5/3*q - 1/6, q^3 - 999)")) 

Traceback (most recent call last): 

... 

TypeError: cannot convert PARI element Mod(-5/3*q^2 + 5/3*q - 1/6, q^3 - 999) into Number Field in a with defining polynomial x^3 - 17 

 

Test round-trip conversion to PARI and back:: 

 

sage: x = polygen(QQ) 

sage: K.<a> = NumberField(x^3 - 1/2*x + 1/3) 

sage: b = K.random_element() 

sage: K(pari(b)) == b 

True 

 

sage: F.<c> = NumberField(2*x^3 + x + 1) 

sage: d = F.random_element() 

sage: F(F.pari_nf().nfalgtobasis(d)) == d 

True 

 

If the PARI polynomial is different from the Sage polynomial, 

a warning is printed unless ``check=False`` is specified:: 

 

sage: b = pari(a); b 

Mod(-1/12*y^2 - 1/12*y + 1/6, y^3 - 3*y - 22) 

sage: K(b.lift()) 

doctest:...: UserWarning: interpreting PARI polynomial -1/12*y^2 - 1/12*y + 1/6 relative to the defining polynomial x^3 - 3*x - 22 of the PARI number field 

a 

sage: K(b.lift(), check=False) 

a 

 

Using a GAP element may be tricky, as it may contain 

an exclamation mark:: 

 

sage: L.<tau> = NumberField(x^3-2) 

sage: gap(tau^3) 

2 

sage: gap(tau)^3 

!2 

sage: L(gap(tau)^3) # indirect doctest 

2 

 

Check that :trac:`22202` is fixed:: 

 

sage: y = QQ['y'].gen() 

sage: R = QQ.extension(y^2-2,'a')['x'] 

sage: R("a*x").factor() 

(a) * x 

""" 

if isinstance(x, number_field_element.NumberFieldElement): 

K = x.parent() 

if K is self: 

return x 

elif isinstance(x, (number_field_element.OrderElement_absolute, 

number_field_element.OrderElement_relative, 

number_field_element_quadratic.OrderElement_quadratic)): 

L = K.number_field() 

if L is self: 

return self._element_class(self, x) 

x = L(x) 

return self._coerce_from_other_number_field(x) 

elif isinstance(x, pari_gen): 

if x.type() == "t_POLMOD": 

modulus = x.mod() 

if check and modulus != self.pari_polynomial(modulus.variable()): 

raise TypeError("cannot convert PARI element %s into %s" % (x, self)) 

x = x.lift() 

check = False 

elif x.type() == "t_COL": 

x = self.pari_nf().nfbasistoalg_lift(x) 

check = False 

if x.type() in ["t_INT", "t_FRAC"]: 

pass 

elif x.type() == "t_POL": 

var = self.absolute_polynomial().variable_name() 

if check and self.pari_polynomial(var) != self.absolute_polynomial().monic(): 

from warnings import warn 

warn("interpreting PARI polynomial %s relative to the defining polynomial %s of the PARI number field" 

% (x, self.pari_polynomial())) 

# We consider x as a polynomial in the standard 

# generator of the PARI number field, and convert it 

# to a polynomial in the Sage generator. 

if x.poldegree() > 0: 

beta = self._pari_absolute_structure()[2] 

x = x(beta).lift() 

else: 

raise TypeError("%s has unsupported PARI type %s" % (x, x.type())) 

x = self.absolute_polynomial().parent()(x) 

return self._element_class(self, x) 

elif sage.interfaces.gap.is_GapElement(x): 

s = x._sage_repr() 

if self.variable_name() in s: 

return self._convert_from_str(s) 

return self._convert_from_str(s.replace('!', '')) 

elif isinstance(x,str): 

return self._convert_from_str(x) 

elif isinstance(x, (tuple, list)) or \ 

(isinstance(x, sage.modules.free_module_element.FreeModuleElement) and 

self.base_ring().has_coerce_map_from(x.parent().base_ring())): 

if len(x) != self.relative_degree(): 

raise ValueError("Length must be equal to the degree of this number field") 

result = x[0] 

for i in range(1, self.relative_degree()): 

result += x[i]*self.gen(0)**i 

return result 

return self._convert_non_number_field_element(x) 

 

def _convert_non_number_field_element(self, x): 

""" 

Convert a non-number field element ``x`` into this number field. 

 

INPUT: 

 

- ``x`` -- a non number field element, e.g., a list, integer, 

rational, or polynomial 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 + 2/3) 

sage: K._convert_non_number_field_element(-7/8) 

-7/8 

sage: K._convert_non_number_field_element([1,2,3]) 

3*a^2 + 2*a + 1 

 

The list is just turned into a polynomial in the generator:: 

 

sage: K._convert_non_number_field_element([0,0,0,1,1]) 

-2/3*a - 2/3 

 

Any polynomial whose coefficients can be converted to rationals 

will convert to the number field, e.g., this one in 

characteristic 7:: 

 

sage: f = GF(7)['y']([1,2,3]); f 

3*y^2 + 2*y + 1 

sage: K._convert_non_number_field_element(f) 

3*a^2 + 2*a + 1 

 

But not this one over a field of order 27:: 

 

sage: F27.<g> = GF(27) 

sage: f = F27['z']([g^2, 2*g, 1]); f 

z^2 + 2*g*z + g^2 

sage: K._convert_non_number_field_element(f) 

Traceback (most recent call last): 

... 

TypeError: unable to convert g^2 to a rational 

 

One can also convert an element of the polynomial quotient ring 

that is isomorphic to the number field:: 

 

sage: K.<a> = NumberField(x^3 + 17) 

sage: b = K.polynomial_quotient_ring().random_element() 

sage: K(b) 

-1/2*a^2 - 4 

 

We can convert symbolic expressions:: 

 

sage: I = sqrt(-1); parent(I) 

Symbolic Ring 

sage: GaussianIntegers()(2 + I) 

I + 2 

sage: K1 = QuadraticField(3) 

sage: K2 = QuadraticField(5) 

sage: (K,) = K1.composite_fields(K2, preserve_embedding=True) 

sage: K(sqrt(3) + sqrt(5)) 

-1/2*a0^3 + 8*a0 

sage: K(sqrt(-3)*I) 

1/4*a0^3 - 7/2*a0 

""" 

if isinstance(x, integer_types + (Rational, Integer, pari_gen, list)): 

return self._element_class(self, x) 

 

if isinstance(x, sage.rings.polynomial.polynomial_quotient_ring_element.PolynomialQuotientRingElement)\ 

and (x in self.polynomial_quotient_ring()): 

y = self.polynomial_ring().gen() 

return x.lift().subs({y:self.gen()}) 

 

if isinstance(x, (sage.rings.qqbar.AlgebraicNumber, sage.rings.qqbar.AlgebraicReal)): 

return self._convert_from_qqbar(x) 

 

if isinstance(x, polynomial_element.Polynomial): 

return self._element_class(self, x) 

 

# Try converting via QQ. 

try: 

y = QQ(x) 

except (TypeError, ValueError): 

pass 

else: 

return self._element_class(self, y) 

 

# Final attempt: convert via QQbar. This deals in particular 

# with symbolic expressions like sqrt(-5). 

try: 

y = sage.rings.qqbar.QQbar(x) 

except (TypeError, ValueError): 

pass 

else: 

return self._convert_from_qqbar(y) 

 

raise TypeError("unable to convert %r to %s" % (x, self)) 

 

def _convert_from_qqbar(self, x): 

""" 

Convert an element of ``QQbar`` or ``AA`` to this number field, 

if possible. 

 

This requires that the given number field is equipped with an 

embedding. 

 

INPUT: 

 

- ``x`` -- an algebraic number 

 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(3) 

sage: K._convert_from_qqbar(7 + 2*AA(3).sqrt()) 

2*a + 7 

sage: GaussianIntegers()(QQbar(I)) 

I 

sage: CyclotomicField(15)(QQbar.zeta(5)) 

zeta15^3 

sage: CyclotomicField(12)(QQbar.zeta(5)) 

Traceback (most recent call last): 

... 

TypeError: unable to convert 0.3090169943749474? + 0.9510565162951536?*I to Cyclotomic Field of order 12 and degree 4 

""" 

# We use the diagram 

# 

# self 

# ↑ ↘ 

# F → QQbar 

# 

# Where F is the smallest number field containing x. 

# 

# y is the pre-image such that x = F(y) 

F, y, F_to_QQbar = x.as_number_field_element(minimal=True) 

 

# Try all embeddings from F into self 

from sage.rings.qqbar import QQbar 

for F_to_self in F.embeddings(self): 

z = F_to_self(y) 

# Check whether the diagram commutes 

if QQbar(z) == x: 

return z 

 

raise TypeError("unable to convert %r to %s" % (x, self)) 

 

def _convert_from_str(self, x): 

""" 

Coerce a string representation of an element of this 

number field into this number field. 

 

INPUT: 

x -- string 

 

EXAMPLES:: 

 

sage: k.<theta25> = NumberField(x^3+(2/3)*x+1) 

sage: k._convert_from_str('theta25^3 + (1/3)*theta25') 

-1/3*theta25 - 1 

 

This function is called by the coerce method when it gets a string 

as input: 

sage: k('theta25^3 + (1/3)*theta25') 

-1/3*theta25 - 1 

""" 

w = sage.misc.all.sage_eval(x,locals=self.gens_dict()) 

if not (is_Element(w) and w.parent() is self): 

return self(w) 

else: 

return w 

 

def _Hom_(self, codomain, category=None): 

""" 

Return homset of homomorphisms from self to the number field codomain. 

 

EXAMPLES: 

 

This method is implicitly called by :meth:`Hom` and 

:meth:`sage.categories.homset.Hom`:: 

 

sage: K.<i> = NumberField(x^2 + 1); K 

Number Field in i with defining polynomial x^2 + 1 

sage: K.Hom(K) # indirect doctest 

Automorphism group of Number Field in i with defining polynomial x^2 + 1 

sage: Hom(K, QuadraticField(-1, 'b')) 

Set of field embeddings from Number Field in i with defining polynomial x^2 + 1 to Number Field in b with defining polynomial x^2 + 1 

 

CHECKME: handling of the case where codomain is not a number field? 

 

sage: Hom(K, VectorSpace(QQ,3)) 

Set of Morphisms from Number Field in i with defining polynomial x^2 + 1 to Vector space of dimension 3 over Rational Field in Category of commutative additive groups 

 

TESTS: 

 

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

 

sage: R.<x> = QQ[] 

sage: K.<a> = QQ.extension(x^2 + 1) 

sage: K.hom([a]).category_for() 

Category of number fields 

 

:: 

 

sage: H = End(K) 

sage: loads(dumps(H)) is H 

True 

""" 

if not is_NumberFieldHomsetCodomain(codomain): 

raise TypeError("{} is not suitable as codomain for homomorphisms from {}".format(codomain, self)) 

from .morphism import NumberFieldHomset 

return NumberFieldHomset(self, codomain, category) 

 

@cached_method 

def structure(self): 

""" 

Return fixed isomorphism or embedding structure on self. 

 

This is used to record various isomorphisms or embeddings that 

arise naturally in other constructions. 

 

EXAMPLES:: 

 

sage: K.<z> = NumberField(x^2 + 3) 

sage: L.<a> = K.absolute_field(); L 

Number Field in a with defining polynomial x^2 + 3 

sage: L.structure() 

(Isomorphism given by variable name change map: 

From: Number Field in a with defining polynomial x^2 + 3 

To: Number Field in z with defining polynomial x^2 + 3, 

Isomorphism given by variable name change map: 

From: Number Field in z with defining polynomial x^2 + 3 

To: Number Field in a with defining polynomial x^2 + 3) 

 

sage: K.<a> = QuadraticField(-3) 

sage: R.<y> = K[] 

sage: D.<x0> = K.extension(y) 

sage: D_abs.<y0> = D.absolute_field() 

sage: D_abs.structure()[0](y0) 

-a 

""" 

if self._structure is None: 

f = self.hom(self) 

return f,f 

else: 

return self._structure.create_structure(self) 

 

def completion(self, p, prec, extras={}): 

""" 

Returns the completion of self at `p` to the specified 

precision. Only implemented at archimedean places, and then only if 

an embedding has been fixed. 

 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(2) 

sage: K.completion(infinity, 100) 

Real Field with 100 bits of precision 

sage: K.<zeta> = CyclotomicField(12) 

sage: K.completion(infinity, 53, extras={'type': 'RDF'}) 

Complex Double Field 

sage: zeta + 1.5 # implicit test 

2.36602540378444 + 0.500000000000000*I 

""" 

if p == infinity.infinity: 

gen_image = self.gen_embedding() 

if gen_image is not None: 

if gen_image in RDF: 

return QQ.completion(p, prec, extras) 

elif gen_image in CDF: 

return QQ.completion(p, prec, extras).algebraic_closure() 

raise ValueError("No embedding into the complex numbers has been specified.") 

else: 

raise NotImplementedError 

 

def primitive_element(self): 

r""" 

Return a primitive element for this field, i.e., an element that 

generates it over `\QQ`. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 + 2) 

sage: K.primitive_element() 

a 

sage: K.<a,b,c> = NumberField([x^2-2,x^2-3,x^2-5]) 

sage: K.primitive_element() 

a - b + c 

sage: alpha = K.primitive_element(); alpha 

a - b + c 

sage: alpha.minpoly() 

x^2 + (2*b - 2*c)*x - 2*c*b + 6 

sage: alpha.absolute_minpoly() 

x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576 

""" 

try: 

return self.__primitive_element 

except AttributeError: 

pass 

K = self.absolute_field('a') 

from_K, to_K = K.structure() 

self.__primitive_element = from_K(K.gen()) 

return self.__primitive_element 

 

def random_element(self, num_bound=None, den_bound=None, 

integral_coefficients=False, distribution=None): 

r""" 

Return a random element of this number field. 

 

INPUT: 

 

- ``num_bound`` - Bound on numerator of the coefficients of 

the resulting element 

 

- ``den_bound`` - Bound on denominators of the coefficients 

of the resulting element 

 

- ``integral_coefficients`` (default: False) - If True, then 

the resulting element will have integral 

coefficients. This option overrides any 

value of `den_bound`. 

 

- ``distribution`` - Distribution to use for the coefficients 

of the resulting element 

 

OUTPUT: 

 

- Element of this number field 

 

EXAMPLES:: 

 

sage: K.<j> = NumberField(x^8+1) 

sage: K.random_element() 

1/2*j^7 - j^6 - 12*j^5 + 1/2*j^4 - 1/95*j^3 - 1/2*j^2 - 4 

 

sage: K.<a,b,c> = NumberField([x^2-2,x^2-3,x^2-5]) 

sage: K.random_element() 

((6136*c - 7489/3)*b + 5825/3*c - 71422/3)*a + (-4849/3*c + 58918/3)*b - 45718/3*c + 75409/12 

 

sage: K.<a> = NumberField(x^5-2) 

sage: K.random_element(integral_coefficients=True) 

a^3 + a^2 - 3*a - 1 

 

TESTS:: 

 

sage: K.<a> = NumberField(x^5-2) 

sage: K.random_element(-1) 

Traceback (most recent call last): 

... 

TypeError: x must be < y 

sage: K.random_element(5,0) 

Traceback (most recent call last): 

... 

TypeError: x must be < y 

sage: QQ[I].random_element(0) 

Traceback (most recent call last): 

... 

TypeError: x must be > 0 

""" 

if integral_coefficients: 

den_bound = 1 

 

return self._zero_element._random_element(num_bound=num_bound, 

den_bound=den_bound, 

distribution=distribution) 

 

def subfield(self, alpha, name=None, names=None): 

r""" 

Return a number field `K` isomorphic to `\QQ(\alpha)` 

(if this is an absolute number field) or `L(\alpha)` (if this 

is a relative extension `M/L`) and a map from K to self that 

sends the generator of K to alpha. 

 

INPUT: 

 

- ``alpha`` - an element of self, or something that 

coerces to an element of self. 

 

OUTPUT: 

 

- ``K`` - a number field 

- ``from_K`` - a homomorphism from K to self that 

sends the generator of K to alpha. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^4 - 3); K 

Number Field in a with defining polynomial x^4 - 3 

sage: H.<b>, from_H = K.subfield(a^2) 

sage: H 

Number Field in b with defining polynomial x^2 - 3 

sage: from_H(b) 

a^2 

sage: from_H 

Ring morphism: 

From: Number Field in b with defining polynomial x^2 - 3 

To: Number Field in a with defining polynomial x^4 - 3 

Defn: b |--> a^2 

 

A relative example. Note that the result returned is the subfield generated 

by `\alpha` over ``self.base_field()``, not over `\QQ` (see :trac:`5392`):: 

 

sage: L.<a> = NumberField(x^2 - 3) 

sage: M.<b> = L.extension(x^4 + 1) 

sage: K, phi = M.subfield(b^2) 

sage: K.base_field() is L 

True 

 

Subfields inherit embeddings:: 

 

sage: K.<z> = CyclotomicField(5) 

sage: L, K_from_L = K.subfield(z-z^2-z^3+z^4) 

sage: L 

Number Field in z0 with defining polynomial x^2 - 5 

sage: CLF_from_K = K.coerce_embedding(); CLF_from_K 

Generic morphism: 

From: Cyclotomic Field of order 5 and degree 4 

To: Complex Lazy Field 

Defn: z -> 0.309016994374948? + 0.951056516295154?*I 

sage: CLF_from_L = L.coerce_embedding(); CLF_from_L 

Generic morphism: 

From: Number Field in z0 with defining polynomial x^2 - 5 

To: Complex Lazy Field 

Defn: z0 -> 2.236067977499790? 

 

Check transitivity:: 

 

sage: CLF_from_L(L.gen()) 

2.236067977499790? 

sage: CLF_from_K(K_from_L(L.gen())) 

2.23606797749979? + 0.?e-14*I 

 

If `self` has no specified embedding, then `K` comes with an 

embedding in `self`:: 

 

sage: K.<a> = NumberField(x^6 - 6*x^4 + 8*x^2 - 1) 

sage: L.<b>, from_L = K.subfield(a^2) 

sage: L 

Number Field in b with defining polynomial x^3 - 6*x^2 + 8*x - 1 

sage: L.gen_embedding() 

a^2 

 

You can also view a number field as having a different generator by 

just choosing the input to generate the whole field; for that it is 

better to use ``self.change_generator``, which gives 

isomorphisms in both directions. 

""" 

if not names is None: 

name = names 

if name is None: 

name = self.variable_name() + '0' 

beta = self(alpha) 

f = beta.minpoly() 

# If self has a specified embedding, K should inherit it 

if self.coerce_embedding() is not None: 

emb = self.coerce_embedding()(beta) 

else: 

# Otherwise K should at least come with an embedding in self 

emb = beta 

K = NumberField(f, names=name, embedding=emb) 

from_K = K.hom([beta]) 

return K, from_K 

 

def change_generator(self, alpha, name=None, names=None): 

r""" 

Given the number field self, construct another isomorphic number 

field `K` generated by the element alpha of self, along 

with isomorphisms from `K` to self and from self to 

`K`. 

 

EXAMPLES:: 

 

sage: L.<i> = NumberField(x^2 + 1); L 

Number Field in i with defining polynomial x^2 + 1 

sage: K, from_K, to_K = L.change_generator(i/2 + 3) 

sage: K 

Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 

sage: from_K 

Ring morphism: 

From: Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 

To: Number Field in i with defining polynomial x^2 + 1 

Defn: i0 |--> 1/2*i + 3 

sage: to_K 

Ring morphism: 

From: Number Field in i with defining polynomial x^2 + 1 

To: Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 

Defn: i |--> 2*i0 - 6 

 

We can also do 

 

:: 

 

sage: K.<c>, from_K, to_K = L.change_generator(i/2 + 3); K 

Number Field in c with defining polynomial x^2 - 6*x + 37/4 

 

 

We compute the image of the generator `\sqrt{-1}` of `L`. 

 

:: 

 

sage: to_K(i) 

2*c - 6 

 

Note that the image is indeed a square root of -1. 

 

:: 

 

sage: to_K(i)^2 

-1 

sage: from_K(to_K(i)) 

i 

sage: to_K(from_K(c)) 

c 

""" 

if not names is None: 

name = names 

alpha = self(alpha) 

K, from_K = self.subfield(alpha, name=name) 

if K.degree() != self.degree(): 

raise ValueError("alpha must generate a field of degree %s, but alpha generates a subfield of degree %s"%(self.degree(), K.degree())) 

# Now compute to_K, which is an isomorphism 

# from self to K such that from_K(to_K(x)) == x for all x, 

# and to_K(from_K(y)) == y. 

# To do this, we must compute the image of self.gen() 

# under to_K. This means writing self.gen() as a 

# polynomial in alpha, which is possible by the degree 

# check above. This latter we do by linear algebra. 

phi = alpha.coordinates_in_terms_of_powers() 

c = phi(self.gen()) 

to_K = self.hom([K(c)]) 

return K, from_K, to_K 

 

def is_absolute(self): 

""" 

Returns True if self is an absolute field. 

 

This function will be implemented in the derived classes. 

 

EXAMPLES:: 

 

sage: K = CyclotomicField(5) 

sage: K.is_absolute() 

True 

""" 

raise NotImplementedError 

 

def is_relative(self): 

""" 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^10 - 2) 

sage: K.is_absolute() 

True 

sage: K.is_relative() 

False 

""" 

return not self.is_absolute() 

 

@cached_method 

def absolute_field(self, names): 

""" 

Returns self as an absolute extension over QQ. 

 

OUTPUT: 

 

 

- ``K`` - this number field (since it is already 

absolute) 

 

 

Also, ``K.structure()`` returns from_K and to_K, 

where from_K is an isomorphism from K to self and to_K is an 

isomorphism from self to K. 

 

EXAMPLES:: 

 

sage: K = CyclotomicField(5) 

sage: K.absolute_field('a') 

Number Field in a with defining polynomial x^4 + x^3 + x^2 + x + 1 

""" 

return NumberField(self.defining_polynomial(), names, check=False, structure=structure.NameChange(self)) 

 

def is_isomorphic(self, other, isomorphism_maps = False): 

""" 

Return True if self is isomorphic as a number field to other. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 1) 

sage: m.<b> = NumberField(x^2 + 4) 

sage: k.is_isomorphic(m) 

True 

sage: m.<b> = NumberField(x^2 + 5) 

sage: k.is_isomorphic (m) 

False 

 

:: 

 

sage: k = NumberField(x^3 + 2, 'a') 

sage: k.is_isomorphic(NumberField((x+1/3)^3 + 2, 'b')) 

True 

sage: k.is_isomorphic(NumberField(x^3 + 4, 'b')) 

True 

sage: k.is_isomorphic(NumberField(x^3 + 5, 'b')) 

False 

 

sage: k = NumberField(x^2 - x - 1, 'b') 

sage: l = NumberField(x^2 - 7, 'a') 

sage: k.is_isomorphic(l, True) 

(False, []) 

 

sage: k = NumberField(x^2 - x - 1, 'b') 

sage: ky.<y> = k[]; 

sage: l = NumberField(y, 'a') 

sage: k.is_isomorphic(l, True) 

(True, [-x, x + 1]) 

 

""" 

if not isinstance(other, NumberField_generic): 

raise ValueError("other must be a generic number field.") 

t = self.pari_polynomial().nfisisom(other.pari_polynomial()) 

if t == 0: 

t = [] 

res = False 

else: 

res = True 

 

if isomorphism_maps: 

return res, t 

else: 

return res 

 

def is_totally_real(self): 

""" 

Return True if self is totally real, and False otherwise. 

 

Totally real means that every isomorphic embedding of self into the 

complex numbers has image contained in the real numbers. 

 

EXAMPLES:: 

 

sage: NumberField(x^2+2, 'alpha').is_totally_real() 

False 

sage: NumberField(x^2-2, 'alpha').is_totally_real() 

True 

sage: NumberField(x^4-2, 'alpha').is_totally_real() 

False 

""" 

return self.signature()[1] == 0 

 

def is_totally_imaginary(self): 

""" 

Return True if self is totally imaginary, and False otherwise. 

 

Totally imaginary means that no isomorphic embedding of self into 

the complex numbers has image contained in the real numbers. 

 

EXAMPLES:: 

 

sage: NumberField(x^2+2, 'alpha').is_totally_imaginary() 

True 

sage: NumberField(x^2-2, 'alpha').is_totally_imaginary() 

False 

sage: NumberField(x^4-2, 'alpha').is_totally_imaginary() 

False 

""" 

return self.signature()[0] == 0 

 

def is_CM(self): 

r""" 

Return True if self is a CM field (i.e. a totally imaginary 

quadratic extension of a totally real field). 

 

EXAMPLES:: 

 

sage: Q.<a> = NumberField(x - 1) 

sage: Q.is_CM() 

False 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.is_CM() 

True 

sage: L.<zeta20> = CyclotomicField(20) 

sage: L.is_CM() 

True 

sage: K.<omega> = QuadraticField(-3) 

sage: K.is_CM() 

True 

sage: L.<sqrt5> = QuadraticField(5) 

sage: L.is_CM() 

False 

sage: F.<a> = NumberField(x^3 - 2) 

sage: F.is_CM() 

False 

sage: F.<a> = NumberField(x^4-x^3-3*x^2+x+1) 

sage: F.is_CM() 

False 

 

The following are non-CM totally imaginary fields. 

 

:: 

 

sage: F.<a> = NumberField(x^4 + x^3 - x^2 - x + 1) 

sage: F.is_totally_imaginary() 

True 

sage: F.is_CM() 

False 

sage: F2.<a> = NumberField(x^12 - 5*x^11 + 8*x^10 - 5*x^9 - \ 

x^8 + 9*x^7 + 7*x^6 - 3*x^5 + 5*x^4 + \ 

7*x^3 - 4*x^2 - 7*x + 7) 

sage: F2.is_totally_imaginary() 

True 

sage: F2.is_CM() 

False 

 

The following is a non-cyclotomic CM field. 

 

:: 

 

sage: M.<a> = NumberField(x^4 - x^3 - x^2 - 2*x + 4) 

sage: M.is_CM() 

True 

 

Now, we construct a totally imaginary quadratic extension of a 

totally real field (which is not cyclotomic). 

 

:: 

 

sage: E_0.<a> = NumberField(x^7 - 4*x^6 - 4*x^5 + 10*x^4 + 4*x^3 - \ 

6*x^2 - x + 1) 

sage: E_0.is_totally_real() 

True 

sage: E.<b> = E_0.extension(x^2 + 1) 

sage: E.is_CM() 

True 

 

Finally, a CM field that is given as an extension that is not CM. 

 

:: 

 

sage: E_0.<a> = NumberField(x^2 - 4*x + 16) 

sage: y = polygen(E_0) 

sage: E.<z> = E_0.extension(y^2 - E_0.gen() / 2) 

sage: E.is_CM() 

True 

sage: E.is_CM_extension() 

False 

 

""" 

 

#Return cached answer if available 

try: 

return self.__is_CM 

except(AttributeError): 

pass 

 

#Then, deal with simple cases 

if is_odd(self.absolute_degree()): 

self.__is_CM = False 

return False 

if isinstance( 

self, sage.rings.number_field.number_field.NumberField_quadratic): 

self.__is_CM = (self.discriminant() < 0) 

return self.__is_CM 

if isinstance( 

self, sage.rings.number_field.number_field.NumberField_cyclotomic): 

self.__is_CM = True 

return True 

if not self.is_totally_imaginary(): 

self.__is_CM = False 

return False 

if self.is_absolute(): 

K = self 

else: 

F = self.base_field() 

if F.absolute_degree() == self.absolute_degree() / 2: 

if F.is_totally_real(): 

self.__is_CM = True 

self.__max_tot_real_sub = [F, self.coerce_map_from(F)] 

return True 

K = self.absolute_field('z') 

 

#Check for index 2 subextensions that are totally real 

possibilities = K.subfields(K.absolute_degree()/2) 

for F, phi, _ in possibilities: 

if F.is_totally_real(): 

self.__is_CM = True 

if self.is_relative(): 

phi = phi.post_compose(K.structure()[0]) 

self.__max_tot_real_sub = [F, phi] 

return True 

self.__is_CM = False 

return False 

 

def complex_conjugation(self): 

""" 

Return the complex conjugation of self. 

 

This is only well-defined for fields contained in CM fields 

(i.e. for totally real fields and CM fields). Recall that a CM 

field is a totally imaginary quadratic extension of a totally 

real field. For other fields, a ValueError is raised. 

 

EXAMPLES:: 

 

sage: QuadraticField(-1, 'I').complex_conjugation() 

Ring endomorphism of Number Field in I with defining polynomial x^2 + 1 

Defn: I |--> -I 

sage: CyclotomicField(8).complex_conjugation() 

Ring endomorphism of Cyclotomic Field of order 8 and degree 4 

Defn: zeta8 |--> -zeta8^3 

sage: QuadraticField(5, 'a').complex_conjugation() 

Identity endomorphism of Number Field in a with defining polynomial x^2 - 5 

sage: F = NumberField(x^4 + x^3 - 3*x^2 - x + 1, 'a') 

sage: F.is_totally_real() 

True 

sage: F.complex_conjugation() 

Identity endomorphism of Number Field in a with defining polynomial x^4 + x^3 - 3*x^2 - x + 1 

sage: F.<b> = NumberField(x^2 - 2) 

sage: F.extension(x^2 + 1, 'a').complex_conjugation() 

Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 1 over its base field 

Defn: a |--> -a 

b |--> b 

sage: F2.<b> = NumberField(x^2 + 2) 

sage: K2.<a> = F2.extension(x^2 + 1) 

sage: cc = K2.complex_conjugation() 

sage: cc(a) 

-a 

sage: cc(b) 

-b 

 

""" 

 

#Return cached answer if available 

try: 

return self.__complex_conjugation 

except(AttributeError): 

pass 

 

#Then, deal with simple cases 

if isinstance( 

self, sage.rings.number_field.number_field.NumberField_quadratic): 

disc = self.discriminant() 

if disc > 0: 

self.__complex_conjugation = self.coerce_map_from(self) 

return self.__complex_conjugation 

else: 

a = self.gen() 

r = a.trace() 

iy = a - r / 2 

self.__complex_conjugation = self.hom([a - 2 * iy], check=False) 

return self.__complex_conjugation 

if isinstance( 

self, sage.rings.number_field.number_field.NumberField_cyclotomic): 

zeta = self.gen() 

self.__complex_conjugation = self.hom([zeta ** (-1)], check=False) 

return self.__complex_conjugation 

if self.is_totally_real(): 

self.__complex_conjugation = self.coerce_map_from(self) 

return self.__complex_conjugation 

 

if not self.is_CM(): 

raise ValueError('Complex conjugation is only well-defined for fields contained in CM fields.') 

 

#In the remaining case, self.is_CM() should have cached __max_tot_real_sub 

try: 

F, phi = self.__max_tot_real_sub 

except(AttributeError): 

F, phi = self.maximal_totally_real_subfield() 

if self.is_absolute(): 

K_rel = self.relativize(phi, self.variable_name() * 2) 

to_abs, from_abs = K_rel.structure() 

self.__complex_conjugation = K_rel.automorphisms()[1].pre_compose( \ 

from_abs).post_compose(to_abs) 

self.__complex_conjugation = self.hom([self.__complex_conjugation(self.gen())], check=False) 

return self.__complex_conjugation 

else: 

if self.is_CM_extension(): 

return self.automorphisms()[1] 

K_abs = self.absolute_field(self.variable_name() * 2) 

to_self, from_self = K_abs.structure() 

K_rel = K_abs.relativize(phi.post_compose(from_self), self.variable_name() * 3) 

to_abs, from_abs = K_rel.structure() 

self.__complex_conjugation = K_rel.automorphisms()[1].pre_compose(from_abs).post_compose(to_abs) 

self.__complex_conjugation = K_abs.hom([self.__complex_conjugation(K_abs.gen())], check=False) 

self.__complex_conjugation = self.__complex_conjugation.pre_compose(from_self).post_compose(to_self) 

return self.__complex_conjugation 

 

def maximal_totally_real_subfield(self): 

""" 

Return the maximal totally real subfield of self together with an embedding of it into self. 

 

EXAMPLES:: 

 

sage: F.<a> = QuadraticField(11) 

sage: F.maximal_totally_real_subfield() 

[Number Field in a with defining polynomial x^2 - 11, Identity endomorphism of Number Field in a with defining polynomial x^2 - 11] 

sage: F.<a> = QuadraticField(-15) 

sage: F.maximal_totally_real_subfield() 

[Rational Field, Natural morphism: 

From: Rational Field 

To: Number Field in a with defining polynomial x^2 + 15] 

sage: F.<a> = CyclotomicField(29) 

sage: F.maximal_totally_real_subfield() 

(Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 - 56*x^3 + 28*x^2 + 7*x - 1, Ring morphism: 

From: Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 - 56*x^3 + 28*x^2 + 7*x - 1 

To: Cyclotomic Field of order 29 and degree 28 

Defn: a0 |--> -a^27 - a^26 - a^25 - a^24 - a^23 - a^22 - a^21 - a^20 - a^19 - a^18 - a^17 - a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 - 1) 

sage: F.<a> = NumberField(x^3 - 2) 

sage: F.maximal_totally_real_subfield() 

[Rational Field, Coercion map: 

From: Rational Field 

To: Number Field in a with defining polynomial x^3 - 2] 

sage: F.<a> = NumberField(x^4 - x^3 - x^2 + x + 1) 

sage: F.maximal_totally_real_subfield() 

[Rational Field, Coercion map: 

From: Rational Field 

To: Number Field in a with defining polynomial x^4 - x^3 - x^2 + x + 1] 

sage: F.<a> = NumberField(x^4 - x^3 + 2*x^2 + x + 1) 

sage: F.maximal_totally_real_subfield() 

[Number Field in a1 with defining polynomial x^2 - x - 1, Ring morphism: 

From: Number Field in a1 with defining polynomial x^2 - x - 1 

To: Number Field in a with defining polynomial x^4 - x^3 + 2*x^2 + x + 1 

Defn: a1 |--> -1/2*a^3 - 1/2] 

sage: F.<a> = NumberField(x^4-4*x^2-x+1) 

sage: F.maximal_totally_real_subfield() 

[Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1, Identity endomorphism of Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1] 

 

An example of a relative extension where the base field is not the maximal totally real subfield. 

 

:: 

 

sage: E_0.<a> = NumberField(x^2 - 4*x + 16) 

sage: y = polygen(E_0) 

sage: E.<z> = E_0.extension(y^2 - E_0.gen() / 2) 

sage: E.maximal_totally_real_subfield() 

[Number Field in z1 with defining polynomial x^2 - 2*x - 5, Composite map: 

From: Number Field in z1 with defining polynomial x^2 - 2*x - 5 

To: Number Field in z with defining polynomial x^2 - 1/2*a over its base field 

Defn: Ring morphism: 

From: Number Field in z1 with defining polynomial x^2 - 2*x - 5 

To: Number Field in z with defining polynomial x^4 - 2*x^3 + x^2 + 6*x + 3 

Defn: z1 |--> -1/3*z^3 + 1/3*z^2 + z - 1 

then 

Isomorphism map: 

From: Number Field in z with defining polynomial x^4 - 2*x^3 + x^2 + 6*x + 3 

To: Number Field in z with defining polynomial x^2 - 1/2*a over its base field] 

 

""" 

 

try: 

return self.__max_tot_real_sub 

except(AttributeError): 

pass 

 

if isinstance( 

self, sage.rings.number_field.number_field.NumberField_quadratic): 

if self.discriminant() > 0: 

self.__max_tot_real_sub = [self, self.coerce_map_from(self)] 

return self.__max_tot_real_sub 

else: 

self.__max_tot_real_sub = [QQ, self.coerce_map_from(QQ)] 

return self.__max_tot_real_sub 

if isinstance( 

self, sage.rings.number_field.number_field.NumberField_cyclotomic): 

zeta = self.gen() 

self.__max_tot_real_sub = self.subfield(zeta + zeta ** (-1)) 

return self.__max_tot_real_sub 

if self.is_totally_real(): 

self.__max_tot_real_sub = [self, self.coerce_map_from(self)] 

return self.__max_tot_real_sub 

if self.is_absolute(): 

K = self 

else: 

if self.is_CM_extension(): 

self.__max_tot_real_sub = [self.base_field(), self.coerce_map_from(self.base_field())] 

return self.__max_tot_real_sub 

K = self.absolute_field('z') 

 

d = K.absolute_degree() 

divs = d.divisors()[1:-1] 

divs.reverse() 

for i in divs: 

possibilities = K.subfields(i) 

for F, phi, _ in possibilities: 

if F.is_totally_real(): 

if self.is_relative(): 

phi = phi.post_compose(K.structure()[0]) 

self.__max_tot_real_sub = [F, phi] 

return self.__max_tot_real_sub 

self.__max_tot_real_sub = [QQ, self.coerce_map_from(QQ)] 

return self.__max_tot_real_sub 

 

def complex_embeddings(self, prec=53): 

r""" 

Return all homomorphisms of this number field into the approximate 

complex field with precision prec. 

 

This always embeds into an MPFR based complex field. If you 

want embeddings into the 53-bit double precision, which is 

faster, use ``self.embeddings(CDF)``. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^5 + x + 17) 

sage: v = k.complex_embeddings() 

sage: ls = [phi(k.0^2) for phi in v] ; ls # random order 

[2.97572074038..., 

-2.40889943716 + 1.90254105304*I, 

-2.40889943716 - 1.90254105304*I, 

0.921039066973 + 3.07553311885*I, 

0.921039066973 - 3.07553311885*I] 

sage: K.<a> = NumberField(x^3 + 2) 

sage: ls = K.complex_embeddings() ; ls # random order 

[ 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + 2 

To: Complex Double Field 

Defn: a |--> -1.25992104989..., 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + 2 

To: Complex Double Field 

Defn: a |--> 0.629960524947 - 1.09112363597*I, 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + 2 

To: Complex Double Field 

Defn: a |--> 0.629960524947 + 1.09112363597*I 

] 

""" 

CC = sage.rings.complex_field.ComplexField(prec) 

return self.embeddings(CC) 

 

def real_embeddings(self, prec=53): 

r""" 

Return all homomorphisms of this number field into the approximate 

real field with precision prec. 

 

If prec is 53 (the default), then the real double field is 

used; otherwise the arbitrary precision (but slow) real field 

is used. If you want embeddings into the 53-bit double 

precision, which is faster, use ``self.embeddings(RDF)``. 

 

.. NOTE:: 

 

This function uses finite precision real numbers. 

In functions that should output proven results, one 

could use ``self.embeddings(AA)`` instead. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 + 2) 

sage: K.real_embeddings() 

[ 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + 2 

To: Real Field with 53 bits of precision 

Defn: a |--> -1.25992104989487 

] 

sage: K.real_embeddings(16) 

[ 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + 2 

To: Real Field with 16 bits of precision 

Defn: a |--> -1.260 

] 

sage: K.real_embeddings(100) 

[ 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + 2 

To: Real Field with 100 bits of precision 

Defn: a |--> -1.2599210498948731647672106073 

] 

 

As this is a numerical function, the number of embeddings 

may be incorrect if the precision is too low:: 

 

sage: K = NumberField(x^2+2*10^1000*x + 10^2000+1, 'a') 

sage: len(K.real_embeddings()) 

2 

sage: len(K.real_embeddings(100)) 

2 

sage: len(K.real_embeddings(10000)) 

0 

sage: len(K.embeddings(AA)) 

0 

 

""" 

K = sage.rings.real_mpfr.RealField(prec) 

return self.embeddings(K) 

 

def specified_complex_embedding(self): 

r""" 

Returns the embedding of this field into the complex numbers which has 

been specified. 

 

Fields created with the ``QuadraticField`` or 

``CyclotomicField`` constructors come with an implicit 

embedding. To get one of these fields without the embedding, use 

the generic ``NumberField`` constructor. 

 

EXAMPLES:: 

 

sage: QuadraticField(-1, 'I').specified_complex_embedding() 

Generic morphism: 

From: Number Field in I with defining polynomial x^2 + 1 

To: Complex Lazy Field 

Defn: I -> 1*I 

 

:: 

 

sage: QuadraticField(3, 'a').specified_complex_embedding() 

Generic morphism: 

From: Number Field in a with defining polynomial x^2 - 3 

To: Real Lazy Field 

Defn: a -> 1.732050807568878? 

 

:: 

 

sage: CyclotomicField(13).specified_complex_embedding() 

Generic morphism: 

From: Cyclotomic Field of order 13 and degree 12 

To: Complex Lazy Field 

Defn: zeta13 -> 0.885456025653210? + 0.464723172043769?*I 

 

Most fields don't implicitly have embeddings unless explicitly 

specified:: 

 

sage: NumberField(x^2-2, 'a').specified_complex_embedding() is None 

True 

sage: NumberField(x^3-x+5, 'a').specified_complex_embedding() is None 

True 

sage: NumberField(x^3-x+5, 'a', embedding=2).specified_complex_embedding() 

Generic morphism: 

From: Number Field in a with defining polynomial x^3 - x + 5 

To: Real Lazy Field 

Defn: a -> -1.904160859134921? 

sage: NumberField(x^3-x+5, 'a', embedding=CDF.0).specified_complex_embedding() 

Generic morphism: 

From: Number Field in a with defining polynomial x^3 - x + 5 

To: Complex Lazy Field 

Defn: a -> 0.952080429567461? + 1.311248044077123?*I 

 

This function only returns complex embeddings:: 

 

sage: K.<a> = NumberField(x^2-2, embedding=Qp(7)(2).sqrt()) 

sage: K.specified_complex_embedding() is None 

True 

sage: K.gen_embedding() 

3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20) 

sage: K.coerce_embedding() 

Generic morphism: 

From: Number Field in a with defining polynomial x^2 - 2 

To: 7-adic Field with capped relative precision 20 

Defn: a -> 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20) 

""" 

embedding = self.coerce_embedding() 

if embedding is not None: 

from sage.rings.real_mpfr import mpfr_prec_min 

from sage.rings.complex_field import ComplexField 

if ComplexField(mpfr_prec_min()).has_coerce_map_from(embedding.codomain()): 

return embedding 

 

def gen_embedding(self): 

""" 

If an embedding has been specified, return the image of the 

generator under that embedding. Otherwise return None. 

 

EXAMPLES:: 

 

sage: QuadraticField(-7, 'a').gen_embedding() 

2.645751311064591?*I 

sage: NumberField(x^2+7, 'a').gen_embedding() # None 

""" 

embedding = self.coerce_embedding() 

if embedding is None: 

return None 

else: 

return embedding(self.gen()) 

 

def algebraic_closure(self): 

""" 

Return the algebraic closure of self (which is QQbar). 

 

EXAMPLES:: 

 

sage: K.<i> = QuadraticField(-1) 

sage: K.algebraic_closure() 

Algebraic Field 

sage: K.<a> = NumberField(x^3-2) 

sage: K.algebraic_closure() 

Algebraic Field 

sage: K = CyclotomicField(23) 

sage: K.algebraic_closure() 

Algebraic Field 

""" 

return sage.rings.all.QQbar 

 

@cached_method 

def conductor(self, check_abelian=True): 

r""" 

Computes the conductor of the abelian field `K`. 

If check_abelian is set to false and the field is not an 

abelian extension of `\mathbb{Q}`, the output is not meaningful. 

 

INPUT: 

 

- ``check_abelian`` - a boolean (default: ``True``); check to see that this is an abelian extension of `\mathbb{Q}` 

 

OUTPUT: 

 

Integer which is the conductor of the field. 

 

EXAMPLES:: 

 

sage: K = CyclotomicField(27) 

sage: k = K.subfields(9)[0][0] 

sage: k.conductor() 

27 

sage: K.<t> = NumberField(x^3+x^2-2*x-1) 

sage: K.conductor() 

7 

sage: K.<t> = NumberField(x^3+x^2-36*x-4) 

sage: K.conductor() 

109 

sage: K = CyclotomicField(48) 

sage: k = K.subfields(16)[0][0] 

sage: k.conductor() 

48 

sage: NumberField(x,'a').conductor() 

1 

sage: NumberField(x^8 - 8*x^6 + 19*x^4 - 12*x^2 + 1,'a').conductor() 

40 

sage: NumberField(x^8 + 7*x^4 + 1,'a').conductor() 

40 

sage: NumberField(x^8 - 40*x^6 + 500*x^4 - 2000*x^2 + 50,'a').conductor() 

160 

 

ALGORITHM: 

 

For odd primes, it is easy to compute from the ramification 

index because the p-Sylow subgroup is cyclic. For p=2, there 

are two choices for a given ramification index. They can be 

distinguished by the parity of the exponent in the discriminant 

of a 2-adic completion. 

""" 

m = 1 

if check_abelian and not self.is_abelian(): 

raise ValueError("The conductor is only defined for abelian fields") 

 

try: 

De = self.__disc 

except AttributeError: 

De = self.polynomial().discriminant() 

A = De.numerator().prime_factors()+De.denominator().prime_factors() 

else: 

A = De.prime_factors() 

 

for p in A: 

R = self.maximal_order(p) 

e = R.fractional_ideal(p).prime_factors()[0].ramification_index() 

if e!= 1: 

if p==2: 

m *= e*2 

c = R.discriminant().valuation(2) 

c /= self.polynomial().degree()/e 

if is_odd(c): 

m *= 2 

else: 

m *= p**(e.valuation(p)+1) 

return m 

 

def latex_variable_name(self, name=None): 

""" 

Return the latex representation of the variable name for this 

number field. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 3, 'a').latex_variable_name() 

'a' 

sage: NumberField(x^3 + 3, 'theta3').latex_variable_name() 

'\\theta_{3}' 

sage: CyclotomicField(5).latex_variable_name() 

'\\zeta_{5}' 

""" 

if name is None: 

return self.__latex_variable_name 

else: 

self.__latex_variable_name = name 

 

def _repr_(self): 

""" 

Return string representation of this number field. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^13 - (2/3)*x + 3) 

sage: k._repr_() 

'Number Field in a with defining polynomial x^13 - 2/3*x + 3' 

""" 

return "Number Field in %s with defining polynomial %s"%( 

self.variable_name(), self.polynomial()) 

 

def _latex_(self): 

r""" 

Return latex representation of this number field. This is viewed as 

a polynomial quotient ring over a field. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^13 - (2/3)*x + 3) 

sage: k._latex_() 

'\\Bold{Q}[a]/(a^{13} - \\frac{2}{3} a + 3)' 

sage: latex(k) 

\Bold{Q}[a]/(a^{13} - \frac{2}{3} a + 3) 

 

Numbered variables are often correctly typeset:: 

 

sage: k.<theta25> = NumberField(x^25+x+1) 

sage: print(k._latex_()) 

\Bold{Q}[\theta_{25}]/(\theta_{25}^{25} + \theta_{25} + 1) 

""" 

return "%s[%s]/(%s)"%(latex(QQ), self.latex_variable_name(), 

self.polynomial()._latex_(self.latex_variable_name())) 

 

def _ideal_class_(self, n=0): 

""" 

Return the Python class used in defining the zero ideal of the ring 

of integers of this number field. 

 

This function is required by the general ring/ideal machinery. The 

value defined here is the default value for all number fields. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 2, 'c')._ideal_class_() 

<class 'sage.rings.number_field.number_field_ideal.NumberFieldIdeal'> 

""" 

return sage.rings.number_field.number_field_ideal.NumberFieldIdeal 

 

def _fractional_ideal_class_(self): 

""" 

Return the Python class used in defining fractional ideals of the 

ring of integers of this number field. 

 

This function is required by the general ring/ideal machinery. The 

value defined here is the default value for all number fields 

*except* relative number fields; this function is overridden by 

one of the same name on class NumberField_relative. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 2, 'c')._fractional_ideal_class_() 

<class 'sage.rings.number_field.number_field_ideal.NumberFieldFractionalIdeal'> 

""" 

return sage.rings.number_field.number_field_ideal.NumberFieldFractionalIdeal 

 

def ideal(self, *gens, **kwds): 

""" 

K.ideal() returns a fractional ideal of the field, except for the 

zero ideal which is not a fractional ideal. 

 

EXAMPLES:: 

 

sage: K.<i>=NumberField(x^2+1) 

sage: K.ideal(2) 

Fractional ideal (2) 

sage: K.ideal(2+i) 

Fractional ideal (i + 2) 

sage: K.ideal(0) 

Ideal (0) of Number Field in i with defining polynomial x^2 + 1 

""" 

try: 

return self.fractional_ideal(*gens, **kwds) 

except ValueError: 

return sage.rings.ring.Ring.ideal(self, gens, **kwds) 

 

def fractional_ideal(self, *gens, **kwds): 

r""" 

Return the ideal in `\mathcal{O}_K` generated by gens. 

This overrides the ``sage.rings.ring.Field`` method to 

use the ``sage.rings.ring.Ring`` one instead, since 

we're not really concerned with ideals in a field but in its ring 

of integers. 

 

INPUT: 

 

 

- ``gens`` - a list of generators, or a number field 

ideal. 

 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3-2) 

sage: K.fractional_ideal([1/a]) 

Fractional ideal (1/2*a^2) 

 

One can also input a number field ideal itself, 

or, more usefully, for a tower of number fields an ideal 

in one of the fields lower down the tower. 

 

:: 

 

sage: K.fractional_ideal(K.ideal(a)) 

Fractional ideal (a) 

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

sage: M.<c> = L.extension(x^2 + 1) 

sage: L.ideal(K.ideal(2, a)) 

Fractional ideal (a) 

sage: M.ideal(K.ideal(2, a)) == M.ideal(a*(b - c)/2) 

True 

 

The zero ideal is not a fractional ideal! 

 

:: 

 

sage: K.fractional_ideal(0) 

Traceback (most recent call last): 

... 

ValueError: gens must have a nonzero element (zero ideal is not a fractional ideal) 

""" 

if len(gens) == 1 and isinstance(gens[0], (list, tuple)): 

gens = gens[0] 

if len(gens) == 1 and isinstance(gens[0], NumberFieldFractionalIdeal): 

I = gens[0] 

if I.number_field() is self: 

return I 

else: 

gens = I.gens() 

return self._fractional_ideal_class_()(self, gens, **kwds) 

 

def ideals_of_bdd_norm(self, bound): 

""" 

All integral ideals of bounded norm. 

 

INPUT: 

 

 

- ``bound`` - a positive integer 

 

 

OUTPUT: A dict of all integral ideals I such that Norm(I) <= bound, 

keyed by norm. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2 + 23) 

sage: d = K.ideals_of_bdd_norm(10) 

sage: for n in d: 

....: print(n) 

....: for I in d[n]: 

....: print(I) 

1 

Fractional ideal (1) 

2 

Fractional ideal (2, 1/2*a - 1/2) 

Fractional ideal (2, 1/2*a + 1/2) 

3 

Fractional ideal (3, 1/2*a - 1/2) 

Fractional ideal (3, 1/2*a + 1/2) 

4 

Fractional ideal (4, 1/2*a + 3/2) 

Fractional ideal (2) 

Fractional ideal (4, 1/2*a + 5/2) 

5 

6 

Fractional ideal (1/2*a - 1/2) 

Fractional ideal (6, 1/2*a + 5/2) 

Fractional ideal (6, 1/2*a + 7/2) 

Fractional ideal (1/2*a + 1/2) 

7 

8 

Fractional ideal (1/2*a + 3/2) 

Fractional ideal (4, a - 1) 

Fractional ideal (4, a + 1) 

Fractional ideal (1/2*a - 3/2) 

9 

Fractional ideal (9, 1/2*a + 11/2) 

Fractional ideal (3) 

Fractional ideal (9, 1/2*a + 7/2) 

10 

""" 

hnf_ideals = self.pari_nf().ideallist(bound) 

d = {} 

for i in range(bound): 

d[i+1] = [self.ideal(hnf) for hnf in hnf_ideals[i]] 

return d 

 

def primes_above(self, x, degree=None): 

r""" 

Return prime ideals of self lying over x. 

 

INPUT: 

 

 

- ``x``: usually an element or ideal of self. It 

should be such that self.ideal(x) is sensible. This excludes x=0. 

 

- ``degree`` (default: None): None or an integer. 

If None, find all primes above x of any degree. If an integer, find 

all primes above x such that the resulting residue field has 

exactly this degree. 

 

 

OUTPUT: A list of prime ideals of self lying over x. If degree 

is specified and no such ideal exists, returns the empty list. 

The output is sorted by residue degree first, then by 

underlying prime (or equivalently, by norm). 

 

EXAMPLES:: 

 

sage: x = ZZ['x'].gen() 

sage: F.<t> = NumberField(x^3 - 2) 

 

:: 

 

sage: P2s = F.primes_above(2) 

sage: P2s # random 

[Fractional ideal (-t)] 

sage: all(2 in P2 for P2 in P2s) 

True 

sage: all(P2.is_prime() for P2 in P2s) 

True 

sage: [ P2.norm() for P2 in P2s ] 

[2] 

 

:: 

 

sage: P3s = F.primes_above(3) 

sage: P3s # random 

[Fractional ideal (t + 1)] 

sage: all(3 in P3 for P3 in P3s) 

True 

sage: all(P3.is_prime() for P3 in P3s) 

True 

sage: [ P3.norm() for P3 in P3s ] 

[3] 

 

The ideal (3) is totally ramified in F, so there is no degree 2 

prime above 3:: 

 

sage: F.primes_above(3, degree=2) 

[] 

sage: [ id.residue_class_degree() for id, _ in F.ideal(3).factor() ] 

[1] 

 

Asking for a specific degree works:: 

 

sage: P5_1s = F.primes_above(5, degree=1) 

sage: P5_1s # random 

[Fractional ideal (-t^2 - 1)] 

sage: P5_1 = P5_1s[0]; P5_1.residue_class_degree() 

1 

 

:: 

 

sage: P5_2s = F.primes_above(5, degree=2) 

sage: P5_2s # random 

[Fractional ideal (t^2 - 2*t - 1)] 

sage: P5_2 = P5_2s[0]; P5_2.residue_class_degree() 

2 

 

Works in relative extensions too:: 

 

sage: PQ.<X> = QQ[] 

sage: F.<a, b> = NumberField([X^2 - 2, X^2 - 3]) 

sage: PF.<Y> = F[] 

sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b) 

sage: I = F.ideal(a + 2*b) 

sage: P, Q = K.primes_above(I) 

sage: K.ideal(I) == P^4*Q 

True 

sage: K.primes_above(I, degree=1) == [P] 

True 

sage: K.primes_above(I, degree=4) == [Q] 

True 

 

It doesn't make sense to factor the ideal (0), so this raises an error:: 

 

sage: F.prime_above(0) 

Traceback (most recent call last): 

... 

AttributeError: 'NumberFieldIdeal' object has no attribute 'prime_factors' 

""" 

if degree is not None: 

degree = ZZ(degree) 

facs = sorted([ (id.residue_class_degree(), id.absolute_norm(), id) for id in self.prime_factors(x) ]) 

if degree is None: 

return [ id for d, n, id in facs ] 

else: 

return [ id for d, n, id in facs if d == degree ] 

 

def prime_above(self, x, degree=None): 

r""" 

Return a prime ideal of self lying over x. 

 

INPUT: 

 

 

- ``x``: usually an element or ideal of self. It 

should be such that self.ideal(x) is sensible. This excludes x=0. 

 

- ``degree`` (default: None): None or an integer. 

If one, find a prime above x of any degree. If an integer, find a 

prime above x such that the resulting residue field has exactly 

this degree. 

 

 

OUTPUT: A prime ideal of self lying over x. If degree is specified 

and no such ideal exists, raises a ValueError. 

 

EXAMPLES:: 

 

sage: x = ZZ['x'].gen() 

sage: F.<t> = NumberField(x^3 - 2) 

 

:: 

 

sage: P2 = F.prime_above(2) 

sage: P2 # random 

Fractional ideal (-t) 

sage: 2 in P2 

True 

sage: P2.is_prime() 

True 

sage: P2.norm() 

2 

 

:: 

 

sage: P3 = F.prime_above(3) 

sage: P3 # random 

Fractional ideal (t + 1) 

sage: 3 in P3 

True 

sage: P3.is_prime() 

True 

sage: P3.norm() 

3 

 

The ideal (3) is totally ramified in F, so there is no degree 2 

prime above 3:: 

 

sage: F.prime_above(3, degree=2) 

Traceback (most recent call last): 

... 

ValueError: No prime of degree 2 above Fractional ideal (3) 

sage: [ id.residue_class_degree() for id, _ in F.ideal(3).factor() ] 

[1] 

 

Asking for a specific degree works:: 

 

sage: P5_1 = F.prime_above(5, degree=1) 

sage: P5_1 # random 

Fractional ideal (-t^2 - 1) 

sage: P5_1.residue_class_degree() 

1 

 

:: 

 

sage: P5_2 = F.prime_above(5, degree=2) 

sage: P5_2 # random 

Fractional ideal (t^2 - 2*t - 1) 

sage: P5_2.residue_class_degree() 

2 

 

Relative number fields are ok:: 

 

sage: G = F.extension(x^2 - 11, 'b') 

sage: G.prime_above(7) 

Fractional ideal (b + 2) 

 

It doesn't make sense to factor the ideal (0):: 

 

sage: F.prime_above(0) 

Traceback (most recent call last): 

... 

AttributeError: 'NumberFieldIdeal' object has no attribute 'prime_factors' 

 

""" 

ids = self.primes_above(x, degree) 

if not ids: 

raise ValueError("No prime of degree %s above %s" % (degree, self.ideal(x))) 

return ids[0] 

 

def primes_of_bounded_norm(self, B): 

r""" 

Returns a sorted list of all prime ideals with norm at most `B`. 

 

INPUT: 

 

- ``B`` -- a positive integer or real; upper bound on the norms of the 

primes generated. 

 

OUTPUT: 

 

A list of all prime ideals of this number field of norm at 

most `B`, sorted by norm. Primes of the same norm are sorted 

using the comparison function for ideals, which is based on 

the Hermite Normal Form. 

 

.. note:: 

 

See also :meth:`primes_of_bounded_norm_iter` for an 

iterator version of this, but note that the iterator sorts 

the primes in order of underlying rational prime, not by 

norm. 

 

EXAMPLES:: 

 

sage: K.<i> = QuadraticField(-1) 

sage: K.primes_of_bounded_norm(10) 

[Fractional ideal (i + 1), Fractional ideal (-i - 2), Fractional ideal (2*i + 1), Fractional ideal (3)] 

sage: K.primes_of_bounded_norm(1) 

[] 

sage: K.<a> = NumberField(x^3-2) 

sage: P = K.primes_of_bounded_norm(30) 

sage: P 

[Fractional ideal (a), 

Fractional ideal (a + 1), 

Fractional ideal (-a^2 - 1), 

Fractional ideal (a^2 + a - 1), 

Fractional ideal (2*a + 1), 

Fractional ideal (-2*a^2 - a - 1), 

Fractional ideal (a^2 - 2*a - 1), 

Fractional ideal (a + 3)] 

sage: [p.norm() for p in P] 

[2, 3, 5, 11, 17, 23, 25, 29] 

""" 

try: 

B = ZZ(B) 

except (TypeError, AttributeError): 

try: 

B = ZZ(B.ceil()) 

except (TypeError, AttributeError): 

raise TypeError("%s is not valid bound on prime ideals" % B) 

if B<2: 

return [] 

 

if self is QQ: 

return arith.primes(B+1) 

else: 

P = [pp for p in arith.primes(B+1) for pp in self.primes_above(p)] 

P = [p for p in P if p.norm() <= B] 

P.sort(key=lambda P: (P.norm(),P)) 

return P 

 

def primes_of_bounded_norm_iter(self, B): 

r""" 

Iterator yielding all prime ideals with norm at most `B`. 

 

INPUT: 

 

- ``B`` -- a positive integer or real; upper bound on the norms of the 

primes generated. 

 

OUTPUT: 

 

An iterator over all prime ideals of this number field of norm 

at most `B`. 

 

.. note:: 

 

The output is not sorted by norm, but by size of the 

underlying rational prime. 

 

EXAMPLES:: 

 

sage: K.<i> = QuadraticField(-1) 

sage: it = K.primes_of_bounded_norm_iter(10) 

sage: list(it) 

[Fractional ideal (i + 1), 

Fractional ideal (3), 

Fractional ideal (-i - 2), 

Fractional ideal (2*i + 1)] 

sage: list(K.primes_of_bounded_norm_iter(1)) 

[] 

""" 

try: 

B = ZZ(B) 

except (TypeError, AttributeError): 

try: 

B = ZZ(B.ceil()) 

except (TypeError, AttributeError): 

raise TypeError("%s is not valid bound on prime ideals" % B) 

 

if B < 2: 

return 

 

if self is QQ: 

for p in arith.primes(B+1): 

yield p 

else: 

for p in arith.primes(B+1): 

for pp in self.primes_above(p): 

if pp.norm() <= B: 

yield pp 

 

 

def primes_of_degree_one_iter(self, num_integer_primes=10000, max_iterations=100): 

r""" 

Return an iterator yielding prime ideals of absolute degree one and 

small norm. 

 

.. warning:: 

 

It is possible that there are no primes of `K` of 

absolute degree one of small prime norm, and it possible 

that this algorithm will not find any primes of small norm. 

 

See module :mod:`sage.rings.number_field.small_primes_of_degree_one` 

for details. 

 

INPUT: 

 

 

- ``num_integer_primes (default: 10000)`` - an 

integer. We try to find primes of absolute norm no greater than the 

num_integer_primes-th prime number. For example, if 

num_integer_primes is 2, the largest norm found will be 3, since 

the second prime is 3. 

 

- ``max_iterations (default: 100)`` - an integer. We 

test max_iterations integers to find small primes before raising 

StopIteration. 

 

 

EXAMPLES:: 

 

sage: K.<z> = CyclotomicField(10) 

sage: it = K.primes_of_degree_one_iter() 

sage: Ps = [ next(it) for i in range(3) ] 

sage: Ps # random 

[Fractional ideal (z^3 + z + 1), Fractional ideal (3*z^3 - z^2 + z - 1), Fractional ideal (2*z^3 - 3*z^2 + z - 2)] 

sage: [ P.norm() for P in Ps ] # random 

[11, 31, 41] 

sage: [ P.residue_class_degree() for P in Ps ] 

[1, 1, 1] 

""" 

from sage.rings.number_field.small_primes_of_degree_one import Small_primes_of_degree_one_iter 

return Small_primes_of_degree_one_iter(self, num_integer_primes, max_iterations) 

 

def primes_of_degree_one_list(self, n, num_integer_primes=10000, max_iterations=100): 

r""" 

Return a list of n prime ideals of absolute degree one and small 

norm. 

 

.. warning:: 

 

It is possible that there are no primes of `K` of 

absolute degree one of small prime norm, and it possible 

that this algorithm will not find any primes of small norm. 

 

See module :mod:`sage.rings.number_field.small_primes_of_degree_one` 

for details. 

 

INPUT: 

 

 

- ``num_integer_primes (default: 10000)`` - an 

integer. We try to find primes of absolute norm no greater than the 

num_integer_primes-th prime number. For example, if 

num_integer_primes is 2, the largest norm found will be 3, since 

the second prime is 3. 

 

- ``max_iterations (default: 100)`` - an integer. We 

test max_iterations integers to find small primes before raising 

StopIteration. 

 

 

EXAMPLES:: 

 

sage: K.<z> = CyclotomicField(10) 

sage: Ps = K.primes_of_degree_one_list(3) 

sage: Ps # random output 

[Fractional ideal (-z^3 - z^2 + 1), Fractional ideal (2*z^3 - 2*z^2 + 2*z - 3), Fractional ideal (2*z^3 - 3*z^2 + z - 2)] 

sage: [ P.norm() for P in Ps ] 

[11, 31, 41] 

sage: [ P.residue_class_degree() for P in Ps ] 

[1, 1, 1] 

""" 

it = self.primes_of_degree_one_iter() 

return [ next(it) for i in range(n) ] 

 

def completely_split_primes(self, B = 200): 

r""" 

Returns a list of rational primes which split completely in the number field `K`. 

 

INPUT: 

 

- ``B`` -- a positive integer bound (default: 200) 

 

OUTPUT: 

 

A list of all primes ``p < B`` which split completely in ``K``. 

 

EXAMPLES:: 

 

sage: K.<xi> = NumberField(x^3 - 3*x + 1) 

sage: K.completely_split_primes(100) 

[17, 19, 37, 53, 71, 73, 89] 

""" 

from sage.rings.fast_arith import prime_range 

from sage.rings.finite_rings.finite_field_constructor import GF 

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 

from sage.arith.all import factor 

split_primes = [] 

for p in prime_range(B): 

Fp = GF(p) 

FpT = PolynomialRing(Fp,'T') 

g = FpT(self.defining_polynomial()) 

if len(factor(g)) == self.degree(): 

split_primes.append(p) 

return split_primes 

 

def _is_valid_homomorphism_(self, codomain, im_gens): 

""" 

Return whether or not there is a homomorphism defined by the given 

images of generators. 

 

To do this we just check that the elements of the image of the 

given generator (im_gens always has length 1) satisfies the 

relation of the defining poly of this field. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 - 3) 

sage: k._is_valid_homomorphism_(QQ, [0]) 

False 

sage: k._is_valid_homomorphism_(k, []) 

False 

sage: k._is_valid_homomorphism_(k, [a]) 

True 

sage: k._is_valid_homomorphism_(k, [-a]) 

True 

sage: k._is_valid_homomorphism_(k, [a+1]) 

False 

""" 

try: 

if len(im_gens) != 1: 

return False 

# We need that elements of the base ring of the polynomial 

# ring map canonically into codomain. 

codomain._coerce_(QQ.one()) 

f = self.defining_polynomial() 

return codomain(f(im_gens[0])) == 0 

except (TypeError, ValueError): 

return False 

 

@cached_method 

def _pari_absolute_structure(self): 

r""" 

Return data relating the Sage and PARI absolute polynomials. 

 

OUTPUT: 

 

Let `L` be this number field, and let `f` be the defining 

polynomial of `K` over `\QQ`. This method returns a triple 

``(g, alpha, beta)``, where 

 

- ``g`` is the defining relative polynomial of the PARI ``nf`` 

structure (see :meth:`pari_nf`); 

 

- ``alpha`` is the image of `x \bmod f` under some isomorphism 

`\phi\colon K[x]/(f) \to K[x]/(g)` 

 

- ``beta`` is the image of `x \bmod g` under the inverse 

isomorphism `\phi^{-1}\colon K[x]/(g) \to K[x]/(f)` 

 

EXAMPLES:: 

 

If `f` is monic and integral, the result satisfies ``g = f`` 

and ``alpha = beta = x``:: 

 

sage: K.<a> = NumberField(x^2 - 2) 

sage: K._pari_absolute_structure() 

(y^2 - 2, Mod(y, y^2 - 2), Mod(y, y^2 - 2)) 

 

An example where `f` neither monic nor integral:: 

 

sage: K.<a> = NumberField(2*x^2 + 1/3) 

sage: K._pari_absolute_structure() 

(y^2 + 6, Mod(1/6*y, y^2 + 6), Mod(6*y, y^2 + 1/6)) 

""" 

f = self.absolute_polynomial()._pari_with_name('y') 

if f.pollead() == f.content().denominator() == 1: 

g = f 

alpha = beta = g.variable().Mod(g) 

else: 

g, alpha = f.polredbest(flag=1) 

beta = alpha.modreverse() 

return g, alpha, beta 

 

def pari_polynomial(self, name='x'): 

""" 

Return the PARI polynomial corresponding to this number field. 

 

INPUT: 

 

- ``name`` -- variable name (default: ``'x'``) 

 

OUTPUT: 

 

A monic polynomial with integral coefficients (PARI ``t_POL``) 

defining the PARI number field corresponding to ``self``. 

 

.. WARNING:: 

 

This is *not* the same as simply converting the defining 

polynomial to PARI. 

 

EXAMPLES:: 

 

sage: y = polygen(QQ) 

sage: k.<a> = NumberField(y^2 - 3/2*y + 5/3) 

sage: k.pari_polynomial() 

x^2 - x + 40 

sage: k.polynomial().__pari__() 

x^2 - 3/2*x + 5/3 

sage: k.pari_polynomial('a') 

a^2 - a + 40 

 

Some examples with relative number fields:: 

 

sage: k.<a, c> = NumberField([x^2 + 3, x^2 + 1]) 

sage: k.pari_polynomial() 

x^4 + 8*x^2 + 4 

sage: k.pari_polynomial('a') 

a^4 + 8*a^2 + 4 

sage: k.absolute_polynomial() 

x^4 + 8*x^2 + 4 

sage: k.relative_polynomial() 

x^2 + 3 

 

sage: k.<a, c> = NumberField([x^2 + 1/3, x^2 + 1/4]) 

sage: k.pari_polynomial() 

x^4 - x^2 + 1 

sage: k.absolute_polynomial() 

x^4 - x^2 + 1 

 

This fails with arguments which are not a valid PARI variable name:: 

 

sage: k = QuadraticField(-1) 

sage: k.pari_polynomial('I') 

Traceback (most recent call last): 

... 

PariError: I already exists with incompatible valence 

sage: k.pari_polynomial('i') 

i^2 + 1 

sage: k.pari_polynomial('theta') 

Traceback (most recent call last): 

... 

PariError: theta already exists with incompatible valence 

""" 

return self._pari_absolute_structure()[0].change_variable_name(name) 

 

def pari_nf(self, important=True): 

""" 

Return the PARI number field corresponding to this field. 

 

INPUT: 

 

- ``important`` -- boolean (default: ``True``). If ``False``, 

raise a ``RuntimeError`` if we need to do a difficult 

discriminant factorization. This is useful when an integral 

basis is not strictly required, such as for factoring 

polynomials over this number field. 

 

OUTPUT: 

 

The PARI number field obtained by calling the PARI function 

:pari:`nfinit` with ``self.pari_polynomial('y')`` as argument. 

 

.. NOTE:: 

 

This method has the same effect as ``pari(self)``. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^4 - 3*x + 7); k 

Number Field in a with defining polynomial x^4 - 3*x + 7 

sage: k.pari_nf()[:4] 

[y^4 - 3*y + 7, [0, 2], 85621, 1] 

sage: pari(k)[:4] 

[y^4 - 3*y + 7, [0, 2], 85621, 1] 

 

:: 

 

sage: k.<a> = NumberField(x^4 - 3/2*x + 5/3); k 

Number Field in a with defining polynomial x^4 - 3/2*x + 5/3 

sage: k.pari_nf() 

[y^4 - 324*y + 2160, [0, 2], 48918708, 216, ..., [36, 36*y, y^3 + 6*y^2 - 252, 6*y^2], [1, 0, 0, 252; 0, 1, 0, 0; 0, 0, 0, 36; 0, 0, 6, -36], [1, 0, 0, 0, 0, 0, -18, 42, 0, -18, -46, -60, 0, 42, -60, -60; 0, 1, 0, 0, 1, 0, 2, 0, 0, 2, -11, -1, 0, 0, -1, 9; 0, 0, 1, 0, 0, 0, 6, 6, 1, 6, -5, 0, 0, 6, 0, 0; 0, 0, 0, 1, 0, 6, -6, -6, 0, -6, -1, 2, 1, -6, 2, 0]] 

sage: pari(k) 

[y^4 - 324*y + 2160, [0, 2], 48918708, 216, ...] 

sage: gp(k) 

[y^4 - 324*y + 2160, [0, 2], 48918708, 216, ...] 

 

With ``important=False``, we simply bail out if we cannot 

easily factor the discriminant:: 

 

sage: p = next_prime(10^40); q = next_prime(10^41) 

sage: K.<a> = NumberField(x^2 - p*q) 

sage: K.pari_nf(important=False) 

Traceback (most recent call last): 

... 

RuntimeError: Unable to factor discriminant with trial division 

 

Next, we illustrate the ``maximize_at_primes`` and ``assume_disc_small`` 

parameters of the ``NumberField`` constructor. The following would take 

a very long time without the ``maximize_at_primes`` option:: 

 

sage: K.<a> = NumberField(x^2 - p*q, maximize_at_primes=[p]) 

sage: K.pari_nf() 

[y^2 - 100000000000000000000...] 

 

Since the discriminant is square-free, this also works:: 

 

sage: K.<a> = NumberField(x^2 - p*q, assume_disc_small=True) 

sage: K.pari_nf() 

[y^2 - 100000000000000000000...] 

""" 

try: 

return self._pari_nf 

except AttributeError: 

f = self.pari_polynomial("y") 

if f.poldegree() > 1: 

f = pari([f, self._pari_integral_basis(important=important)]) 

self._pari_nf = f.nfinit() 

return self._pari_nf 

 

def pari_zk(self): 

""" 

Integral basis of the PARI number field corresponding to this field. 

 

This is the same as pari_nf().getattr('zk'), but much faster. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 - 17) 

sage: k.pari_zk() 

[1, 1/3*y^2 - 1/3*y + 1/3, y] 

sage: k.pari_nf().getattr('zk') 

[1, 1/3*y^2 - 1/3*y + 1/3, y] 

""" 

return self.pari_nf().nf_get_zk() 

 

def __pari__(self): 

""" 

Return the PARI number field corresponding to this field. 

 

EXAMPLES:: 

 

sage: k = NumberField(x^2 + x + 1, 'a') 

sage: k.__pari__() 

[y^2 + y + 1, [0, 1], -3, 1, ... [1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]] 

sage: pari(k) 

[y^2 + y + 1, [0, 1], -3, 1, ...[1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]] 

""" 

return self.pari_nf() 

 

def _pari_init_(self): 

""" 

Return the PARI number field corresponding to this field. 

 

EXAMPLES:: 

 

sage: k = NumberField(x^2 + x + 1, 'a') 

sage: k._pari_init_() 

'[y^2 + y + 1, [0, 1], -3, 1, ... [1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]' 

sage: gp(k) 

[y^2 + y + 1, [0, 1], -3, 1, ...[1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]] 

""" 

return str(self.pari_nf()) 

 

def pari_bnf(self, proof=None, units=True): 

""" 

PARI big number field corresponding to this field. 

 

INPUT: 

 

- ``proof`` -- If False, assume GRH. If True, run PARI's 

:pari:`bnfcertify` to make sure that the results are correct. 

 

- ``units`` -- (default: True) If True, insist on having 

fundamental units. If False, the units may or may not be 

computed. 

 

OUTPUT: 

 

The PARI ``bnf`` structure of this number field. 

 

.. warning:: 

 

Even with ``proof=True``, I wouldn't trust this to mean 

that everything computed involving this number field is 

actually correct. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 1); k 

Number Field in a with defining polynomial x^2 + 1 

sage: len(k.pari_bnf()) 

10 

sage: k.pari_bnf()[:4] 

[[;], matrix(0,3), [;], ...] 

sage: len(k.pari_nf()) 

9 

sage: k.<a> = NumberField(x^7 + 7); k 

Number Field in a with defining polynomial x^7 + 7 

sage: dummy = k.pari_bnf(proof=True) 

""" 

proof = get_flag(proof, "number_field") 

# First compute bnf 

try: 

bnf = self._pari_bnf 

except AttributeError: 

f = self.pari_polynomial("y") 

if units: 

self._pari_bnf = f.bnfinit(1) 

else: 

self._pari_bnf = f.bnfinit() 

bnf = self._pari_bnf 

# Certify if needed 

if proof and not getattr(self, "_pari_bnf_certified", False): 

if bnf.bnfcertify() != 1: 

raise ValueError("The result is not correct according to bnfcertify") 

self._pari_bnf_certified = True 

return bnf 

 

def pari_rnfnorm_data(self, L, proof=True): 

""" 

Return the PARI :pari:`rnfisnorminit` data corresponding to the 

extension L/self. 

 

EXAMPLES:: 

 

sage: x = polygen(QQ) 

sage: K = NumberField(x^2 - 2, 'alpha') 

sage: L = K.extension(x^2 + 5, 'gamma') 

sage: ls = K.pari_rnfnorm_data(L) ; len(ls) 

8 

 

sage: K.<a> = NumberField(x^2 + x + 1) 

sage: P.<X> = K[] 

sage: L.<b> = NumberField(X^3 + a) 

sage: ls = K.pari_rnfnorm_data(L); len(ls) 

8 

""" 

if L.base_field() != self: 

raise ValueError("L must be an extension of self") 

 

Kbnf = self.pari_bnf(proof=proof) 

return Kbnf.rnfisnorminit(L.pari_relative_polynomial()) 

 

def _gap_init_(self): 

""" 

Create a gap object representing self and return its name 

 

EXAMPLES:: 

 

sage: z = QQ['z'].0 

sage: K.<zeta> = NumberField(z^2 - 2) 

sage: K._gap_init_() # the following variable name $sage1 represents the F.base_ring() in gap and is somehow random 

'CallFuncList(function() local z,E; z:=Indeterminate($sage1,"z"); E:=AlgebraicExtension($sage1,z^2 - 2,"zeta"); return E; end,[])' 

sage: k = gap(K) 

sage: k 

<algebraic extension over the Rationals of degree 2> 

sage: k.GeneratorsOfDivisionRing() 

[ zeta ] 

 

The following tests that it is possible to use a defining 

polynomial in the variable ``E``, even though by default 

``E`` is used as a local variable in the above GAP 

``CallFuncList``:: 

 

sage: P.<E> = QQ[] 

sage: L.<tau> = NumberField(E^3 - 2) 

sage: l = gap(L); l 

<algebraic extension over the Rationals of degree 3> 

sage: l.GeneratorsOfField() 

[ tau ] 

sage: gap(tau)^3 

!2 

 

""" 

if not self.is_absolute(): 

raise NotImplementedError("Currently, only simple algebraic extensions are implemented in gap") 

G = sage.interfaces.gap.gap 

q = self.polynomial() 

if q.variable_name()!='E': 

return 'CallFuncList(function() local %s,E; %s:=Indeterminate(%s,"%s"); E:=AlgebraicExtension(%s,%s,"%s"); return E; end,[])'%(q.variable_name(),q.variable_name(),G(self.base_ring()).name(),q.variable_name(),G(self.base_ring()).name(),repr(self.polynomial()),str(self.gen())) 

else: 

return 'CallFuncList(function() local %s,F; %s:=Indeterminate(%s,"%s"); F:=AlgebraicExtension(%s,%s,"%s"); return F; end,[])'%(q.variable_name(),q.variable_name(),G(self.base_ring()).name(),q.variable_name(),G(self.base_ring()).name(),repr(self.polynomial()),str(self.gen())) 

 

def characteristic(self): 

""" 

Return the characteristic of this number field, which is of course 

0. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^99 + 2); k 

Number Field in a with defining polynomial x^99 + 2 

sage: k.characteristic() 

0 

""" 

return ZZ.zero() 

 

def class_group(self, proof=None, names='c'): 

r""" 

Return the class group of the ring of integers of this number 

field. 

 

INPUT: 

 

 

- ``proof`` - if True then compute the class group 

provably correctly. Default is True. Call number_field_proof to 

change this default globally. 

 

- ``names`` - names of the generators of this class 

group. 

 

 

OUTPUT: The class group of this number field. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2 + 23) 

sage: G = K.class_group(); G 

Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 

sage: G.0 

Fractional ideal class (2, 1/2*a - 1/2) 

sage: G.gens() 

(Fractional ideal class (2, 1/2*a - 1/2),) 

 

:: 

 

sage: G.number_field() 

Number Field in a with defining polynomial x^2 + 23 

sage: G is K.class_group() 

True 

sage: G is K.class_group(proof=False) 

False 

sage: G.gens() 

(Fractional ideal class (2, 1/2*a - 1/2),) 

 

There can be multiple generators:: 

 

sage: k.<a> = NumberField(x^2 + 20072) 

sage: G = k.class_group(); G 

Class group of order 76 with structure C38 x C2 of Number Field in a with defining polynomial x^2 + 20072 

sage: G.0 # random 

Fractional ideal class (41, a + 10) 

sage: G.0^38 

Trivial principal fractional ideal class 

sage: G.1 # random 

Fractional ideal class (2, -1/2*a) 

sage: G.1^2 

Trivial principal fractional ideal class 

 

Class groups of Hecke polynomials tend to be very small:: 

 

sage: f = ModularForms(97, 2).T(2).charpoly() 

sage: f.factor() 

(x - 3) * (x^3 + 4*x^2 + 3*x - 1) * (x^4 - 3*x^3 - x^2 + 6*x - 1) 

sage: [NumberField(g,'a').class_group().order() for g,_ in f.factor()] 

[1, 1, 1] 

""" 

proof = proof_flag(proof) 

try: 

return self.__class_group[proof, names] 

except KeyError: 

pass 

except AttributeError: 

self.__class_group = {} 

k = self.pari_bnf(proof) 

cycle_structure = tuple( ZZ(c) for c in k.bnf_get_cyc() ) 

 

# Gens is a list of ideals (the generators) 

gens = tuple( self.ideal(hnf) for hnf in k.bnf_get_gen() ) 

 

G = ClassGroup(cycle_structure, names, self, gens, proof=proof) 

self.__class_group[proof, names] = G 

return G 

 

def class_number(self, proof=None): 

""" 

Return the class number of this number field, as an integer. 

 

INPUT: 

 

 

- ``proof`` - bool (default: True unless you called 

number_field_proof) 

 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 23, 'a').class_number() 

3 

sage: NumberField(x^2 + 163, 'a').class_number() 

1 

sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').class_number(proof=False) 

1539 

""" 

proof = proof_flag(proof) 

return self.class_group(proof).order() 

 

def S_class_group(self, S, proof=None, names='c'): 

""" 

Returns the S-class group of this number field over its base field. 

 

INPUT: 

 

- ``S`` - a set of primes of the base field 

 

- ``proof`` - if False, assume the GRH in computing the class group. 

Default is True. Call ``number_field_proof`` to change this 

default globally. 

 

- ``names`` - names of the generators of this class group. 

 

OUTPUT: 

 

The S-class group of this number field. 

 

EXAMPLES: 

 

A well known example:: 

 

sage: K.<a> = QuadraticField(-5) 

sage: K.S_class_group([]) 

S-class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 5 

 

When we include the prime `(2, a+1)`, the S-class group becomes 

trivial:: 

 

sage: K.S_class_group([K.ideal(2,a+1)]) 

S-class group of order 1 of Number Field in a with defining polynomial x^2 + 5 

 

TESTS:: 

 

sage: K.<a> = QuadraticField(-14) 

sage: I = K.ideal(2,a) 

sage: S = (I,) 

sage: CS = K.S_class_group(S);CS 

S-class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 14 

sage: T = tuple([]) 

sage: CT = K.S_class_group(T);CT 

S-class group of order 4 with structure C4 of Number Field in a with defining polynomial x^2 + 14 

sage: K.class_group() 

Class group of order 4 with structure C4 of Number Field in a with defining polynomial x^2 + 14 

""" 

proof = proof_flag(proof) 

if all(P.is_principal() for P in S): 

C = self.class_group(proof=proof) 

Slist = list(zip([g.ideal() for g in C.gens()], C.invariants())) 

else: 

Slist = self._S_class_group_and_units(tuple(S), proof=proof)[1] 

return SClassGroup(tuple(s[1] for s in Slist), names, self, 

tuple(s[0] for s in Slist), tuple(S)) 

 

def S_units(self, S, proof=True): 

""" 

Returns a list of generators of the S-units. 

 

INPUT: 

 

- ``S`` -- a set of primes of the base field 

 

- ``proof`` -- if ``False``, assume the GRH in computing the class group 

 

OUTPUT: 

 

A list of generators of the unit group. 

 

.. note:: 

 

For more functionality see the S_unit_group() function. 

 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(-3) 

sage: K.unit_group() 

Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 

sage: K.S_units([]) # random 

[1/2*a + 1/2] 

sage: K.S_units([])[0].multiplicative_order() 

6 

 

An example in a relative extension (see :trac:`8722`):: 

 

sage: L.<a,b> = NumberField([x^2 + 1, x^2 - 5]) 

sage: p = L.ideal((-1/2*b - 1/2)*a + 1/2*b - 1/2) 

sage: W = L.S_units([p]); [x.norm() for x in W] 

[9, 1, 1] 

 

Our generators should have the correct parent (:trac:`9367`):: 

 

sage: _.<x> = QQ[] 

sage: L.<alpha> = NumberField(x^3 + x + 1) 

sage: p = L.S_units([ L.ideal(7) ]) 

sage: p[0].parent() 

Number Field in alpha with defining polynomial x^3 + x + 1 

 

TESTS: 

 

This checks that the multiple entries issue at :trac:`9341` is fixed:: 

 

sage: _.<t> = QQ[] 

sage: K.<T> = NumberField(t-1) 

sage: I = K.ideal(2) 

sage: K.S_units([I]) 

[2, -1] 

sage: J = K.ideal(-2) 

sage: K.S_units([I, J, I]) 

[2, -1] 

 

""" 

return self._S_class_group_and_units(tuple(S), proof=proof)[0] 

 

@cached_method 

def _S_class_group_and_units(self, S, proof=True): 

""" 

Compute S class group and units. 

 

INPUT: 

 

- ``S`` - a tuple of prime ideals of self 

 

- ``proof`` - if False, assume the GRH in computing the class group 

 

OUTPUT: 

 

- ``units, clgp_gens``, where: 

 

- ``units`` - A list of generators of the unit group. 

 

- ``clgp_gens`` - A list of generators of the `S`-class group. 

Each generator is represented as a pair ``(gen, order)``, 

where ``gen`` is a fractional ideal of self and ``order`` is 

its order in the `S`-class group. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2+5) 

sage: K._S_class_group_and_units(()) 

([-1], [(Fractional ideal (2, a + 1), 2)]) 

 

sage: K.<a> = NumberField(polygen(QQ)) 

sage: K._S_class_group_and_units( (K.ideal(5),) ) 

([5, -1], []) 

 

TESTS:: 

 

sage: K.<a> = NumberField(x^3 - 381 * x + 127) 

sage: K._S_class_group_and_units(tuple(K.primes_above(13))) 

([2/13*a^2 + 1/13*a - 677/13, 

1/13*a^2 + 7/13*a - 332/13, 

-1/13*a^2 + 6/13*a + 345/13, 

-1, 

2/13*a^2 + 1/13*a - 755/13, 

1/13*a^2 - 19/13*a - 7/13], 

[(Fractional ideal (11, a - 2), 2), (Fractional ideal (19, a + 7), 2)]) 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(2*x^2 - 1/3) 

sage: K._S_class_group_and_units(tuple(K.primes_above(2) + K.primes_above(3))) 

([-6*a + 2, 6*a + 3, -1, 12*a + 5], []) 

""" 

K_pari = self.pari_bnf(proof=proof) 

from sage.misc.all import uniq 

S_pari = [p.pari_prime() for p in uniq(S)] 

result = K_pari.bnfsunit(S_pari) 

units = [self(x, check=False) for x in result[0]] + self.unit_group().gens_values() 

orders = result[4][1].sage() 

gens = [self.ideal(_) for _ in result[4][2]] 

return units, [(gens[k], orders[k]) for k in range(len(orders)) if orders[k] > 1] 

 

@cached_method 

def _S_class_group_quotient_matrix(self, S): 

r""" 

Return the matrix of the quotient map from the class group to the 

S-class group. The result is cached. 

 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(-21) 

sage: K._S_class_group_quotient_matrix((K.ideal([2, a+1]),)) 

[1] 

[0] 

sage: K._S_class_group_quotient_matrix((K.ideal([5, a+2]),)) 

[0] 

[1] 

sage: K._S_class_group_quotient_matrix(()) 

[1 0] 

[0 1] 

sage: K.<a> = QuadraticField(-105) 

sage: K._S_class_group_quotient_matrix((K.ideal(11, a + 4),)) 

[0 0] 

[1 0] 

[0 1] 

""" 

from sage.matrix.constructor import matrix 

S_clgp_gens = self._S_class_group_and_units(S)[1] 

a = len(S_clgp_gens) 

c = self.class_group().ngens() 

M = [u[0].ideal_class_log() for u in S_clgp_gens] 

M += [x.ideal_class_log() for x in S] 

M = matrix(ZZ, M) 

A, Q = M.hermite_form(transformation=True) 

assert A[:c] == 1 and A[c:] == 0 

return Q[:c, :a] 

 

def selmer_group(self, S, m, proof=True, orders=False): 

r""" 

Compute the group `K(S,m)`. 

 

INPUT: 

 

- ``S`` -- a set of primes of ``self`` 

 

- ``m`` -- a positive integer 

 

- ``proof`` -- if False, assume the GRH in computing the class group 

 

- ``orders`` (default False) -- if True, output two lists, the 

generators and their orders 

 

OUTPUT: 

 

A list of generators of `K(S,m)`, and (optionally) their 

orders as elements of `K^\times/(K^\times)^m`. This is the 

subgroup of `K^\times/(K^\times)^m` consisting of elements `a` 

such that the valuation of `a` is divisible by `m` at all 

primes not in `S`. It fits in an exact sequence between the 

units modulo `m`-th powers and the `m`-torsion in the 

`S`-class group: 

 

.. MATH:: 

 

1 \longrightarrow 

O_{K,S}^\times / (O_{K,S}^\times)^m \longrightarrow 

K(S,m) \longrightarrow 

\operatorname{Cl}_{K,S}[m] \longrightarrow 

0. 

 

The group `K(S,m)` contains the subgroup of those `a` such 

that `K(\sqrt[m]{a})/K` is unramified at all primes of `K` 

outside of `S`, but may contain it properly when not all 

primes dividing `m` are in `S`. 

 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(-5) 

sage: K.selmer_group((), 2) 

[-1, 2] 

 

The previous example shows that the group generated by the 

output may be strictly larger than the 'true' Selmer group of 

elements giving extensions unramified outside `S`, since that 

has order just 2, generated by `-1`:: 

 

sage: K.class_number() 

2 

sage: K.hilbert_class_field('b') 

Number Field in b with defining polynomial x^2 + 1 over its base field 

 

When `m` is prime all the orders are equal to `m`, but in general they are only divisors of `m`:: 

 

sage: K.<a> = QuadraticField(-5) 

sage: P2 = K.ideal(2, -a+1) 

sage: P3 = K.ideal(3, a+1) 

sage: K.selmer_group((), 2, orders=True) 

([-1, 2], [2, 2]) 

sage: K.selmer_group((), 4, orders=True) 

([-1, 4], [2, 2]) 

sage: K.selmer_group([P2], 2) 

[2, -1] 

sage: K.selmer_group((P2,P3), 4) 

[2, -a - 1, -1] 

sage: K.selmer_group((P2,P3), 4, orders=True) 

([2, -a - 1, -1], [4, 4, 2]) 

sage: K.selmer_group([P2], 3) 

[2] 

sage: K.selmer_group([P2, P3], 3) 

[2, -a - 1] 

sage: K.selmer_group([P2, P3, K.ideal(a)], 3) # random signs 

[2, a + 1, a] 

 

Example over `\QQ` (as a number field):: 

 

sage: K.<a> = NumberField(polygen(QQ)) 

sage: K.selmer_group([],5) 

[] 

sage: K.selmer_group([K.prime_above(p) for p in [2,3,5]],2) 

[2, 3, 5, -1] 

sage: K.selmer_group([K.prime_above(p) for p in [2,3,5]],6, orders=True) 

([2, 3, 5, -1], [6, 6, 6, 2]) 

 

TESTS:: 

 

sage: K.<a> = QuadraticField(-5) 

sage: P2 = K.ideal(2, -a+1) 

sage: P3 = K.ideal(3, a+1) 

sage: P5 = K.ideal(a) 

sage: S = K.selmer_group([P2, P3, P5], 3) 

sage: S in ([2, a + 1, a], [2, a + 1, -a], [2, -a - 1, a], [2, -a - 1, -a]) or S 

True 

 

Verify that :trac:`14489` is fixed:: 

 

sage: K.<a> = NumberField(x^3 - 381 * x + 127) 

sage: K.selmer_group(K.primes_above(13), 2) 

[2/13*a^2 + 1/13*a - 677/13, 

1/13*a^2 + 7/13*a - 332/13, 

-1/13*a^2 + 6/13*a + 345/13, 

-1, 

2/13*a^2 + 1/13*a - 755/13, 

1/13*a^2 - 19/13*a - 7/13, 

2/13*a^2 + 53/13*a - 92/13, 

2/13*a^2 + 40/13*a - 27/13] 

 

Verify that :trac:`16708` is fixed:: 

 

sage: K.<a> = QuadraticField(-5) 

sage: p = K.primes_above(2)[0] 

sage: S = K.selmer_group((), 4) 

sage: all(4.divides(x.valuation(p)) for x in S) 

True 

""" 

units, clgp_gens = self._S_class_group_and_units(tuple(S), proof=proof) 

gens = [] 

ords = [] 

for unit in units: 

order = unit.multiplicative_order() 

if order == Infinity: 

gens.append(unit) 

ords.append(m) 

else: 

m1 = order.gcd(m) 

if m1!= 1: 

gens.append(unit) 

ords.append(m1) 

card_S = len(S) 

if card_S != 0: 

from sage.matrix.constructor import Matrix 

H = self.class_group() 

gen_ords = [g.order() for g in H.gens()] 

pari_ords = pari(gen_ords).Col() 

Sords = [H(s).order() for s in S] 

MS = Matrix(ZZ, [H(s).exponents() for s in S]).transpose() 

pari_MS = pari(MS) 

for gen, order in clgp_gens: 

d = order.gcd(m) 

if d != 1: 

# The ideal I = gen^(order/d) has order d in Cl_S[m]. 

# After multiplying by primes in S, the ideal 

# I^m = gen^(order*m/d) becomes principal. We take 

# a generator of this ideal to get the corresponding 

# generator of the m-Selmer group. 

J = gen ** (order * m // d) 

if card_S != 0 and not J.is_principal(): 

B = H(J).exponents() 

pari_B = (-pari(B)).Col() 

exps = pari_MS.matsolvemod(pari_ords, pari_B).Vec().sage() 

Spart = prod([S[i] ** (exps[i] % Sords[i]) for i in range(card_S)]) 

J *= Spart 

gens.append(self(J.gens_reduced()[0])) 

ords.append(d) 

if orders: 

return gens, ords 

else: 

return gens 

 

def selmer_group_iterator(self, S, m, proof=True): 

r""" 

Return an iterator through elements of the finite group `K(S,m)`. 

 

INPUT: 

 

- ``S`` -- a set of primes of ``self`` 

 

- ``m`` -- a positive integer 

 

- ``proof`` -- if False, assume the GRH in computing the class group 

 

OUTPUT: 

 

An iterator yielding the distinct elements of `K(S,m)`. See 

the docstring for :meth:`NumberField_generic.selmer_group` for 

more information. 

 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(-5) 

sage: list(K.selmer_group_iterator((), 2)) 

[1, 2, -1, -2] 

sage: list(K.selmer_group_iterator((), 4)) 

[1, 4, -1, -4] 

sage: list(K.selmer_group_iterator([K.ideal(2, -a+1)], 2)) 

[1, -1, 2, -2] 

sage: list(K.selmer_group_iterator([K.ideal(2, -a+1), K.ideal(3, a+1)], 2)) 

[1, -1, -a - 1, a + 1, 2, -2, -2*a - 2, 2*a + 2] 

 

Examples over `\QQ` (as a number field):: 

 

sage: K.<a> = NumberField(polygen(QQ)) 

sage: list(K.selmer_group_iterator([], 5)) 

[1] 

sage: list(K.selmer_group_iterator([], 4)) 

[1, -1] 

sage: list(K.selmer_group_iterator([K.prime_above(p) for p in [11,13]],2)) 

[1, -1, 13, -13, 11, -11, 143, -143] 

""" 

KSgens, ords = self.selmer_group(S=S, m=m, proof=proof, orders=True) 

one = self.one() 

from sage.misc.all import cartesian_product_iterator 

for ev in cartesian_product_iterator([range(o) for o in ords]): 

yield prod([p ** e for p, e in zip(KSgens, ev)], one) 

 

def composite_fields(self, other, names=None, both_maps=False, preserve_embedding=True): 

""" 

Return the possible composite number fields formed from 

``self`` and ``other``. 

 

INPUT: 

 

- ``other`` -- number field 

 

- ``names`` -- generator name for composite fields 

 

- ``both_maps`` -- boolean (default: ``False``) 

 

- ``preserve_embedding`` -- boolean (default: True) 

 

OUTPUT: 

 

A list of the composite fields, possibly with maps. 

 

If ``both_maps`` is ``True``, the list consists of quadruples 

``(F, self_into_F, other_into_F, k)`` such that 

``self_into_F`` is an embedding of ``self`` in ``F``, 

``other_into_F`` is an embedding of in ``F``, and ``k`` is one 

of the following: 

 

- an integer such that ``F.gen()`` equals 

``other_into_F(other.gen()) + k*self_into_F(self.gen())``; 

 

- ``Infinity``, in which case ``F.gen()`` equals 

``self_into_F(self.gen())``; 

 

- ``None`` (when ``other`` is a relative number field). 

 

If both ``self`` and ``other`` have embeddings into an ambient 

field, then each ``F`` will have an embedding with respect to 

which both ``self_into_F`` and ``other_into_F`` will be 

compatible with the ambient embeddings. 

 

If ``preserve_embedding`` is ``True`` and if ``self`` and 

``other`` both have embeddings into the same ambient field, or 

into fields which are contained in a common field, only the 

compositum respecting both embeddings is returned. In all 

other cases, all possible composite number fields are 

returned. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^4 - 2) 

sage: K.composite_fields(K) 

[Number Field in a with defining polynomial x^4 - 2, 

Number Field in a0 with defining polynomial x^8 + 28*x^4 + 2500] 

 

A particular compositum is selected, together with compatible maps 

into the compositum, if the fields are endowed with a real or 

complex embedding:: 

 

sage: K1 = NumberField(x^4 - 2, 'a', embedding=RR(2^(1/4))) 

sage: K2 = NumberField(x^4 - 2, 'a', embedding=RR(-2^(1/4))) 

sage: K1.composite_fields(K2) 

[Number Field in a with defining polynomial x^4 - 2] 

sage: [F, f, g, k], = K1.composite_fields(K2, both_maps=True); F 

Number Field in a with defining polynomial x^4 - 2 

sage: f(K1.0), g(K2.0) 

(a, -a) 

 

With ``preserve_embedding`` set to ``False``, the embeddings 

are ignored:: 

 

sage: K1.composite_fields(K2, preserve_embedding=False) 

[Number Field in a with defining polynomial x^4 - 2, 

Number Field in a0 with defining polynomial x^8 + 28*x^4 + 2500] 

 

Changing the embedding selects a different compositum:: 

 

sage: K3 = NumberField(x^4 - 2, 'a', embedding=CC(2^(1/4)*I)) 

sage: [F, f, g, k], = K1.composite_fields(K3, both_maps=True); F 

Number Field in a0 with defining polynomial x^8 + 28*x^4 + 2500 

sage: f(K1.0), g(K3.0) 

(1/240*a0^5 - 41/120*a0, 1/120*a0^5 + 19/60*a0) 

 

If no embeddings are specified, the maps into the compositum 

are chosen arbitrarily:: 

 

sage: Q1.<a> = NumberField(x^4 + 10*x^2 + 1) 

sage: Q2.<b> = NumberField(x^4 + 16*x^2 + 4) 

sage: Q1.composite_fields(Q2, 'c') 

[Number Field in c with defining polynomial x^8 + 64*x^6 + 904*x^4 + 3840*x^2 + 3600] 

sage: F, Q1_into_F, Q2_into_F, k = Q1.composite_fields(Q2, 'c', both_maps=True)[0] 

sage: Q1_into_F 

Ring morphism: 

From: Number Field in a with defining polynomial x^4 + 10*x^2 + 1 

To: Number Field in c with defining polynomial x^8 + 64*x^6 + 904*x^4 + 3840*x^2 + 3600 

Defn: a |--> 19/14400*c^7 + 137/1800*c^5 + 2599/3600*c^3 + 8/15*c 

 

This is just one of four embeddings of ``Q1`` into ``F``:: 

 

sage: Hom(Q1, F).order() 

4 

 

Note that even with ``preserve_embedding=True``, this method may fail 

to recognize that the two number fields have compatible embeddings, and 

hence return several composite number fields:: 

 

sage: x = polygen(ZZ) 

sage: A.<a> = NumberField(x^3 - 7, embedding=CC(-0.95+1.65*I)) 

sage: B.<a> = NumberField(x^9 - 7, embedding=QQbar.polynomial_root(x^9 - 7, RIF(1.2, 1.3))) 

sage: len(A.composite_fields(B, preserve_embedding=True)) 

2 

 

TESTS: 

 

Let's check that embeddings are being respected:: 

 

sage: x = polygen(ZZ) 

sage: K0.<b> = CyclotomicField(7, 'a').subfields(3)[0][0].change_names() 

sage: K1.<a1> = K0.extension(x^2 - 2*b^2, 'a1').absolute_field() 

sage: K2.<a2> = K0.extension(x^2 - 3*b^2, 'a2').absolute_field() 

 

We need embeddings, so we redefine:: 

 

sage: L1.<a1> = NumberField(K1.polynomial(), 'a1', embedding=CC.0) 

sage: L2.<a2> = NumberField(K2.polynomial(), 'a2', embedding=CC.0) 

sage: [CDF(a1), CDF(a2)] 

[-0.6293842454258951, -0.7708351267200304] 

 

and we get the same embeddings via the compositum:: 

 

sage: F, L1_into_F, L2_into_F, k = L1.composite_fields(L2, both_maps=True)[0] 

sage: [CDF(L1_into_F(L1.gen())), CDF(L2_into_F(L2.gen()))] 

[-0.6293842454258952, -0.7708351267200303] 

 

Let's check that if only one field has an embedding, the resulting 

fields do not have embeddings:: 

 

sage: L1.composite_fields(K2)[0].coerce_embedding() is None 

True 

sage: L2.composite_fields(K1)[0].coerce_embedding() is None 

True 

 

We check that other can be a relative number field:: 

 

sage: L.<a, b> = NumberField([x^3 - 5, x^2 + 3]) 

sage: CyclotomicField(3, 'w').composite_fields(L, both_maps=True) 

[(Number Field in a with defining polynomial x^3 - 5 over its base field, Ring morphism: 

From: Cyclotomic Field of order 3 and degree 2 

To: Number Field in a with defining polynomial x^3 - 5 over its base field 

Defn: w |--> -1/2*b - 1/2, Relative number field endomorphism of Number Field in a with defining polynomial x^3 - 5 over its base field 

Defn: a |--> a 

b |--> b, None)] 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(x^2 + 1/2) 

sage: L.<b> = NumberField(3*x^2 - 1) 

sage: K.composite_fields(L) 

[Number Field in ab with defining polynomial 36*x^4 + 12*x^2 + 25] 

sage: C = K.composite_fields(L, both_maps=True); C 

[(Number Field in ab with defining polynomial 36*x^4 + 12*x^2 + 25, 

Ring morphism: 

From: Number Field in a with defining polynomial x^2 + 1/2 

To: Number Field in ab with defining polynomial 36*x^4 + 12*x^2 + 25 

Defn: a |--> -3/5*ab^3 - 7/10*ab, 

Ring morphism: 

From: Number Field in b with defining polynomial 3*x^2 - 1 

To: Number Field in ab with defining polynomial 36*x^4 + 12*x^2 + 25 

Defn: b |--> -3/5*ab^3 + 3/10*ab, 

-1)] 

sage: M, f, g, k = C[0] 

sage: M.gen() == g(b) + k*f(a) 

True 

 

This also fixes the bugs reported at :trac:`14164` and 

:trac:`18243`:: 

 

sage: R.<x> = QQ[] 

sage: f = 6*x^5 + x^4 + x^2 + 5*x + 7 

sage: r = f.roots(QQbar, multiplicities=False) 

sage: F1 = NumberField(f.monic(), 'a', embedding=r[0]) 

sage: F2 = NumberField(f.monic(), 'a', embedding=r[1]) 

sage: (F, map1, map2, k) = F1.composite_fields(F2, both_maps=True)[0] 

sage: F.degree() 

20 

sage: F.gen() == map2(F2.gen()) + k*map1(F1.gen()) 

True 

 

sage: f = x^8 - 3*x^7 + 61/3*x^6 - 9*x^5 + 298*x^4 + 458*x^3 + 1875*x^2 + 4293*x + 3099 

sage: F1 = NumberField(f, 'z', embedding=-1.18126721294295 + 3.02858651117832j) 

sage: F2 = NumberField(f, 'z', embedding=-1.18126721294295 - 3.02858651117832j) 

sage: (F, map1, map2, k) = F1.composite_fields(F2, both_maps=True)[0] 

sage: F.degree() 

32 

sage: F.gen() == map2(F2.gen()) + k*map1(F1.gen()) 

True 

 

Check that the bugs reported at :trac:`24357` are fixed:: 

 

sage: A.<a> = NumberField(x^9 - 7) 

sage: B.<b> = NumberField(x^3-7, embedding=a^3) 

sage: C.<c> = QuadraticField(-1) 

sage: B.composite_fields(C) 

[Number Field in bc with defining polynomial x^6 + 3*x^4 + 14*x^3 + 3*x^2 - 42*x + 50] 

 

sage: y = polygen(QQ, 'y') 

sage: A.<a> = NumberField(x^3 - 7, embedding=CC(-0.95+1.65*I)) 

sage: B.<b> = NumberField(y^9 - 7, embedding=CC(-1.16+0.42*I)) 

sage: A.composite_fields(B) 

[Number Field in b with defining polynomial y^9 - 7] 

""" 

if not isinstance(other, NumberField_generic): 

raise TypeError("other must be a number field.") 

 

sv = self.variable_name(); ov = other.variable_name() 

if names is None: 

names = sv + (ov if ov != sv else "") 

name = normalize_names(1, names)[0] 

 

# should we try to preserve embeddings? 

subfields_have_embeddings = preserve_embedding 

if self.coerce_embedding() is None: 

subfields_have_embeddings = False 

if other.coerce_embedding() is None: 

subfields_have_embeddings = False 

if subfields_have_embeddings: 

try: 

from sage.categories.pushout import pushout 

ambient_field = pushout(self.coerce_embedding().codomain(), other.coerce_embedding().codomain()) 

except sage.structure.coerce_exceptions.CoercionException: 

ambient_field = None 

if ambient_field is None: 

subfields_have_embeddings = False 

 

f = self.absolute_polynomial() 

g = other.absolute_polynomial().change_variable_name(f.variable_name()) 

R = f.parent() 

f = f.__pari__(); f /= f.content() 

g = g.__pari__(); g /= g.content() 

 

m = self.degree() 

n = other.absolute_degree() 

 

if not both_maps and not subfields_have_embeddings: 

# short cut! 

# eliminate duplicates from the fields given by polcompositum 

# and return the resulting number fields. There is no need to 

# check that the polynomials are irreducible. 

C = [] 

for r in f.polcompositum(g): 

if not any(r.nfisisom(s) for s in C): 

C.append(r) 

C = [R(_) for _ in C] 

 

q = sum(1 for r in C if r.degree() != max(m, n)) 

if q == 1 and name != sv and name != ov: 

names = [name] 

else: 

names = [name + str(i) for i in range(q)] 

 

i = 0 

rets = [] 

for r in C: 

d = r.degree() 

if d == m: 

rets.append(self) 

elif d == n: 

rets.append(other) 

else: 

rets.append(NumberField(r, names[i], check=False)) 

i += 1 

return rets 

 

# If flag = 1, polcompositum outputs a vector of 4-component vectors 

# [R, a, b, k], where R ranges through the list of all possible compositums 

# as above, and a (resp. b) expresses the root of P (resp. Q) as 

# an element of Q(X)/(R). Finally, k is a small integer such that 

# b + ka = X modulo R. 

# In this case duplicates must only be eliminated if embeddings are going 

# to be preserved. 

C = [] 

for v in f.polcompositum(g, 1): 

if subfields_have_embeddings or not any(v[0].nfisisom(u[0]) for u in C): 

C.append(v) 

 

a = self.gen() 

b = other.gen() 

 

# If both subfields are provided with embeddings, then we must select 

# the compositum which corresponds to these embeddings. We do this by 

# evaluating the given polynomials at the corresponding embedded values. 

# For the case we want, the result will be zero, but rounding errors are 

# difficult to predict, so we just take the field which yields the 

# minimum value. 

if subfields_have_embeddings: 

poly_vals = [] 

for r, _, _, k in C: 

r = R(r) 

k = ZZ(k) 

embedding = other.coerce_embedding()(b) + k*self.coerce_embedding()(a) 

poly_vals.append(r(embedding).abs()) 

i = poly_vals.index(min(poly_vals)) 

C = [C[i]] 

 

q = sum(1 for r, _, _, _ in C if r.poldegree() != max(m, n)) 

if q == 1 and name != sv and name != ov: 

names = [name, ''] 

else: 

names = [name + str(i) for i in range(q + 1)] 

 

if both_maps and not other.is_absolute(): 

other_abs = other.absolute_field('z') 

from_other_abs, to_other_abs = other_abs.structure() 

 

embedding = None 

i = 0 

rets = [] 

for r, a_in_F, b_in_F, k in C: 

r = R(r) 

d = r.degree() 

if d == m and not both_maps: 

rets.append(self) 

elif d == n and not both_maps: 

rets.append(other) 

else: 

k = ZZ(k) 

if subfields_have_embeddings: 

embedding = other.coerce_embedding()(b) + k*self.coerce_embedding()(a) 

F = NumberField(r, names[i], check=False, embedding=embedding) 

i += 1 

if both_maps: 

a_in_F = F(R(a_in_F.lift())) 

b_in_F = F(R(b_in_F.lift())) 

if other.is_absolute(): 

if d == m: 

self_to_F = self.hom([self.gen()]) 

other_to_F = other.hom([(~self.hom([a_in_F]))(b_in_F)]) 

F = self 

k = Infinity 

i -= 1 

elif d == n: 

other_to_F = other.hom([other.gen()]) 

self_to_F = self.hom([(~other.hom([b_in_F]))(a_in_F)]) 

F = other 

k = ZZ.zero() 

i -= 1 

else: 

self_to_F = self.hom([a_in_F]) 

other_to_F = other.hom([b_in_F]) 

else: 

other_abs_to_F = other_abs.hom([b_in_F]) 

other_to_F = RelativeNumberFieldHomomorphism_from_abs(other.Hom(F), other_abs_to_F*to_other_abs) 

if d == m: 

self_to_F = self.hom([self.gen()]) 

other_to_F = RelativeNumberFieldHomomorphism_from_abs(other.Hom(self), (~self.hom([a_in_F]))*other_abs_to_F*to_other_abs) 

F = self 

k = None 

i -= 1 

elif d == n: 

other_to_F = RelativeNumberFieldHomomorphism_from_abs(other.Hom(other), from_other_abs) 

self_to_F = self.hom([from_other_abs((~other_abs_to_F)(a_in_F))]) 

F = other 

k = None 

i -= 1 

else: 

self_to_F = self.hom([a_in_F]) 

other_to_F = RelativeNumberFieldHomomorphism_from_abs(other.Hom(F), other_abs_to_F*to_other_abs) 

rets.append( (F, self_to_F, other_to_F, k) ) 

else: 

rets.append(F) 

return rets 

 

def absolute_degree(self): 

""" 

Return the degree of self over `\QQ`. 

 

EXAMPLES:: 

 

sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').absolute_degree() 

3 

sage: NumberField(x + 1, 'a').absolute_degree() 

1 

sage: NumberField(x^997 + 17*x + 3, 'a', check=False).absolute_degree() 

997 

""" 

return self.polynomial().degree() 

 

def degree(self): 

""" 

Return the degree of this number field. 

 

EXAMPLES:: 

 

sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').degree() 

3 

sage: NumberField(x + 1, 'a').degree() 

1 

sage: NumberField(x^997 + 17*x + 3, 'a', check=False).degree() 

997 

""" 

return self.polynomial().degree() 

 

def different(self): 

r""" 

Compute the different fractional ideal of this number field. 

 

The codifferent is the fractional ideal of all `x` in `K` 

such that the trace of `xy` is an integer for 

all `y \in O_K`. 

 

The different is the integral ideal which is the inverse of 

the codifferent. 

 

See :wikipedia:`Different_ideal` 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^2 + 23) 

sage: d = k.different() 

sage: d 

Fractional ideal (-a) 

sage: d.norm() 

23 

sage: k.disc() 

-23 

 

The different is cached:: 

 

sage: d is k.different() 

True 

 

Another example:: 

 

sage: k.<b> = NumberField(x^2 - 123) 

sage: d = k.different(); d 

Fractional ideal (2*b) 

sage: d.norm() 

492 

sage: k.disc() 

492 

""" 

try: 

return self.__different 

except AttributeError: 

self.__different = self.ideal(self.pari_nf().nf_get_diff()) 

return self.__different 

 

def discriminant(self, v=None): 

""" 

Returns the discriminant of the ring of integers of the number 

field, or if v is specified, the determinant of the trace pairing 

on the elements of the list v. 

 

INPUT: 

 

- ``v`` -- (optional) list of elements of this number field 

 

OUTPUT: 

 

Integer if `v` is omitted, and Rational otherwise. 

 

EXAMPLES:: 

 

sage: K.<t> = NumberField(x^3 + x^2 - 2*x + 8) 

sage: K.disc() 

-503 

sage: K.disc([1, t, t^2]) 

-2012 

sage: K.disc([1/7, (1/5)*t, (1/3)*t^2]) 

-2012/11025 

sage: (5*7*3)^2 

11025 

sage: NumberField(x^2 - 1/2, 'a').discriminant() 

8 

""" 

if v is None: 

try: 

return self.__disc 

except AttributeError: 

self.__disc = ZZ(self.pari_polynomial().nfdisc()) 

return self.__disc 

else: 

return QQ(self.trace_pairing(v).det()) 

 

def disc(self, v=None): 

""" 

Shortcut for self.discriminant. 

 

EXAMPLES:: 

 

sage: k.<b> = NumberField(x^2 - 123) 

sage: k.disc() 

492 

""" 

return self.discriminant(v=v) 

 

def trace_dual_basis(self, b): 

r""" 

Compute the dual basis of a basis of ``self`` with respect to the trace pairing. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 + x + 1) 

sage: b = [1, 2*a, 3*a^2] 

sage: T = K.trace_dual_basis(b); T 

[4/31*a^2 - 6/31*a + 13/31, -9/62*a^2 - 1/31*a - 3/31, 2/31*a^2 - 3/31*a + 4/93] 

sage: [(b[i]*T[j]).trace() for i in range(3) for j in range(3)] 

[1, 0, 0, 0, 1, 0, 0, 0, 1] 

""" 

if not len(b) == self.degree(): 

raise ValueError('Not a basis of the number field.') 

M = self.trace_pairing(b) 

if not M.is_invertible(): 

raise ValueError('Not a basis of the number field.') 

return [sum([v[i]*b[i] for i in range(len(b))]) for v in M.inverse()] 

 

def elements_of_norm(self, n, proof=None): 

""" 

Return a list of elements of norm ``n``. 

 

INPUT: 

 

- ``n`` -- integer in this number field 

 

- ``proof`` -- boolean (default: ``True``, unless you called 

``number_field_proof`` and set it otherwise) 

 

OUTPUT: 

 

A complete system of integral elements of norm `n`, modulo 

units of positive norm. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2+1) 

sage: K.elements_of_norm(3) 

[] 

sage: K.elements_of_norm(50) 

[-7*a + 1, 5*a - 5, 7*a + 1] 

 

TESTS: 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(7/9*x^3 + 7/3*x^2 - 56*x + 123) 

sage: K.elements_of_norm(7) 

[7/225*a^2 - 7/75*a - 42/25] 

""" 

proof = proof_flag(proof) 

B = self.pari_bnf(proof).bnfisintnorm(n) 

return [self(x, check=False) for x in B] 

 

def extension(self, poly, name=None, names=None, *args, **kwds): 

""" 

Return the relative extension of this field by a given polynomial. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 - 2) 

sage: R.<t> = K[] 

sage: L.<b> = K.extension(t^2 + a); L 

Number Field in b with defining polynomial t^2 + a over its base field 

 

We create another extension:: 

 

sage: k.<a> = NumberField(x^2 + 1); k 

Number Field in a with defining polynomial x^2 + 1 

sage: y = polygen(QQ,'y') 

sage: m.<b> = k.extension(y^2 + 2); m 

Number Field in b with defining polynomial y^2 + 2 over its base field 

 

Note that b is a root of `y^2 + 2`:: 

 

sage: b.minpoly() 

x^2 + 2 

sage: b.minpoly('z') 

z^2 + 2 

 

A relative extension of a relative extension:: 

 

sage: k.<a> = NumberField([x^2 + 1, x^3 + x + 1]) 

sage: R.<z> = k[] 

sage: L.<b> = NumberField(z^3 + 3 + a); L 

Number Field in b with defining polynomial z^3 + a0 + 3 over its base field 

 

Extension fields with given defining data are unique 

(:trac:`20791`):: 

 

sage: K.<a> = NumberField(x^2 + 1) 

sage: K.extension(x^2 - 2, 'b') is K.extension(x^2 - 2, 'b') 

True 

""" 

if not isinstance(poly, polynomial_element.Polynomial): 

try: 

poly = poly.polynomial(self) 

except (AttributeError, TypeError): 

raise TypeError("polynomial (=%s) must be a polynomial."%repr(poly)) 

if poly.base_ring() is not self: 

poly = poly.change_ring(self) 

if names is not None: 

name = names 

if isinstance(name, tuple): 

name = name[0] 

return NumberField(poly, name, *args, **kwds) 

 

def factor(self, n): 

r""" 

Ideal factorization of the principal ideal generated by `n`. 

 

EXAMPLES: 

 

Here we show how to factor Gaussian integers (up to units). 

First we form a number field defined by `x^2 + 1`:: 

 

sage: K.<I> = NumberField(x^2 + 1); K 

Number Field in I with defining polynomial x^2 + 1 

 

Here are the factors:: 

 

sage: fi, fj = K.factor(17); fi,fj 

((Fractional ideal (I + 4), 1), (Fractional ideal (I - 4), 1)) 

 

Now we extract the reduced form of the generators:: 

 

sage: zi = fi[0].gens_reduced()[0]; zi 

I + 4 

sage: zj = fj[0].gens_reduced()[0]; zj 

I - 4 

 

We recover the integer that was factored in `\ZZ[i]` (up to a unit):: 

 

sage: zi*zj 

-17 

 

One can also factor elements or ideals of the number field:: 

 

sage: K.<a> = NumberField(x^2 + 1) 

sage: K.factor(1/3) 

(Fractional ideal (3))^-1 

sage: K.factor(1+a) 

Fractional ideal (a + 1) 

sage: K.factor(1+a/5) 

(Fractional ideal (a + 1)) * (Fractional ideal (-a - 2))^-1 * (Fractional ideal (2*a + 1))^-1 * (Fractional ideal (-3*a - 2)) 

 

An example over a relative number field:: 

 

sage: pari('setrand(2)') 

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

sage: f = L.factor(a + 1); f 

(Fractional ideal (1/2*a*b - a + 1/2)) * (Fractional ideal (-1/2*a*b - a + 1/2)) 

sage: f.value() == a+1 

True 

 

It doesn't make sense to factor the ideal (0), so this raises an error:: 

 

sage: L.factor(0) 

Traceback (most recent call last): 

... 

AttributeError: 'NumberFieldIdeal' object has no attribute 'factor' 

 

AUTHORS: 

 

- Alex Clemesha (2006-05-20), Francis Clarke (2009-04-21): examples 

""" 

return self.ideal(n).factor() 

 

def prime_factors(self, x): 

""" 

Return a list of the prime ideals of self which divide 

the ideal generated by `x`. 

 

OUTPUT: list of prime ideals (a new list is returned each time this 

function is called) 

 

EXAMPLES:: 

 

sage: K.<w> = NumberField(x^2 + 23) 

sage: K.prime_factors(w + 1) 

[Fractional ideal (2, 1/2*w - 1/2), Fractional ideal (2, 1/2*w + 1/2), Fractional ideal (3, 1/2*w + 1/2)] 

""" 

return self.ideal(x).prime_factors() 

 

def gen(self, n=0): 

""" 

Return the generator for this number field. 

 

INPUT: 

 

 

- ``n`` - must be 0 (the default), or an exception is 

raised. 

 

 

EXAMPLES:: 

 

sage: k.<theta> = NumberField(x^14 + 2); k 

Number Field in theta with defining polynomial x^14 + 2 

sage: k.gen() 

theta 

sage: k.gen(1) 

Traceback (most recent call last): 

... 

IndexError: Only one generator. 

""" 

if n != 0: 

raise IndexError("Only one generator.") 

try: 

return self.__gen 

except AttributeError: 

if self.__polynomial is not None: 

X = self.__polynomial.parent().gen() 

else: 

X = PolynomialRing(QQ).gen() 

self.__gen = self._element_class(self, X) 

return self.__gen 

 

@cached_method 

def _generator_matrix(self): 

""" 

Return the matrix form of the generator of ``self``. 

 

.. SEEALSO:: 

 

:meth:`~sage.rings.number_field.number_field_element.NumberFieldElement.matrix` 

 

EXAMPLES:: 

 

sage: x = QQ['x'].gen() 

sage: K.<v> = NumberField(x^4 + 514*x^2 + 64321) 

sage: R.<r> = NumberField(x^2 + 4*v*x + 5*v^2 + 514) 

sage: R._generator_matrix() 

[ 0 1] 

[-5*v^2 - 514 -4*v] 

""" 

x = self.gen() 

a = x 

d = self.relative_degree() 

v = x.list() 

for n in range(d-1): 

a *= x 

v += a.list() 

from sage.matrix.matrix_space import MatrixSpace 

M = MatrixSpace(self.base_ring(), d) 

ret = M(v) 

ret.set_immutable() 

return ret 

 

def is_field(self, proof=True): 

""" 

Return True since a number field is a field. 

 

EXAMPLES:: 

 

sage: NumberField(x^5 + x + 3, 'c').is_field() 

True 

""" 

return True 

 

def is_galois(self): 

r""" 

Return True if this number field is a Galois extension of 

`\QQ`. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 1, 'i').is_galois() 

True 

sage: NumberField(x^3 + 2, 'a').is_galois() 

False 

sage: NumberField(x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 1, 'a').is_galois() 

True 

sage: NumberField(x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 10, 'a').is_galois() 

False 

""" 

#return self.galois_group(type="pari").order() == self.degree() 

if self.degree() < 12: 

return self.galois_group(type='pari').order() == self.degree() 

else: 

return len(self.automorphisms()) == self.degree() 

 

@cached_method 

def is_abelian(self): 

r""" 

Return True if this number field is an abelian Galois extension of 

`\QQ`. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 1, 'i').is_abelian() 

True 

sage: NumberField(x^3 + 2, 'a').is_abelian() 

False 

sage: NumberField(x^3 + x^2 - 2*x - 1, 'a').is_abelian() 

True 

sage: NumberField(x^6 + 40*x^3 + 1372, 'a').is_abelian() 

False 

sage: NumberField(x^6 + x^5 - 5*x^4 - 4*x^3 + 6*x^2 + 3*x - 1, 'a').is_abelian() 

True 

""" 

 

if not self.is_galois(): 

return False 

 

d = self.degree() 

dsqrt = d.isqrt() 

if d == 1 or d.is_prime() or (d == dsqrt**2 and dsqrt.is_prime()): 

return True 

 

if d <= 11: 

return self.galois_group().is_abelian() 

 

pari_pol = pari(self.polynomial()) 

return pari_pol.galoisinit().galoisisabelian(1)==1 

 

@cached_method 

def galois_group(self, type=None, algorithm='pari', names=None): 

r""" 

Return the Galois group of the Galois closure of this number field. 

 

INPUT: 

 

- ``type`` - ``none``, ``gap``, or ``pari``. If None (the default), 

return an explicit group of automorphisms of self as a 

``GaloisGroup_v2`` object. Otherwise, return a ``GaloisGroup_v1`` 

wrapper object based on a PARI or Gap transitive group object, which 

is quicker to compute, but rather less useful (in particular, it 

can't be made to act on self). If type = 'gap', the database_gap 

package should be installed. 

 

- ``algorithm`` - 'pari', 'kash', 'magma'. (default: 'pari', except 

when the degree is >= 12 when 'kash' is tried.) 

 

- ``name`` - a string giving a name for the generator of the Galois 

closure of self, when self is not Galois. This is ignored if type is 

not None. 

 

Note that computing Galois groups as abstract groups is often much 

faster than computing them as explicit automorphism groups (but of 

course you get less information out!) For more (important!) 

documentation, so the documentation for Galois groups of polynomials 

over `\QQ`, e.g., by typing ``K.polynomial().galois_group?``, 

where `K` is a number field. 

 

To obtain actual field homomorphisms from the number field to its 

splitting field, use type=None. 

 

EXAMPLES: 

 

With type ``None``:: 

 

sage: k.<b> = NumberField(x^2 - 14) # a Galois extension 

sage: G = k.galois_group(); G 

Galois group of Number Field in b with defining polynomial x^2 - 14 

sage: G.gen(0) 

(1,2) 

sage: G.gen(0)(b) 

-b 

sage: G.artin_symbol(k.primes_above(3)[0]) 

(1,2) 

 

sage: k.<b> = NumberField(x^3 - x + 1) # not Galois 

sage: G = k.galois_group(names='c'); G 

Galois group of Galois closure in c of Number Field in b with defining polynomial x^3 - x + 1 

sage: G.gen(0) 

(1,2,3)(4,5,6) 

 

With type ``'pari'``:: 

 

sage: NumberField(x^3-2, 'a').galois_group(type="pari") 

Galois group PARI group [6, -1, 2, "S3"] of degree 3 of the Number Field in a with defining polynomial x^3 - 2 

 

:: 

 

sage: NumberField(x-1, 'a').galois_group(type="gap") # optional - database_gap 

Galois group Transitive group number 1 of degree 1 of the Number Field in a with defining polynomial x - 1 

sage: NumberField(x^2+2, 'a').galois_group(type="gap") # optional - database_gap 

Galois group Transitive group number 1 of degree 2 of the Number Field in a with defining polynomial x^2 + 2 

sage: NumberField(x^3-2, 'a').galois_group(type="gap") # optional - database_gap 

Galois group Transitive group number 2 of degree 3 of the Number Field in a with defining polynomial x^3 - 2 

 

:: 

 

sage: x = polygen(QQ) 

sage: NumberField(x^3 + 2*x + 1, 'a').galois_group(type='gap') # optional - database_gap 

Galois group Transitive group number 2 of degree 3 of the Number Field in a with defining polynomial x^3 + 2*x + 1 

sage: NumberField(x^3 + 2*x + 1, 'a').galois_group(algorithm='magma') # optional - magma database_gap 

Galois group Transitive group number 2 of degree 3 of the Number Field in a with defining polynomial x^3 + 2*x + 1 

 

EXPLICIT GALOIS GROUP: We compute the Galois group as an explicit 

group of automorphisms of the Galois closure of a field. 

 

:: 

 

sage: K.<a> = NumberField(x^3 - 2) 

sage: L.<b1> = K.galois_closure(); L 

Number Field in b1 with defining polynomial x^6 + 108 

sage: G = End(L); G 

Automorphism group of Number Field in b1 with defining polynomial x^6 + 108 

sage: G.list() 

[ 

Ring endomorphism of Number Field in b1 with defining polynomial x^6 + 108 

Defn: b1 |--> b1, 

... 

Ring endomorphism of Number Field in b1 with defining polynomial x^6 + 108 

Defn: b1 |--> -1/12*b1^4 - 1/2*b1 

] 

sage: G[2](b1) 

1/12*b1^4 + 1/2*b1 

""" 

from .galois_group import GaloisGroup_v1, GaloisGroup_v2 

 

if type is None: 

return GaloisGroup_v2(self, names) 

 

elif type=="pari": 

return GaloisGroup_v1(self.absolute_polynomial().galois_group(pari_group=True, algorithm=algorithm), self) 

elif type=="gap": 

return GaloisGroup_v1(self.absolute_polynomial().galois_group(pari_group=False, algorithm=algorithm), self) 

else: 

raise ValueError("Galois group type must be None, 'pari', or 'gap'.") 

 

def _normalize_prime_list(self, v): 

""" 

Internal function to convert into a tuple of primes either None or 

a single prime or a list. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K._normalize_prime_list(None) 

() 

sage: K._normalize_prime_list(3) 

(3,) 

sage: K._normalize_prime_list([3,5]) 

(3, 5) 

""" 

if v is None: 

v = [] 

elif not isinstance(v, (list, tuple)): 

v = [v] 

return tuple(map(ZZ, v)) 

 

def power_basis(self): 

r""" 

Return a power basis for this number field over its base field. 

 

If this number field is represented as `k[t]/f(t)`, then 

the basis returned is `1, t, t^2, \ldots, t^{d-1}` where 

`d` is the degree of this number field over its base 

field. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^5 + 10*x + 1) 

sage: K.power_basis() 

[1, a, a^2, a^3, a^4] 

 

:: 

 

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

sage: L.power_basis() 

[1, b] 

sage: L.absolute_field('c').power_basis() 

[1, c, c^2, c^3, c^4, c^5, c^6, c^7, c^8, c^9] 

 

:: 

 

sage: M = CyclotomicField(15) 

sage: M.power_basis() 

[1, zeta15, zeta15^2, zeta15^3, zeta15^4, zeta15^5, zeta15^6, zeta15^7] 

""" 

g = self.gen() 

return [ g**i for i in range(self.relative_degree()) ] 

 

def integral_basis(self, v=None): 

""" 

Returns a list containing a ZZ-basis for the full ring of integers 

of this number field. 

 

INPUT: 

 

 

- ``v`` - None, a prime, or a list of primes. See the 

documentation for self.maximal_order. 

 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^5 + 10*x + 1) 

sage: K.integral_basis() 

[1, a, a^2, a^3, a^4] 

 

Next we compute the ring of integers of a cubic field in which 2 is 

an "essential discriminant divisor", so the ring of integers is not 

generated by a single element. 

 

:: 

 

sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8) 

sage: K.integral_basis() 

[1, 1/2*a^2 + 1/2*a, a^2] 

 

ALGORITHM: Uses the pari library (via _pari_integral_basis). 

""" 

return self.maximal_order(v=v).basis() 

 

def _pari_integral_basis(self, v=None, important=True): 

""" 

Internal function returning an integral basis of this number field in 

PARI format. 

 

INPUT: 

 

- ``v`` -- None, a prime, or a list of primes. See the 

documentation for self.maximal_order. 

 

- ``important`` -- boolean (default: ``True``). If ``False``, 

raise a ``RuntimeError`` if we need to do a difficult 

discriminant factorization. This is useful when an integral 

basis is not strictly required. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^5 + 10*x + 1) 

sage: K._pari_integral_basis() 

[1, y, y^2, y^3, y^4] 

 

Next we compute the ring of integers of a cubic field in which 2 is 

an "essential discriminant divisor", so the ring of integers is not 

generated by a single element. 

 

:: 

 

sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8) 

sage: K._pari_integral_basis() 

[1, y, 1/2*y^2 - 1/2*y] 

sage: K.integral_basis() 

[1, 1/2*a^2 + 1/2*a, a^2] 

""" 

if (v is None or len(v) == 0) and self._maximize_at_primes: 

v = self._maximize_at_primes 

 

v = self._normalize_prime_list(v) 

try: 

return self._integral_basis_dict[v] 

except (AttributeError, KeyError): 

f = self.pari_polynomial("y") 

if len(v) > 0: 

B = f.nfbasis(fa=v) 

elif self._assume_disc_small: 

B = f.nfbasis(1) 

elif not important: 

# Trial divide the discriminant with primes up to 10^6 

m = self.pari_polynomial().poldisc().abs().factor(limit=10**6) 

# Since we only need a *squarefree* factorization for 

# primes with exponent 1, we need trial division up to D^(1/3) 

# instead of D^(1/2). 

trialdivlimit2 = pari(10**12) 

trialdivlimit3 = pari(10**18) 

if all([ p < trialdivlimit2 or (e == 1 and p < trialdivlimit3) or p.isprime() for p,e in zip(m[0],m[1]) ]): 

B = f.nfbasis(fa = m) 

else: 

raise RuntimeError("Unable to factor discriminant with trial division") 

else: 

B = f.nfbasis() 

 

self._integral_basis_dict[v] = B 

return B 

 

def reduced_basis(self, prec=None): 

r""" 

This function returns an LLL-reduced basis for the 

Minkowski-embedding of the maximal order of a number field. 

 

INPUT: 

 

- ``self`` - number field, the base field 

 

- ``prec (default: None)`` - the precision with which to 

compute the Minkowski embedding. 

 

 

OUTPUT: 

 

An LLL-reduced basis for the Minkowski-embedding of the 

maximal order of a number field, given by a sequence of (integral) 

elements from the field. 

 

.. note:: 

 

In the non-totally-real case, the LLL routine we call is 

currently PARI's :pari:`qflll`, which works with floating point 

approximations, and so the result is only as good as the 

precision promised by PARI. The matrix returned will always 

be integral; however, it may only be only "almost" LLL-reduced 

when the precision is not sufficiently high. 

 

EXAMPLES:: 

 

sage: F.<t> = NumberField(x^6-7*x^4-x^3+11*x^2+x-1) 

sage: F.maximal_order().basis() 

[1/2*t^5 + 1/2*t^4 + 1/2*t^2 + 1/2, t, t^2, t^3, t^4, t^5] 

sage: F.reduced_basis() 

[-1, -1/2*t^5 + 1/2*t^4 + 3*t^3 - 3/2*t^2 - 4*t - 1/2, t, 1/2*t^5 + 1/2*t^4 - 4*t^3 - 5/2*t^2 + 7*t + 1/2, 1/2*t^5 - 1/2*t^4 - 2*t^3 + 3/2*t^2 - 1/2, 1/2*t^5 - 1/2*t^4 - 3*t^3 + 5/2*t^2 + 4*t - 5/2] 

sage: CyclotomicField(12).reduced_basis() 

[1, zeta12^2, zeta12, zeta12^3] 

 

TESTS: 

 

Check that the bug reported at :trac:`10017` is fixed:: 

 

sage: x = polygen(QQ) 

sage: k.<a> = NumberField(x^6 + 2218926655879913714112*x^4 - 32507675650290949030789018433536*x^3 + 4923635504174417014460581055002374467948544*x^2 - 36066074010564497464129951249279114076897746988630016*x + 264187244046129768986806800244258952598300346857154900812365824) 

sage: new_basis = k.reduced_basis(prec=120) 

sage: [c.minpoly() for c in new_basis] 

[x - 1, 

x^2 - x + 1, 

x^6 + 3*x^5 - 102*x^4 - 103*x^3 + 10572*x^2 - 59919*x + 127657, 

x^6 - 3*x^5 - 102*x^4 + 315*x^3 + 10254*x^2 - 80955*x + 198147, 

x^3 - 171*x + 848, 

x^6 + 171*x^4 + 1696*x^3 + 29241*x^2 + 145008*x + 719104] 

sage: R = k.order(new_basis) 

sage: R.discriminant()==k.discriminant() 

True 

""" 

ZK = self.integral_basis() 

d = self.absolute_degree() 

 

# If self is totally real, then we can use (x*y).trace() as 

# the inner product on the Minkowski embedding, which is 

# faster than computing all the conjugates, etc ... 

 

if self.is_totally_real(): 

from sage.matrix.constructor import matrix 

T = pari(matrix(ZZ, d, d, [[(x*y).trace() for x in ZK] for y in ZK])).qflllgram() 

else: 

M = self.minkowski_embedding(ZK, prec=prec) 

T = pari(M).qflll() 

 

return [ sum([ ZZ(T[i][j]) * ZK[j] for j in range(d)]) for i in range(d)] 

 

def reduced_gram_matrix(self, prec=None): 

r""" 

This function returns the Gram matrix of an LLL-reduced basis for 

the Minkowski embedding of the maximal order of a number field. 

 

INPUT: 

 

 

- ``self`` - number field, the base field 

 

- ``prec (default: None)`` - the precision with which 

to calculate the Minkowski embedding. (See NOTE below.) 

 

 

OUTPUT: The Gram matrix `[\langle x_i,x_j \rangle]` of an LLL reduced 

basis for the maximal order of self, where the integral basis for 

self is given by `\{x_0, \dots, x_{n-1}\}`. Here `\langle , \rangle` is 

the usual inner product on `\RR^n`, and self is embedded in `\RR^n` by 

the Minkowski embedding. See the docstring for 

:meth:`NumberField_absolute.minkowski_embedding` for more information. 

 

.. note:: 

 

In the non-totally-real case, the LLL routine we call is 

currently PARI's :pari:`qflll`, which works with floating point 

approximations, and so the result is only as good as the 

precision promised by PARI. In particular, in this case, 

the returned matrix will *not* be integral, and may not 

have enough precision to recover the correct gram matrix 

(which is known to be integral for theoretical 

reasons). Thus the need for the prec flag above. 

 

If the following run-time error occurs: "PariError: not a definite 

matrix in lllgram (42)" try increasing the prec parameter, 

 

EXAMPLES:: 

 

sage: F.<t> = NumberField(x^6-7*x^4-x^3+11*x^2+x-1) 

sage: F.reduced_gram_matrix() 

[ 6 3 0 2 0 1] 

[ 3 9 0 1 0 -2] 

[ 0 0 14 6 -2 3] 

[ 2 1 6 16 -3 3] 

[ 0 0 -2 -3 16 6] 

[ 1 -2 3 3 6 19] 

sage: Matrix(6, [(x*y).trace() for x in F.integral_basis() for y in F.integral_basis()]) 

[2550 133 259 664 1368 3421] 

[ 133 14 3 54 30 233] 

[ 259 3 54 30 233 217] 

[ 664 54 30 233 217 1078] 

[1368 30 233 217 1078 1371] 

[3421 233 217 1078 1371 5224] 

 

:: 

 

sage: x = polygen(QQ) 

sage: F.<alpha> = NumberField(x^4+x^2+712312*x+131001238) 

sage: F.reduced_gram_matrix(prec=128) 

[ 4.0000000000000000000000000000000000000 0.00000000000000000000000000000000000000 -1.9999999999999999999999999999999999037 -0.99999999999999999999999999999999383702] 

[ 0.00000000000000000000000000000000000000 46721.539331563218381658483353092335550 -11488.910026551724275122749703614966768 -418.12718083977141198754424579680468382] 

[ -1.9999999999999999999999999999999999037 -11488.910026551724275122749703614966768 5.5658915310500611768713076521847709187e8 1.4179092271494070050433368847682152174e8] 

[ -0.99999999999999999999999999999999383702 -418.12718083977141198754424579680468382 1.4179092271494070050433368847682152174e8 1.3665897267919181137884111201405279175e12] 

""" 

if self.is_totally_real(): 

try: 

return self.__reduced_gram_matrix 

except AttributeError: 

pass 

else: 

try: 

if self.__reduced_gram_matrix_prec >= prec: 

return self.__reduced_gram_matrix 

except AttributeError: 

pass 

 

from sage.matrix.constructor import matrix 

from sage.misc.flatten import flatten 

d = self.absolute_degree() 

 

if self.is_totally_real(): 

B = self.reduced_basis() 

self.__reduced_gram_matrix = matrix(ZZ, d, d, 

[[(x*y).trace() for x in B] 

for y in B]) 

else: 

M = self.minkowski_embedding(prec=prec) 

T = matrix(d, flatten([ a.vector().list() 

for a in self.reduced_basis(prec=prec) ])) 

A = M*(T.transpose()) 

self.__reduced_gram_matrix = A.transpose()*A 

if prec is None: 

## this is the default choice for minkowski_embedding 

self.__reduced_gram_matrix_prec = 53 

else: 

self.__reduced_gram_matrix_prec = prec 

 

return self.__reduced_gram_matrix 

 

 

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

# Supplementary algorithm to enumerate lattice points 

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

 

def _positive_integral_elements_with_trace(self, C): 

r""" 

Find all totally positive integral elements in self whose 

trace is between C[0] and C[1], inclusive. 

 

.. note:: 

 

This is currently only implemented in the case that self is 

totally real, since it requires exact computation of 

:meth:`.reduced_gram_matrix`. 

 

EXAMPLES:: 

 

sage: K.<alpha> = NumberField(ZZ['x'].0^2-2) 

sage: K._positive_integral_elements_with_trace([0,5]) 

[alpha + 2, -alpha + 2, 2, 1] 

sage: L.<beta> = NumberField(ZZ['x'].0^2+1) 

sage: L._positive_integral_elements_with_trace([5,11]) 

Traceback (most recent call last): 

... 

NotImplementedError: exact computation of LLL reduction only implemented in the totally real case 

sage: L._positive_integral_elements_with_trace([-5,1]) 

Traceback (most recent call last): 

... 

ValueError: bounds must be positive 

""" 

if C[0] < 0: 

raise ValueError("bounds must be positive") 

 

if not self.is_totally_real(): 

raise NotImplementedError("exact computation of LLL reduction only implemented in the totally real case") 

 

Z_F = self.maximal_order() 

B = self.reduced_basis() 

T = self.reduced_gram_matrix() 

P = pari(T).qfminim((C[1]**2)*(1./2), 10**6)[2] 

 

S = [] 

for p in P: 

theta = sum([ p.list()[i]*B[i] for i in range(self.degree())]) 

if theta.trace() < 0: 

theta *= -1 

if theta.trace() >= C[0] and theta.trace() <= C[1]: 

if self(theta).is_totally_positive(): 

S.append(self(theta)) 

return S 

 

 

def zeta_function(self, prec=53, 

max_imaginary_part=0, 

max_asymp_coeffs=40): 

r""" 

Return the Zeta function of this number field. 

 

This actually returns an interface to Tim Dokchitser's program for 

computing with the Dedekind zeta function zeta_F(s) of the number 

field F. 

 

INPUT: 

 

 

- ``prec`` - integer (bits precision) 

 

- ``max_imaginary_part`` - real number 

 

- ``max_asymp_coeffs`` - integer 

 

 

OUTPUT: The zeta function of this number field. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(ZZ['x'].0^2+ZZ['x'].0-1) 

sage: Z = K.zeta_function() 

sage: Z 

Zeta function associated to Number Field in a with defining polynomial x^2 + x - 1 

sage: Z(-1) 

0.0333333333333333 

sage: L.<a, b, c> = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) 

sage: Z = L.zeta_function() 

sage: Z(5) 

1.00199015670185 

""" 

from sage.lfunctions.all import Dokchitser 

key = (prec, max_imaginary_part, max_asymp_coeffs) 

r1 = self.signature()[0] 

r2 = self.signature()[1] 

zero = [0] 

one = [1] 

Z = Dokchitser(conductor = abs(self.absolute_discriminant()), 

gammaV = (r1+r2)*zero + r2*one, 

weight = 1, 

eps = 1, 

poles = [1], 

prec = prec) 

s = 'nf = nfinit(%s);'%self.absolute_polynomial() 

s += 'dzk = dirzetak(nf,cflength());' 

Z.init_coeffs('dzk[k]', pari_precode=s, 

max_imaginary_part=max_imaginary_part, 

max_asymp_coeffs=max_asymp_coeffs) 

Z.check_functional_equation() 

Z.rename('Zeta function associated to %s'%self) 

return Z 

 

@cached_method 

def narrow_class_group(self, proof=None): 

r""" 

Return the narrow class group of this field. 

 

INPUT: 

 

- ``proof`` - default: None (use the global proof 

setting, which defaults to True). 

 

EXAMPLES:: 

 

sage: NumberField(x^3+x+9, 'a').narrow_class_group() 

Multiplicative Abelian group isomorphic to C2 

 

TESTS:: 

 

sage: QuadraticField(3, 'a').narrow_class_group() 

Multiplicative Abelian group isomorphic to C2 

""" 

proof = proof_flag(proof) 

k = self.pari_bnf(proof) 

s = k.bnfnarrow().sage() 

return sage.groups.abelian_gps.abelian_group.AbelianGroup(s[1]) 

 

def ngens(self): 

""" 

Return the number of generators of this number field (always 1). 

 

OUTPUT: the python integer 1. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 17,'a').ngens() 

1 

sage: NumberField(x + 3,'a').ngens() 

1 

sage: k.<a> = NumberField(x + 3) 

sage: k.ngens() 

1 

sage: k.0 

-3 

""" 

return 1 

 

def order(self): 

""" 

Return the order of this number field (always +infinity). 

 

OUTPUT: always positive infinity 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + 19,'a').order() 

+Infinity 

""" 

return infinity.infinity 

 

def absolute_polynomial_ntl(self): 

r""" 

Alias for :meth:`~polynomial_ntl`. Mostly for internal use. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + (2/3)*x - 9/17,'a').absolute_polynomial_ntl() 

([-27 34 51], 51) 

""" 

return self.polynomial_ntl() 

 

def polynomial_ntl(self): 

""" 

Return defining polynomial of this number field as a pair, an ntl 

polynomial and a denominator. 

 

This is used mainly to implement some internal arithmetic. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + (2/3)*x - 9/17,'a').polynomial_ntl() 

([-27 34 51], 51) 

""" 

try: 

return (self.__polynomial_ntl, self.__denominator_ntl) 

except AttributeError: 

self.__denominator_ntl = ntl.ZZ() 

den = self.polynomial().denominator() 

self.__denominator_ntl.set_from_sage_int(ZZ(den)) 

self.__polynomial_ntl = ntl.ZZX((self.polynomial()*den).list()) 

return (self.__polynomial_ntl, self.__denominator_ntl) 

 

def polynomial(self): 

""" 

Return the defining polynomial of this number field. 

 

This is exactly the same as 

``self.defining_polynomial()``. 

 

EXAMPLES:: 

 

sage: NumberField(x^2 + (2/3)*x - 9/17,'a').polynomial() 

x^2 + 2/3*x - 9/17 

""" 

return self.__polynomial 

 

def defining_polynomial(self): # do not overload this -- overload polynomial instead 

""" 

Return the defining polynomial of this number field. 

 

This is exactly the same as ``self.polynomial()``. 

 

EXAMPLES:: 

 

sage: k5.<z> = CyclotomicField(5) 

sage: k5.defining_polynomial() 

x^4 + x^3 + x^2 + x + 1 

sage: y = polygen(QQ,'y') 

sage: k.<a> = NumberField(y^9 - 3*y + 5); k 

Number Field in a with defining polynomial y^9 - 3*y + 5 

sage: k.defining_polynomial() 

y^9 - 3*y + 5 

""" 

return self.polynomial() 

 

def polynomial_ring(self): 

""" 

Return the polynomial ring that we view this number field as being 

a quotient of (by a principal ideal). 

 

EXAMPLES: An example with an absolute field:: 

 

sage: k.<a> = NumberField(x^2 + 3) 

sage: y = polygen(QQ, 'y') 

sage: k.<a> = NumberField(y^2 + 3) 

sage: k.polynomial_ring() 

Univariate Polynomial Ring in y over Rational Field 

 

An example with a relative field:: 

 

sage: y = polygen(QQ, 'y') 

sage: M.<a> = NumberField([y^3 + 97, y^2 + 1]); M 

Number Field in a0 with defining polynomial y^3 + 97 over its base field 

sage: M.polynomial_ring() 

Univariate Polynomial Ring in y over Number Field in a1 with defining polynomial y^2 + 1 

""" 

return self.relative_polynomial().parent() 

 

def polynomial_quotient_ring(self): 

""" 

Return the polynomial quotient ring isomorphic to this number 

field. 

 

EXAMPLES:: 

 

sage: K = NumberField(x^3 + 2*x - 5, 'alpha') 

sage: K.polynomial_quotient_ring() 

Univariate Quotient Polynomial Ring in alpha over Rational Field with modulus x^3 + 2*x - 5 

""" 

return self.polynomial_ring().quotient(self.relative_polynomial(), self.variable_name()) 

 

def regulator(self, proof=None): 

""" 

Return the regulator of this number field. 

 

Note that PARI computes the regulator to higher precision than the 

Sage default. 

 

INPUT: 

 

 

- ``proof`` - default: True, unless you set it 

otherwise. 

 

 

EXAMPLES:: 

 

sage: NumberField(x^2-2, 'a').regulator() 

0.881373587019543 

sage: NumberField(x^4+x^3+x^2+x+1, 'a').regulator() 

0.962423650119207 

""" 

proof = proof_flag(proof) 

try: 

return self.__regulator 

except AttributeError: 

from sage.rings.all import RealField 

k = self.pari_bnf(proof) 

self.__regulator = RealField(53)(k.bnf_get_reg()) 

return self.__regulator 

 

def residue_field(self, prime, names=None, check=True): 

""" 

Return the residue field of this number field at a given prime, ie 

`O_K / p O_K`. 

 

INPUT: 

 

 

- ``prime`` - a prime ideal of the maximal order in 

this number field, or an element of the field which generates a 

principal prime ideal. 

 

- ``names`` - the name of the variable in the residue 

field 

 

- ``check`` - whether or not to check the primality of 

prime. 

 

 

OUTPUT: The residue field at this prime. 

 

EXAMPLES:: 

 

sage: R.<x> = QQ[] 

sage: K.<a> = NumberField(x^4+3*x^2-17) 

sage: P = K.ideal(61).factor()[0][0] 

sage: K.residue_field(P) 

Residue field in abar of Fractional ideal (61, a^2 + 30) 

 

:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.residue_field(1+i) 

Residue field of Fractional ideal (i + 1) 

 

TESTS:: 

 

sage: L.<b> = NumberField(x^2 + 5) 

sage: L.residue_field(P) 

Traceback (most recent call last): 

... 

ValueError: Fractional ideal (61, a^2 + 30) is not an ideal of Number Field in b with defining polynomial x^2 + 5 

sage: L.residue_field(2) 

Traceback (most recent call last): 

... 

ValueError: Fractional ideal (2) is not a prime ideal 

 

:: 

 

sage: L.residue_field(L.prime_above(5)^2) 

Traceback (most recent call last): 

... 

ValueError: Fractional ideal (5) is not a prime ideal 

""" 

from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal 

if is_NumberFieldIdeal(prime) and prime.number_field() is not self: 

raise ValueError("%s is not an ideal of %s"%(prime,self)) 

# This allows principal ideals to be specified using a generator: 

try: 

prime = self.ideal(prime) 

except TypeError: 

pass 

 

if not is_NumberFieldIdeal(prime) or prime.number_field() is not self: 

raise ValueError("%s is not an ideal of %s"%(prime,self)) 

if check and not prime.is_prime(): 

raise ValueError("%s is not a prime ideal"%prime) 

from sage.rings.finite_rings.residue_field import ResidueField 

return ResidueField(prime, names=names, check=False) 

 

def signature(self): 

""" 

Return (r1, r2), where r1 and r2 are the number of real embeddings 

and pairs of complex embeddings of this field, respectively. 

 

EXAMPLES:: 

 

sage: NumberField(x^2+1, 'a').signature() 

(0, 1) 

sage: NumberField(x^3-2, 'a').signature() 

(1, 1) 

""" 

r1, r2 = self.pari_nf().nf_get_sign() 

return (ZZ(r1), ZZ(r2)) 

 

def trace_pairing(self, v): 

""" 

Return the matrix of the trace pairing on the elements of the list 

`v`. 

 

EXAMPLES:: 

 

sage: K.<zeta3> = NumberField(x^2 + 3) 

sage: K.trace_pairing([1,zeta3]) 

[ 2 0] 

[ 0 -6] 

""" 

import sage.matrix.matrix_space 

A = sage.matrix.matrix_space.MatrixSpace(self.base_ring(), len(v))(0) 

for i in range(len(v)): 

for j in range(i,len(v)): 

t = (self(v[i]*v[j])).trace() 

A[i,j] = t 

A[j,i] = t 

return A 

 

def uniformizer(self, P, others="positive"): 

""" 

Returns an element of self with valuation 1 at the prime ideal P. 

 

INPUT: 

 

 

- ``self`` - a number field 

 

- ``P`` - a prime ideal of self 

 

- ``others`` - either "positive" (default), in which 

case the element will have non-negative valuation at all other 

primes of self, or "negative", in which case the element will have 

non-positive valuation at all other primes of self. 

 

 

.. note:: 

 

When P is principal (e.g. always when self has class number 

one) the result may or may not be a generator of P! 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2 + 5); K 

Number Field in a with defining polynomial x^2 + 5 

sage: P,Q = K.ideal(3).prime_factors() 

sage: P 

Fractional ideal (3, a + 1) 

sage: pi = K.uniformizer(P); pi 

a + 1 

sage: K.ideal(pi).factor() 

(Fractional ideal (2, a + 1)) * (Fractional ideal (3, a + 1)) 

sage: pi = K.uniformizer(P,'negative'); pi 

1/2*a + 1/2 

sage: K.ideal(pi).factor() 

(Fractional ideal (2, a + 1))^-1 * (Fractional ideal (3, a + 1)) 

 

:: 

 

sage: K = CyclotomicField(9) 

sage: Plist=K.ideal(17).prime_factors() 

sage: pilist = [K.uniformizer(P) for P in Plist] 

sage: [pi.is_integral() for pi in pilist] 

[True, True, True] 

sage: [pi.valuation(P) for pi,P in zip(pilist,Plist)] 

[1, 1, 1] 

sage: [ pilist[i] in Plist[i] for i in range(len(Plist)) ] 

[True, True, True] 

 

:: 

 

sage: K.<t> = NumberField(x^4 - x^3 - 3*x^2 - x + 1) 

sage: [K.uniformizer(P) for P,e in factor(K.ideal(2))] 

[2] 

sage: [K.uniformizer(P) for P,e in factor(K.ideal(3))] 

[t - 1] 

sage: [K.uniformizer(P) for P,e in factor(K.ideal(5))] 

[t^2 - t + 1, t + 2, t - 2] 

sage: [K.uniformizer(P) for P,e in factor(K.ideal(7))] 

[t^2 + 3*t + 1] 

sage: [K.uniformizer(P) for P,e in factor(K.ideal(67))] 

[t + 23, t + 26, t - 32, t - 18] 

 

ALGORITHM: 

 

Use PARI. More precisely, use the second component of 

:pari:`idealprimedec` in the "positive" case. Use :pari:`idealappr` 

with exponent of -1 and invert the result in the "negative" 

case. 

""" 

if not is_NumberFieldIdeal(P): 

P = self.ideal(P) 

P = P.pari_prime() 

if others == "positive": 

return self(P[1]) 

elif others == "negative": 

nf = self.pari_nf() 

F = pari.matrix(1, 2, [P, -1]) 

return ~self(nf.idealappr(F, 1)) 

else: 

raise ValueError("others must be 'positive' or 'negative'") 

 

def units(self, proof=None): 

""" 

Return generators for the unit group modulo torsion. 

 

ALGORITHM: Uses PARI's :pari:`bnfunit` command. 

 

INPUT: 

 

- ``proof`` (bool, default True) flag passed to ``pari``. 

 

.. note:: 

 

For more functionality see the unit_group() function. 

 

.. SEEALSO:: 

 

:meth:`unit_group` 

:meth:`S_unit_group` 

:meth:`S_units` 

 

EXAMPLES:: 

 

sage: x = polygen(QQ) 

sage: A = x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3 

sage: K = NumberField(A, 'a') 

sage: K.units() 

(1/275*a^3 - 7/55*a^2 + 6/11*a - 3,) 

 

For big number fields, provably computing the unit group can 

take a very long time. In this case, one can ask for the 

conjectural unit group (correct if the Generalized Riemann 

Hypothesis is true):: 

 

sage: K = NumberField(x^17 + 3, 'a') 

sage: K.units(proof=True) # takes forever, not tested 

... 

sage: K.units(proof=False) # result not independently verified 

(a^9 + a - 1, 

a^15 - a^12 + a^10 - a^9 - 2*a^8 + 3*a^7 + a^6 - 3*a^5 + a^4 + 4*a^3 - 3*a^2 - 2*a + 2, 

a^16 - a^15 + a^14 - a^12 + a^11 - a^10 - a^8 + a^7 - 2*a^6 + a^4 - 3*a^3 + 2*a^2 - 2*a + 1, 

2*a^16 - a^14 - a^13 + 3*a^12 - 2*a^10 + a^9 + 3*a^8 - 3*a^6 + 3*a^5 + 3*a^4 - 2*a^3 - 2*a^2 + 3*a + 4, 

2*a^16 - 3*a^15 + 3*a^14 - 3*a^13 + 3*a^12 - a^11 + a^9 - 3*a^8 + 4*a^7 - 5*a^6 + 6*a^5 - 4*a^4 + 3*a^3 - 2*a^2 - 2*a + 4, 

a^16 - a^15 - 3*a^14 - 4*a^13 - 4*a^12 - 3*a^11 - a^10 + 2*a^9 + 4*a^8 + 5*a^7 + 4*a^6 + 2*a^5 - 2*a^4 - 6*a^3 - 9*a^2 - 9*a - 7, 

a^15 + a^14 + 2*a^11 + a^10 - a^9 + a^8 + 2*a^7 - a^5 + 2*a^3 - a^2 - 3*a + 1, 

5*a^16 - 6*a^14 + a^13 + 7*a^12 - 2*a^11 - 7*a^10 + 4*a^9 + 7*a^8 - 6*a^7 - 7*a^6 + 8*a^5 + 6*a^4 - 11*a^3 - 5*a^2 + 13*a + 4) 

 

TESTS: 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(1/2*x^2 - 1/6) 

sage: K.units() 

(3*a - 2,) 

""" 

proof = proof_flag(proof) 

 

# if we have cached provable results, return them immediately 

try: 

return self.__units 

except AttributeError: 

pass 

 

# if proof==False and we have cached results, return them immediately 

if not proof: 

try: 

return self.__units_no_proof 

except AttributeError: 

pass 

 

# get PARI to compute the units 

B = self.pari_bnf(proof).bnfunit() 

B = tuple(self(b, check=False) for b in B) 

if proof: 

# cache the provable results and return them 

self.__units = B 

return self.__units 

else: 

# cache the conjectural results and return them 

self.__units_no_proof = B 

return self.__units_no_proof 

 

def unit_group(self, proof=None): 

""" 

Return the unit group (including torsion) of this number field. 

 

ALGORITHM: Uses PARI's :pari:`bnfunit` command. 

 

INPUT: 

 

- ``proof`` (bool, default True) flag passed to ``pari``. 

 

.. note:: 

 

The group is cached. 

 

.. SEEALSO:: 

 

:meth:`units` 

:meth:`S_unit_group` 

:meth:`S_units` 

 

EXAMPLES:: 

 

sage: x = QQ['x'].0 

sage: A = x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3 

sage: K = NumberField(A, 'a') 

sage: U = K.unit_group(); U 

Unit group with structure C10 x Z of Number Field in a with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375 

sage: U.gens() 

(u0, u1) 

sage: U.gens_values() # random 

[-1/275*a^3 + 7/55*a^2 - 6/11*a + 4, 1/275*a^3 + 4/55*a^2 - 5/11*a + 3] 

sage: U.invariants() 

(10, 0) 

sage: [u.multiplicative_order() for u in U.gens()] 

[10, +Infinity] 

 

For big number fields, provably computing the unit group can 

take a very long time. In this case, one can ask for the 

conjectural unit group (correct if the Generalized Riemann 

Hypothesis is true):: 

 

sage: K = NumberField(x^17 + 3, 'a') 

sage: K.unit_group(proof=True) # takes forever, not tested 

... 

sage: U = K.unit_group(proof=False) 

sage: U 

Unit group with structure C2 x Z x Z x Z x Z x Z x Z x Z x Z of Number Field in a with defining polynomial x^17 + 3 

sage: U.gens() 

(u0, u1, u2, u3, u4, u5, u6, u7, u8) 

sage: U.gens_values() # result not independently verified 

[-1, a^9 + a - 1, a^15 - a^12 + a^10 - a^9 - 2*a^8 + 3*a^7 + a^6 - 3*a^5 + a^4 + 4*a^3 - 3*a^2 - 2*a + 2, a^16 - a^15 + a^14 - a^12 + a^11 - a^10 - a^8 + a^7 - 2*a^6 + a^4 - 3*a^3 + 2*a^2 - 2*a + 1, 2*a^16 - a^14 - a^13 + 3*a^12 - 2*a^10 + a^9 + 3*a^8 - 3*a^6 + 3*a^5 + 3*a^4 - 2*a^3 - 2*a^2 + 3*a + 4, 2*a^16 - 3*a^15 + 3*a^14 - 3*a^13 + 3*a^12 - a^11 + a^9 - 3*a^8 + 4*a^7 - 5*a^6 + 6*a^5 - 4*a^4 + 3*a^3 - 2*a^2 - 2*a + 4, a^16 - a^15 - 3*a^14 - 4*a^13 - 4*a^12 - 3*a^11 - a^10 + 2*a^9 + 4*a^8 + 5*a^7 + 4*a^6 + 2*a^5 - 2*a^4 - 6*a^3 - 9*a^2 - 9*a - 7, a^15 + a^14 + 2*a^11 + a^10 - a^9 + a^8 + 2*a^7 - a^5 + 2*a^3 - a^2 - 3*a + 1, 5*a^16 - 6*a^14 + a^13 + 7*a^12 - 2*a^11 - 7*a^10 + 4*a^9 + 7*a^8 - 6*a^7 - 7*a^6 + 8*a^5 + 6*a^4 - 11*a^3 - 5*a^2 + 13*a + 4] 

""" 

proof = proof_flag(proof) 

 

try: 

return self._unit_group 

except AttributeError: 

pass 

 

if not proof: 

try: 

return self._unit_group_no_proof 

except AttributeError: 

pass 

 

U = UnitGroup(self,proof) 

if proof: 

self._unit_group = U 

else: 

self._unit_group_no_proof = U 

return U 

 

def S_unit_group(self, proof=None, S=None): 

""" 

Return the S-unit group (including torsion) of this number field. 

 

ALGORITHM: Uses PARI's :pari:`bnfsunit` command. 

 

INPUT: 

 

- ``proof`` (bool, default True) flag passed to ``pari``. 

- ``S`` - list or tuple of prime ideals, or an ideal, or a single 

ideal or element from which an ideal can be constructed, in 

which case the support is used. If None, the global unit 

group is constructed; otherwise, the S-unit group is 

constructed. 

 

.. note:: 

 

The group is cached. 

 

EXAMPLES:: 

 

sage: x = polygen(QQ) 

sage: K.<a> = NumberField(x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3) 

sage: U = K.S_unit_group(S=a); U 

S-unit group with structure C10 x Z x Z x Z of Number Field in a with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375 with S = (Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9)) 

sage: U.gens() 

(u0, u1, u2, u3) 

sage: U.gens_values() # random 

[-1/275*a^3 + 7/55*a^2 - 6/11*a + 4, 1/275*a^3 + 4/55*a^2 - 5/11*a + 3, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5, -14/275*a^3 + 21/55*a^2 - 29/11*a + 6] 

sage: U.invariants() 

(10, 0, 0, 0) 

sage: [u.multiplicative_order() for u in U.gens()] 

[10, +Infinity, +Infinity, +Infinity] 

sage: U.primes() 

(Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9)) 

 

With the default value of `S`, the S-unit group is the same as 

the global unit group:: 

 

sage: x = polygen(QQ) 

sage: K.<a> = NumberField(x^3 + 3) 

sage: U = K.unit_group(proof=False) 

sage: U == K.S_unit_group(proof=False) 

True 

 

The value of `S` may be specified as a list of prime ideals, 

or an ideal, or an element of the field:: 

 

sage: K.<a> = NumberField(x^3 + 3) 

sage: U = K.S_unit_group(proof=False, S=K.ideal(6).prime_factors()); U 

S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) 

sage: K.<a> = NumberField(x^3 + 3) 

sage: U = K.S_unit_group(proof=False, S=K.ideal(6)); U 

S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) 

sage: K.<a> = NumberField(x^3 + 3) 

sage: U = K.S_unit_group(proof=False, S=6); U 

S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) 

 

sage: U 

S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) 

sage: U.primes() 

(Fractional ideal (-a^2 + a - 1), 

Fractional ideal (a + 1), 

Fractional ideal (a)) 

sage: U.gens() 

(u0, u1, u2, u3, u4) 

sage: U.gens_values() 

[-1, a^2 - 2, -a^2 + a - 1, a + 1, a] 

 

The exp and log methods can be used to create `S`-units from 

sequences of exponents, and recover the exponents:: 

 

sage: U.gens_orders() 

(2, 0, 0, 0, 0) 

sage: u = U.exp((3,1,4,1,5)); u 

-6*a^2 + 18*a - 54 

sage: u.norm().factor() 

-1 * 2^9 * 3^5 

sage: U.log(u) 

(1, 1, 4, 1, 5) 

 

""" 

proof = proof_flag(proof) 

 

# process the parameter S: 

if not S: 

S = () 

else: 

if isinstance(S, list): 

S = tuple(S) 

if not isinstance(S, tuple): 

try: 

S = tuple(self.ideal(S).prime_factors()) 

except (NameError, TypeError, ValueError): 

raise ValueError("Cannot make a set of primes from %s"%(S,)) 

else: 

try: 

S = tuple(self.ideal(P) for P in S) 

except (NameError, TypeError, ValueError): 

raise ValueError("Cannot make a set of primes from %s"%(S,)) 

if not all([P.is_prime() for P in S]): 

raise ValueError("Not all elements of %s are prime ideals"%(S,)) 

 

try: 

return self._S_unit_group_cache[S] 

except AttributeError: 

self._S_unit_group_cache = {} 

except KeyError: 

pass 

 

if not proof: 

try: 

return self._S_unit_group_no_proof_cache[S] 

except AttributeError: 

self._S_unit_group_no_proof_cache = {} 

except KeyError: 

pass 

 

U = UnitGroup(self,proof,S=S) 

if proof: 

self._S_unit_group_cache[S] = U 

else: 

self._S_unit_group_no_proof_cache[S] = U 

return U 

 

def zeta(self, n=2, all=False): 

""" 

Return one, or a list of all, primitive n-th root of unity in this field. 

 

INPUT: 

 

- ``n`` - positive integer 

 

- ``all`` - bool. If False (default), return a primitive 

`n`-th root of unity in this field, or raise a ValueError 

exception if there are none. If True, return a list of 

all primitive `n`-th roots of unity in this field 

(possibly empty). 

 

.. note:: 

 

To obtain the maximal order of a root of unity in this field, 

use self.number_of_roots_of_unity(). 

 

.. note:: 

 

We do not create the full unit group since that can be 

expensive, but we do use it if it is already known. 

 

EXAMPLES:: 

 

sage: K.<z> = NumberField(x^2 + 3) 

sage: K.zeta(1) 

1 

sage: K.zeta(2) 

-1 

sage: K.zeta(2, all=True) 

[-1] 

sage: K.zeta(3) 

1/2*z - 1/2 

sage: K.zeta(3, all=True) 

[1/2*z - 1/2, -1/2*z - 1/2] 

sage: K.zeta(4) 

Traceback (most recent call last): 

... 

ValueError: There are no 4th roots of unity in self. 

 

:: 

 

sage: r.<x> = QQ[] 

sage: K.<b> = NumberField(x^2+1) 

sage: K.zeta(4) 

b 

sage: K.zeta(4,all=True) 

[b, -b] 

sage: K.zeta(3) 

Traceback (most recent call last): 

... 

ValueError: There are no 3rd roots of unity in self. 

sage: K.zeta(3,all=True) 

[] 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(1/2*x^2 + 1/6) 

sage: K.zeta(3) 

-3/2*a - 1/2 

""" 

try: 

return self._unit_group.zeta(n,all) 

except AttributeError: 

pass 

try: 

return self._unit_group_no_proof.zeta(n,all) 

except AttributeError: 

pass 

 

K = self 

n = ZZ(n) 

if n <= 0: 

raise ValueError("n (=%s) must be positive"%n) 

if n == 1: 

if all: 

return [K(1)] 

else: 

return K(1) 

elif n == 2: 

if all: 

return [K(-1)] 

else: 

return K(-1) 

 

# First check if the degree of K is compatible with an 

# inclusion QQ(\zeta_n) -> K. 

if sage.arith.all.euler_phi(n).divides(K.absolute_degree()): 

# Factor the n-th cyclotomic polynomial over K. 

f = K.pari_polynomial('y') 

factors = f.nffactor(pari.polcyclo(n)).component(1) 

roots = [K(-g.polcoeff(0)) for g in factors if g.poldegree() == 1] 

if all: 

return roots 

if roots: 

return roots[0] 

raise ValueError("There are no %s roots of unity in self." % n.ordinal_str()) 

 

def zeta_order(self): 

r""" 

Return the number of roots of unity in this field. 

 

.. note:: 

 

We do not create the full unit group since that can be 

expensive, but we do use it if it is already known. 

 

EXAMPLES:: 

 

sage: F.<alpha> = NumberField(x**22+3) 

sage: F.zeta_order() 

6 

sage: F.<alpha> = NumberField(x**2-7) 

sage: F.zeta_order() 

2 

 

TESTS: 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(1/2*x^2 + 1/6) 

sage: K.zeta_order() 

6 

""" 

try: 

return self._unit_group.zeta_order() 

except AttributeError: 

pass 

try: 

return self._unit_group_no_proof.zeta_order() 

except AttributeError: 

pass 

 

return ZZ(self.pari_nf().nfrootsof1()[0]) 

 

number_of_roots_of_unity = zeta_order 

 

def primitive_root_of_unity(self): 

""" 

Return a generator of the roots of unity in this field. 

 

OUTPUT: a primitive root of unity. No guarantee is made about 

which primitive root of unity this returns, not even for 

cyclotomic fields. Repeated calls of this function may return 

a different value. 

 

.. note:: 

 

We do not create the full unit group since that can be 

expensive, but we do use it if it is already known. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2+1) 

sage: z = K.primitive_root_of_unity(); z 

i 

sage: z.multiplicative_order() 

4 

 

sage: K.<a> = NumberField(x^2+x+1) 

sage: z = K.primitive_root_of_unity(); z 

a + 1 

sage: z.multiplicative_order() 

6 

 

sage: x = polygen(QQ) 

sage: F.<a,b> = NumberField([x^2 - 2, x^2 - 3]) 

sage: y = polygen(F) 

sage: K.<c> = F.extension(y^2 - (1 + a)*(a + b)*a*b) 

sage: K.primitive_root_of_unity() 

-1 

 

We do not special-case cyclotomic fields, so we do not always 

get the most obvious primitive root of unity:: 

 

sage: K.<a> = CyclotomicField(3) 

sage: z = K.primitive_root_of_unity(); z 

a + 1 

sage: z.multiplicative_order() 

6 

 

sage: K = CyclotomicField(3) 

sage: z = K.primitive_root_of_unity(); z 

zeta3 + 1 

sage: z.multiplicative_order() 

6 

 

TESTS: 

 

Check for :trac:`15027`. We use a new variable name:: 

 

sage: K.<f> = NumberField(x^2 + x + 1) 

sage: K.primitive_root_of_unity() 

f + 1 

sage: UK = K.unit_group() 

sage: K.primitive_root_of_unity() 

f + 1 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(3*x^2 + 1) 

sage: K.primitive_root_of_unity() 

-3/2*a + 1/2 

""" 

try: 

return self._unit_group.torsion_generator().value() 

except AttributeError: 

pass 

try: 

return self._unit_group_no_proof.torsion_generator().value() 

except AttributeError: 

pass 

 

pK = self.pari_nf() 

n, z = pK.nfrootsof1() 

return self(z, check=False) 

 

def roots_of_unity(self): 

""" 

Return all the roots of unity in this field, primitive or not. 

 

EXAMPLES:: 

 

sage: K.<b> = NumberField(x^2+1) 

sage: zs = K.roots_of_unity(); zs 

[b, -1, -b, 1] 

sage: [ z**K.number_of_roots_of_unity() for z in zs ] 

[1, 1, 1, 1] 

""" 

z = self.primitive_root_of_unity() 

n = self.zeta_order() 

return [ z**k for k in range(1, n+1) ] 

 

def zeta_coefficients(self, n): 

""" 

Compute the first n coefficients of the Dedekind zeta function of 

this field as a Dirichlet series. 

 

EXAMPLES:: 

 

sage: x = QQ['x'].0 

sage: NumberField(x^2+1, 'a').zeta_coefficients(10) 

[1, 1, 0, 1, 2, 0, 0, 1, 1, 2] 

""" 

return self.pari_nf().dirzetak(n) 

 

def solve_CRT(self, reslist, Ilist, check=True): 

r""" 

Solve a Chinese remainder problem over this number field. 

 

INPUT: 

 

- ``reslist`` -- a list of residues, i.e. integral number field elements 

 

- ``Ilist`` -- a list of integral ideals, assumed pairwise coprime 

 

- ``check`` (boolean, default True) -- if True, result is checked 

 

OUTPUT: 

 

An integral element x such that x-reslist[i] is in Ilist[i] for all i. 

 

.. note:: 

 

The current implementation requires the ideals to be pairwise 

coprime. A more general version would be possible. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2-10) 

sage: Ilist = [K.primes_above(p)[0] for p in prime_range(10)] 

sage: b = K.solve_CRT([1,2,3,4],Ilist,True) 

sage: all([b-i-1 in Ilist[i] for i in range(4)]) 

True 

sage: Ilist = [K.ideal(a), K.ideal(2)] 

sage: K.solve_CRT([0,1],Ilist,True) 

Traceback (most recent call last): 

... 

ArithmeticError: ideals in solve_CRT() must be pairwise coprime 

sage: Ilist[0]+Ilist[1] 

Fractional ideal (2, a) 

""" 

n = len(reslist) 

try: 

reslist = [self(x) for x in reslist] 

except ValueError: 

raise ValueError("solve_CRT requires a list of arguments in the field") 

if n==0: 

return self.zero() 

if n==1: 

return reslist[0] 

if n==2: 

try: 

r = Ilist[0].element_1_mod(Ilist[1]) 

except TypeError: 

raise ArithmeticError("ideals in solve_CRT() must be pairwise coprime") 

x = ((1-r)*reslist[0]+r*reslist[1]).mod(prod(Ilist)) 

else: # n>2;, use induction / recursion 

x = self.solve_CRT([reslist[0],self.solve_CRT(reslist[1:],Ilist[1:])], 

[Ilist[0],prod(Ilist[1:])], check=check) 

if check and not all([x-xi in Ii for xi,Ii in zip(reslist, Ilist)]): 

raise RuntimeError("Error in number field solve_CRT()") 

return self(x) 

 

def valuation(self, prime): 

r""" 

Return the valuation on this field defined by ``prime``. 

 

INPUT: 

 

- ``prime`` -- a prime that does not split, a discrete 

(pseudo-)valuation or a fractional ideal 

 

EXAMPLES: 

 

The valuation can be specified with an integer ``prime`` that is 

completely ramified in ``R``:: 

 

sage: K.<a> = NumberField(x^2 + 1) 

sage: K.valuation(2) 

2-adic valuation 

 

It can also be unramified in ``R``:: 

 

sage: K.valuation(3) 

3-adic valuation 

 

A ``prime`` that factors into pairwise distinct factors, results in an error:: 

 

sage: K.valuation(5) 

Traceback (most recent call last): 

... 

ValueError: The valuation Gauss valuation induced by 5-adic valuation does not approximate a unique extension of 5-adic valuation with respect to x^2 + 1 

 

The valuation can also be selected by giving a valuation on the base 

ring that extends uniquely:: 

 

sage: CyclotomicField(5).valuation(ZZ.valuation(5)) 

5-adic valuation 

 

When the extension is not unique, this does not work:: 

 

sage: K.valuation(ZZ.valuation(5)) 

Traceback (most recent call last): 

... 

ValueError: The valuation Gauss valuation induced by 5-adic valuation does not approximate a unique extension of 5-adic valuation with respect to x^2 + 1 

 

For a number field which is of the form `K[x]/(G)`, you can specify a 

valuation by providing a discrete pseudo-valuation on `K[x]` which sends 

`G` to infinity. This lets us specify which extension of the 5-adic 

valuation we care about in the above example:: 

 

sage: R.<x> = QQ[] 

sage: v = K.valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 2, infinity)) 

sage: w = K.valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 1/2, infinity)) 

sage: v == w 

False 

 

Note that you get the same valuation, even if you write down the 

pseudo-valuation differently:: 

 

sage: ww = K.valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 3, infinity)) 

sage: w is ww 

True 

 

The valuation ``prime`` does not need to send the defining polynomial `G` 

to infinity. It is sufficient if it singles out one of the valuations on 

the number field. This is important if the prime only factors over the 

completion, i.e., if it is not possible to write down one of the factors 

within the number field:: 

 

sage: v = GaussValuation(R, QQ.valuation(5)).augmentation(x + 3, 1) 

sage: K.valuation(v) 

[ 5-adic valuation, v(x + 3) = 1 ]-adic valuation 

 

Finally, ``prime`` can also be a fractional ideal of a number field if it 

singles out an extension of a `p`-adic valuation of the base field:: 

 

sage: K.valuation(K.fractional_ideal(a + 1)) 

2-adic valuation 

 

.. SEEALSO:: 

 

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

:meth:`pAdicGeneric.valuation() <sage.rings.padics.padic_generic.pAdicGeneric.valuation>` 

 

""" 

from sage.rings.padics.padic_valuation import pAdicValuation 

return pAdicValuation(self, prime) 

 

def some_elements(self): 

""" 

Return a list of elements in the given number field. 

 

EXAMPLES:: 

 

sage: R.<t> = QQ[] 

sage: K.<a> = QQ.extension(t^2 - 2); K 

Number Field in a with defining polynomial t^2 - 2 

sage: K.some_elements() 

[1, a, 2*a, 3*a - 4, 1/2, 1/3*a, 1/6*a, 0, 1/2*a, 2, ..., 12, -12*a + 18]  

 

sage: T.<u> = K[] 

sage: M.<b> = K.extension(t^3 - 5); M 

Number Field in b with defining polynomial t^3 - 5 over its base field 

sage: M.some_elements() 

[1, b, 1/2*a*b, ..., 2/5*b^2 + 2/5, 1/6*b^2 + 5/6*b + 13/6, 2] 

 

TESTS: 

 

This also works in trivial extensions:: 

 

sage: R.<t> = QQ[] 

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

Number Field in a with defining polynomial t 

sage: K.some_elements() 

[0, 1, 2, -1, 1/2, -1/2, 1/4, -2, 4] 

 

""" 

elements = [] 

 

polynomials = [self(f) for f in self.polynomial_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 

 

 

class NumberField_absolute(NumberField_generic): 

def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None, 

assume_disc_small=False, maximize_at_primes=None, structure=None): 

""" 

Function to initialize an absolute number field. 

 

EXAMPLES:: 

 

sage: K = NumberField(x^17 + 3, 'a'); K 

Number Field in a with defining polynomial x^17 + 3 

sage: type(K) 

<class 'sage.rings.number_field.number_field.NumberField_absolute_with_category'> 

sage: TestSuite(K).run() 

""" 

NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding, 

assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structure=structure) 

self._element_class = number_field_element.NumberFieldElement_absolute 

self._zero_element = self._element_class(self, 0) 

self._one_element = self._element_class(self, 1) 

 

self._init_embedding_approx() 

 

def _coerce_from_other_number_field(self, x): 

""" 

Coerce a number field element x into this number field. 

 

Unless `x` is in ``QQ``, this requires ``x.parent()`` and 

``self`` to have compatible embeddings: either they both embed 

in a common field, or there is an embedding of ``x.parent()`` 

into ``self`` or the other way around. If no compatible 

embeddings are found and `x` is not in ``QQ``, then raise 

``TypeError``. This guarantees that these conversions respect 

the field operations and conversions between several fields 

commute. 

 

REMARK: 

 

The name of this method was chosen for historical reasons. 

In fact, what it does is not a coercion but a conversion. 

 

INPUT: 

 

``x`` -- an element of some number field 

 

OUTPUT: 

 

An element of ``self`` corresponding to ``x``. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 + 2) 

sage: L.<b> = NumberField(x^2 + 1) 

sage: K._coerce_from_other_number_field(L(2/3)) 

2/3 

sage: L._coerce_from_other_number_field(K(0)) 

0 

sage: K._coerce_from_other_number_field(b) 

Traceback (most recent call last): 

... 

TypeError: No compatible natural embeddings found for Number Field in a with defining polynomial x^3 + 2 and Number Field in b with defining polynomial x^2 + 1 

 

Two number fields both containing `i`:: 

 

sage: K.<a> = NumberField(x^4 + 6*x^2 + 1, embedding = CC(-2.4*I)) 

sage: L.<b> = NumberField(x^4 + 8*x^2 + 4, embedding = CC(2.7*I)) 

sage: Ki = 1/2*a^3 + 5/2*a; Ki.minpoly() 

x^2 + 1 

sage: L(Ki) 

-1/4*b^3 - 3/2*b 

sage: K(L(Ki)) == Ki 

True 

sage: Q.<i> = QuadraticField(-1) 

sage: Q(Ki) 

i 

sage: Q(L(Ki)) 

i 

sage: L( (Ki+2)^1000 ) 

737533628...075020804*b^3 + 442520177...450124824*b + 793311113...453515313 

 

This fails if we don't specify the embeddings:: 

 

sage: K.<a> = NumberField(x^4 + 6*x^2 + 1) 

sage: L.<b> = NumberField(x^4 + 8*x^2 + 4) 

sage: L(1/2*a^3 + 5/2*a) 

Traceback (most recent call last): 

... 

TypeError: No compatible natural embeddings found for Number Field in b with defining polynomial x^4 + 8*x^2 + 4 and Number Field in a with defining polynomial x^4 + 6*x^2 + 1 

 

Embeddings can also be `p`-adic:: 

 

sage: F = Qp(73) 

sage: K.<a> = NumberField(x^4 + 6*x^2 + 1, embedding = F(1290990671961076190983179596556712119)) 

sage: L.<b> = NumberField(x^4 + 8*x^2 + 4, embedding = F(1773398470280167815153042237103591466)) 

sage: L(2*a^3 + 10*a + 3) 

b^3 + 6*b + 3 

 

If we take the same non-Galois number field with two different 

embeddings, conversion fails:: 

 

sage: K.<a> = NumberField(x^3 - 4*x + 1, embedding = 0.254) 

sage: L.<b> = NumberField(x^3 - 4*x + 1, embedding = 1.86) 

sage: L(a) 

Traceback (most recent call last): 

... 

ValueError: Cannot convert a to Number Field in b with defining polynomial x^3 - 4*x + 1 (using the specified embeddings) 

 

Subfields automatically come with an embedding:: 

 

sage: K.<a> = NumberField(x^2 - 5) 

sage: L.<b>, phi = K.subfield(-a) 

sage: phi(b) 

-a 

sage: K(b) 

-a 

sage: L(a) 

-b 

 

Below we create two subfields of `K` which both contain `i`. 

Since `L2` and `L3` both embed in `K`, conversion works:: 

 

sage: K.<z> = NumberField(x^8 - x^4 + 1) 

sage: i = (x^2+1).roots(ring=K)[0][0] 

sage: r2 = (x^2-2).roots(ring=K)[0][0] 

sage: r3 = (x^2-3).roots(ring=K)[0][0] 

sage: L2.<a2>, phi2 = K.subfield(r2+i) 

sage: L3.<a3>, phi3 = K.subfield(r3+i) 

sage: i_in_L2 = L2(i); i_in_L2 

1/6*a2^3 + 1/6*a2 

sage: i_in_L3 = L3(i); i_in_L3 

1/8*a3^3 

sage: L2(i_in_L3) == i_in_L2 

True 

sage: L3(i_in_L2) == i_in_L3 

True 

 

TESTS: 

 

The following was fixed in :trac:`8800`:: 

 

sage: P.<x> = QQ[] 

sage: K.<a> = NumberField(x^3-5,embedding=0) 

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

sage: F,R = L.construction() 

sage: F(R) == L #indirect doctest 

True 

 

AUTHORS: 

 

- Jeroen Demeyer (2011-09-30): :trac:`11869` 

 

""" 

# Special case for x in QQ. This is common, so should be fast. 

xpol = x.polynomial() 

if xpol.degree() <= 0: 

return self._element_class(self, xpol[0]) 

# Convert from L to K 

K = self 

L = x.parent() 

# Find embeddings for K and L. If no embedding is given, simply 

# take the identity map as "embedding". This handles the case 

# where one field is created as subfield of the other. 

Kgen = K.gen_embedding() 

if Kgen is None: 

Kgen = K.gen() 

KF = Kgen.parent() 

Lgen = L.gen_embedding() 

if Lgen is None: 

Lgen = L.gen() 

LF = Lgen.parent() 

 

# Do not use CDF or RDF because of constraints on the 

# exponent of floating-point numbers 

from sage.rings.all import RealField, ComplexField 

CC = ComplexField(53) 

RR = RealField(53) 

 

# Find a common field F into which KF and LF both embed. 

if CC.has_coerce_map_from(KF) and CC.has_coerce_map_from(LF): 

# We postpone converting Kgen and Lgen to F until we know the 

# floating-point precision required. 

F = CC 

elif KF is LF: 

F = KF 

elif KF.has_coerce_map_from(LF): 

F = KF 

Lgen = F(Lgen) 

elif LF.has_coerce_map_from(KF): 

F = LF 

Kgen = F(Kgen) 

else: 

raise TypeError("No compatible natural embeddings found for %s and %s"%(KF,LF)) 

 

# List of candidates for K(x) 

f = x.minpoly() 

ys = f.roots(ring=K, multiplicities=False) 

if not ys: 

raise ValueError("Cannot convert %s to %s (regardless of embeddings)"%(x,K)) 

 

# Define a function are_roots_equal to determine whether two 

# roots of f are equal. A simple a == b does not suffice for 

# inexact fields because of floating-point errors. 

if F.is_exact(): 

are_roots_equal = lambda a,b: a == b 

else: 

### Compute a lower bound on the distance between the roots of f. 

### This essentially gives the precision to work with. 

 

# A function 

# log2abs: F --> RR 

# x |-> log2(abs(x)) 

# This should work for all fields F with an absolute value. 

# The p-adic absolute value goes into QQ, so we need the RR(). 

log2abs = lambda x: RR(F(x).abs()).log2() 

 

# Compute half Fujiwara's bound on the roots of f 

n = f.degree() 

log_half_root_bound = log2abs(f[0]/2)/n 

for i in range(1,n): 

bd = log2abs(f[i])/(n-i) 

if bd > log_half_root_bound: 

log_half_root_bound = bd 

# Twice the bound on the roots of f, in other words an upper 

# bound for the distance between two roots. 

log_double_root_bound = log_half_root_bound + 2.0 # 2.0 = log2(4) 

# Now we compute the minimum distance between two roots of f 

# using the fact that the discriminant of f is the product of 

# all root distances. 

# We use pari to compute the discriminant to work around #11872. 

log_root_diff = log2abs(pari(f).poldisc())*0.5 - (n*(n-1)*0.5 - 1.0)*log_double_root_bound 

# Let eps be 1/128 times the minimal root distance. 

# This implies: If two roots of f are at distance <= eps, then 

# they are equal. The factor 128 is arbitrary, it is an extra 

# safety margin. 

eps = (log_root_diff - 7.0).exp2() 

are_roots_equal = lambda a,b: (a-b).abs() <= eps 

if F is CC: 

# Adjust the precision of F, sufficient to represent all 

# the temporaries in the computation with a precision 

# of eps, plus some extra bits. 

H = [log_double_root_bound - 1.0] 

for e in [x] + ys: 

H += [log2abs(c) for c in e.polynomial().coefficients()] 

prec = (max(H) + RR(n+1).log2() - log_root_diff).ceil() + 12 + n 

F = ComplexField(prec=prec) 

Kgen = F(Kgen) 

Lgen = F(Lgen) 

 

# Embed x and the y's in F 

emb_x = x.polynomial()(Lgen) 

for y in ys: 

emb_y = y.polynomial()(Kgen) 

if are_roots_equal(emb_x, emb_y): 

return y 

raise ValueError("Cannot convert %s to %s (using the specified embeddings)"%(x,K)) 

 

def _coerce_map_from_(self, R): 

""" 

Canonical coercion of a ring R into self. 

 

Currently any ring coercing into the base ring canonically coerces 

into this field, as well as orders in any number field coercing into 

this field, and of course the field itself as well. 

 

Two embedded number fields may mutually coerce into each other, if 

the pushout of the two ambient fields exists and if it is possible 

to construct an :class:`~sage.rings.number_field.number_field_morphisms.EmbeddedNumberFieldMorphism`. 

 

EXAMPLES:: 

 

sage: S.<y> = NumberField(x^3 + x + 1) 

sage: S.coerce(int(4)) # indirect doctest 

4 

sage: S.coerce(long(7)) 

7 

sage: S.coerce(-Integer(2)) 

-2 

sage: z = S.coerce(-7/8); z, type(z) 

(-7/8, <type 'sage.rings.number_field.number_field_element.NumberFieldElement_absolute'>) 

sage: S.coerce(y) is y 

True 

 

Fields with embeddings into an ambient field coerce naturally by the given embedding:: 

 

sage: CyclotomicField(15).coerce(CyclotomicField(5).0 - 17/3) 

zeta15^3 - 17/3 

sage: K.<a> = CyclotomicField(16) 

sage: K(CyclotomicField(4).0) 

a^4 

sage: QuadraticField(-3, 'a').coerce_map_from(CyclotomicField(3)) 

Generic morphism: 

From: Cyclotomic Field of order 3 and degree 2 

To: Number Field in a with defining polynomial x^2 + 3 

Defn: zeta3 -> 1/2*a - 1/2 

 

Two embedded number fields with mutual coercions (testing against a 

bug that was fixed in :trac:`8800`):: 

 

sage: K.<r4> = NumberField(x^4-2) 

sage: L1.<r2_1> = NumberField(x^2-2, embedding = r4**2) 

sage: L2.<r2_2> = NumberField(x^2-2, embedding = -r4**2) 

sage: r2_1+r2_2 # indirect doctest 

0 

sage: (r2_1+r2_2).parent() is L1 

True 

sage: (r2_2+r2_1).parent() is L2 

True 

 

Coercion of an order (testing against a bug that was fixed in 

:trac:`8800`):: 

 

sage: K.has_coerce_map_from(L1) 

True 

sage: L1.has_coerce_map_from(K) 

False 

sage: K.has_coerce_map_from(L1.maximal_order()) 

True 

sage: L1.has_coerce_map_from(K.maximal_order()) 

False 

 

There are situations for which one might imagine conversion 

could make sense (at least after fixing choices), but of course 

there will be no coercion from the Symbolic Ring to a Number Field:: 

 

sage: K.<a> = QuadraticField(2) 

sage: K.coerce(sqrt(2)) 

Traceback (most recent call last): 

... 

TypeError: no canonical coercion from Symbolic Ring to Number Field in a with defining polynomial x^2 - 2 

 

TESTS:: 

 

sage: K.<a> = NumberField(polygen(QQ)^3-2) 

sage: type(K.coerce_map_from(QQ)) 

<type 'sage.structure.coerce_maps.DefaultConvertMap_unique'> 

 

Make sure we still get our optimized morphisms for special fields:: 

 

sage: K.<a> = NumberField(polygen(QQ)^2-2) 

sage: type(K.coerce_map_from(QQ)) 

<type 'sage.rings.number_field.number_field_element_quadratic.Q_to_quadratic_field_element'> 

 

""" 

if R in integer_types: 

return self._generic_coerce_map(R) 

elif R in (ZZ, QQ, self.base()): 

return self._generic_coerce_map(R) 

from sage.rings.number_field.order import is_NumberFieldOrder 

if is_NumberFieldOrder(R) and self.has_coerce_map_from(R.number_field()): 

return self._generic_coerce_map(R) 

# R is not QQ by the above tests 

if is_NumberField(R) and R.coerce_embedding() is not None: 

if self.coerce_embedding() is not None: 

try: 

return number_field_morphisms.EmbeddedNumberFieldMorphism(R, self) 

except ValueError: # no common embedding found 

return None 

else: 

# R is embedded, self isn't. So, we could only have 

# the forgetful coercion. But this yields to non-commuting 

# coercions, as was pointed out at ticket #8800 

return None 

 

def base_field(self): 

""" 

Returns the base field of self, which is always QQ 

 

EXAMPLES:: 

 

sage: K = CyclotomicField(5) 

sage: K.base_field() 

Rational Field 

""" 

return QQ 

 

def is_absolute(self): 

""" 

Returns True since self is an absolute field. 

 

EXAMPLES:: 

 

sage: K = CyclotomicField(5) 

sage: K.is_absolute() 

True 

""" 

return True 

 

def absolute_polynomial(self): 

r""" 

Return absolute polynomial that defines this absolute field. This 

is the same as ``self.polynomial()``. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2 + 1) 

sage: K.absolute_polynomial () 

x^2 + 1 

""" 

return self.polynomial() 

 

def absolute_generator(self): 

r""" 

An alias for 

:meth:`sage.rings.number_field.number_field.NumberField_generic.gen`. 

This is provided for consistency with relative fields, where the 

element returned by 

:meth:`sage.rings.number_field.number_field_rel.NumberField_relative.gen` 

only generates the field over its base field (not necessarily over 

`\QQ`). 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2 - 17) 

sage: K.absolute_generator() 

a 

""" 

return self.gen() 

 

def optimized_representation(self, name=None, both_maps=True): 

""" 

Return a field isomorphic to self with a better defining polynomial 

if possible, along with field isomorphisms from the new field to 

self and from self to the new field. 

 

EXAMPLES: We construct a compositum of 3 quadratic fields, then 

find an optimized representation and transform elements back and 

forth. 

 

:: 

 

sage: K = NumberField([x^2 + p for p in [5, 3, 2]],'a').absolute_field('b'); K 

Number Field in b with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 

sage: L, from_L, to_L = K.optimized_representation() 

sage: L # your answer may different, since algorithm is random 

Number Field in b1 with defining polynomial x^8 + 4*x^6 + 7*x^4 + 

36*x^2 + 81 

sage: to_L(K.0) # random 

4/189*b1^7 + 1/63*b1^6 + 1/27*b1^5 - 2/9*b1^4 - 5/27*b1^3 - 8/9*b1^2 + 3/7*b1 - 3/7 

sage: from_L(L.0) # random 

1/1152*b^7 - 1/192*b^6 + 23/576*b^5 - 17/96*b^4 + 37/72*b^3 - 5/6*b^2 + 55/24*b - 3/4 

 

The transformation maps are mutually inverse isomorphisms. 

 

:: 

 

sage: from_L(to_L(K.0)) == K.0 

True 

sage: to_L(from_L(L.0)) == L.0 

True 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(7/9*x^3 + 7/3*x^2 - 56*x + 123) 

sage: K.optimized_representation() 

(Number Field in a1 with defining polynomial x^3 - 7*x - 7, 

Ring morphism: 

From: Number Field in a1 with defining polynomial x^3 - 7*x - 7 

To: Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 

Defn: a1 |--> 7/225*a^2 - 7/75*a - 42/25, 

Ring morphism: 

From: Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 

To: Number Field in a1 with defining polynomial x^3 - 7*x - 7 

Defn: a |--> -15/7*a1^2 + 9) 

""" 

if name is None: 

name = self.variable_names() 

name = normalize_names(1, name)[0] 

 

f = self.absolute_polynomial().__pari__() 

 

g, alpha = f.polredbest(flag=1) 

beta = alpha.modreverse() 

 

b = self(QQ['x'](lift(beta))) 

h = QQ['x'](g) 

 

embedding = None 

if self.coerce_embedding() is not None: 

embedding = self.coerce_embedding()(b) 

# trac 7695 add a _ to prevent zeta70 etc. 

if name[-1].isdigit(): 

new_name = name + '_1' 

else: 

new_name = name + '1' 

 

K = NumberField(h, names=new_name, embedding=embedding) 

from_K = K.hom([b]) 

 

if both_maps: 

a = K(alpha) 

to_K = self.hom([a]) 

 

return K, from_K, to_K 

 

return K, from_K 

 

def optimized_subfields(self, degree=0, name=None, both_maps=True): 

""" 

Return optimized representations of many (but *not* necessarily 

all!) subfields of self of the given degree, or of all possible degrees if 

degree is 0. 

 

EXAMPLES:: 

 

sage: K = NumberField([x^2 + p for p in [5, 3, 2]],'a').absolute_field('b'); K 

Number Field in b with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 

sage: L = K.optimized_subfields(name='b') 

sage: L[0][0] 

Number Field in b0 with defining polynomial x 

sage: L[1][0] 

Number Field in b1 with defining polynomial x^2 - 3*x + 3 

sage: [z[0] for z in L] # random -- since algorithm is random 

[Number Field in b0 with defining polynomial x - 1, 

Number Field in b1 with defining polynomial x^2 - x + 1, 

Number Field in b2 with defining polynomial x^4 - 5*x^2 + 25, 

Number Field in b3 with defining polynomial x^4 - 2*x^2 + 4, 

Number Field in b4 with defining polynomial x^8 + 4*x^6 + 7*x^4 + 36*x^2 + 81] 

 

We examine one of the optimized subfields in more detail:: 

 

sage: M, from_M, to_M = L[2] 

sage: M # random 

Number Field in b2 with defining polynomial x^4 - 5*x^2 + 25 

sage: from_M # may be slightly random 

Ring morphism: 

From: Number Field in b2 with defining polynomial x^4 - 5*x^2 + 25 

To: Number Field in a1 with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 

Defn: b2 |--> -5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1 

 

The to_M map is None, since there is no map from K to M:: 

 

sage: to_M 

 

We apply the from_M map to the generator of M, which gives a 

rather large element of `K`:: 

 

sage: from_M(M.0) # random 

-5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1 

 

Nevertheless, that large-ish element lies in a degree 4 subfield:: 

 

sage: from_M(M.0).minpoly() # random 

x^4 - 5*x^2 + 25 

 

TESTS: 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(2*x^4 + 6*x^2 + 1/2) 

sage: K.optimized_subfields() 

[ 

(Number Field in a0 with defining polynomial x, Ring morphism: 

From: Number Field in a0 with defining polynomial x 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: 0 |--> 0, None), 

(Number Field in a1 with defining polynomial x^2 - 2*x + 2, Ring morphism: 

From: Number Field in a1 with defining polynomial x^2 - 2*x + 2 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a1 |--> a^3 + 7/2*a + 1, None), 

(Number Field in a2 with defining polynomial x^2 - 2*x + 2, Ring morphism: 

From: Number Field in a2 with defining polynomial x^2 - 2*x + 2 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a2 |--> -a^3 - 7/2*a + 1, None), 

(Number Field in a3 with defining polynomial x^2 - 2, Ring morphism: 

From: Number Field in a3 with defining polynomial x^2 - 2 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a3 |--> a^2 + 3/2, None), 

(Number Field in a4 with defining polynomial x^2 + 1, Ring morphism: 

From: Number Field in a4 with defining polynomial x^2 + 1 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a4 |--> a^3 + 7/2*a, None), 

(Number Field in a5 with defining polynomial x^2 + 2, Ring morphism: 

From: Number Field in a5 with defining polynomial x^2 + 2 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a5 |--> 2*a^3 + 5*a, None), 

(Number Field in a6 with defining polynomial x^4 + 1, Ring morphism: 

From: Number Field in a6 with defining polynomial x^4 + 1 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a6 |--> a^3 + 1/2*a^2 + 5/2*a + 3/4, Ring morphism: 

From: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

To: Number Field in a6 with defining polynomial x^4 + 1 

Defn: a |--> -1/2*a6^3 + a6^2 - 1/2*a6) 

] 

""" 

return self._subfields_helper(degree=degree,name=name, 

both_maps=both_maps,optimize=True) 

 

def change_names(self, names): 

r""" 

Return number field isomorphic to self but with the given generator 

name. 

 

INPUT: 

 

 

- ``names`` - should be exactly one variable name. 

 

 

Also, ``K.structure()`` returns from_K and to_K, 

where from_K is an isomorphism from K to self and to_K is an 

isomorphism from self to K. 

 

EXAMPLES:: 

 

sage: K.<z> = NumberField(x^2 + 3); K 

Number Field in z with defining polynomial x^2 + 3 

sage: L.<ww> = K.change_names() 

sage: L 

Number Field in ww with defining polynomial x^2 + 3 

sage: L.structure()[0] 

Isomorphism given by variable name change map: 

From: Number Field in ww with defining polynomial x^2 + 3 

To: Number Field in z with defining polynomial x^2 + 3 

sage: L.structure()[0](ww + 5/3) 

z + 5/3 

""" 

return self.absolute_field(names) 

 

def subfields(self, degree=0, name=None): 

""" 

Return all subfields of self of the given degree, 

or of all possible degrees if degree is 0. The subfields are returned as 

absolute fields together with an embedding into self. For the case of the 

field itself, the reverse isomorphism is also provided. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField( [x^3 - 2, x^2 + x + 1] ) 

sage: K = K.absolute_field('b') 

sage: S = K.subfields() 

sage: len(S) 

6 

sage: [k[0].polynomial() for k in S] 

[x - 3, 

x^2 - 3*x + 9, 

x^3 - 3*x^2 + 3*x + 1, 

x^3 - 3*x^2 + 3*x + 1, 

x^3 - 3*x^2 + 3*x - 17, 

x^6 - 3*x^5 + 6*x^4 - 11*x^3 + 12*x^2 + 3*x + 1] 

sage: R.<t> = QQ[] 

sage: L = NumberField(t^3 - 3*t + 1, 'c') 

sage: [k[1] for k in L.subfields()] 

[Ring morphism: 

From: Number Field in c0 with defining polynomial t 

To: Number Field in c with defining polynomial t^3 - 3*t + 1 

Defn: 0 |--> 0, 

Ring morphism: 

From: Number Field in c1 with defining polynomial t^3 - 3*t + 1 

To: Number Field in c with defining polynomial t^3 - 3*t + 1 

Defn: c1 |--> c] 

sage: len(L.subfields(2)) 

0 

sage: len(L.subfields(1)) 

1 

 

TESTS: 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(2*x^4 + 6*x^2 + 1/2) 

sage: K.subfields() 

[ 

(Number Field in a0 with defining polynomial x, Ring morphism: 

From: Number Field in a0 with defining polynomial x 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: 0 |--> 0, None), 

(Number Field in a1 with defining polynomial x^2 - 2, Ring morphism: 

From: Number Field in a1 with defining polynomial x^2 - 2 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a1 |--> a^2 + 3/2, None), 

(Number Field in a2 with defining polynomial x^2 + 4, Ring morphism: 

From: Number Field in a2 with defining polynomial x^2 + 4 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a2 |--> 2*a^3 + 7*a, None), 

(Number Field in a3 with defining polynomial x^2 + 2, Ring morphism: 

From: Number Field in a3 with defining polynomial x^2 + 2 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a3 |--> 2*a^3 + 5*a, None), 

(Number Field in a4 with defining polynomial x^4 + 1, Ring morphism: 

From: Number Field in a4 with defining polynomial x^4 + 1 

To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

Defn: a4 |--> a^3 + 1/2*a^2 + 5/2*a + 3/4, Ring morphism: 

From: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2 

To: Number Field in a4 with defining polynomial x^4 + 1 

Defn: a |--> -1/2*a4^3 + a4^2 - 1/2*a4) 

] 

""" 

return self._subfields_helper(degree=degree, name=name, 

both_maps=True, optimize=False) 

 

def _subfields_helper(self, degree=0, name=None, both_maps=True, optimize=False): 

""" 

Internal function: common code for optimized_subfields() and subfields(). 

 

TESTS: 

 

Let's make sure embeddings are being respected:: 

 

sage: K.<a> = NumberField(x^4 - 23, embedding=50) 

sage: K, CDF(a) 

(Number Field in a with defining polynomial x^4 - 23, 2.1899387030948425) 

sage: Ss = K.subfields(); len(Ss) # indirect doctest 

3 

sage: diffs = [ S.coerce_embedding()(S.gen()) - CDF(S_into_K(S.gen())) for S, S_into_K, _ in Ss ] 

sage: all(abs(diff) < 1e-5 for diff in diffs) 

True 

 

sage: L1, _, _ = K.subfields(2)[0]; L1, CDF(L1.gen()) # indirect doctest 

(Number Field in a0 with defining polynomial x^2 - 23, -4.795831523312719) 

 

If we take a different embedding of the large field, we get a 

different embedding of the degree 2 subfield:: 

 

sage: K.<a> = NumberField(x^4 - 23, embedding=-50) 

sage: L2, _, _ = K.subfields(2)[0]; L2, CDF(L2.gen()) # indirect doctest 

(Number Field in a0 with defining polynomial x^2 - 23, -4.795831523312719) 

 

Test for :trac:`7695`:: 

 

sage: F = CyclotomicField(7) 

sage: K = F.subfields(3)[0][0] 

sage: K 

Number Field in zeta7_0 with defining polynomial x^3 + x^2 - 2*x - 1 

 

""" 

if name is None: 

name = self.variable_names() 

name = normalize_names(1, name)[0] 

try: 

return self.__subfields[name, degree, both_maps, optimize] 

except AttributeError: 

self.__subfields = {} 

except KeyError: 

pass 

f = self.pari_polynomial() 

if optimize: 

v = f.polred(2) 

elts = v[0] 

polys = v[1] 

else: 

v = f.nfsubfields(degree) 

elts = [x[1] for x in v] 

polys = [x[0] for x in v] 

 

R = self.polynomial_ring() 

 

embedding = None 

ans = [] 

for i in range(len(elts)): 

f = R(polys[i]) 

if not (degree == 0 or f.degree() == degree): 

continue 

a = self(elts[i], check=False) 

if self.coerce_embedding() is not None: 

embedding = self.coerce_embedding()(a) 

# trac 7695 add a _ to prevent zeta70 etc. 

if name[-1].isdigit(): 

new_name= name+ '_' + str(i) 

else: 

new_name = name + str(i) 

K = NumberField(f, names=new_name, embedding=embedding) 

 

from_K = K.hom([a]) # check=False here ?? would be safe unless there are bugs. 

 

if both_maps and K.degree() == self.degree(): 

g = K['x'](self.polynomial()) 

a = from_K(K.gen()) 

for root in g.roots(multiplicities=False): 

to_K = self.hom([root]) # check=False here ?? 

if to_K(a) == K.gen(): 

break 

else: 

to_K = None 

ans.append((K, from_K, to_K)) 

ans = Sequence(ans, immutable=True, cr=ans!=[]) 

self.__subfields[name, degree, both_maps, optimize] = ans 

return ans 

 

def maximal_order(self, v=None): 

""" 

Return the maximal order, i.e., the ring of integers, associated to 

this number field. 

 

INPUT: 

 

- ``v`` - (default: ``None``) ``None``, a prime, or a list of primes. 

 

- if ``v`` is ``None``, return the maximal order. 

 

- if ``v`` is a prime, return an order that is `p`-maximal. 

 

- if ``v`` is a list, return an order that is maximal at each prime 

in the list ``v``. 

 

 

EXAMPLES: 

 

In this example, the maximal order cannot be generated by a single 

element:: 

 

sage: k.<a> = NumberField(x^3 + x^2 - 2*x+8) 

sage: o = k.maximal_order() 

sage: o 

Maximal Order in Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8 

 

We compute `p`-maximal orders for several `p`. Note 

that computing a `p`-maximal order is much faster in 

general than computing the maximal order:: 

 

sage: p = next_prime(10^22); q = next_prime(10^23) 

sage: K.<a> = NumberField(x^3 - p*q) 

sage: K.maximal_order([3]).basis() 

[1/3*a^2 + 1/3*a + 1/3, a, a^2] 

sage: K.maximal_order([2]).basis() 

[1, a, a^2] 

sage: K.maximal_order([p]).basis() 

[1, a, a^2] 

sage: K.maximal_order([q]).basis() 

[1, a, a^2] 

sage: K.maximal_order([p,3]).basis() 

[1/3*a^2 + 1/3*a + 1/3, a, a^2] 

 

An example with bigger discriminant:: 

 

sage: p = next_prime(10^97); q = next_prime(10^99) 

sage: K.<a> = NumberField(x^3 - p*q) 

sage: K.maximal_order(prime_range(10000)).basis() 

[1, a, a^2] 

""" 

return self._maximal_order(self._normalize_prime_list(v)) 

 

@cached_method 

def _maximal_order(self, v): 

r""" 

Helper method which adds caching to :meth:`maximal_order`. 

 

EXAMPLES:: 

 

sage: k.<a> = NumberField(x^3 + x^2 - 2*x+8) 

sage: k.maximal_order() is k.maximal_order() # indirect doctest 

True 

 

TESTS: 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: K.<a> = NumberField(3*x^2 + 1) 

sage: K.maximal_order().basis() 

[3/2*a + 1/2, 3*a] 

""" 

B = [self(b, check=False) for b in self._pari_integral_basis(v=v)] 

 

import sage.rings.number_field.order as order 

return order.absolute_order_from_module_generators(B, 

check_integral=False, check_rank=False, 

check_is_ring=False, is_maximal=not v) 

 

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

r""" 

Return the order with given ring generators in the maximal order of 

this number field. 

 

INPUT: 

 

- ``gens`` - list of elements in this number field; if no generators 

are given, just returns the cardinality of this number field 

(`\infty`) for consistency. 

 

- ``check_is_integral`` - bool (default: ``True``), whether to check 

that each generator is integral. 

 

- ``check_rank`` - bool (default: ``True``), whether to check that the 

ring generated by ``gens`` is of full rank. 

 

- ``allow_subfield`` - bool (default: ``False``), if ``True`` and the 

generators do not generate an order, i.e., they generate a subring 

of smaller rank, instead of raising an error, return an order in a 

smaller number field. 

 

EXAMPLES:: 

 

sage: k.<i> = NumberField(x^2 + 1) 

sage: k.order(2*i) 

Order in Number Field in i with defining polynomial x^2 + 1 

sage: k.order(10*i) 

Order in Number Field in i with defining polynomial x^2 + 1 

sage: k.order(3) 

Traceback (most recent call last): 

... 

ValueError: the rank of the span of gens is wrong 

sage: k.order(i/2) 

Traceback (most recent call last): 

... 

ValueError: each generator must be integral 

 

Alternatively, an order can be constructed by adjoining elements to 

`\ZZ`:: 

 

sage: K.<a> = NumberField(x^3 - 2) 

sage: ZZ[a] 

Order in Number Field in a0 with defining polynomial x^3 - 2 

 

TESTS: 

 

We verify that :trac:`2480` is fixed:: 

 

sage: K.<a> = NumberField(x^4 + 4*x^2 + 2) 

sage: B = K.integral_basis() 

sage: K.order(*B) 

Order in Number Field in a with defining polynomial x^4 + 4*x^2 + 2 

sage: K.order(B) 

Order in Number Field in a with defining polynomial x^4 + 4*x^2 + 2 

sage: K.order(gens=B) 

Order in Number Field in a with defining polynomial x^4 + 4*x^2 + 2 

""" 

# set gens appropriately from the arguments 

gens = kwds.pop('gens', args) 

 

if len(gens) == 0: 

return NumberField_generic.order(self) 

if len(gens) == 1 and isinstance(gens[0], (list, tuple)): 

gens = gens[0] 

gens = map(self, gens) 

return self._order(tuple(gens), **kwds) 

 

@cached_method 

def _order(self, gens, **kwds): 

r""" 

Helper method for :meth:`order` which adds caching. See :meth:`order` 

for a description of the parameters and keyword parameters. 

 

TESTS: 

 

Test that caching works:: 

 

sage: K.<a> = NumberField(x^3 - 2) 

sage: K.order(a) is K.order(a) # indirect doctest 

True 

 

Keywords have no influence on the caching:: 

 

sage: K.order(a) is K.order(a,check_is_integral=True) is K.order(a,check_is_integral=False) 

True 

 

Even if the order lives in a different field, caching works (currently, 

however, ``allow_subfield`` is incorrect :trac:`16046`):: 

 

sage: K.<a> = NumberField(x**4+3) 

sage: o = K.order([a**2], allow_subfield=True) 

sage: o is K.order([a**2], allow_subfield=True) 

True 

 

Different generators for the same order:: 

 

sage: K.order(a) is K.order(a,a^2) is K.order(a^2,a) 

True 

 

""" 

import sage.rings.number_field.order as order 

ret = order.absolute_order_from_ring_generators(gens, **kwds) 

# we make sure that the result is a unique parent even if it the order 

# lives in a different field 

if ret.ambient() is not self: 

return ret.ambient().order(gens, **kwds) 

 

gens = ret.basis() 

if self._order.is_in_cache(gens): 

# different ways of specifying the same set of generators lead to 

# the same order - this is to make sure that orders are unique 

# parents 

return self._order(gens) 

 

self._order.set_cache(ret, gens) 

return ret 

 

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.<a> = NumberField(x^3 + 2) 

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

sage: from_V(V([1,2,3])) 

3*a^2 + 2*a + 1 

sage: to_V(1 + 2*a + 3*a^2) 

(1, 2, 3) 

sage: V 

Vector space of dimension 3 over Rational Field 

sage: to_V 

Isomorphism map: 

From: Number Field in a with defining polynomial x^3 + 2 

To: Vector space of dimension 3 over Rational Field 

sage: from_V(to_V(2/3*a - 5/8)) 

2/3*a - 5/8 

sage: to_V(from_V(V([0,-1/7,0]))) 

(0, -1/7, 0) 

""" 

try: 

return self.__vector_space 

except AttributeError: 

V = QQ**self.degree() 

from_V = maps.MapVectorSpaceToNumberField(V, self) 

to_V = maps.MapNumberFieldToVectorSpace(self, V) 

self.__vector_space = (V, from_V, to_V) 

return self.__vector_space 

 

def absolute_vector_space(self): 

r""" 

Return vector space over `\QQ` corresponding to this 

number field, along with maps from that space to this number field 

and in the other direction. 

 

For an absolute extension this is identical to 

``self.vector_space()``. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 - 5) 

sage: K.absolute_vector_space() 

(Vector space of dimension 3 over Rational Field, 

Isomorphism map: 

From: Vector space of dimension 3 over Rational Field 

To: Number Field in a with defining polynomial x^3 - 5, 

Isomorphism map: 

From: Number Field in a with defining polynomial x^3 - 5 

To: Vector space of dimension 3 over Rational Field) 

""" 

return self.vector_space() 

 

 

def _galois_closure_and_embedding(self, names=None): 

r""" 

Return number field `K` that is the Galois closure of self and an 

embedding of self into `K`. 

 

INPUT: 

 

- ``names`` - variable name for Galois closure 

 

.. warning:: 

 

This is an internal function; see :meth:`galois_closure`. 

 

EXAMPLES: 

 

For medium-sized Galois groups of fields with small discriminants, 

this computation is feasible:: 

 

sage: K.<a> = NumberField(x^6 + 4*x^2 + 2) 

sage: K.galois_group(type='pari').order() 

48 

sage: L, phi = K._galois_closure_and_embedding('c') 

sage: phi.domain() is K, phi.codomain() is L 

(True, True) 

sage: L 

Number Field in c with defining polynomial x^48 + 8*x^46 - 20*x^44 - 520*x^42 + 12106*x^40 - 68344*x^38 + 463156*x^36 - 1823272*x^34 + 8984591*x^32 - 25016080*x^30 + 84949344*x^28 - 163504384*x^26 + 417511068*x^24 - 394687376*x^22 + 836352224*x^20 + 72845696*x^18 + 1884703919*x^16 + 732720520*x^14 + 3960878676*x^12 + 2507357768*x^10 + 5438373834*x^8 + 3888508744*x^6 + 4581432268*x^4 + 1765511400*x^2 + 1723993441 

sage: K.defining_polynomial()( phi(K.gen()) ) 

0 

""" 

if names is None: 

raise TypeError("You must specify the name of the generator.") 

 

try: 

# compose with variable renaming 

L = self.__galois_closure.change_names(names) 

L_to_orig, orig_to_L = L.structure() 

# "flatten" the composition by hand 

self_into_L = self.hom([ (orig_to_L * self.__galois_closure_embedding)(self.gen()) ]) 

return (L, self_into_L) 

except AttributeError: 

pass 

 

# Compute degree of Galois closure if possible 

try: 

deg = self.galois_group(type='pari').order() 

except NotImplementedError: 

deg = None 

 

L, self_into_L = self.defining_polynomial().change_ring(self).splitting_field(names, map=True, degree_multiple=deg) 

self.__galois_closure = L 

self.__galois_closure_embedding = self_into_L 

return (self.__galois_closure, self.__galois_closure_embedding) 

 

def galois_closure(self, names=None, map=False): 

""" 

Return number field `K` that is the Galois closure of self, 

i.e., is generated by all roots of the defining polynomial of 

self, and possibly an embedding of self into `K`. 

 

INPUT: 

 

- ``names`` - variable name for Galois closure 

 

- ``map`` - (default: False) also return an embedding of self into `K` 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^4 - 2) 

sage: M = K.galois_closure('b'); M 

Number Field in b with defining polynomial x^8 + 28*x^4 + 2500 

sage: L.<a2> = K.galois_closure(); L 

Number Field in a2 with defining polynomial x^8 + 28*x^4 + 2500 

sage: K.galois_group(names=("a3")).order() 

8 

 

:: 

 

sage: phi = K.embeddings(L)[0] 

sage: phi(K.0) 

1/120*a2^5 + 19/60*a2 

sage: phi(K.0).minpoly() 

x^4 - 2 

 

sage: L, phi = K.galois_closure('b', map=True) 

sage: L 

Number Field in b with defining polynomial x^8 + 28*x^4 + 2500 

sage: phi 

Ring morphism: 

From: Number Field in a with defining polynomial x^4 - 2 

To: Number Field in b with defining polynomial x^8 + 28*x^4 + 2500 

Defn: a |--> 1/240*b^5 - 41/120*b 

 

A cyclotomic field is already Galois:: 

 

sage: K.<a> = NumberField(cyclotomic_polynomial(23)) 

sage: L.<z> = K.galois_closure() 

sage: L 

Number Field in z with defining polynomial x^22 + x^21 + x^20 + x^19 + x^18 + x^17 + x^16 + x^15 + x^14 + x^13 + x^12 + x^11 + x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1 

 

TESTS: 

 

Let's make sure we're renaming correctly:: 

 

sage: K.<a> = NumberField(x^4 - 2) 

sage: L, phi = K.galois_closure('cc', map=True) 

sage: L 

Number Field in cc with defining polynomial x^8 + 28*x^4 + 2500 

sage: phi 

Ring morphism: 

From: Number Field in a with defining polynomial x^4 - 2 

To: Number Field in cc with defining polynomial x^8 + 28*x^4 + 2500 

Defn: a |--> 1/240*cc^5 - 41/120*cc 

""" 

L, self_into_L = self._galois_closure_and_embedding(names) 

if map: 

return (L, self_into_L) 

else: 

return L 

 

def automorphisms(self): 

r""" 

Compute all Galois automorphisms of self. 

 

This uses PARI's :pari:`nfgaloisconj` and is much faster than root finding 

for many fields. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2 + 10000) 

sage: K.automorphisms() 

[ 

Ring endomorphism of Number Field in a with defining polynomial x^2 + 10000 

Defn: a |--> a, 

Ring endomorphism of Number Field in a with defining polynomial x^2 + 10000 

Defn: a |--> -a 

] 

 

Here's a larger example, that would take some time if we found 

roots instead of using PARI's specialized machinery:: 

 

sage: K = NumberField(x^6 - x^4 - 2*x^2 + 1, 'a') 

sage: len(K.automorphisms()) 

2 

 

`L` is the Galois closure of `K`:: 

 

sage: L = NumberField(x^24 - 84*x^22 + 2814*x^20 - 15880*x^18 - 409563*x^16 - 8543892*x^14 + 25518202*x^12 + 32831026956*x^10 - 672691027218*x^8 - 4985379093428*x^6 + 320854419319140*x^4 + 817662865724712*x^2 + 513191437605441, 'a') 

sage: len(L.automorphisms()) 

24 

 

Number fields defined by non-monic and non-integral 

polynomials are supported (:trac:`252`):: 

 

sage: R.<x> = QQ[] 

sage: f = 7/9*x^3 + 7/3*x^2 - 56*x + 123 

sage: K.<a> = NumberField(f) 

sage: A = K.automorphisms(); A 

[ 

Ring endomorphism of Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 

Defn: a |--> a, 

Ring endomorphism of Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 

Defn: a |--> -7/15*a^2 - 18/5*a + 96/5, 

Ring endomorphism of Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 

Defn: a |--> 7/15*a^2 + 13/5*a - 111/5 

] 

sage: prod(x - sigma(a) for sigma in A) == f.monic() 

True 

""" 

try: 

# this should be concordant with embeddings 

return self.__embeddings[self] 

except AttributeError: 

self.__embeddings = {} 

except KeyError: 

pass 

f = self.pari_polynomial('y') 

# Compute the conjugates of Mod(x, f). 

conj = self.pari_nf().nfgaloisconj() 

# Convert these to conjugates of self.gen(). 

P = self._pari_absolute_structure()[1].lift() 

conj = sorted([self(P(g.Mod(f))) for g in conj]) 

v = [self.hom([e]) for e in conj] # check=False here? 

put_natural_embedding_first(v) 

self.__embeddings[self] = Sequence(v, cr=(v != []), immutable=True, 

check=False, universe=self.Hom(self)) 

return self.__embeddings[self] 

 

def embeddings(self, K): 

""" 

Compute all field embeddings of self into the field K (which need 

not even be a number field, e.g., it could be the complex numbers). 

This will return an identical result when given K as input again. 

 

If possible, the most natural embedding of self into K is put first 

in the list. 

 

INPUT: 

 

- ``K`` - a number field 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^3 - 2) 

sage: L.<a1> = K.galois_closure(); L 

Number Field in a1 with defining polynomial x^6 + 108 

sage: K.embeddings(L)[0] 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Number Field in a1 with defining polynomial x^6 + 108 

Defn: a |--> 1/18*a1^4 

sage: K.embeddings(L) is K.embeddings(L) 

True 

 

We embed a quadratic field into a cyclotomic field:: 

 

sage: L.<a> = QuadraticField(-7) 

sage: K = CyclotomicField(7) 

sage: L.embeddings(K) 

[ 

Ring morphism: 

From: Number Field in a with defining polynomial x^2 + 7 

To: Cyclotomic Field of order 7 and degree 6 

Defn: a |--> 2*zeta7^4 + 2*zeta7^2 + 2*zeta7 + 1, 

Ring morphism: 

From: Number Field in a with defining polynomial x^2 + 7 

To: Cyclotomic Field of order 7 and degree 6 

Defn: a |--> -2*zeta7^4 - 2*zeta7^2 - 2*zeta7 - 1 

] 

 

We embed a cubic field in the complex numbers:: 

 

sage: K.<a> = NumberField(x^3 - 2) 

sage: K.embeddings(CC) 

[ 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Complex Field with 53 bits of precision 

Defn: a |--> -0.62996052494743... - 1.09112363597172*I, 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Complex Field with 53 bits of precision 

Defn: a |--> -0.62996052494743... + 1.09112363597172*I, 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Complex Field with 53 bits of precision 

Defn: a |--> 1.25992104989487 

] 

 

Test that :trac:`15053` is fixed:: 

 

sage: K = NumberField(x^3 - 2, 'a') 

sage: K.embeddings(GF(3)) 

[] 

""" 

try: 

# this should be concordant with automorphisms 

return self.__embeddings[K] 

except AttributeError: 

self.__embeddings = {} 

except KeyError: 

pass 

if K is self: 

return self.automorphisms() 

if K.characteristic() != 0: 

return Sequence([], immutable=True, check=False, universe=self.Hom(K)) 

 

f = self.defining_polynomial() 

r = sorted(f.roots(K, multiplicities=False)) 

v = [self.hom([e], check=False) for e in r] 

# If there is an embedding that preserves variable names 

# then it is most natural, so we put it first. 

put_natural_embedding_first(v) 

 

self.__embeddings[K] = Sequence(v, cr=v!=[], immutable=True, 

check=False, universe=self.Hom(K)) 

return self.__embeddings[K] 

 

def minkowski_embedding(self, B=None, prec=None): 

r""" 

Return an nxn matrix over RDF whose columns are the images of the 

basis `\{1, \alpha, \dots, \alpha^{n-1}\}` of self over 

`\QQ` (as vector spaces), where here 

`\alpha` is the generator of self over 

`\QQ`, i.e. self.gen(0). If B is not None, return 

the images of the vectors in B as the columns instead. If prec is 

not None, use RealField(prec) instead of RDF. 

 

This embedding is the so-called "Minkowski embedding" of a number 

field in `\RR^n`: given the `n` embeddings 

`\sigma_1, \dots, \sigma_n` of self in 

`\CC`, write `\sigma_1, \dots, \sigma_r` 

for the real embeddings, and 

`\sigma_{r+1}, \dots, \sigma_{r+s}` for choices of one of 

each pair of complex conjugate embeddings (in our case, we simply 

choose the one where the image of `\alpha` has positive 

real part). Here `(r,s)` is the signature of self. Then the 

Minkowski embedding is given by 

 

.. MATH:: 

 

x \mapsto ( \sigma_1(x), \dots, 

\sigma_r(x), \sqrt{2}\Re(\sigma_{r+1}(x)), 

\sqrt{2}\Im(\sigma_{r+1}(x)), \dots, 

\sqrt{2}\Re(\sigma_{r+s}(x)), 

\sqrt{2}\Im(\sigma_{r+s}(x))) 

 

Equivalently, this is an embedding of self in `\RR^n` so 

that the usual norm on `\RR^n` coincides with 

`|x| = \sum_i |\sigma_i(x)|^2` on self. 

 

.. TODO:: 

 

This could be much improved by implementing homomorphisms 

over VectorSpaces. 

 

EXAMPLES:: 

 

sage: F.<alpha> = NumberField(x^3+2) 

sage: F.minkowski_embedding() 

[ 1.00000000000000 -1.25992104989487 1.58740105196820] 

[ 1.41421356237... 0.8908987181... -1.12246204830...] 

[0.000000000000000 1.54308184421... 1.94416129723...] 

sage: F.minkowski_embedding([1, alpha+2, alpha^2-alpha]) 

[ 1.00000000000000 0.740078950105127 2.84732210186307] 

[ 1.41421356237... 3.7193258428... -2.01336076644...] 

[0.000000000000000 1.54308184421... 0.40107945302...] 

sage: F.minkowski_embedding() * (alpha + 2).vector().column() 

[0.740078950105127] 

[ 3.7193258428...] 

[ 1.54308184421...] 

 

TESTS:: 

 

sage: emb = F.Minkowski_embedding() 

doctest:warning...: 

DeprecationWarning: Minkowski_embedding is deprecated. Please use minkowski_embedding instead. 

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

""" 

n = self.degree() 

if prec is None: 

R = sage.rings.real_double.RDF 

else: 

R = sage.rings.real_mpfr.RealField(prec) 

r,s = self.signature() 

places = self.places(prec=prec) 

 

if B is None: 

B = [ (self.gen(0))**i for i in range(n) ] 

 

A = ZZ['x'] 

f = A.gen(0)**2-2 

sqrt2 = f.roots(R)[1][0] 

 

d = {} 

 

for col in range(n): 

 

for row in range(r): 

d[(row,col)] = places[row](B[col]) 

 

for i in range(s): 

z = places[r+i](B[col]) 

d[(r+2*i,col)] = z.real()*sqrt2 

d[(r+2*i+1,col)] = z.imag()*sqrt2 

 

 

M = sage.matrix.all.matrix(d) 

 

return M 

 

Minkowski_embedding = deprecated_function_alias(23685, minkowski_embedding) 

 

def places(self, all_complex=False, prec=None): 

""" 

Return the collection of all infinite places of self. 

 

By default, this returns the set of real places as 

homomorphisms into RIF first, followed by a choice of one of 

each pair of complex conjugate homomorphisms into CIF. 

 

On the other hand, if prec is not None, we simply return places 

into RealField(prec) and ComplexField(prec) (or RDF, CDF if 

prec=53). One can also use ``prec=infinity``, which returns embeddings 

into the field `\overline{\QQ}` of algebraic numbers (or its subfield 

`\mathbb{A}` of algebraic reals); this permits exact computation, but 

can be extremely slow. 

 

There is an optional flag all_complex, which defaults to False. If 

all_complex is True, then the real embeddings are returned as 

embeddings into CIF instead of RIF. 

 

EXAMPLES:: 

 

sage: F.<alpha> = NumberField(x^3-100*x+1) ; F.places() 

[Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 

To: Real Field with 106 bits of precision 

Defn: alpha |--> -10.00499625499181184573367219280, 

Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 

To: Real Field with 106 bits of precision 

Defn: alpha |--> 0.01000001000003000012000055000273, 

Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 

To: Real Field with 106 bits of precision 

Defn: alpha |--> 9.994996244991781845613530439509] 

 

:: 

 

sage: F.<alpha> = NumberField(x^3+7) ; F.places() 

[Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 + 7 

To: Real Field with 106 bits of precision 

Defn: alpha |--> -1.912931182772389101199116839549, 

Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 + 7 

To: Complex Field with 53 bits of precision 

Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I] 

 

:: 

 

sage: F.<alpha> = NumberField(x^3+7) ; F.places(all_complex=True) 

[Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 + 7 

To: Complex Field with 53 bits of precision 

Defn: alpha |--> -1.91293118277239, 

Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 + 7 

To: Complex Field with 53 bits of precision 

Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I] 

sage: F.places(prec=10) 

[Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 + 7 

To: Real Field with 10 bits of precision 

Defn: alpha |--> -1.9, 

Ring morphism: 

From: Number Field in alpha with defining polynomial x^3 + 7 

To: Complex Field with 10 bits of precision 

Defn: alpha |--> 0.96 + 1.7*I] 

""" 

if prec is None: 

R = RIF 

C = CIF 

 

elif prec == 53: 

R = sage.rings.real_double.RDF 

C = sage.rings.complex_double.CDF 

 

elif prec == Infinity: 

R = sage.rings.all.AA 

C = sage.rings.all.QQbar 

 

else: 

R = sage.rings.real_mpfr.RealField(prec) 

C = sage.rings.complex_field.ComplexField(prec) 

 

## first, find the intervals with roots, and see how much 

## precision we need to approximate the roots 

## 

all_intervals = [ x[0] for x in self.defining_polynomial().roots(C) ] 

 

## first, set up the real places 

if all_complex: 

real_intervals = [ x for x in all_intervals if x.imag().is_zero() ] 

else: 

real_intervals = [ x[0] for x in self.defining_polynomial().roots(R) ] 

 

if prec is None: 

real_places = [ self.hom([i.center()], check=False) for i in real_intervals ] 

 

complex_places = [ self.hom([i.center()], check=False) for i in 

all_intervals if i.imag() > 0 ] 

else: 

real_places = [ self.hom([i], check=False) for i in real_intervals ] 

 

complex_places = [ self.hom([i], check=False) for i in 

all_intervals if i.imag() > 0 ] 

 

return real_places + complex_places 

 

def real_places(self, prec=None): 

""" 

Return all real places of self as homomorphisms into RIF. 

 

EXAMPLES:: 

 

sage: F.<alpha> = NumberField(x^4-7) ; F.real_places() 

[Ring morphism: 

From: Number Field in alpha with defining polynomial x^4 - 7 

To: Real Field with 106 bits of precision 

Defn: alpha |--> -1.626576561697785743211232345494, 

Ring morphism: 

From: Number Field in alpha with defining polynomial x^4 - 7 

To: Real Field with 106 bits of precision 

Defn: alpha |--> 1.626576561697785743211232345494] 

""" 

return self.places(prec=prec)[0:self.signature()[0]] 

 

def abs_val(self, v, iota, prec=None): 

r""" 

Return the value `|\iota|_{v}`. 

 

INPUT: 

 

- ``v`` -- a place of ``K``, finite (a fractional ideal) or infinite (element of ``K.places(prec)``) 

- ``iota`` -- an element of ``K`` 

- ``prec`` -- (default: None) the precision of the real field 

 

OUTPUT: 

 

The absolute value as a real number 

 

EXAMPLES:: 

 

sage: K.<xi> = NumberField(x^3-3) 

sage: phi_real = K.places()[0] 

sage: phi_complex = K.places()[1] 

sage: v_fin = tuple(K.primes_above(3))[0] 

 

sage: K.abs_val(phi_real,xi^2) 

2.08008382305190 

 

sage: K.abs_val(phi_complex,xi^2) 

4.32674871092223 

 

sage: K.abs_val(v_fin,xi^2) 

0.111111111111111 

""" 

if prec is None: 

prec = 53 

R = sage.rings.real_mpfr.RealField(prec) 

 

try: 

p = v.smallest_integer() 

iota_ideal = self.ideal(self(iota)) 

exponent = - v.residue_class_degree() * iota_ideal.valuation(v) 

return R(p**exponent) 

except AttributeError: 

if is_real_place(v): 

return R(v(iota).abs()) 

else: 

return R(v(iota).abs()**2) 

 

def relativize(self, alpha, names, structure=None): 

r""" 

Given an element in self or an embedding of a subfield into self, 

return a relative number field `K` isomorphic to self that is relative 

over the absolute field `\QQ(\alpha)` or the domain of `alpha`, along 

with isomorphisms from `K` to self and from self to `K`. 

 

INPUT: 

 

- ``alpha`` - an element of self or an embedding of a subfield into 

self 

- ``names`` - 2-tuple of names of generator for output field K and the 

subfield QQ(alpha) names[0] generators K and names[1] QQ(alpha). 

- ``structure`` -- an instance of 

:class:`structure.NumberFieldStructure` or ``None`` (default: 

``None``), if ``None``, then the resulting field's :meth:`structure` 

will return isomorphisms from and to this field. Otherwise, the field 

will be equipped with ``structure``. 

 

OUTPUT: 

 

K -- relative number field 

 

Also, ``K.structure()`` returns from_K and to_K, where 

from_K is an isomorphism from K to self and to_K is an isomorphism 

from self to K. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^10 - 2) 

sage: L.<c,d> = K.relativize(a^4 + a^2 + 2); L 

Number Field in c with defining polynomial x^2 - 1/5*d^4 + 8/5*d^3 - 23/5*d^2 + 7*d - 18/5 over its base field 

sage: c.absolute_minpoly() 

x^10 - 2 

sage: d.absolute_minpoly() 

x^5 - 10*x^4 + 40*x^3 - 90*x^2 + 110*x - 58 

sage: (a^4 + a^2 + 2).minpoly() 

x^5 - 10*x^4 + 40*x^3 - 90*x^2 + 110*x - 58 

sage: from_L, to_L = L.structure() 

sage: to_L(a) 

c 

sage: to_L(a^4 + a^2 + 2) 

d 

sage: from_L(to_L(a^4 + a^2 + 2)) 

a^4 + a^2 + 2 

 

The following demonstrates distinct embeddings of a subfield into a 

larger field:: 

 

sage: K.<a> = NumberField(x^4 + 2*x^2 + 2) 

sage: K0 = K.subfields(2)[0][0]; K0 

Number Field in a0 with defining polynomial x^2 - 2*x + 2 

sage: rho, tau = K0.embeddings(K) 

sage: L0 = K.relativize(rho(K0.gen()), 'b'); L0 

Number Field in b0 with defining polynomial x^2 - b1 + 2 over its base field 

sage: L1 = K.relativize(rho, 'b'); L1 

Number Field in b with defining polynomial x^2 - a0 + 2 over its base field 

sage: L2 = K.relativize(tau, 'b'); L2 

Number Field in b with defining polynomial x^2 + a0 over its base field 

sage: L0.base_field() is K0 

False 

sage: L1.base_field() is K0 

True 

sage: L2.base_field() is K0 

True 

 

Here we see that with the different embeddings, the relative norms are 

different:: 

 

sage: a0 = K0.gen() 

sage: L1_into_K, K_into_L1 = L1.structure() 

sage: L2_into_K, K_into_L2 = L2.structure() 

sage: len(K.factor(41)) 

4 

sage: w1 = -a^2 + a + 1; P = K.ideal([w1]) 

sage: Pp = L1.ideal(K_into_L1(w1)).ideal_below(); Pp == K0.ideal([4*a0 + 1]) 

True 

sage: Pp == w1.norm(rho) 

True 

 

sage: w2 = a^2 + a - 1; Q = K.ideal([w2]) 

sage: Qq = L2.ideal(K_into_L2(w2)).ideal_below(); Qq == K0.ideal([-4*a0 + 9]) 

True 

sage: Qq == w2.norm(tau) 

True 

 

sage: Pp == Qq 

False 

 

TESTS: 

 

We can relativize over the whole field:: 

 

sage: K.<a> = NumberField(x^4 + 2*x^2 + 2) 

sage: K.relativize(K.gen(), 'a') 

Number Field in a0 with defining polynomial x - a1 over its base field 

sage: K.relativize(2*K.gen(), 'a') 

Number Field in a0 with defining polynomial x - 1/2*a1 over its base field 

 

We can relativize over the prime field:: 

 

sage: L = K.relativize(K(1), 'a'); L 

Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field 

sage: L.base_field() 

Number Field in a1 with defining polynomial x - 1 

sage: L.base_field().base_field() 

Rational Field 

 

sage: L = K.relativize(K(2), 'a'); L 

Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field 

sage: L.base_field() 

Number Field in a1 with defining polynomial x - 2 

sage: L.base_field().base_field() 

Rational Field 

 

sage: L = K.relativize(K(0), 'a'); L 

Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field 

sage: L.base_field() 

Number Field in a1 with defining polynomial x 

sage: L.base_field().base_field() 

Rational Field 

 

We can relativize over morphisms returned by self.subfields():: 

 

sage: L = NumberField(x^4 + 1, 'a') 

sage: [L.relativize(h, 'c') for (f,h,i) in L.subfields()] 

[Number Field in c with defining polynomial x^4 + 1 over its base field, 

Number Field in c with defining polynomial x^2 - a1*x + 1 over its base field, 

Number Field in c with defining polynomial x^2 - 1/2*a2 over its base field, 

Number Field in c with defining polynomial x^2 - a3*x - 1 over its base field, 

Number Field in c with defining polynomial x - a4 over its base field] 

 

We can relativize over a relative field:: 

 

sage: K.<z> = CyclotomicField(16) 

sage: L, L_into_K, _ = K.subfields(4)[0]; L 

Number Field in z0 with defining polynomial x^4 + 16 

sage: F, F_into_L, _ = L.subfields(2)[0]; F 

Number Field in z0_0 with defining polynomial x^2 + 64 

 

sage: L_over_F = L.relativize(F_into_L, 'c'); L_over_F 

Number Field in c with defining polynomial x^2 - 1/2*z0_0 over its base field 

sage: L_over_F_into_L, _ = L_over_F.structure() 

 

sage: K_over_rel = K.relativize(L_into_K * L_over_F_into_L, 'a'); K_over_rel 

Number Field in a with defining polynomial x^2 - 1/2*c over its base field 

sage: K_over_rel.base_field() is L_over_F 

True 

sage: K_over_rel.structure() 

(Relative number field morphism: 

From: Number Field in a with defining polynomial x^2 - 1/2*c over its base field 

To: Cyclotomic Field of order 16 and degree 8 

Defn: a |--> z 

c |--> 2*z^2 

z0_0 |--> 8*z^4, Ring morphism: 

From: Cyclotomic Field of order 16 and degree 8 

To: Number Field in a with defining polynomial x^2 - 1/2*c over its base field 

Defn: z |--> a) 

 

We can relativize over a really large field:: 

 

sage: K.<a> = CyclotomicField(3^3*2^3) 

sage: R = K.relativize(a^(3^2), 't'); R 

Number Field in t0 with defining polynomial x^9 - t1 over its base field 

sage: R.structure() 

(Relative number field morphism: 

From: Number Field in t0 with defining polynomial x^9 - t1 over its base field 

To: Cyclotomic Field of order 216 and degree 72 

Defn: t0 |--> a 

t1 |--> a^9, 

Ring morphism: 

From: Cyclotomic Field of order 216 and degree 72 

To: Number Field in t0 with defining polynomial x^9 - t1 over its base field 

Defn: a |--> t0) 

 

Only one name is required when a morphism is given (fixing :trac:`12005`):: 

 

sage: R.<x> = PolynomialRing(QQ) 

sage: K.<i> = NumberField(x^2 + 1) 

sage: L.<b> = NumberField(x^4 - x^2 + 1) 

sage: phi = K.hom(b^3, L) 

sage: M.<r> = L.relativize(phi) 

sage: M 

Number Field in r with defining polynomial x^2 - i*x - 1 over its base field 

sage: M.base_field() 

Number Field in i with defining polynomial x^2 + 1 

""" 

# step 1: construct the abstract field generated by alpha.w 

# step 2: make a relative extension of it. 

# step 3: construct isomorphisms 

from sage.all import vector, matrix 

 

from sage.categories.map import is_Map 

if is_Map(alpha): 

# alpha better be a morphism with codomain self 

if alpha.codomain() != self: 

raise ValueError("Co-domain of morphism must be self") 

L = alpha.domain() 

alpha = alpha(L.gen()) # relativize over phi's domain 

if L is QQ: 

from sage.rings.all import polygen 

f = polygen(QQ) 

else: 

f = L.defining_polynomial() # = alpha.minpoly() 

names = normalize_names(1, names) 

else: 

# alpha must be an element coercible to self 

alpha = self(alpha) 

f = alpha.minpoly() 

names = normalize_names(2, names) 

L = NumberField(f, names[1]) 

 

# now we do some linear algebra to find the minpoly of self.gen() over L 

L_into_self = L.hom([alpha]) 

 

extdeg = self.absolute_degree() // L.absolute_degree() # [ L : self ] 

a = self.gen() 

 

# we will find a linear relation between small powers of a over L 

basis = [ a**i * b for i in range(extdeg) for b in map(L_into_self, L.power_basis()) ] 

basis.append(a**extdeg) # this one makes the basis no longer a basis 

mat = matrix([ b.vector() for b in basis ]) 

soln_space = mat.left_kernel(mat.row_space()(0)) 

# the solution space is one dimensional and the last entry is non-zero 

# because a satisfies no smaller linear relation 

assert soln_space.dimension() == 1 

(reln, ) = soln_space.basis() 

assert reln[-1] != 0 

reln = reln * ~reln[-1] 

 

# now we need to get those coeffs in L 

coeff_mat = matrix(extdeg, f.degree(), list(reln)[:-1]) # easy way to divide into the correct lengths 

coeffs_in_L = [ r*vector(L.power_basis()) for r in coeff_mat.rows() ] 

# f is the minimal polynomial of a over L 

f = L['x'](coeffs_in_L + [1]) 

# sanity check... 

 

mp_in_self = self['x']([L_into_self(_) for _ in f.coefficients(sparse=False)]) 

assert mp_in_self(a) == 0 

 

if structure is None: 

from sage.rings.number_field.structure import RelativeFromAbsolute 

structure = RelativeFromAbsolute(self, alpha) 

if L is QQ: 

return L.extension(f, names[0]) 

else: 

return L.extension(f, names[0], structure=structure) 

 

# Synonyms so that terminology appropriate to relative number fields 

# can be applied to an absolute number field: 

 

def absolute_degree(self): 

""" 

A synonym for degree. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.absolute_degree() 

2 

""" 

return self.degree() 

 

def relative_degree(self): 

""" 

A synonym for degree. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.relative_degree() 

2 

""" 

return self.degree() 

 

def absolute_polynomial(self): 

""" 

A synonym for polynomial. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.absolute_polynomial() 

x^2 + 1 

""" 

return self.polynomial() 

 

def relative_polynomial(self): 

""" 

A synonym for polynomial. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.relative_polynomial() 

x^2 + 1 

""" 

return self.polynomial() 

 

def absolute_vector_space(self): 

""" 

A synonym for vector_space. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.absolute_vector_space() 

(Vector space of dimension 2 over Rational Field, 

Isomorphism map: 

From: Vector space of dimension 2 over Rational Field 

To: Number Field in i with defining polynomial x^2 + 1, 

Isomorphism map: 

From: Number Field in i with defining polynomial x^2 + 1 

To: Vector space of dimension 2 over Rational Field) 

""" 

return self.vector_space() 

 

def relative_vector_space(self): 

""" 

A synonym for vector_space. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.relative_vector_space() 

(Vector space of dimension 2 over Rational Field, 

Isomorphism map: 

From: Vector space of dimension 2 over Rational Field 

To: Number Field in i with defining polynomial x^2 + 1, 

Isomorphism map: 

From: Number Field in i with defining polynomial x^2 + 1 

To: Vector space of dimension 2 over Rational Field) 

""" 

return self.vector_space() 

 

def absolute_discriminant(self): 

""" 

A synonym for discriminant. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.absolute_discriminant() 

-4 

""" 

return self.discriminant() 

 

def relative_discriminant(self): 

""" 

A synonym for discriminant. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.relative_discriminant() 

-4 

""" 

return self.discriminant() 

 

def absolute_different(self): 

""" 

A synonym for different. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.absolute_different() 

Fractional ideal (2) 

""" 

return self.different() 

 

def relative_different(self): 

""" 

A synonym for different. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2 + 1) 

sage: K.relative_different() 

Fractional ideal (2) 

""" 

return self.different() 

 

def hilbert_symbol(self, a, b, P = None): 

r""" 

Returns the Hilbert symbol `(a,b)_P` for a prime P of self 

and non-zero elements a and b of self. 

If P is omitted, return the global Hilbert symbol `(a,b)` instead. 

 

INPUT: 

 

- ``a``, ``b`` -- elements of self 

 

- ``P`` -- (default: None) If `P` is ``None``, compute the global 

symbol. Otherwise, `P` should be either a prime ideal of self 

(which may also be given as a generator or set of generators) 

or a real or complex embedding. 

 

OUTPUT: 

 

If a or b is zero, returns 0. 

 

If a and b are non-zero and P is specified, returns 

the Hilbert symbol `(a,b)_P`, which is 1 if the equation 

`a x^2 + b y^2 = 1` has a solution in the completion of 

self at P, and is -1 otherwise. 

 

If a and b are non-zero and P is unspecified, returns 1 

if the equation has a solution in self and -1 otherwise. 

 

EXAMPLES: 

 

Some global examples:: 

 

sage: K.<a> = NumberField(x^2 - 23) 

sage: K.hilbert_symbol(0, a+5) 

0 

sage: K.hilbert_symbol(a, 0) 

0 

sage: K.hilbert_symbol(-a, a+1) 

1 

sage: K.hilbert_symbol(-a, a+2) 

-1 

sage: K.hilbert_symbol(a, a+5) 

-1 

 

That the latter two are unsolvable should be visible in local 

obstructions. For the first, this is a prime ideal above 19. 

For the second, the ramified prime above 23:: 

 

sage: K.hilbert_symbol(-a, a+2, a+2) 

-1 

sage: K.hilbert_symbol(a, a+5, K.ideal(23).factor()[0][0]) 

-1 

 

More local examples:: 

 

sage: K.hilbert_symbol(a, 0, K.ideal(5)) 

0 

sage: K.hilbert_symbol(a, a+5, K.ideal(5)) 

1 

sage: K.hilbert_symbol(a+1, 13, (a+6)*K.maximal_order()) 

-1 

sage: [emb1, emb2] = K.embeddings(AA) 

sage: K.hilbert_symbol(a, -1, emb1) 

-1 

sage: K.hilbert_symbol(a, -1, emb2) 

1 

 

Ideals P can be given by generators:: 

 

sage: K.<a> = NumberField(x^5 - 23) 

sage: pi = 2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11 

sage: K.hilbert_symbol(a, a+5, pi) 

1 

sage: rho = 2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11 

sage: K.hilbert_symbol(a, a+5, rho) 

1 

 

This also works for non-principal ideals:: 

 

sage: K.<a> = QuadraticField(-5) 

sage: P = K.ideal(3).factor()[0][0] 

sage: P.gens_reduced() # random, could be the other factor 

(3, a + 1) 

sage: K.hilbert_symbol(a, a+3, P) 

1 

sage: K.hilbert_symbol(a, a+3, [3, a+1]) 

1 

 

Primes above 2:: 

 

sage: K.<a> = NumberField(x^5 - 23) 

sage: O = K.maximal_order() 

sage: p = [p[0] for p in (2*O).factor() if p[0].norm() == 16][0] 

sage: K.hilbert_symbol(a, a+5, p) 

1 

sage: K.hilbert_symbol(a, 2, p) 

1 

sage: K.hilbert_symbol(-1, a-2, p) 

-1 

 

Various real fields are allowed:: 

 

sage: K.<a> = NumberField(x^3+x+1) 

sage: K.hilbert_symbol(a/3, 1/2, K.embeddings(RDF)[0]) 

1 

sage: K.hilbert_symbol(a/5, -1, K.embeddings(RR)[0]) 

-1 

sage: [K.hilbert_symbol(a, -1, e) for e in K.embeddings(AA)] 

[-1] 

 

Real embeddings are not allowed to be disguised as complex embeddings:: 

 

sage: K.<a> = QuadraticField(5) 

sage: K.hilbert_symbol(-1, -1, K.embeddings(CC)[0]) 

Traceback (most recent call last): 

... 

ValueError: Possibly real place (=Ring morphism: 

From: Number Field in a with defining polynomial x^2 - 5 

To: Complex Field with 53 bits of precision 

Defn: a |--> -2.23606797749979) given as complex embedding in hilbert_symbol. Is it real or complex? 

sage: K.hilbert_symbol(-1, -1, K.embeddings(QQbar)[0]) 

Traceback (most recent call last): 

... 

ValueError: Possibly real place (=Ring morphism: 

From: Number Field in a with defining polynomial x^2 - 5 

To: Algebraic Field 

Defn: a |--> -2.236067977499790?) given as complex embedding in hilbert_symbol. Is it real or complex? 

sage: K.<b> = QuadraticField(-5) 

sage: K.hilbert_symbol(-1, -1, K.embeddings(CDF)[0]) 

1 

sage: K.hilbert_symbol(-1, -1, K.embeddings(QQbar)[0]) 

1 

 

a and b do not have to be integral or coprime:: 

 

sage: K.<i> = QuadraticField(-1) 

sage: O = K.maximal_order() 

sage: K.hilbert_symbol(1/2, 1/6, 3*O) 

1 

sage: p = 1+i 

sage: K.hilbert_symbol(p, p, p) 

1 

sage: K.hilbert_symbol(p, 3*p, p) 

-1 

sage: K.hilbert_symbol(3, p, p) 

-1 

sage: K.hilbert_symbol(1/3, 1/5, 1+i) 

1 

sage: L = QuadraticField(5, 'a') 

sage: L.hilbert_symbol(-3, -1/2, 2) 

1 

 

Various other examples:: 

 

sage: K.<a> = NumberField(x^3+x+1) 

sage: K.hilbert_symbol(-6912, 24, -a^2-a-2) 

1 

sage: K.<a> = NumberField(x^5-23) 

sage: P = K.ideal(-1105*a^4 + 1541*a^3 - 795*a^2 - 2993*a + 11853) 

sage: Q = K.ideal(-7*a^4 + 13*a^3 - 13*a^2 - 2*a + 50) 

sage: b = -a+5 

sage: K.hilbert_symbol(a,b,P) 

1 

sage: K.hilbert_symbol(a,b,Q) 

1 

sage: K.<a> = NumberField(x^5-23) 

sage: P = K.ideal(-1105*a^4 + 1541*a^3 - 795*a^2 - 2993*a + 11853) 

sage: K.hilbert_symbol(a, a+5, P) 

1 

sage: K.hilbert_symbol(a, 2, P) 

1 

sage: K.hilbert_symbol(a+5, 2, P) 

-1 

sage: K.<a> = NumberField(x^3 - 4*x + 2) 

sage: K.hilbert_symbol(2, -2, K.primes_above(2)[0]) 

1 

 

Check that the bug reported at :trac:`16043` has been fixed:: 

 

sage: K.<a> = NumberField(x^2 + 5) 

sage: p = K.primes_above(2)[0]; p 

Fractional ideal (2, a + 1) 

sage: K.hilbert_symbol(2*a, -1, p) 

1 

sage: K.hilbert_symbol(2*a, 2, p) 

-1 

sage: K.hilbert_symbol(2*a, -2, p) 

-1 

 

AUTHOR: 

 

- Aly Deines (2010-08-19): part of the doctests 

 

- Marco Streng (2010-12-06) 

""" 

if a.is_zero() or b.is_zero(): 

return 0 

a = self(a) 

b = self(b) 

if P is None: 

return pari(self).nfhilbert(a, b) 

 

from sage.categories.map import Map 

from sage.categories.all import Rings 

if isinstance(P, Map) and P.category_for().is_subcategory(Rings()): 

# P is a morphism of Rings 

if P.domain() is not self: 

raise ValueError("Domain of P (=%s) should be self (=%s) in self.hilbert_symbol" % (P, self)) 

codom = P.codomain() 

from sage.rings.complex_field import is_ComplexField 

from sage.rings.complex_interval_field import is_ComplexIntervalField 

from sage.rings.real_mpfr import is_RealField 

from sage.rings.real_mpfi import is_RealIntervalField 

from sage.rings.all import (AA, CDF, QQbar, RDF) 

if is_ComplexField(codom) or is_ComplexIntervalField(codom) or \ 

codom is CDF or codom is QQbar: 

if P(self.gen()).imag() == 0: 

raise ValueError("Possibly real place (=%s) given as complex embedding in hilbert_symbol. Is it real or complex?" % P) 

return 1 

if is_RealField(codom) or codom is RDF or codom is AA: 

if P(a) > 0 or P(b) > 0: 

return 1 

return -1 

if not is_NumberFieldIdeal(P): 

P = self.ideal(P) 

if P.number_field() is not self: 

raise ValueError("P (=%s) should be an ideal of self (=%s) in hilbert_symbol, not of %s" % (P, self, P.number_field())) 

if not P.is_prime(): 

raise ValueError("Non-prime ideal P (=%s) in hilbert_symbol" % P) 

return pari(self).nfhilbert(a, b, P.pari_prime()) 

 

def hilbert_conductor(self,a,b): 

""" 

This is the product of all (finite) primes where the Hilbert symbol is -1. 

What is the same, this is the (reduced) discriminant of the quaternion 

algebra `(a,b)` over a number field. 

 

INPUT: 

 

- ``a``, ``b`` -- elements of the number field ``self`` 

 

OUTPUT: 

 

- squarefree ideal of the ring of integers of ``self`` 

 

EXAMPLES:: 

 

sage: F.<a> = NumberField(x^2-x-1) 

sage: F.hilbert_conductor(2*a,F(-1)) 

Fractional ideal (2) 

sage: K.<b> = NumberField(x^3-4*x+2) 

sage: K.hilbert_conductor(K(2),K(-2)) 

Fractional ideal (1) 

sage: K.hilbert_conductor(K(2*b),K(-2)) 

Fractional ideal (b^2 + b - 2) 

 

AUTHOR: 

 

- Aly Deines 

 

""" 

a, b = self(a), self(b) 

d = self.ideal(1) 

for p in union(union( self.ideal(2).prime_factors(), self.ideal(a).prime_factors()), self.ideal(b).prime_factors()): 

if self.hilbert_symbol(a,b,p) == -1: 

d *= p 

return d 

 

def elements_of_bounded_height(self,bound,precision=53,LLL=False): 

r""" 

Return an iterator over the elements of ``self`` with relative 

multiplicative height at most ``bound``. 

 

The algorithm requires floating point arithmetic, so the user is 

allowed to specify the precision for such calculations. 

 

It might be helpful to work with an LLL-reduced system of fundamental 

units, so the user has the option to perform an LLL reduction for the 

fundamental units by setting ``LLL`` to True. 

 

Certain computations may be faster assuming GRH, which may be done 

globally by using the number_field(True/False) switch. 

 

For details: See [Doyle-Krumm]_. 

 

INPUT: 

 

- ``bound`` - a real number 

- ``precision`` - (default: 53) a positive integer 

- ``LLL`` - (default: False) a boolean value 

 

OUTPUT: 

 

- an iterator of number field elements 

 

.. WARNING:: 

 

In the current implementation, the output of the algorithm cannot be 

guaranteed to be correct due to the necessity of floating point 

computations. In some cases, the default 53-bit precision is 

considerably lower than would be required for the algorithm to 

generate correct output. 

 

.. TODO:: 

 

Should implement a version of the algorithm that guarantees correct 

output. See Algorithm 4 in [Doyle-Krumm]_ for details of an 

implementation that takes precision issues into account. 

 

EXAMPLES: 

 

There are no elements in a number field with multiplicative height less 

than 1:: 

 

sage: K.<g> = NumberField(x^5 - x + 19) 

sage: list(K.elements_of_bounded_height(0.9)) 

[] 

 

The only elements in a number field of height 1 are 0 and the roots of 

unity:: 

 

sage: K.<a> = NumberField(x^2 + x + 1) 

sage: list(K.elements_of_bounded_height(1)) 

[0, a + 1, a, -1, -a - 1, -a, 1] 

 

:: 

 

sage: K.<a> = CyclotomicField(20) 

sage: len(list(K.elements_of_bounded_height(1))) 

21 

 

The elements in the output iterator all have relative multiplicative 

height at most the input bound:: 

 

sage: K.<a> = NumberField(x^6 + 2) 

sage: L = K.elements_of_bounded_height(5) 

sage: for t in L: 

....: exp(6*t.global_height()) 

....: 

1.00000000000000 

1.00000000000000 

1.00000000000000 

2.00000000000000 

2.00000000000000 

2.00000000000000 

2.00000000000000 

4.00000000000000 

4.00000000000000 

4.00000000000000 

4.00000000000000 

 

:: 

 

sage: K.<a> = NumberField(x^2 - 71) 

sage: L = K.elements_of_bounded_height(20) 

sage: all(exp(2*t.global_height()) <= 20 for t in L) # long time (5 s) 

True 

 

:: 

 

sage: K.<a> = NumberField(x^2 + 17) 

sage: L = K.elements_of_bounded_height(120) 

sage: len(list(L)) 

9047 

 

:: 

 

sage: K.<a> = NumberField(x^4 - 5) 

sage: L = K.elements_of_bounded_height(50) 

sage: len(list(L)) # long time (2 s) 

2163 

 

:: 

 

sage: K.<a> = CyclotomicField(13) 

sage: L = K.elements_of_bounded_height(2) 

sage: len(list(L)) # long time (3 s) 

27 

 

:: 

 

sage: K.<a> = NumberField(x^6 + 2) 

sage: L = K.elements_of_bounded_height(60, precision=100) 

sage: len(list(L)) # long time (5 s) 

1899 

 

:: 

 

sage: K.<a> = NumberField(x^4 - x^3 - 3*x^2 + x + 1) 

sage: L = K.elements_of_bounded_height(10, LLL=true) 

sage: len(list(L)) 

99 

 

AUTHORS: 

 

- John Doyle (2013) 

 

- David Krumm (2013) 

""" 

from sage.rings.number_field.bdd_height import bdd_height, bdd_height_iq 

r1, r2 = self.signature() 

r = r1 + r2 - 1 

if self.degree() == 2 and r == 0: 

return bdd_height_iq(self, bound) 

else: 

return bdd_height(self, bound, precision, LLL) 

 

class NumberField_cyclotomic(NumberField_absolute): 

""" 

Create a cyclotomic extension of the rational field. 

 

The command CyclotomicField(n) creates the n-th cyclotomic field, 

obtained by adjoining an n-th root of unity to the rational field. 

 

EXAMPLES:: 

 

sage: CyclotomicField(3) 

Cyclotomic Field of order 3 and degree 2 

sage: CyclotomicField(18) 

Cyclotomic Field of order 18 and degree 6 

sage: z = CyclotomicField(6).gen(); z 

zeta6 

sage: z^3 

-1 

sage: (1+z)^3 

6*zeta6 - 3 

 

:: 

 

sage: K = CyclotomicField(197) 

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

True 

sage: loads((z^2).dumps()) == z^2 

True 

 

:: 

 

sage: cf12 = CyclotomicField( 12 ) 

sage: z12 = cf12.0 

sage: cf6 = CyclotomicField( 6 ) 

sage: z6 = cf6.0 

sage: FF = Frac( cf12['x'] ) 

sage: x = FF.0 

sage: z6*x^3/(z6 + x) 

zeta12^2*x^3/(x + zeta12^2) 

 

:: 

 

sage: cf6 = CyclotomicField(6) ; z6 = cf6.gen(0) 

sage: cf3 = CyclotomicField(3) ; z3 = cf3.gen(0) 

sage: cf3(z6) 

zeta3 + 1 

sage: cf6(z3) 

zeta6 - 1 

sage: type(cf6(z3)) 

<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 

sage: cf1 = CyclotomicField(1) ; z1 = cf1.0 

sage: cf3(z1) 

1 

sage: type(cf3(z1)) 

<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 

""" 

def __init__(self, n, names, embedding=None, assume_disc_small=False, maximize_at_primes=None): 

""" 

A cyclotomic field, i.e., a field obtained by adjoining an n-th 

root of unity to the rational numbers. 

 

EXAMPLES:: 

 

sage: k = CyclotomicField(3) 

sage: type(k) 

<class 'sage.rings.number_field.number_field.NumberField_cyclotomic_with_category'> 

 

TESTS: 

 

The ``gcd`` and ``xgcd`` methods do not agree on this field, see 

:trac:`23274`:: 

 

sage: TestSuite(k).run() 

Failure in _test_gcd_vs_xgcd: 

... 

AssertionError: The methods gcd and xgcd disagree on Cyclotomic Field of order 3 and degree 2: 

gcd(0,2) = 1 

xgcd(0,2) = (2, 0, 1) 

------------------------------------------------------------ 

The following tests failed: _test_gcd_vs_xgcd 

 

:: 

 

sage: type(CyclotomicField(4).zero()) 

<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 

sage: type(CyclotomicField(6).one()) 

<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 

sage: type(CyclotomicField(6).an_element()) 

<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 

sage: type(CyclotomicField(15).zero()) 

<type 'sage.rings.number_field.number_field_element.NumberFieldElement_absolute'> 

""" 

f = QQ['x'].cyclotomic_polynomial(n) 

if names[0].startswith('zeta'): 

latex_name = "\\zeta_{%s}"%n 

else: 

latex_name = latex_variable_name(names[0]) 

self.__n = n = Integer(n) 

NumberField_absolute.__init__(self, f, 

name= names, 

latex_name=latex_name, 

check=False, 

embedding = embedding, 

assume_disc_small=assume_disc_small, 

maximize_at_primes=maximize_at_primes) 

if n%2: 

self.__zeta_order = 2*n 

else: 

self.__zeta_order = n 

## quadratic number fields require this: 

if f.degree() == 2: 

# define a boolean flag as for NumberField_quadratic to know, which 

# square root we choose (True means no embedding or positive 

# imaginary value). 

# Note that the test is done with NumberFieldElement and not with 

# NumberFieldElement_quadratic which requires somehow this flag. 

# As a consequence, a result of _an_element_() with the wrong class 

# is cached during the call to has_coerce_map_from. We reset the 

# cache afterwards. 

self._standard_embedding = not CDF.has_coerce_map_from(self) or CDF(self.gen()).imag() > 0 

self._cache_an_element = None 

 

self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic 

if n == 4: 

self._D = ZZ(-1) 

self._NumberField_generic__gen = self._element_class(self, (QQ(0), QQ(1))) 

else: 

## n is 3 or 6 

self._D = ZZ(-3) 

one_half = ZZ(1)/ZZ(2) 

if n == 3: 

self._NumberField_generic__gen = self._element_class(self, (one_half-1, one_half)) 

else: 

self._NumberField_generic__gen = self._element_class(self, (one_half, one_half)) 

 

# NumberField_absolute.__init__(...) set _zero_element and 

# _one_element to NumberFieldElement_absolute values, which is 

# wrong (and dangerous; such elements can actually be used to 

# crash Sage: see #5316). Overwrite them with correct values. 

self._zero_element = self._element_class(self, (QQ(0),QQ(0))) 

self._one_element = self._element_class(self, (QQ(1),QQ(0))) 

 

zeta = self.gen() 

zeta._set_multiplicative_order(n) 

self._init_embedding_approx() 

 

def construction(self): 

""" 

Return data defining a functorial construction of ``self``. 

 

EXAMPLES:: 

 

sage: F, R = CyclotomicField(5).construction() 

sage: R 

Rational Field 

sage: F.polys 

[x^4 + x^3 + x^2 + x + 1] 

sage: F.names 

['zeta5'] 

sage: F.embeddings 

[0.309016994374948? + 0.951056516295154?*I] 

sage: F.structures 

[None] 

""" 

F,R = NumberField_generic.construction(self) 

F.cyclotomic = self.__n 

return F,R 

 

def _magma_init_(self, magma): 

""" 

Function returning a string to create this cyclotomic field in 

Magma. 

 

.. note:: 

 

The Magma generator name is also initialized to be the same 

as for the Sage field. 

 

EXAMPLES:: 

 

sage: K=CyclotomicField(7,'z') 

sage: K._magma_init_(magma) # optional - magma 

'SageCreateWithNames(CyclotomicField(7),["z"])' 

sage: K=CyclotomicField(7,'zeta') 

sage: K._magma_init_(magma) # optional - magma 

'SageCreateWithNames(CyclotomicField(7),["zeta"])' 

""" 

s = 'CyclotomicField(%s)'%self.__n 

return magma._with_names(s, self.variable_names()) 

 

def _gap_init_(self): 

""" 

Return a string that provides a representation of ``self`` in GAP. 

 

TESTS:: 

 

sage: K = CyclotomicField(8) 

sage: gap(K) # indirect doctest 

CF(8) 

sage: gap(K.0) 

E(8) 

sage: K(gap(K.0^5)); K(gap(K.0^5))==K.0^5 

-zeta8 

True 

 

The following was the motivating example to introduce 

a genuine representation of cyclotomic fields in the 

GAP interface -- see :trac:`5618`. :: 

 

sage: H = AlternatingGroup(4) 

sage: g = H.list()[1] 

sage: K = H.subgroup([g]) 

sage: z = CyclotomicField(3).an_element(); z 

zeta3 

sage: c = K.character([1,z,z**2]); c 

Character of Subgroup of (Alternating group of order 4!/2 as a permutation group) generated by [(1,2,3)] 

sage: c(g^2); z^2 

-zeta3 - 1 

-zeta3 - 1 

 

""" 

return 'CyclotomicField(%s)'%self.__n 

 

def _libgap_(self): 

""" 

Return a LibGAP representation of ``self``. 

 

TESTS:: 

 

sage: K = CyclotomicField(8) 

sage: K._libgap_() 

CF(8) 

sage: libgap(K) # indirect doctest 

CF(8) 

""" 

from sage.libs.gap.libgap import libgap 

return libgap.CyclotomicField(self.__n) 

 

def _repr_(self): 

r""" 

Return string representation of this cyclotomic field. 

 

The "order" of the cyclotomic field `\QQ(\zeta_n)` 

in the string output refers to the order of the `\zeta_n`, 

i.e., it is the integer `n`. The degree is the degree of 

the field as an extension of `\QQ`. 

 

EXAMPLES:: 

 

sage: CyclotomicField(4)._repr_() 

'Cyclotomic Field of order 4 and degree 2' 

sage: CyclotomicField(400)._repr_() 

'Cyclotomic Field of order 400 and degree 160' 

""" 

return "Cyclotomic Field of order %s and degree %s"%( 

self.__n, self.degree()) 

 

def _n(self): 

""" 

Return the n used to create this cyclotomic field. 

 

EXAMPLES:: 

 

sage: CyclotomicField(3).zeta_order() 

6 

sage: CyclotomicField(3)._n() 

3 

""" 

return self.__n 

 

def _latex_(self): 

""" 

Return the latex representation of this cyclotomic field. 

 

EXAMPLES:: 

 

sage: Z = CyclotomicField(4) 

sage: Z.gen() 

zeta4 

sage: latex(Z) # indirect doctest 

\Bold{Q}(\zeta_{4}) 

 

Latex printing respects the generator name:: 

 

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

sage: latex(k) 

\Bold{Q}[a]/(a^{2} + 1) 

sage: k 

Cyclotomic Field of order 4 and degree 2 

sage: k.gen() 

a 

 

TESTS: 

 

We check that the bug reported on :trac:`8938` is fixed:: 

 

sage: C5.<z> = CyclotomicField(5) 

sage: P.<s, t> = C5[] 

sage: f = (z^2 + z)*s 

sage: f 

(z^2 + z)*s 

sage: latex(f) 

\left(z^{2} + z\right) s 

""" 

v = self.latex_variable_name() 

if v.startswith('\\zeta_'): 

return "%s(%s)"%(latex(QQ), v) 

else: 

return NumberField_generic._latex_(self) 

 

def _coerce_map_from_(self, K): 

r""" 

Return a coercion map from `K` to ``self``, or None. 

 

The cyclotomic field `\QQ(\zeta_n)` coerces into the 

cyclotomic field `\QQ(\zeta_m)` if and only if `n' \mid m`, 

where `n'` is the odd part of `n` if `4 \nmid n` and `n' = n` 

otherwise. 

 

The morphism is consistent with the chosen embedding into `\CC`. 

 

If `K` is not a cyclotomic field, the normal coercion rules 

for number fields are used. 

 

EXAMPLES:: 

 

sage: K.<a> = CyclotomicField(12) 

sage: L.<b> = CyclotomicField(132) 

sage: L.coerce_map_from(K) # indirect doctest 

Generic morphism: 

From: Cyclotomic Field of order 12 and degree 4 

To: Cyclotomic Field of order 132 and degree 40 

Defn: a -> b^11 

sage: a + b 

b^11 + b 

sage: L.coerce_map_from(CyclotomicField(4, 'z')) 

Generic morphism: 

From: Cyclotomic Field of order 4 and degree 2 

To: Cyclotomic Field of order 132 and degree 40 

Defn: z -> b^33 

sage: L.coerce_map_from(CyclotomicField(5, 'z')) is None 

True 

 

sage: K.<a> = CyclotomicField(3) 

sage: L.<b> = CyclotomicField(6) 

sage: L.coerce_map_from(K) 

Generic morphism: 

From: Cyclotomic Field of order 3 and degree 2 

To: Cyclotomic Field of order 6 and degree 2 

Defn: a -> b - 1 

sage: K.coerce_map_from(L) 

Generic morphism: 

From: Cyclotomic Field of order 6 and degree 2 

To: Cyclotomic Field of order 3 and degree 2 

Defn: b -> a + 1 

 

sage: CyclotomicField(33).coerce_map_from(CyclotomicField(66)) 

Generic morphism: 

From: Cyclotomic Field of order 66 and degree 20 

To: Cyclotomic Field of order 33 and degree 20 

Defn: zeta66 -> -zeta33^17 

sage: CyclotomicField(15).coerce_map_from(CyclotomicField(6)) 

Generic morphism: 

From: Cyclotomic Field of order 6 and degree 2 

To: Cyclotomic Field of order 15 and degree 8 

Defn: zeta6 -> zeta15^5 + 1 

 

Check that :trac:`12632` is fixed:: 

 

sage: K1 = CyclotomicField(1); K2 = CyclotomicField(2) 

sage: K1.coerce_map_from(K2) 

Generic morphism: 

From: Cyclotomic Field of order 2 and degree 1 

To: Cyclotomic Field of order 1 and degree 1 

Defn: zeta2 -> -1 

 

Check that custom embeddings are respected (:trac:`13765`):: 

 

sage: z105 = CDF(exp(2*pi*I/105)) 

sage: Ka.<a> = CyclotomicField(105, embedding=z105^11) 

sage: Kb.<b> = CyclotomicField(35, embedding=z105^6) 

sage: Ka.coerce_map_from(Kb) 

Generic morphism: 

From: Cyclotomic Field of order 35 and degree 24 

To: Cyclotomic Field of order 105 and degree 48 

Defn: b -> -a^44 - a^42 + a^39 + a^37 + a^35 - a^29 - a^27 - a^25 + a^24 - a^23 + a^22 - a^21 + a^20 + a^18 + a^16 - a^12 - a^10 - a^8 - a^6 + a^5 + a^3 + a 

sage: CC(b) 

0.936234870639737 + 0.351374824081343*I 

sage: CC(-a^44 - a^42 + a^39 + a^37 + a^35 - a^29 - a^27 - a^25 + a^24 - a^23 + a^22 - a^21 + a^20 + a^18 + a^16 - a^12 - a^10 - a^8 - a^6 + a^5 + a^3 + a) 

0.936234870639731 + 0.351374824081341*I 

 

sage: z15 = CDF(exp(2*pi*I/15)) 

sage: CyclotomicField(15).coerce_map_from(CyclotomicField(6, embedding=-z15^5)) 

Generic morphism: 

From: Cyclotomic Field of order 6 and degree 2 

To: Cyclotomic Field of order 15 and degree 8 

Defn: zeta6 -> -zeta15^5 

 

sage: CyclotomicField(15, embedding=z15^4).coerce_map_from(CyclotomicField(6, embedding=-z15^5)) 

Generic morphism: 

From: Cyclotomic Field of order 6 and degree 2 

To: Cyclotomic Field of order 15 and degree 8 

Defn: zeta6 -> -zeta15^5 

 

Check transitivity of coercion embeddings (:trac:`20513`):: 

 

sage: K60.<zeta60> = CyclotomicField(60) 

sage: K30.<zeta30> = CyclotomicField(30, embedding=zeta60**14) 

sage: K15.<zeta15> = CyclotomicField(15, embedding=zeta30**26) 

sage: K5.<zeta5> = CyclotomicField(5, embedding=zeta15**12) 

sage: K60.has_coerce_map_from(K5) 

True 

sage: K60(zeta5) 

-zeta60^14 - zeta60^12 + zeta60^6 + zeta60^4 - 1 

sage: _ == zeta60**(14*26*12) 

True 

""" 

if isinstance(K, NumberField_cyclotomic): 

if (self.coerce_embedding() is None or K.coerce_embedding() is None): 

return None 

ambient_field = self.coerce_embedding().codomain() 

if not ambient_field.has_coerce_map_from(K.coerce_embedding().codomain()): 

return None 

Kn = K.__n 

n = self.__n 

if Kn.divides(n): 

return number_field_morphisms.CyclotomicFieldEmbedding(K, self) 

if Kn == 2 and n == 1: 

# see #12632 

return number_field_morphisms.NumberFieldEmbedding(K, self, -self.gen()) 

if Kn % 4 == 2 and (Kn//2).divides(n): 

e = self._log_gen(ambient_field(-K.gen())) 

return number_field_morphisms.NumberFieldEmbedding(K, self, -self.gen() ** e) 

else: 

return None 

 

elif self.degree() == 2: 

if K is ZZ: 

return number_field_element_quadratic.Z_to_quadratic_field_element(self) 

if K is QQ: 

return number_field_element_quadratic.Q_to_quadratic_field_element(self) 

 

return NumberField_absolute._coerce_map_from_(self, K) 

 

def _log_gen(self, x): 

""" 

Returns an integer `e` such that `self.gen()^e == x`, or `None` 

if no such integer exists. This is primarily used to construct 

embedding-respecting coercions. 

 

If `x` is complex, the result is either an integer `e` such 

that the absolute value of `self.gen()^e-x` is small or 

`None` if no such `e` is found. 

 

EXAMPLES:: 

 

sage: K.<a> = CyclotomicField(5) 

sage: K._log_gen(CDF(a)) 

1 

sage: K._log_gen(CDF(a^4)) 

4 

 

sage: zeta105 = CC(exp(2*pi*i/105)) 

sage: K.<a> = CyclotomicField(105, embedding=zeta105^13) 

sage: zeta105^13, CC(a) 

(0.712376096951345 + 0.701797902883992*I, 0.712376096951345 + 0.701797902883991*I) 

sage: K._log_gen(zeta105^26) 

2 

sage: K._log_gen(zeta105) 

97 

sage: zeta105, CC(a^97) 

(0.998210129767735 + 0.0598041539450342*I, 0.998210129767736 + 0.0598041539450313*I) 

sage: K._log_gen(zeta105^3) 

81 

sage: zeta105^3, CC(a)^81 

(0.983929588598630 + 0.178556894798637*I, 0.983929588598631 + 0.178556894798635*I) 

 

sage: K.<a> = CyclotomicField(5, embedding=None) 

sage: K._log_gen(CDF(.5, -.8)) is None 

True 

 

sage: zeta5 = cyclotomic_polynomial(5).change_ring(Qp(11)).roots()[0][0] 

sage: zeta5 ^ 5 

1 + O(11^20) 

sage: K.<a> = CyclotomicField(5, embedding=zeta5^2) 

sage: K._log_gen(zeta5) 

3 

 

sage: K60.<zeta60> = CyclotomicField(60) 

sage: K30.<zeta30> = CyclotomicField(30, embedding=zeta60**2) 

sage: K15.<zeta15> = CyclotomicField(15, embedding=zeta30**2) 

sage: K5.<zeta5> = CyclotomicField(5, embedding=zeta15**12) 

sage: K60._log_gen(zeta30) 

2 

sage: K60._log_gen(zeta15) 

4 

sage: K60._log_gen(zeta5) 

48 

sage: K5._log_gen(zeta15**3) 

4 

""" 

X = x.parent() 

gen = self.gen() 

 

if self.has_coerce_map_from(X): 

Y = self 

x = self(x) 

elif X.has_coerce_map_from(self): 

Y = X 

gen = X(self.gen()) 

else: 

return 

 

n = self._n() 

if CDF.has_coerce_map_from(Y): 

x = CDF(x) 

gen = CDF(gen) 

# Let zeta = e^(2*pi*i/n) 

two_pi = 2*RDF.pi() 

a = (n * x.arg() / two_pi).round() # x = zeta^a 

b = (n * gen.arg() / two_pi).round() # gen = zeta^b 

e = mod(a/b, n).lift() # e is the expected result 

if abs(gen**e-x) < 1/n: # a sanity check 

return e 

else: 

# NOTE: this can be *very* slow! 

gen_pow_e = 1 

for e in range(n): 

if gen_pow_e == x: 

return e 

gen_pow_e *= gen 

 

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

""" 

Create an element of this cyclotomic field from `x`. 

 

EXAMPLES: 

 

The following example illustrates coercion from the 

cyclotomic field Q(zeta_42) to the cyclotomic field Q(zeta_6), in 

a case where such coercion is defined:: 

 

sage: k42 = CyclotomicField(42) 

sage: k6 = CyclotomicField(6) 

sage: a = k42.gen(0) 

sage: b = a^7 

sage: b 

zeta42^7 

sage: k6(b) # indirect doctest 

zeta6 

sage: b^2 

zeta42^7 - 1 

sage: k6(b^2) 

zeta6 - 1 

 

Conversion of elements of the :class:`~sage.rings.universal_cyclotomic_field.UniversalCyclotomicField`:: 

 

sage: CF = CyclotomicField(5) 

sage: UCF.<E> = UniversalCyclotomicField() 

sage: CF(E(5)) 

zeta5 

 

sage: CF = CyclotomicField(10) 

sage: CF(E(5)) 

zeta10^2 

 

Coercion of GAP cyclotomic elements is also supported:: 

 

sage: CyclotomicField(18)(gap('E(3)')) # indirect doctest 

zeta18^3 - 1 

 

Converting from rings of integers:: 

 

sage: K.<z> = CyclotomicField(7) 

sage: O = K.maximal_order() 

sage: K(O.1) 

z 

sage: K(O.1^2 + O.1 - 2) 

z^2 + z - 2 

""" 

if isinstance(x, number_field_element.NumberFieldElement): 

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

return self._coerce_from_other_cyclotomic_field(x) 

else: 

return NumberField_absolute._element_constructor_(self, x) 

elif isinstance(x, pari_gen): 

return NumberField_absolute._element_constructor_(self, x, check=check) 

elif (sage.interfaces.gap.is_GapElement(x) or 

isinstance(x, sage.libs.gap.element.GapElement)): 

return self._coerce_from_gap(x) 

elif isinstance(x,str): 

return self._convert_from_str(x) 

 

# late import because of speed 

from sage.rings.universal_cyclotomic_field import UniversalCyclotomicFieldElement 

if isinstance(x,UniversalCyclotomicFieldElement): 

return x.to_cyclotomic_field(self) 

else: 

return self._convert_non_number_field_element(x) 

 

# TODO: 

# The following is very nice and much more flexible / powerful. 

# However, it is simply not *consistent*, since it totally 

# breaks the doctests in eisenstein_submodule.py. 

# FIX THIS. 

 

## def _will_be_better_coerce_from_other_cyclotomic_field(self, x, only_canonical=False): 

## """ 

## Coerce an element x of a cyclotomic field into self, if at all possible. 

 

## INPUT: 

## x -- number field element 

 

## only_canonical -- bool (default: False); Attempt to work, 

## even in some cases when x is not in a subfield of 

## the cyclotomics (as long as x is a root of unity). 

 

## EXAMPLES:: 

 

## sage: k5 = CyclotomicField(5) 

## sage: k3 = CyclotomicField(3) 

## sage: k15 = CyclotomicField(15) 

## sage: k15._coerce_from_other_cyclotomic_field(k3.gen()) 

## zeta15^5 

## sage: k15._coerce_from_other_cyclotomic_field(k3.gen()^2 + 17/3) 

## -zeta15^5 + 14/3 

## sage: k3._coerce_from_other_cyclotomic_field(k15.gen()^5) 

## zeta3 

## sage: k3._coerce_from_other_cyclotomic_field(-2/3 * k15.gen()^5 + 2/3) 

## -2/3*zeta3 + 2/3 

## """ 

 

## K = x.parent() 

 

## if K is self: 

## return x 

## n = K.zeta_order() 

## m = self.zeta_order() 

 

 

## self_gen = self.gen() 

 

## if m % n == 0: # easy case 

## # pass this off to a method in the element class 

## # it can be done very quickly and easily by the cython<->NTL 

## # interface there 

## return x._lift_cyclotomic_element(self) 

 

## # Whatever happens below, it has to be consistent with 

## # zeta_r |---> (zeta_s)^m 

 

## if m % 2 and not n%2: 

## m *= 2 

## self_gen = -self_gen 

 

## if only_canonical and m % n: 

## raise TypeError, "no canonical coercion" 

 

## if not is_CyclotomicField(K): 

## raise TypeError, "x must be in a cyclotomic field" 

 

## v = x.list() 

 

## # Find the smallest power r >= 1 of the generator g of K that is in self, 

## # i.e., find the smallest r such that g^r has order dividing m. 

 

## d = sage.arith.all.gcd(m,n) 

## r = n // d 

 

## # Since we use the power basis for cyclotomic fields, if every 

## # v[i] with i not divisible by r is 0, then we're good. 

 

## # If h generates self and has order m, then the element g^r 

## # maps to the power of self of order gcd(m,n)., i.e., h^(m/gcd(m,n)) 

## # 

## z = self_gen**(m // d) 

## w = self(1) 

 

## a = self(0) 

## for i in range(len(v)): 

## if i%r: 

## if v[i]: 

## raise TypeError, "element does not belong to cyclotomic field" 

## else: 

## a += w*v[i] 

## w *= z 

## return a 

 

def _coerce_from_other_cyclotomic_field(self, x, only_canonical=False): 

""" 

Coerce an element x of a cyclotomic field into self, if at all 

possible. 

 

INPUT: 

 

 

- ``x`` - number field element 

 

- ``only_canonical`` - bool (default: False); Attempt 

to work, even in some cases when x is not in a subfield of the 

cyclotomics (as long as x is a root of unity). 

 

 

EXAMPLES:: 

 

sage: K = CyclotomicField(24) ; L = CyclotomicField(48) 

sage: L._coerce_from_other_cyclotomic_field(K.0+1) 

zeta48^2 + 1 

sage: K(L.0**2) 

zeta24 

""" 

K = x.parent() 

if K is self: 

return x 

n = K._n() 

m = self._n() 

if m % n == 0: # easy case 

# pass this off to a method in the element class 

# it can be done very quickly and easily by the 

# Cython<->NTL interface there 

return x._lift_cyclotomic_element(self) 

else: 

if only_canonical: 

raise TypeError 

n = x.multiplicative_order() 

m = self.zeta_order() 

if m % n == 0: 

# Harder case. E.g., x = (zeta_42)^7 and 

# self.__zeta = zeta_6, so it is possible to 

# coerce x in, but not zeta_42 in. 

# Algorithm: 

# 1. Compute self.__zeta as an element 

# of K = parent of x. Call this y. 

# 2. Write x as a power r of y. 

# TODO: we do step two STUPIDLY. 

# 3. Return self.__zeta to the power r. 

y = K(self.zeta(m)) 

z = y 

for r in range(y.multiplicative_order()): 

if z == x: 

return self.zeta(m)**(r+1) 

z *= y 

raise TypeError("Cannot coerce %s into %s"%(x,self)) 

return self._element_class(self, g) 

 

 

def _coerce_from_gap(self, x): 

""" 

Attempt to coerce a GAP number field element into this cyclotomic 

field. 

 

EXAMPLES:: 

 

sage: k5.<z> = CyclotomicField(5) 

sage: gap('E(5)^7 + 3') 

-3*E(5)-2*E(5)^2-3*E(5)^3-3*E(5)^4 

sage: w = gap('E(5)^7 + 3') 

sage: z^7 + 3 

z^2 + 3 

sage: k5(w) # indirect doctest 

z^2 + 3 

 

It may be that GAP uses a name for the generator of the cyclotomic field. 

We can deal with this case, if this name coincides with the name in Sage:: 

 

sage: F = CyclotomicField(8) 

sage: z = F.gen() 

sage: a = gap(z+1/z); a 

E(8)-E(8)^3 

sage: F(a) 

-zeta8^3 + zeta8 

 

Matrices over cyclotomic fields are correctly dealt with it as well:: 

 

sage: b = gap(Matrix(F,[[z^2,1],[0,a+1]])); b 

[ [ E(4), 1 ], [ 0, 1+E(8)-E(8)^3 ] ] 

sage: b[1,2] 

1 

sage: F(b[1,2]) 

1 

sage: matrix(F, b) 

[ zeta8^2 1] 

[ 0 -zeta8^3 + zeta8 + 1] 

 

It also word with libGAP instead of GAP:: 

 

sage: b = libgap.eval('[[E(4), 1], [0, 1+E(8)-E(8)^3]]') 

sage: matrix(F, b) 

[ zeta8^2 1] 

[ 0 -zeta8^3 + zeta8 + 1] 

""" 

if x.IsRat(): 

return self(QQ(x)) 

coeffs = x.CoeffsCyc(self.__n) 

zeta = self.gen() 

return sum(QQ(c)*zeta**i for i,c in enumerate(coeffs)) 

 

def _Hom_(self, codomain, cat=None): 

""" 

Return homset of homomorphisms from the cyclotomic field self to 

the number field codomain. 

 

The cat option is currently ignored. 

 

EXAMPLES: 

 

This function is implicitly called by the Hom method or 

function. 

 

:: 

 

sage: K.<a> = NumberField(x^2 + 3); K 

Number Field in a with defining polynomial x^2 + 3 

sage: CyclotomicField(3).Hom(K) # indirect doctest 

Set of field embeddings from Cyclotomic Field of order 3 and degree 2 to Number Field in a with defining polynomial x^2 + 3 

sage: End(CyclotomicField(21)) 

Automorphism group of Cyclotomic Field of order 21 and degree 12 

""" 

if is_NumberFieldHomsetCodomain(codomain): 

from . import morphism 

return morphism.CyclotomicFieldHomset(self, codomain) 

else: 

raise TypeError 

 

def is_galois(self): 

""" 

Return True since all cyclotomic fields are automatically Galois. 

 

EXAMPLES:: 

 

sage: CyclotomicField(29).is_galois() 

True 

""" 

return True 

 

def is_isomorphic(self, other): 

""" 

Return True if the cyclotomic field self is isomorphic as a number 

field to other. 

 

EXAMPLES:: 

 

sage: CyclotomicField(11).is_isomorphic(CyclotomicField(22)) 

True 

sage: CyclotomicField(11).is_isomorphic(CyclotomicField(23)) 

False 

sage: CyclotomicField(3).is_isomorphic(NumberField(x^2 + x +1, 'a')) 

True 

sage: CyclotomicField(18).is_isomorphic(CyclotomicField(9)) 

True 

sage: CyclotomicField(10).is_isomorphic(NumberField(x^4 - x^3 + x^2 - x + 1, 'b')) 

True 

 

Check :trac:`14300`:: 

 

sage: K = CyclotomicField(4) 

sage: N = K.extension(x^2-5, 'z') 

sage: K.is_isomorphic(N) 

False 

sage: K.is_isomorphic(CyclotomicField(8)) 

False 

""" 

if is_CyclotomicField(other): 

return self.zeta_order() == other.zeta_order() 

return NumberField_generic.is_isomorphic(self, other) 

 

def complex_embedding(self, prec=53): 

r""" 

Return the embedding of this cyclotomic field into the approximate 

complex field with precision prec obtained by sending the generator 

`\zeta` of self to exp(2\*pi\*i/n), where `n` is 

the multiplicative order of `\zeta`. 

 

EXAMPLES:: 

 

sage: C = CyclotomicField(4) 

sage: C.complex_embedding() 

Ring morphism: 

From: Cyclotomic Field of order 4 and degree 2 

To: Complex Field with 53 bits of precision 

Defn: zeta4 |--> 6.12323399573677e-17 + 1.00000000000000*I 

 

Note in the example above that the way zeta is computed (using sin 

and cosine in MPFR) means that only the prec bits of the number 

after the decimal point are valid. 

 

:: 

 

sage: K = CyclotomicField(3) 

sage: phi = K.complex_embedding(10) 

sage: phi(K.0) 

-0.50 + 0.87*I 

sage: phi(K.0^3) 

1.0 

sage: phi(K.0^3 - 1) 

0.00 

sage: phi(K.0^3 + 7) 

8.0 

""" 

CC = sage.rings.complex_field.ComplexField(prec) 

return self.hom([CC.zeta(self._n())], check=False) 

 

def complex_embeddings(self, prec=53): 

r""" 

Return all embeddings of this cyclotomic field into the approximate 

complex field with precision prec. 

 

If you want 53-bit double precision, which is faster but less 

reliable, then do ``self.embeddings(CDF)``. 

 

EXAMPLES:: 

 

sage: CyclotomicField(5).complex_embeddings() 

[ 

Ring morphism: 

From: Cyclotomic Field of order 5 and degree 4 

To: Complex Field with 53 bits of precision 

Defn: zeta5 |--> 0.309016994374947 + 0.951056516295154*I, 

Ring morphism: 

From: Cyclotomic Field of order 5 and degree 4 

To: Complex Field with 53 bits of precision 

Defn: zeta5 |--> -0.809016994374947 + 0.587785252292473*I, 

Ring morphism: 

From: Cyclotomic Field of order 5 and degree 4 

To: Complex Field with 53 bits of precision 

Defn: zeta5 |--> -0.809016994374947 - 0.587785252292473*I, 

Ring morphism: 

From: Cyclotomic Field of order 5 and degree 4 

To: Complex Field with 53 bits of precision 

Defn: zeta5 |--> 0.309016994374947 - 0.951056516295154*I 

] 

""" 

CC = sage.rings.complex_field.ComplexField(prec) 

try: 

return self.__embeddings[CC] 

except AttributeError: 

self.__embeddings = {} 

except KeyError: 

pass 

n = self._n() 

z = CC.zeta(n) 

X = [m for m in range(n) if arith.gcd(m,n) == 1] 

v = [self.hom([z**n], check=False) for n in X] 

self.__embeddings[CC] = Sequence(v, cr=True, immutable=True, 

check=False, universe=self.Hom(CC)) 

return self.__embeddings[CC] 

 

def real_embeddings(self, prec=53): 

r""" 

Return all embeddings of this cyclotomic field into the approximate 

real field with precision prec. 

 

Mostly, of course, there are no such embeddings. 

 

EXAMPLES:: 

 

sage: CyclotomicField(4).real_embeddings() 

[] 

sage: CyclotomicField(2).real_embeddings() 

[ 

Ring morphism: 

From: Cyclotomic Field of order 2 and degree 1 

To: Real Field with 53 bits of precision 

Defn: -1 |--> -1.00000000000000 

] 

""" 

K = sage.rings.real_mpfr.RealField(prec) 

n = self._n() 

if n > 2: 

return Sequence([], cr=False, immutable=True, 

check=False, universe=self.Hom(K)) 

else: 

return self.embeddings(K) 

 

def signature(self): 

""" 

Return (r1, r2), where r1 and r2 are the number of real embeddings 

and pairs of complex embeddings of this cyclotomic field, 

respectively. 

 

Trivial since, apart from QQ, cyclotomic fields are totally 

complex. 

 

EXAMPLES:: 

 

sage: CyclotomicField(5).signature() 

(0, 2) 

sage: CyclotomicField(2).signature() 

(1, 0) 

""" 

m = ZZ(self.degree()) 

if m == 1: 

return (ZZ(1), ZZ(0)) 

else: 

return (ZZ(0), ZZ(m/2)) 

 

def different(self): 

""" 

Returns the different ideal of the cyclotomic field self. 

 

EXAMPLES:: 

 

sage: C20 = CyclotomicField(20) 

sage: C20.different() 

Fractional ideal (10, 2*zeta20^6 - 4*zeta20^4 - 4*zeta20^2 + 2) 

sage: C18 = CyclotomicField(18) 

sage: D = C18.different().norm() 

sage: D == C18.discriminant().abs() 

True 

""" 

try: 

return self.__different 

 

except AttributeError: 

 

z = self.gen() 

n = self._n() 

D = self.ideal(1) 

factors = n.factor() 

for f in factors: 

p = f[0] 

r = f[1] 

e = (r*p - r - 1)*p**(r-1) 

D *= self.ideal(z**(n/p**r) - 1)**e 

self.__different = D 

return self.__different 

 

def discriminant(self, v=None): 

""" 

Returns the discriminant of the ring of integers of the cyclotomic 

field self, or if v is specified, the determinant of the trace 

pairing on the elements of the list v. 

 

Uses the formula for the discriminant of a prime power cyclotomic 

field and Hilbert Theorem 88 on the discriminant of composita. 

 

INPUT: 

 

 

- ``v (optional)`` - list of element of this number 

field 

 

 

OUTPUT: Integer if v is omitted, and Rational otherwise. 

 

EXAMPLES:: 

 

sage: CyclotomicField(20).discriminant() 

4000000 

sage: CyclotomicField(18).discriminant() 

-19683 

""" 

if v is None: 

try: 

return self.__disc 

except AttributeError: 

n = self._n() 

deg = self.degree() 

d = ZZ(1) # so that CyclotomicField(1).disc() has the right type 

factors = n.factor() 

for (p, r) in factors: 

e = (r*p - r - 1) * deg // (p-1) 

d *= p**e 

sign = 1 

if len(factors) == 1 and (n == 4 or factors[0][0].mod(4) == 3): 

sign = -1 

elif len(factors) == 2 and factors[0] == (2, 1) and factors[1][0].mod(4) == 3: 

sign = -1 

self.__disc = sign*d 

return self.__disc 

else: 

return NumberField_generic.discriminant(self, v) 

 

def next_split_prime(self, p=2): 

""" 

Return the next prime integer `p` that splits completely in 

this cyclotomic field (and does not ramify). 

 

EXAMPLES:: 

 

sage: K.<z> = CyclotomicField(3) 

sage: K.next_split_prime(7) 

13 

""" 

n = self._n() 

while True: 

p = arith.next_prime(p) 

if p % n == 1: 

return p 

 

def _pari_integral_basis(self, v=None, important=True): 

""" 

Internal function returning an integral basis of this number field in 

PARI format. 

 

This field is cyclotomic, so this is a trivial computation, 

since the power basis on the generator is an integral basis. 

Thus the ``v`` and ``important`` parameters are ignored. 

 

EXAMPLES:: 

 

sage: CyclotomicField(5)._pari_integral_basis() 

[1, y, y^2, y^3] 

sage: len(CyclotomicField(137)._pari_integral_basis()) 

136 

""" 

try: 

return self._integral_basis_dict[tuple()] 

except KeyError: 

z = pari(self.gen()) 

a = pari(1) 

B = [] 

for n in range(self.degree()): 

B.append(a.lift()) 

a *= z 

self._integral_basis_dict[tuple()] = pari(B) 

return B 

 

 

def zeta_order(self): 

""" 

Return the order of the maximal root of unity contained in this 

cyclotomic field. 

 

EXAMPLES:: 

 

sage: CyclotomicField(1).zeta_order() 

2 

sage: CyclotomicField(4).zeta_order() 

4 

sage: CyclotomicField(5).zeta_order() 

10 

sage: CyclotomicField(5)._n() 

5 

sage: CyclotomicField(389).zeta_order() 

778 

""" 

return self.__zeta_order 

 

def _multiplicative_order_table(self): 

""" 

Return a dictionary that maps powers of zeta to their order. This 

makes computing the orders of the elements of finite order in this 

field faster. 

 

EXAMPLES:: 

 

sage: v = CyclotomicField(6)._multiplicative_order_table() 

sage: w = v.items(); w.sort(); w 

[(-1, 2), (1, 1), (-x, 3), (-x + 1, 6), (x - 1, 3), (x, 6)] 

""" 

try: 

return self.__multiplicative_order_table 

except AttributeError: 

t = {} 

x = self(1) 

n = self.zeta_order() 

m = 0 

zeta = self.zeta(n) 

# todo: this desperately needs to be optimized!!! 

for i in range(n): 

t[x.polynomial()] = n//arith.GCD(m,n) # multiplicative_order of (zeta_n)**m 

x *= zeta 

m += 1 

self.__multiplicative_order_table = t 

return t 

 

def zeta(self, n=None, all=False): 

""" 

Return an element of multiplicative order `n` in this 

cyclotomic field. 

 

If there is no such element, raise a ``ValueError``. 

 

INPUT: 

 

- ``n`` -- integer (default: None, returns element of 

maximal order) 

 

- ``all`` -- bool (default: False) - whether to return 

a list of all primitive `n`-th roots of unity. 

 

OUTPUT: root of unity or list 

 

EXAMPLES:: 

 

sage: k = CyclotomicField(4) 

sage: k.zeta() 

zeta4 

sage: k.zeta(2) 

-1 

sage: k.zeta().multiplicative_order() 

4 

 

:: 

 

sage: k = CyclotomicField(21) 

sage: k.zeta().multiplicative_order() 

42 

sage: k.zeta(21).multiplicative_order() 

21 

sage: k.zeta(7).multiplicative_order() 

7 

sage: k.zeta(6).multiplicative_order() 

6 

sage: k.zeta(84) 

Traceback (most recent call last): 

.. 

ValueError: 84 does not divide order of generator (42) 

 

:: 

 

sage: K.<a> = CyclotomicField(7) 

sage: K.zeta(all=True) 

[-a^4, -a^5, a^5 + a^4 + a^3 + a^2 + a + 1, -a, -a^2, -a^3] 

sage: K.zeta(14, all=True) 

[-a^4, -a^5, a^5 + a^4 + a^3 + a^2 + a + 1, -a, -a^2, -a^3] 

sage: K.zeta(2, all=True) 

[-1] 

sage: K.<a> = CyclotomicField(10) 

sage: K.zeta(20, all=True) 

Traceback (most recent call last): 

... 

ValueError: 20 does not divide order of generator (10) 

 

:: 

 

sage: K.<a> = CyclotomicField(5) 

sage: K.zeta(4) 

Traceback (most recent call last): 

... 

ValueError: 4 does not divide order of generator (10) 

sage: v = K.zeta(5, all=True); v 

[a, a^2, a^3, -a^3 - a^2 - a - 1] 

sage: [b^5 for b in v] 

[1, 1, 1, 1] 

""" 

if n is None: 

n = self.zeta_order() 

else: 

n = Integer(n) 

 

z = self.gen() 

m = self._n() 

if n % 2 == 0 and m % 2 == 1: 

# In the n-th cyclotomic field, n odd, there are 

# actually 2*n-th roots of unity, so we include them. 

z = -z**((m+1)//2) # -z 

m = 2*m 

if m % n != 0: 

raise ValueError("%s does not divide order of generator (%s)" % 

(n, self.zeta_order())) 

a = z**(m//n) 

if not all: 

return a 

 

v = [a] 

b = a*a 

for i in range(2,n): 

if n.gcd(i).is_one(): 

v.append(b) 

b = b * a 

return v 

 

def number_of_roots_of_unity(self): 

""" 

Return number of roots of unity in this cyclotomic field. 

 

EXAMPLES:: 

 

sage: K.<a> = CyclotomicField(21) 

sage: K.number_of_roots_of_unity() 

42 

""" 

n = self._n() 

if n%2: 

n *= 2 

return n 

 

def roots_of_unity(self): 

""" 

Return all the roots of unity in this cyclotomic field, primitive 

or not. 

 

EXAMPLES:: 

 

sage: K.<a> = CyclotomicField(3) 

sage: zs = K.roots_of_unity(); zs 

[1, a, -a - 1, -1, -a, a + 1] 

sage: [ z**K.number_of_roots_of_unity() for z in zs ] 

[1, 1, 1, 1, 1, 1] 

""" 

z = self.gen() 

n = self._n() 

v = [z**k for k in range(n)] 

if n%2: 

v += [-x for x in v] 

return v 

 

 

class NumberField_quadratic(NumberField_absolute): 

r""" 

Create a quadratic extension of the rational field. 

 

The command ``QuadraticField(a)`` creates the field `\QQ(\sqrt{a})`. 

 

EXAMPLES:: 

 

sage: QuadraticField(3, 'a') 

Number Field in a with defining polynomial x^2 - 3 

sage: QuadraticField(-4, 'b') 

Number Field in b with defining polynomial x^2 + 4 

""" 

def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding=None, 

assume_disc_small=False, maximize_at_primes=None, structure=None): 

""" 

Create a quadratic number field. 

 

EXAMPLES:: 

 

sage: k.<a> = QuadraticField(5, check=False); k 

Number Field in a with defining polynomial x^2 - 5 

 

Don't do this:: 

 

sage: k.<a> = QuadraticField(4, check=False); k 

Number Field in a with defining polynomial x^2 - 4 

 

TESTS:: 

 

sage: k.<a> = QuadraticField(7) 

sage: type(k.zero()) 

<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 

sage: type(k.one()) 

<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 

 

sage: TestSuite(k).run() 

 

Check that :trac:`23008` is fixed:: 

 

sage: z = polygen(ZZ, 'z') 

sage: K.<phi> = NumberField(z^2 - z - 1, embedding=QQbar(golden_ratio)) 

sage: floor(phi) 

1 

""" 

NumberField_absolute.__init__(self, polynomial, name=name, check=check, 

embedding=embedding, latex_name=latex_name, 

assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes, structure=structure) 

self._standard_embedding = True 

self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic 

c, b, a = [QQ(t) for t in self.defining_polynomial().list()] 

# set the generator 

Dpoly = b*b - 4*a*c 

D = (Dpoly.numer() * Dpoly.denom()).squarefree_part(bound=10000) 

self._D = D 

parts = -b/(2*a), (Dpoly/D).sqrt()/(2*a) 

self._NumberField_generic__gen = self._element_class(self, parts) 

 

# we must set the flag _standard_embedding *before* any element creation 

# Note that in the following code, no element is built. 

if self.coerce_embedding() is not None and CDF.has_coerce_map_from(self): 

rootD = CDF(number_field_element_quadratic.NumberFieldElement_quadratic(self, (QQ(0),QQ(1)))) 

if D > 0: 

self._standard_embedding = rootD.real() > 0 

else: 

self._standard_embedding = rootD.imag() > 0 

 

# we reset _NumberField_generic__gen has the flag standard_embedding 

# might be modified 

self._NumberField_generic__gen = self._element_class(self, parts) 

 

# NumberField_absolute.__init__(...) set _zero_element and 

# _one_element to NumberFieldElement_absolute values, which is 

# wrong (and dangerous; such elements can actually be used to 

# crash Sage: see #5316). Overwrite them with correct values. 

self._zero_element = self._element_class(self, (QQ(0), QQ(0))) 

self._one_element = self._element_class(self, (QQ(1), QQ(0))) 

 

def _coerce_map_from_(self, K): 

""" 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(-3) 

sage: f = K.coerce_map_from(QQ); f # indirect doctest 

Natural morphism: 

From: Rational Field 

To: Number Field in a with defining polynomial x^2 + 3 

sage: f(3/5) 

3/5 

sage: parent(f(3/5)) is K 

True 

 

sage: g = K.coerce_map_from(ZZ); g # indirect doctest 

Natural morphism: 

From: Integer Ring 

To: Number Field in a with defining polynomial x^2 + 3 

sage: g(1) 

1 

sage: parent(g(1)) is K 

True 

""" 

if K is ZZ: 

return number_field_element_quadratic.Z_to_quadratic_field_element(self) 

if K is int: 

return self._coerce_map_via([ZZ], int) # faster than direct 

if K is QQ: 

return number_field_element_quadratic.Q_to_quadratic_field_element(self) 

return NumberField_absolute._coerce_map_from_(self, K) 

 

def _latex_(self): 

""" 

Return the latex representation of this quadratic field. 

 

EXAMPLES:: 

 

sage: Z = QuadraticField(7) 

sage: latex(Z) # indirect doctest 

\Bold{Q}(\sqrt{7}) 

 

sage: Z = QuadraticField(7, latex_name='x') 

sage: latex(Z) # indirect doctest 

\Bold{Q}[x]/(x^{2} - 7) 

""" 

v = self.latex_variable_name() 

if v.startswith('\\sqrt'): 

return "%s(%s)"%(latex(QQ), v) 

else: 

return NumberField_generic._latex_(self) 

 

def _polymake_init_(self): 

r""" 

Return the polymake representation of this quadratic field. 

 

This is merely a string, and does not represent a specific quadratic field. 

In polymake, only the elements know which field they belong to. 

 

EXAMPLES:: 

 

sage: Z = QuadraticField(7) 

sage: polymake(Z) # optional - polymake # indirect doctest 

QuadraticExtension 

 

""" 

return '"QuadraticExtension"' 

 

def discriminant(self, v=None): 

""" 

Returns the discriminant of the ring of integers of the number 

field, or if v is specified, the determinant of the trace pairing 

on the elements of the list v. 

 

INPUT: 

 

 

- ``v (optional)`` - list of element of this number 

field 

 

 

OUTPUT: Integer if v is omitted, and Rational otherwise. 

 

EXAMPLES:: 

 

sage: K.<i> = NumberField(x^2+1) 

sage: K.discriminant() 

-4 

sage: K.<a> = NumberField(x^2+5) 

sage: K.discriminant() 

-20 

sage: K.<a> = NumberField(x^2-5) 

sage: K.discriminant() 

5 

""" 

if v is None: 

try: 

return self.__disc 

except AttributeError: 

d = self._D.squarefree_part() 

if d % 4 != 1: 

d *= 4 

self.__disc = d 

return self.__disc 

else: 

return NumberField_generic.discriminant(self, v) 

 

def is_galois(self): 

""" 

Return True since all quadratic fields are automatically Galois. 

 

EXAMPLES:: 

 

sage: QuadraticField(1234,'d').is_galois() 

True 

""" 

return True 

 

def class_number(self, proof=None): 

r""" 

Return the size of the class group of self. 

 

If proof = False (*not* the default!) and the discriminant of the 

field is negative, then the following warning from the PARI manual 

applies: 

 

.. warning:: 

 

For `D<0`, this function may give incorrect results when 

the class group has a low exponent (has many cyclic 

factors), because implementing Shank's method in full 

generality slows it down immensely. 

 

EXAMPLES:: 

 

sage: QuadraticField(-23,'a').class_number() 

3 

 

These are all the primes so that the class number of 

`\QQ(\sqrt{-p})` is `1`:: 

 

sage: [d for d in prime_range(2,300) if not is_square(d) and QuadraticField(-d,'a').class_number() == 1] 

[2, 3, 7, 11, 19, 43, 67, 163] 

 

It is an open problem to *prove* that there are infinity many 

positive square-free `d` such that 

`\QQ(\sqrt{d})` has class number `1`: 

 

:: 

 

sage: len([d for d in range(2,200) if not is_square(d) and QuadraticField(d,'a').class_number() == 1]) 

121 

 

TESTS:: 

 

sage: type(QuadraticField(-23,'a').class_number()) 

<type 'sage.rings.integer.Integer'> 

sage: type(NumberField(x^3 + 23, 'a').class_number()) 

<type 'sage.rings.integer.Integer'> 

sage: type(NumberField(x^3 + 23, 'a').extension(x^2 + 5, 'b').class_number()) 

<type 'sage.rings.integer.Integer'> 

sage: type(CyclotomicField(10).class_number()) 

<type 'sage.rings.integer.Integer'> 

""" 

proof = proof_flag(proof) 

try: 

return self.__class_number 

except AttributeError: 

self.__class_number = self.discriminant().class_number(proof) 

return self.__class_number 

 

def hilbert_class_field_defining_polynomial(self, name='x'): 

r""" 

Returns a polynomial over `\QQ` whose roots generate the 

Hilbert class field of this quadratic field as an extension of 

this quadratic field. 

 

.. note:: 

 

Computed using PARI via Schertz's method. This 

implementation is quite fast. 

 

EXAMPLES:: 

 

sage: K.<b> = QuadraticField(-23) 

sage: K.hilbert_class_field_defining_polynomial() 

x^3 - x^2 + 1 

 

Note that this polynomial is not the actual Hilbert class 

polynomial: see ``hilbert_class_polynomial``:: 

 

sage: K.hilbert_class_polynomial() 

x^3 + 3491750*x^2 - 5151296875*x + 12771880859375 

 

:: 

 

sage: K.<a> = QuadraticField(-431) 

sage: K.class_number() 

21 

sage: K.hilbert_class_field_defining_polynomial(name='z') 

z^21 + 6*z^20 + 9*z^19 - 4*z^18 + 33*z^17 + 140*z^16 + 220*z^15 + 243*z^14 + 297*z^13 + 461*z^12 + 658*z^11 + 743*z^10 + 722*z^9 + 681*z^8 + 619*z^7 + 522*z^6 + 405*z^5 + 261*z^4 + 119*z^3 + 35*z^2 + 7*z + 1 

""" 

f = pari(self.discriminant()).quadhilbert() 

return QQ[name](f) 

 

def hilbert_class_field(self, names): 

r""" 

Returns the Hilbert class field of this quadratic field as a 

relative extension of this field. 

 

.. note:: 

 

For the polynomial that defines this field as a relative 

extension, see the ``hilbert_class_field_defining_polynomial`` 

command, which is vastly faster than this command, since it doesn't 

construct a relative extension. 

 

EXAMPLES:: 

 

sage: K.<a> = NumberField(x^2 + 23) 

sage: L = K.hilbert_class_field('b'); L 

Number Field in b with defining polynomial x^3 - x^2 + 1 over its base field 

sage: L.absolute_field('c') 

Number Field in c with defining polynomial x^6 - 2*x^5 + 70*x^4 - 90*x^3 + 1631*x^2 - 1196*x + 12743 

sage: K.hilbert_class_field_defining_polynomial() 

x^3 - x^2 + 1 

""" 

f = self.hilbert_class_field_defining_polynomial() 

return self.extension(f, names) 

 

def hilbert_class_polynomial(self, name='x'): 

r""" 

Compute the Hilbert class polynomial of this quadratic field. 

 

Right now, this is only implemented for imaginary quadratic 

fields. 

 

EXAMPLES:: 

 

sage: K.<a> = QuadraticField(-3) 

sage: K.hilbert_class_polynomial() 

x 

 

sage: K.<a> = QuadraticField(-31) 

sage: K.hilbert_class_polynomial(name='z') 

z^3 + 39491307*z^2 - 58682638134*z + 1566028350940383 

""" 

D = self.discriminant() 

 

if D > 0: 

raise NotImplementedError("Hilbert class polynomial is not implemented for real quadratic fields.") 

 

from sage.schemes.elliptic_curves.all import hilbert_class_polynomial as HCP 

return QQ[name](HCP(D)) 

 

def is_fundamental_discriminant(D): 

r""" 

Return True if the integer `D` is a fundamental 

discriminant, i.e., if `D \cong 0,1\pmod{4}`, and 

`D\neq 0, 1` and either (1) `D` is square free or 

(2) we have `D\cong 0\pmod{4}` with 

`D/4 \cong 2,3\pmod{4}` and `D/4` square free. These 

are exactly the discriminants of quadratic fields. 

 

EXAMPLES:: 

 

sage: [D for D in range(-15,15) if is_fundamental_discriminant(D)] 

[-15, -11, -8, -7, -4, -3, 5, 8, 12, 13] 

sage: [D for D in range(-15,15) if not is_square(D) and QuadraticField(D,'a').disc() == D] 

[-15, -11, -8, -7, -4, -3, 5, 8, 12, 13] 

""" 

d = D % 4 

if not (d in [0,1]): 

return False 

return D != 1 and D != 0 and \ 

(arith.is_squarefree(D) or \ 

(d == 0 and (D//4)%4 in [2,3] and arith.is_squarefree(D//4))) 

 

 

################### 

# For pickling 

################### 

 

 

def NumberField_absolute_v1(poly, name, latex_name, canonical_embedding=None): 

""" 

Used for unpickling old pickles. 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import NumberField_absolute_v1 

sage: R.<x> = QQ[] 

sage: NumberField_absolute_v1(x^2 + 1, 'i', 'i') 

Number Field in i with defining polynomial x^2 + 1 

""" 

return NumberField(polynomial=poly, name=name, latex_name=latex_name, check=False, embedding=canonical_embedding) 

 

NumberField_generic_v1 = NumberField_absolute_v1 # for historical reasons only (so old objects unpickle) 

 

def NumberField_cyclotomic_v1(zeta_order, name, canonical_embedding=None): 

""" 

Used for unpickling old pickles. 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import NumberField_cyclotomic_v1 

sage: NumberField_cyclotomic_v1(5,'a') 

Cyclotomic Field of order 5 and degree 4 

sage: NumberField_cyclotomic_v1(5,'a').variable_name() 

'a' 

""" 

return CyclotomicField(n=zeta_order, names=name, embedding=canonical_embedding) 

 

def NumberField_quadratic_v1(poly, name, canonical_embedding=None): 

""" 

Used for unpickling old pickles. 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import NumberField_quadratic_v1 

sage: R.<x> = QQ[] 

sage: NumberField_quadratic_v1(x^2 - 2, 'd') 

Number Field in d with defining polynomial x^2 - 2 

""" 

return NumberField(polynomial=poly, name=name, check=False, embedding=canonical_embedding) 

 

def put_natural_embedding_first(v): 

""" 

Helper function for embeddings() functions for number fields. 

 

INPUT: a list of embeddings of a number field 

 

OUTPUT: None. The 

list is altered in-place, so that, if possible, the first embedding 

has been switched with one of the others, so that if there is an 

embedding which preserves the generator names then it appears 

first. 

 

EXAMPLES:: 

 

sage: K.<a> = CyclotomicField(7) 

sage: embs = K.embeddings(K) 

sage: [e(a) for e in embs] # random - there is no natural sort order 

[a, a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1] 

sage: id = [ e for e in embs if e(a) == a ][0]; id 

Ring endomorphism of Cyclotomic Field of order 7 and degree 6 

Defn: a |--> a 

sage: permuted_embs = list(embs); permuted_embs.remove(id); permuted_embs.append(id) 

sage: [e(a) for e in permuted_embs] # random - but natural map is not first 

[a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1, a] 

sage: permuted_embs[0] != a 

True 

sage: from sage.rings.number_field.number_field import put_natural_embedding_first 

sage: put_natural_embedding_first(permuted_embs) 

sage: [e(a) for e in permuted_embs] # random - but natural map is first 

[a, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1, a^2] 

sage: permuted_embs[0] == id 

True 

""" 

for i in range(len(v)): 

phi = v[i] 

a = str(list(phi.domain().gens())) 

b = str(list(phi.im_gens())) 

if a == b: 

v[i] = v[0] 

v[0] = phi 

return 

 

 

 

def refine_embedding(e, prec=None): 

r""" 

Given an embedding from a number field to either `\RR` or 

`\CC`, returns an equivalent embedding with higher precision. 

 

INPUT: 

 

 

- ``e`` - an embedding of a number field into either 

RR or CC (with some precision) 

 

- ``prec`` - (default None) the desired precision; if None, 

current precision is doubled; if Infinity, the equivalent 

embedding into either ``QQbar`` or ``AA`` is returned. 

 

EXAMPLES:: 

 

sage: from sage.rings.number_field.number_field import refine_embedding 

sage: K = CyclotomicField(3) 

sage: e10 = K.complex_embedding(10) 

sage: e10.codomain().precision() 

10 

sage: e25 = refine_embedding(e10, prec=25) 

sage: e25.codomain().precision() 

25 

 

An example where we extend a real embedding into ``AA``:: 

 

sage: K.<a> = NumberField(x^3-2) 

sage: K.signature() 

(1, 1) 

sage: e = K.embeddings(RR)[0]; e 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Real Field with 53 bits of precision 

Defn: a |--> 1.25992104989487 

sage: e = refine_embedding(e,Infinity); e 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Algebraic Real Field 

Defn: a |--> 1.259921049894873? 

 

Now we can obtain arbitrary precision values with no trouble:: 

 

sage: RealField(150)(e(a)) 

1.2599210498948731647672106072782283505702515 

sage: _^3 

2.0000000000000000000000000000000000000000000 

sage: RealField(200)(e(a^2-3*a+7)) 

4.8076379022835799804500738174376232086807389337953290695624 

 

Complex embeddings can be extended into ``QQbar``:: 

 

sage: e = K.embeddings(CC)[0]; e 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Complex Field with 53 bits of precision 

Defn: a |--> -0.62996052494743... - 1.09112363597172*I 

sage: e = refine_embedding(e,Infinity); e 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 - 2 

To: Algebraic Field 

Defn: a |--> -0.6299605249474365? - 1.091123635971722?*I 

sage: ComplexField(200)(e(a)) 

-0.62996052494743658238360530363911417528512573235075399004099 - 1.0911236359717214035600726141898088813258733387403009407036*I 

sage: e(a)^3 

2 

 

Embeddings into lazy fields work:: 

 

sage: L = CyclotomicField(7) 

sage: x = L.specified_complex_embedding(); x 

Generic morphism: 

From: Cyclotomic Field of order 7 and degree 6 

To: Complex Lazy Field 

Defn: zeta7 -> 0.623489801858734? + 0.781831482468030?*I 

sage: refine_embedding(x, 300) 

Ring morphism: 

From: Cyclotomic Field of order 7 and degree 6 

To: Complex Field with 300 bits of precision 

Defn: zeta7 |--> 0.623489801858733530525004884004239810632274730896402105365549439096853652456487284575942507 + 0.781831482468029808708444526674057750232334518708687528980634958045091731633936441700868007*I 

sage: refine_embedding(x, infinity) 

Ring morphism: 

From: Cyclotomic Field of order 7 and degree 6 

To: Algebraic Field 

Defn: zeta7 |--> 0.6234898018587335? + 0.7818314824680299?*I 

 

When the old embedding is into the real lazy field, 

then only real embeddings should be considered. 

See :trac:`17495`:: 

 

sage: R.<x> = QQ[] 

sage: K.<a> = NumberField(x^3 + x - 1, embedding=0.68) 

sage: from sage.rings.number_field.number_field import refine_embedding 

sage: refine_embedding(K.specified_complex_embedding(), 100) 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + x - 1 

To: Real Field with 100 bits of precision 

Defn: a |--> 0.68232780382801932736948373971 

sage: refine_embedding(K.specified_complex_embedding(), Infinity) 

Ring morphism: 

From: Number Field in a with defining polynomial x^3 + x - 1 

To: Algebraic Real Field 

Defn: a |--> 0.6823278038280193? 

""" 

K = e.domain() 

RC = e.codomain() 

if RC in (sage.rings.qqbar.AA, sage.rings.qqbar.QQbar): 

return e 

if RC in (RLF, CLF): 

prec_old = e.gen_image().approx().prec() 

old_root = e(K.gen()).approx() 

else: 

prec_old = RC.precision() 

old_root = e(K.gen()) 

 

if prec is None: 

prec = 2*prec_old 

elif prec_old >= prec: 

return e 

 

# We first compute all the embeddings at the new precision: 

if sage.rings.real_mpfr.is_RealField(RC) or RC in (RDF, RLF): 

if prec == Infinity: 

elist = K.embeddings(sage.rings.qqbar.AA) 

else: 

elist = K.real_embeddings(prec) 

else: 

if prec == Infinity: 

elist = K.embeddings(sage.rings.qqbar.QQbar) 

else: 

elist = K.complex_embeddings(prec) 

 

# Now we determine which is an extension of the old one; this 

# relies on the fact that coercing a high-precision root into a 

# field with lower precision will equal the lower-precision root! 

diffs = [(RC(ee(K.gen()))-old_root).abs() for ee in elist] 

return elist[min(zip(diffs, count()))[1]] 

 

def is_real_place(v): 

r""" 

Return ``True`` if ``v`` is real, ``False`` if ``v`` is complex 

 

INPUT: 

 

- ``v`` -- an infinite place of ``K`` 

 

OUTPUT: 

 

A boolean indicating whether a place is real (``True``) or complex (``False``). 

 

EXAMPLES:: 

 

sage: K.<xi> = NumberField(x^3-3) 

sage: phi_real = K.places()[0] 

sage: phi_complex = K.places()[1] 

sage: v_fin = tuple(K.primes_above(3))[0] 

 

sage: is_real_place(phi_real) 

True 

 

sage: is_real_place(phi_complex) 

False 

 

It is an error to put in a finite place 

 

:: 

 

sage: is_real_place(v_fin) 

Traceback (most recent call last): 

... 

AttributeError: 'NumberFieldFractionalIdeal' object has no attribute 'im_gens' 

 

""" 

RR = sage.rings.real_mpfr.RealField(53) 

try: 

RR(v.im_gens()[0]) 

return True 

except TypeError: 

return False