Giter Club home page Giter Club logo

algebrafs's Introduction

AlgebraFs

This project is a simple computer algebra system (CAS), written entirely in pure F#, for pure fun. It uses an extremely simple expression language modelled by the union:

type Expr =
    | Const of float
    | Id of string
    | Func of string * Expr list

Constructs in this expression language are either constants that are floats, symbolic identifiers of string or functions that have a name (the string part) and arguments (the Expr list part)

Partial Active patterns

Active patterns are used extensively in this project to faciliate writing functions that operate on these kinds of expressions, example:

let (|Sin|_|) = function
    | Func("sin", [expr]) -> Some expr
    | _ -> None

let (|Cos|_|) = function
    | Func("cos", [expr]) -> Some expr
    | _ -> None

let (|Tan|_|) = function
    | Func("tan", [expr]) -> Some expr
    | _ -> None

Having these patterns defined, you could write the following:

// val isTrigonometric : Expr -> bool
let isTrigonometric = function
    | Sin x -> true
    | Cos x -> true
    | Tan x -> true
    | _ -> false

So the library is built around these patterns, evaluating an expression and differentiating a single variable (real) functions is built-in, example:

"sin(5x^2)"
|> Parser.tryParse 
|> function 
    | ParseError msg -> printf "Parse error: %s" msg
    | Parsed expr -> 
        Calculus.derivative expr (Id "x")
        |> Algebra.fullSimplify
        |> Printer.pretty
        |> printfn "%s" // returns "cos(5*x^2) * 10x"

algebrafs's People

Contributors

jbeeko avatar zaid-ajaj avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jbeeko ingted

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.