// BoolLevel.code




bool scaneRowOfIsBool(var row){
	i=0;
	for(;i<row->size();++i)if(typeof((*row)[i])!="bool")return 0;
	return 1;
}



var getBasisPredecatsTypes(){
	Q={
		"void","bool","int","float","double","digit","string",
		"char","vector","set","map","program","graph","function"
		};
	R={};
	i=0;
	for(;i<Q.size();++i)R.push(PROGRAM("typeof(x)=="+Q[i].export()));
	Q={"int","float","double","digit"};
	R.push(PROGRAM(Q.export()+".find(typeof(x))>=0"));
	R.push(PROGRAM("((set)v).size()<2"));
	R.push(PROGRAM("((set)v).size()==1"));
	return R;
}



bool BoolLevel(var sys){
	if(!scaneRowOfIsBool(&sys->outputs))return 0;
	R=getBasisPredecatsTypes();
	if(sys->namesinput.size()==1){
		SovpaloP={};
		i=0;
		for(;i<R.size();++i){
			P=R[i];
			names=P.getNames(1);
			P.replace(names[0],"U");
			P2=PROGRAM("!#");
			P2.setSub({0},P);
			Result={};
			Result2={};
			t=0;
			for(;t<sys->inputs.size();++t){
				U=(sys->inputs)[t];
				Result.push(eval(P));
				Result2.push(eval(P2));
				}
			if(Result!=sys->outputs&&Result2!=sys->outputs);else {
				if(Result2==sys->outputs)P=P2;
				SovpaloP.push(P);
				}
			}
		if(SovpaloP.size()){
			Powers={};
			i=0;
			for(;i<SovpaloP.size();++i)Powers.push(SovpaloP[i].getPower());
			P=SovpaloP[Powers.find(Powers.min())];
			P.replace("U",(sys->namesinput)[0]);
			P2=PROGRAM("return #");
			P2.setSub({0},P);
			Xfunct={inputnames:sys->namesinput,name:(*sys)["имя программы"],outputnames:(sys->namesoutput)[0],program:P2};
			sys->functions.push(Xfunct);
			return 1;
			}
		}
	return 0;
}


// BoolLevel.code	:-|