APIs: macOS • Linux • iOS • watchOS • tvOS
SDGMathematics
⚠ This project is obsolete. It has been superseded by SDGCornerstone. ⚠
SDGMathematics extends support for mathematics.
Features
- Mathematical operations such as exponents, roots, logarithms, and trigonometry.
- Arbitrary‐precision number types:
WholeNumber,Integer&RationalNumber. - Customizable randomization of numbers and boolean values.
- A hierarchical protocol model for number types:
WholeArithmetic,IntegralArithmetic,RationalArithmetic,RealArithmetic, etc. - A
Measurementprotocol to simplify working with differing units. - Automated reversal of complex functions via
findLocalMinimum(near:within:inFunction), etc.
Importing
SDGMathematics is intended for use with the Swift Package Manager.
Simply add SDGMathematics as a dependency in Package.swift:
let package = Package(
...
dependencies: [
...
.Package(url: "https://github.com/SDGGiesbrecht/SDGMathematics", versions: "2.0.0" ..< "3.0.0"),
...
]
)
SDGMathematics can then be imported in source files:
import SDGMathematics
Example Usage
import SDGLogic
import SDGMathematics
func verifyPythagoreanTheorem() {
let a = 3.0
let b = 4.0
let c = 5.0
if √(a↑2 + b↑2) ≠ c {
print("Pythagoras was wrong! (Or maybe I just need to research floating point numbers...)")
}
}
func tryTrigonometry() {
let θ = 90.0°
let sine = sin(θ)
print("The sine of \(θ.inRadians) radians is \(sine)")
}
func playWithDice() {
func rollDie() -> Int {
return Int(randomInRange: 1 ... 6)
}
if rollDie() == 1 ∧ rollDie() == 1 {
print("Snake eyes!")
} else {
print("Not this time...")
}
}
func analyzeParabola() {
let parabola: (Int) -> Int = {
(x: Int) -> Int in
return 2 × x↑2 + 4 × x − 1
}
let vertexX = findLocalMinimum(near: 0, inFunction: parabola)
print("The vertex is at (\( vertexX ), \( parabola(vertexX) )).")
}
About
The SDGMathematics project is maintained by Jeremy David Giesbrecht.
If SDGMathematics saves you money, consider giving some of it as a donation.
If SDGMathematics saves you time, consider devoting some of it to contributing back to the project.
Ἄξιος γὰρ ὁ ἐργάτης τοῦ μισθοῦ αὐτοῦ ἐστι.
For the worker is worthy of his wages.
―ישוע/Yeshuʼa
View on GitHub
SDGMathematics Reference