| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
AbsExpression = {} |
| 5 |
local __AbsExpression = {} |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 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 |
|
| 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 |
|
| 41 |
function AbsExpression:autosimplify() |
| 42 |
return AbsExpression(self.expression:autosimplify()):evaluate() |
| 43 |
end |
| 44 |
|
| 45 |
|
| 46 |
function AbsExpression:subexpressions() |
| 47 |
return {self.expression} |
| 48 |
end |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
function AbsExpression:setsubexpressions(subexpressions) |
| 53 |
return AbsExpression(subexpressions[1]) |
| 54 |
end |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
function AbsExpression:order(other) |
| 59 |
return FunctionExpression("abs", self.expression):order(other) |
| 60 |
end |
| 61 |
|
| 62 |
|
| 63 |
function AbsExpression:tolatex() |
| 64 |
return "\\left|" .. self.expression:tolatex() .. "\\right|" |
| 65 |
end |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
__AbsExpression.__index = CompoundExpression |
| 72 |
__AbsExpression.__call = AbsExpression.new |
| 73 |
AbsExpression = setmetatable(AbsExpression, __AbsExpression) |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
ABS = function (a) |
| 79 |
return AbsExpression(a) |
| 80 |
end |