Last active
December 11, 2015 10:39
-
-
Save ken0nek/950dd01919b073a322f2 to your computer and use it in GitHub Desktop.
integral, sigma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Double : ForwardIndexType { | |
public func successor() -> Double { | |
return self + 1.0 | |
} | |
} | |
infix operator ∫ { associativity left precedence 120 } | |
func ∫ (left: Range<Double>, right: (Double -> Double)) -> Double { | |
let dx = (left.endIndex - left.startIndex) / 1000 | |
let r = left.startIndex.stride(to: left.endIndex, by: dx) | |
return r.reduce(0.0) { $0 + right($1) * dx } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Double : ForwardIndexType { | |
public func successor() -> Double { | |
return self + 1.0 | |
} | |
} | |
infix operator ∑ { associativity left precedence 120 } | |
func ∑ (left: Range<Double>, right: (Double -> Double)) -> Double { | |
let r = left.startIndex.stride(to: left.endIndex, by: 1) | |
return r.reduce(0.0) { $0 + right($1) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment