mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	new permutation invariant
This commit is contained in:
		
							parent
							
								
									751ef0561b
								
							
						
					
					
						commit
						d5a3716e77
					
				
					 1 changed files with 9 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -36,6 +36,7 @@ void permutation::swap(unsigned i, unsigned j) noexcept {
 | 
			
		|||
    unsigned j_prime = m_p[j];
 | 
			
		||||
    std::swap(m_p[i], m_p[j]);
 | 
			
		||||
    std::swap(m_inv_p[i_prime], m_inv_p[j_prime]); 
 | 
			
		||||
    SASSERT(check_invariant());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -66,11 +67,19 @@ void permutation::display(std::ostream & out) const {
 | 
			
		|||
bool permutation::check_invariant() const {
 | 
			
		||||
    SASSERT(m_p.size() == m_inv_p.size());
 | 
			
		||||
    unsigned n = m_p.size();
 | 
			
		||||
    std::vector<bool> check_vector(n, false); // To check for duplicate and out-of-range values
 | 
			
		||||
    for (unsigned i = 0; i < n; i++) {
 | 
			
		||||
        unsigned pi = m_p[i];
 | 
			
		||||
        SASSERT(m_p[i] < n);
 | 
			
		||||
        SASSERT(m_inv_p[i] < n);
 | 
			
		||||
        SASSERT(m_p[m_inv_p[i]] == i);
 | 
			
		||||
        SASSERT(m_inv_p[m_p[i]] == i);
 | 
			
		||||
        // Check the inversion hasn't been checked yet
 | 
			
		||||
        if (check_vector[pi]) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        // Mark this value as checked
 | 
			
		||||
        check_vector[pi] = true;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue