RatPolyStack
public class RatPolyStack : Sequence
RatPolyStack is a mutable finite sequence of RatPoly objects.
Abstract State: Each RatPolyStack can be described by [p1, p2, … ], where [] is an empty stack, [p1] is a one element stack containing the Poly ‘p1’, and so on. RatPolyStacks can also be described constructively, with the append operation, ‘:’. such that [p1]:S is the result of putting p1 at the front of the RatPolyStack S.
A finite sequence has an associated size, corresponding to the number of elements in the sequence. Thus the size of [] is 0, the size of [p1] is 1, the size of [p1, p1] is 2, and so on.
-
Declaration
Swift
public typealias Iterator = Array<RatPoly>.Iterator
-
Effects**: Constructs a new RatPolyStack, [].
Declaration
Swift
public init()
-
The number of RayPolys in this RatPolyStack.
Declaration
Swift
public var count: Int { get }
-
Pushes a RatPoly onto the top of self.
Modifies: self
Effects: self_post = [p]:self
-Parameter p: The RatPoly to push onto this stack.
Declaration
Swift
public func push(_ p: RatPoly)
-
Removes and returns the top RatPoly.
Requires: self.count > 0
Modifies: self
Effects: If self = [p]:S then self_post = S
Declaration
Swift
public func pop() -> RatPoly
Return Value
p where self = [p]:S
-
Duplicates the top RatPoly on self.
Requires: self.count > 0
Modifies: self
Effects: If self = [p]:S then self_post = [p, p]:S
Declaration
Swift
public func dup()
-
Swaps the top two elements of self.
Requires: self.count >= 2
Modifies: self
Effects: If self = [p1, p2]:S then self_post = [p2, p1]:S
Declaration
Swift
public func swap()
-
Clears the stack.
Modifies: self
Effects: self_post = []
Declaration
Swift
public func clear()
-
Pops two elements off of the stack, adds them, and places the result on top of the stack.
Requires: self.count >= 2
Modifies: self
Effects: If self = [p1, p2]:S then self_post = [p3]:S where p3 = p1 + p2
Declaration
Swift
public func add()
-
Subtracts the top poly from the next from top poly, pops both off the stack, and places the result on top of the stack.
Requires: self.count >= 2
Modifies: self
Effects: If self = [p1, p2]:S then self_post = [p3]:S where p3 = p2 - p1
Declaration
Swift
public func sub()
-
Pops two elements off of the stack, multiplies them, and places the result on top of the stack.
Requires: self.count >= 2
Modifies: self
Effects: If self = [p1, p2]:S then self_post = [p3]:S where p3 = p1 * p2
Declaration
Swift
public func mul()
-
Divides the next from top poly by the top poly, pops both off the stack, and places the result on top of the stack.
Requires: self.count >= 2
Modifies: self
Effects: If self = [p1, p2]:S then self_post = [p3]:S where p3 = p2 / p1
Declaration
Swift
public func div()
-
Pops the top element off of the stack, differentiates it, and places the result on top of the stack.
Requires: self.count >= 1
Modifies: self
Effects: If self = [p1]:S then self_post = [p2]:S where p2 = derivative of p1
Declaration
Swift
public func differentiate()
-
Pops the top element off of the stack, integrates it, and places the result on top of the stack.
Requires: self.count >= 1
Modifies: self
Effects: If self = [p1]:S then self_post = [p2]:S where p2 = indefinite integral of p1 with integration constant 0
Declaration
Swift
public func integrate()
-
Returns an iterator of the elements contained in the stack.
Declaration
Swift
public func makeIterator() -> Iterator
Return Value
an iterator of the elements contained in the stack in order from the bottom of the stack to the top of the stack.