| 1 |
--- @class ConstantExpression |
| 2 |
--- @alias Constant ConstantExpression |
| 3 |
--- Interface for a mathematical expression without any symbols. |
| 4 |
--- ConstantExpressions are AtomicExpressions by default, but individual classes may overwrite that inheritance. |
| 5 |
ConstantExpression = {} |
| 6 |
local __ConstantExpression = {} |
| 7 |
|
| 8 |
---------------------- |
| 9 |
-- Instance methods -- |
| 10 |
---------------------- |
| 11 |
|
| 12 |
|
| 13 |
--- @param symbol SymbolExpression |
| 14 |
--- @return boolean |
| 15 |
function ConstantExpression:freeof(symbol) |
| 16 |
return true |
| 17 |
end |
| 18 |
|
| 19 |
--- @return boolean |
| 20 |
function ConstantExpression:isconstant() |
| 21 |
return true |
| 22 |
end |
| 23 |
|
| 24 |
--- @param other Expression |
| 25 |
--- @return boolean |
| 26 |
function ConstantExpression:order(other) |
| 27 |
|
| 28 |
-- Constants come before non-constants. |
| 29 |
if not other:isconstant() then |
| 30 |
return true |
| 31 |
end |
| 32 |
|
| 33 |
if self ~= E and self ~= PI and self ~= I then |
| 34 |
if other ~= E and other ~= PI and other ~= I then |
| 35 |
-- If both self and other are ring elements, we use the total order on the ring to sort. |
| 36 |
return self < other |
| 37 |
end |
| 38 |
-- Special constants come after ring elements. |
| 39 |
return true |
| 40 |
end |
| 41 |
|
| 42 |
-- Special constants come after ring elements. |
| 43 |
if other ~= E and other ~= PI and other ~= I then |
| 44 |
return false |
| 45 |
end |
| 46 |
|
| 47 |
-- Ensures E < PI < I. |
| 48 |
|
| 49 |
if self == E then return true end |
| 50 |
|
| 51 |
if self == I then return false end |
| 52 |
|
| 53 |
return other == I |
| 54 |
end |
| 55 |
|
| 56 |
----------------- |
| 57 |
-- Inheritance -- |
| 58 |
----------------- |
| 59 |
|
| 60 |
__ConstantExpression.__index = AtomicExpression |
| 61 |
ConstantExpression = setmetatable(ConstantExpression, __ConstantExpression) |
| 62 |
|