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

r""" 

Univariate Skew Polynomials 

  

This module provides the 

:class:`~sage.rings.polynomial.skew_polynomial_element.SkewPolynomial`, 

which constructs a single univariate skew polynomial over commutative 

base rings and an automorphism over the base ring. Skew polynomials are 

non-commutative and so principal methods such as gcd, lcm, monic, 

multiplication, and division are given in left and right forms. 

  

The generic implementation of dense skew polynomials is 

:class:`~sage.rings.polynomial.skew_polynomial_element.SkewPolynomial_generic_dense`. 

The classes  

:class:`~sage.rings.polynomial.skew_polynomial_element.ConstantSkewPolynomialSection` 

and :class:`~sage.rings.polynomial.skew_polynomial_element.SkewPolynomialBaseringInjection` 

handle conversion from a skew polynomial ring to its base ring and vice versa respectively. 

  

.. WARNING:: 

  

The current semantics of 

:meth:`~sage.rings.polynomial.skew_polynomial_element.SkewPolynomial.__call__` 

are experimental, so a warning is thrown when a skew polynomial is evaluated 

for the first time in a session. See the method documentation for details. 

  

TESTS:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 2*(t + x) + 1 

sage: a(t^2) 

doctest:...: FutureWarning: This class/method/function is marked as 

experimental. It, its functionality or its interface might change 

without a formal deprecation. 

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

2*t^3 + 3*t^2 + 4*t + 2 

sage: a(t) 

2*t^2 + 3*t + 2 

  

AUTHORS: 

  

- Xavier Caruso (2012-06-29): initial version 

  

- Arpit Merchant (2016-08-04): improved docstrings, fixed doctests and 

refactored classes and methods 

  

- Johan Rosenkilde (2016-08-03): changes for bug fixes, docstring and 

doctest errors 

  

""" 

  

############################################################################# 

# Copyright (C) 2012 Xavier Caruso <xavier.caruso@normalesup.org> 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 2 of the License, or 

# (at your option) any later version. 

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

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

  

from __future__ import print_function, absolute_import, division 

  

import re 

from copy import copy 

from sage.rings.infinity import infinity 

from sage.structure.factorization import Factorization 

from sage.structure.element cimport Element, RingElement, AlgebraElement, ModuleElement 

from sage.structure.parent cimport Parent 

from sage.structure.parent_gens cimport ParentWithGens 

from sage.misc.abstract_method import abstract_method 

from sage.categories.homset import Hom 

from sage.categories.fields import Fields 

from sage.rings.integer cimport Integer 

from cpython.object cimport PyObject_RichCompare 

from sage.categories.map cimport Map 

from sage.rings.morphism cimport Morphism, RingHomomorphism 

from sage.rings.polynomial.polynomial_element cimport _dict_to_list 

from sage.structure.element import coerce_binop 

from sage.misc.superseded import experimental 

  

cdef class SkewPolynomial(AlgebraElement): 

r""" 

Abstract base class for skew polynomials. 

  

This class must be inherited from and have key methods overridden. 

  

.. RUBRIC:: Definition 

  

Let `R` be a commutative ring equipped with an automorphism `\sigma`. 

  

Then, a skew polynomial is given by the equation: 

  

.. MATH:: 

  

F(X) = a_{n} X^{n} + \cdots + a_0, 

  

where the coefficients `a_i \in R` and `X` is a formal variable. 

  

Addition between two skew polynomials is defined by the usual addition 

operation and the modified multiplication is defined by the rule 

`X a = \sigma(a) X` for all `a` in `R`. Skew polynomials are thus 

non-commutative and the degree of a product is equal to the sum of the 

degrees of the factors. 

  

Let `a` and `b` be two skew polynomials in the same ring `S`. 

The *left (resp. right) euclidean division* of `a` by `b` is a couple 

`(q,r)` of elements in `S` such that 

  

- `a = q b + r` (resp. `a = b q + r`) 

  

- the degree of `r` is less than the degree of `b` 

  

`q` (resp. `r`) is called the *quotient* (resp. the remainder) 

of this euclidean division. 

  

.. RUBRIC:: Properties 

  

Keeping the previous notation, if the leading coefficient of `b` 

is a unit (e.g. if `b` is monic) then the quotient and the remainder 

in the *right* euclidean division exist and are unique. 

  

The same result holds for the *left* euclidean division if in addition 

the twist map defining the skew polynomial ring is invertible. 

  

.. RUBRIC:: Evaluation 

  

The value of a given a skew polynomial `p(x) = \sum_{i=0}^d a_i x^i` 

at `r` is calculated using the formula: 

  

.. MATH:: 

  

p(r) = \sum_{i=0}^d a_i \sigma^i(r) 

  

where `\sigma` is the base ring automorphism. This is called 

the *operator evaluation* method. 

  

EXAMPLES: 

  

We illustrate some functionalities implemented in this class. 

  

We create the skew polynomial ring:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma]; S 

Skew Polynomial Ring in x over Univariate Polynomial Ring in t over Integer Ring 

twisted by t |--> t + 1 

  

and some elements in it:: 

  

sage: a = t + x + 1; a 

x + t + 1 

sage: b = S([t^2,t+1,1]); b 

x^2 + (t + 1)*x + t^2 

sage: c = S.random_element(degree=3,monic=True); c 

x^3 + (-95*t^2 + t + 2)*x^2 + (-t^2 + t)*x + 2*t - 8 

  

Ring operations are supported:: 

  

sage: a + b 

x^2 + (t + 2)*x + t^2 + t + 1 

sage: a - b 

-x^2 - t*x - t^2 + t + 1 

  

sage: a * b 

x^3 + (2*t + 3)*x^2 + (2*t^2 + 4*t + 2)*x + t^3 + t^2 

sage: b * a 

x^3 + (2*t + 4)*x^2 + (2*t^2 + 3*t + 2)*x + t^3 + t^2 

sage: a * b == b * a 

False 

  

sage: b^2 

x^4 + (2*t + 4)*x^3 + (3*t^2 + 7*t + 6)*x^2 

+ (2*t^3 + 4*t^2 + 3*t + 1)*x + t^4 

sage: b^2 == b*b 

True 

  

Sage also implements arithmetic over skew polynomial rings. You will find 

below a short panorama:: 

  

sage: q,r = c.right_quo_rem(b) 

sage: q 

x - 95*t^2 

sage: r 

(95*t^3 + 93*t^2 - t - 1)*x + 95*t^4 + 2*t - 8 

sage: c == q*b + r 

True 

  

The operators ``//`` and ``%`` give respectively the quotient 

and the remainder of the *right* euclidean division:: 

  

sage: q == c // b 

True 

sage: r == c % b 

True 

  

Left euclidean division won't work over our current `S` because Sage can't 

invert the twist map:: 

  

sage: q,r = c.left_quo_rem(b) 

Traceback (most recent call last): 

... 

NotImplementedError: inversion of the twist map Ring endomorphism of Univariate Polynomial Ring in t over Integer Ring 

Defn: t |--> t + 1 

  

Here we can see the effect of the operator evaluation compared to the usual 

polynomial evaluation:: 

  

sage: a = x^2 

sage: a(t) 

t + 2 

  

Here is a working example over a finite field:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x^4 + (4*t + 1)*x^3 + (t^2 + 3*t + 3)*x^2 + (3*t^2 + 2*t + 2)*x + (3*t^2 + 3*t + 1) 

sage: b = (2*t^2 + 3)*x^2 + (3*t^2 + 1)*x + 4*t + 2 

sage: q,r = a.left_quo_rem(b) 

sage: q 

(4*t^2 + t + 1)*x^2 + (2*t^2 + 2*t + 2)*x + 2*t^2 + 4*t + 3 

sage: r 

(t + 2)*x + 3*t^2 + 2*t + 4 

sage: a == b*q + r 

True 

  

Once we have euclidean divisions, we have for free gcd and lcm 

(at least if the base ring is a field):: 

  

sage: a = (x + t) * (x + t^2)^2 

sage: b = (x + t) * (t*x + t + 1) * (x + t^2) 

sage: a.right_gcd(b) 

x + t^2 

sage: a.left_gcd(b) 

x + t 

  

The left lcm has the following meaning: given skew polynomials `a` and `b`, 

their left lcm is the least degree polynomial `c = ua = vb` for some skew 

polynomials `u, v`. Such a `c` always exist if the base ring is a field:: 

  

sage: c = a.left_lcm(b); c 

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

sage: c.is_right_divisible_by(a) 

True 

sage: c.is_right_divisible_by(b) 

True 

  

The right lcm is defined similarly as the least degree polynomial `c = au = 

bv` for some `u,v`:: 

  

sage: d = a.right_lcm(b); d 

x^5 + (t^2 + 1)*x^4 + (3*t^2 + 3*t + 3)*x^3 + (3*t^2 + t + 2)*x^2 + (4*t^2 + 3*t)*x + 4*t + 4 

sage: d.is_left_divisible_by(a) 

True 

sage: d.is_left_divisible_by(b) 

True 

  

.. SEEALSO:: 

  

- :mod:`sage.rings.polynomial.skew_polynomial_ring` 

- :mod:`sage.rings.polynomial.skew_polynomial_ring_constructor` 

""" 

def __init__(self, parent, construct=False): 

r""" 

Initialize ``self``. 

  

INPUT: 

  

- ``parent`` -- parent of ``self`` 

  

- ``construct`` -- boolean (default: ``False``) 

  

TESTS:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: P = x + t 

sage: TestSuite(P).run() 

sage: Q = S([1, t, t+2]) 

sage: TestSuite(Q).run() 

""" 

AlgebraElement.__init__(self, parent) 

  

cdef long _hash_c(self): 

raise NotImplementedError 

  

def __hash__(self): 

r""" 

Return hash of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: hash(a) == hash(a) 

True 

""" 

return self._hash_c() 

  

cdef void _inplace_rmul(self, SkewPolynomial_generic_dense right): 

raise NotImplementedError 

cdef void _inplace_pow(self, Py_ssize_t n): 

raise NotImplementedError 

  

cpdef int degree(self): 

r""" 

Return the degree of ``self``. 

  

By convention, the zero skew polynomial has degree `-1`. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^2 + t*x^3 + t^2*x + 1 

sage: a.degree() 

3 

sage: S.zero().degree() 

-1 

sage: S(5).degree() 

0 

""" 

  

cdef SkewPolynomial _new_c(self, list coeffs, Parent P, char check=0): 

r""" 

Fast creation of a new skew polynomial 

  

.. NOTE:: 

  

Override this function in classes which inherit 

from SkewPolynomial. 

""" 

l = P(coeffs) 

return l 

  

cpdef SkewPolynomial _new_constant_poly(self, RingElement a, Parent P, char check=0): 

r""" 

Fast creation of a new constant skew polynomial 

  

EXAMPLES:: 

  

sage: from sage.rings.polynomial.skew_polynomial_element import SkewPolynomialBaseringInjection 

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: SkewPolynomialBaseringInjection(k, k['x', Frob]) #indirect doctest 

Skew Polynomial base injection morphism: 

From: Finite Field in t of size 5^3 

To: Skew Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 

""" 

if a: 

n = self._new_c([a],P,check) 

else: 

n = self._new_c([],P) 

return n 

  

def __call__(self, eval_pt): 

r""" 

Evaluate ``self`` at ``eval_pt`` using operator evaluation. 

  

Given a skew polynomial `p(x) = \sum_{i=0}^d a_i * x^i`, we define 

the evaluation `p(r)` to be `\sum_{i=0}^d a_i * \sigma^i(r)`, where 

`\sigma` is the twist map of the skew polynomial ring. 

  

INPUT: 

  

- ``eval_pt`` -- element of the base ring of ``self`` 

  

OUTPUT: 

  

The operator evaluation of ``self`` at ``eval_pt``. 

  

.. TODO:: 

  

Currently, only "operator evaluation" of skew polynomials is 

implemented (see :meth:`.operator_eval`). 

There are two other notions of evaluation of a skew polynomial 

`p(x)` at some element `a` of the base ring. First, the value 

of the polynomial can be defined as the remainder of the right 

division of `p(x)` by `x-a`. Second, the value can be given by 

the formula, `p(a) = \sum_{i=0}^{m-1} B_{i} * p(\beta_{i})` 

where `m` is the degree of the base ring (`F_{q^m}`) of the skew 

polynomial ring, `B_{i}` is the `i`-th element in the vector 

representation of `a` in `F_{q}` and`\beta_{i}` is the `i`-th 

element of the corresponding basis of `F_{q^m}` over `F_{q}`. 

 

The current calling convention might change in the future to 

accommodate these. Therefore, the current method has been 

marked as experimental. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x + 1 

sage: a(t^2) 

t^3 + 3*t^2 + t 

sage: b = x^2 + t*x^3 + t^2*x + 1 

sage: b(2*t + 3) 

2*t^3 + 7*t^2 + 13*t + 10 

""" 

return self._call(eval_pt) 

  

@experimental(trac_number=13215) 

def _call(self, eval_pt): 

r""" 

Helper function for the :meth:`__call__` method to accommodate 

the ``@experimental`` decorator. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: T.<x> = k['x',Frob] 

sage: a = 3*t^2*x^2 + (t + 1)*x + 2 

sage: a(t) #indirect test 

2*t^2 + 2*t + 3 

""" 

return self.operator_eval(eval_pt) 

  

cpdef operator_eval(self, eval_pt): 

r""" 

Evaluate ``self`` at ``eval_pt`` by the operator evaluation 

method. 

  

INPUT: 

  

- ``eval_pt`` -- element of the base ring of ``self`` 

  

OUTPUT: 

  

The value of the polynomial at the point specified by the argument. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: T.<x> = k['x',Frob] 

sage: a = 3*t^2*x^2 + (t + 1)*x + 2 

sage: a(t) #indirect test 

2*t^2 + 2*t + 3 

sage: a.operator_eval(t) 

2*t^2 + 2*t + 3 

  

Evaluation points outside the base ring is usually not possible due to the twist map:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x + 1 

sage: a.operator_eval(1/t) 

Traceback (most recent call last): 

... 

TypeError: 1/t fails to convert into the map's domain Univariate Polynomial Ring in t over Rational Field, but a `pushforward` method is not properly implemented 

""" 

cdef RingHomomorphism sigma = self._parent.twist_map() 

cdef list coefficients = self.list() 

cdef RingElement ret = self.base_ring().zero() 

cdef RingElement a = eval_pt 

for c in coefficients: 

ret += c * a 

a = sigma(a) 

return ret 

  

def __setitem__(self, n, value): 

r""" 

Set the ``n``-th coefficient of ``self``. 

  

This always raises an ``IndexError``, since polynomials are immutable in 

Sage. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x + t 

sage: a[1] = t + 1 

Traceback (most recent call last): 

... 

IndexError: skew polynomials are immutable 

""" 

raise IndexError("skew polynomials are immutable") 

  

def square(self): 

r""" 

Return the square of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + t; a 

x + t 

sage: a.square() 

x^2 + (2*t + 1)*x + t^2 

sage: a.square() == a*a 

True 

""" 

return self * self 

  

def conjugate(self, n): 

r""" 

Return ``self`` conjugated by `x^n`, where `x` is the 

variable of ``self``. 

  

The conjugate is obtained from ``self`` by applying the `n`-th iterate 

of the twist map to each of its coefficients. 

  

INPUT: 

  

- `n` -- an integer, the power of conjugation 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x^3 + (t^2 + 1)*x^2 + 2*t 

sage: b = a.conjugate(2); b 

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

sage: x^2*a == b*x^2 

True 

  

In principle, negative values for `n` are allowed, but Sage needs to be 

able to invert the twist map:: 

  

sage: b = a.conjugate(-1) 

Traceback (most recent call last): 

... 

NotImplementedError: inversion of the twist map Ring endomorphism of Univariate Polynomial Ring in t over Rational Field 

Defn: t |--> t + 1 

  

Here is a working example:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: T.<y> = k['y',Frob] 

sage: u = T.random_element(); u 

(2*t^2 + 3)*y^2 + (4*t^2 + t + 4)*y + 2*t^2 + 2 

sage: v = u.conjugate(-1); v 

(3*t^2 + t)*y^2 + (4*t^2 + 2*t + 4)*y + 3*t^2 + t + 4 

sage: u*y == y*v 

True 

""" 

r = self._new_c([self._parent.twist_map(n)(x) for x in self.list()], 

self._parent, 0) 

return r 

  

def constant_coefficient(self): 

r""" 

Return the constant coefficient (i.e. the coefficient of term 

of degree `0`) of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + t^2 + 2 

sage: a.constant_coefficient() 

t^2 + 2 

""" 

if not self: 

return self.base_ring().zero() 

else: 

return self[0] 

  

def leading_coefficient(self): 

r""" 

Return the coefficient of the highest-degree monomial of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (t+1)*x^5 + t^2*x^3 + x 

sage: a.leading_coefficient() 

t + 1 

""" 

cdef int d = self.degree() 

if d == -1: 

raise ValueError("the skew polynomial must not be 0") 

return self[d] 

  

def is_unit(self): 

r""" 

Return ``True`` if this skew polynomial is a unit. 

  

When the base ring `R` is an integral domain, then a skew polynomial `f` 

is a unit if and only if degree of `f` is `0` and `f` is then a unit in 

`R`. 

  

.. NOTE:: 

  

The case when `R` is not an integral domain is not yet implemented. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + (t+1)*x^5 + t^2*x^3 - x^5 

sage: a.is_unit() 

False 

""" 

# TODO: Sage does not yet have support for finding order of 

# automorphisms. Once that is available, general case can 

# be implemented. Reference: http://bit.ly/29Vidu7 

if self._parent.base_ring().is_integral_domain(): 

if self.degree() == 0 and self[0].is_unit(): 

return True 

else: 

return False 

else: 

raise NotImplementedError("is_unit is not implemented for skew polynomial rings " 

"over base rings which are not integral domains.") 

  

def is_nilpotent(self): 

r""" 

Check if ``self`` is nilpotent. 

  

Given a commutative ring `R` and a base ring automorphism `\sigma` 

of order `n`, an element `f` of `R[X, \sigma]` is nilpotent if 

and only if all coefficients of `f^n` are nilpotent in `R`. 

  

.. NOTE:: 

  

The paper "Nilpotents and units in skew polynomial rings 

over commutative rings" by M. Rimmer and K.R. Pearson describes 

the method to check whether a given skew polynomial is nilpotent. 

That method however, requires one to know the order of the 

automorphism which is not available in Sage. This method is thus 

not yet implemented.  

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: x.is_nilpotent() 

Traceback (most recent call last): 

... 

NotImplementedError 

""" 

raise NotImplementedError 

  

def is_monic(self): 

r""" 

Return ``True`` if this skew polynomial is monic. 

  

The zero polynomial is by definition not monic. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + t 

sage: a.is_monic() 

True 

sage: a = 0*x 

sage: a.is_monic() 

False 

sage: a = t*x^3 + x^4 + (t+1)*x^2 

sage: a.is_monic() 

True 

sage: a = (t^2 + 2*t)*x^2 + x^3 + t^10*x^5 

sage: a.is_monic() 

False 

""" 

return not self.is_zero() and self[self.degree()] == 1 

  

def left_monic(self): 

r""" 

Return the unique monic skew polynomial `m` which divides ``self`` on 

the left and has the same degree. 

  

Given a skew polynomial `p` of degree `n`, its left monic is given by 

`m = p \sigma^{-n}(1/k)`, where `k` is the leading coefficient of 

`p`, i.e. by the appropriate scalar multiplication on the right. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 

sage: b = a.left_monic(); b 

x^3 + (4*t^2 + 3*t)*x^2 + (4*t + 2)*x + 2*t^2 + 4*t + 3 

  

Check list:: 

  

sage: b.degree() == a.degree() 

True 

sage: b.is_left_divisible_by(a) 

True 

sage: twist = S.twist_map(-a.degree()) 

sage: a == b * twist(a.leading_coefficient()) 

True 

  

Note that `b` does not divide `a` on the right:: 

  

sage: a.is_right_divisible_by(b) 

False 

  

This function does not work if the leading coefficient is not a 

unit:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x 

sage: a.left_monic() 

Traceback (most recent call last): 

... 

NotImplementedError: the leading coefficient is not a unit 

""" 

try: 

a = self.base_ring()(~self.leading_coefficient()) 

except (ZeroDivisionError, TypeError): 

raise NotImplementedError("the leading coefficient is not a unit") 

r = self * self._parent.twist_map(-self.degree())(a) 

return r 

  

def right_monic(self): 

r""" 

Return the unique monic skew polynomial `m` which divides ``self`` on 

the right and has the same degree. 

  

Given a skew polynomial `p` of degree `n`, its left monic is given by 

`m = (1/k) * p`, where `k` is the leading coefficient of `p`, i.e. by 

the appropriate scalar multiplication on the left. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 

sage: b = a.right_monic(); b 

x^3 + (2*t^2 + 3*t + 4)*x^2 + (3*t^2 + 4*t + 1)*x + 2*t^2 + 4*t + 3 

  

Check list:: 

  

sage: b.degree() == a.degree() 

True 

sage: b.is_right_divisible_by(a) 

True 

sage: a == a.leading_coefficient() * b 

True 

  

Note that `b` does not divide `a` on the right:: 

  

sage: a.is_left_divisible_by(b) 

False 

  

This function does not work if the leading coefficient is not a 

unit:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x 

sage: a.right_monic() 

Traceback (most recent call last): 

... 

NotImplementedError: the leading coefficient is not a unit 

""" 

try: 

a = self.base_ring()(~self.leading_coefficient()) 

except (ZeroDivisionError, TypeError): 

raise NotImplementedError("the leading coefficient is not a unit") 

r = a * self 

return r 

  

cpdef _mod_(self, other): 

r""" 

Return the remainder in the *right* euclidean division of 

``self`` by ``other```. 

  

TESTS:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: b = x^2 + 2*t*x + 2 

sage: a = (x+t)*b + t*x + 1 

sage: a % b 

t*x + 1 

  

sage: (a*t).right_quo_rem(b*t) 

Traceback (most recent call last): 

... 

NotImplementedError: the leading coefficient of the divisor is not invertible 

""" 

_,r = self.right_quo_rem(other) 

return r 

  

cpdef _floordiv_(self, right): 

r""" 

Return the quotient of the *right* euclidean division of 

``self`` by ``right``. 

  

The algorithm fails if the leading coefficient of the divisor 

(``right``) is not invertible. 

  

TESTS:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: b = x^2 + t 

sage: a = (x^2 + t*x + 1)*b + t^3*x 

sage: a // b 

x^2 + t*x + 1 

  

sage: (t*a) // (t*b) 

Traceback (most recent call last): 

... 

NotImplementedError: the leading coefficient of the divisor is not invertible 

  

""" 

q,_ = self.right_quo_rem(right) 

return q 

  

cpdef _div_(self, right): 

r""" 

Not Implemented. 

  

To implement this, localization of Ore rings is needed, see 

:trac:`13215`. 

  

Use the operator `//` even for exact division. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^5 + (t + 2)*x^2 + t^2 

sage: b = x^3 + 4*t 

sage: c = a*b 

  

sage: c / b 

Traceback (most recent call last): 

... 

NotImplementedError: localization of Ore rings not yet implemented 

  

sage: c // b == a 

True 

""" 

# Should this actually return something in the fraction field like 

# we do elsewhere in Sage? - TCS 

raise NotImplementedError("localization of Ore rings not yet implemented") 

  

def is_left_divisible_by(self, other): 

r""" 

Check if ``self`` is divisible by ``other`` on the left. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

Return ``True`` or ``False``. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x^2 + t*x + t^2 + 3 

sage: b = x^3 + (t + 1)*x^2 + 1 

sage: c = a*b 

sage: c.is_left_divisible_by(a) 

True 

sage: c.is_left_divisible_by(b) 

False 

  

Divisibility by `0` does not make sense:: 

  

sage: c.is_left_divisible_by(S(0)) 

Traceback (most recent call last): 

... 

ZeroDivisionError: division by zero is not valid 

""" 

_, r = self.left_quo_rem(other) 

return r.is_zero() 

  

def is_right_divisible_by(self, other): 

r""" 

Check if ``self`` is divisible by ``other`` on the right. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

Return ``True`` or ``False``. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x^2 + t*x + t^2 + 3 

sage: b = x^3 + (t + 1)*x^2 + 1 

sage: c = a*b 

sage: c.is_right_divisible_by(a) 

False 

sage: c.is_right_divisible_by(b) 

True 

  

Divisibility by `0` does not make sense:: 

  

sage: c.is_right_divisible_by(S(0)) 

Traceback (most recent call last): 

... 

ZeroDivisionError: division by zero is not valid 

  

This function does not work if the leading coefficient of the divisor 

is not a unit:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^2 + 2*x + t 

sage: b = (t+1)*x + t^2 

sage: c = a*b 

sage: c.is_right_divisible_by(b) 

Traceback (most recent call last): 

... 

NotImplementedError: the leading coefficient of the divisor is not invertible 

""" 

_, r = self.right_quo_rem(other) 

return r.is_zero() 

  

def left_divides(self, other): 

r""" 

Check if ``self`` divides ``other`` on the left. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

Return ``True`` or ``False``. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x^2 + t*x + t^2 + 3 

sage: b = x^3 + (t + 1)*x^2 + 1 

sage: c = a*b 

sage: a.left_divides(c) 

True 

sage: b.left_divides(c) 

False 

  

Divisibility by `0` does not make sense:: 

  

sage: S(0).left_divides(c) 

Traceback (most recent call last): 

... 

ZeroDivisionError: division by zero is not valid 

""" 

_, r = other.left_quo_rem(self) 

return r.is_zero() 

  

def right_divides(self, other): 

r""" 

Check if ``self`` divides ``other`` on the right. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

Return ``True`` or ``False``. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x^2 + t*x + t^2 + 3 

sage: b = x^3 + (t + 1)*x^2 + 1 

sage: c = a*b 

sage: a.right_divides(c) 

False 

sage: b.right_divides(c) 

True 

  

Divisibility by `0` does not make sense:: 

  

sage: S(0).right_divides(c) 

Traceback (most recent call last): 

... 

ZeroDivisionError: division by zero is not valid 

  

This function does not work if the leading coefficient of the divisor 

is not a unit:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^2 + 2*x + t 

sage: b = (t+1)*x + t^2 

sage: c = a*b 

sage: b.right_divides(c) 

Traceback (most recent call last): 

... 

NotImplementedError: the leading coefficient of the divisor is not invertible 

""" 

_, r = other.right_quo_rem(self) 

return r.is_zero() 

  

@coerce_binop 

def left_xgcd(self, other, monic=True): 

r""" 

Return the left gcd of ``self`` and ``other`` along with the 

coefficients for the linear combination. 

  

If `a` is ``self`` and `b` is ``other``, then there are skew polynomials 

`u` and `v` such that `g = a u + b v`, where `g` is the left gcd of `a` 

and `b`. This method returns `(g, u, v)`. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

- ``monic`` -- boolean (default: ``True``). Return whether the left gcd 

should be normalized to be monic. 

  

OUTPUT: 

  

- The left gcd of ``self`` and ``other``, that is a skew polynomial 

`g` with the following property: any skew polynomial is 

divisible on the left by `g` iff it is divisible on the left 

by both ``self`` and ``other``. 

If monic is ``True``, `g` is in addition monic. (With this 

extra condition, it is uniquely determined.) 

  

- Two skew polynomials `u` and `v` such that: 

  

.. MATH:: 

  

g = a * u + b * v, 

  

where `s` is ``self`` and `b` is ``other``. 

  

.. NOTE:: 

  

Works only if following two conditions are fulfilled 

(otherwise left gcd do not exist in general): 

1) the base ring is a field and 2) the twist map on 

this field is bijective. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (x + t) * (x^2 + t*x + 1) 

sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) 

sage: g,u,v = a.left_xgcd(b); g 

x + t 

sage: a*u + b*v == g 

True 

  

Specifying ``monic=False``, we *can* get a nonmonic gcd:: 

  

sage: g,u,v = a.left_xgcd(b, monic=False); g 

2*t*x + 4*t + 2 

sage: a*u + b*v == g 

True 

  

The base ring must be a field:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (x + t) * (x^2 + t*x + 1) 

sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) 

sage: a.left_xgcd(b) 

Traceback (most recent call last): 

... 

TypeError: the base ring must be a field 

  

And the twist map must be bijective:: 

  

sage: FR = R.fraction_field() 

sage: f = FR.hom([FR(t)^2]) 

sage: S.<x> = FR['x',f] 

sage: a = (x + t) * (x^2 + t*x + 1) 

sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) 

sage: a.left_xgcd(b) 

Traceback (most recent call last): 

... 

NotImplementedError: inversion of the twist map Ring endomorphism of Fraction Field of Univariate Polynomial Ring in t over Rational Field 

Defn: t |--> t^2 

""" 

if self.base_ring() not in Fields: 

raise TypeError("the base ring must be a field") 

G = self 

U = self._parent.one() 

if other.is_zero(): 

V = self._parent.zero() 

else: 

V1 = self._parent.zero() 

V3 = other 

while not V3.is_zero(): 

Q,R = G.left_quo_rem(V3) 

T = U - V1*Q 

U = V1 

G = V3 

V1 = T 

V3 = R 

V, _ = (G - self*U).left_quo_rem(other) 

if monic: 

lc = ~G.leading_coefficient() 

lc = self._parent.twist_map(-G.degree())(lc) 

G = G * lc 

U = U * lc 

V = V * lc 

return G,U,V 

  

@coerce_binop 

def right_xgcd(self, other, monic=True): 

r""" 

Return the right gcd of ``self`` and ``other`` along with the 

coefficients for the linear combination. 

  

If `a` is ``self`` and `b` is ``other``, then there are skew polynomials 

`u` and `v` such that `g = u a + v b`, where `g` is the right gcd of `a` 

and `b`. This method returns `(g, u, v)`. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

- ``monic`` -- boolean (default: ``True``). Return whether the right gcd 

should be normalized to be monic. 

  

OUTPUT: 

  

- The right gcd of ``self`` and ``other``, that is a skew polynomial 

`g` with the following property: any skew polynomial is 

divisible on the right by `g` iff it is divisible on the right 

by both ``self`` and ``other``. 

If monic is ``True``, `g` is in addition monic. (With this 

extra condition, it is uniquely determined.) 

  

- Two skew polynomials `u` and `v` such that: 

  

.. MATH:: 

  

g = u * a + v * b 

  

where `a` is ``self`` and `b` is ``other``. 

  

.. NOTE:: 

  

Works only if the base ring is a field (otherwise right 

gcd do not exist in general). 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (x^2 + t*x + 1) * (x + t) 

sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) 

sage: g,u,v = a.right_xgcd(b); g 

x + t 

sage: u*a + v*b == g 

True 

  

Specifying ``monic=False``, we *can* get a nonmonic gcd:: 

  

sage: g,u,v = a.right_xgcd(b,monic=False); g 

(4*t^2 + 4*t + 1)*x + 4*t^2 + 4*t + 3 

sage: u*a + v*b == g 

True 

  

The base ring must be a field:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (x^2 + t*x + 1) * (x + t) 

sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) 

sage: a.right_xgcd(b) 

Traceback (most recent call last): 

... 

TypeError: the base ring must be a field 

""" 

if self.base_ring() not in Fields: 

raise TypeError("the base ring must be a field") 

G = self 

U = self._parent.one() 

if other.is_zero(): 

V = self._parent.zero() 

else: 

V1 = self._parent.zero() 

V3 = other 

while not V3.is_zero(): 

Q, R = G.right_quo_rem(V3) 

T = U - Q*V1 

U = V1 

G = V3 

V1 = T 

V3 = R 

V,_ = (G - U*self).right_quo_rem(other) 

if monic: 

lc = ~G.leading_coefficient() 

G = lc * G 

U = lc * U 

V = lc * V 

return G,U,V 

  

@coerce_binop 

def right_gcd(self, other, monic=True): 

r""" 

Return the right gcd of ``self`` and ``other``. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

- ``monic`` -- boolean (default: ``True``). Return whether the right gcd 

should be normalized to be monic. 

  

OUTPUT: 

  

The right gcd of ``self`` and ``other``, that is a skew polynomial 

`g` with the following property: any skew polynomial is 

divisible on the right by `g` iff it is divisible on the right 

by both ``self`` and ``other``. 

If monic is ``True``, `g` is in addition monic. (With this 

extra condition, it is uniquely determined.) 

  

.. NOTE:: 

  

Works only if the base ring is a field (otherwise right 

gcd do not exist in general). 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (x^2 + t*x + 1) * (x + t) 

sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) 

sage: a.right_gcd(b) 

x + t 

  

Specifying ``monic=False``, we *can* get a nonmonic gcd:: 

  

sage: a.right_gcd(b,monic=False) 

(4*t^2 + 4*t + 1)*x + 4*t^2 + 4*t + 3 

  

The base ring need to be a field:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (x^2 + t*x + 1) * (x + t) 

sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) 

sage: a.right_gcd(b) 

Traceback (most recent call last): 

... 

TypeError: the base ring must be a field 

""" 

if self.base_ring() not in Fields: 

raise TypeError("the base ring must be a field") 

if other.is_zero(): 

return self 

A = self 

B = other 

while not B.is_zero(): 

A, B = B, A % B 

if monic: 

A = A.right_monic() 

return A 

  

@coerce_binop 

def left_gcd(self, other, monic=True): 

r""" 

Return the left gcd of ``self`` and ``other``. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

- ``monic`` -- boolean (default: ``True``). Return whether the left gcd 

should be normalized to be monic. 

  

OUTPUT: 

  

The left gcd of ``self`` and ``other``, that is a skew polynomial 

`g` with the following property: any skew polynomial is 

divisible on the left by `g` iff it is divisible on the left 

by both ``self`` and ``other``. 

If monic is ``True``, `g` is in addition monic. (With this 

extra condition, it is uniquely determined.) 

  

.. NOTE:: 

  

Works only if two following conditions are fulfilled 

(otherwise left gcd do not exist in general): 

1) the base ring is a field and 2) the twist map on 

this field is bijective. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (x + t) * (x^2 + t*x + 1) 

sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) 

sage: a.left_gcd(b) 

x + t 

  

Specifying ``monic=False``, we *can* get a nonmonic gcd:: 

  

sage: a.left_gcd(b,monic=False) 

2*t*x + 4*t + 2 

  

The base ring needs to be a field:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (x + t) * (x^2 + t*x + 1) 

sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) 

sage: a.left_gcd(b) 

Traceback (most recent call last): 

... 

TypeError: the base ring must be a field 

  

And the twist map needs to be bijective:: 

  

sage: FR = R.fraction_field() 

sage: f = FR.hom([FR(t)^2]) 

sage: S.<x> = FR['x',f] 

sage: a = (x + t) * (x^2 + t*x + 1) 

sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) 

sage: a.left_gcd(b) 

Traceback (most recent call last): 

... 

NotImplementedError: inversion of the twist map Ring endomorphism of Fraction Field of Univariate Polynomial Ring in t over Rational Field 

Defn: t |--> t^2 

""" 

if self.base_ring() not in Fields: 

raise TypeError("the base ring must be a field") 

if other.is_zero(): 

return self 

A = self 

B = other 

while not B.is_zero(): 

A_ = A 

A = B 

_, B = A_.left_quo_rem(B) 

if monic: 

A = A.left_monic() 

return A 

  

@coerce_binop 

def left_lcm(self, other, monic=True): 

r""" 

Return the left lcm of ``self`` and ``other``. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

- ``monic`` -- boolean (default: ``True``). Return whether the left lcm 

should be normalized to be monic. 

  

OUTPUT: 

  

The left lcm of ``self`` and ``other``, that is a skew polynomial 

`g` with the following property: any skew polynomial divides 

`g` on the *right* iff it divides both ``self`` and ``other`` 

on the *right*. 

If monic is ``True``, `g` is in addition monic. (With this 

extra condition, it is uniquely determined.) 

  

.. NOTE:: 

  

Works only if the base ring is a field (otherwise left 

lcm do not exist in general). 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (x + t^2) * (x + t) 

sage: b = 2 * (x^2 + t + 1) * (x * t) 

sage: c = a.left_lcm(b); c 

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

sage: c.is_right_divisible_by(a) 

True 

sage: c.is_right_divisible_by(b) 

True 

sage: a.degree() + b.degree() == c.degree() + a.right_gcd(b).degree() 

True 

  

Specifying ``monic=False``, we *can* get a nonmonic gcd:: 

  

sage: a.left_lcm(b,monic=False) 

(t^2 + t)*x^5 + (4*t^2 + 4*t + 1)*x^4 + (t + 1)*x^3 + (t^2 + 2)*x^2 + (3*t + 4)*x 

  

The base ring needs to be a field:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (x + t^2) * (x + t) 

sage: b = 2 * (x^2 + t + 1) * (x * t) 

sage: a.left_lcm(b) 

Traceback (most recent call last): 

... 

TypeError: the base ring must be a field 

""" 

if self.base_ring() not in Fields: 

raise TypeError("the base ring must be a field") 

if self.is_zero() or other.is_zero(): 

raise ZeroDivisionError("division by zero is not valid") 

U = self._parent.one() 

G = self 

V1 = self._parent.zero() 

V3 = other 

while not V3.is_zero(): 

Q, R = G.right_quo_rem(V3) 

T = U - Q*V1 

U = V1 

G = V3 

V1 = T 

V3 = R 

V1 = V1 * self 

if monic: 

V1 = V1.right_monic() 

return V1 

  

@coerce_binop 

def right_lcm(self, other, monic=True): 

r""" 

Return the right lcm of ``self`` and ``other``. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

 

- ``monic`` -- boolean (default: ``True``). Return whether the right lcm 

should be normalized to be monic. 

  

OUTPUT: 

  

The right lcm of ``self`` and ``other``, that is a skew polynomial 

`g` with the following property: any skew polynomial divides 

`g` on the *left* iff it divides both ``self`` and ``other`` 

on the *left*. 

If monic is ``True``, `g` is in addition monic. (With this 

extra condition, it is uniquely determined.) 

  

.. NOTE:: 

  

Works only if two following conditions are fulfilled 

(otherwise right lcm do not exist in general): 

1) the base ring is a field and 2) the twist map on 

this field is bijective. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (x + t) * (x + t^2) 

sage: b = 2 * (x + t) * (x^2 + t + 1) 

sage: c = a.right_lcm(b); c 

x^4 + (2*t^2 + t + 2)*x^3 + (3*t^2 + 4*t + 1)*x^2 + (3*t^2 + 4*t + 1)*x + t^2 + 4 

sage: c.is_left_divisible_by(a) 

True 

sage: c.is_left_divisible_by(b) 

True 

sage: a.degree() + b.degree() == c.degree() + a.left_gcd(b).degree() 

True 

  

Specifying ``monic=False``, we *can* get a nonmonic gcd:: 

  

sage: a.right_lcm(b,monic=False) 

2*t*x^4 + (3*t + 1)*x^3 + (4*t^2 + 4*t + 3)*x^2 

+ (3*t^2 + 4*t + 2)*x + 3*t^2 + 2*t + 3 

  

The base ring needs to be a field:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (x + t) * (x + t^2) 

sage: b = 2 * (x + t) * (x^2 + t + 1) 

sage: a.right_lcm(b) 

Traceback (most recent call last): 

... 

TypeError: the base ring must be a field 

  

And the twist map needs to be bijective:: 

  

sage: FR = R.fraction_field() 

sage: f = FR.hom([FR(t)^2]) 

sage: S.<x> = FR['x',f] 

sage: a = (x + t) * (x + t^2) 

sage: b = 2 * (x + t) * (x^2 + t + 1) 

sage: a.right_lcm(b) 

Traceback (most recent call last): 

... 

NotImplementedError: inversion of the twist map Ring endomorphism of Fraction Field of Univariate Polynomial Ring in t over Rational Field 

Defn: t |--> t^2 

""" 

if self.base_ring() not in Fields: 

raise TypeError("the base ring must be a field") 

if self.is_zero() or other.is_zero(): 

raise ZeroDivisionError("division by zero is not valid") 

R = self.parent() 

U = R.one() 

G = self 

V1 = R.zero() 

V3 = other 

while not V3.is_zero(): 

Q, R = G.left_quo_rem(V3) 

T = U - V1*Q 

U = V1 

G = V3 

V1 = T 

V3 = R 

V1 = self * V1 

if monic: 

V1 = V1.left_monic() 

return V1 

  

def _repr_(self, name=None): 

r""" 

Return string representation of this skew polynomial. 

  

INPUT: 

  

- ``name`` -- the name of the variable (default: the 

name given when the skew polynomial ring was created) 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t^2 + 1/2*x*t; 

sage: a._repr_() 

'(1/2*t + 1/2)*x + t^2' 

sage: a._repr_(name='y') 

'(1/2*t + 1/2)*y + t^2' 

""" 

s = " " 

m = self.degree() + 1 

if name is None: 

name = self.parent().variable_name() 

atomic_repr = self.parent().base_ring()._repr_option('element_is_atomic') 

coeffs = self.list() 

for n in reversed(range(m)): 

x = coeffs[n] 

if x: 

if n != m-1: 

s += " + " 

x = y = repr(x) 

if y.find("-") == 0: 

y = y[1:] 

if not atomic_repr and n > 0 and (y.find("+") != -1 or y.find("-") != -1): 

x = "(%s)"%x 

if n > 1: 

var = "*%s^%s"%(name,n) 

elif n==1: 

var = "*%s"%name 

else: 

var = "" 

s += "%s%s"%(x,var) 

s = s.replace(" + -", " - ") 

s = re.sub(r' 1(\.0+)?\*',' ', s) 

s = re.sub(r' -1(\.0+)?\*',' -', s) 

if s == " ": 

return "0" 

return s[1:] 

  

def _latex_(self, name=None): 

r""" 

Return a latex representation of this skew polynomial. 

  

INPUT: 

  

- ``name`` -- the name of the variable (default: the 

name given when the skew polynomial ring was created) 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t^2 + 1/2*x*t; 

sage: a._latex_() 

'\\left(\\frac{1}{2} t + \\frac{1}{2}\\right) x + t^{2}' 

sage: a._latex_(name='y') 

'\\left(\\frac{1}{2} t + \\frac{1}{2}\\right) y + t^{2}' 

""" 

s = " " 

coeffs = self.list() 

m = len(coeffs) 

if name is None: 

name = self.parent().latex_variable_names()[0] 

atomic_repr = self.parent().base_ring()._repr_option('element_is_atomic') 

for n in reversed(range(m)): 

x = self[n] 

x = y = x._latex_() 

if x != '0': 

if n != m-1: 

s += " + " 

if y.find("-") == 0: 

y = y[1:] 

if not atomic_repr and n > 0 and (y.find("+") != -1 or y.find("-") != -1): 

x = "\\left(%s\\right)"%x 

if n > 1: 

var = "|%s^{%s}"%(name,n) 

elif n==1: 

var = "|%s"%name 

else: 

var = "" 

s += "%s %s"%(x,var) 

s = s.replace(" + -", " - ") 

s = re.sub(" 1(\.0+)? \|"," ", s) 

s = re.sub(" -1(\.0+)? \|", " -", s) 

s = s.replace("|","") 

if s == " ": 

return "0" 

return s[1:].lstrip().rstrip() 

  

def _is_atomic(self): 

r""" 

Check ``self`` is a single monomial whose leading coefficient 

is atomic in the base ring. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: S([t+1])._is_atomic() 

False 

sage: S([1])._is_atomic() 

True 

""" 

return (self.degree() == self.valuation() and 

self.leading_coefficient()._is_atomic()) 

  

def __nonzero__(self): 

r""" 

Test whether ``self`` is nonzero. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + 1 

sage: bool(a) 

True 

sage: b = S.zero() 

sage: bool(b) 

False 

""" 

return not self.is_zero() 

  

def base_ring(self): 

r""" 

Return the base ring of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = S.random_element() 

sage: a.base_ring() 

Univariate Polynomial Ring in t over Integer Ring 

sage: a.base_ring() is R 

True 

""" 

return self.parent().base_ring() 

  

def shift(self, n): 

r""" 

Return ``self`` multiplied on the right by the power `x^n`. 

  

If `n` is negative, terms below `x^n` will be discarded. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^5 + t^4*x^4 + t^2*x^2 + t^10 

sage: a.shift(0) 

x^5 + t^4*x^4 + t^2*x^2 + t^10 

sage: a.shift(-1) 

x^4 + t^4*x^3 + t^2*x 

sage: a.shift(-5) 

1 

sage: a.shift(2) 

x^7 + t^4*x^6 + t^2*x^4 + t^10*x^2 

  

One can also use the infix shift operator:: 

  

sage: a >> 2 

x^3 + t^4*x^2 + t^2 

sage: a << 2 

x^7 + t^4*x^6 + t^2*x^4 + t^10*x^2 

""" 

if n == 0 or self.degree() < 0: 

return self 

if n > 0: 

return self._parent(n*[self.base_ring().zero()] + self.list(), check=False) 

if n < 0: 

if n > self.degree(): 

return self._parent([]) 

else: 

return self._parent(self.list()[-n:], check=False) 

  

def __lshift__(self, k): 

r""" 

Return ``self`` multiplied on the right by the power `x^k`. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^5 + t^4*x^4 + t^2*x^2 + t^10 

sage: a << 2 

x^7 + t^4*x^6 + t^2*x^4 + t^10*x^2 

""" 

return self.shift(k) 

  

def __rshift__(self, k): 

r""" 

Return ``self`` multiplied on the right by the power `x^(-k)`. 

  

If `n` is negative, terms below `x^n` will be discarded. 

 

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^5 + t^4*x^4 + t^2*x^2 + t^10 

sage: a >> 2 

x^3 + t^4*x^2 + t^2 

""" 

return self.shift(-k) 

  

def change_variable_name(self, var): 

r""" 

Change the name of the variable of ``self``. 

  

This will create the skew polynomial ring with the new name but same 

base ring and twist map. The returned skew polynomial will be an element 

of that skew polynomial ring. 

  

INPUT: 

  

- ``var`` -- the name of the new variable 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x', sigma] 

sage: a = x^3 + (2*t + 1)*x + t^2 + 3*t + 5 

sage: b = a.change_variable_name('y'); b 

y^3 + (2*t + 1)*y + t^2 + 3*t + 5 

  

Note that a new parent is created at the same time:: 

  

sage: b.parent() 

Skew Polynomial Ring in y over Univariate Polynomial Ring in t over Integer Ring 

twisted by t |--> t + 1 

""" 

parent = self._parent 

R = parent.base_ring()[var,parent.twist_map()] 

return R(self.list()) 

  

def is_term(self): 

r""" 

Return ``True`` if ``self`` is an element of the base ring times a 

power of the generator. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: x.is_term() 

True 

sage: R(1).is_term() 

True 

sage: (3*x^5).is_term() 

True 

sage: (1+3*x^5).is_term() 

False 

  

If you want to test that ``self`` also has leading coefficient 1, use 

:meth:`is_monomial()` instead:: 

  

sage: (3*x^5).is_monomial() 

False 

""" 

return len(self.exponents()) == 1 

  

def is_monomial(self): 

r""" 

Return ``True`` if ``self`` is a monomial, i.e., a power of 

the generator. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: x.is_monomial() 

True 

sage: (x+1).is_monomial() 

False 

sage: (x^2).is_monomial() 

True 

sage: S(1).is_monomial() 

True 

  

The coefficient must be 1:: 

  

sage: (2*x^5).is_monomial() 

False 

sage: S(t).is_monomial() 

False 

  

To allow a non-1 leading coefficient, use is_term():: 

  

sage: (2*x^5).is_term() 

True 

sage: S(t).is_term() 

True 

""" 

return self.is_term() and self.leading_coefficient() == 1 

  

cpdef list coefficients(self, sparse=True): 

r""" 

Return the coefficients of the monomials appearing in ``self``. 

  

If ``sparse=True`` (the default), return only the non-zero coefficients. 

Otherwise, return the same value as ``self.list()``. 

  

.. NOTE:: 

  

This should be overridden in subclasses. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: a.coefficients() 

[t^2 + 1, t + 1, 1] 

sage: a.coefficients(sparse=False) 

[t^2 + 1, 0, t + 1, 0, 1] 

""" 

raise NotImplementedError 

  

def number_of_terms(self): 

r""" 

Return the number of non-zero coefficients of ``self``. 

  

This is also known as the weight, hamming weight or sparsity. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: a.number_of_terms() 

3 

  

This is also an alias for ``hamming_weight``:: 

  

sage: a.hamming_weight() 

3 

""" 

return len(self.coefficients()) 

  

# alias hamming_weight for number_of_terms: 

hamming_weight = number_of_terms 

  

def __copy__(self): 

r""" 

Return a "copy" of ``self``. 

  

In Sage, since skew polynomials are immutable, this just returns 

``self`` again. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: b = copy(a) 

sage: b is a 

True 

""" 

return self 

  

cpdef bint is_zero(self): 

r""" 

Return ``True`` if ``self`` is the zero polynomial. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + 1 

sage: a.is_zero() 

False 

sage: b = S.zero() 

sage: b.is_zero() 

True 

""" 

return self.degree() == -1 

  

cpdef bint is_one(self): 

r""" 

Test whether this polynomial is `1`. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: R(1).is_one() 

True 

sage: (x + 3).is_one() 

False 

""" 

return self.degree() == 0 and self[0].is_one() 

  

@coerce_binop 

def right_mod(self, other): 

r""" 

Return the remainder of right division of ``self`` by ``other``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + t*x^2 

sage: b = x + 1 

sage: a % b 

t + 1 

sage: (x^3 + x - 1).right_mod(x^2 - 1) 

2*x - 1 

""" 

return self % other 

  

@coerce_binop 

def left_mod(self, other): 

r""" 

Return the remainder of left division of ``self`` by ``other``. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = 1 + t*x^2 

sage: b = x + 1 

sage: a.left_mod(b) 

2*t^2 + 4*t 

""" 

(_,r) = self.left_quo_rem(other) 

return r 

  

def is_constant(self): 

r""" 

Return whether ``self`` is a constant polynomial. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: R(2).is_constant() 

True 

sage: (x + 1).is_constant() 

False 

""" 

return self.degree() <= 0 

  

def exponents(self): 

r""" 

Return the exponents of the monomials appearing in ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: a.exponents() 

[0, 2, 4] 

""" 

return [i for i in range(self.degree()+1) if bool(self[i])] 

  

def prec(self): 

r""" 

Return the precision of ``self``. 

  

This is always infinity, since polynomials are of infinite precision by 

definition (there is no big-oh). 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: x.prec() 

+Infinity 

""" 

return infinity 

  

def padded_list(self, n=None): 

r""" 

Return list of coefficients of ``self`` up to (but not including) 

degree `n`. 

  

Includes `0`s in the list on the right so that the list always has length 

exactly `n`. 

  

INPUT: 

  

- ``n`` -- (default: ``None``); if given, an integer that 

is at least `0` 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + t*x^3 + t^2*x^5 

sage: a.padded_list() 

[1, 0, 0, t, 0, t^2] 

sage: a.padded_list(10) 

[1, 0, 0, t, 0, t^2, 0, 0, 0, 0] 

sage: len(a.padded_list(10)) 

10 

sage: a.padded_list(3) 

[1, 0, 0] 

sage: a.padded_list(0) 

[] 

sage: a.padded_list(-1) 

Traceback (most recent call last): 

... 

ValueError: n must be at least 0 

""" 

v = self.list() 

if n is None: 

return v 

if n < 0: 

raise ValueError("n must be at least 0") 

if len(v) < n: 

z = self._parent.base_ring().zero() 

return v + [z]*(n - len(v)) 

else: 

return v[:int(n)] 

  

def variable_name(self): 

r""" 

Return the string name of the variable used in ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + t 

sage: a.variable_name() 

'x' 

""" 

return self.parent().variable_name() 

  

def multi_point_evaluation(self, eval_pts): 

""" 

Evaluate ``self`` at list of evaluation points. 

  

INPUT: 

  

- ``eval_pts`` -- list of points at which ``self`` is to be evaluated 

  

OUTPUT: 

  

List of values of ``self`` at the ``eval_pts``. 

  

.. TODO:: 

  

This method currently trivially calls the evaluation function 

repeatedly. If fast skew polynomial multiplication is available, an 

asymptotically faster method is possible using standard divide and 

conquer techniques and 

:meth:`sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general.minimal_vanishing_polynomial`. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x + t 

sage: eval_pts = [1, t, t^2] 

sage: c = a.multi_point_evaluation(eval_pts); c 

[t + 1, 3*t^2 + 4*t + 4, 4*t] 

sage: c == [ a(e) for e in eval_pts ] 

True 

""" 

return [ self(e) for e in eval_pts ] 

  

  

cdef class SkewPolynomial_generic_dense(SkewPolynomial): 

r""" 

Generic implementation of dense skew polynomial supporting any valid base 

ring and twist map. 

""" 

  

def __init__(self, parent, x=None, int check=1, int construct=0, **kwds): 

r""" 

Construct a skew polynomial over the given parent with the given 

coefficients. 

  

INPUT: 

  

- ``parent`` -- parent of ``self`` 

  

- ``x`` -- list of coefficients from which ``self`` can be constructed 

  

- ``check`` -- flag variable to normalize the polynomial 

  

- ``construct`` -- boolean (default: ``False``) 

  

TESTS:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

  

We create a skew polynomial from a list:: 

  

sage: S([t,1]) 

x + t 

  

from another skew polynomial:: 

  

sage: S(x^2 + t) 

x^2 + t 

  

from a constant:: 

  

sage: x = S(t^2 + 1); x 

t^2 + 1 

sage: x.parent() is S 

True 

""" 

SkewPolynomial.__init__(self, parent) 

if x is None: 

self._coeffs = [] 

return 

  

R = parent.base_ring() 

if isinstance(x, list): 

if check: 

self._coeffs = [R(t) for t in x] 

self.__normalize() 

else: 

self._coeffs = x 

return 

  

if isinstance(x, SkewPolynomial): 

if (<Element>x)._parent is self._parent: 

x = list(x.list()) 

elif R.has_coerce_map_from((<Element>x)._parent): 

try: 

if x.is_zero(): 

self._coeffs = [] 

return 

except (AttributeError, TypeError): 

pass 

x = [x] 

else: 

self._coeffs = [R(a, **kwds) for a in x.list()] 

if check: 

self.__normalize() 

return 

  

elif isinstance(x, int) and x == 0: 

self._coeffs = [] 

return 

  

elif isinstance(x, dict): 

x = _dict_to_list(x, R.zero()) 

  

elif not isinstance(x, list): 

x = [x] 

if check: 

self._coeffs = [R(z, **kwds) for z in x] 

self.__normalize() 

else: 

self._coeffs = x 

  

def __reduce__(self): 

r""" 

Return the generic dense skew polynomial corresponding to the 

current parameters provided ``self``. 

  

EXAMPLES: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: loads(dumps(x)) == x 

True 

sage: loads(dumps(x)) 

x 

""" 

return (self._parent, (self._coeffs,)) 

  

cdef long _hash_c(self): 

r""" 

This hash incorporates the name of the variable. 

  

.. NOTE:: 

  

This is an internal method. Use :meth:`__hash__` instead. 

""" 

#todo - come up with a way to create hashes of zero that 

# that do not incorrectly indicate that the element is 0. 

cdef long result = 0 

cdef long result_mon 

cdef long c_hash 

cdef long var_name_hash = 0 

cdef int i 

for i from 0 <= i < len(self._coeffs): 

if i == 1: 

var_name_hash = hash((<ParentWithGens>self._parent)._names[0]) 

c_hash = hash(self._coeffs[i]) 

if c_hash != 0: 

if i == 0: 

result += c_hash 

else: 

result_mon = c_hash 

result_mon = (1000003 * result_mon) ^ var_name_hash 

result_mon = (1000003 * result_mon) ^ i 

result += result_mon 

if result == -1: 

return -2 

return result 

  

cpdef _richcmp_(left, right, int op): 

r""" 

Compare the two skew polynomials ``self`` and ``other``. 

  

We order polynomials first by degree, then in dictionary order 

starting with the coefficient of largest degree. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: b = (2*t^2)*x + t + 1 

sage: a > b 

True 

sage: a < b 

False 

""" 

cdef x = (<SkewPolynomial_generic_dense>left)._coeffs 

cdef y = (<SkewPolynomial_generic_dense>right)._coeffs 

return PyObject_RichCompare(x, y, op) 

  

def __iter__(self): 

r""" 

Iterate over the list of coefficients of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: P = S([1, 2, 3]) 

sage: [y for y in iter(P)] 

[1, 2, 3] 

""" 

return iter((<SkewPolynomial_generic_dense>self)._coeffs) 

  

def __getitem__(self, n): 

r""" 

Return the `n`-th coefficient of ``self``. 

  

INPUT: 

  

- ``n`` -- an integer 

  

OUTPUT: 

  

- the ``n``-th coefficient of ``self`` 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x^2 + (t + 3/7)*x + t^2 

sage: a[1] 

t + 3/7 

sage: a[3] 

0 

""" 

try: 

l = (<SkewPolynomial_generic_dense>self)._coeffs[n] 

return l 

except IndexError: 

return self.base_ring().zero() 

  

cpdef list list(self, bint copy=True): 

r""" 

Return a list of the coefficients of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: l = a.list(); l 

[t^2 + 1, 0, t + 1, 0, 1] 

  

Note that `l` is a list, it is mutable, and each call to the list 

method returns a new list:: 

  

sage: type(l) 

<... 'list'> 

sage: l[0] = 5 

sage: a.list() 

[t^2 + 1, 0, t + 1, 0, 1] 

""" 

if copy: 

# This creates a shallow copy 

return list((<SkewPolynomial_generic_dense>self)._coeffs) 

else: 

return (<SkewPolynomial_generic_dense>self)._coeffs 

  

cpdef dict dict(self): 

r""" 

Return a dictionary representation of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^2012 + t*x^1006 + t^3 + 2*t 

sage: a.dict() 

{0: t^3 + 2*t, 1006: t, 2012: 1} 

""" 

cdef dict X = {} 

cdef list Y = (<SkewPolynomial_generic_dense>self)._coeffs 

cdef int i 

for i in range(len(Y)): 

c = Y[i] 

if c: 

X[i] = c 

return X 

  

cpdef int degree(self): 

r""" 

Return the degree of ``self``. 

  

By convention, the zero skew polynomial has degree `-1`. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^2 + t*x^3 + t^2*x + 1 

sage: a.degree() 

3 

  

By convention, the degree of `0` is `-1`:: 

  

sage: S(0).degree() 

-1 

""" 

return len(self._coeffs) - 1 

  

cpdef _add_(self, right): 

r""" 

Add two polynomials. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = S.random_element(monic=True); a 

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

sage: b = -S.random_element(monic=True); b 

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

sage: c = a+b; c 

(-12*t^2 + 3*t - 193/285)*x - 1/4*t^2 - 1/2*t - 3 

sage: c.degree() 

1 

""" 

cdef Py_ssize_t i, min 

cdef list x = (<SkewPolynomial_generic_dense>self)._coeffs 

cdef list y = (<SkewPolynomial_generic_dense>right)._coeffs 

cdef Py_ssize_t dx = len(x), dy = len(y) 

  

if dx > dy: 

r = self._new_c([x[i] + y[i] for i from 0 <= i < dy] + x[dy:], self._parent, 0) 

elif dx < dy: 

r = self._new_c([x[i] + y[i] for i from 0 <= i < dx] + y[dx:], self._parent, 0) 

else: 

r = self._new_c([x[i] + y[i] for i in range(dx)], self._parent, 1) 

return r 

  

cpdef _sub_(self, right): 

r""" 

Subtract polynomial ``right`` from ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = S.random_element(monic=True); a 

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

sage: b = S.random_element(monic=True); b 

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

sage: c = a-b; c 

(-12*t^2 + 3*t - 193/285)*x - 1/4*t^2 - 1/2*t - 3 

sage: c.degree() 

1 

""" 

cdef Py_ssize_t i, min 

cdef list x = (<SkewPolynomial_generic_dense>self)._coeffs 

cdef list y = (<SkewPolynomial_generic_dense>right)._coeffs 

cdef Py_ssize_t dx = len(x), dy = len(y) 

cdef RingElement c 

  

if dx > dy: 

r = self._new_c([x[i] - y[i] for i from 0 <= i < dy] + x[dy:], self._parent, 0) 

elif dx < dy: 

r = self._new_c([x[i] - y[i] for i from 0 <= i < dx] + [ -c for c in y[dx:] ], self._parent, 0) 

else: 

r = self._new_c([x[i] - y[i] for i from 0 <= i < dx], self._parent, 1) 

return r 

  

cpdef _neg_(self): 

r""" 

Return the negative of ``self``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x^2 + x - 3 

sage: -a 

-t*x^2 - x + 3 

""" 

c = self._new_c([-x for x in (<SkewPolynomial_generic_dense>self)._coeffs], 

self._parent, 0) 

return c 

  

cpdef ModuleElement _lmul_(self, Element right): 

r""" 

Multiply ``self`` on the right by scalar. 

  

INPUT: 

  

- ``right`` -- an element of the base ring 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x + t 

sage: b = t 

sage: a * b 

(t + 1)*x + t^2 

sage: a * b == b * a 

False 

""" 

if right == 0: 

return self._parent.zero() 

cdef list x = (<SkewPolynomial_generic_dense>self)._coeffs 

cdef Py_ssize_t i 

twist_map = self._parent._map 

r = self._new_c([ (twist_map**i)(right)*x[i] for i from 0 <= i < len(x) ], 

self._parent, 0) 

return r 

  

cpdef ModuleElement _rmul_(self, Element left): 

r""" 

Multiply ``self`` on the left by scalar. 

  

INPUT: 

  

- ``left`` -- an element of the base ring 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t 

sage: b = x + t 

sage: a * b 

t*x + t^2 

sage: a * b == b * a 

False 

""" 

if left == 0: 

return self.parent().zero() 

cdef list x = (<SkewPolynomial_generic_dense>self)._coeffs 

cdef Py_ssize_t i 

r = self._new_c([ left*x[i] for i from 0 <= i < len(x) ], self._parent, 0) 

return r 

  

cpdef _mul_(self, right): 

r""" 

Multiply ``self`` on the right by a skew polynomial. 

  

INPUT: 

  

- ``right`` -- a skew polynomial in the same ring as ``self`` 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^2 + t; a 

x^2 + t 

sage: b = x^2 + (t + 1)*x; b 

x^2 + (t + 1)*x 

sage: a * b 

x^4 + (t + 3)*x^3 + t*x^2 + (t^2 + t)*x 

sage: a * b == b * a 

False 

  

TESTS:: 

  

sage: S(0)*a, (S(0)*a).list() 

(0, []) 

""" 

cdef list x = (<SkewPolynomial_generic_dense>self)._coeffs 

cdef list y = (<SkewPolynomial_generic_dense>right)._coeffs 

cdef Py_ssize_t i, k, start, end 

cdef Py_ssize_t dx = len(x)-1, dy = len(y)-1 

parent = self._parent 

if dx == -1: 

return self # = zero 

elif dy == -1: 

return right # = zero 

elif dx == 0: 

c = x[0] 

r = self._new_c([c*a for a in y], parent, 0) 

return r 

cdef list coeffs = [] 

for k from 0 <= k <= dx+dy: 

start = 0 if k <= dy else k-dy 

end = k if k <= dx else dx 

sum = x[start] * parent.twist_map(start)(y[k-start]) 

for i from start < i <= end: 

sum += x[i] * parent.twist_map(i)(y[k-i]) 

coeffs.append(sum) 

r = self._new_c(coeffs, parent, 0) 

return r 

  

cdef SkewPolynomial _new_c(self, list coeffs, Parent P, char check=0): 

r""" 

Fast creation of a new skew polynomial given a list of coefficients. 

  

.. WARNING:: 

  

The list ``coeffs`` is stored internally in the newly created skew 

polynomial, so this must not be modified after calling this method. 

  

TESTS:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x^3 + x^4 + (t+1)*x^2 

sage: a.truncate(4) #indirect doctest 

t*x^3 + (t + 1)*x^2 

""" 

cdef type t = type(self) 

cdef SkewPolynomial_generic_dense f = t.__new__(t) 

f._parent = P 

f._coeffs = coeffs 

if check: 

f.__normalize() 

return f 

  

cdef void __normalize(self): 

r""" 

Remove higher order `0`-coefficients from the representation of ``self``. 

  

TESTS:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma]; S #indirect doctest 

Skew Polynomial Ring in x over Univariate Polynomial Ring in t over Rational Field twisted by t |--> t + 1 

""" 

cdef list x = self._coeffs 

cdef Py_ssize_t n = len(x) - 1 

while n >= 0 and not x[n]: 

del x[n] 

n -= 1 

  

def valuation(self): 

r""" 

Return the minimal degree of a non-zero monomial of ``self``. 

  

By convention, the zero skew polynomial has valuation `+\infty`. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = x^2 + t*x^3 + t^2*x 

sage: a.valuation() 

1 

  

By convention, the valuation of `0` is `+\infty`:: 

  

sage: S(0).valuation() 

+Infinity 

""" 

cdef list x = self._coeffs 

if not x: 

return infinity 

cdef Py_ssize_t v = 0 

while x[v].is_zero() and v < len(x): 

v += 1 

return v 

  

cdef void _inplace_rmul(self, SkewPolynomial_generic_dense right): 

r""" 

Replace ``self`` by ``self*right`` (only for internal use). 

  

TESTS:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x + t 

sage: modulus = x^3 + t*x^2 + (t+3)*x - 2 

sage: a.left_power_mod(100,modulus) # indirect doctest 

(4*t^2 + t + 1)*x^2 + (t^2 + 4*t + 1)*x + 3*t^2 + 3*t 

""" 

cdef list x = self._coeffs 

cdef list y = right._coeffs 

cdef Py_ssize_t i, k, start, end 

cdef Py_ssize_t d1 = len(x)-1, d2 = len(y)-1 

parent = self._parent 

if d2 == -1: 

self._coeffs = [ ] 

elif d1 >= 0: 

for k from d1 < k <= d1+d2: 

start = 0 if k <= d2 else k-d2 

sum = x[start] * parent.twist_map(start)(y[k-start]) 

for i from start < i <= d1: 

sum += x[i] * parent.twist_map(i)(y[k-i]) 

x.append(sum) 

for k from d1 >= k >= 0: 

start = 0 if k <= d2 else k-d2 

end = k if k <= d1 else d1 

sum = x[start] * parent.twist_map(start)(y[k-start]) 

for i from start < i <= end: 

sum += x[i] * parent.twist_map(i)(y[k-i]) 

x[k] = sum 

  

cdef void _inplace_pow(self, Py_ssize_t n): 

r""" 

Replace ``self`` by ``self**n`` (only for internal use). 

  

TESTS:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x + t 

sage: modulus = x^3 + t*x^2 + (t+3)*x - 2 

sage: a.left_power_mod(100,modulus) # indirect doctest 

(4*t^2 + t + 1)*x^2 + (t^2 + 4*t + 1)*x + 3*t^2 + 3*t 

""" 

while n & 1 == 0: 

self._inplace_rmul(self) 

n = n >> 1 

cdef SkewPolynomial_generic_dense selfpow = <SkewPolynomial_generic_dense>self._new_c(list(self._coeffs), self._parent) 

n = n >> 1 

while n != 0: 

selfpow._inplace_rmul(selfpow) 

if n&1 == 1: 

self._inplace_rmul(selfpow) 

n = n >> 1 

  

def truncate(self, n): 

r""" 

Return the polynomial resulting from discarding all monomials of degree 

at least `n`. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = t*x^3 + x^4 + (t+1)*x^2 

sage: a.truncate(4) 

t*x^3 + (t + 1)*x^2 

sage: a.truncate(3) 

(t + 1)*x^2 

""" 

return self._new_c(self._coeffs[:n], self._parent, 1) 

  

@coerce_binop 

def left_quo_rem(self, other): 

r""" 

Return the quotient and remainder of the left euclidean 

division of ``self`` by ``other``. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

- the quotient and the remainder of the left euclidean 

division of this skew polynomial by ``other`` 

  

.. NOTE:: 

  

This will fail if the leading coefficient of ``other`` is not a unit 

or if Sage can't invert the twist map. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 

sage: b = (3*t^2 + 4*t + 2)*x^2 + (2*t^2 + 4*t + 3)*x + 2*t^2 + t + 1 

sage: q,r = a.left_quo_rem(b) 

sage: a == b*q + r 

True 

  

In the following example, Sage does not know the inverse 

of the twist map:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = (-2*t^2 - t + 1)*x^3 + (-t^2 + t)*x^2 + (-12*t - 2)*x - t^2 - 95*t + 1 

sage: b = x^2 + (5*t - 6)*x - 4*t^2 + 4*t - 1 

sage: a.left_quo_rem(b) 

Traceback (most recent call last): 

... 

NotImplementedError: inversion of the twist map Ring endomorphism of Univariate Polynomial Ring in t over Integer Ring 

Defn: t |--> t + 1 

""" 

cdef list a = list(self._coeffs) 

cdef list b = (<SkewPolynomial_generic_dense?>other)._coeffs 

cdef Py_ssize_t i, j 

cdef Py_ssize_t da = self.degree(), db = other.degree() 

if db < 0: 

raise ZeroDivisionError("division by zero is not valid") 

if da < db: 

return (self._new_c([], self._parent), self) 

try: 

inv = self.base_ring()(~b[db]) 

except (ZeroDivisionError, TypeError): 

raise NotImplementedError("the leading coefficient of the divisor is not invertible") 

cdef list q = [ ] 

parent = self._parent 

for i from da-db >= i >= 0: 

try: 

c = parent.twist_map(-db)(inv*a[i+db]) 

for j from 0 <= j < db: 

a[i+j] -= b[j] * parent.twist_map(j)(c) 

except Exception: 

raise NotImplementedError("inversion of the twist map %s" % parent.twist_map()) 

q.append(c) 

q.reverse() 

return (self._new_c(q, parent), self._new_c(a[:db], parent, 1)) 

  

@coerce_binop 

def right_quo_rem(self, other): 

r""" 

Return the quotient and remainder of the right euclidean 

division of ``self`` by ``other``. 

  

INPUT: 

  

- ``other`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

- the quotient and the remainder of the left euclidean 

division of this skew polynomial by ``other`` 

  

.. NOTE:: 

  

This will fail if the leading coefficient of the divisor 

is not a unit. 

  

EXAMPLES:: 

  

sage: R.<t> = ZZ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = S.random_element(degree=4); a 

t^2*x^4 + (-12*t^2 - 2*t - 1)*x^3 + (-95*t^2 + t + 2)*x^2 + (-t^2 + t)*x + 2*t - 8 

sage: b = S.random_element(monic=True); b 

x^2 + (4*t^2 - t - 2)*x - t^2 + t - 1 

sage: q,r = a.right_quo_rem(b) 

sage: a == q*b + r 

True 

  

The leading coefficient of the divisor need to be invertible:: 

  

sage: c = S.random_element(); c 

(-4*t^2 + t)*x^2 - 2*t^2*x + 5*t^2 - 6*t - 4 

sage: a.right_quo_rem(c) 

Traceback (most recent call last): 

... 

NotImplementedError: the leading coefficient of the divisor is not invertible 

""" 

cdef list a = list(self._coeffs) 

cdef list b = (<SkewPolynomial_generic_dense?>other)._coeffs 

cdef Py_ssize_t i, j 

cdef Py_ssize_t da = self.degree(), db = other.degree() 

parent = self._parent 

if db < 0: 

raise ZeroDivisionError("division by zero is not valid") 

if da < db: 

return (self._new_c([],parent), self) 

try: 

inv = self.base_ring()(~b[db]) 

except (ZeroDivisionError, TypeError): 

raise NotImplementedError("the leading coefficient of the divisor" 

" is not invertible") 

cdef list q = [ ] 

parent = self._parent 

for i from da-db >= i >= 0: 

c = parent.twist_map(i)(inv) * a[i+db] 

for j from 0 <= j < db: 

a[i+j] -= c * parent.twist_map(i)(b[j]) 

q.append(c) 

q.reverse() 

return (self._new_c(q, parent), self._new_c(a[:db], parent, 1)) 

  

cpdef left_power_mod(self, exp, modulus): 

r""" 

Return the remainder of ``self**exp`` in the left euclidean division 

by ``modulus``. 

  

INPUT: 

  

- ``exp`` -- an Integer 

  

- ``modulus`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

Remainder of ``self**exp`` in the left euclidean division 

by ``modulus``. 

  

REMARK: 

  

The quotient of the underlying skew polynomial ring by the 

principal ideal generated by ``modulus`` is in general *not* 

a ring. 

  

As a consequence, Sage first computes exactly ``self**exp`` 

and then reduce it modulo ``modulus``. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x + t 

sage: modulus = x^3 + t*x^2 + (t+3)*x - 2 

sage: a.left_power_mod(100,modulus) 

(4*t^2 + t + 1)*x^2 + (t^2 + 4*t + 1)*x + 3*t^2 + 3*t 

""" 

cdef SkewPolynomial_generic_dense r 

if not isinstance(exp, Integer): 

try: 

exp = Integer(exp) 

except TypeError: 

raise TypeError("non-integral exponents not supported") 

  

if len(self._coeffs) <= 1: 

return self.parent()(self._coeffs[0]**exp) 

if exp == 0: 

return self.parent().one() 

if exp < 0: 

return (~self).left_power_mod(-exp, modulus) 

  

if self == self.parent().gen(): 

P = self.parent() 

R = P.base_ring() 

v = [R.zero()]*exp + [R.one()] 

r = <SkewPolynomial_generic_dense>self._parent(v) 

else: 

r = <SkewPolynomial_generic_dense>self._new_c(list(self._coeffs), self._parent) 

r._inplace_pow(exp) 

  

if modulus: 

_, r = r.left_quo_rem(modulus) 

return r 

  

cpdef right_power_mod(self, exp, modulus): 

r""" 

Return the remainder of ``self**exp`` in the right euclidean division 

by ``modulus``. 

  

INPUT: 

  

- ``exp`` -- an Integer 

  

- ``modulus`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

Remainder of ``self**exp`` in the right euclidean division 

by ``modulus``. 

  

REMARK: 

  

The quotient of the underlying skew polynomial ring by the 

principal ideal generated by ``modulus`` is in general *not* 

a ring. 

  

As a consequence, Sage first computes exactly ``self**exp`` 

and then reduce it modulo ``modulus``. 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x + t 

sage: b = a^10 # short form for ``a._pow_(10)`` 

sage: b == a*a*a*a*a*a*a*a*a*a 

True 

sage: modulus = x^3 + t*x^2 + (t+3)*x - 2 

sage: br = a.right_power_mod(10,modulus); br 

(t^2 + t)*x^2 + (3*t^2 + 1)*x + t^2 + t 

sage: rq, rr = b.right_quo_rem(modulus) 

sage: br == rr 

True 

sage: a.right_power_mod(100,modulus) 

(2*t^2 + 3)*x^2 + (t^2 + 4*t + 2)*x + t^2 + 2*t + 1 

""" 

cdef SkewPolynomial_generic_dense r 

if not isinstance(exp, Integer): 

try: 

exp = Integer(exp) 

except TypeError: 

raise TypeError("non-integral exponents not supported") 

  

if len(self._coeffs) <= 1: 

return self.parent()(self._coeffs[0]**exp) 

if exp == 0: 

return self.parent().one() 

if exp < 0: 

return (~self).right_power_mod(-exp, modulus) 

  

if self == self.parent().gen(): 

P = self.parent() 

R = P.base_ring() 

v = [R.zero()]*exp + [R.one()] 

r = <SkewPolynomial_generic_dense>self._parent(v) 

else: 

r = <SkewPolynomial_generic_dense>self._new_c(list(self._coeffs), self._parent) 

r._inplace_pow(exp) 

  

if modulus: 

_, r = r.right_quo_rem(modulus) 

return r 

  

def __pow__(self, exp, modulus): 

r""" 

Return the remainder of ``self**exp`` in the left euclidean 

division by ``modulus``. 

  

INPUT: 

  

- ``exp`` -- an Integer 

  

- ``modulus`` -- a skew polynomial in the same ring as ``self`` 

  

OUTPUT: 

  

Remainder of ``self**exp`` in the right euclidean division 

by ``modulus``. 

  

REMARK: 

  

The quotient of the underlying skew polynomial ring by the 

principal ideal generated by ``modulus`` is in general *not* 

a ring. 

  

As a consequence, Sage first computes exactly ``self**exp`` 

and then reduce it modulo ``modulus``. 

  

.. SEEALSO:: 

  

:meth:`~sage.rings.polynomial.skew_polynomial_element._pow_` 

  

EXAMPLES:: 

  

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: a = x + t 

sage: b = a^10 

sage: b == a*a*a*a*a*a*a*a*a*a 

True 

sage: modulus = x^3 + t*x^2 + (t+3)*x - 2 

sage: bmod = a.right_power_mod(10,modulus); bmod 

(t^2 + t)*x^2 + (3*t^2 + 1)*x + t^2 + t 

sage: rq, rr = b.right_quo_rem(modulus) 

sage: bmod == rr 

True 

""" 

return self.right_power_mod(exp, modulus) 

  

cpdef list coefficients(self, sparse=True): 

r""" 

Return the coefficients of the monomials appearing in ``self``. 

  

If ``sparse=True`` (the default), return only the non-zero coefficients. 

Otherwise, return the same value as ``self.list()``. 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: a = 1 + x^4 + (t+1)*x^2 + t^2 

sage: a.coefficients() 

[t^2 + 1, t + 1, 1] 

sage: a.coefficients(sparse=False) 

[t^2 + 1, 0, t + 1, 0, 1] 

""" 

zero = self.parent().base_ring().zero() 

if sparse: 

return [c for c in self._coeffs if not c.is_zero()] 

else: 

return self._coeffs 

  

cdef class ConstantSkewPolynomialSection(Map): 

r""" 

Representation of the canonical homomorphism from the constants of a skew 

polynomial ring to the base ring. 

  

This class is necessary for automatic coercion from zero-degree skew 

polynomial ring into the base ring. 

  

EXAMPLES:: 

  

sage: from sage.rings.polynomial.skew_polynomial_element import ConstantSkewPolynomialSection 

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: m = ConstantSkewPolynomialSection(S, R); m 

Generic map: 

From: Skew Polynomial Ring in x over Univariate Polynomial Ring in t over Rational Field twisted by t |--> t + 1 

To: Univariate Polynomial Ring in t over Rational Field 

""" 

cpdef Element _call_(self, x): 

r""" 

Return the corresponding element of the base ring if ``self`` is a 

constant skew polynomial. Otherwise, it fails. 

 

TESTS:: 

 

sage: from sage.rings.polynomial.skew_polynomial_element import ConstantSkewPolynomialSection 

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: m = ConstantSkewPolynomialSection(S, R); m 

Generic map: 

From: Skew Polynomial Ring in x over Univariate Polynomial Ring in t over Rational Field twisted by t |--> t + 1 

To: Univariate Polynomial Ring in t over Rational Field 

sage: m(S([0,1])-S([0,1])) 

0 

sage: m(S([3,1])-S([0,1])) 

3 

sage: m(S([0,1])-S([0,t])) 

Traceback (most recent call last): 

... 

TypeError: not a constant polynomial 

""" 

if x.degree() <= 0: 

try: 

return <Element>(x.constant_coefficient()) 

except AttributeError: 

return <Element>((<SkewPolynomial>x).constant_coefficient()) 

else: 

raise TypeError("not a constant polynomial") 

  

  

cdef class SkewPolynomialBaseringInjection(Morphism): 

r""" 

Representation of the canonical homomorphism from a ring `R` into a skew 

polynomial ring over `R`. 

  

This class is necessary for automatic coercion from the base ring to the skew 

polynomial ring. 

  

.. SEEALSO:: 

  

:class:`~sage.rings.polynomial.polynomial_element.PolynomialBaseringInjection` 

  

EXAMPLES:: 

  

sage: R.<t> = QQ[] 

sage: sigma = R.hom([t+1]) 

sage: S.<x> = R['x',sigma] 

sage: S.coerce_map_from(S.base_ring()) #indirect doctest 

Skew Polynomial base injection morphism: 

From: Univariate Polynomial Ring in t over Rational Field 

To: Skew Polynomial Ring in x over Univariate Polynomial Ring in t over Rational Field twisted by t |--> t + 1 

""" 

  

def __init__(self, domain, codomain): 

r""" 

Construct a Skew Polynomial Basering Injection. 

  

INPUT: 

  

- ``domain`` -- a ring `R`. This will be the domain of the injection. 

  

- ``codomain`` -- a skew polynomial ring over ``domain``. This will be 

the codomain. 

  

TESTS:: 

  

sage: from sage.rings.polynomial.skew_polynomial_element import SkewPolynomialBaseringInjection 

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: SkewPolynomialBaseringInjection(k, k['x', Frob]) 

Skew Polynomial base injection morphism: 

From: Finite Field in t of size 5^3 

To: Skew Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 

sage: R.<t> = QQ[] 

sage: SkewPolynomialBaseringInjection(QQ, k['x', Frob]) 

Traceback (most recent call last): 

... 

AssertionError: the domain of the injection must be the base ring of the skew polynomial ring 

""" 

assert codomain.base_ring() is domain, \ 

"the domain of the injection must be the base ring of the skew polynomial ring" 

Morphism.__init__(self, Hom(domain,codomain)) 

self._an_element = codomain.gen() 

self._repr_type_str = "Skew Polynomial base injection" 

self._new_constant_poly_ = self._an_element._new_constant_poly 

  

def an_element(self): 

r""" 

Return an element of the codomain of the ring homomorphism. 

  

EXAMPLES:: 

  

sage: from sage.rings.polynomial.skew_polynomial_element import SkewPolynomialBaseringInjection 

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: m = SkewPolynomialBaseringInjection(k, k['x', Frob]) 

sage: m.an_element() 

x 

""" 

return self._an_element 

  

cpdef Element _call_(self, e): 

r""" 

Return the corresponding skew polynomial to the element from the 

base ring according to ``self``. 

  

INPUT: 

  

- ``e`` -- element belonging to the base ring according to ``self`` 

  

OUTPUT: 

  

The skew polynomial corresponding to `e` according to ``self``. 

  

TESTS:: 

  

sage: from sage.rings.polynomial.skew_polynomial_element import SkewPolynomialBaseringInjection 

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: m = SkewPolynomialBaseringInjection(k, k['x', Frob]) 

sage: m(4) 

4 

sage: parent(m(4)) 

Skew Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 

""" 

try: 

return self._codomain._element_constructor_(e) 

except AttributeError: 

return self._codomain(e) 

  

def section(self): 

r""" 

Return the canonical homomorphism from the constants of a skew 

polynomial ring to the base ring according to ``self``. 

  

TESTS:: 

  

sage: from sage.rings.polynomial.skew_polynomial_element import SkewPolynomialBaseringInjection 

sage: k.<t> = GF(5^3) 

sage: Frob = k.frobenius_endomorphism() 

sage: S.<x> = k['x',Frob] 

sage: m = SkewPolynomialBaseringInjection(k, k['x', Frob]) 

sage: m.section() 

Generic map: 

From: Skew Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 

To: Finite Field in t of size 5^3 

""" 

return ConstantSkewPolynomialSection(self._codomain, self.domain())