Mind Ramblings My Blog

Supporting substitutions

Hello All! I can say this week was quite productive. Ondrej, my mentor, had suggested me to make a new timeline for the rest of the time, and now I know how useful that turned out to be!

IRuby Notebooks

So, the beginner notebook is now upto date and contains everything that you need to know to get started. Also, I have prepared another notebook, that takes an actual question on differentiation from math.stackoverflow.com and solves it using SymEngine. It can be found here. It really shows, how convenient can using SymEngine be.

Substitutions module (#subs)

Now, you can mention what to substitute with what by storing the information in a Hash and then passing it to the subs method on any expression. It will return the same expression where keys would have been substituted by their corresponding mapped values.

x = SymEngine::Symbol.new('x')
y = SymEngine::Symbol.new('y')
z = SymEngine::Symbol.new('z')
k = SymEngine::Symbol.new('k')
e = x + y + z
f = e.subs(x => k , y => k / 2, => z => 2 * k)
puts f.to_s
# (7/2)*k

Making a Hash is not necessary, if you want to substitute just one variable

e.subs(x, 2).to_s
# 2+y+z

Next Week

I will be working on porting the trigonometric functions, and documentation/cleanup work mostly. If time permits, maybe we can move to Matrices and that can go with my code sample for GSoC endterm evaluation.


  • Updated the beginner notebook
  • Added the Ruby wrappers for #diff
  • Added rspec tests for #diff
  • Example notebook demonstrating differentiation with an actual problem
  • Added the source for basic_subs2
  • Added c tests for basic_subs2
  • Modified implementation of basic_subs2
  • Added C wrapper source for map_basic_basic
  • Added tests for CMapBasicBasic
  • Added pending tests for #subs
  • supported 2 param #subs with tests passing
  • Added c wrapper source for basic_subs
  • Added c tests for basic_subs
  • supported #subs with Hash, tests pass
  • Added test cases for error checking
  • Added 3-element Hash test case for subs

comments powered by Disqus