(expr: Expression)
| 36 | } |
| 37 | |
| 38 | export function interval(expr: Expression): Interval | undefined { |
| 39 | if (isFunction(expr, 'Interval')) { |
| 40 | let op1: Expression = expr.op1; |
| 41 | let op2: Expression = expr.op2; |
| 42 | let openStart = false; |
| 43 | let openEnd = false; |
| 44 | if (isFunction(op1, 'Open')) { |
| 45 | openStart = true; |
| 46 | op1 = op1.op1; |
| 47 | } else if (isFunction(op1, 'Closed')) { |
| 48 | op1 = op1.op1; |
| 49 | } |
| 50 | |
| 51 | if (isFunction(op2, 'Open')) { |
| 52 | openEnd = true; |
| 53 | op2 = op2.op1; |
| 54 | } else if (isFunction(op2, 'Closed')) { |
| 55 | op2 = op2.op1; |
| 56 | } |
| 57 | |
| 58 | const start = op1.N(); |
| 59 | const end = op2.N(); |
| 60 | |
| 61 | if (!isNumber(start) || !isNumber(end)) return undefined; |
| 62 | |
| 63 | return { start: start.re, openStart, end: end.re, openEnd }; |
| 64 | } |
| 65 | |
| 66 | // |
| 67 | // Known sets which are also intervals... |
| 68 | // |
| 69 | if (isSymbol(expr)) { |
| 70 | if (expr.symbol === 'EmptySet') |
| 71 | return { start: 0, openStart: true, end: 0, openEnd: true }; |
| 72 | |
| 73 | if (expr.symbol === 'RealNumbers') |
| 74 | return { |
| 75 | start: -Infinity, |
| 76 | openStart: false, |
| 77 | end: Infinity, |
| 78 | openEnd: false, |
| 79 | }; |
| 80 | |
| 81 | if (expr.symbol === 'NegativeNumbers') |
| 82 | return { start: -Infinity, openStart: false, end: 0, openEnd: true }; |
| 83 | |
| 84 | if (expr.symbol === 'NonPositiveNumbers') |
| 85 | return { start: -Infinity, openStart: false, end: 0, openEnd: false }; |
| 86 | |
| 87 | if (expr.symbol === 'PositiveNumbers') |
| 88 | return { start: 0, openStart: true, end: Infinity, openEnd: false }; |
| 89 | |
| 90 | if (expr.symbol === 'NonNegativeNumbers') |
| 91 | return { start: 0, openStart: false, end: Infinity, openEnd: false }; |
| 92 | } |
| 93 | |
| 94 | return undefined; |
| 95 | } |
no test coverage detected