:- module(flocks,[]). %% converted djd
:- style_check(-singleton). % added djd
%% :- module('flocks', []).

:- discontiguous 'flocks.delNthElement.p4'/4. %% added djd
:- discontiguous '~flocks.delNthElement.p4'/4. %% added djd
:- discontiguous 'flocks.insNthElement.p4'/4. %% added djd
:- discontiguous '~flocks.insNthElement.p4'/4. %% added djd
:- discontiguous 'flocks.nthElement.p3'/3. %% added djd
:- discontiguous '~flocks.nthElement.p3'/3. %% added djd


:- op(500, yfx, and).
:- op(400, yfx, or).

'flocks.extent.p2'(A, B) :-
        user:goedel_freeze(ground([A]), 'flocks':'flocks.extent.p2.0'(A,B)).
'~flocks.extent.p2'(A, B) :-
        user:goedel_freeze(ground([A]), 'flocks':'~flocks.extent.p2.0'(A,B)).
'flocks.extent.p2.0'('flocks.flock.f1'(A), B) :-
        'lists':'lists.length.p2'(A, B).
'~flocks.extent.p2.0'('flocks.flock.f1'(A), B) :-
        'lists':'~lists.length.p2'(A, B).
'flocks.deleteUnit.p4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'flocks':'flocks.deleteUnit.p4.0'(A,B,C,D)).
'~flocks.deleteUnit.p4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'flocks':'~flocks.deleteUnit.p4.0'(A,B,C,D)).
'flocks.deleteUnit.p4.0'('flocks.flock.f1'(A), B, C, 'flocks.flock.f1'(D)) :-
        'flocks.delNthElement.p4'(A, C, B, D).
'~flocks.deleteUnit.p4.0'('flocks.flock.f1'(A), B, C, 'flocks.flock.f1'(D)) :-
        '~flocks.delNthElement.p4'(A, C, B, D).
'flocks.delNthElement.p4'([A|B], 1, A, B).
'~flocks.delNthElement.p4'([A|B], 1, A, B).
'flocks.delNthElement.p4'([A|B], C, D, [A|E]) :-
        'integers':'integers.>.p2'(C, 1),
        'integers':minus(C, 1, F),
        'flocks.delNthElement.p4'(B, F, D, E).
'~flocks.delNthElement.p4'([A|B], C, D, [A|E]) :-
        'integers':'~integers.>.p2'(C, 1),
        'integers':minus(C, 1, F),
        '~flocks.delNthElement.p4'(B, F, D, E).
'flocks.emptyFlock.p1'('flocks.flock.f1'([])).
'~flocks.emptyFlock.p1'('flocks.flock.f1'([])).
'flocks.unitInFlock.p3'(A, B, C) :-
        user:goedel_freeze(ground([A]), 'flocks':'flocks.unitInFlock.p3.0'(A,B,C)).
'~flocks.unitInFlock.p3'(A, B, C) :-
        user:goedel_freeze(ground([A]), 'flocks':'~flocks.unitInFlock.p3.0'(A,B,C)).
'flocks.unitInFlock.p3.0'('flocks.flock.f1'(A), B, C) :-
        'flocks.nthElement.p3'(A, C, B).
'~flocks.unitInFlock.p3.0'('flocks.flock.f1'(A), B, C) :-
        '~flocks.nthElement.p3'(A, C, B).
'flocks.insertUnit.p4'(A, B, C, D) :-
        user:goedel_freeze(ground([A,B,C]), 'flocks':'flocks.insertUnit.p4.0'(A,B,C,D)).
'~flocks.insertUnit.p4'(A, B, C, D) :-
        user:goedel_freeze(ground([A,B,C]), 'flocks':'~flocks.insertUnit.p4.0'(A,B,C,D)).
'flocks.insertUnit.p4.0'('flocks.flock.f1'(A), B, C, 'flocks.flock.f1'(D)) :-
        'flocks.insNthElement.p4'(A, C, B, D).
'~flocks.insertUnit.p4.0'('flocks.flock.f1'(A), B, C, 'flocks.flock.f1'(D)) :-
        '~flocks.insNthElement.p4'(A, C, B, D).
'flocks.insNthElement.p4'(A, 1, B, [B|A]) :- !.
'~flocks.insNthElement.p4'(A, 1, B, [B|A]).
'flocks.insNthElement.p4'([A|B], C, D, [A|E]) :-
        call_residue('integers':'integers.>.p2'(C,1), F),
        (   F=[] ->
            !
        ;   user:release_suspended(F)
        ),
        'integers':minus(C, 1, G),
        'flocks.insNthElement.p4'(B, G, D, E).
'~flocks.insNthElement.p4'([A|B], C, D, [A|E]) :-
        'integers':'~integers.>.p2'(C, 1),
        'integers':minus(C, 1, F),
        '~flocks.insNthElement.p4'(B, F, D, E).
'flocks.nthElement.p3'([A|_], 1, A).
'~flocks.nthElement.p3'([A|_], 1, A).
'flocks.nthElement.p3'([_|A], B, C) :-
        'integers':'integers.>.p2'(B, 1),
        'integers':minus(B, 1, D),
        'flocks.nthElement.p3'(A, D, C).
'~flocks.nthElement.p3'([_|A], B, C) :-
        'integers':'~integers.>.p2'(B, 1),
        'integers':minus(B, 1, D),
        '~flocks.nthElement.p3'(A, D, C).
'flocks.unitWithIdentifier.p4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'flocks':'flocks.unitWithIdentifier.p4.0'(A,B,C,D)).
'~flocks.unitWithIdentifier.p4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'flocks':'~flocks.unitWithIdentifier.p4.0'(A,B,C,D)).
'flocks.unitWithIdentifier.p4.0'('flocks.flock.f1'(A), B, C, D) :-
        'flocks.nthElement.p3'(A, D, C),
        'units':'units.unitParts.p3'(C, B, _).
'~flocks.unitWithIdentifier.p4.0'('flocks.flock.f1'(A), B, C, D) :-
        '~flocks.nthElement.p3'(A, D, C),
        'units':'~units.unitParts.p3'(C, B, _).
