Skip to content

Commit e7fe90e

Browse files
authored
api: Add Sort::getInstantiatedParameters(). (cvc5#8445)
This adds a function to retrieve the sort arguments an instantiated sort has been instantiated with. It further deletes Sort::getDatatypeParamSorts() and Sort::getUninterpretedSortParamSorts().
1 parent 3d21e43 commit e7fe90e

File tree

10 files changed

+235
-272
lines changed

10 files changed

+235
-272
lines changed

src/api/cpp/cvc5.cpp

+12-33
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,18 @@ Sort Sort::instantiate(const std::vector<Sort>& params) const
14451445
CVC5_API_TRY_CATCH_END;
14461446
}
14471447

1448+
std::vector<Sort> Sort::getInstantiatedParameters() const
1449+
{
1450+
CVC5_API_TRY_CATCH_BEGIN;
1451+
CVC5_API_CHECK_NOT_NULL;
1452+
CVC5_API_CHECK(d_type->isInstantiated())
1453+
<< "Expected instantiated parametric sort";
1454+
//////// all checks before this line
1455+
return typeNodeVectorToSorts(d_solver, d_type->getInstantiatedParamTypes());
1456+
////////
1457+
CVC5_API_TRY_CATCH_END;
1458+
}
1459+
14481460
Sort Sort::substitute(const Sort& sort, const Sort& replacement) const
14491461
{
14501462
CVC5_API_TRY_CATCH_BEGIN;
@@ -1672,27 +1684,6 @@ Sort Sort::getSequenceElementSort() const
16721684
CVC5_API_TRY_CATCH_END;
16731685
}
16741686

1675-
/* Uninterpreted sort -------------------------------------------------- */
1676-
1677-
std::vector<Sort> Sort::getUninterpretedSortParamSorts() const
1678-
{
1679-
CVC5_API_TRY_CATCH_BEGIN;
1680-
CVC5_API_CHECK_NOT_NULL;
1681-
CVC5_API_CHECK(isUninterpretedSort()) << "Not an uninterpreted sort.";
1682-
//////// all checks before this line
1683-
1684-
/* This method is not implemented in the NodeManager, since whether a
1685-
* uninterpreted sort is parameterized is irrelevant for solving. */
1686-
std::vector<TypeNode> params;
1687-
for (size_t i = 0, nchildren = d_type->getNumChildren(); i < nchildren; i++)
1688-
{
1689-
params.push_back((*d_type)[i]);
1690-
}
1691-
return typeNodeVectorToSorts(d_solver, params);
1692-
////////
1693-
CVC5_API_TRY_CATCH_END;
1694-
}
1695-
16961687
/* Sort constructor sort ----------------------------------------------- */
16971688

16981689
size_t Sort::getUninterpretedSortConstructorArity() const
@@ -1745,18 +1736,6 @@ uint32_t Sort::getFloatingPointSignificandSize() const
17451736

17461737
/* Datatype sort ------------------------------------------------------- */
17471738

1748-
std::vector<Sort> Sort::getDatatypeParamSorts() const
1749-
{
1750-
CVC5_API_TRY_CATCH_BEGIN;
1751-
CVC5_API_CHECK_NOT_NULL;
1752-
CVC5_API_CHECK(d_type->isParametricDatatype())
1753-
<< "Not a parametric datatype sort.";
1754-
//////// all checks before this line
1755-
return typeNodeVectorToSorts(d_solver, d_type->getDType().getParameters());
1756-
////////
1757-
CVC5_API_TRY_CATCH_END;
1758-
}
1759-
17601739
size_t Sort::getDatatypeArity() const
17611740
{
17621741
CVC5_API_TRY_CATCH_BEGIN;

src/api/cpp/cvc5.h

+12-18
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,25 @@ class CVC5_EXPORT Sort
615615
* Instantiate a parameterized datatype sort or uninterpreted sort
616616
* constructor sort.
617617
*
618-
* Create sorts parameter with Solver::mkParamSort().
618+
* Create sort parameters with Solver::mkParamSort().
619619
*
620620
* @warning This method is experimental and may change in future versions.
621621
*
622622
* @param params the list of sort parameters to instantiate with
623+
* @return the instantiated sort
623624
*/
624625
Sort instantiate(const std::vector<Sort>& params) const;
625626

627+
/**
628+
* Get the sorts used to instantiate the sort parameters of a parametric
629+
* sort (parametric datatype or uninterpreted sort constructor sort,
630+
* see Sort::instantiate(const std::vector<Sort>& const)).
631+
*
632+
* @return the sorts used to instantiate the sort parameters of a
633+
* parametric sort
634+
*/
635+
std::vector<Sort> getInstantiatedParameters() const;
636+
626637
/**
627638
* Substitution of Sorts.
628639
*
@@ -768,11 +779,6 @@ class CVC5_EXPORT Sort
768779
*/
769780
bool isUninterpretedSortParameterized() const;
770781

771-
/**
772-
* @return the parameter sorts of an uninterpreted sort
773-
*/
774-
std::vector<Sort> getUninterpretedSortParamSorts() const;
775-
776782
/* Sort constructor sort ----------------------------------------------- */
777783

778784
/**
@@ -801,18 +807,6 @@ class CVC5_EXPORT Sort
801807

802808
/* Datatype sort ------------------------------------------------------- */
803809

804-
/**
805-
*
806-
* Return the parameters of a parametric datatype sort. If this sort is a
807-
* non-instantiated parametric datatype, this returns the parameter sorts of
808-
* the underlying datatype. If this sort is an instantiated parametric
809-
* datatype, then this returns the sort parameters that were used to
810-
* construct the sort via Sort::instantiate().
811-
*
812-
* @return the parameter sorts of a parametric datatype sort.
813-
*/
814-
std::vector<Sort> getDatatypeParamSorts() const;
815-
816810
/**
817811
* @return the arity of a datatype sort
818812
*/

src/api/java/io/github/cvc5/api/Sort.java

+17-30
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ public Datatype getDatatype()
399399
* @apiNote This method is experimental and may change in future versions.
400400
*
401401
* @param params the list of sort parameters to instantiate with
402+
* @return the instantiated sort
402403
*/
403404
public Sort instantiate(List<Sort> params)
404405
{
@@ -424,6 +425,22 @@ public Sort instantiate(Sort[] params)
424425

425426
private native long instantiate(long pointer, long[] paramsPointers);
426427

428+
/**
429+
* Get the sorts used to instantiate the sort parameters of a parametric
430+
* sort (parametric datatype or uninterpreted sort constructor sort,
431+
* see Sort.instantiate()).
432+
*
433+
* @return the sorts used to instantiate the sort parameters of a
434+
* parametric sort
435+
*/
436+
public Sort[] getInstantiatedParameters()
437+
{
438+
long[] pointers = getInstantiatedParameters(pointer);
439+
return Utils.getSorts(solver, pointers);
440+
}
441+
442+
private native long[] getInstantiatedParameters(long pointer);
443+
427444
/**
428445
* Substitution of Sorts.
429446
*
@@ -661,19 +678,6 @@ public Sort getSequenceElementSort()
661678

662679
private native long getSequenceElementSort(long pointer);
663680

664-
/* Uninterpreted sort -------------------------------------------------- */
665-
666-
/**
667-
* @return the parameter sorts of an uninterpreted sort
668-
*/
669-
public Sort[] getUninterpretedSortParamSorts()
670-
{
671-
long[] pointers = getUninterpretedSortParamSorts(pointer);
672-
return Utils.getSorts(solver, pointers);
673-
}
674-
675-
private native long[] getUninterpretedSortParamSorts(long pointer);
676-
677681
/* Sort constructor sort ----------------------------------------------- */
678682

679683
/**
@@ -722,23 +726,6 @@ public int getFloatingPointSignificandSize()
722726

723727
/* Datatype sort ------------------------------------------------------- */
724728

725-
/**
726-
* Return the parameters of a parametric datatype sort. If this sort is a
727-
* non-instantiated parametric datatype, this returns the parameter sorts of
728-
* the underlying datatype. If this sort is an instantiated parametric
729-
* datatype, then this returns the sort parameters that were used to
730-
* construct the sort via Sort.instantiate().
731-
*
732-
* @return the parameter sorts of a datatype sort
733-
*/
734-
public Sort[] getDatatypeParamSorts()
735-
{
736-
long[] pointers = getDatatypeParamSorts(pointer);
737-
return Utils.getSorts(solver, pointers);
738-
}
739-
740-
private native long[] getDatatypeParamSorts(long pointer);
741-
742729
/**
743730
* @return the arity of a datatype sort
744731
*/

src/api/java/jni/sort.cpp

+24-46
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,30 @@ Java_io_github_cvc5_api_Sort_isInstantiated(JNIEnv* env, jobject, jlong pointer)
468468
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, static_cast<jboolean>(false));
469469
}
470470

471+
/*
472+
* Class: io_github_cvc5_api_Sort
473+
* Method: getInstantiatedParameters
474+
* Signature: (J)[J
475+
*/
476+
JNIEXPORT jlongArray JNICALL
477+
Java_io_github_cvc5_api_Sort_getInstantiatedParameters(JNIEnv* env,
478+
jobject,
479+
jlong pointer)
480+
{
481+
CVC5_JAVA_API_TRY_CATCH_BEGIN;
482+
Sort* current = reinterpret_cast<Sort*>(pointer);
483+
std::vector<Sort> sorts = current->getInstantiatedParameters();
484+
std::vector<jlong> sortPointers(sorts.size());
485+
for (size_t i = 0; i < sorts.size(); i++)
486+
{
487+
sortPointers[i] = reinterpret_cast<jlong>(new Sort(sorts[i]));
488+
}
489+
jlongArray ret = env->NewLongArray(sorts.size());
490+
env->SetLongArrayRegion(ret, 0, sorts.size(), sortPointers.data());
491+
return ret;
492+
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
493+
}
494+
471495
/*
472496
* Class: io_github_cvc5_api_Sort
473497
* Method: getDatatype
@@ -840,30 +864,6 @@ JNIEXPORT jlong JNICALL Java_io_github_cvc5_api_Sort_getSequenceElementSort(
840864
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
841865
}
842866

843-
/*
844-
* Class: io_github_cvc5_api_Sort
845-
* Method: getUninterpretedSortParamSorts
846-
* Signature: (J)[J
847-
*/
848-
JNIEXPORT jlongArray JNICALL
849-
Java_io_github_cvc5_api_Sort_getUninterpretedSortParamSorts(JNIEnv* env,
850-
jobject,
851-
jlong pointer)
852-
{
853-
CVC5_JAVA_API_TRY_CATCH_BEGIN;
854-
Sort* current = reinterpret_cast<Sort*>(pointer);
855-
std::vector<Sort> sorts = current->getUninterpretedSortParamSorts();
856-
std::vector<jlong> sortPointers(sorts.size());
857-
for (size_t i = 0; i < sorts.size(); i++)
858-
{
859-
sortPointers[i] = reinterpret_cast<jlong>(new Sort(sorts[i]));
860-
}
861-
jlongArray ret = env->NewLongArray(sorts.size());
862-
env->SetLongArrayRegion(ret, 0, sorts.size(), sortPointers.data());
863-
return ret;
864-
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
865-
}
866-
867867
/*
868868
* Class: io_github_cvc5_api_Sort
869869
* Method: getUninterpretedSortConstructorArity
@@ -926,28 +926,6 @@ Java_io_github_cvc5_api_Sort_getFloatingPointSignificandSize(JNIEnv* env,
926926
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
927927
}
928928

929-
/*
930-
* Class: io_github_cvc5_api_Sort
931-
* Method: getDatatypeParamSorts
932-
* Signature: (J)[J
933-
*/
934-
JNIEXPORT jlongArray JNICALL Java_io_github_cvc5_api_Sort_getDatatypeParamSorts(
935-
JNIEnv* env, jobject, jlong pointer)
936-
{
937-
CVC5_JAVA_API_TRY_CATCH_BEGIN;
938-
Sort* current = reinterpret_cast<Sort*>(pointer);
939-
std::vector<Sort> sorts = current->getDatatypeParamSorts();
940-
std::vector<jlong> sortPointers(sorts.size());
941-
for (size_t i = 0; i < sorts.size(); i++)
942-
{
943-
sortPointers[i] = reinterpret_cast<jlong>(new Sort(sorts[i]));
944-
}
945-
jlongArray ret = env->NewLongArray(sorts.size());
946-
env->SetLongArrayRegion(ret, 0, sorts.size(), sortPointers.data());
947-
return ret;
948-
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
949-
}
950-
951929
/*
952930
* Class: io_github_cvc5_api_Sort
953931
* Method: getDatatypeArity

src/api/python/cvc5.pxd

+1-2
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ cdef extern from "api/cpp/cvc5.h" namespace "cvc5::api":
400400
bint isInstantiated() except +
401401
Datatype getDatatype() except +
402402
Sort instantiate(const vector[Sort]& params) except +
403+
vector[Sort] getInstantiatedParameters() except +
403404
Sort substitute(const vector[Sort] & es, const vector[Sort] & reps) except +
404405
size_t getConstructorArity() except +
405406
vector[Sort] getConstructorDomainSorts() except +
@@ -416,12 +417,10 @@ cdef extern from "api/cpp/cvc5.h" namespace "cvc5::api":
416417
Sort getSetElementSort() except +
417418
Sort getBagElementSort() except +
418419
Sort getSequenceElementSort() except +
419-
vector[Sort] getUninterpretedSortParamSorts() except +
420420
size_t getUninterpretedSortConstructorArity() except +
421421
uint32_t getBitVectorSize() except +
422422
uint32_t getFloatingPointExponentSize() except +
423423
uint32_t getFloatingPointSignificandSize() except +
424-
vector[Sort] getDatatypeParamSorts() except +
425424
size_t getDatatypeArity() except +
426425
size_t getTupleLength() except +
427426
vector[Sort] getTupleSorts() except +

src/api/python/cvc5.pxi

+17-29
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,7 @@ cdef class Sort:
28372837
versions.
28382838
28392839
:param params: the list of sort parameters to instantiate with
2840+
:return: the instantiated sort
28402841
"""
28412842
cdef Sort sort = Sort(self.solver)
28422843
cdef vector[c_Sort] v
@@ -2845,6 +2846,22 @@ cdef class Sort:
28452846
sort.csort = self.csort.instantiate(v)
28462847
return sort
28472848

2849+
def getInstantiatedParameters(self):
2850+
"""
2851+
Get the sorts used to instantiate the sort parameters of a
2852+
parametric sort (parametric datatype or uninterpreted sort
2853+
constructor sort, see Sort.instantiate()).
2854+
2855+
:return the sorts used to instantiate the sort parameters of a
2856+
parametric sort
2857+
"""
2858+
instantiated_sorts = []
2859+
for s in self.csort.getInstantiatedParameters():
2860+
sort = Sort(self.solver)
2861+
sort.csort = s
2862+
instantiated_sorts.append(sort)
2863+
return instantiated_sorts
2864+
28482865
def substitute(self, sort_or_list_1, sort_or_list_2):
28492866
"""
28502867
Substitution of Sorts.
@@ -3017,17 +3034,6 @@ cdef class Sort:
30173034
sort.csort = self.csort.getSequenceElementSort()
30183035
return sort
30193036

3020-
def getUninterpretedSortParamSorts(self):
3021-
"""
3022-
:return: the parameter sorts of an uninterpreted sort
3023-
"""
3024-
param_sorts = []
3025-
for s in self.csort.getUninterpretedSortParamSorts():
3026-
sort = Sort(self.solver)
3027-
sort.csort = s
3028-
param_sorts.append(sort)
3029-
return param_sorts
3030-
30313037
def getUninterpretedSortConstructorArity(self):
30323038
"""
30333039
:return: the arity of a sort constructor sort
@@ -3052,24 +3058,6 @@ cdef class Sort:
30523058
"""
30533059
return self.csort.getFloatingPointSignificandSize()
30543060

3055-
def getDatatypeParamSorts(self):
3056-
"""
3057-
Return the parameters of a parametric datatype sort. If this sort
3058-
is a non-instantiated parametric datatype, this returns the
3059-
parameter sorts of the underlying datatype. If this sort is an
3060-
instantiated parametric datatype, then this returns the sort
3061-
parameters that were used to construct the sort via
3062-
:py:meth:`instantiate()`.
3063-
3064-
:return: the parameter sorts of a parametric datatype sort
3065-
"""
3066-
param_sorts = []
3067-
for s in self.csort.getDatatypeParamSorts():
3068-
sort = Sort(self.solver)
3069-
sort.csort = s
3070-
param_sorts.append(sort)
3071-
return param_sorts
3072-
30733061
def getDatatypeArity(self):
30743062
"""
30753063
:return: the arity of a datatype sort

src/expr/type_node.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ std::vector<TypeNode> TypeNode::getInstantiatedParamTypes() const
364364
{
365365
Assert(isInstantiated());
366366
vector<TypeNode> params;
367-
for (uint32_t i = 1, i_end = getNumChildren(); i < i_end; ++i)
367+
for (uint32_t i = isInstantiatedDatatype() ? 1 : 0, i_end = getNumChildren();
368+
i < i_end;
369+
++i)
368370
{
369371
params.push_back((*this)[i]);
370372
}

0 commit comments

Comments
 (0)