# combine_x0_x1 Function

## public function combine_x0_x1(rdm_ind, x0, x1) result(comb)

### Arguments

Type IntentOptional Attributes Name
integer(kind=int_rdm), intent(in) :: rdm_ind
real(kind=dp), intent(in) :: x0
real(kind=dp), intent(in) :: x1

## Source Code

    function combine_x0_x1(rdm_ind, x0, x1) result(comb)
! this function combines the x0 and x1 coupling coefficient
! components correctly depending on the provided rdm_index
integer(int_rdm), intent(in) :: rdm_ind
real(dp), intent(in) :: x0, x1
real(dp) :: comb
debug_function_name("combine_x0_x1")
integer :: ex_lvl, ex_typ, i, j, k, l

ex_lvl = extract_excit_lvl_rdm(rdm_ind)
ex_typ = extract_excit_type_rdm(rdm_ind)

ASSERT(ex_lvl == 1 .or. ex_lvl == 2)
ASSERT(ex_typ /= excit_type%invalid)

if (ex_lvl == 1) then
ASSERT(near_zero(x1))
comb = x0
else if (ex_lvl == 2) then

select case (ex_typ)

! group together everything where x1 is 0
case (excit_type%single_overlap_L_to_R, &
excit_type%single_overlap_R_to_L, &
excit_type%fullstop_lowering, &
excit_type%fullstop_raising, &
excit_type%fullstart_raising, &
excit_type%fullstart_lowering, &
excit_type%fullstart_stop_alike)

ASSERT(near_zero(x1))
comb = x0

! group everything together where x0 is 0:
case (excit_type%fullstop_L_to_R, &
excit_type%fullstop_R_to_L, &
excit_type%fullstart_L_to_R, &
excit_type%fullstart_R_to_L, &
excit_type%fullstart_stop_mixed)

ASSERT(near_zero(x0))
comb = x1

case (excit_type%double_lowering, &
excit_type%double_raising)
! in these two cases i need to determine the sign influence
! from the generator ordering

call extract_2_rdm_ind(rdm_ind, i, j, k, l)
comb = x0 + generator_sign(i, j, k, l) * x1

case (excit_type%double_L_to_R_to_L, &
excit_type%double_R_to_L_to_R, &
excit_type%double_L_to_R, &
excit_type%double_R_to_L)
! i think for these cases i really need nothing..
comb = x0 + x1

case default
! should not be here!
! maybe in the future i should expand this
! by analysing the indices and producing all of them..
ASSERT(.false.)
end select

else
comb = 0.0_dp
end if

end function combine_x0_x1