Skip to content

symcalc/symcalc-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SymCalc Ruby

SymCalc Logo

Website / License: Apache-2.0 / Changelog / Ruby , C++

SymCalc (which stands for Symbolic Calculus) is a library that introduces mathematics to code, where you can declare, evaluate, and differentiate any possible maths function with a single call.

SymCalc allows to write readable and flexible code, adding a lot of functionality along the way, like this:

fx = 5 * x ** 2 + sin(x)

Instead of hard-coded functions like this:

def fx(x)
    5 * x ** 2 + Math.sin(x)
end

Contents

Example

require 'symcalc'
include SymCalc

# SymCalc variable
x = var("x")

# SymCalc function
fx = x ** 2 * 5 - 4 * sin(exp(x))

# SymCalc derivative
dfdx = fx.derivative()

# SymCalc evaluate
value = dfdx.eval x: 5

puts value

Basic usage

  1. Require SymCalc:
require 'symcalc'
include SymCalc
  1. Define a variable:
x = var("x")
  1. Define a function:
fx = x ** 2
  1. Evaluate:
value = fx.eval(x: 4)
# or
value = fx(x: 4)
  1. Differentiate:
dfdx = fx.derivative
  1. Multi-variable!:
x = var("x")
y = var("y")

fxy = x ** 2 - 4 * abs(y)

dfdx = fxy.derivative(variable: x)
dfdy = fxy.derivative(variable: y)
  1. Display:
puts fx # Prints the function
  1. Run:
ruby main.rb
  1. See more on the website!

Install

Run:

gem install symcalc

Learning SymCalc

You can learn more about SymCalc on these resources:

Authors

SymCalc is currently developed and maintaned by Kyryl Shyshko (@kyryloshy)