gelpia icon indicating copy to clipboard operation
gelpia copied to clipboard

Named constants (pi)

Open monadius opened this issue 8 years ago • 21 comments

Common mathematical constants should be supported in .dop files. The most important constant is pi. Internally, the best possible interval approximation should be used.

monadius avatar Jul 11 '16 21:07 monadius

I will expose (some) of the internal GAOL constants: two_pi half_pi pi_dn pi_up half_pi_dn half_pi_up ln2_dn ln2_up two_power_53 GAOL_NAN GAOL_INFINITY NaN (quiet)

I believe these are good approximations. Gaol reference (attached for convenience) gaol.pdf page 49

keram88 avatar Jul 11 '16 22:07 keram88

I should also include e

keram88 avatar Jul 11 '16 22:07 keram88

For the constant e it is better to use a different name. For example, e_const.

monadius avatar Jul 11 '16 22:07 monadius

Somehow I dropped pi from Gaol's constants.

keram88 avatar Jul 11 '16 22:07 keram88

Use intervals for two_pi, half_pi, pi (page 19 of gaol.pdf)

monadius avatar Jul 11 '16 22:07 monadius

This is (partially) a front-end parser issue, so I'm assigning Ian.

keram88 avatar Jul 11 '16 22:07 keram88

I didn't notice that page 49 is about double versions. It looks like Gaol doesn't have e, so I'll need to get a good interval for it. I'll add it as a constant interval e_const = [down(e), up(e)].

keram88 avatar Jul 11 '16 23:07 keram88

For Ian's reference: Gaol's string constructor uses the tightest possible interval for pi. For now you can pass it straight through as a constant.

The width of the interval for the string "pi" is 1 ULP (in hex, [400921fb54442d18, 400921fb54442d19]), and the full decimal expansion of the lower bound is less than pi and the upper bound is greater than pi.

keram88 avatar Jul 11 '16 23:07 keram88

See https://github.com/soarlab/gelpia/issues/16 for a hint at the general strategy to implement this.

keram88 avatar Jul 17 '16 21:07 keram88

half_pi, two_pi, pi and e_const have been added. The constants are confirmed to be 1 ULP wide interval approximations.

keram88 avatar Jul 18 '16 23:07 keram88

I get the following error now:

bin/dop_gelpia benchmarks/classical_tests/1d/forrester.dop 
Traceback (most recent call last):
  File "bin/dop_gelpia", line 10, in <module>
   import argument_parser as ap
  File "/home/alexey/Work/Projects/gelpia/bin/argument_parser.py", line 11, in <module>
    from lexed_to_parsed import parse_function
  File "/home/alexey/Work/Projects/gelpia/bin/lexed_to_parsed.py", line 162
    t[0] = ["ConstantInterval", *SYMBOLIC_CONSTS[t[1]]]

My Python version is 3.4.4

monadius avatar Jul 19 '16 03:07 monadius

Why did you choose these names: half_pi, two_pi, pi, and e_const? They are not uniform since e has const added to the end of it. I suspect you did that to ease parsing or something like that, yes? Anyhow, I think they should either all have const or not.

zvonimir avatar Jul 19 '16 14:07 zvonimir

The names for the pi related constants come from GAOL itself. There's no difficulty in choosing the name, if Alexey's happy with the names or he has suggestions we'll change them.

Personally I'd prefer constants to be all upper case.

keram88 avatar Jul 19 '16 15:07 keram88

Alexey's issue is fixed in https://github.com/soarlab/gelpia/commit/967d2b948323b6a64df03c2ff6ef10cf7f0bc012. I didn't know until now python 3.5 had this in-place destructuring (I can't find where in python 3.5 this was allowed). I've turned the code into simple list operations.

keram88 avatar Jul 19 '16 15:07 keram88

Sticking w Gaol names seems a good idea (could not type gaol quickly on phone w/o it turning to goal . Then tried Ga ol , and it turned to gold. ...)

On Jul 19, 2016 9:14 AM, "Mark S. Baranowski (Marek Stanisław Baranowski)" < [email protected]> wrote:

The names for the pi related constants come from GAOL itself. There's no difficulty in choosing the name, if Alexey's happy with the names or he has suggestions we'll change them.

Personally I'd prefer constants to all upper case.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/soarlab/gelpia/issues/13#issuecomment-233665029, or mute the thread https://github.com/notifications/unsubscribe-auth/AEyiCne8kESjKf4aZKCXbWUaapy0UI1Sks5qXOm1gaJpZM4JJy4y .

ganeshutah avatar Jul 19 '16 15:07 ganeshutah

I prefer existing names: pi, half_pi, etc. I don't want to have different naming conventions for regular functions (sin, cos, etc.) and constants (which are 0-arity functions). On the other hand, I agree that the name e_const may be not good. The only problem with e is that the names 'e' and 'E' are not acceptable: there is a big chance that there is a variable 'e' or 'E'.

monadius avatar Jul 19 '16 17:07 monadius

How about exp? http://www.cplusplus.com/reference/cmath/exp/

zvonimir avatar Jul 19 '16 18:07 zvonimir

exp is already used. One alternative is euler (but there is another mathematical constant with the same name). Maybe, exp1 (or exp_1)?

monadius avatar Jul 19 '16 18:07 monadius

I think I like exp1 the best.

zvonimir avatar Jul 19 '16 18:07 zvonimir

I like exp1 as well. I'll defer the decision to Alexey.

keram88 avatar Jul 19 '16 19:07 keram88

The name exp1 is good. Let's use it.

monadius avatar Jul 19 '16 20:07 monadius