<commit_before>'use strict'

// TODO include in notation.js

const tex=require('./tex')
const TexDepvar=require('./tex-depvar')
const TexScalarDepvar=require('./tex-scalar-depvar')

class TexVectorDepvar extends TexDepvar {
	constructor(X,x,subscripts=[]) {
		super()
		this.X=X
		this.x=x
		this.subscripts=subscripts
	}
	_(...ii) {
		return new TexVectorDepvar(this.X,this.x,[...this.subscripts,...ii])
	}
	toString() {
		if (this.subscripts.length>0) {
			return `${this.X}_{${this.subscripts.join()}}` // TODO comma-less joins like ij
		} else {
			return this.X
		}
	}
	parallelExpression(template) {
		return `\\[ ${template(this).replace(/&/g,'')} \\]`
	}
	firstComponentExpressionPreamble(template) {
		const x=new TexScalarDepvar(this.x,this.subscripts)
		return template(`first component of `,x)
	}
	firstComponentExpression(template) {
		const x=new TexScalarDepvar(this.x,this.subscripts)
		return `\\[ ${template(x)} \\]`
	}
	restDiffComponentExpressionContent() {
		const x=new TexScalarDepvar(this.x,this.subscripts)
		return nt=>[
			`find other components by differentiating \\( ${x} \\):`,
			`\\[ ${this} = \\begin{bmatrix}`+
				`${x} \\\\`+
				`${nt.dd(x,'t',1)} \\\\`+
				`${nt.dd(x,'t',2)} \\\\`+
				`\\vdots \\\\`+
				`${nt.dd(x,'t','n-1')}`+
			`\\end{bmatrix} \\]`,
		]
	}
	ICLinearSystemSolution([a,b,c,d],[k1,k2]) {
		const detFraction=tex.frac([1],[a,d,'-',b,c])
		const matrixPrefix=(detFraction=='1' ? '' : detFraction+' ')
		return nt=>[
			`\\[ ${nt.mat2(a,b,c,d)} ${nt.vec2(k1,k2)} = ${this}(0) \\]`,
			`\\[ ${nt.vec2(k1,k2)} = ${matrixPrefix}${nt.mat2(d,tex.sum(['-',b]),tex.sum(['-',c]),a)} ${this}(0) \\]`,
		]
	}
	generalLinearSolution([k1,k2],[exp1,exp2],[a11,a12,a21,a22],[b11,b12,b21,b22]) {
		const c11=tex.sum([a11,b11,'+',a12,b21])
		const c12=tex.sum([a11,b12,'+',a12,b22])
		const c21=tex.sum([a21,b11,'+',a22,b21])
		const c22=tex.sum([a21,b12,'+',a22,b22])
		const kexp=(exp1==exp2
			? nt=>nt.svec2(k1,k2)+' '+exp1
			: nt=>nt.svec2(k1+' '+exp1,k2+' '+exp2)
		)
		return (systemLineBreak,scalarLineBreak)=>(nt)=>[
			`\\begin{aligned} `+
				`${this} = \\: & ${k1} ${exp1} ${nt.vec2(c11,c21)} \\\\`+
					`+ \\: & ${k2} ${exp2} ${nt.vec2(c12,c22)} \\\\`+
					`= \\: & ${nt.smat2(a11,a12,a21,a22)} ${nt.smat2(b11,b12,b21,b22)} ${kexp(nt)}`+
			`\\end{aligned}`
		]
	}
}

module.exports=TexVectorDepvar<commit_msg>depvar general solution for vector - line break option<commit_after>'use strict'

// TODO include in notation.js

const tex=require('./tex')
const TexDepvar=require('./tex-depvar')
const TexScalarDepvar=require('./tex-scalar-depvar')

class TexVectorDepvar extends TexDepvar {
	constructor(X,x,subscripts=[]) {
		super()
		this.X=X
		this.x=x
		this.subscripts=subscripts
	}
	_(...ii) {
		return new TexVectorDepvar(this.X,this.x,[...this.subscripts,...ii])
	}
	toString() {
		if (this.subscripts.length>0) {
			return `${this.X}_{${this.subscripts.join()}}` // TODO comma-less joins like ij
		} else {
			return this.X
		}
	}
	parallelExpression(template) {
		return `\\[ ${template(this).replace(/&/g,'')} \\]`
	}
	firstComponentExpressionPreamble(template) {
		const x=new TexScalarDepvar(this.x,this.subscripts)
		return template(`first component of `,x)
	}
	firstComponentExpression(template) {
		const x=new TexScalarDepvar(this.x,this.subscripts)
		return `\\[ ${template(x)} \\]`
	}
	restDiffComponentExpressionContent() {
		const x=new TexScalarDepvar(this.x,this.subscripts)
		return nt=>[
			`find other components by differentiating \\( ${x} \\):`,
			`\\[ ${this} = \\begin{bmatrix}`+
				`${x} \\\\`+
				`${nt.dd(x,'t',1)} \\\\`+
				`${nt.dd(x,'t',2)} \\\\`+
				`\\vdots \\\\`+
				`${nt.dd(x,'t','n-1')}`+
			`\\end{bmatrix} \\]`,
		]
	}
	ICLinearSystemSolution([a,b,c,d],[k1,k2]) {
		const detFraction=tex.frac([1],[a,d,'-',b,c])
		const matrixPrefix=(detFraction=='1' ? '' : detFraction+' ')
		return nt=>[
			`\\[ ${nt.mat2(a,b,c,d)} ${nt.vec2(k1,k2)} = ${this}(0) \\]`,
			`\\[ ${nt.vec2(k1,k2)} = ${matrixPrefix}${nt.mat2(d,tex.sum(['-',b]),tex.sum(['-',c]),a)} ${this}(0) \\]`,
		]
	}
	generalLinearSolution([k1,k2],[exp1,exp2],[a11,a12,a21,a22],[b11,b12,b21,b22]) {
		const c11=tex.sum([a11,b11,'+',a12,b21],o=>'{'+o+'}')
		const c12=tex.sum([a11,b12,'+',a12,b22],o=>'{'+o+'}')
		const c21=tex.sum([a21,b11,'+',a22,b21],o=>'{'+o+'}')
		const c22=tex.sum([a21,b12,'+',a22,b22],o=>'{'+o+'}')
		const kexp=(exp1==exp2
			? nt=>nt.svec2(k1,k2)+' '+exp1
			: nt=>nt.svec2(k1+' '+exp1,k2+' '+exp2)
		)
		return (systemLineBreak,vectorLineBreak)=>{
			const eq=(vectorLineBreak ? '= \\: &' : '&=')
			const pl=(vectorLineBreak ? '+ \\: &' : '+')
			const br=(vectorLineBreak ? '\\\\' : '')
			return nt=>[
				`\\begin{aligned} `+
					`${this} ${eq} ${k1} ${exp1} ${nt.vec2(c11,c21)} ${br}`+
						`${pl} ${k2} ${exp2} ${nt.vec2(c12,c22)} \\\\`+
						`${eq} ${nt.smat2(a11,a12,a21,a22)} ${nt.smat2(b11,b12,b21,b22)} ${kexp(nt)}`+
				`\\end{aligned}`
			]
		}
	}
}

module.exports=TexVectorDepvar
{'fraction_non_alphanumeric': 0.27172386112783464, 'fraction_numerical': 0.04856512141280353, 'mean_word_length': 4.090909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3795069', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2181, 'n_words': 260}