* Check constraint expression for multi-index sequences. * Returns true if constraints are satisfied or no constraints exist.
( ce: ComputeEngine, constraints: Expression, variables: string[], indices: number[] )
| 232 | if (constraint.max !== undefined && index > constraint.max) return false; |
| 233 | } |
| 234 | } |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Check constraint expression for multi-index sequences. |
| 240 | * Returns true if constraints are satisfied or no constraints exist. |
| 241 | */ |
| 242 | function checkConstraints( |
| 243 | ce: ComputeEngine, |
| 244 | constraints: Expression, |
| 245 | variables: string[], |
| 246 | indices: number[] |
| 247 | ): boolean { |
| 248 | // Substitute variable values |
| 249 | const subs: Record<string, Expression> = {}; |
| 250 | for (let i = 0; i < variables.length; i++) { |
| 251 | subs[variables[i]] = ce.number(indices[i]); |
| 252 | } |
| 253 | |
| 254 | const substituted = constraints.subs(subs); |
| 255 | const result = substituted.evaluate(); |
| 256 | |
| 257 | // Check if result is truthy (non-zero number or True) |
| 258 | if (isSymbol(result)) { |
| 259 | if (result.symbol === 'True') return true; |
| 260 | if (result.symbol === 'False') return false; |
| 261 | } |