Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattt/Euler
Swift Custom Operators for Mathematical Notation
https://github.com/mattt/Euler
math notation operator playground swift
Last synced: 3 months ago
JSON representation
Swift Custom Operators for Mathematical Notation
- Host: GitHub
- URL: https://github.com/mattt/Euler
- Owner: mattt
- License: mit
- Archived: true
- Created: 2014-08-05T21:33:35.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T16:53:44.000Z (over 3 years ago)
- Last Synced: 2024-03-28T03:01:57.729Z (7 months ago)
- Topics: math, notation, operator, playground, swift
- Language: Swift
- Size: 109 KB
- Stars: 1,150
- Watchers: 32
- Forks: 60
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Euler - Swift Custom Operators for Mathematical Notation. (Math / Other Hardware)
- awesome-swift - Euler - Swift Custom Operators for Mathematical Notation. (Extensions)
- awesome-ios-star - Euler - Swift Custom Operators for Mathematical Notation. (Math / Other Hardware)
README
# Euler
[![Build Status][ci status badge]][ci status]
[![License][license badge]][license]
[![Swift Version][swift version badge]][swift version]Euler uses [custom operators in the "Math Symbols"](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID418) character set to implement functions using traditional mathematical notation.
**Please keep in mind that this is not intended or recommended for production.** Custom operators of any breed are ripe for misuse and abuse, and should be used with as much care and caution as you would something like method swizzling or complex macros.
Euler is much better-suited to a Playground, where it could be used for teaching and learning logic and mathematics using a more vernacular notation.
> Euler is named after [Leonhard Euler](http://en.wikipedia.org/wiki/Leonhard_Euler), the Swiss mathematician credited for the popularization of modern mathematical notation such as the Greek letters `Σ` for summation & `π` for the ratio of a circle's circumference to its diameter, the letters _`e`_ to denote the base of the natural logarithm & _`i`_ to denote the imaginary unit, `sin` & `cos` for trigonometric functions, and `f(x)` to denote the function `f` with argument `x`.
---
## Example Usage
```swift
import Foundation
import Euler
import PlaygroundSupport𝑒 // 2.718281828459045
¬true // false
3 × 4 // 12
let prime = [2, 3, 5, 7, 11]
let fibonacci = [1, 1, 2, 3, 5, 8, 13]
prime ∩ fibonacci // {2, 3, 5}∑[1, 2, 3, 4, 5] // 15
[1, 2] ⋅ [3, 4] // 11
7 ≠ 9 // true
var f: (Double) -> Double = sin
let g: (Double) -> Double = cosfor x in stride(from: 0, to: 4 * π, by: π / 8) {
(f ∘ g)(x) // ∿∿∿
}(f′)(π) // -1
```## Inventory
### Mathematical Constants
- `π` - [Pi](http://en.wikipedia.org/wiki/Pi)
- `𝝉` - [Tau](http://en.wikipedia.org/wiki/Tau_%282%CF%80%29#tau)
- `𝑒` - [e](http://en.wikipedia.org/wiki/E_%28mathematical_constant%29)
- `ε` - [Machine Epsilon](https://en.wikipedia.org/wiki/Machine_epsilon)### Logic
- `¬`, `~` - [Logical Negation](http://en.wikipedia.org/wiki/Negation)
- `∧` - [Logical Conjunction](http://en.wikipedia.org/wiki/Logical_conjunction)
- `∨` - [Logical Disjunction](http://en.wikipedia.org/wiki/Logical_disjunction)
- `⊻`, `⊕`, `↮`, `≢` - [Logical XOR](http://en.wikipedia.org/wiki/Exclusive_or)
- `⊼`, `↑` - [Logical NAND](http://en.wikipedia.org/wiki/Logical_NAND)
- `⊽`, `↓` - [Logical NOR](http://en.wikipedia.org/wiki/Logical_NOR)
- `⊦` - [Logical Assertion](http://en.wikipedia.org/wiki/Logical_Assertion)## Arithmetic
- `×` - [Multiplication](http://en.wikipedia.org/wiki/Multiplication)
- `÷`, `∕` - [Division](http://en.wikipedia.org/wiki/Division_%28mathematics%29)
- `√` - [Square Root](http://en.wikipedia.org/wiki/Square_root)
- `∛` - [Cube Root](http://en.wikipedia.org/wiki/Cube_root)
- `∜` - [Tesseract Root](http://en.wikipedia.org/wiki/Nth_root)
- `±` - [Plus/Minus](http://en.wikipedia.org/wiki/Plus-minus_sign)
- `∓` - [Minus/Plus](http://en.wikipedia.org/wiki/Plus-minus_sign#Minus-plus_sign)
- `∣` - [Divides](http://en.wikipedia.org/wiki/Divisor)
- `∤` - [Does Not Divide](http://en.wikipedia.org/wiki/Divisor)## Sets
- `∈` - [Set Membership](http://en.wikipedia.org/wiki/Element_%28mathematics%29)
- `∉` - [Set Non-Membership](http://en.wikipedia.org/wiki/Element_%28mathematics%29)
- `∋` - [Converse Set Membership](http://en.wikipedia.org/wiki/Element_%28mathematics%29)
- `∌` - [Converse Set Membership](http://en.wikipedia.org/wiki/Element_%28mathematics%29)
- `∩` - [Set Intersection](http://en.wikipedia.org/wiki/Intersection_%28set_theory%29)
- `∪` - [Set Union](http://en.wikipedia.org/wiki/Union_%28set_theory%29)
- `⊆` - [Subset](http://en.wikipedia.org/wiki/Subset)
- `⊂` - [Proper Subset](http://en.wikipedia.org/wiki/Subset)
- `⊄` - [Not A Subset Of](http://en.wikipedia.org/wiki/Subset)
- `⊇` - [Superset](http://en.wikipedia.org/wiki/Subset)
- `⊃` - [Proper Superset](http://en.wikipedia.org/wiki/Subset)
- `⊅` - [Not A Superset Of](http://en.wikipedia.org/wiki/Subset)## Sequences
- `∑` - [Summation](http://en.wikipedia.org/wiki/Summation)
- `∏` - [Cartesian Product](http://en.wikipedia.org/wiki/Cartesian_product)## Vectors
- `⋅` - [Dot Product](http://en.wikipedia.org/wiki/Dot_product)
- `×` - [Cross Product](http://en.wikipedia.org/wiki/Cross_product)
- `‖` - [Vector Norm](http://en.wikipedia.org/wiki/Norm_%28mathematics%29)
- `⦡` - [Angle Between Vectors](http://en.wikipedia.org/wiki/Dot_product)## Comparison
- `⩵` - [Equality](http://en.wikipedia.org/wiki/Equality_%28mathematics%29)
- `≠` - [Inequality](http://en.wikipedia.org/wiki/Inequality_%28mathematics%29)
- `≤` - [Less Than Or Equal To](http://en.wikipedia.org/wiki/Inequality_%28mathematics%29)
- `≨` - [Less Than And Not Equal To](http://en.wikipedia.org/wiki/Inequality_%28mathematics%29)
- `≥` - [Greater Than Or Equal To](http://en.wikipedia.org/wiki/Inequality_%28mathematics%29)
- `≩` - [Greater Than And Not Equal To](http://en.wikipedia.org/wiki/Inequality_%28mathematics%29)
- `≬` - [Between](http://en.wikipedia.org/wiki/Inequality_%28mathematics%29)
- `≈` - [Approximate Equality](http://en.wikipedia.org/wiki/Approximation)
- `≉` - [Approximate Inequality](http://en.wikipedia.org/wiki/Approximation)## Calculus
- `′` - [Derivative](http://en.wikipedia.org/wiki/Derivative#Lagrange.27s_notation)
- `∫` - [Integral](http://en.wikipedia.org/wiki/Integral)## Functions
- `∘` - [Composition](http://en.wikipedia.org/wiki/Function_composition)
---
## License
MIT
## Contact
Mattt ([@mattt](https://twitter.com/mattt))
[ci status]: https://github.com/mattt/Euler/actions
[ci status badge]: https://github.com/mattt/Euler/workflows/CI/badge.svg
[license]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license badge]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[swift version]: https://swift.org/download/
[swift version badge]: http://img.shields.io/badge/swift%20version-5.0-orange.svg?style=flat