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

r""" 

Base classes for triangulations 

  

We provide (fast) cython implementations here. 

  

AUTHORS: 

  

- Volker Braun (2010-09-14): initial version. 

""" 

  

  

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

# Copyright (C) 2010 Volker Braun <vbraun.name@gmail.com> 

# 

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

# 

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

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

from __future__ import absolute_import 

  

from sage.misc.fast_methods cimport hash_by_id 

from sage.structure.sage_object cimport SageObject 

from sage.structure.parent cimport Parent 

from sage.categories.sets_cat import Sets 

from sage.matrix.constructor import matrix 

from sage.misc.misc import uniq 

from sage.misc.cachefunc import cached_method 

  

from .functions cimport binomial 

from .triangulations cimport \ 

triangulations_ptr, init_triangulations, next_triangulation, delete_triangulations 

  

  

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

cdef class Point(SageObject): 

r""" 

A point of a point configuration. 

  

Note that the coordinates of the points of a point configuration 

are somewhat arbitrary. What counts are the abstract linear 

relations between the points, for example encoded by the 

:meth:`~sage.geometry.triangulation.point_configuration.PointConfiguration.circuits`. 

  

.. WARNING:: 

  

You should not create :class:`Point` objects manually. The 

constructor of :class:`PointConfiguration_base` takes care of 

this for you. 

  

INPUT: 

  

- ``point_configuration`` -- :class:`PointConfiguration_base`. The 

point configuration to which the point belongs. 

  

- ``i`` -- integer. The index of the point in the point 

configuration. 

  

- ``projective`` -- the projective coordinates of the point. 

  

- ``affine`` -- the affine coordinates of the point. 

  

- ``reduced`` -- the reduced (with linearities removed) 

coordinates of the point. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([(0,0)]) 

sage: from sage.geometry.triangulation.base import Point 

sage: Point(pc, 123, (0,0,1), (0,0), ()) 

P(0, 0) 

""" 

  

cdef int _index 

cdef tuple _projective, _affine, _reduced_affine 

cdef object _point_configuration 

cdef object _reduced_affine_vector, _reduced_projective_vector 

  

  

def __init__(self, point_configuration, i, projective, affine, reduced): 

r""" 

Construct a :class:`Point`. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([(0,0)]) 

sage: from sage.geometry.triangulation.base import Point 

sage: Point(pc, 123, (0,0,1), (0,0), ()) # indirect doctest 

P(0, 0) 

""" 

self._index = i 

self._projective = tuple(projective) 

self._affine = tuple(affine) 

self._reduced_affine = tuple(reduced) 

self._point_configuration = point_configuration 

V = point_configuration.reduced_affine_vector_space() 

self._reduced_affine_vector = V(self._reduced_affine) 

P = point_configuration.reduced_projective_vector_space() 

self._reduced_projective_vector = P(self.reduced_projective()) 

  

def __hash__(self): 

r""" 

Hash value for a point in a point configuration 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0],[0,1],[1,1]]) 

sage: hash(p[0]) # random 

35822008390213632 

""" 

return hash(self._point_configuration) ^ (<long>self._index) 

  

cpdef point_configuration(self): 

r""" 

Return the point configuration to which the point belongs. 

  

OUTPUT: 

  

A :class:`~sage.geometry.triangulation.point_configuration.PointConfiguration`. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([ (0,0), (1,0), (0,1) ]) 

sage: p = pc.point(0) 

sage: p is pc.point(0) 

True 

sage: p.point_configuration() is pc 

True 

""" 

return self._point_configuration 

  

  

def __iter__(self): 

r""" 

Iterate through the affine ambient space coordinates of the point. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([(0,0)]) 

sage: from sage.geometry.triangulation.base import Point 

sage: p = Point(pc, 123, (1,2,1), (3,4), ()) 

sage: list(p) # indirect doctest 

[3, 4] 

""" 

return iter(self._affine) 

  

def __len__(self): 

r""" 

Return the affine ambient space dimension. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([(0,0)]) 

sage: from sage.geometry.triangulation.base import Point 

sage: p = Point(pc, 123, (1,2,1), (3,4), ()) 

sage: len(p) 

2 

sage: p.__len__() 

2 

""" 

return len(self._affine) 

  

  

cpdef index(self): 

""" 

Return the index of the point in the point configuration. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[0, 1], [0, 0], [1, 0]]) 

sage: p = pc.point(2); p 

P(1, 0) 

sage: p.index() 

2 

""" 

return self._index 

  

  

cpdef projective(self): 

r""" 

Return the projective coordinates of the point in the ambient space. 

  

OUTPUT: 

  

A tuple containing the coordinates. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[10, 0, 1], [10, 0, 0], [10, 2, 3]]) 

sage: p = pc.point(2); p 

P(10, 2, 3) 

sage: p.affine() 

(10, 2, 3) 

sage: p.projective() 

(10, 2, 3, 1) 

sage: p.reduced_affine() 

(2, 2) 

sage: p.reduced_projective() 

(2, 2, 1) 

sage: p.reduced_affine_vector() 

(2, 2) 

""" 

return self._projective 

  

  

cpdef affine(self): 

r""" 

Return the affine coordinates of the point in the ambient space. 

  

OUTPUT: 

  

A tuple containing the coordinates. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[10, 0, 1], [10, 0, 0], [10, 2, 3]]) 

sage: p = pc.point(2); p 

P(10, 2, 3) 

sage: p.affine() 

(10, 2, 3) 

sage: p.projective() 

(10, 2, 3, 1) 

sage: p.reduced_affine() 

(2, 2) 

sage: p.reduced_projective() 

(2, 2, 1) 

sage: p.reduced_affine_vector() 

(2, 2) 

""" 

return self._affine 

  

  

cpdef reduced_affine(self): 

r""" 

Return the affine coordinates of the point on the hyperplane 

spanned by the point configuration. 

  

OUTPUT: 

  

A tuple containing the coordinates. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[10, 0, 1], [10, 0, 0], [10, 2, 3]]) 

sage: p = pc.point(2); p 

P(10, 2, 3) 

sage: p.affine() 

(10, 2, 3) 

sage: p.projective() 

(10, 2, 3, 1) 

sage: p.reduced_affine() 

(2, 2) 

sage: p.reduced_projective() 

(2, 2, 1) 

sage: p.reduced_affine_vector() 

(2, 2) 

""" 

return self._reduced_affine 

  

  

cpdef reduced_projective(self): 

r""" 

Return the projective coordinates of the point on the hyperplane 

spanned by the point configuration. 

  

OUTPUT: 

  

A tuple containing the coordinates. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[10, 0, 1], [10, 0, 0], [10, 2, 3]]) 

sage: p = pc.point(2); p 

P(10, 2, 3) 

sage: p.affine() 

(10, 2, 3) 

sage: p.projective() 

(10, 2, 3, 1) 

sage: p.reduced_affine() 

(2, 2) 

sage: p.reduced_projective() 

(2, 2, 1) 

sage: p.reduced_affine_vector() 

(2, 2) 

""" 

return tuple(self._reduced_affine)+(1,) 

  

  

cpdef reduced_affine_vector(self): 

""" 

Return the affine coordinates of the point on the hyperplane 

spanned by the point configuration. 

  

OUTPUT: 

  

A tuple containing the coordinates. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[10, 0, 1], [10, 0, 0], [10, 2, 3]]) 

sage: p = pc.point(2); p 

P(10, 2, 3) 

sage: p.affine() 

(10, 2, 3) 

sage: p.projective() 

(10, 2, 3, 1) 

sage: p.reduced_affine() 

(2, 2) 

sage: p.reduced_projective() 

(2, 2, 1) 

sage: p.reduced_affine_vector() 

(2, 2) 

""" 

return self._reduced_affine_vector 

  

  

cpdef reduced_projective_vector(self): 

""" 

Return the affine coordinates of the point on the hyperplane 

spanned by the point configuration. 

  

OUTPUT: 

  

A tuple containing the coordinates. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[10, 0, 1], [10, 0, 0], [10, 2, 3]]) 

sage: p = pc.point(2); p 

P(10, 2, 3) 

sage: p.affine() 

(10, 2, 3) 

sage: p.projective() 

(10, 2, 3, 1) 

sage: p.reduced_affine() 

(2, 2) 

sage: p.reduced_projective() 

(2, 2, 1) 

sage: p.reduced_affine_vector() 

(2, 2) 

sage: type(p.reduced_affine_vector()) 

<type 'sage.modules.vector_rational_dense.Vector_rational_dense'> 

""" 

return self._reduced_projective_vector 

  

  

cpdef _repr_(self): 

""" 

Return a string representation of the point. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: pc = PointConfiguration([[10, 0, 1], [10, 0, 0]]) 

sage: from sage.geometry.triangulation.base import Point 

sage: p = Point(pc, 123, (0,0,1), (0,0), (0,)) 

sage: p._repr_() 

'P(0, 0)' 

""" 

return 'P'+str(self._affine) 

  

  

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

cdef class PointConfiguration_base(Parent): 

r""" 

The cython abstract base class for 

:class:`~sage.geometry.triangulation.PointConfiguration`. 

  

.. WARNING:: 

  

You should not instantiate this base class, but only its 

derived class 

:class:`~sage.geometry.triangulation.point_configuration.PointConfiguration`. 

""" 

  

def __init__(self, points, defined_affine): 

r""" 

Construct a :class:`PointConfiguration_base`. 

  

INPUT: 

  

- ``points`` -- a tuple of tuples of projective coordinates 

with ``1`` as the final coordinate. 

  

- ``defined_affine`` -- Boolean. Whether the point 

configuration is defined as a configuration of affine (as 

opposed to projective) points. 

  

TESTS:: 

  

sage: from sage.geometry.triangulation.base import PointConfiguration_base 

sage: PointConfiguration_base(((1,2,1),(2,3,1),(3,4,1)), False) 

<sage.geometry.triangulation.base.PointConfiguration_base object at ...> 

""" 

Parent.__init__(self, category = Sets()) 

self._init_points(points) 

self._is_affine = defined_affine 

  

  

cdef tuple _pts 

cdef int _ambient_dim 

cdef int _dim 

cdef object _base_ring 

cdef bint _is_affine 

cdef object _reduced_affine_vector_space, _reduced_projective_vector_space 

  

  

cdef _init_points(self, tuple projective_points): 

""" 

Internal method to determine coordinates of points. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0, 1], [0, 0], [1, 0]]) # indirect doctest 

sage: p.points() 

(P(0, 1), P(0, 0), P(1, 0)) 

  

Special cases:: 

  

sage: PointConfiguration([]) 

The pointless empty configuration 

sage: PointConfiguration([(1,2,3)]) 

A point configuration in affine 3-space over Integer Ring 

consisting of 1 point. The triangulations of this point 

configuration are assumed to be connected, not necessarily 

fine, not necessarily regular. 

""" 

n = len(projective_points) 

if n==0: 

self._ambient_dim = 0 

self._dim = -1 

self._pts = tuple() 

return 

  

# We now are sure that projective_points is not empty 

self._ambient_dim = len(projective_points[0])-1 

assert all([ len(p)==self._ambient_dim+1 for p in projective_points ]), \ 

'The given point coordinates must all have the same length.' 

assert len(uniq(projective_points)) == len(projective_points), \ 

'Not all points are pairwise distinct.' 

  

proj = matrix(projective_points).transpose() 

self._base_ring = proj.base_ring() 

  

if all([ x==1 for x in proj.row(self.ambient_dim()) ]): 

aff = proj.submatrix(0,0,nrows=self.ambient_dim()) 

else: 

raise NotImplementedError # TODO 

  

if n>1: 

# shift first point to origin 

red = matrix([ aff.column(i)-aff.column(0) for i in range(0,n) ]).transpose() 

# pick linearly independent rows 

red = matrix([ red.row(i) for i in red.pivot_rows()]) 

else: 

red = matrix(0,1) 

self._dim = red.nrows() 

  

from sage.modules.free_module import VectorSpace 

self._reduced_affine_vector_space = VectorSpace(self._base_ring.fraction_field(), self._dim) 

self._reduced_projective_vector_space = VectorSpace(self._base_ring.fraction_field(), self._dim+1) 

self._pts = tuple([ Point(self, i, proj.column(i), aff.column(i), red.column(i)) 

for i in range(0,n) ]) 

  

def __hash__(self): 

r""" 

Hash function. 

  

TESTS:: 

  

sage: p = PointConfiguration([[0,0],[0,1]]) 

sage: hash(p) # random 

8746748042501 

""" 

return hash_by_id(<void *> self) 

  

cpdef reduced_affine_vector_space(self): 

""" 

Return the vector space that contains the affine points. 

  

OUTPUT: 

  

A vector space over the fraction field of :meth:`base_ring`. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0,0], [1,2,3]]) 

sage: p.base_ring() 

Integer Ring 

sage: p.reduced_affine_vector_space() 

Vector space of dimension 1 over Rational Field 

sage: p.reduced_projective_vector_space() 

Vector space of dimension 2 over Rational Field 

""" 

return self._reduced_affine_vector_space 

  

  

cpdef reduced_projective_vector_space(self): 

""" 

Return the vector space that is spanned by the homogeneous 

coordinates. 

  

OUTPUT: 

  

A vector space over the fraction field of :meth:`base_ring`. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0,0], [1,2,3]]) 

sage: p.base_ring() 

Integer Ring 

sage: p.reduced_affine_vector_space() 

Vector space of dimension 1 over Rational Field 

sage: p.reduced_projective_vector_space() 

Vector space of dimension 2 over Rational Field 

""" 

return self._reduced_projective_vector_space 

  

  

cpdef ambient_dim(self): 

""" 

Return the dimension of the ambient space of the point 

configuration. 

  

See also :meth:`dimension` 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0,0]]) 

sage: p.ambient_dim() 

3 

sage: p.dim() 

0 

""" 

return self._ambient_dim 

  

  

cpdef dim(self): 

""" 

Return the actual dimension of the point 

configuration. 

  

See also :meth:`ambient_dim` 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0,0]]) 

sage: p.ambient_dim() 

3 

sage: p.dim() 

0 

""" 

return self._dim 

  

  

cpdef base_ring(self): 

r""" 

Return the base ring, that is, the ring containing the 

coordinates of the points. 

  

OUTPUT: 

  

A ring. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([(0,0)]) 

sage: p.base_ring() 

Integer Ring 

  

sage: p = PointConfiguration([(1/2,3)]) 

sage: p.base_ring() 

Rational Field 

  

sage: p = PointConfiguration([(0.2, 5)]) 

sage: p.base_ring() 

Real Field with 53 bits of precision 

""" 

return self._base_ring 

  

  

cpdef bint is_affine(self): 

""" 

Whether the configuration is defined by affine points. 

  

OUTPUT: 

  

Boolean. If true, the homogeneous coordinates all have `1` as 

their last entry. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([(0.2, 5), (3, 0.1)]) 

sage: p.is_affine() 

True 

  

sage: p = PointConfiguration([(0.2, 5, 1), (3, 0.1, 1)], projective=True) 

sage: p.is_affine() 

False 

""" 

return self._is_affine 

  

  

def _assert_is_affine(self): 

""" 

Raise a ``ValueError`` if the point configuration is not 

defined by affine points. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([(0.2, 5), (3, 0.1)]) 

sage: p._assert_is_affine() 

sage: p = PointConfiguration([(0.2, 5, 1), (3, 0.1, 1)], projective=True) 

sage: p._assert_is_affine() 

Traceback (most recent call last): 

... 

ValueError: The point configuration contains projective points. 

""" 

if not self.is_affine(): 

raise ValueError('The point configuration contains projective points.') 

  

  

def __getitem__(self, i): 

""" 

Return the ``i``-th point. 

  

Same as :meth:`point`. 

  

INPUT: 

  

- ``i`` -- integer. 

  

OUTPUT: 

  

The ``i``-th point of the point configuration. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[1,0], [2,3], [3,2]]) 

sage: [ p[i] for i in range(0,p.n_points()) ] 

[P(1, 0), P(2, 3), P(3, 2)] 

sage: list(p) 

[P(1, 0), P(2, 3), P(3, 2)] 

sage: list(p.points()) 

[P(1, 0), P(2, 3), P(3, 2)] 

sage: [ p.point(i) for i in range(0,p.n_points()) ] 

[P(1, 0), P(2, 3), P(3, 2)] 

""" 

return self._pts[i] 

  

  

cpdef n_points(self): 

""" 

Return the number of points. 

  

Same as ``len(self)``. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: p 

A point configuration in affine 2-space over Integer Ring 

consisting of 5 points. The triangulations of this point 

configuration are assumed to be connected, not necessarily 

fine, not necessarily regular. 

sage: len(p) 

5 

sage: p.n_points() 

5 

""" 

return len(self._pts) 

  

  

cpdef points(self): 

""" 

Return a list of the points. 

  

OUTPUT: 

  

Returns a list of the points. See also the :meth:`__iter__` 

method, which returns the corresponding generator. 

  

EXAMPLES:: 

  

sage: pconfig = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: list(pconfig) 

[P(0, 0), P(0, 1), P(1, 0), P(1, 1), P(-1, -1)] 

sage: [ p for p in pconfig.points() ] 

[P(0, 0), P(0, 1), P(1, 0), P(1, 1), P(-1, -1)] 

sage: pconfig.point(0) 

P(0, 0) 

sage: pconfig.point(1) 

P(0, 1) 

sage: pconfig.point( pconfig.n_points()-1 ) 

P(-1, -1) 

""" 

return self._pts 

  

  

def point(self, i): 

""" 

Return the i-th point of the configuration. 

  

Same as :meth:`__getitem__` 

  

INPUT: 

  

- ``i`` -- integer. 

  

OUTPUT: 

  

A point of the point configuration. 

  

EXAMPLES:: 

  

sage: pconfig = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: list(pconfig) 

[P(0, 0), P(0, 1), P(1, 0), P(1, 1), P(-1, -1)] 

sage: [ p for p in pconfig.points() ] 

[P(0, 0), P(0, 1), P(1, 0), P(1, 1), P(-1, -1)] 

sage: pconfig.point(0) 

P(0, 0) 

sage: pconfig[0] 

P(0, 0) 

sage: pconfig.point(1) 

P(0, 1) 

sage: pconfig.point( pconfig.n_points()-1 ) 

P(-1, -1) 

""" 

return self._pts[i] 

  

  

def __len__(self): 

""" 

Return the number of points. 

  

Same as :meth:`n_points` 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: p 

A point configuration in affine 2-space over Integer Ring 

consisting of 5 points. The triangulations of this point 

configuration are assumed to be connected, not necessarily 

fine, not necessarily regular. 

sage: len(p) 

5 

sage: p.n_points() 

5 

""" 

return len(self._pts) 

  

  

cpdef simplex_to_int(self, simplex): 

r""" 

Returns an integer that uniquely identifies the given simplex. 

  

See also the inverse method :meth:`int_to_simplex`. 

  

The enumeration is compatible with [PUNTOS]_. 

  

INPUT: 

  

- ``simplex`` -- iterable, for example a list. The elements 

are the vertex indices of the simplex. 

  

OUTPUT: 

  

An integer that uniquely specifies the simplex. 

  

EXAMPLES:: 

  

sage: U=matrix([ 

....: [ 0, 0, 0, 0, 0, 2, 4,-1, 1, 1, 0, 0, 1, 0], 

....: [ 0, 0, 0, 1, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0], 

....: [ 0, 2, 0, 0, 0, 0,-1, 0, 1, 0, 1, 0, 0, 1], 

....: [ 0, 1, 1, 0, 0, 1, 0,-2, 1, 0, 0,-1, 1, 1], 

....: [ 0, 0, 0, 0, 1, 0,-1, 0, 0, 0, 0, 0, 0, 0] 

....: ]) 

sage: pc = PointConfiguration(U.columns()) 

sage: pc.simplex_to_int([1,3,4,7,10,13]) 

1678 

sage: pc.int_to_simplex(1678) 

(1, 3, 4, 7, 10, 13) 

""" 

cdef int s = 1 

cdef int k = 1 

cdef int n = self.n_points() 

cdef int d = len(simplex) 

assert d==self.dim()+1 

cdef int i, j 

for i in range(1,d+1): 

l = simplex[i-1]+1 

for j in range(k,l): 

s += binomial(n-j,d-i) 

k = l+1 

return s 

  

  

cpdef int_to_simplex(self, int s): 

r""" 

Reverses the enumeration of possible simplices in 

:meth:`simplex_to_int`. 

  

The enumeration is compatible with [PUNTOS]_. 

  

INPUT: 

  

- ``s`` -- int. An integer that uniquely specifies a simplex. 

  

OUTPUT: 

  

An ordered tuple consisting of the indices of the vertices of 

the simplex. 

  

EXAMPLES:: 

  

sage: U=matrix([ 

....: [ 0, 0, 0, 0, 0, 2, 4,-1, 1, 1, 0, 0, 1, 0], 

....: [ 0, 0, 0, 1, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0], 

....: [ 0, 2, 0, 0, 0, 0,-1, 0, 1, 0, 1, 0, 0, 1], 

....: [ 0, 1, 1, 0, 0, 1, 0,-2, 1, 0, 0,-1, 1, 1], 

....: [ 0, 0, 0, 0, 1, 0,-1, 0, 0, 0, 0, 0, 0, 0] 

....: ]) 

sage: pc = PointConfiguration(U.columns()) 

sage: pc.simplex_to_int([1,3,4,7,10,13]) 

1678 

sage: pc.int_to_simplex(1678) 

(1, 3, 4, 7, 10, 13) 

""" 

simplex = [] 

cdef int l = 0 

cdef int n = self.n_points() 

cdef int d = self.dim()+1 

cdef int k, b 

for k in range(1,d): 

l += 1 

i = l 

j = 1 

b = binomial(n-l,d-k) 

while (s>b) and (b>0): 

j += 1 

l += 1 

s -= b 

b = binomial(n-l,d-k) 

simplex.append(l-1) 

simplex.append(s+l-1) 

assert len(simplex) == d 

return tuple(simplex) 

  

  

  

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

cdef class ConnectedTriangulationsIterator(SageObject): 

r""" 

A Python shim for the C++-class 'triangulations' 

  

INPUT: 

  

- ``point_configuration`` -- a 

:class:`~sage.geometry.triangulation.point_configuration.PointConfiguration`. 

  

- ``seed`` -- a regular triangulation or ``None`` (default). In 

the latter case, a suitable triangulation is generated 

automatically. Otherwise, you can explicitly specify the seed 

triangulation as 

  

* A 

:class:`~sage.geometry.triangulation.element.Triangulation` 

object, or 

  

* an iterable of iterables specifying the vertices of the simplices, or 

  

* an iterable of integers, which are then considered the 

enumerated simplices (see 

:meth:`~PointConfiguration_base.simplex_to_int`. 

  

- ``star`` -- either ``None`` (default) or an integer. If an 

integer is passed, all returned triangulations will be star with 

respect to the 

  

- ``fine`` -- boolean (default: ``False``). Whether to return only 

fine triangulations, that is, simplicial decompositions that 

make use of all the points of the configuration. 

  

OUTPUT: 

  

An iterator. The generated values are tuples of 

integers, which encode simplices of the triangulation. The output 

is a suitable input to 

:class:`~sage.geometry.triangulation.element.Triangulation`. 

  

EXAMPLES:: 

  

sage: p = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: from sage.geometry.triangulation.base import ConnectedTriangulationsIterator 

sage: ci = ConnectedTriangulationsIterator(p) 

sage: next(ci) 

(9, 10) 

sage: next(ci) 

(2, 3, 4, 5) 

sage: next(ci) 

(7, 8) 

sage: next(ci) 

(1, 3, 5, 7) 

sage: next(ci) 

Traceback (most recent call last): 

... 

StopIteration 

  

You can reconstruct the triangulation from the compressed output via:: 

  

sage: from sage.geometry.triangulation.element import Triangulation 

sage: Triangulation((2, 3, 4, 5), p) 

(<0,1,3>, <0,1,4>, <0,2,3>, <0,2,4>) 

  

How to use the restrictions:: 

  

sage: ci = ConnectedTriangulationsIterator(p, fine=True) 

sage: list(ci) 

[(2, 3, 4, 5), (1, 3, 5, 7)] 

sage: ci = ConnectedTriangulationsIterator(p, star=1) 

sage: list(ci) 

[(7, 8)] 

sage: ci = ConnectedTriangulationsIterator(p, star=1, fine=True) 

sage: list(ci) 

[] 

""" 

  

cdef triangulations_ptr _tp 

  

  

def __cinit__(self): 

""" 

The Cython constructor. 

  

TESTS:: 

  

sage: from sage.geometry.triangulation.base import ConnectedTriangulationsIterator 

sage: p = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: ConnectedTriangulationsIterator(p, fine=True) # indirect doctest 

<sage.geometry.triangulation.base.ConnectedTriangulationsIterator object at ...> 

""" 

self._tp = NULL 

  

  

def __init__(self, point_configuration, seed=None, star=None, fine=False): 

r""" 

The Python constructor. 

  

See :class:`ConnectedTriangulationsIterator` for a description 

of the arguments. 

  

TESTS:: 

  

sage: p = PointConfiguration([[0,4],[2,3],[3,2],[4,0],[3,-2],[2,-3],[0,-4],[-2,-3],[-3,-2],[-4,0],[-3,2],[-2,3]]) 

sage: from sage.geometry.triangulation.base import ConnectedTriangulationsIterator 

sage: ci = ConnectedTriangulationsIterator(p) 

sage: len(list(ci)) # long time (26s on sage.math, 2012) 

16796 

sage: ci = ConnectedTriangulationsIterator(p, star=3) 

sage: len(list(ci)) # long time (26s on sage.math, 2012) 

1 

""" 

if star is None: 

star = -1 

if seed is None: 

seed = point_configuration.lexicographic_triangulation().enumerate_simplices() 

try: 

enumerated_simplices_seed = seed.enumerated_simplices() 

except AttributeError: 

enumerated_simplices_seed = tuple([ int(t) for t in seed ]) 

assert self._tp == NULL 

self._tp = init_triangulations(point_configuration.n_points(), 

point_configuration.dim()+1, 

star, fine, 

enumerated_simplices_seed, 

point_configuration.bistellar_flips()) 

  

  

def __dealloc__(self): 

r""" 

The Cython destructor. 

""" 

delete_triangulations(self._tp) 

  

  

def __iter__(self): 

r""" 

The iterator interface: Start iterating. 

  

TESTS:: 

  

sage: from sage.geometry.triangulation.base import ConnectedTriangulationsIterator 

sage: p = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: ci = ConnectedTriangulationsIterator(p, fine=True) 

sage: ci.__iter__() 

<sage.geometry.triangulation.base.ConnectedTriangulationsIterator object at ...> 

sage: ci.__iter__() is ci 

True 

""" 

return self 

  

  

def __next__(self): 

r""" 

The iterator interface: Next iteration. 

  

EXAMPLES:: 

  

sage: from sage.geometry.triangulation.base import ConnectedTriangulationsIterator 

sage: p = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) 

sage: ci = ConnectedTriangulationsIterator(p) 

sage: ci.__next__() 

(9, 10) 

""" 

t = next_triangulation(self._tp) 

if len(t) == 0: 

raise StopIteration 

return t