<commit_before>package model;

import java.util.ArrayList;

public class Add extends Expression {
	private ArrayList<Expression> exp;
	
	public Add(ArrayList<Expression> exps) {
		//this.exp = exp;
		this.exp = new ArrayList<>();
		double constantSum = 0;
		
		for(Expression e : exps) {
			if(e instanceof Constant) {
				try {
					constantSum += e.calc();
					continue;
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
			this.exp.add(e);
			this.varList.addAll(e.getUsingVariables());
		}
		if(constantSum != 0 || exp.isEmpty()) {
			exp.add(new Constant(constantSum));
		}
	}
	
	public Add(ArrayList<Expression> exp, double co) {
		this.coefficient = co;
		this.exp = exp;
		
		for(Expression e : exp) {
			this.varList.addAll(e.getUsingVariables());
		}
	}

	@Override
	public Expression derivative(Variable var) throws Exception {
		if(!this.varList.contains(var)) {
			return new Constant(0.0);
		}

		ArrayList<Expression> dexp = new ArrayList<Expression>();
		
		for(Expression e : this.exp) {
			dexp.add(e.derivative(var));
		}
		
		Expression deriv = new Add(dexp, this.coefficient);
		
		return deriv;
	}

	@Override
	public Expression integrate(Variable var) throws Exception {
		if(!this.varList.contains(var)) {
			return new Constant(0.0);
		}
		
		ArrayList<Expression> iexp = new ArrayList<Expression>();
		
		for(Expression e : this.exp) {
			iexp.add(e.integrate(var));
		}
		
		Expression integ = new Add(iexp, this.coefficient);
		
		return integ;
	}

	@Override
	public double calc() throws Exception {
		double sum = 0;
		
		for(Expression e : this.exp) {
			sum += e.calc();
		}
		
		return sum * this.coefficient;
	}

	@Override
	public String stringify() {
		String expression = "";

		try {
			for(int i = 0; i < this.exp.size(); i++) {
				Expression elem = this.exp.get(i);
				if(elem instanceof Constant && elem.stringify().equals("0") && this.exp.size()>1) {
					continue;
				}
				if(i > 0) {
					if(!elem.isCoeffPositive()) {
						elem.setNegativeCoeff();
						expression += " - " + elem.stringify();
						elem.setNegativeCoeff();<commit_msg>[bugfix] Stringify functionality fix<commit_after>package model;

import java.util.ArrayList;

public class Add extends Expression {
	private ArrayList<Expression> exp;
	
	public Add(ArrayList<Expression> exps) {
		//this.exp = exp;
		this.exp = new ArrayList<>();
		double constantSum = 0;
		
		for(Expression e : exps) {
			if(e instanceof Constant) {
				try {
					constantSum += e.calc();
					continue;
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
			this.exp.add(e);
			this.varList.addAll(e.getUsingVariables());
		}
		if(constantSum != 0 || exp.isEmpty()) {
			exp.add(new Constant(constantSum));
		}
	}
	
	public Add(ArrayList<Expression> exp, double co) {
		this.coefficient = co;
		this.exp = exp;
		
		for(Expression e : exp) {
			this.varList.addAll(e.getUsingVariables());
		}
	}

	@Override
	public Expression derivative(Variable var) throws Exception {
		if(!this.varList.contains(var)) {
			return new Constant(0.0);
		}

		ArrayList<Expression> dexp = new ArrayList<Expression>();
		
		for(Expression e : this.exp) {
			dexp.add(e.derivative(var));
		}
		
		Expression deriv = new Add(dexp, this.coefficient);
		
		return deriv;
	}

	@Override
	public Expression integrate(Variable var) throws Exception {
		if(!this.varList.contains(var)) {
			return new Constant(0.0);
		}
		
		ArrayList<Expression> iexp = new ArrayList<Expression>();
		
		for(Expression e : this.exp) {
			iexp.add(e.integrate(var));
		}
		
		Expression integ = new Add(iexp, this.coefficient);
		
		return integ;
	}

	@Override
	public double calc() throws Exception {
		double sum = 0;
		
		for(Expression e : this.exp) {
			sum += e.calc();
		}
		
		return sum * this.coefficient;
	}

	@Override
	public String stringify() {
		String expression = "";

		try {
			for(int i = 0; i < this.exp.size(); i++) {
				Expression elem = this.exp.get(i);
				if(elem instanceof Constant && elem.stringify().equals("0") && this.exp.size()>1) {
					continue;
				}
				if(!expression.equals("")) {
					if(!elem.isCoeffPositive()) {
						elem.setNegativeCoeff();
						expression += " - " + elem.stringify();
						elem.setNegativeCoeff();
{'fraction_non_alphanumeric': 0.1457156308851224, 'fraction_numerical': 0.005885122410546139, 'mean_word_length': 3.1779744346116026, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '2532913', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1371, 'n_words': 311}