@dimod.decorators.vartype_argument('<STR_LIT>')<EOL>def halfadder_gate(variables, vartype=dimod.BINARY, name='<STR_LIT>'):
variables = tuple(variables)<EOL>if vartype is dimod.BINARY:<EOL><INDENT>configs = frozenset([(<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>),<EOL>(<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:0>),<EOL>(<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>),<EOL>(<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>)])<EOL><DEDENT>else:<EOL><INDENT>configs = frozenset([(-<NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>),<EOL>(-<NUM_LIT:1>, +<NUM_LIT:1>, +<NUM_LIT:1>, -<NUM_LIT:1>),<EOL>(+<NUM_LIT:1>, -<NUM_LIT:1>, +<NUM_LIT:1>, -<NUM_LIT:1>),<EOL>(+<NUM_LIT:1>, +<NUM_LIT:1>, -<NUM_LIT:1>, +<NUM_LIT:1>)])<EOL><DEDENT>def func(augend, addend, sum_, carry):<EOL><INDENT>total = (augend > <NUM_LIT:0>) + (addend > <NUM_LIT:0>)<EOL>if total == <NUM_LIT:0>:<EOL><INDENT>return (sum_ <= <NUM_LIT:0>) and (carry <= <NUM_LIT:0>)<EOL><DEDENT>elif total == <NUM_LIT:1>:<EOL><INDENT>return (sum_ > <NUM_LIT:0>) and (carry <= <NUM_LIT:0>)<EOL><DEDENT>elif total == <NUM_LIT:2>:<EOL><INDENT>return (sum_ <= <NUM_LIT:0>) and (carry > <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>return Constraint(func, configs, variables, vartype=vartype, name=name)<EOL>
Half adder.

    Args:
        variables (list): Variable labels for the and gate as `[in1, in2, sum, carry]`,
            where `in1, in2` are inputs to be added and `sum` and 'carry' the resultant
            outputs.
        vartype (Vartype, optional, default='BINARY'): Variable type. Accepted
            input values:

            * Vartype.SPIN, 'SPIN', {-1, 1}
            * Vartype.BINARY, 'BINARY', {0, 1}
        name (str, optional, default='HALF_ADDER'): Name for the constraint.

    Returns:
        Constraint(:obj:`.Constraint`): Constraint that is satisfied when its variables are
        assigned values that match the valid states of a Boolean half adder.

    Examples:
        >>> import dwavebinarycsp
        >>> import dwavebinarycsp.factories.constraint.gates as gates
        >>> csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY)
        >>> csp.add_constraint(gates.halfadder_gate(['a', 'b', 'total', 'carry'], name='HA1'))
        >>> csp.check({'a': 1, 'b': 1, 'total': 0, 'carry': 1})
        True