|
1 | 1 | using Semgus.Model.Smt.Terms; |
2 | 2 | using Semgus.Model.Smt.Theories; |
3 | | - |
| 3 | +using System.Collections; |
4 | 4 | using System.Diagnostics.CodeAnalysis; |
5 | 5 |
|
6 | 6 | namespace Semgus.Model.Smt.Extensions |
@@ -94,6 +94,65 @@ internal SmtBitVectorsExtension(SmtCoreTheory core, SmtBitVectorsTheory bv) |
94 | 94 |
|
95 | 95 | }); |
96 | 96 |
|
| 97 | + sb.AddFn(name: "bvugt", |
| 98 | + val: SmtSourceBuilder.CheckArgumentSortsEqual, |
| 99 | + valCmt: "Argument sorts must be of the same size", |
| 100 | + retCalc: SmtSourceBuilder.UseFirstArgumentSort, |
| 101 | + bv0, |
| 102 | + bv0, |
| 103 | + bv0) |
| 104 | + .DefinitionMissing((ctx, fn, rank) => |
| 105 | + { |
| 106 | + SmtIdentifier bvult_id = new("bvult"); |
| 107 | + |
| 108 | + var a1_id = new SmtIdentifier("a1"); |
| 109 | + var a2_id = new SmtIdentifier("a2"); |
| 110 | + |
| 111 | + SmtScope scope = new(default); |
| 112 | + scope.TryAddVariableBinding(a1_id, rank.ArgumentSorts[0], SmtVariableBindingType.Lambda, ctx, out var a1_binding, out _); |
| 113 | + scope.TryAddVariableBinding(a2_id, rank.ArgumentSorts[1], SmtVariableBindingType.Lambda, ctx, out var a2_binding, out _); |
| 114 | + |
| 115 | + var a1 = new SmtVariable(a1_id, a1_binding!); |
| 116 | + var a2 = new SmtVariable(a2_id, a2_binding!); |
| 117 | + |
| 118 | + var b = new SmtTermBuilder(ctx); |
| 119 | + return b.Lambda(scope, |
| 120 | + b.Apply(bvult_id, a2, a1)); |
| 121 | + |
| 122 | + }); |
| 123 | + |
| 124 | + sb.AddFn(name: "bvsub", |
| 125 | + val: SmtSourceBuilder.CheckArgumentSortsEqual, |
| 126 | + valCmt: "Argument sorts must be of the same size", |
| 127 | + retCalc: SmtSourceBuilder.UseFirstArgumentSort, |
| 128 | + bv0, |
| 129 | + bv0, |
| 130 | + bv0) |
| 131 | + .DefinitionMissing((ctx, fn, rank) => |
| 132 | + { |
| 133 | + SmtIdentifier bvadd_id = new("bvadd"); |
| 134 | + SmtIdentifier bvnot_id = new("bvnot"); |
| 135 | + |
| 136 | + var a1_id = new SmtIdentifier("a1"); |
| 137 | + var a2_id = new SmtIdentifier("a2"); |
| 138 | + var c1_id = new SmtIdentifier("c1"); |
| 139 | + |
| 140 | + SmtScope scope = new(default); |
| 141 | + scope.TryAddVariableBinding(a1_id, rank.ArgumentSorts[0], SmtVariableBindingType.Lambda, ctx, out var a1_binding, out _); |
| 142 | + scope.TryAddVariableBinding(a2_id, rank.ArgumentSorts[1], SmtVariableBindingType.Lambda, ctx, out var a2_binding, out _); |
| 143 | + |
| 144 | + var a1 = new SmtVariable(a1_id, a1_binding!); |
| 145 | + var a2 = new SmtVariable(a2_id, a2_binding!); |
| 146 | + var c1 = new SmtBitVectorLiteral(ctx, new BitArray(new int[] { 1 })); |
| 147 | + |
| 148 | + var b = new SmtTermBuilder(ctx); |
| 149 | + // 2's complement |
| 150 | + return b.Lambda(scope, |
| 151 | + b.Apply(bvadd_id, b.Apply(bvadd_id, a1, b.Apply(bvnot_id, a2)), |
| 152 | + c1)); |
| 153 | + |
| 154 | + }); |
| 155 | + |
97 | 156 | Functions = sb.Functions; |
98 | 157 | PrimaryFunctionSymbols = sb.PrimaryFunctionSymbols; |
99 | 158 | } |
|
0 commit comments