Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Commander

edited October 2013 in Code Sharing Posts: 577

Hi everyone! Today I'm proud to announce, Commander! It adds tons of new functions for your day to day use in Codea, Here are some of them so far:

button(name, width, height, x, y) - Useful for game menus and other game features.

math.tau()

rt(number, power) - Finds the root of a number, for example. if you plug in 3 in the "power" slot, it will give you the cube root of said number.

cbrt(number) - Finds the cube root of a number

And much more!

Download for it will be up soon, once I pack it into a auto installer :)

Also, feel free to give me suggestions for some functions, I'm running out of ideas fast.

Comments

  • Posts: 2,161

    Okay, I'm curious. What is math.tau()?

  • Posts: 577

    Snatched this from the wiki, its better at explaining it then me:

    *
    In 1958 Albert Eagle proposed replacing π by τ = π/2 to simplify formulas. However, no other authors are known to use tau in this way. Currently, some people use a different transcendental number for tau's value, τ = 6.283185307179586... = 2π. To them, τ seems to be more natural than π, as it is the ratio of a circle's circumference to its radius rather than its diameter and τ simplifies many formulas. Proposals to celebrate this number, because it approximately equals 6.28, by making 28 June "Tau Day" and eating "twice the pie",[154] have been reported in the media. However the use of τ has not made its way into current scientific discussion
    *

  • Posts: 2,161

    Oh dear, I was afraid of that!

    There is no logic at all in having a special constant for 2π.

  • Jmv38Jmv38 Mod
    edited October 2013 Posts: 3,297

    Hi @Andrew_Stacey ! Is there any rationnal (but historical reasons) for having chosen pi rather than 2pi? Except e^(i.pi)=-1 ? One turn is 2.pi.

  • Posts: 577

    @Andrew_Stacy Are you suggestion I should, remove it from my functions? <):)

  • Posts: 2,161

    @Prynok No, I'm not suggesting that you remove it. Just that I don't think that it's something worth making a special constant for so if you didn't have it then I would say not to bother putting it in. But as you already have it in then leave it there.

    I'm with Albert Eagle on this one. I think that 2π is a stupid choice but π/2 actually has some reason for being the "special" angle.

    @Jmv38 I understand that it comes from the fact that it is much easier to measure the diameter of a circle than its radius so the ratio of circumference to diameter is more directly useful than the ratio of circumference to radius. Euler's formula, e^{i π}, came much much later.

  • dave1707dave1707 Mod
    edited October 2013 Posts: 8,578

    @Prynok Why call a function to calculate a value when you can use the same code that's in the function to get the same value and use less code. Or instead of making a function, just set Tau=2*math.pi and use Tau in any calculations. I say remove the function and just set Tau.


    function math.tau() -- function to return tau    return 2*math.pi end c=math.tau()*r -- code using function c=2*math.pi*r -- code just doing calculation Tau=2*math.pi -- set Tau to value c=Tau*r --code using Tau
  • Posts: 577

    *dave1707 that's exactly what I'm doing :)

  • Jmv38Jmv38 Mod
    Posts: 3,297

    @andrew_Stacey thanks for your reply.
    However i dont buy your explanation: circles that you want to measure the diameter do not exist in nature. What exist however, is circles man-made. People often made circles with a rope and a stick in the center, to draw a circular fence for instance. The rope gives you the radius, not the diameter. So it is easier to know the radius than the diameter. They needed to know the perimeter then to know how much logs they will need to complete the fence.
    I think there is certainly a reason for pi rather than 2pi, but i have doubts about the explanation you suggest.

  • IgnatzIgnatz Mod
    edited October 2013 Posts: 5,396

    @Prynok - I think the question is why you'd bother including trivial one line functions like tau. The same goes for getting the root of a number, which is just a^(1/b), or the cube root, which is the same formula and doesn't need its own function, IMHO.

    If other Codea users are like me, then they don't like to have to include external libraries of code unless they are really necessary. That's perhaps why a library of functions you could easily write yourself doesn't sound so exciting.

    However, these may be bad examples, so don't let us stop you publishing your function library. You may well have some gems we will be very glad to use.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Jmv38 - I guess the choice of pi is because it is a special number. Why wouldn't you factor the two out first? Pi is used in all sorts of things.

  • edited October 2013 Posts: 1,976

    @Prynok You made a function to return 2 * π, therefor the syntax is math.tau(), when you could just set a constant, math.tau = 2*math.pi, and have the syntax be math.tau.

    Edit:

    +1 @Ignatz

  • Jmv38Jmv38 Mod
    Posts: 3,297

    @ignatz exactly. But what is so 'special' about pi? Coulnt we have choosen 2pi as the special number instead? I am just curious about that kind of things. Sometimes there is a nice random story behind. Sometines there is a deep law of nature. I like both!

  • Posts: 577

    @Ignazts Exactly! Thats why I made it, its suppose to be "easily written."

    The reason you would want to use it is because its a time saver, for example, why make a clock for your game, when there is already code for that clock?

  • Jmv38Jmv38 Mod
    edited October 2013 Posts: 3,297

    The reason could be water tanks: they were cilinder shape. So their volume is height x surface, and surface is pi x r^2! It is very important to know exactly the volume of water you have in your tank when the dry season is coming!

  • Posts: 2,161

    @Jmv38 Except that I would imagine them to count in fractions of a full water tank. So they know they need a full water tank to last 3 months, whereupon if it is half full then can only last 1.5 months. No need to know the exact volume.

    I really do think that when measuring, the diameter is easier than the radius.

    As for a deep law of nature, with regard to π versus 2π then there is none. The sole argument for 2π is "it makes the formulae nicer". There is a reason to choose π/2 instead of π that has more to do with deep concepts: the notion of orthogonality is incredibly important and that is to do with π/2.

  • dave1707dave1707 Mod
    Posts: 8,578

    Why do we use pi or 2 * pi or any other value, because it's easy for us to do that. Universal constants don't have values, WE assign values to them. I'm sure when the universe creates a star, it doesn't try to figure out it circumference or volume based on pi or 2 * pi, it just happens, it's the law. So what you use is based on what you want to use. If you want to use c=pi * d or c=2 * pi * r, or c=1.89 * s-fg/j, it doesn't matter because the answer is the same. We assign values to variables, the universe doesn't. The answers will be what they are no matter what we use.

  • Posts: 1,255

    @Prynok Looking forward to seeing the whole library. I'm sure that the subject of the last dozen or so messages is only a small part of the package.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    @Andrew_Stacey thanks for the insight. After all, you may be right about the diameter: the people who build the tank know the radius, but the people who come 10 or 100 year later to repair it must measure it, and then the diameter is easier than the radius.
    @Dave1707 your are perfectly right. But... great insight of the univeral laws have come from noticing some strange coincidences in coupling values. Units make sense, and sometime expressing a value in the good units reveals the physical origin of this value.

  • edited October 2013 Posts: 577

    @Everyone

    Uh oh, I didn't think the tau function would stir up such a dispute, The reason I added it was manily because we are learning about it in school for some reason, and I thought someone could make a cool formula with it. But you don't have to use it, guys. :)

    EDIT: I'm guessing I shouldn't add phi, either?

  • Jmv38Jmv38 Mod
    edited October 2013 Posts: 3,297

    @Prynok well dont worry. I wont call it a dispute, but rather an interesting discussion between gentlemen! And i would even add: thanks for triggering it!

  • IgnatzIgnatz Mod
    edited October 2013 Posts: 5,396

    We already have math.pi

    But useful little functions might include sin, cos, tan etc using degrees instead of radians (eg math.sin requires radians, which is easy to forget until you start getting rubbish results!). If you want to really twist your mind, try doing it using closures (see sin example at bottom of page)

    http://www.lua.org/pil/6.1.html

    But I would keep adding stuff you're learning about. It doesn't matter if nobody else wants them. It doesn't matter if they are obvious. Just have fun and explore. And you just might find something that's really interesting...

    http://calvinethobbes.free.fr/images/lastcalvin.gif

  • Jmv38Jmv38 Mod
    Posts: 3,297

    @ignatz i am a total fan of Calvin&Hobbes! Everything is perfect in this comics: exquisite sensitiivity of the drawing, humor, and intelligence. So much above anything else. Since Little Nemo.

  • Posts: 2,161

    pi is in the standard library because it is used a lot. It is quicker to include it than for just about every graphical program to start with math.pi = math.atan(1)*4. I don't know how much one would use the golden ratio in normal graphics. It's aesthetic value is somewhat dubious (I defy you to tell the difference between a rectangle with ratio φ and one with ratio 1.6, or even 1.5 at a distance) so it's unlikely to be used as much as π. For comparison, the base of the natural logarithm is not defined in the standard library.

    However, from a pedagogical point of view then you should put in as many as you are learning about and for each then you should design a little program that uses it. That's a great way to solidify your understanding of the concept behind it.

    (But I would echo @dave1707's first post about functions versus constants. These are definitely constants and not functions.)

    To reply to @dave1707's other post, you are right that it is us who name things, but the implication that the things we name are arbitrary is incorrect. One reason that we name things is to make calculations simpler and then the thing that we name tends to be the thing that occurs most. But there is a deeper reason for naming things: to encapsulate a concept. As far as calculation is concerned, there is no difference between π/2, π, or 2π. But with regard to concepts then π/2 encapsulates a concept that is far deeper than π or 2π, namely orthogonality. Knowing when two quantities are orthogonal is far, far more useful than knowing when they point in the same or opposite directions. For example, the fact that the pure signals, aka the exponential functions e2k iπ t/N, are orthogonal means that the energy of a sum of such functions can be computed from the coefficients in the sum. Without orthogonality there's no such easy computation.

    So while arguments over π versus 2π may seem frivolous, they needn't be. The Celts, amongst others, held that to know something's true name was to have power over it. They were right.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    e2k iπ t/N .....mmm... Or e 2π i k t/N ? ( ;-) just kidding)

  • Posts: 2,161

    @Jmv38 Oh blast! I was pretty sure that <sup>...</sup> wouldn't work but thought it worth trying, and then forgot to preview the post. I meant e^{2 k i pi t/N}.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    @Andrew_Stacey that was clear for me that you meant that. I was only fooling around about the position of x2, never mind!

Sign In or Register to comment.