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

r""" 

Scalar Fields 

 

Given a topological manifold `M` over a topological field `K` (in most 

applications, `K = \RR` or `K = \CC`), a *scalar field* on `M` is a 

continuous map 

 

.. MATH:: 

 

f: M \longrightarrow K 

 

Scalar fields are implemented by the class :class:`ScalarField`. 

 

AUTHORS: 

 

- Eric Gourgoulhon, Michal Bejger (2013-2015): initial version 

- Travis Scrimshaw (2016): review tweaks 

- Marco Mancini (2017): SymPy as an optional symbolic engine, alternative to SR 

 

REFERENCES: 

 

- [Lee2011]_ 

- [KN1963]_ 

 

""" 

 

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

# Copyright (C) 2015 Eric Gourgoulhon <eric.gourgoulhon@obspm.fr> 

# Copyright (C) 2015 Michal Bejger <bejger@camk.edu.pl> 

# Copyright (C) 2016 Travis Scrimshaw <tscrimsh@umn.edu> 

# Copyright (C) 2017 Marco Mancini <marco.mancini@obspm.fr> 

# 

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

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

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

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

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

 

from six import itervalues 

 

from sage.structure.element import CommutativeAlgebraElement 

from sage.symbolic.expression import Expression 

from sage.manifolds.chart_func import ChartFunction 

 

class ScalarField(CommutativeAlgebraElement): 

r""" 

Scalar field on a topological manifold. 

 

Given a topological manifold `M` over a topological field `K` (in most 

applications, `K = \RR` or `K = \CC`), a *scalar field on* `M` is a 

continuous map 

 

.. MATH:: 

 

f: M \longrightarrow K. 

 

A scalar field on `M` is an element of the commutative algebra 

`C^0(M)` (see 

:class:`~sage.manifolds.scalarfield_algebra.ScalarFieldAlgebra`). 

 

INPUT: 

 

- ``parent`` -- the algebra of scalar fields containing the scalar field 

(must be an instance of class 

:class:`~sage.manifolds.scalarfield_algebra.ScalarFieldAlgebra`) 

 

- ``coord_expression`` -- (default: ``None``) coordinate expression(s) of 

the scalar field; this can be either 

 

* a dictionary of coordinate expressions in various charts on 

the domain, with the charts as keys; 

* a single coordinate expression; if the argument ``chart`` is 

``'all'``, this expression is set to all the charts defined 

on the open set; otherwise, the expression is set in the 

specific chart provided by the argument ``chart`` 

 

- ``chart`` -- (default: ``None``) chart defining the coordinates used 

in ``coord_expression`` when the latter is a single coordinate 

expression; if none is provided (default), the default chart of the 

open set is assumed. If ``chart=='all'``, ``coord_expression`` is 

assumed to be independent of the chart (constant scalar field). 

 

- ``name`` -- (default: ``None``) string; name (symbol) given to the 

scalar field 

 

- ``latex_name`` -- (default: ``None``) string; LaTeX symbol to denote the 

scalar field; if none is provided, the LaTeX symbol is set to ``name`` 

 

If ``coord_expression`` is ``None`` or incomplete, coordinate 

expressions can be added after the creation of the object, by means of 

the methods :meth:`add_expr`, :meth:`add_expr_by_continuation` and 

:meth:`set_expr`. 

 

EXAMPLES: 

 

A scalar field on the 2-sphere:: 

 

sage: M = Manifold(2, 'M', structure='topological') # the 2-dimensional sphere S^2 

sage: U = M.open_subset('U') # complement of the North pole 

sage: c_xy.<x,y> = U.chart() # stereographic coordinates from the North pole 

sage: V = M.open_subset('V') # complement of the South pole 

sage: c_uv.<u,v> = V.chart() # stereographic coordinates from the South pole 

sage: M.declare_union(U,V) # S^2 is the union of U and V 

sage: xy_to_uv = c_xy.transition_map(c_uv, (x/(x^2+y^2), y/(x^2+y^2)), 

....: intersection_name='W', 

....: restrictions1= x^2+y^2!=0, 

....: restrictions2= u^2+v^2!=0) 

sage: uv_to_xy = xy_to_uv.inverse() 

sage: f = M.scalar_field({c_xy: 1/(1+x^2+y^2), c_uv: (u^2+v^2)/(1+u^2+v^2)}, 

....: name='f') ; f 

Scalar field f on the 2-dimensional topological manifold M 

sage: f.display() 

f: M --> R 

on U: (x, y) |--> 1/(x^2 + y^2 + 1) 

on V: (u, v) |--> (u^2 + v^2)/(u^2 + v^2 + 1) 

 

For scalar fields defined by a single coordinate expression, the latter 

can be passed instead of the dictionary over the charts:: 

 

sage: g = U.scalar_field(x*y, chart=c_xy, name='g') ; g 

Scalar field g on the Open subset U of the 2-dimensional topological 

manifold M 

 

The above is indeed equivalent to:: 

 

sage: g = U.scalar_field({c_xy: x*y}, name='g') ; g 

Scalar field g on the Open subset U of the 2-dimensional topological 

manifold M 

 

Since ``c_xy`` is the default chart of ``U``, the argument ``chart`` can 

be skipped:: 

 

sage: g = U.scalar_field(x*y, name='g') ; g 

Scalar field g on the Open subset U of the 2-dimensional topological 

manifold M 

 

The scalar field `g` is defined on `U` and has an expression in terms of 

the coordinates `(u,v)` on `W=U\cap V`:: 

 

sage: g.display() 

g: U --> R 

(x, y) |--> x*y 

on W: (u, v) |--> u*v/(u^4 + 2*u^2*v^2 + v^4) 

 

Scalar fields on `M` can also be declared with a single chart:: 

 

sage: f = M.scalar_field(1/(1+x^2+y^2), chart=c_xy, name='f') ; f 

Scalar field f on the 2-dimensional topological manifold M 

 

Their definition must then be completed by providing the expressions on 

other charts, via the method :meth:`add_expr`, to get a global cover of 

the manifold:: 

 

sage: f.add_expr((u^2+v^2)/(1+u^2+v^2), chart=c_uv) 

sage: f.display() 

f: M --> R 

on U: (x, y) |--> 1/(x^2 + y^2 + 1) 

on V: (u, v) |--> (u^2 + v^2)/(u^2 + v^2 + 1) 

 

We can even first declare the scalar field without any coordinate 

expression and provide them subsequently:: 

 

sage: f = M.scalar_field(name='f') 

sage: f.add_expr(1/(1+x^2+y^2), chart=c_xy) 

sage: f.add_expr((u^2+v^2)/(1+u^2+v^2), chart=c_uv) 

sage: f.display() 

f: M --> R 

on U: (x, y) |--> 1/(x^2 + y^2 + 1) 

on V: (u, v) |--> (u^2 + v^2)/(u^2 + v^2 + 1) 

 

We may also use the method :meth:`add_expr_by_continuation` to complete 

the coordinate definition using the analytic continuation from domains in 

which charts overlap:: 

 

sage: f = M.scalar_field(1/(1+x^2+y^2), chart=c_xy, name='f') ; f 

Scalar field f on the 2-dimensional topological manifold M 

sage: f.add_expr_by_continuation(c_uv, U.intersection(V)) 

sage: f.display() 

f: M --> R 

on U: (x, y) |--> 1/(x^2 + y^2 + 1) 

on V: (u, v) |--> (u^2 + v^2)/(u^2 + v^2 + 1) 

 

A scalar field can also be defined by some unspecified function of the 

coordinates:: 

 

sage: h = U.scalar_field(function('H')(x, y), name='h') ; h 

Scalar field h on the Open subset U of the 2-dimensional topological 

manifold M 

sage: h.display() 

h: U --> R 

(x, y) |--> H(x, y) 

on W: (u, v) |--> H(u/(u^2 + v^2), v/(u^2 + v^2)) 

 

We may use the argument ``latex_name`` to specify the LaTeX symbol denoting 

the scalar field if the latter is different from ``name``:: 

 

sage: latex(f) 

f 

sage: f = M.scalar_field({c_xy: 1/(1+x^2+y^2), c_uv: (u^2+v^2)/(1+u^2+v^2)}, 

....: name='f', latex_name=r'\mathcal{F}') 

sage: latex(f) 

\mathcal{F} 

 

The coordinate expression in a given chart is obtained via the method 

:meth:`expr`, which returns a symbolic expression:: 

 

sage: f.expr(c_uv) 

(u^2 + v^2)/(u^2 + v^2 + 1) 

sage: type(f.expr(c_uv)) 

<type 'sage.symbolic.expression.Expression'> 

 

The method :meth:`coord_function` returns instead a function of the 

chart coordinates, i.e. an instance of 

:class:`~sage.manifolds.chart_func.ChartFunction`:: 

 

sage: f.coord_function(c_uv) 

(u^2 + v^2)/(u^2 + v^2 + 1) 

sage: type(f.coord_function(c_uv)) 

<class 'sage.manifolds.chart_func.ChartFunctionRing_with_category.element_class'> 

sage: f.coord_function(c_uv).display() 

(u, v) |--> (u^2 + v^2)/(u^2 + v^2 + 1) 

 

The value returned by the method :meth:`expr` is actually the coordinate 

expression of the chart function:: 

 

sage: f.expr(c_uv) is f.coord_function(c_uv).expr() 

True 

 

A constant scalar field is declared by setting the argument ``chart`` to 

``'all'``:: 

 

sage: c = M.scalar_field(2, chart='all', name='c') ; c 

Scalar field c on the 2-dimensional topological manifold M 

sage: c.display() 

c: M --> R 

on U: (x, y) |--> 2 

on V: (u, v) |--> 2 

 

A shortcut is to use the method 

:meth:`~sage.manifolds.manifold.TopologicalManifold.constant_scalar_field`:: 

 

sage: c == M.constant_scalar_field(2) 

True 

 

The constant value can be some unspecified parameter:: 

 

sage: var('a') 

a 

sage: c = M.constant_scalar_field(a, name='c') ; c 

Scalar field c on the 2-dimensional topological manifold M 

sage: c.display() 

c: M --> R 

on U: (x, y) |--> a 

on V: (u, v) |--> a 

 

A special case of constant field is the zero scalar field:: 

 

sage: zer = M.constant_scalar_field(0) ; zer 

Scalar field zero on the 2-dimensional topological manifold M 

sage: zer.display() 

zero: M --> R 

on U: (x, y) |--> 0 

on V: (u, v) |--> 0 

 

It can be obtained directly by means of the function 

:meth:`~sage.manifolds.manifold.TopologicalManifold.zero_scalar_field`:: 

 

sage: zer is M.zero_scalar_field() 

True 

 

A third way is to get it as the zero element of the algebra `C^0(M)` 

of scalar fields on `M` (see below):: 

 

sage: zer is M.scalar_field_algebra().zero() 

True 

 

By definition, a scalar field acts on the manifold's points, sending 

them to elements of the manifold's base field (real numbers in the 

present case):: 

 

sage: N = M.point((0,0), chart=c_uv) # the North pole 

sage: S = M.point((0,0), chart=c_xy) # the South pole 

sage: E = M.point((1,0), chart=c_xy) # a point at the equator 

sage: f(N) 

0 

sage: f(S) 

1 

sage: f(E) 

1/2 

sage: h(E) 

H(1, 0) 

sage: c(E) 

a 

sage: zer(E) 

0 

 

A scalar field can be compared to another scalar field:: 

 

sage: f == g 

False 

 

...to a symbolic expression:: 

 

sage: f == x*y 

False 

sage: g == x*y 

True 

sage: c == a 

True 

 

...to a number:: 

 

sage: f == 2 

False 

sage: zer == 0 

True 

 

...to anything else:: 

 

sage: f == M 

False 

 

Standard mathematical functions are implemented:: 

 

sage: sqrt(f) 

Scalar field sqrt(f) on the 2-dimensional topological manifold M 

sage: sqrt(f).display() 

sqrt(f): M --> R 

on U: (x, y) |--> 1/sqrt(x^2 + y^2 + 1) 

on V: (u, v) |--> sqrt(u^2 + v^2)/sqrt(u^2 + v^2 + 1) 

 

:: 

 

sage: tan(f) 

Scalar field tan(f) on the 2-dimensional topological manifold M 

sage: tan(f).display() 

tan(f): M --> R 

on U: (x, y) |--> sin(1/(x^2 + y^2 + 1))/cos(1/(x^2 + y^2 + 1)) 

on V: (u, v) |--> sin((u^2 + v^2)/(u^2 + v^2 + 1))/cos((u^2 + v^2)/(u^2 + v^2 + 1)) 

 

.. RUBRIC:: Arithmetics of scalar fields 

 

Scalar fields on `M` (resp. `U`) belong to the algebra `C^0(M)` 

(resp. `C^0(U)`):: 

 

sage: f.parent() 

Algebra of scalar fields on the 2-dimensional topological manifold M 

sage: f.parent() is M.scalar_field_algebra() 

True 

sage: g.parent() 

Algebra of scalar fields on the Open subset U of the 2-dimensional 

topological manifold M 

sage: g.parent() is U.scalar_field_algebra() 

True 

 

Consequently, scalar fields can be added:: 

 

sage: s = f + c ; s 

Scalar field f+c on the 2-dimensional topological manifold M 

sage: s.display() 

f+c: M --> R 

on U: (x, y) |--> (a*x^2 + a*y^2 + a + 1)/(x^2 + y^2 + 1) 

on V: (u, v) |--> ((a + 1)*u^2 + (a + 1)*v^2 + a)/(u^2 + v^2 + 1) 

 

and subtracted:: 

 

sage: s = f - c ; s 

Scalar field f-c on the 2-dimensional topological manifold M 

sage: s.display() 

f-c: M --> R 

on U: (x, y) |--> -(a*x^2 + a*y^2 + a - 1)/(x^2 + y^2 + 1) 

on V: (u, v) |--> -((a - 1)*u^2 + (a - 1)*v^2 + a)/(u^2 + v^2 + 1) 

 

Some tests:: 

 

sage: f + zer == f 

True 

sage: f - f == zer 

True 

sage: f + (-f) == zer 

True 

sage: (f+c)-f == c 

True 

sage: (f-c)+c == f 

True 

 

We may add a number (interpreted as a constant scalar field) to a scalar 

field:: 

 

sage: s = f + 1 ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> (x^2 + y^2 + 2)/(x^2 + y^2 + 1) 

on V: (u, v) |--> (2*u^2 + 2*v^2 + 1)/(u^2 + v^2 + 1) 

sage: (f+1)-1 == f 

True 

 

The number can represented by a symbolic variable:: 

 

sage: s = a + f ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s == c + f 

True 

 

However if the symbolic variable is a chart coordinate, the addition 

is performed only on the chart domain:: 

 

sage: s = f + x; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> (x^3 + x*y^2 + x + 1)/(x^2 + y^2 + 1) 

sage: s = f + u; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on V: (u, v) |--> (u^3 + (u + 1)*v^2 + u^2 + u)/(u^2 + v^2 + 1) 

 

The addition of two scalar fields with different domains is possible if 

the domain of one of them is a subset of the domain of the other; the 

domain of the result is then this subset:: 

 

sage: f.domain() 

2-dimensional topological manifold M 

sage: g.domain() 

Open subset U of the 2-dimensional topological manifold M 

sage: s = f + g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.domain() 

Open subset U of the 2-dimensional topological manifold M 

sage: s.display() 

U --> R 

(x, y) |--> (x*y^3 + (x^3 + x)*y + 1)/(x^2 + y^2 + 1) 

on W: (u, v) |--> (u^6 + 3*u^4*v^2 + 3*u^2*v^4 + v^6 + u*v^3 

+ (u^3 + u)*v)/(u^6 + v^6 + (3*u^2 + 1)*v^4 + u^4 + (3*u^4 + 2*u^2)*v^2) 

 

The operation actually performed is `f|_U + g`:: 

 

sage: s == f.restrict(U) + g 

True 

 

In Sage framework, the addition of `f` and `g` is permitted because 

there is a *coercion* of the parent of `f`, namely `C^0(M)`, to 

the parent of `g`, namely `C^0(U)` (see 

:class:`~sage.manifolds.scalarfield_algebra.ScalarFieldAlgebra`):: 

 

sage: CM = M.scalar_field_algebra() 

sage: CU = U.scalar_field_algebra() 

sage: CU.has_coerce_map_from(CM) 

True 

 

The coercion map is nothing but the restriction to domain `U`:: 

 

sage: CU.coerce(f) == f.restrict(U) 

True 

 

Since the algebra `C^0(M)` is a vector space over `\RR`, scalar fields 

can be multiplied by a number, either an explicit one:: 

 

sage: s = 2*f ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> 2/(x^2 + y^2 + 1) 

on V: (u, v) |--> 2*(u^2 + v^2)/(u^2 + v^2 + 1) 

 

or a symbolic one:: 

 

sage: s = a*f ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> a/(x^2 + y^2 + 1) 

on V: (u, v) |--> (u^2 + v^2)*a/(u^2 + v^2 + 1) 

 

However, if the symbolic variable is a chart coordinate, the 

multiplication is performed only in the corresponding chart:: 

 

sage: s = x*f; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> x/(x^2 + y^2 + 1) 

sage: s = u*f; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on V: (u, v) |--> (u^2 + v^2)*u/(u^2 + v^2 + 1) 

 

Some tests:: 

 

sage: 0*f == 0 

True 

sage: 0*f == zer 

True 

sage: 1*f == f 

True 

sage: (-2)*f == - f - f 

True 

 

The ring multiplication of the algebras `C^0(M)` and `C^0(U)` 

is the pointwise multiplication of functions:: 

 

sage: s = f*f ; s 

Scalar field f*f on the 2-dimensional topological manifold M 

sage: s.display() 

f*f: M --> R 

on U: (x, y) |--> 1/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1) 

on V: (u, v) |--> (u^4 + 2*u^2*v^2 + v^4)/(u^4 + v^4 + 2*(u^2 + 1)*v^2 

+ 2*u^2 + 1) 

sage: s = g*h ; s 

Scalar field g*h on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

g*h: U --> R 

(x, y) |--> x*y*H(x, y) 

on W: (u, v) |--> u*v*H(u/(u^2 + v^2), v/(u^2 + v^2))/(u^4 + 2*u^2*v^2 + v^4) 

 

Thanks to the coercion `C^0(M) \to C^0(U)` mentioned above, 

it is possible to multiply a scalar field defined on `M` by a 

scalar field defined on `U`, the result being a scalar field 

defined on `U`:: 

 

sage: f.domain(), g.domain() 

(2-dimensional topological manifold M, 

Open subset U of the 2-dimensional topological manifold M) 

sage: s = f*g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

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

on W: (u, v) |--> u*v/(u^4 + v^4 + (2*u^2 + 1)*v^2 + u^2) 

sage: s == f.restrict(U)*g 

True 

 

Scalar fields can be divided (pointwise division):: 

 

sage: s = f/c ; s 

Scalar field f/c on the 2-dimensional topological manifold M 

sage: s.display() 

f/c: M --> R 

on U: (x, y) |--> 1/(a*x^2 + a*y^2 + a) 

on V: (u, v) |--> (u^2 + v^2)/(a*u^2 + a*v^2 + a) 

sage: s = g/h ; s 

Scalar field g/h on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

g/h: U --> R 

(x, y) |--> x*y/H(x, y) 

on W: (u, v) |--> u*v/((u^4 + 2*u^2*v^2 + v^4)*H(u/(u^2 + v^2), v/(u^2 + v^2))) 

sage: s = f/g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> 1/(x*y^3 + (x^3 + x)*y) 

on W: (u, v) |--> (u^6 + 3*u^4*v^2 + 3*u^2*v^4 + v^6)/(u*v^3 + (u^3 + u)*v) 

sage: s == f.restrict(U)/g 

True 

 

For scalar fields defined on a single chart domain, we may perform some 

arithmetics with symbolic expressions involving the chart coordinates:: 

 

sage: s = g + x^2 - y ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> x^2 + (x - 1)*y 

on W: (u, v) |--> -(v^3 - u^2 + (u^2 - u)*v)/(u^4 + 2*u^2*v^2 + v^4) 

 

:: 

 

sage: s = g*x ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> x^2*y 

on W: (u, v) |--> u^2*v/(u^6 + 3*u^4*v^2 + 3*u^2*v^4 + v^6) 

 

:: 

 

sage: s = g/x ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> y 

on W: (u, v) |--> v/(u^2 + v^2) 

sage: s = x/g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> 1/y 

on W: (u, v) |--> (u^2 + v^2)/v 

 

 

.. RUBRIC:: Examples with SymPy as the symbolic engine 

 

From now on, we ask that all symbolic calculus on manifold `M` are 

performed by SymPy:: 

 

sage: M.set_calculus_method('sympy') 

 

We define `f` as above:: 

 

sage: f = M.scalar_field({c_xy: 1/(1+x^2+y^2), c_uv: (u^2+v^2)/(1+u^2+v^2)}, 

....: name='f') ; f 

Scalar field f on the 2-dimensional topological manifold M 

sage: f.display() # notice the SymPy display of exponents 

f: M --> R 

on U: (x, y) |--> 1/(x**2 + y**2 + 1) 

on V: (u, v) |--> (u**2 + v**2)/(u**2 + v**2 + 1) 

sage: type(f.coord_function(c_xy).expr()) 

<class 'sympy.core.power.Pow'> 

 

The scalar field `g` defined on `U`:: 

 

sage: g = U.scalar_field({c_xy: x*y}, name='g') 

sage: g.display() # again notice the SymPy display of exponents 

g: U --> R 

(x, y) |--> x*y 

on W: (u, v) |--> u*v/(u**4 + 2*u**2*v**2 + v**4) 

 

Definition on a single chart and subsequent completion:: 

 

sage: f = M.scalar_field(1/(1+x^2+y^2), chart=c_xy, name='f') 

sage: f.add_expr((u^2+v^2)/(1+u^2+v^2), chart=c_uv) 

sage: f.display() 

f: M --> R 

on U: (x, y) |--> 1/(x**2 + y**2 + 1) 

on V: (u, v) |--> (u**2 + v**2)/(u**2 + v**2 + 1) 

 

Defintion without any coordinate expression and subsequent completion:: 

 

sage: f = M.scalar_field(name='f') 

sage: f.add_expr(1/(1+x^2+y^2), chart=c_xy) 

sage: f.add_expr((u^2+v^2)/(1+u^2+v^2), chart=c_uv) 

sage: f.display() 

f: M --> R 

on U: (x, y) |--> 1/(x**2 + y**2 + 1) 

on V: (u, v) |--> (u**2 + v**2)/(u**2 + v**2 + 1) 

 

Use of :meth:`add_expr_by_continuation`:: 

 

sage: f = M.scalar_field(1/(1+x^2+y^2), chart=c_xy, name='f') 

sage: f.add_expr_by_continuation(c_uv, U.intersection(V)) 

sage: f.display() 

f: M --> R 

on U: (x, y) |--> 1/(x**2 + y**2 + 1) 

on V: (u, v) |--> (u**2 + v**2)/(u**2 + v**2 + 1) 

 

A scalar field defined by some unspecified function of the 

coordinates:: 

 

sage: h = U.scalar_field(function('H')(x, y), name='h') ; h 

Scalar field h on the Open subset U of the 2-dimensional topological 

manifold M 

sage: h.display() 

h: U --> R 

(x, y) |--> H(x, y) 

on W: (u, v) |--> H(u/(u**2 + v**2), v/(u**2 + v**2)) 

 

The coordinate expression in a given chart is obtained via the method 

:meth:`expr`, which in the present context, returns a SymPy object:: 

 

sage: f.expr(c_uv) 

(u**2 + v**2)/(u**2 + v**2 + 1) 

sage: type(f.expr(c_uv)) 

<class 'sympy.core.mul.Mul'> 

 

The method :meth:`coord_function` returns instead a function of the 

chart coordinates, i.e. an instance of 

:class:`~sage.manifolds.chart_func.ChartFunction`:: 

 

sage: f.coord_function(c_uv) 

(u**2 + v**2)/(u**2 + v**2 + 1) 

sage: type(f.coord_function(c_uv)) 

<class 'sage.manifolds.chart_func.ChartFunctionRing_with_category.element_class'> 

sage: f.coord_function(c_uv).display() 

(u, v) |--> (u**2 + v**2)/(u**2 + v**2 + 1) 

 

The value returned by the method :meth:`expr` is actually the coordinate 

expression of the chart function:: 

 

sage: f.expr(c_uv) is f.coord_function(c_uv).expr() 

True 

 

We may ask for the ``SR`` representation of the coordinate function:: 

 

sage: f.coord_function(c_uv).expr('SR') 

(u^2 + v^2)/(u^2 + v^2 + 1) 

 

A constant scalar field with SymPy representation:: 

 

sage: c = M.constant_scalar_field(2, name='c') 

sage: c.display() 

c: M --> R 

on U: (x, y) |--> 2 

on V: (u, v) |--> 2 

sage: type(c.expr(c_xy)) 

<class 'sympy.core.numbers.Integer'> 

 

The constant value can be some unspecified parameter:: 

 

sage: var('a') 

a 

sage: c = M.constant_scalar_field(a, name='c') 

sage: c.display() 

c: M --> R 

on U: (x, y) |--> a 

on V: (u, v) |--> a 

sage: type(c.expr(c_xy)) 

<class 'sympy.core.symbol.Symbol'> 

 

The zero scalar field:: 

 

sage: zer = M.constant_scalar_field(0) ; zer 

Scalar field zero on the 2-dimensional topological manifold M 

sage: zer.display() 

zero: M --> R 

on U: (x, y) |--> 0 

on V: (u, v) |--> 0 

sage: type(zer.expr(c_xy)) 

<class 'sympy.core.numbers.Zero'> 

sage: zer is M.zero_scalar_field() 

True 

 

Action of scalar fields on manifold's points:: 

 

sage: N = M.point((0,0), chart=c_uv) # the North pole 

sage: S = M.point((0,0), chart=c_xy) # the South pole 

sage: E = M.point((1,0), chart=c_xy) # a point at the equator 

sage: f(N) 

0 

sage: f(S) 

1 

sage: f(E) 

1/2 

sage: h(E) 

H(1, 0) 

sage: c(E) 

a 

sage: zer(E) 

0 

 

A scalar field can be compared to another scalar field:: 

 

sage: f == g 

False 

 

...to a symbolic expression:: 

 

sage: f == x*y 

False 

sage: g == x*y 

True 

sage: c == a 

True 

 

...to a number:: 

 

sage: f == 2 

False 

sage: zer == 0 

True 

 

...to anything else:: 

 

sage: f == M 

False 

 

Standard mathematical functions are implemented:: 

 

sage: sqrt(f) 

Scalar field sqrt(f) on the 2-dimensional topological manifold M 

sage: sqrt(f).display() 

sqrt(f): M --> R 

on U: (x, y) |--> 1/sqrt(x**2 + y**2 + 1) 

on V: (u, v) |--> sqrt(u**2 + v**2)/sqrt(u**2 + v**2 + 1) 

 

:: 

 

sage: tan(f) 

Scalar field tan(f) on the 2-dimensional topological manifold M 

sage: tan(f).display() 

tan(f): M --> R 

on U: (x, y) |--> tan(1/(x**2 + y**2 + 1)) 

on V: (u, v) |--> tan((u**2 + v**2)/(u**2 + v**2 + 1)) 

 

.. RUBRIC:: Arithmetics of scalar fields with SymPy 

 

Scalar fields on `M` (resp. `U`) belong to the algebra `C^0(M)` 

(resp. `C^0(U)`):: 

 

sage: f.parent() 

Algebra of scalar fields on the 2-dimensional topological manifold M 

sage: f.parent() is M.scalar_field_algebra() 

True 

sage: g.parent() 

Algebra of scalar fields on the Open subset U of the 2-dimensional 

topological manifold M 

sage: g.parent() is U.scalar_field_algebra() 

True 

 

Consequently, scalar fields can be added:: 

 

sage: s = f + c ; s 

Scalar field f+c on the 2-dimensional topological manifold M 

sage: s.display() 

f+c: M --> R 

on U: (x, y) |--> (a*x**2 + a*y**2 + a + 1)/(x**2 + y**2 + 1) 

on V: (u, v) |--> (a*u**2 + a*v**2 + a + u**2 + v**2)/(u**2 + v**2 + 1) 

 

and subtracted:: 

 

sage: s = f - c ; s 

Scalar field f-c on the 2-dimensional topological manifold M 

sage: s.display() 

f-c: M --> R 

on U: (x, y) |--> (-a*x**2 - a*y**2 - a + 1)/(x**2 + y**2 + 1) 

on V: (u, v) |--> (-a*u**2 - a*v**2 - a + u**2 + v**2)/(u**2 + v**2 + 1) 

 

Some tests:: 

 

sage: f + zer == f 

True 

sage: f - f == zer 

True 

sage: f + (-f) == zer 

True 

sage: (f+c)-f == c 

True 

sage: (f-c)+c == f 

True 

 

We may add a number (interpreted as a constant scalar field) to a scalar 

field:: 

 

sage: s = f + 1 ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> (x**2 + y**2 + 2)/(x**2 + y**2 + 1) 

on V: (u, v) |--> (2*u**2 + 2*v**2 + 1)/(u**2 + v**2 + 1) 

sage: (f+1)-1 == f 

True 

 

The number can represented by a symbolic variable:: 

 

sage: s = a + f ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s == c + f 

True 

 

However if the symbolic variable is a chart coordinate, the addition 

is performed only on the chart domain:: 

 

sage: s = f + x; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> (x**3 + x*y**2 + x + 1)/(x**2 + y**2 + 1) 

sage: s = f + u; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on V: (u, v) |--> (u**3 + u**2 + u*v**2 + u + v**2)/(u**2 + v**2 + 1) 

 

The addition of two scalar fields with different domains is possible if 

the domain of one of them is a subset of the domain of the other; the 

domain of the result is then this subset:: 

 

sage: f.domain() 

2-dimensional topological manifold M 

sage: g.domain() 

Open subset U of the 2-dimensional topological manifold M 

sage: s = f + g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.domain() 

Open subset U of the 2-dimensional topological manifold M 

sage: s.display() 

U --> R 

(x, y) |--> (x**3*y + x*y**3 + x*y + 1)/(x**2 + y**2 + 1) 

on W: (u, v) |--> (u**6 + 3*u**4*v**2 + u**3*v + 3*u**2*v**4 + u*v**3 + u*v + v**6)/(u**6 + 3*u**4*v**2 + u**4 + 3*u**2*v**4 + 2*u**2*v**2 + v**6 + v**4) 

 

The operation actually performed is `f|_U + g`:: 

 

sage: s == f.restrict(U) + g 

True 

 

Since the algebra `C^0(M)` is a vector space over `\RR`, scalar fields 

can be multiplied by a number, either an explicit one:: 

 

sage: s = 2*f ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> 2/(x**2 + y**2 + 1) 

on V: (u, v) |--> 2*(u**2 + v**2)/(u**2 + v**2 + 1) 

 

or a symbolic one:: 

 

sage: s = a*f ; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> a/(x**2 + y**2 + 1) 

on V: (u, v) |--> a*(u**2 + v**2)/(u**2 + v**2 + 1) 

 

However, if the symbolic variable is a chart coordinate, the 

multiplication is performed only in the corresponding chart:: 

 

sage: s = x*f; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on U: (x, y) |--> x/(x**2 + y**2 + 1) 

sage: s = u*f; s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

on V: (u, v) |--> u*(u**2 + v**2)/(u**2 + v**2 + 1) 

 

Some tests:: 

 

sage: 0*f == 0 

True 

sage: 0*f == zer 

True 

sage: 1*f == f 

True 

sage: (-2)*f == - f - f 

True 

 

The ring multiplication of the algebras `C^0(M)` and `C^0(U)` 

is the pointwise multiplication of functions:: 

 

sage: s = f*f ; s 

Scalar field f*f on the 2-dimensional topological manifold M 

sage: s.display() 

f*f: M --> R 

on U: (x, y) |--> 1/(x**4 + 2*x**2*y**2 + 2*x**2 + y**4 + 2*y**2 + 1) 

on V: (u, v) |--> (u**4 + 2*u**2*v**2 + v**4)/(u**4 + 2*u**2*v**2 + 2*u**2 + v**4 + 2*v**2 + 1) 

 

sage: s = g*h ; s 

Scalar field g*h on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

g*h: U --> R 

(x, y) |--> x*y*H(x, y) 

on W: (u, v) |--> u*v*H(u/(u**2 + v**2), v/(u**2 + v**2))/(u**4 + 2*u**2*v**2 + v**4) 

 

Thanks to the coercion `C^0(M) \to C^0(U)` mentioned above, 

it is possible to multiply a scalar field defined on `M` by a 

scalar field defined on `U`, the result being a scalar field 

defined on `U`:: 

 

sage: f.domain(), g.domain() 

(2-dimensional topological manifold M, 

Open subset U of the 2-dimensional topological manifold M) 

sage: s = f*g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> x*y/(x**2 + y**2 + 1) 

on W: (u, v) |--> u*v/(u**4 + 2*u**2*v**2 + u**2 + v**4 + v**2) 

 

sage: s == f.restrict(U)*g 

True 

 

Scalar fields can be divided (pointwise division):: 

 

sage: s = f/c ; s 

Scalar field f/c on the 2-dimensional topological manifold M 

sage: s.display() 

f/c: M --> R 

on U: (x, y) |--> 1/(a*(x**2 + y**2 + 1)) 

on V: (u, v) |--> (u**2 + v**2)/(a*(u**2 + v**2 + 1)) 

sage: s = g/h ; s 

Scalar field g/h on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

g/h: U --> R 

(x, y) |--> x*y/H(x, y) 

on W: (u, v) |--> u*v/((u**4 + 2*u**2*v**2 + v**4)*H(u/(u**2 + v**2), v/(u**2 + v**2))) 

 

sage: s = f/g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> 1/(x*y*(x**2 + y**2 + 1)) 

on W: (u, v) |--> (u**6 + 3*u**4*v**2 + 3*u**2*v**4 + v**6)/(u*v*(u**2 + v**2 + 1)) 

sage: s == f.restrict(U)/g 

True 

 

For scalar fields defined on a single chart domain, we may perform some 

arithmetics with symbolic expressions involving the chart coordinates:: 

 

sage: s = g + x^2 - y ; s 

Scalar field on the Open subset U of the 2-dimensional topological manifold M 

sage: s.display() 

U --> R 

(x, y) |--> x**2 + x*y - y 

on W: (u, v) |--> (-u**2*v + u**2 + u*v - v**3)/(u**4 + 2*u**2*v**2 + v**4) 

 

 

:: 

 

sage: s = g*x ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> x**2*y 

on W: (u, v) |--> u**2*v/(u**6 + 3*u**4*v**2 + 3*u**2*v**4 + v**6) 

 

:: 

 

sage: s = g/x ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> y 

on W: (u, v) |--> v/(u**2 + v**2) 

sage: s = x/g ; s 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: s.display() 

U --> R 

(x, y) |--> 1/y 

on W: (u, v) |--> u**2/v + v 

 

The test suite is passed:: 

 

sage: TestSuite(f).run() 

sage: TestSuite(zer).run() 

 

""" 

def __init__(self, parent, coord_expression=None, chart=None, name=None, 

latex_name=None): 

r""" 

Construct a scalar field. 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') ; f 

Scalar field f on the 2-dimensional topological manifold M 

sage: from sage.manifolds.scalarfield import ScalarField 

sage: isinstance(f, ScalarField) 

True 

sage: f.parent() 

Algebra of scalar fields on the 2-dimensional topological 

manifold M 

sage: TestSuite(f).run() 

 

""" 

CommutativeAlgebraElement.__init__(self, parent) 

domain = parent._domain 

self._domain = domain 

self._manifold = domain.manifold() 

self._is_zero = False # a priori, may be changed below or via 

# method __bool__() 

self._name = name 

if latex_name is None: 

self._latex_name = self._name 

else: 

self._latex_name = latex_name 

self._express = {} # dict of coordinate expressions (ChartFunction 

# instances) with charts as keys 

if coord_expression is not None: 

if isinstance(coord_expression, dict): 

for chart, expression in coord_expression.items(): 

if isinstance(expression, ChartFunction): 

self._express[chart] = expression 

else: 

self._express[chart] = chart.function(expression) 

elif isinstance(coord_expression, ChartFunction): 

self._express[coord_expression.chart()] = coord_expression 

else: 

if chart is None: 

chart = self._domain.default_chart() 

if chart == 'all': 

# coord_expression is the same in all charts (constant 

# scalar field) 

for ch in self._domain.atlas(): 

self._express[ch] = ch.function(coord_expression) 

else: 

self._express[chart] = chart.function(coord_expression) 

self._init_derived() # initialization of derived quantities 

 

####### Required methods for an algebra element (beside arithmetic) ####### 

 

def __bool__(self): 

r""" 

Return ``True`` if ``self`` is nonzero and ``False`` otherwise. 

 

This method is called by :meth:`~sage.structure.element.Element.is_zero()`. 

 

EXAMPLES: 

 

Tests on a 2-dimensional manifold:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x*y) 

sage: f.is_zero() 

False 

sage: f.set_expr(0) 

sage: f.is_zero() 

True 

sage: g = M.scalar_field(0) 

sage: g.is_zero() 

True 

sage: M.zero_scalar_field().is_zero() 

True 

""" 

if self._is_zero: 

return False 

if not self._express: 

# undefined scalar field 

return True 

for funct in itervalues(self._express): 

if not funct.is_zero(): 

self._is_zero = False 

return True 

self._is_zero = True 

return False 

 

__nonzero__ = __bool__ # For Python2 compatibility 

 

def is_trivial_zero(self): 

r""" 

Check if ``self`` is trivially equal to zero without any 

simplification. 

 

This method is supposed to be fast as compared with 

``self.is_zero()`` or ``self == 0`` and is intended to be 

used in library code where trying to obtain a mathematically 

correct result by applying potentially expensive rewrite rules 

is not desirable. 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: 0}) 

sage: f.is_trivial_zero() 

True 

sage: f = M.scalar_field(0) 

sage: f.is_trivial_zero() 

True 

sage: M.zero_scalar_field().is_trivial_zero() 

True 

sage: f = M.scalar_field({X: x+y}) 

sage: f.is_trivial_zero() 

False 

 

Scalar field defined by means of two charts:: 

 

sage: U1 = M.open_subset('U1'); X1.<x1,y1> = U1.chart() 

sage: U2 = M.open_subset('U2'); X2.<x2,y2> = U2.chart() 

sage: f = M.scalar_field({X1: 0, X2: 0}) 

sage: f.is_trivial_zero() 

True 

sage: f = M.scalar_field({X1: 0, X2: 1}) 

sage: f.is_trivial_zero() 

False 

 

No simplification is attempted, so that ``False`` is returned for 

non-trivial cases:: 

 

sage: f = M.scalar_field({X: cos(x)^2 + sin(x)^2 - 1}) 

sage: f.is_trivial_zero() 

False 

 

On the contrary, the method 

:meth:`~sage.structure.element.Element.is_zero` and the direct 

comparison to zero involve some simplification algorithms and 

return ``True``:: 

 

sage: f.is_zero() 

True 

sage: f == 0 

True 

 

""" 

if self._is_zero: 

return True 

return all(func.is_trivial_zero() for func in self._express.values()) 

 

def __eq__(self, other): 

r""" 

Comparison (equality) operator. 

 

INPUT: 

 

- ``other`` -- a scalar field (or something else) 

 

OUTPUT: 

 

- ``True`` if ``self`` is equal to ``other``, ``False`` otherwise 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}) 

sage: f == 1 

False 

sage: f == M.zero_scalar_field() 

False 

sage: g = M.scalar_field({X: x+y}) 

sage: f == g 

True 

sage: h = M.scalar_field({X: 1}) 

sage: h == M.one_scalar_field() 

True 

sage: h == 1 

True 

 

""" 

if other is self: 

return True 

if not isinstance(other, ScalarField): 

# We try a conversion of other to a scalar field, except if 

# other is None (since this would generate an undefined scalar 

# field) 

if other is None: 

return False 

try: 

other = self.parent()(other) # conversion to a scalar field 

except TypeError: 

return False 

if other._domain != self._domain: 

return False 

if other.is_zero(): 

return self.is_zero() 

com_charts = self.common_charts(other) 

if com_charts is None: 

raise ValueError("no common chart for the comparison") 

for chart in com_charts: 

if not (self._express[chart] == other._express[chart]): 

return False 

return True 

 

def __ne__(self, other): 

r""" 

Non-equality operator. 

 

INPUT: 

 

- ``other`` -- a scalar field 

 

OUTPUT: 

 

- ``True`` if ``self`` differs from ``other``, ``False`` otherwise 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}) 

sage: f != 1 

True 

sage: f != M.zero_scalar_field() 

True 

sage: g = M.scalar_field({X: x+y}) 

sage: f != g 

False 

 

""" 

return not (self == other) 

 

####### End of required methods for an algebra element (beside arithmetic) ####### 

 

def _init_derived(self): 

r""" 

Initialize the derived quantities. 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}) 

sage: f._init_derived() 

 

""" 

self._restrictions = {} # dict. of restrictions of self on subsets 

# of self._domain, with the subsets as keys 

 

def _del_derived(self): 

r""" 

Delete the derived quantities. 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}) 

sage: U = M.open_subset('U', coord_def={X: x>0}) 

sage: f.restrict(U) 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M 

sage: f._restrictions 

{Open subset U of the 2-dimensional topological manifold M: 

Scalar field on the Open subset U of the 2-dimensional topological 

manifold M} 

sage: f._del_derived() 

sage: f._restrictions # restrictions are derived quantities 

{} 

 

""" 

self._restrictions.clear() 

 

def _repr_(self): 

r""" 

String representation of the object. 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}) 

sage: f._repr_() 

'Scalar field on the 2-dimensional topological manifold M' 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: f._repr_() 

'Scalar field f on the 2-dimensional topological manifold M' 

sage: f 

Scalar field f on the 2-dimensional topological manifold M 

 

""" 

description = "Scalar field" 

if self._name is not None: 

description += " " + self._name 

description += " on the {}".format(self._domain) 

return description 

 

def _latex_(self): 

r""" 

LaTeX representation of the object. 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}) 

sage: f._latex_() 

'\\mbox{Scalar field on the 2-dimensional topological manifold M}' 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: f._latex_() 

'f' 

sage: f = M.scalar_field({X: x+y}, name='f', latex_name=r'\Phi') 

sage: f._latex_() 

'\\Phi' 

sage: latex(f) 

\Phi 

 

""" 

if self._latex_name is None: 

return r'\mbox{' + str(self) + r'}' 

else: 

return self._latex_name 

 

def set_name(self, name=None, latex_name=None): 

r""" 

Set (or change) the text name and LaTeX name of the scalar field. 

 

INPUT: 

 

- ``name`` -- (string; default: ``None``) name given to the scalar 

field 

- ``latex_name`` -- (string; default: ``None``) LaTeX symbol to denote 

the scalar field; if ``None`` while ``name`` is provided, the LaTeX 

symbol is set to ``name`` 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}) 

sage: f = M.scalar_field({X: x+y}); f 

Scalar field on the 2-dimensional topological manifold M 

sage: f.set_name('f'); f 

Scalar field f on the 2-dimensional topological manifold M 

sage: latex(f) 

f 

sage: f.set_name('f', latex_name=r'\Phi'); f 

Scalar field f on the 2-dimensional topological manifold M 

sage: latex(f) 

\Phi 

 

""" 

if name is not None: 

self._name = name 

if latex_name is None: 

self._latex_name = self._name 

if latex_name is not None: 

self._latex_name = latex_name 

 

def domain(self): 

r""" 

Return the open subset on which the scalar field is defined. 

 

OUTPUT: 

 

- instance of class 

:class:`~sage.manifolds.manifold.TopologicalManifold` 

representing the manifold's open subset on which the 

scalar field is defined 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x+2*y) 

sage: f.domain() 

2-dimensional topological manifold M 

sage: U = M.open_subset('U', coord_def={c_xy: x<0}) 

sage: g = f.restrict(U) 

sage: g.domain() 

Open subset U of the 2-dimensional topological manifold M 

 

""" 

return self._domain 

 

def copy(self): 

r""" 

Return an exact copy of the scalar field. 

 

EXAMPLES: 

 

Copy on a 2-dimensional manifold:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x*y^2) 

sage: g = f.copy() 

sage: type(g) 

<class 'sage.manifolds.scalarfield_algebra.ScalarFieldAlgebra_with_category.element_class'> 

sage: g.expr() 

x*y^2 

sage: g == f 

True 

sage: g is f 

False 

 

""" 

result = type(self)(self.parent(), name=self._name, 

latex_name=self._latex_name) 

for chart, funct in self._express.items(): 

result._express[chart] = funct.copy() 

return result 

 

def coord_function(self, chart=None, from_chart=None): 

r""" 

Return the function of the coordinates representing the scalar field 

in a given chart. 

 

INPUT: 

 

- ``chart`` -- (default: ``None``) chart with respect to which the 

coordinate expression is to be returned; if ``None``, the 

default chart of the scalar field's domain will be used 

- ``from_chart`` -- (default: ``None``) chart from which the 

required expression is computed if it is not known already in the 

chart ``chart``; if ``None``, a chart is picked in the known 

expressions 

 

OUTPUT: 

 

- instance of :class:`~sage.manifolds.chart_func.ChartFunction` 

representing the coordinate function of the scalar field in the 

given chart 

 

EXAMPLES: 

 

Coordinate function on a 2-dimensional manifold:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x*y^2) 

sage: f.coord_function() 

x*y^2 

sage: f.coord_function(c_xy) # equivalent form (since c_xy is the default chart) 

x*y^2 

sage: type(f.coord_function()) 

<class 'sage.manifolds.chart_func.ChartFunctionRing_with_category.element_class'> 

 

Expression via a change of coordinates:: 

 

sage: c_uv.<u,v> = M.chart() 

sage: c_uv.transition_map(c_xy, [u+v, u-v]) 

Change of coordinates from Chart (M, (u, v)) to Chart (M, (x, y)) 

sage: f._express # at this stage, f is expressed only in terms of (x,y) coordinates 

{Chart (M, (x, y)): x*y^2} 

sage: f.coord_function(c_uv) # forces the computation of the expression of f in terms of (u,v) coordinates 

u^3 - u^2*v - u*v^2 + v^3 

sage: f.coord_function(c_uv) == (u+v)*(u-v)^2 # check 

True 

sage: f._express # random (dict. output); f has now 2 coordinate expressions: 

{Chart (M, (x, y)): x*y^2, Chart (M, (u, v)): u^3 - u^2*v - u*v^2 + v^3} 

 

Usage in a physical context (simple Lorentz transformation - boost in 

``x`` direction, with relative velocity ``v`` between ``o1`` 

and ``o2`` frames):: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: o1.<t,x> = M.chart() 

sage: o2.<T,X> = M.chart() 

sage: f = M.scalar_field(x^2 - t^2) 

sage: f.coord_function(o1) 

-t^2 + x^2 

sage: v = var('v'); gam = 1/sqrt(1-v^2) 

sage: o2.transition_map(o1, [gam*(T - v*X), gam*(X - v*T)]) 

Change of coordinates from Chart (M, (T, X)) to Chart (M, (t, x)) 

sage: f.coord_function(o2) 

-T^2 + X^2 

 

""" 

if chart is None: 

chart = self._domain._def_chart 

else: 

if chart not in self._domain._atlas: 

raise ValueError("the {} is not a chart ".format(chart) + 

"defined on the {}".format(self._domain)) 

if chart not in self._express: 

# Check whether chart corresponds to a subchart of a chart 

# where the expression of self is known: 

for known_chart in self._express: 

if chart in known_chart._subcharts: 

new_expr = self._express[known_chart].expr() 

self._express[chart] = chart.function(new_expr) 

return self._express[chart] 

# If this point is reached, the expression must be computed 

# from that in the chart from_chart, by means of a 

# change-of-coordinates formula: 

if from_chart is None: 

# from_chart in searched among the charts of known expressions 

# and subcharts of them 

known_express = self._express.copy() 

found = False 

for kchart in known_express: 

for skchart in kchart._subcharts: 

if (chart, skchart) in self._domain._coord_changes: 

from_chart = skchart 

found = True 

if skchart not in self._express: 

self._express[skchart] = skchart.function( 

self._express[kchart].expr()) 

break 

if found: 

break 

if not found: 

raise ValueError("no starting chart could be found to " + 

"compute the expression in the {}".format(chart)) 

change = self._domain._coord_changes[(chart, from_chart)] 

# old coordinates expressed in terms of the new ones: 

coords = [ change._transf._functions[i].expr() 

for i in range(self._manifold.dim()) ] 

new_expr = self._express[from_chart](*coords) 

self._express[chart] = chart.function(new_expr) 

self._del_derived() 

return self._express[chart] 

 

def function_chart(self, chart=None, from_chart=None): 

r""" 

Deprecated. 

 

Use :meth:`coord_function` instead. 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x*y^2) 

sage: fc = f.function_chart() 

doctest:...: DeprecationWarning: Use coord_function() instead. 

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

sage: fc 

x*y^2 

 

""" 

from sage.misc.superseded import deprecation 

deprecation(18640, 'Use coord_function() instead.') 

return self.coord_function(chart=chart, from_chart=from_chart) 

 

def expr(self, chart=None, from_chart=None): 

r""" 

Return the coordinate expression of the scalar field in a given 

chart. 

 

INPUT: 

 

- ``chart`` -- (default: ``None``) chart with respect to which the 

coordinate expression is required; if ``None``, the default 

chart of the scalar field's domain will be used 

- ``from_chart`` -- (default: ``None``) chart from which the 

required expression is computed if it is not known already in the 

chart ``chart``; if ``None``, a chart is picked in ``self._express`` 

 

OUTPUT: 

 

- symbolic expression representing the coordinate 

expression of the scalar field in the given chart. 

 

EXAMPLES: 

 

Expression of a scalar field on a 2-dimensional manifold:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x*y^2) 

sage: f.expr() 

x*y^2 

sage: f.expr(c_xy) # equivalent form (since c_xy is the default chart) 

x*y^2 

sage: type(f.expr()) 

<type 'sage.symbolic.expression.Expression'> 

 

Expression via a change of coordinates:: 

 

sage: c_uv.<u,v> = M.chart() 

sage: c_uv.transition_map(c_xy, [u+v, u-v]) 

Change of coordinates from Chart (M, (u, v)) to Chart (M, (x, y)) 

sage: f._express # at this stage, f is expressed only in terms of (x,y) coordinates 

{Chart (M, (x, y)): x*y^2} 

sage: f.expr(c_uv) # forces the computation of the expression of f in terms of (u,v) coordinates 

u^3 - u^2*v - u*v^2 + v^3 

sage: bool( f.expr(c_uv) == (u+v)*(u-v)^2 ) # check 

True 

sage: f._express # random (dict. output); f has now 2 coordinate expressions: 

{Chart (M, (x, y)): x*y^2, Chart (M, (u, v)): u^3 - u^2*v - u*v^2 + v^3} 

 

""" 

return self.coord_function(chart, from_chart).expr() 

 

def set_expr(self, coord_expression, chart=None): 

r""" 

Set the coordinate expression of the scalar field. 

 

The expressions with respect to other charts are deleted, in order to 

avoid any inconsistency. To keep them, use :meth:`add_expr` instead. 

 

INPUT: 

 

- ``coord_expression`` -- coordinate expression of the scalar field 

- ``chart`` -- (default: ``None``) chart in which ``coord_expression`` 

is defined; if ``None``, the default chart of the scalar field's 

domain is assumed 

 

EXAMPLES: 

 

Setting scalar field expressions on a 2-dimensional manifold:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x^2 + 2*x*y +1) 

sage: f._express 

{Chart (M, (x, y)): x^2 + 2*x*y + 1} 

sage: f.set_expr(3*y) 

sage: f._express # the (x,y) expression has been changed: 

{Chart (M, (x, y)): 3*y} 

sage: c_uv.<u,v> = M.chart() 

sage: f.set_expr(cos(u)-sin(v), c_uv) 

sage: f._express # the (x,y) expression has been lost: 

{Chart (M, (u, v)): cos(u) - sin(v)} 

sage: f.set_expr(3*y) 

sage: f._express # the (u,v) expression has been lost: 

{Chart (M, (x, y)): 3*y} 

 

""" 

if chart is None: 

chart = self._domain._def_chart 

self._is_zero = False # a priori 

self._express.clear() 

self._express[chart] = chart.function(coord_expression) 

self._del_derived() 

 

def add_expr(self, coord_expression, chart=None): 

r""" 

Add some coordinate expression to the scalar field. 

 

The previous expressions with respect to other charts are kept. To 

clear them, use :meth:`set_expr` instead. 

 

INPUT: 

 

- ``coord_expression`` -- coordinate expression of the scalar field 

- ``chart`` -- (default: ``None``) chart in which ``coord_expression`` 

is defined; if ``None``, the default chart of the scalar field's 

domain is assumed 

 

.. WARNING:: 

 

If the scalar field has already expressions in other charts, it 

is the user's responsibility to make sure that the expression 

to be added is consistent with them. 

 

EXAMPLES: 

 

Adding scalar field expressions on a 2-dimensional manifold:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(x^2 + 2*x*y +1) 

sage: f._express 

{Chart (M, (x, y)): x^2 + 2*x*y + 1} 

sage: f.add_expr(3*y) 

sage: f._express # the (x,y) expression has been changed: 

{Chart (M, (x, y)): 3*y} 

sage: c_uv.<u,v> = M.chart() 

sage: f.add_expr(cos(u)-sin(v), c_uv) 

sage: f._express # random (dict. output); f has now 2 expressions: 

{Chart (M, (x, y)): 3*y, Chart (M, (u, v)): cos(u) - sin(v)} 

 

""" 

if chart is None: 

chart = self._domain._def_chart 

self._express[chart] = chart.function(coord_expression) 

self._is_zero = False # a priori 

self._del_derived() 

 

def add_expr_by_continuation(self, chart, subdomain): 

r""" 

Set coordinate expression in a chart by continuation of the 

coordinate expression in a subchart. 

 

The continuation is performed by demanding that the coordinate 

expression is identical to that in the restriction of the chart to 

a given subdomain. 

 

INPUT: 

 

- ``chart`` -- coordinate chart `(U,(x^i))` in which the expression of 

the scalar field is to set 

- ``subdomain`` -- open subset `V\subset U` in which the expression 

in terms of the restriction of the coordinate chart `(U,(x^i))` to 

`V` is already known or can be evaluated by a change of coordinates. 

 

EXAMPLES: 

 

Scalar field on the sphere `S^2`:: 

 

sage: M = Manifold(2, 'S^2', structure='topological') 

sage: U = M.open_subset('U') ; V = M.open_subset('V') # the complement of resp. N pole and S pole 

sage: M.declare_union(U,V) # S^2 is the union of U and V 

sage: c_xy.<x,y> = U.chart() ; c_uv.<u,v> = V.chart() # stereographic coordinates 

sage: xy_to_uv = c_xy.transition_map(c_uv, (x/(x^2+y^2), y/(x^2+y^2)), 

....: intersection_name='W', restrictions1= x^2+y^2!=0, 

....: restrictions2= u^2+v^2!=0) 

sage: uv_to_xy = xy_to_uv.inverse() 

sage: W = U.intersection(V) # S^2 minus the two poles 

sage: f = M.scalar_field(atan(x^2+y^2), chart=c_xy, name='f') 

 

The scalar field has been defined only on the domain covered by the 

chart ``c_xy``, i.e. `U`:: 

 

sage: f.display() 

f: S^2 --> R 

on U: (x, y) |--> arctan(x^2 + y^2) 

 

We note that on `W = U \cap V`, the expression of `f` in terms of 

coordinates `(u,v)` can be deduced from that in the coordinates 

`(x,y)` thanks to the transition map between the two charts:: 

 

sage: f.display(c_uv.restrict(W)) 

f: S^2 --> R 

on W: (u, v) |--> arctan(1/(u^2 + v^2)) 

 

We use this fact to extend the definition of `f` to the open 

subset `V`, covered by the chart ``c_uv``:: 

 

sage: f.add_expr_by_continuation(c_uv, W) 

 

Then, `f` is known on the whole sphere:: 

 

sage: f.display() 

f: S^2 --> R 

on U: (x, y) |--> arctan(x^2 + y^2) 

on V: (u, v) |--> arctan(1/(u^2 + v^2)) 

 

""" 

if not chart._domain.is_subset(self._domain): 

raise ValueError("the chart is not defined on a subset of " + 

"the scalar field domain") 

schart = chart.restrict(subdomain) 

self._express[chart] = chart.function(self.expr(schart)) 

self._is_zero = False # a priori 

self._del_derived() 

 

def display(self, chart=None): 

r""" 

Display the expression of the scalar field in a given chart. 

 

Without any argument, this function displays the expressions of the 

scalar field in all the charts defined on the scalar field's domain 

that are not restrictions of another chart to some subdomain 

(the "top charts"). 

 

INPUT: 

 

- ``chart`` -- (default: ``None``) chart with respect to which 

the coordinate expression is to be displayed; if ``None``, the 

display is performed in all the top charts in which the 

coordinate expression is known 

 

The output is either text-formatted (console mode) or LaTeX-formatted 

(notebook mode). 

 

EXAMPLES: 

 

Various displays:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: c_xy.<x,y> = M.chart() 

sage: f = M.scalar_field(sqrt(x+1), name='f') 

sage: f.display() 

f: M --> R 

(x, y) |--> sqrt(x + 1) 

sage: latex(f.display()) 

\begin{array}{llcl} f:& M & \longrightarrow & \mathbb{R} \\ & \left(x, y\right) & \longmapsto & \sqrt{x + 1} \end{array} 

sage: g = M.scalar_field(function('G')(x, y), name='g') 

sage: g.display() 

g: M --> R 

(x, y) |--> G(x, y) 

sage: latex(g.display()) 

\begin{array}{llcl} g:& M & \longrightarrow & \mathbb{R} \\ & \left(x, y\right) & \longmapsto & G\left(x, y\right) \end{array} 

 

A shortcut of ``display()`` is ``disp()``:: 

 

sage: f.disp() 

f: M --> R 

(x, y) |--> sqrt(x + 1) 

 

""" 

from sage.misc.latex import latex 

from sage.tensor.modules.format_utilities import FormattedExpansion 

 

def _display_expression(self, chart, result): 

r""" 

Helper function for :meth:`display`. 

""" 

try: 

expression = self.coord_function(chart) 

coords = chart[:] 

if len(coords) == 1: 

coords = coords[0] 

if chart._domain == self._domain: 

if self._name is not None: 

result._txt += " " 

result._latex += " & " 

else: 

result._txt += "on " + chart._domain._name + ": " 

result._latex += r"\mbox{on}\ " + latex(chart._domain) + \ 

r": & " 

result._txt += repr(coords) + " |--> " + repr(expression) + "\n" 

result._latex += latex(coords) + r"& \longmapsto & " + \ 

latex(expression) + r"\\" 

except (TypeError, ValueError): 

pass 

 

# Name of the base field: 

field = self._domain.base_field() 

field_type = self._domain.base_field_type() 

if field_type == 'real': 

field_name = 'R' 

field_latex_name = r'\mathbb{R}' 

elif field_type == 'complex': 

field_name = 'C' 

field_latex_name = r'\mathbb{C}' 

else: 

field_name = str(field) 

field_latex_name = latex(field) 

# 

result = FormattedExpansion() 

if self._name is None: 

symbol = "" 

else: 

symbol = self._name + ": " 

result._txt = symbol + self._domain._name + " --> " + field_name + "\n" 

if self._latex_name is None: 

symbol = "" 

else: 

symbol = self._latex_name + ":" 

result._latex = r"\begin{array}{llcl} " + symbol + r"&" + \ 

latex(self._domain) + r"& \longrightarrow & " + \ 

field_latex_name + r" \\" 

if chart is None: 

for ch in self._domain._top_charts: 

_display_expression(self, ch, result) 

else: 

_display_expression(self, chart, result) 

result._txt = result._txt[:-1] 

result._latex = result._latex[:-2] + r"\end{array}" 

return result 

 

disp = display 

 

def restrict(self, subdomain): 

r""" 

Restriction of the scalar field to an open subset of its domain of 

definition. 

 

INPUT: 

 

- ``subdomain`` -- an open subset of the scalar field's domain 

 

OUTPUT: 

 

- instance of :class:`ScalarField` representing the restriction of 

the scalar field to ``subdomain`` 

 

EXAMPLES: 

 

Restriction of a scalar field defined on `\RR^2` to the 

unit open disc:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() # Cartesian coordinates 

sage: U = M.open_subset('U', coord_def={X: x^2+y^2 < 1}) # U unit open disc 

sage: f = M.scalar_field(cos(x*y), name='f') 

sage: f_U = f.restrict(U) ; f_U 

Scalar field f on the Open subset U of the 2-dimensional 

topological manifold M 

sage: f_U.display() 

f: U --> R 

(x, y) |--> cos(x*y) 

sage: f.parent() 

Algebra of scalar fields on the 2-dimensional topological 

manifold M 

sage: f_U.parent() 

Algebra of scalar fields on the Open subset U of the 2-dimensional 

topological manifold M 

 

The restriction to the whole domain is the identity:: 

 

sage: f.restrict(M) is f 

True 

sage: f_U.restrict(U) is f_U 

True 

 

Restriction of the zero scalar field:: 

 

sage: M.zero_scalar_field().restrict(U) 

Scalar field zero on the Open subset U of the 2-dimensional 

topological manifold M 

sage: M.zero_scalar_field().restrict(U) is U.zero_scalar_field() 

True 

 

""" 

if subdomain == self._domain: 

return self 

if subdomain not in self._restrictions: 

if not subdomain.is_subset(self._domain): 

raise ValueError("the specified domain is not a subset of " + 

"the domain of definition of the scalar field") 

# Special case of the zero scalar field: 

if self._is_zero: 

return subdomain._zero_scalar_field 

# First one tries to get the restriction from a tighter domain: 

for dom, rst in self._restrictions.items(): 

if subdomain.is_subset(dom): 

self._restrictions[subdomain] = rst.restrict(subdomain) 

break 

else: 

# If this fails, the restriction is obtained via coercion 

resu = subdomain.scalar_field_algebra()(self) 

resu._name = self._name 

resu._latex_name = self._latex_name 

self._restrictions[subdomain] = resu 

return self._restrictions[subdomain] 

 

def common_charts(self, other): 

r""" 

Find common charts for the expressions of the scalar field and 

``other``. 

 

INPUT: 

 

- ``other`` -- a scalar field 

 

OUTPUT: 

 

- list of common charts; if no common chart is found, ``None`` is 

returned (instead of an empty list) 

 

EXAMPLES: 

 

Search for common charts on a 2-dimensional manifold with 2 

overlapping domains:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: U = M.open_subset('U') 

sage: c_xy.<x,y> = U.chart() 

sage: V = M.open_subset('V') 

sage: c_uv.<u,v> = V.chart() 

sage: M.declare_union(U,V) # M is the union of U and V 

sage: f = U.scalar_field(x^2) 

sage: g = M.scalar_field(x+y) 

sage: f.common_charts(g) 

[Chart (U, (x, y))] 

sage: g.add_expr(u, c_uv) 

sage: f._express 

{Chart (U, (x, y)): x^2} 

sage: g._express # random (dictionary output) 

{Chart (U, (x, y)): x + y, Chart (V, (u, v)): u} 

sage: f.common_charts(g) 

[Chart (U, (x, y))] 

 

Common charts found as subcharts: the subcharts are introduced via 

a transition map between charts c_xy and c_uv on the intersecting 

subdomain `W = U\cap V`:: 

 

sage: trans = c_xy.transition_map(c_uv, (x+y, x-y), 'W', x<0, u+v<0) 

sage: M.atlas() 

[Chart (U, (x, y)), Chart (V, (u, v)), Chart (W, (x, y)), 

Chart (W, (u, v))] 

sage: c_xy_W = M.atlas()[2] 

sage: c_uv_W = M.atlas()[3] 

sage: trans.inverse() 

Change of coordinates from Chart (W, (u, v)) to Chart (W, (x, y)) 

sage: f.common_charts(g) 

[Chart (U, (x, y))] 

sage: f.expr(c_xy_W) 

x^2 

sage: f._express # random (dictionary output) 

{Chart (U, (x, y)): x^2, Chart (W, (x, y)): x^2} 

sage: g._express # random (dictionary output) 

{Chart (U, (x, y)): x + y, Chart (V, (u, v)): u} 

sage: g.common_charts(f) # c_xy_W is not returned because it is subchart of 'xy' 

[Chart (U, (x, y))] 

sage: f.expr(c_uv_W) 

1/4*u^2 + 1/2*u*v + 1/4*v^2 

sage: f._express # random (dictionary output) 

{Chart (U, (x, y)): x^2, Chart (W, (x, y)): x^2, 

Chart (W, (u, v)): 1/4*u^2 + 1/2*u*v + 1/4*v^2} 

sage: g._express # random (dictionary output) 

{Chart (U, (x, y)): x + y, Chart (V, (u, v)): u} 

sage: f.common_charts(g) 

[Chart (U, (x, y)), Chart (W, (u, v))] 

sage: # the expressions have been updated on the subcharts 

sage: g._express # random (dictionary output) 

{Chart (U, (x, y)): x + y, Chart (V, (u, v)): u, 

Chart (W, (u, v)): u} 

 

Common charts found by computing some coordinate changes:: 

 

sage: W = U.intersection(V) 

sage: f = W.scalar_field(x^2, c_xy_W) 

sage: g = W.scalar_field(u+1, c_uv_W) 

sage: f._express 

{Chart (W, (x, y)): x^2} 

sage: g._express 

{Chart (W, (u, v)): u + 1} 

sage: f.common_charts(g) 

[Chart (W, (u, v)), Chart (W, (x, y))] 

sage: f._express # random (dictionary output) 

{Chart (W, (u, v)): 1/4*u^2 + 1/2*u*v + 1/4*v^2, 

Chart (W, (x, y)): x^2} 

sage: g._express # random (dictionary output) 

{Chart (W, (u, v)): u + 1, Chart (W, (x, y)): x + y + 1} 

 

""" 

if not isinstance(other, ScalarField): 

raise TypeError("the second argument must be a scalar field") 

coord_changes = self._manifold._coord_changes 

resu = [] 

# 

# 1/ Search for common charts among the existing expressions, i.e. 

# without performing any expression transformation. 

# ------------------------------------------------------------- 

for chart1 in self._express: 

if chart1 in other._express: 

resu.append(chart1) 

# Search for a subchart: 

known_expr1 = self._express.copy() 

known_expr2 = other._express.copy() 

for chart1 in known_expr1: 

if chart1 not in resu: 

for chart2 in known_expr2: 

if chart2 not in resu: 

if chart2 in chart1._subcharts: 

self.expr(chart2) 

resu.append(chart2) 

if chart1 in chart2._subcharts: 

other.expr(chart1) 

resu.append(chart1) 

# 

# 2/ Search for common charts via one expression transformation 

# ---------------------------------------------------------- 

for chart1 in known_expr1: 

if chart1 not in resu: 

for chart2 in known_expr2: 

if chart2 not in resu: 

if (chart1, chart2) in coord_changes: 

self.coord_function(chart2, from_chart=chart1) 

resu.append(chart2) 

if (chart2, chart1) in coord_changes: 

other.coord_function(chart1, from_chart=chart2) 

resu.append(chart1) 

if resu == []: 

return None 

else: 

return resu 

 

def __call__(self, p, chart=None): 

r""" 

Compute the value of the scalar field at a given point. 

 

INPUT: 

 

- ``p`` -- point in the scalar field's domain 

- ``chart`` -- (default: ``None``) chart in which the coordinates 

of ``p`` are to be considered; if ``None``, a chart in which 

both ``p``'s coordinates and the expression of the scalar field 

are known is searched, starting from the default chart 

of ``self._domain`` 

 

OUTPUT: 

 

- value at ``p`` 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: p = M((2,-5), name='p'); p 

Point p on the 2-dimensional topological manifold M 

sage: f.__call__(p) 

-3 

sage: f(p) 

-3 

sage: M.zero_scalar_field()(p) 

0 

sage: M.one_scalar_field()(p) 

1 

 

Example with a change of chart:: 

 

sage: Y.<u,v> = M.chart() 

sage: X_to_Y = X.transition_map(Y, [x+y, x-y]) 

sage: Y_to_X = X_to_Y.inverse() 

sage: g = M.scalar_field({Y: u*v}, name='g') 

sage: g(p) 

-21 

sage: p.coord(Y) 

(-3, 7) 

 

""" 

#!# it should be "if p not in self_domain:" instead, but this test is 

# skipped for efficiency 

if p not in self._manifold: 

raise ValueError("the {} ".format(p) + "does not belong " + 

"to the {}".format(self._manifold)) 

if self._is_zero: 

return 0 

if chart is None: 

# A common chart is searched: 

def_chart = self._domain._def_chart 

if def_chart in p._coordinates and def_chart in self._express: 

chart = def_chart 

else: 

for chart_p in p._coordinates: 

if chart_p in self._express: 

chart = chart_p 

break 

if chart is None: 

# A change of coordinates is attempted for p: 

for chart_s in self._express: 

try: 

p.coord(chart_s) 

chart = chart_s 

break 

except ValueError: 

pass 

else: 

# A change of coordinates is attempted on the scalar field 

# expressions: 

for chart_p in p._coordinates: 

try: 

self.coord_function(chart_p) 

chart = chart_p 

break 

except (TypeError, ValueError): 

pass 

if chart is None: 

raise ValueError("no common chart has been found to evaluate " + 

"the action of {} on the {}".format(self, p)) 

return self._express[chart](*(p._coordinates[chart])) 

 

def __pos__(self): 

r""" 

Unary plus operator. 

 

OUTPUT: 

 

- an exact copy of the scalar field 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: g = f.__pos__(); g 

Scalar field +f on the 2-dimensional topological manifold M 

sage: g == f 

True 

 

""" 

result = type(self)(self.parent()) 

for chart in self._express: 

result._express[chart] = + self._express[chart] 

if self._name is not None: 

result._name = '+' + self._name 

if self._latex_name is not None: 

result._latex_name = '+' + self._latex_name 

return result 

 

def __neg__(self): 

r""" 

Unary minus operator. 

 

OUTPUT: 

 

- the negative of the scalar field 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: g = f.__neg__(); g 

Scalar field -f on the 2-dimensional topological manifold M 

sage: g.display() 

-f: M --> R 

(x, y) |--> -x - y 

sage: g.__neg__() == f 

True 

 

""" 

result = type(self)(self.parent()) 

for chart in self._express: 

result._express[chart] = - self._express[chart] 

if self._name is not None: 

result._name = '-' + self._name 

if self._latex_name is not None: 

result._latex_name = '-' + self._latex_name 

return result 

 

 

######### CommutativeAlgebraElement arithmetic operators ######## 

 

def _add_(self, other): 

r""" 

Scalar field addition. 

 

INPUT: 

 

- ``other`` -- a scalar field (in the same algebra as ``self``) 

 

OUTPUT: 

 

- the scalar field resulting from the addition of ``self`` and 

``other`` 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: g = M.scalar_field({X: x*y}, name='g') 

sage: s = f._add_(g); s 

Scalar field f+g on the 2-dimensional topological manifold M 

sage: s.display() 

f+g: M --> R 

(x, y) |--> (x + 1)*y + x 

sage: s == f+g 

True 

sage: f._add_(M.zero_scalar_field()) == f 

True 

 

""" 

# Special cases: 

if self._is_zero: 

return other.copy() 

if other._is_zero: 

return self.copy() 

# Generic case: 

com_charts = self.common_charts(other) 

if com_charts is None: 

raise ValueError("no common chart for the addition") 

result = type(self)(self.parent()) 

for chart in com_charts: 

# ChartFunction addition: 

result._express[chart] = self._express[chart] + other._express[chart] 

if self._name is not None and other._name is not None: 

result._name = self._name + '+' + other._name 

if self._latex_name is not None and other._latex_name is not None: 

result._latex_name = self._latex_name + '+' + other._latex_name 

return result 

 

def _sub_(self, other): 

r""" 

Scalar field subtraction. 

 

INPUT: 

 

- ``other`` -- a scalar field (in the same algebra as ``self``) 

 

OUTPUT: 

 

- the scalar field resulting from the subtraction of ``other`` from 

``self`` 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: g = M.scalar_field({X: x*y}, name='g') 

sage: s = f._sub_(g); s 

Scalar field f-g on the 2-dimensional topological manifold M 

sage: s.display() 

f-g: M --> R 

(x, y) |--> -(x - 1)*y + x 

sage: s == f-g 

True 

sage: f._sub_(M.zero_scalar_field()) == f 

True 

 

""" 

# Special cases: 

if self._is_zero: 

return -other 

if other._is_zero: 

return self.copy() 

# Generic case: 

com_charts = self.common_charts(other) 

if com_charts is None: 

raise ValueError("no common chart for the subtraction") 

result = type(self)(self.parent()) 

for chart in com_charts: 

# ChartFunction subtraction: 

result._express[chart] = self._express[chart] - other._express[chart] 

if self._name is not None and other._name is not None: 

result._name = self._name + '-' + other._name 

if self._latex_name is not None and other._latex_name is not None: 

result._latex_name = self._latex_name + '-' + other._latex_name 

return result 

 

 

def _mul_(self, other): 

r""" 

Scalar field multiplication. 

 

INPUT: 

 

- ``other`` -- a scalar field (in the same algebra as ``self``) 

 

OUTPUT: 

 

- the scalar field resulting from the multiplication of ``self`` by 

``other`` 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: g = M.scalar_field({X: x*y}, name='g') 

sage: s = f._mul_(g); s 

Scalar field f*g on the 2-dimensional topological manifold M 

sage: s.display() 

f*g: M --> R 

(x, y) |--> x^2*y + x*y^2 

sage: s == f*g 

True 

sage: f._mul_(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

sage: f._mul_(M.one_scalar_field()) == f 

True 

 

""" 

from sage.tensor.modules.format_utilities import format_mul_txt, \ 

format_mul_latex 

# Special cases: 

if self._is_zero or other._is_zero: 

return self._domain.zero_scalar_field() 

# Generic case: 

com_charts = self.common_charts(other) 

if com_charts is None: 

raise ValueError("no common chart for the multiplication") 

result = type(self)(self.parent()) 

for chart in com_charts: 

# ChartFunction multiplication: 

result._express[chart] = self._express[chart] * other._express[chart] 

result._name = format_mul_txt(self._name, '*', other._name) 

result._latex_name = format_mul_latex(self._latex_name, ' ', 

other._latex_name) 

return result 

 

def _div_(self, other): 

r""" 

Scalar field division. 

 

INPUT: 

 

- ``other`` -- a scalar field (in the same algebra as self) 

 

OUTPUT: 

 

- the scalar field resulting from the division of ``self`` by 

``other`` 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: g = M.scalar_field({X: x*y}, name='g') 

sage: s = f._div_(g); s 

Scalar field f/g on the 2-dimensional topological manifold M 

sage: s.display() 

f/g: M --> R 

(x, y) |--> (x + y)/(x*y) 

sage: s == f/g 

True 

sage: f._div_(M.zero_scalar_field()) 

Traceback (most recent call last): 

... 

ZeroDivisionError: division of a scalar field by zero 

 

""" 

from sage.tensor.modules.format_utilities import format_mul_txt, \ 

format_mul_latex 

# Special cases: 

if other._is_zero: 

raise ZeroDivisionError("division of a scalar field by zero") 

if self._is_zero: 

return self._domain.zero_scalar_field() 

# Generic case: 

com_charts = self.common_charts(other) 

if com_charts is None: 

raise ValueError("no common chart for the division") 

result = type(self)(self.parent()) 

for chart in com_charts: 

# ChartFunction division: 

result._express[chart] = self._express[chart] / other._express[chart] 

result._name = format_mul_txt(self._name, '/', other._name) 

result._latex_name = format_mul_latex(self._latex_name, '/', 

other._latex_name) 

return result 

 

def _lmul_(self, number): 

r""" 

Scalar multiplication operator: return ``number * self`` or 

``self * number``. 

 

This differs from ``_mul_(self, other)`` by the fact that ``number`` 

is not assumed to be a scalar field defined on the same domain as 

``self``, contrary to ``other`` in ``_mul_(self, other)``. In 

practice, ``number`` is a an element of the field on which the 

scalar field algebra is defined. 

 

INPUT: 

 

- ``number`` -- an element of the ring on which the scalar field 

algebra is defined; this should be an element of the topological 

field on which the manifold is constructed (possibly represented 

by a symbolic expression) 

 

OUTPUT: 

 

- the scalar field ``number * self`` 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f') 

sage: s = f._lmul_(2); s 

Scalar field on the 2-dimensional topological manifold M 

sage: s.display() 

M --> R 

(x, y) |--> 2*x + 2*y 

sage: s == 2 * f 

True 

sage: s == f * 2 

True 

sage: f._lmul_(pi).display() 

M --> R 

(x, y) |--> pi*(x + y) 

sage: f._lmul_(pi) == pi*f 

True 

sage: f._lmul_(0) == M.zero_scalar_field() 

True 

sage: f._lmul_(1) == f 

True 

 

""" 

if number == 0: 

return self.parent().zero() 

result = type(self)(self.parent()) 

if isinstance(number, Expression): 

var = number.variables() # possible symbolic variables in number 

if var: 

# There are symbolic variables in number 

# Are any of them a chart coordinate ? 

chart_var = False 

for chart in self._express: 

if any(s in chart[:] for s in var): 

chart_var = True 

break 

if chart_var: 

# Some symbolic variables in number are chart coordinates 

for chart, expr in self._express.items(): 

# The multiplication is performed only if 

# either 

# (i) all the symbolic variables in number are 

# coordinates of this chart 

# or (ii) no symbolic variable in number belongs to a 

# different chart 

chart_coords = chart[:] 

var_not_in_chart = [s for s in var 

if not s in chart_coords] 

any_in_other_chart = False 

if var_not_in_chart != []: 

for other_chart in self._domain.atlas(): 

other_chart_coords = other_chart[:] 

for s in var_not_in_chart: 

if s in other_chart_coords: 

any_in_other_chart = True 

break 

if any_in_other_chart: 

break 

if not any_in_other_chart: 

result._express[chart] = number * expr 

return result 

# General case: the multiplication is performed on all charts: 

for chart, expr in self._express.items(): 

result._express[chart] = number * expr 

return result 

 

######### End of CommutativeAlgebraElement arithmetic operators ######## 

 

def _function_name(self, func, func_latex, parentheses=True): 

r""" 

Helper function to set the symbol of a function applied to the 

scalar field. 

 

TESTS:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f', latex_name=r"\Phi") 

sage: f._function_name("cos", r"\cos") 

('cos(f)', '\\cos\\left(\\Phi\\right)') 

sage: f._function_name("sqrt", r"\sqrt", parentheses=False) 

('sqrt(f)', '\\sqrt{\\Phi}') 

sage: f = M.scalar_field({X: x+y}) # no name given to f 

sage: f._function_name("cos", r"\cos") 

(None, None) 

 

""" 

if self._name is None: 

name = None 

else: 

name = func + "(" + self._name + ")" 

if self._latex_name is None: 

latex_name = None 

else: 

if parentheses: 

latex_name = func_latex + r"\left(" + self._latex_name + \ 

r"\right)" 

else: 

latex_name = func_latex + r"{" + self._latex_name + r"}" 

return name, latex_name 

 

def exp(self): 

r""" 

Exponential of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\exp f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f', latex_name=r"\Phi") 

sage: g = exp(f) ; g 

Scalar field exp(f) on the 2-dimensional topological manifold M 

sage: g.display() 

exp(f): M --> R 

(x, y) |--> e^(x + y) 

sage: latex(g) 

\exp\left(\Phi\right) 

 

Automatic simplifications occur:: 

 

sage: f = M.scalar_field({X: 2*ln(1+x^2)}, name='f') 

sage: exp(f).display() 

exp(f): M --> R 

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

 

The inverse function is :meth:`log`:: 

 

sage: log(exp(f)) == f 

True 

 

Some tests:: 

 

sage: exp(M.zero_scalar_field()) == M.constant_scalar_field(1) 

True 

sage: exp(M.constant_scalar_field(1)) == M.constant_scalar_field(e) 

True 

 

""" 

name, latex_name = self._function_name("exp", r"\exp") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.exp() 

return resu 

 

def log(self): 

r""" 

Natural logarithm of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\ln f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f', latex_name=r"\Phi") 

sage: g = log(f) ; g 

Scalar field ln(f) on the 2-dimensional topological manifold M 

sage: g.display() 

ln(f): M --> R 

(x, y) |--> log(x + y) 

sage: latex(g) 

\ln\left(\Phi\right) 

 

The inverse function is :meth:`exp`:: 

 

sage: exp(log(f)) == f 

True 

 

""" 

name, latex_name = self._function_name("ln", r"\ln") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.log() 

return resu 

 

def __pow__(self, exponent): 

r""" 

The scalar field to a given power. 

 

INPUT: 

 

- ``exponent`` -- the exponent 

 

OUTPUT: 

 

- the scalar field `f^a`, where `f` is the current scalar field and 

`a` the exponent 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x+y}, name='f', latex_name=r'\Phi') 

sage: g = f.__pow__(pi) ; g 

Scalar field f^pi on the 2-dimensional topological manifold M 

sage: latex(g) 

{\Phi}^{ \pi } 

sage: g.display() 

f^pi: M --> R 

(x, y) |--> (x + y)^pi 

 

The global function ``pow`` can be used:: 

 

sage: pow(f, pi) == f.__pow__(pi) 

True 

 

as well as the exponent notation:: 

 

sage: f^pi == f.__pow__(pi) 

True 

 

Some checks:: 

 

sage: pow(f, 2) == f*f 

True 

sage: pow(pow(f, 1/2), 2) == f 

True 

 

""" 

from sage.misc.latex import latex 

if self._name is None: 

name = None 

else: 

name = self._name + "^{}".format(exponent) 

if self._latex_name is None: 

latex_name = None 

else: 

latex_name = r"{" + self._latex_name + r"}^{" + \ 

latex(exponent) + r"}" 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.__pow__(exponent) 

return resu 

 

def sqrt(self): 

r""" 

Square root of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\sqrt f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: 1+x^2+y^2}, name='f', 

....: latex_name=r"\Phi") 

sage: g = sqrt(f) ; g 

Scalar field sqrt(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\sqrt{\Phi} 

sage: g.display() 

sqrt(f): M --> R 

(x, y) |--> sqrt(x^2 + y^2 + 1) 

 

Some tests:: 

 

sage: g^2 == f 

True 

sage: sqrt(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

 

""" 

name, latex_name = self._function_name("sqrt", r"\sqrt", 

parentheses=False) 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.sqrt() 

return resu 

 

def cos(self): 

r""" 

Cosine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\cos f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = cos(f) ; g 

Scalar field cos(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\cos\left(\Phi\right) 

sage: g.display() 

cos(f): M --> R 

(x, y) |--> cos(x*y) 

 

Some tests:: 

 

sage: cos(M.zero_scalar_field()) == M.constant_scalar_field(1) 

True 

sage: cos(M.constant_scalar_field(pi/2)) == M.zero_scalar_field() 

True 

 

""" 

name, latex_name = self._function_name("cos", r"\cos") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.cos() 

return resu 

 

def sin(self): 

r""" 

Sine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\sin f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = sin(f) ; g 

Scalar field sin(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\sin\left(\Phi\right) 

sage: g.display() 

sin(f): M --> R 

(x, y) |--> sin(x*y) 

 

Some tests:: 

 

sage: sin(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

sage: sin(M.constant_scalar_field(pi/2)) == M.constant_scalar_field(1) 

True 

 

""" 

name, latex_name = self._function_name("sin", r"\sin") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.sin() 

return resu 

 

def tan(self): 

r""" 

Tangent of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\tan f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = tan(f) ; g 

Scalar field tan(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\tan\left(\Phi\right) 

sage: g.display() 

tan(f): M --> R 

(x, y) |--> sin(x*y)/cos(x*y) 

 

Some tests:: 

 

sage: tan(f) == sin(f) / cos(f) 

True 

sage: tan(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

sage: tan(M.constant_scalar_field(pi/4)) == M.constant_scalar_field(1) 

True 

 

""" 

name, latex_name = self._function_name("tan", r"\tan") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.tan() 

return resu 

 

def arccos(self): 

r""" 

Arc cosine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\arccos f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = arccos(f) ; g 

Scalar field arccos(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\arccos\left(\Phi\right) 

sage: g.display() 

arccos(f): M --> R 

(x, y) |--> arccos(x*y) 

 

The notation ``acos`` can be used as well:: 

 

sage: acos(f) 

Scalar field arccos(f) on the 2-dimensional topological manifold M 

sage: acos(f) == g 

True 

 

Some tests:: 

 

sage: cos(g) == f 

True 

sage: arccos(M.constant_scalar_field(1)) == M.zero_scalar_field() 

True 

sage: arccos(M.zero_scalar_field()) == M.constant_scalar_field(pi/2) 

True 

 

""" 

name, latex_name = self._function_name("arccos", r"\arccos") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.arccos() 

return resu 

 

def arcsin(self): 

r""" 

Arc sine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\arcsin f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = arcsin(f) ; g 

Scalar field arcsin(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\arcsin\left(\Phi\right) 

sage: g.display() 

arcsin(f): M --> R 

(x, y) |--> arcsin(x*y) 

 

The notation ``asin`` can be used as well:: 

 

sage: asin(f) 

Scalar field arcsin(f) on the 2-dimensional topological manifold M 

sage: asin(f) == g 

True 

 

Some tests:: 

 

sage: sin(g) == f 

True 

sage: arcsin(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

sage: arcsin(M.constant_scalar_field(1)) == M.constant_scalar_field(pi/2) 

True 

 

""" 

name, latex_name = self._function_name("arcsin", r"\arcsin") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.arcsin() 

return resu 

 

def arctan(self): 

r""" 

Arc tangent of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\arctan f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = arctan(f) ; g 

Scalar field arctan(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\arctan\left(\Phi\right) 

sage: g.display() 

arctan(f): M --> R 

(x, y) |--> arctan(x*y) 

 

The notation ``atan`` can be used as well:: 

 

sage: atan(f) 

Scalar field arctan(f) on the 2-dimensional topological manifold M 

sage: atan(f) == g 

True 

 

Some tests:: 

 

sage: tan(g) == f 

True 

sage: arctan(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

sage: arctan(M.constant_scalar_field(1)) == M.constant_scalar_field(pi/4) 

True 

 

""" 

name, latex_name = self._function_name("arctan", r"\arctan") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.arctan() 

return resu 

 

def cosh(self): 

r""" 

Hyperbolic cosine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\cosh f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = cosh(f) ; g 

Scalar field cosh(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\cosh\left(\Phi\right) 

sage: g.display() 

cosh(f): M --> R 

(x, y) |--> cosh(x*y) 

 

Some test:: 

 

sage: cosh(M.zero_scalar_field()) == M.constant_scalar_field(1) 

True 

 

""" 

name, latex_name = self._function_name("cosh", r"\cosh") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.cosh() 

return resu 

 

def sinh(self): 

r""" 

Hyperbolic sine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\sinh f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = sinh(f) ; g 

Scalar field sinh(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\sinh\left(\Phi\right) 

sage: g.display() 

sinh(f): M --> R 

(x, y) |--> sinh(x*y) 

 

Some test:: 

 

sage: sinh(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

 

""" 

name, latex_name = self._function_name("sinh", r"\sinh") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.sinh() 

return resu 

 

def tanh(self): 

r""" 

Hyperbolic tangent of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\tanh f`, where `f` is the current scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = tanh(f) ; g 

Scalar field tanh(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\tanh\left(\Phi\right) 

sage: g.display() 

tanh(f): M --> R 

(x, y) |--> sinh(x*y)/cosh(x*y) 

 

Some tests:: 

 

sage: tanh(f) == sinh(f) / cosh(f) 

True 

sage: tanh(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

 

""" 

name, latex_name = self._function_name("tanh", r"\tanh") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.tanh() 

return resu 

 

def arccosh(self): 

r""" 

Inverse hyperbolic cosine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\mathrm{arccosh}\, f`, where `f` is the current 

scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = arccosh(f) ; g 

Scalar field arccosh(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\,\mathrm{arccosh}\left(\Phi\right) 

sage: g.display() 

arccosh(f): M --> R 

(x, y) |--> arccosh(x*y) 

 

The notation ``acosh`` can be used as well:: 

 

sage: acosh(f) 

Scalar field arccosh(f) on the 2-dimensional topological manifold M 

sage: acosh(f) == g 

True 

 

Some tests:: 

 

sage: cosh(g) == f 

True 

sage: arccosh(M.constant_scalar_field(1)) == M.zero_scalar_field() 

True 

 

""" 

name, latex_name = self._function_name("arccosh", r"\,\mathrm{arccosh}") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.arccosh() 

return resu 

 

def arcsinh(self): 

r""" 

Inverse hyperbolic sine of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\mathrm{arcsinh}\, f`, where `f` is the current 

scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = arcsinh(f) ; g 

Scalar field arcsinh(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\,\mathrm{arcsinh}\left(\Phi\right) 

sage: g.display() 

arcsinh(f): M --> R 

(x, y) |--> arcsinh(x*y) 

 

The notation ``asinh`` can be used as well:: 

 

sage: asinh(f) 

Scalar field arcsinh(f) on the 2-dimensional topological manifold M 

sage: asinh(f) == g 

True 

 

Some tests:: 

 

sage: sinh(g) == f 

True 

sage: arcsinh(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

 

""" 

name, latex_name = self._function_name("arcsinh", r"\,\mathrm{arcsinh}") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.arcsinh() 

return resu 

 

def arctanh(self): 

r""" 

Inverse hyperbolic tangent of the scalar field. 

 

OUTPUT: 

 

- the scalar field `\mathrm{arctanh}\, f`, where `f` is the current 

scalar field 

 

EXAMPLES:: 

 

sage: M = Manifold(2, 'M', structure='topological') 

sage: X.<x,y> = M.chart() 

sage: f = M.scalar_field({X: x*y}, name='f', latex_name=r"\Phi") 

sage: g = arctanh(f) ; g 

Scalar field arctanh(f) on the 2-dimensional topological manifold M 

sage: latex(g) 

\,\mathrm{arctanh}\left(\Phi\right) 

sage: g.display() 

arctanh(f): M --> R 

(x, y) |--> arctanh(x*y) 

 

The notation ``atanh`` can be used as well:: 

 

sage: atanh(f) 

Scalar field arctanh(f) on the 2-dimensional topological manifold M 

sage: atanh(f) == g 

True 

 

Some tests:: 

 

sage: tanh(g) == f 

True 

sage: arctanh(M.zero_scalar_field()) == M.zero_scalar_field() 

True 

sage: arctanh(M.constant_scalar_field(1/2)) == M.constant_scalar_field(log(3)/2) 

True 

 

""" 

name, latex_name = self._function_name("arctanh", r"\,\mathrm{arctanh}") 

resu = type(self)(self.parent(), name=name, latex_name=latex_name) 

for chart, func in self._express.items(): 

resu._express[chart] = func.arctanh() 

return resu