Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding simplify flag to group(). #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions engine/triangulation/detail/algebra-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,27 @@ AbelianGroup TriangulationBase<dim>::homology() const {
}

template <int dim>
const GroupPresentation& TriangulationBase<dim>::group() const {
if (fundGroup_.has_value())
return *fundGroup_;

const GroupPresentation& TriangulationBase<dim>::group(bool simplify) const {
if (simplify) {
if (simplifiedFundGroup_)
return *simplifiedFundGroup_;
if (isEmpty())
return *(simplifiedFundGroup_ = GroupPresentation());
GroupPresentation ans =
fundGroup_ ? *fundGroup_ : unsimplifiedGroup();
ans.intelligentSimplify();
return *(simplifiedFundGroup_ = std::move(ans));
} else {
if (isEmpty())
return *(fundGroup_ = GroupPresentation());
return *(fundGroup_ = unsimplifiedGroup());
}
}

template <int dim>
GroupPresentation TriangulationBase<dim>::unsimplifiedGroup() const {
GroupPresentation ans;

if (isEmpty())
return *(fundGroup_ = std::move(ans));


// Calculate a maximal forest in the dual 1-skeleton.
ensureSkeleton();

Expand All @@ -199,7 +211,8 @@ const GroupPresentation& TriangulationBase<dim>::group() const {
ans.addGenerator(nGens);

// Find out which (dim-1)-face corresponds to which generator.
long* genIndex = new long[countFaces<dim-1>()];
std::unique_ptr<long[]> genIndex =
std::make_unique<long[]>(countFaces<dim-1>());
long i = 0;
for (Face<dim, dim-1>* f : faces<dim-1>())
if (! (f->isBoundary() || f->inMaximalForest()))
Expand Down Expand Up @@ -234,11 +247,7 @@ const GroupPresentation& TriangulationBase<dim>::group() const {
}
}

// Tidy up.
delete[] genIndex;
ans.intelligentSimplify();

return *(fundGroup_ = std::move(ans));
return ans;
}

template <int dim>
Expand Down
2 changes: 2 additions & 0 deletions engine/triangulation/detail/skeleton-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ void TriangulationBase<dim>::clearBaseProperties() {
// Clear properties.
if (! topologyLock_) {
fundGroup_.reset();
simplifiedFundGroup_.reset();
H1_.reset();
}
}
Expand Down Expand Up @@ -634,6 +635,7 @@ void TriangulationBase<dim>::swapBaseData(TriangulationBase<dim>& other) {
faces_.swap(other.faces_);
nBoundaryFaces_.swap(other.nBoundaryFaces_);
fundGroup_.swap(other.fundGroup_);
simplifiedFundGroup_.swap(other.simplifiedFundGroup_);
H1_.swap(other.H1_);
}

Expand Down
46 changes: 39 additions & 7 deletions engine/triangulation/detail/triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ class TriangulationBase :
mutable std::optional<GroupPresentation> fundGroup_;
/**< Fundamental group of the triangulation.
This is std::nullopt if it has not yet been computed. */
mutable std::optional<GroupPresentation> simplifiedFundGroup_;
/**< Simplified fundamental group of the triangulation.
It was either computed from fundGroup_ by
GroupPresentation::intelligentSimplify or set by the
user through setGroupPresentation.
This is std::nullopt if it has not yet been computed. */
mutable std::optional<AbelianGroup> H1_;
/**< First homology group of the triangulation.
This is std::nullopt if it has not yet been computed. */
Expand Down Expand Up @@ -1327,7 +1333,8 @@ class TriangulationBase :
/*@{*/

/**
* Returns the fundamental group of this triangulation.
* Returns the unsimplified or simplified (default) presentation of
* the fundamental group of this triangulation.
*
* The fundamental group is computed in the dual 2-skeleton. This
* means:
Expand All @@ -1350,6 +1357,15 @@ class TriangulationBase :
* barycentric subdivision is performed on a such a triangulation,
* the result of group() might change.
*
* By default, the presentation will be simplified. The unsimplified
* presentation can be obtained by passing simplify = false as
* argument. In the unsimplified presentation, the generators
* correspond to those facet-pairings that are not dual to edges
* in the maximal forest in the dual 2-skeleton chosen by regina
* (those facet-pairings can be found by checking that neither
* Face<dim, dim-1>::isBoundary() nor
* Face<dim, dim-1>::inMaximalForest returns true).
*
* Bear in mind that each time the triangulation changes, the
* fundamental group will be deleted. Thus the reference that is
* returned from this routine should not be kept for later use.
Expand All @@ -1370,9 +1386,12 @@ class TriangulationBase :
* fundamental group with fillings, call
* SnapPeaTriangulation::fundamentalGroupFilled() instead.
*
* \return the fundamental group.
* \param simplify \c true if the presentation should be simplified
* (default to \c true).
*
* \return A presentation of the fundamental group.
*/
const GroupPresentation& group() const;
const GroupPresentation& group(bool simplify = true) const;
/**
* An alias for group(), which returns the fundamental group of this
* triangulation.
Expand All @@ -1394,9 +1413,9 @@ class TriangulationBase :
* fundamental group with fillings, call
* SnapPeaTriangulation::fundamentalGroupFilled() instead.
*
* \return the fundamental group.
* \return a presentation of the fundamental group.
*/
const GroupPresentation& fundamentalGroup() const;
const GroupPresentation& fundamentalGroup(bool simplify = true) const;
/**
* Allows the specific presentation of the fundamental group to be
* changed by some other (external) means.
Expand Down Expand Up @@ -3582,6 +3601,14 @@ class TriangulationBase :
bool sameDegreesAt(const TriangulationBase& other,
std::integer_sequence<int, useDim...>) const;

/**
* Computes unsimplified presentation of fundamental group.
*
* \return Unsimplified presentation of fundamental group.
*/
GroupPresentation
unsimplifiedGroup() const;

protected:
/**
* An object that facilitates both firing change events and
Expand Down Expand Up @@ -3828,6 +3855,7 @@ TriangulationBase<dim>::TriangulationBase(const TriangulationBase<dim>& src,
// Clone properties:
if (cloneProps) {
fundGroup_ = src.fundGroup_;
simplifiedFundGroup_ = src.simplifiedFundGroup_;
H1_ = src.H1_;
}
}
Expand All @@ -3842,6 +3870,7 @@ TriangulationBase<dim>::TriangulationBase(TriangulationBase<dim>&& src)
calculatedSkeleton_(src.calculatedSkeleton_),
orientable_(src.orientable_),
fundGroup_(std::move(src.fundGroup_)),
simplifiedFundGroup_(std::move(src.simplifiedFundGroup_)),
H1_(std::move(src.H1_)) {
// For our simplices and skeletal components, we use swaps instead
// of moves because we need to ensure that src's lists finish empty.
Expand Down Expand Up @@ -3910,6 +3939,7 @@ TriangulationBase<dim>& TriangulationBase<dim>::operator =

// Clone properties:
fundGroup_ = src.fundGroup_;
simplifiedFundGroup_ = src.simplifiedFundGroup_;
H1_ = src.H1_;

return *this;
Expand Down Expand Up @@ -3948,6 +3978,7 @@ TriangulationBase<dim>& TriangulationBase<dim>::operator =
std::swap(calculatedSkeleton_, src.calculatedSkeleton_);

fundGroup_ = std::move(src.fundGroup_);
simplifiedFundGroup_ = std::move(src.simplifiedFundGroup_);
H1_ = std::move(src.H1_);

// Let src dispose of the original simplices and skeletal objects in
Expand Down Expand Up @@ -4966,9 +4997,10 @@ std::vector<Triangulation<dim>>
}

template <int dim>
inline const GroupPresentation& TriangulationBase<dim>::fundamentalGroup()
inline const GroupPresentation& TriangulationBase<dim>::fundamentalGroup(
const bool simplify)
const {
return group();
return group(simplify);
}

template <int dim>
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ template MatrixInt TriangulationBase<10>::dualToPrimal<7>() const;
template MatrixInt TriangulationBase<10>::dualToPrimal<8>() const;
template MatrixInt TriangulationBase<10>::dualToPrimal<9>() const;

template const GroupPresentation& TriangulationBase<10>::group() const;
template const GroupPresentation& TriangulationBase<10>::group(bool) const;

template void TriangulationBase<10>::calculateSkeleton();
template void TriangulationBase<10>::cloneSkeleton(
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ template MatrixInt TriangulationBase<11>::dualToPrimal<8>() const;
template MatrixInt TriangulationBase<11>::dualToPrimal<9>() const;
template MatrixInt TriangulationBase<11>::dualToPrimal<10>() const;

template const GroupPresentation& TriangulationBase<11>::group() const;
template const GroupPresentation& TriangulationBase<11>::group(bool) const;

template void TriangulationBase<11>::calculateSkeleton();
template void TriangulationBase<11>::cloneSkeleton(
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ template MatrixInt TriangulationBase<12>::dualToPrimal<9>() const;
template MatrixInt TriangulationBase<12>::dualToPrimal<10>() const;
template MatrixInt TriangulationBase<12>::dualToPrimal<11>() const;

template const GroupPresentation& TriangulationBase<12>::group() const;
template const GroupPresentation& TriangulationBase<12>::group(bool) const;

template void TriangulationBase<12>::calculateSkeleton();
template void TriangulationBase<12>::cloneSkeleton(
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ template MatrixInt TriangulationBase<13>::dualToPrimal<10>() const;
template MatrixInt TriangulationBase<13>::dualToPrimal<11>() const;
template MatrixInt TriangulationBase<13>::dualToPrimal<12>() const;

template const GroupPresentation& TriangulationBase<13>::group() const;
template const GroupPresentation& TriangulationBase<13>::group(bool) const;

template void TriangulationBase<13>::calculateSkeleton();
template void TriangulationBase<13>::cloneSkeleton(
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ template MatrixInt TriangulationBase<14>::dualToPrimal<11>() const;
template MatrixInt TriangulationBase<14>::dualToPrimal<12>() const;
template MatrixInt TriangulationBase<14>::dualToPrimal<13>() const;

template const GroupPresentation& TriangulationBase<14>::group() const;
template const GroupPresentation& TriangulationBase<14>::group(bool) const;

template void TriangulationBase<14>::calculateSkeleton();
template void TriangulationBase<14>::cloneSkeleton(
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ template MatrixInt TriangulationBase<15>::dualToPrimal<12>() const;
template MatrixInt TriangulationBase<15>::dualToPrimal<13>() const;
template MatrixInt TriangulationBase<15>::dualToPrimal<14>() const;

template const GroupPresentation& TriangulationBase<15>::group() const;
template const GroupPresentation& TriangulationBase<15>::group(bool) const;

template void TriangulationBase<15>::calculateSkeleton();
template void TriangulationBase<15>::cloneSkeleton(
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ template MatrixInt TriangulationBase<2>::dualBoundaryMap<2>() const;
template MatrixInt TriangulationBase<2>::dualToPrimal<0>() const;
template MatrixInt TriangulationBase<2>::dualToPrimal<1>() const;

template const GroupPresentation& TriangulationBase<2>::group() const;
template const GroupPresentation& TriangulationBase<2>::group(bool) const;

template void TriangulationBase<2>::calculateSkeleton();
template void TriangulationBase<2>::cloneSkeleton(const TriangulationBase<2>&);
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ template MatrixInt TriangulationBase<3>::dualToPrimal<0>() const;
template MatrixInt TriangulationBase<3>::dualToPrimal<1>() const;
template MatrixInt TriangulationBase<3>::dualToPrimal<2>() const;

template const GroupPresentation& TriangulationBase<3>::group() const;
template const GroupPresentation& TriangulationBase<3>::group(bool) const;

template void TriangulationBase<3>::calculateSkeleton();
template void TriangulationBase<3>::cloneSkeleton(const TriangulationBase<3>&);
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template MatrixInt TriangulationBase<4>::dualToPrimal<1>() const;
template MatrixInt TriangulationBase<4>::dualToPrimal<2>() const;
template MatrixInt TriangulationBase<4>::dualToPrimal<3>() const;

template const GroupPresentation& TriangulationBase<4>::group() const;
template const GroupPresentation& TriangulationBase<4>::group(bool) const;

template void TriangulationBase<4>::calculateSkeleton();
template void TriangulationBase<4>::cloneSkeleton(const TriangulationBase<4>&);
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ template MatrixInt TriangulationBase<5>::dualToPrimal<2>() const;
template MatrixInt TriangulationBase<5>::dualToPrimal<3>() const;
template MatrixInt TriangulationBase<5>::dualToPrimal<4>() const;

template const GroupPresentation& TriangulationBase<5>::group() const;
template const GroupPresentation& TriangulationBase<5>::group(bool) const;

template void TriangulationBase<5>::calculateSkeleton();
template void TriangulationBase<5>::cloneSkeleton(const TriangulationBase<5>&);
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ template MatrixInt TriangulationBase<6>::dualToPrimal<3>() const;
template MatrixInt TriangulationBase<6>::dualToPrimal<4>() const;
template MatrixInt TriangulationBase<6>::dualToPrimal<5>() const;

template const GroupPresentation& TriangulationBase<6>::group() const;
template const GroupPresentation& TriangulationBase<6>::group(bool) const;

template void TriangulationBase<6>::calculateSkeleton();
template void TriangulationBase<6>::cloneSkeleton(const TriangulationBase<6>&);
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ template MatrixInt TriangulationBase<7>::dualToPrimal<4>() const;
template MatrixInt TriangulationBase<7>::dualToPrimal<5>() const;
template MatrixInt TriangulationBase<7>::dualToPrimal<6>() const;

template const GroupPresentation& TriangulationBase<7>::group() const;
template const GroupPresentation& TriangulationBase<7>::group(bool) const;

template void TriangulationBase<7>::calculateSkeleton();
template void TriangulationBase<7>::cloneSkeleton(const TriangulationBase<7>&);
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ template MatrixInt TriangulationBase<8>::dualToPrimal<5>() const;
template MatrixInt TriangulationBase<8>::dualToPrimal<6>() const;
template MatrixInt TriangulationBase<8>::dualToPrimal<7>() const;

template const GroupPresentation& TriangulationBase<8>::group() const;
template const GroupPresentation& TriangulationBase<8>::group(bool) const;

template void TriangulationBase<8>::calculateSkeleton();
template void TriangulationBase<8>::cloneSkeleton(const TriangulationBase<8>&);
Expand Down
2 changes: 1 addition & 1 deletion engine/triangulation/explicit/triangulation9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ template MatrixInt TriangulationBase<9>::dualToPrimal<6>() const;
template MatrixInt TriangulationBase<9>::dualToPrimal<7>() const;
template MatrixInt TriangulationBase<9>::dualToPrimal<8>() const;

template const GroupPresentation& TriangulationBase<9>::group() const;
template const GroupPresentation& TriangulationBase<9>::group(bool) const;

template void TriangulationBase<9>::calculateSkeleton();
template void TriangulationBase<9>::cloneSkeleton(const TriangulationBase<9>&);
Expand Down
4 changes: 3 additions & 1 deletion python/dim2/triangulation2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,14 @@ void addTriangulation2(pybind11::module_& m) {
.def("isConnected", &Triangulation<2>::isConnected,
rbase::isConnected)
.def("group", &Triangulation<2>::group,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal, rbase::group)
.def("fundamentalGroup", &Triangulation<2>::fundamentalGroup,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal,
rbase::fundamentalGroup)
.def("setGroupPresentation",
&Triangulation<2>::setGroupPresentation,
&Triangulation<2>::setGroupPresentation,
rbase::setGroupPresentation)
.def("simplifiedFundamentalGroup", // deprecated
&Triangulation<2>::setGroupPresentation,
Expand Down
2 changes: 2 additions & 0 deletions python/dim3/triangulation3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,10 @@ void addTriangulation3(pybind11::module_& m) {
.def("isConnected", &Triangulation<3>::isConnected,
rbase::isConnected)
.def("group", &Triangulation<3>::group,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal, rbase::group)
.def("fundamentalGroup", &Triangulation<3>::fundamentalGroup,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal,
rbase::fundamentalGroup)
.def("setGroupPresentation",
Expand Down
2 changes: 2 additions & 0 deletions python/dim4/triangulation4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ void addTriangulation4(pybind11::module_& m) {
.def("isConnected", &Triangulation<4>::isConnected,
rbase::isConnected)
.def("group", &Triangulation<4>::group,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal, rbase::group)
.def("fundamentalGroup", &Triangulation<4>::fundamentalGroup,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal,
rbase::fundamentalGroup)
.def("setGroupPresentation",
Expand Down
2 changes: 2 additions & 0 deletions python/generic/triangulation-bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ void addTriangulation(pybind11::module_& m, const char* name) {
.def("eulerCharTri", &Triangulation<dim>::eulerCharTri,
rbase::eulerCharTri)
.def("group", &Triangulation<dim>::group,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal, rbase::group)
.def("fundamentalGroup", &Triangulation<dim>::fundamentalGroup,
pybind11::arg("simplify") = true,
pybind11::return_value_policy::reference_internal,
rbase::fundamentalGroup)
.def("setGroupPresentation",
Expand Down
3 changes: 3 additions & 0 deletions python/testsuite/refs.out
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ g0^6 g1 g0^-1 g1 g0 g1^-1
g0^6
g0^7

g1^-1 g0 g1 g2 g0^-1
g0 g2 g1 g2^-1

foo
foo
foo
Expand Down
Loading