Code Monkey home page Code Monkey logo

rugheid / swift-matheagle Goto Github PK

View Code? Open in Web Editor NEW
42.0 3.0 6.0 3.79 MB

A general math framework to make using math easy. Currently supports function solving and optimisation, matrix and vector algebra, complex numbers, big int, big frac, big rational, graphs and general handy extensions and functions.

License: MIT License

Swift 72.43% Python 0.10% C 9.86% Objective-C 4.19% C++ 13.42%
swift complex-numbers mathematics biginteger graph-algorithms prime-numbers vector-math matrix-math

swift-matheagle's Introduction

Swift-MathEagle

Travis

MathEagle is named after the golden eagle, since this is the fastest bird in the world (in horizontal flight).

This project is meant to make math easy in swift without losing performance. The syntax is designed to be as simple as possible. Contributors are always welcome, the more the merrier!

Warning!

MathEagle is still in its initial development phase so the syntax still changes frequently.

Installation

The fastest way to add MathEagle to your project is to download it as a zip file and drag all files in the MathEagle/Source folder to your project. Make sure to add them to your target. For Mac applications you can use the generated framework, check the wiki for more information. I'm currently working on an iOS framework.

MathEagle requires gmp (GNU multiple precision arithmetic library) be installed. Install gmp via brew install gmp assuming you have Homebrew installed.

Supported Xcode Versions

MathEagle is fully compatible with:

  • Xcode 9 and Swift 4

Currently Supported

  • Basic extensions, operators like power (** operator) and functions like sign and factorial
  • Prime functions
  • Complex numbers
  • Single variable function root solving
  • Single variable function optimization
  • Matrix and Vector math
  • Basic graph algorithms

MathEagle is fully generic, so almost all classes and functions work with any type (even types you define). MathEagle vectors for example can also be of type Int, while the Float and Double type vectors use Accelerate in the background for speed.

Take a look at the Wiki for documentation.

Advantages

The biggest advantage of MathEagle is that it's totally generic. You can create matrices and vectors and use functions like isPrime with all numeric types. You can even create your own type (let's say Quaternion), implement the protocols and everything just works. Of course specific implementations are overloaded to maintain performance. Vector addition for Float vectors for example is overloaded to use the Accelerate framework.

Benchmarking

First benchmarking tests show that MathEagle is as fast as Python's famous numpy. You can check the "Benchmarking Files" folder in MathEagle's tests. (These tests were conducted on an early 2013 15-inch Retina Macbook Pro with a 2.7 GHz Intel Core i7 and 16 GB of RAM.

Here are some plots for Vector addition: ![Vector Addition Float Benchmarking](/MathEagleTests/Benchmarking Files/Plot Images/VectorAdditionFloat.png) ![Vector Addition Double Benchmarking](/MathEagleTests/Benchmarking Files/Plot Images/VectorAdditionDouble.png)

To Do

  • Documentation
  • Further General Development
  • Incorporate Accelerate for all applications

swift-matheagle's People

Contributors

anthonyclays avatar kellyroach avatar mennovf avatar rugheid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

swift-matheagle's Issues

Add more optimization routines

The only optimization procedure currently implemented is the golden section method. Optimization of functions with more than one variable (most notable Rosenbrock's function) is impossible without other methods.

Some initial suggestions:

For a well-written, high-level, fast and clear example of those (and other) routines, I highly recommend checking out Optim.jl.

Make Complex generic

As the readme states:

The biggest advantage about MathEagle is that it's totally generic. ๐Ÿ˜‰

Making Complex generic over any real number would be great (especially when you get around to adding arbitrary precision numerics)

Swift 3 compatibility

Hey, I'd love to see this lib available in Swift 3 so I can implement it in my project.

Thanks ๐Ÿ˜„

GNU Scientific Library

The GNU Scientific Library contains many nice features, including polynomials, permutations, combinations, FFT, ...

Make numberOfDigits function

This function could use something like this, but then Swifty:

n = 1;
if (i >= 100000000){i /= 100000000; n += 8;}
if (i >= 10000){i /= 10000; n += 4;}
if (i >= 100){i /= 100; n += 2;}
if (i >= 10){i /= 10; n += 1;}

GNU MPFR

Change the BigFloat class to use GNU MPFR instead of GMP. This allows the use of more important functions like logarithms.

Add more benchmarks

Current benchmarks are not entirely representative of the performance, as simple vectorized computations are easily compiled to near-perfect machine code.

Some benchmark suggestions:

  • Linear algebra routines (SVD, matrix inverse, eigenvalues...)
  • Number theory functions (primality tests, integer factorization...)
  • Optimization (test using rosenbrock function, count the number of objective function calls)

Combinatorics routines

  • Permutations / combinations iterators
  • gamma function
  • integer / fixed set partitions
  • calculating the parity of a permutation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.