summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luacas/tex/core/binaryoperation/difference.lua
blob: 2cc56b6600a808d1414480121bbf05bb85aec25c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- Seperates the various binary operations into their own files for readability

--- Automatic simplification of difference expressions.
--- @return BinaryOperation
function BinaryOperation:simplifydifference()
    local term1 = self.expressions[1]
    local term2 = self.expressions[2]

    if not term2 then
        return BinaryOperation(BinaryOperation.MUL, {Integer(-1), term1}):autosimplify()
    end

    return BinaryOperation(BinaryOperation.ADD, {term1, BinaryOperation(BinaryOperation.MUL, {Integer(-1), term2}):autosimplify()}):autosimplify()
end