Symbolic math in pure ruby

B

Benoit Daloze

[Note: parts of this message were removed to make it a legal post.]

That looks really cool, thanks!

I began something like that some time ago.

Remembering I had some awful:
module MathExp
class Function
def self.sq(x = nil) Function.new:)sq, x, '2x', 'x^3/3') end

I was using String for functions, as I didn't know yet the power of coerce.
But that was quite easy to get derivative and integral.

Great job !
 
B

Benoit Daloze

[Note: parts of this message were removed to make it a legal post.]

You should maybe try with -w:
ruby -vw symbolic.rb
ruby 1.9.2dev (2009-12-11 trunk 26067) [x86_64-darwin10.2.0]

/symbolic/summand.rb:73: warning: private attribute?
/symbolic/factor.rb:71: warning: shadowing outer local variable - base
/symbolic/factor.rb:117: warning: private attribute?

The second is easy, but the others reveal strange use of attr_reader.

Why do you use attr_reader in private context? This is only usefull in a
public context I think, as instance variables can be directly accessed by
@var (even when it is a variable from the superclass)

It correctly pass all the tests, with one warning about drb(circular
require) and these 3. Putting the attr_reader before the "private" actually
remove the warnings.

2009/12/16 Benoit Daloze said:
That looks really cool, thanks!

I began something like that some time ago.

Remembering I had some awful:
module MathExp
class Function
def self.sq(x = nil) Function.new:)sq, x, '2x', 'x^3/3') end

I was using String for functions, as I didn't know yet the power of coerce.
But that was quite easy to get derivative and integral.

Great job !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top