public function rename_variable(string this_one, string to_that) { ArrayList old_args = new ArrayList(_arguments); ArrayList new_args = new ArrayList(); while (old_args.Count > 0) { if (old_args[0] is function) { function fun = new function((function)old_args[0]); old_args[0] = fun.rename_variable(this_one, to_that); } else if ((string)old_args[0] == this_one) { new_args.Add(to_that); } else { new_args.Add(old_args[0]); } old_args.RemoveAt(0); } function f = new function(name, new_args); return(f); }
public formula rename_variable(string that_one, string to_this_one) { formula new_expression = new formula(); if (!this.is_Predicate) { if (top_operation is dis) { new_expression = first_operand.rename_variable(that_one, to_this_one) | second_operand.rename_variable(that_one, to_this_one); } else if (top_operation is kon) { new_expression = first_operand.rename_variable(that_one, to_this_one) & second_operand.rename_variable(that_one, to_this_one); } else if (top_operation is quantifier) { new_expression = this; new_expression = new_expression.first_operand.rename_variable(that_one, to_this_one); new_expression.logical_exp.Insert(0, top_operation); return(new_expression); } //скорее всего здесь предикатное выражение, посему: if (first_operand.is_Predicate) { Predicate Pred = new Predicate((Predicate)first_operand.logical_exp[0]); for (int i = 0; i < Pred.arguments.Count; i++) { if ((string)Pred.arguments[i] == that_one) { Pred.arguments[i] = to_this_one; } if (Pred.arguments[i] is function) { function f = new function((function)Pred.arguments[i]); Pred.arguments[i] = f.rename_variable(that_one, to_this_one); } } new_expression.logical_exp.Add(Pred); } if (second_operand.is_Predicate) { Predicate Pred = new Predicate((Predicate)second_operand.logical_exp[0]); for (int i = 0; i < Pred.arguments.Count; i++) { if (Pred.arguments[i] is function) { function f = new function((function)Pred.arguments[i]); Pred.arguments[i] = f.rename_variable(that_one, to_this_one); } else if ((string)Pred.arguments[i] == that_one) { Pred.arguments[i] = to_this_one; } } new_expression.logical_exp.Add(Pred); } } else { Predicate Pred = new Predicate((Predicate)this.logical_exp[0]); for (int i = 0; i < Pred.arguments.Count; i++) { if (Pred.arguments[i] is function) { function f = new function((function)Pred.arguments[i]); Pred.arguments[i] = f.rename_variable(that_one, to_this_one); } else if ((string)Pred.arguments[i] == that_one) { Pred.arguments[i] = to_this_one; } } new_expression.logical_exp.Add(Pred); } return(new_expression); }