Change default target to xcode
DiscreteMathematics is a set of algorithm implementations from Discrete Mathematics.
==%
The equivalence relation a ≡ b(mod m) ↔ m | (b - a).
-8 ==% (7, 5) // true 2 ==% (8, 5) // false
|%
Returns whether or not a|b ↔ ∃ q ∈ N, b = q · a.
3 |% 9 // true 2 |% 7 // false
Performs division on two integers and returns the quotient and remainder.
a = q · b + r
longDivision(a: 8, b: 3) // (q: 2, r: 2)
gcd() returns the greatest common divisor using the Euclidean Algorithm.
gcd()
gcd(5005, 4410) // 35 gcd(175, 155) // 5
egcd() returns the GCD of two integers as an integer combination using the Extended Euclidean Algorithm.
egcd()
a · x + b · y = d
egcd(5005, 4410) // (d: 35, x: -37, y: 42) egcd(175, 155) // (d: 5, x: 8, y: -9)
Two elements, a, b, are coprime if gcd(a, b) = 1.
coprime(17, -60) // true
lde() returns a solution to the given Linear Diophantine Equation or nil if it has no solutions.
lde()
nil
lde(a: 175, b: 155, c: 50) // (x: 80, y: -90) lde(a: 234, b: 182, c: 10) // nil
ldeSolutions() returns a function that will compute all possible solutions to an LDE.
ldeSolutions()
let solutions = ldeSolutions(a: 175, b: 155, c: 50) solutions!(3) // (173, -195)
The recommended way to install DiscreteMathematics is by using the Swift Package Manager.
DiscreteMathematics
To install it, add the following to your Package.swift‘s dependencies array:
Package.swift
dependencies
.package(url: "https://github.com/cszatma/DiscreteMathematics.git", from: "2.0.0")
DiscreteMathematics is also available through CocoaPods.
To install it, add the following line to your Podfile:
pod 'DiscreteMathematics', '~> 2.0'
DiscreteMathematics is available under the MIT License.
Open an issue or submit a pull request.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Discrete Mathematics
DiscreteMathematics is a set of algorithm implementations from Discrete Mathematics.
Examples
Operators
Congruence Modulo n
==%
:The equivalence relation a ≡ b(mod m) ↔ m | (b - a).
Divides
|%
:Returns whether or not a|b ↔ ∃ q ∈ N, b = q · a.
Functions
Long Division
Performs division on two integers and returns the quotient and remainder.
a = q · b + r
Greatest Common Divisor
gcd()
returns the greatest common divisor using the Euclidean Algorithm.egcd()
returns the GCD of two integers as an integer combination using the Extended Euclidean Algorithm.a · x + b · y = d
Coprime
Two elements, a, b, are coprime if gcd(a, b) = 1.
Linear Diophantine Equation
lde()
returns a solution to the given Linear Diophantine Equation ornil
if it has no solutions.ldeSolutions()
returns a function that will compute all possible solutions to an LDE.Installation
Swift Package Manager
The recommended way to install
DiscreteMathematics
is by using the Swift Package Manager.To install it, add the following to your
Package.swift
‘sdependencies
array:CocoaPods
DiscreteMathematics is also available through CocoaPods.
To install it, add the following line to your Podfile:
License
DiscreteMathematics is available under the MIT License.
Contributing
Open an issue or submit a pull request.