Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend_to_inplace and shrink_to_inplace. #47

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ v0.4 (not yet released)
`#43 <https://github.com/msoeken/kitty/pull/43>`_
`#45 <https://github.com/msoeken/kitty/pull/45>`_

* Operations: ``shrink_to``
* Operations: ``shrink_to`` and ``shrink_to_inplace``
`#42 <https://github.com/msoeken/kitty/pull/42>`_
`#47 <https://github.com/msoeken/kitty/pull/47>`_

* Operation ``extend_to`` is now called ``extend_to_inplace``, new special out-of-place versions ``extend_to``
`#47 <https://github.com/msoeken/kitty/pull/47>`_

* CNF generation: ``cnf_characteristic``
`#41 <https://github.com/msoeken/kitty/pull/41>`_
Expand Down
2 changes: 2 additions & 0 deletions docs/operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Combination and manipulation
flip
min_base_inplace
expand_inplace
extend_to_inplace
extend_to
shrink_to_inplace
shrink_to
shift_left_inplace
shift_left
Expand Down
2 changes: 1 addition & 1 deletion include/kitty/constructors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ inline void create_characteristic( TT& tt, const TTFrom& from )
create_nth_var( var, from.num_vars() );

auto ext = tt.construct();
extend_to( ext, from );
extend_to_inplace( ext, from );

tt = ~var ^ ext;
}
Expand Down
37 changes: 19 additions & 18 deletions include/kitty/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ void expand_inplace( TT& tt, const std::vector<uint8_t>& support )
\param from Smaller truth table to copy from
*/
template<typename TT, typename TTFrom>
void extend_to( TT& tt, const TTFrom& from )
void extend_to_inplace( TT& tt, const TTFrom& from )
{
assert( tt.num_vars() >= from.num_vars() );

Expand All @@ -711,34 +711,35 @@ void extend_to( TT& tt, const TTFrom& from )

/*! \brief Extends smaller truth table to larger static one

This is a special version of `extend_to` that has the truth table as a return
value. It only works for creating static truth tables. The template
parameter `NumVars` must be equal or larger to the number of variables in
`from`.
This is an out-of-place version of `extend_to_inplace` that has the truth
table as a return value. It only works for creating static truth tables. The
template parameter `NumVars` must be equal or larger to the number of
variables in `from`.

\param from Smaller truth table to copy from
*/
template<int NumVars, typename TTFrom>
inline static_truth_table<NumVars> extend_to( const TTFrom& from )
{
static_truth_table<NumVars> tt;
extend_to( tt, from );
extend_to_inplace( tt, from );
return tt;
}

/*! \brief Extends smaller truth table to larger dynamic one

This is a special version of `extend_to` that has the truth table as a return
value. It only works for creating dynamic truth tables. The parameter
`num_vars` must be equal or larger to the number of variables in `from`.
This is an out-of-place version of `extend_to_inplace` that has the truth
table as a return value. It only works for creating dynamic truth tables.
The parameter `num_vars` must be equal or larger to the number of variables in
`from`.

\param from Smaller truth table to copy from
*/
template<typename TTFrom>
inline dynamic_truth_table extend_to( const TTFrom& from, unsigned num_vars )
{
auto tt = create<dynamic_truth_table>( num_vars );
extend_to( tt, from );
extend_to_inplace( tt, from );
return tt;
}

Expand All @@ -752,7 +753,7 @@ inline dynamic_truth_table extend_to( const TTFrom& from, unsigned num_vars )
\param from Larger truth table to copy from
*/
template<typename TT, typename TTFrom>
void shrink_to( TT& tt, const TTFrom& from )
void shrink_to_inplace( TT& tt, const TTFrom& from )
{
assert( tt.num_vars() <= from.num_vars() );

Expand All @@ -766,8 +767,8 @@ void shrink_to( TT& tt, const TTFrom& from )

/*! \brief Shrinks larger truth table to smaller static one

This is a special version of `shrink_to` that has the truth table as a return
value. It only works for creating static truth tables. The template
This is an out-of-place version of `shrink_to` that has the truth table as a
return value. It only works for creating static truth tables. The template
parameter `NumVars` must be equal or smaller to the number of variables in
`from`.

Expand All @@ -777,23 +778,23 @@ template<int NumVars, typename TTFrom>
inline static_truth_table<NumVars> shrink_to( const TTFrom& from )
{
static_truth_table<NumVars> tt;
shrink_to( tt, from );
shrink_to_inplace( tt, from );
return tt;
}

/*! \brief Shrinks larger truth table to smaller dynamic one

This is a special version of `shrink_to` that has the truth table as a return
value. It only works for creating dynamic tables. The parameter `num_vars`
must be equal or smaller to the number of variables in `from`.
This is an out-of-place version of `shrink_to` that has the truth table as a
return value. It only works for creating dynamic tables. The parameter
`num_vars` must be equal or smaller to the number of variables in `from`.

\param from Smaller truth table to copy from
*/
template<typename TTFrom>
inline dynamic_truth_table shrink_to( const TTFrom& from, unsigned num_vars )
{
auto tt = create<dynamic_truth_table>( num_vars );
shrink_to( tt, from );
shrink_to_inplace( tt, from );
return tt;
}

Expand Down
16 changes: 8 additions & 8 deletions test/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ TEST_F( OperationsTest, extend_to )

create_majority( maj );
create_threshold( th, 4 );
extend_to( th_extend, th );
extend_to_inplace( th_extend, th );

EXPECT_EQ( cofactor0( maj, 8 ), th_extend );

Expand All @@ -494,7 +494,7 @@ TEST_F( OperationsTest, extend_to_same )
static_truth_table<9> tt1, tt2;

create_random( tt1 );
extend_to( tt2, tt1 );
extend_to_inplace( tt2, tt1 );

EXPECT_EQ( tt1, tt2 );
}
Expand Down Expand Up @@ -611,7 +611,7 @@ void majority_decomposition_acw( TT& f1, TT& f2 )

dynamic_truth_table lhs( 2 * k - 1 );
create_majority( lhs );
extend_to( f1, lhs );
extend_to_inplace( f1, lhs );

dynamic_truth_table rhs1( 2 * k - 1 );
dynamic_truth_table rhs2( 2 * k - 1 );
Expand All @@ -621,8 +621,8 @@ void majority_decomposition_acw( TT& f1, TT& f2 )

auto rhs1_e = f2.construct();
auto rhs2_e = f2.construct();
extend_to( rhs1_e, rhs1 );
extend_to( rhs2_e, rhs2 );
extend_to_inplace( rhs1_e, rhs1 );
extend_to_inplace( rhs2_e, rhs2 );

create_nth_var( f2, 2 * k - 1 );

Expand Down Expand Up @@ -703,7 +703,7 @@ TEST_F( OperationsTest, majority_odd_conjecture )
static_truth_table<n - 2> f1_m3;
create_majority( f1_m3 );
static_truth_table<n - 1> f1;
extend_to( f1, f1_m3 );
extend_to_inplace( f1, f1_m3 );

/* create f2 */
static_truth_table<n - 1> f2, rem;
Expand All @@ -726,8 +726,8 @@ TEST_F( OperationsTest, majority_odd_conjecture )

/* create majority */
static_truth_table<n> f1_e, f2_e;
extend_to( f1_e, f1 );
extend_to( f2_e, f2 );
extend_to_inplace( f1_e, f1 );
extend_to_inplace( f2_e, f2 );

EXPECT_EQ( maj, ternary_majority( nth<n>( n - 1 ), f1_e, f2_e ) );
}