Robert Klemme wrote in post #1122887:
> On Mon, Sep 30, 2013 at 5:33 AM, Naga Vijay <lists / ruby-forum.com>
> wrote:
>> Hello Fellow Rubyists,
>>
>> Just wanted to introduce/disclose programming using "Prior Knowledge"
>> based on domain knowledge.
>>
>> This note in https://github.com/nvijayap/mathematics is self-explanatory
>
> I beg to differ.  It tells me nothing about why I should be using that
> gem.  What's the advantage of using Mathematics.average over doing it
> yourself - it's a one liner anyway?  (Btw. the error for empty lists
> of numbers might be seen as a bit mysterious.)

Thanks for reviewing and providing valuable comments.

The gem is just an avenue to express the "Prior Knowledge" programming 
style/paradigm.

The gem just includes methods such as "average" as a bridging mechanism 
to math words that crop up in conversation/teaching/linguistics.

I will look into handling empty list.

>
>> IMPORTANT NOTE:
>> --------------
>> This program introduces/relies on "Prior Knowledge"
>> in the domain of mathematics, and avoids
>> computation where unnecessary.
>
> Why do you use #method_missing for #sin and #cos?  The implementation
> of the two methods is in no way dynamic.  You could just code them as
> regular methods. That way you would also get error reporting in case
> someone passes more than one argument to sin and cos.  It's a mystery
> to me why you call a variable which holds degrees "rad" (aka
> "radiants").

The way it is currently designed/implemented is to quickly let out 
answers for known arguments, and rely on Math for the rest - in the 
spirit of "Prior Knowledge" paradigm - no need to drill down further 
into a call, when answer is known from a "domain" space. The 
implementation may change down the line while adhering to "Prior 
Knowledge" paradigm.

>
> Also, "case" might be seen as a bit inefficient.  You could use a Hash
> for better efficiency:
>
> irb(main):004:0> sin = Hash.new {|h,x|
> Math.sin(x)}.merge!(0=>0,Math::PI/2=>1,Math::PI=>0,Math::PI*3/4=>-1)
> => {0=>0, 1.5707963267948966=>1, 3.141592653589793=>0,
> 2.356194490192345=>-1}
> irb(main):005:0> sin[Math::PI]
> => 0
>

Agreed; Made some changes by using Hash in some places with latest 
release of the gem.

> Question is whether it's worth the added overhead.  For all values not
> "prior known" you get the old behavior anyway.  And if you want nice
> (rounded) output, there's printf (see below).
>

The aim/goal is to gradually expand on this; Mathematics is just one 
domain; "Prior Knowledge" paradigm can encompass other domains.  It is a 
mesh-in of co-mingling currently known approaches/paradigms with this 
"Prior Knowledge" paradigm.

>> Also, resorting to computation sometimes doesn't yield
>> perfect results as known/anticipated. Example:
>> (environment: ruby 2.0.0p247 (2013-06-27 revision 41674)
>> [x86_64-darwin12.4.0])
>>
>> $ ruby -e "puts Math.sin(Math::PI) # I expect 0"
>> 1.2246467991473532e-16
>
> Yes, but
>
> $ ruby -e 'printf "%.3f\n", Math.sin(Math::PI)'
> 0.000
>

It's not about extent of rounding; it's about letting out known answer 
rightaway.  It's not about getting it work to match with known answer, 
it's about not drilling down further into the computational logistics 
when the known answer can be quickly let out.  It is just a mixup of 
computation and domain knowledge.  The domain can be in any space.

>> You may be able to use to good effect in your programs.
>
> Hm...
>
> Cheers
>
> robert

-- 
Posted via http://www.ruby-forum.com/.