-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from Shoooooon/main
Support parametric sorts in the JSON format (and initial ArraysEx support)
- Loading branch information
Showing
9 changed files
with
270 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(declare-term-types | ||
((E 0) (Start 0)) | ||
((($IBVVary ) | ||
($bvsub E E) | ||
($bvadd E E) | ||
($IBVVarx )) | ||
(($bv=x E)))) | ||
|
||
|
||
|
||
(define-funs-rec | ||
((E.Sem ((E_term_0 E) (r__0 (_ BitVec 32)) (rv (Array Int Int)) (x (_ BitVec 32)) (y (_ BitVec 32))) Bool) | ||
(Start.Sem ((Start_term_0 Start) (x_r0 (_ BitVec 32)) (y_r0 (_ BitVec 32)) (rq (Array Int Int)) (x (_ BitVec 32)) (y (_ BitVec 32))) Bool)) | ||
|
||
((match E_term_0 | ||
(($IBVVary (exists ((r__1 (_ BitVec 32))) (and (= r__0 r__1) | ||
(= r__1 y)))) | ||
(($bvsub E_term_1 E_term_2) (exists ((r__1 (_ BitVec 32)) (r__2 (_ BitVec 32)) (rb (Array Int Int))) (and (= r__0 (bvadd r__1 (bvneg r__2))) | ||
(E.Sem E_term_1 r__1 rb x y) | ||
(E.Sem E_term_2 r__2 rb x y)))) | ||
(($bvadd E_term_1 E_term_2) (exists ((r__1 (_ BitVec 32)) (r__2 (_ BitVec 32)) (rb (Array Int Int))) (and (= r__0 (bvadd r__1 r__2)) | ||
(E.Sem E_term_1 r__1 rb x y) | ||
(E.Sem E_term_2 r__2 rb x y)))) | ||
($IBVVarx (exists ((r__1 (_ BitVec 32))) (and (= r__0 r__1) | ||
(= r__1 x)))))) | ||
(match Start_term_0 | ||
((($bv=x E_term_1) (exists ((r__1 (_ BitVec 32)) (rb (Array Int Int))) (and (and (= x_r0 r__1) | ||
(and (= rb rb) (= y y_r0))) | ||
(E.Sem E_term_1 r__1 rb x y)))))))) | ||
|
||
|
||
(synth-fun BVtest_ADD_01() Start) | ||
|
||
|
||
(constraint (exists ((rq (Array Int Int)) (y (_ BitVec 32))) (Start.Sem BVtest_ADD_01 #x00000004 #x00000004 rq #x00000003 y))) | ||
|
||
(check-synth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--format | ||
json | ||
--mode | ||
batch | ||
-- | ||
data/array.sem |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
using Semgus.Model.Smt.Terms; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using static Semgus.Model.Smt.SmtCommonIdentifiers; | ||
|
||
namespace Semgus.Model.Smt.Theories | ||
{ | ||
/// <summary> | ||
/// The theory of arrays with extensions | ||
/// </summary> | ||
internal class SmtArraysExTheory : ISmtTheory | ||
{ | ||
/// <summary> | ||
/// A singleton theory instance | ||
/// </summary> | ||
public static SmtArraysExTheory Instance { get; } = new(); | ||
|
||
/// <summary> | ||
/// Underlying array sort | ||
/// </summary> | ||
internal sealed class ArraySort : SmtSort | ||
{ | ||
/// <summary> | ||
/// Cache of instantiated sorts. We need this since sorts are compared by reference | ||
/// </summary> | ||
private static readonly IDictionary<(SmtSortIdentifier, SmtSortIdentifier), ArraySort> _sortCache | ||
= new Dictionary<(SmtSortIdentifier, SmtSortIdentifier), ArraySort>(); | ||
|
||
/// <summary> | ||
/// The sort used for indexing the array | ||
/// </summary> | ||
public SmtSort IndexSort { get; private set; } | ||
|
||
/// <summary> | ||
/// The sort used for the array element values | ||
/// </summary> | ||
public SmtSort ValueSort { get; private set; } | ||
|
||
/// <summary> | ||
/// Constructs a new array sort with the given parameters | ||
/// </summary> | ||
/// <param name="size">Size of bit vectors in this sort</param> | ||
private ArraySort(SmtSortIdentifier indexSort, SmtSortIdentifier valueSort) : | ||
base(new(new SmtIdentifier(ArraySortPrimaryId.Symbol), indexSort, valueSort)) | ||
{ | ||
IndexSort = new UnresolvedParameterSort(indexSort); | ||
ValueSort = new UnresolvedParameterSort(valueSort); | ||
IsParametric = true; | ||
Arity = 2; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the array sort for the given index and value sorts | ||
/// </summary> | ||
/// <param name="index">The index sort to use</param> | ||
/// <param name="value">The value sort to use</param> | ||
/// <returns>The array sort for the given index and value sorts</returns> | ||
public static ArraySort GetSort(SmtSortIdentifier index, SmtSortIdentifier value) | ||
{ | ||
if (_sortCache.TryGetValue((index, value), out ArraySort? sort)) | ||
{ | ||
return sort; | ||
} | ||
else | ||
{ | ||
sort = new ArraySort(index, value); | ||
_sortCache.Add((index, value), sort); | ||
return sort; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Updates this sort with the resolved parameteric sorts | ||
/// </summary> | ||
/// <param name="resolved">Resolved parameters. Must have arity 2</param> | ||
public override void UpdateForResolvedParameters(IList<SmtSort> resolved) | ||
{ | ||
if (resolved.Count != 2) | ||
{ | ||
throw new InvalidOperationException("Got list of resolved sorts not of length 2!"); | ||
} | ||
|
||
IndexSort = resolved[0]; | ||
ValueSort = resolved[1]; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// This theory's name | ||
/// </summary> | ||
public SmtIdentifier Name { get; } = ArraysExTheoryId; | ||
|
||
#region Deprecated | ||
public IReadOnlyDictionary<SmtIdentifier, IApplicable> Functions { get; } | ||
#endregion | ||
|
||
/// <summary> | ||
/// The primary (i.e., non-indexed) sort symbols (e.g., "Array") | ||
/// </summary> | ||
public IReadOnlySet<SmtIdentifier> PrimarySortSymbols { get; } | ||
|
||
/// <summary> | ||
/// The primary (i.e., non-indexed) function symbols | ||
/// </summary> | ||
public IReadOnlySet<SmtIdentifier> PrimaryFunctionSymbols { get; } | ||
|
||
/// <summary> | ||
/// Constructs an instance of the theory of arrays | ||
/// </summary> | ||
/// <param name="core">Reference to the core theory</param> | ||
private SmtArraysExTheory() | ||
{ | ||
SmtSourceBuilder sb = new(this); | ||
sb.AddOnTheFlyFn("select"); | ||
sb.AddOnTheFlyFn("store"); | ||
|
||
Functions = sb.Functions; | ||
PrimaryFunctionSymbols = sb.PrimaryFunctionSymbols; | ||
PrimarySortSymbols = new HashSet<SmtIdentifier>() { ArraySortPrimaryId }; | ||
} | ||
|
||
/// <summary> | ||
/// Looks up a sort symbol in this theory | ||
/// </summary> | ||
/// <param name="sortId">The sort ID</param> | ||
/// <param name="resolvedSort">The resolved sort</param> | ||
/// <returns>True if successfully gotten</returns> | ||
public bool TryGetSort(SmtSortIdentifier sortId, [NotNullWhen(true)] out SmtSort? resolvedSort) | ||
{ | ||
if (sortId.Arity == 2 && sortId.Name == ArraySortPrimaryId) | ||
{ | ||
resolvedSort = ArraySort.GetSort(sortId.Parameters[0], sortId.Parameters[1]); | ||
return true; | ||
} | ||
resolvedSort = default; | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Looks up a function in this theory | ||
/// </summary> | ||
/// <param name="functionId">The function ID to look up</param> | ||
/// <param name="resolvedFunction">The resolved function</param> | ||
/// <returns>True if successfully gotten</returns> | ||
public bool TryGetFunction(SmtIdentifier functionId, [NotNullWhen(true)] out IApplicable? resolvedFunction) | ||
{ | ||
return Functions.TryGetValue(functionId, out resolvedFunction); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters