Debian Codegraph @

texmf-dist/tex/lualatex/luacas/algebra/luacas-absexpression.lua

raw symbols SCIP
1 --- @class AbsExpression
2 --- The absolute value of an expression.
3 --- @field expression Expression
4 AbsExpression = {}
5 local __AbsExpression = {}
6
7 ----------------------------
8 -- Instance functionality --
9 ----------------------------
10
11 --- Creates a new absolute value expression with the given expression.
12 --- @param expression Expression
13 --- @return AbsExpression
14 function AbsExpression:new(expression)
15 local o = {}
16 local __o = Copy(__ExpressionOperations)
17
18 o.expression = expression
19
20 __o.__index = AbsExpression
21 __o.__tostring = function(a)
22 return '|' .. tostring(a.expression) .. '|'
23 end
24
25 o = setmetatable(o, __o)
26 return o
27 end
28
29 --- @return Expression
30 function AbsExpression:evaluate()
31 if self.expression:isconstant() then
32 if self.expression >= Integer.zero() then
33 return self.expression
34 end
35 return -self.expression
36 end
37 return self
38 end
39
40 --- @return Expression
41 function AbsExpression:autosimplify()
42 return AbsExpression(self.expression:autosimplify()):evaluate()
43 end
44
45 --- @return table<number, Expression>
46 function AbsExpression:subexpressions()
47 return {self.expression}
48 end
49
50 --- @param subexpressions table<number, Expression>
51 --- @return AbsExpression
52 function AbsExpression:setsubexpressions(subexpressions)
53 return AbsExpression(subexpressions[1])
54 end
55
56 --- @param other Expression
57 --- @return boolean
58 function AbsExpression:order(other)
59 return FunctionExpression("abs", self.expression):order(other)
60 end
61
62 --- @return string
63 function AbsExpression:tolatex()
64 return "\\left|" .. self.expression:tolatex() .. "\\right|"
65 end
66
67 -----------------
68 -- Inheritance --
69 -----------------
70
71 __AbsExpression.__index = CompoundExpression
72 __AbsExpression.__call = AbsExpression.new
73 AbsExpression = setmetatable(AbsExpression, __AbsExpression)
74
75 ----------------------
76 -- Static constants --
77 ----------------------
78 ABS = function (a)
79 return AbsExpression(a)
80 end