<commit_before>
:- object(breadth_first(Bound),
	instantiates(blind_search(Bound))).

	:- info([
		version is 1.4,
		author is '<NAME>; adapted to Logtalk by <NAME>.',
		date is 2010/06/23,
		comment is 'Breadth first state space search strategy.',
		source is 'Code adapted from the book "Prolog Programming for Artificial Intelligence" by <NAME>.',
		parnames is ['Bound']]).

	:- uses(list, [member/2, reverse/2]).

	search(Space, State, Bound, Solution) :-
		breadth(Space, l(State), Bound, Path),
		reverse(Path, Solution).

	breadth(Space, Tree, Bound, Solution) :-
		expand([], Tree, Tree2, Solved, Solution, Space, Bound),
		(	Solved == true ->
			true
		;	breadth(Space, Tree2, Bound, Solution)
		).

	expand(Path, l(State), _, true, [State| Path], Space, _) :-
		Space::goal_state(State).
	expand(Path, l(State), t(State, Subs), fail, _, Space, Bound) :-
		Bound > 0,
		bagof(l(Next), (Space::next_state(State, Next), \+ Space::member_path(Next, [State| Path])), Subs).
	expand(Path, t(State,Subs), t(State, Subs2), Solved, Solution, Space, Bound) :-
		expandall([State| Path], Subs, [], Subs2, Solved, Solution, Space, Bound).

	expandall(_, [], [Tree| Trees], [Tree| Trees], fail, _, _, _).
	expandall(Path, [Tree| Trees], Trees2, Subs2, Solved, Solution, Space, Bound) :-
		(	Bound > 0,
			Bound2 is Bound -1,
			expand(Path, Tree, Tree2, Solved2, Solution, Space, Bound2),
			(	Solved2 == true ->
				Solved = true
			;	expandall(Path, Trees, [Tree2| Trees2], Subs2, Solved, Solution, Space, Bound)
			)
		;	expandall(Path, Trees, Trees2, Subs2, Solved, Solution, Space, Bound)
		).

:- end_object.
<commit_msg>Fixed an arithmetic expression in the "searching" example in order to avoid a syntax error with Lean Prolog.<commit_after>
:- object(breadth_first(Bound),
	instantiates(blind_search(Bound))).

	:- info([
		version is 1.4,
		author is '<NAME>; adapted to Logtalk by <NAME>.',
		date is 2010/06/23,
		comment is 'Breadth first state space search strategy.',
		source is 'Code adapted from the book "Prolog Programming for Artificial Intelligence" by <NAME>.',
		parnames is ['Bound']]).

	:- uses(list, [member/2, reverse/2]).

	search(Space, State, Bound, Solution) :-
		breadth(Space, l(State), Bound, Path),
		reverse(Path, Solution).

	breadth(Space, Tree, Bound, Solution) :-
		expand([], Tree, Tree2, Solved, Solution, Space, Bound),
		(	Solved == true ->
			true
		;	breadth(Space, Tree2, Bound, Solution)
		).

	expand(Path, l(State), _, true, [State| Path], Space, _) :-
		Space::goal_state(State).
	expand(Path, l(State), t(State, Subs), fail, _, Space, Bound) :-
		Bound > 0,
		bagof(l(Next), (Space::next_state(State, Next), \+ Space::member_path(Next, [State| Path])), Subs).
	expand(Path, t(State,Subs), t(State, Subs2), Solved, Solution, Space, Bound) :-
		expandall([State| Path], Subs, [], Subs2, Solved, Solution, Space, Bound).

	expandall(_, [], [Tree| Trees], [Tree| Trees], fail, _, _, _).
	expandall(Path, [Tree| Trees], Trees2, Subs2, Solved, Solution, Space, Bound) :-
		(	Bound > 0,
			Bound2 is Bound - 1,
			expand(Path, Tree, Tree2, Solved2, Solution, Space, Bound2),
			(	Solved2 == true ->
				Solved = true
			;	expandall(Path, Trees, [Tree2| Trees2], Subs2, Solved, Solution, Space, Bound)
			)
		;	expandall(Path, Trees, Trees2, Subs2, Solved, Solution, Space, Bound)
		).

:- end_object.

{'fraction_non_alphanumeric': 0.17244471010161386, 'fraction_numerical': 0.01852958756724447, 'mean_word_length': 4.262578616352202, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1993818', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1178, 'n_words': 343}