On Tue, Oct 1, 2013 at 5:47 PM, Naga V. [email protected] wrote:

Robert K. wrote in post #1122887:

On Mon, Sep 30, 2013 at 5:33 AM, Naga V. [email protected]

wrote:

Thanks for reviewing and providing valuable comments.

You’re welcome.

into a call, when answer is known from a “domain” space. The

implementation may change down the line while adhering to “Prior

Knowledge” paradigm.

You did not answer my question but I see you changed the implementation.

Agreed; Made some changes by using Hash in some places with latest

release of the gem.

I am sorry to say that but the way you use Hash there shows a certain

lack of understanding. The new code is even slower than before (see

below). Also looking at a recent version [1] lines 166 and 178 are

just plain wrong.

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.

If you wanted to provide an implementation of the “prior knowledge”

paradigm I would have expected a generic piece of code (a library if

you will) which allows others to make use of that paradigm more

easily. I only see mathematical functions with special treatment of a

few particular input values.

$ 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.

If you advertise your code the way you do you should probably provide

an example which clearly shows the advantage of your approach. Your

solution is less efficient than simply calling original functions.

Example for Math#sin:

$ ./x.rb

Rehearsal --------------------------------------------------------

Math.sin(0) 0.312000 0.000000 0.312000 ( 0.320018)

Math.sin(0.0) 0.109000 0.000000 0.109000 ( 0.107006)

sin(0) 2.262000 0.000000 2.262000 ( 2.266129)

sin(0.0) 1.934000 0.000000 1.934000 ( 1.925110)

sin2(0) 0.297000 0.000000 0.297000 ( 0.300017)

sin2(0.0) 0.281000 0.000000 0.281000 ( 0.281016)

----------------------------------------------- total: 5.195000sec

```
user system total real
```

Math.sin(0) 0.327000 0.000000 0.327000 ( 0.323019)

Math.sin(0.0) 0.094000 0.000000 0.094000 ( 0.107006)

sin(0) 2.293000 0.000000 2.293000 ( 2.281130)

sin(0.0) 1.919000 0.000000 1.919000 ( 1.921110)

sin2(0) 0.296000 0.000000 0.296000 ( 0.299017)

sin2(0.0) 0.281000 0.000000 0.281000 ( 0.283016)

see https://gist.github.com/rklemme/6790261#file-test-01-rb

It is just a mixup of

computation and domain knowledge. The domain can be in any space.

As said above: then a general mechanism would be in order. But

basically we have that with Hash#default_proc already:

$ ruby xx.rb

user system total real

fib1 1.294000 0.000000 1.294000 ( 1.297074)

fib2 0.141000 0.000000 0.141000 ( 0.140008)

fib3 0.000000 0.000000 0.000000 ( 0.007000)

https://gist.github.com/rklemme/6790261#file-test-02-rb

Kind regards

robert

[1]

https://github.com/nvijayap/mathematics/blob/b9e74223262fada6a201ef242a1728e594f4f9a4/lib/mathematics.rb