Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Books for Programming?

  1. Jun 4, 2007 #1
    I want to get into programming. Does anyone have any suggestions for books for beginners?

    My goal is to make a program to finish my project at https://www.physicsforums.com/showthread.php?t=172789

    Is there already a program that can do this?
     
  2. jcsd
  3. Jun 4, 2007 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Mathematica can do it.

    Or you can write your own program. If you're looking for a language that can easily do arbitrary-precision integer math, I'd look into Python. Python includes a native data type called long, which is an arbitrary-precision integer type that you can use just like any other number. Furthermore, Python is pretty easy to pick up.

    Look on python.org for some tutorials, or pick up a copy of Learning Python from O'Reilly if you're completely new to programming. If you already have some programming experience in other languages, pick up Programming Python, also from O'Reilly.

    - Warren
     
  4. Jun 4, 2007 #3

    bfr

    User Avatar

    Python is a good language. I also recommend C++. If you search Google for something like "Beginner C++ Tutorials," you can probably find many good tutorials to help you with your problem, such as this one. C++ needs to be compiled (into native code so that your computer can understand it), so you'll need a compiler. I would recommend the latest Nightly Build of Code::Blocks, but I think that for what you seem to be doing, something that may be easier to install such as Dev-C++ might be better (I'm assuming you're using Windows). Once you've downloaded and installed a compiler and feel comfortable with C++ (variables, loops, functions, object-oriented programming, etc.), I suggest checking out this.
     
    Last edited: Jun 4, 2007
  5. Jun 4, 2007 #4

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    bfr,

    C++ is fine, but it provides no built-in arbitrary-precision arithmetic and is syntactically and semantically much more difficult to learn than Python. However, if you choose to use C++, you might find GMP (the GNU Multiple-Precision Library) useful.

    - Warren
     
  6. Jun 4, 2007 #5

    bfr

    User Avatar

    True.

    Note that the last link in my post actually linked to the GMP. ;) Great minds think alike....
     
  7. Jun 5, 2007 #6
    I've been looking into the Python.

    The python.org interpreter didn't work but I do have a command line interpreter.

    How to you run a script file from the command prompt?
    I've tried "read" and "write" functions but I'm pretty sure those aren't the right ones to use.

    Also, I can't figure out how to turn on the precision numbers. When I make a calculation the interpreter just rounds the nearest integer. I tried to use the "if" command to escape when the program found an integer value, but the number is already rounded, so the number entered for x is outputted.

    x = int(raw_input("Enter an integer: ")
    if ((x*x)-R)/(P-(2*x)) == round(((x*x)-R)/(P-(2*x)))
    print x
    else:
    x = x+1

    The enter integer is for a starting number
     
  8. Jun 5, 2007 #7

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    You type a command like python myscript.py where myscript.py is the name of your program.

    If you're doing integer division, then just use the long datatype (rather than int), and carry on. If you need to do arbitrary-precision floating point division, then you need to install the GMPy module and use that. (You can check to see if GMPy is already installed by typing "import gmpy" in the Python interpreter.) Once GMPy is installed, just use code like this:

    Code (Text):

    import gmpy, math

    m = gmpy.mpf(math.pi)
    print m ** 300
     
    where gmpy.mpf is a multiple-precision floating point number.

    - Warren
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?