Thread: AI Programming language

  1. #1
    Registered User knightjp's Avatar
    Join Date
    Nov 2008
    Location
    Dubai, U.A.E.
    Posts
    15

    AI Programming language

    Hey,

    New to this site. Actually new to programming in C and its variants too. I wanna get into programming in AI but, and I went through alot of articles n forums on the net trying to find out which language is the best for it.
    I hear that Lisp is a very suitable option along with Prolog. These stand as the usual choices and then I noticed that some use Java and C/ C++, out of which C is faster.
    I have a just couple of questions about AI programming.
    Which programming language is faster? If C/C++, which variant is the better to go with?

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Programmign languages have many features that make one 'better' than another for a specific application. If execution speed is your primary concern then I highly recommend C/C++ or Assembly. Assembly is ultimately the fastest, but it generally takes a lot of in dept knowledge about teh target processor to take full advantage fo it. Barring that, C/C++ is probably the fastest for programmers. LISP, ADA, etc. are all very good languages for formal AI development as they have a lot of features that are specific to AI. They should be fairly close to C/C++ in execution speed if you have a modern professional compiler. If you are doing AI in a purely research environment, then one of those is probably better due to the lower development time involved, but for real world applications I recommend C/C++ as it gives you access to a lot of other features, libraries and API's that LISP and ADA wont necessarily.

  3. #3
    Registered User knightjp's Avatar
    Join Date
    Nov 2008
    Location
    Dubai, U.A.E.
    Posts
    15
    Quote Originally Posted by abachler View Post
    Programmign languages have many features that make one 'better' than another for a specific application. If execution speed is your primary concern then I highly recommend C/C++ or Assembly. Assembly is ultimately the fastest, but it generally takes a lot of in dept knowledge about teh target processor to take full advantage fo it. Barring that, C/C++ is probably the fastest for programmers. LISP, ADA, etc. are all very good languages for formal AI development as they have a lot of features that are specific to AI. They should be fairly close to C/C++ in execution speed if you have a modern professional compiler. If you are doing AI in a purely research environment, then one of those is probably better due to the lower development time involved, but for real world applications I recommend C/C++ as it gives you access to a lot of other features, libraries and API's that LISP and ADA wont necessarily.
    Thanks for the info.. Now just to confirm what you are saying, Lisp, etc. are good and the easiest for AI programming. However C/C++ is more complex, executes faster and has more added features.
    I tend to agree that Assembly would be the best. However it might not work for me.
    I work on a mac. My current mac is one of the old PowerPC types and I'm looking to be able to port my program into a new Intel processor one later on.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    C/C++ is generalyl the most portable, although as long as you have a LISP compiler for both OS's your LISP code should port too. The real issue is whether you will eventually want yoru application to do mroe than just AI, for example, if you are writing AI that will go into a game, then you should probably choose a language that is good for both game development and AI development. On the other hand, if learnign 2 languages isnt an issue, you could always learn both adn write the AI in LISP and the game in say C/C++ then just link in the LISP LIB. This is why in general I recommend C/C++, because while it may not be 'Teh Bestest' at a given task, it is damned good at everything.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    AI also covers a huge area of different subjects, such as playing chess, targeting the player in a game, understanding human language (that is, English, Japanese or some such, as different from computers understanding PROGRAMMING LANGUAGES such as C), expert systems that can sort out what parts of information is relevant to a proble (e.g. helping a doctor diagnose an illness).

    All of the above problems have several different solutions that may require different language features and algorithms to solve the problem.

    Languages are like cars. If you ask "what car is best" we could answer "A Ferrari", but if you ask "I have half a ton of large boxes to transport, which car is best", then the answer is ABSOLUTELY NOT "A Ferrari". On the other hand, if you ask "I'd like an expensive, flashy car to attract rich, young females and that goes fast around a race-track", then Ferrari is one of the possible "right" answers. Likewise for languages, the size, type of problem and expected performance vs. development time will determine which is the "right" language.

    --
    Mats
    Last edited by matsp; 11-23-2008 at 08:36 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User knightjp's Avatar
    Join Date
    Nov 2008
    Location
    Dubai, U.A.E.
    Posts
    15
    Quote Originally Posted by matsp View Post
    AI also covers a huge area of different subjects, such as playing chess, targeting the player in a game, understanding human language (that is, English, Japanese or some such, as different from computers understanding PROGRAMMING LANGUAGES such as C), expert systems that can sort out what parts of information is relevant to a proble (e.g. helping a doctor diagnose an illness).

    All of the above problems have several different solutions that may require different language features and algorithms to solve the problem.

    Languages are like cars. If you ask "what car is best" we could answer "A Ferrari", but if you ask "I have half a ton of large boxes to transport, which car is best", then the answer is ABSOLUTELY NOT "A Ferrari". On the other hand, if you ask "I'd like an expensive, flashy car to attract rich, young females and that goes fast around a race-track", then Ferrari is one of the possible "right" answers. Likewise for languages, the size, type of problem and expected performance vs. development time will determine which is the "right" language.

    --
    Mats
    I like the illustration of the ferrari. I'm well aware of the reason one programming language is chosen over another for a particular task. The thing is.... I was told that any language can be used to do AI, but some will be easier than others.
    Considering development time is not an issue with me (as this is a personal hobby project) and my program will be something of a robot like thing.

    I got the idea from watching Albert in "The Absent-minded Professor" (see attachment)

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, you still need to figure out what sort of AI it is - some forms require a lot of calculations (so Fortran, C or C++ would be good candidates), others are decision based (which at least is easier to write in Prolog or some such), yet others deal with huge lists of items that need to be worked on in some way, and a language that has "lists" as it's basic functionality is a good candidate here - LisP stands for List Programming [of course, almost all AI are a combination of these things - but there's one of these that are the MAJORITY of the work].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User knightjp's Avatar
    Join Date
    Nov 2008
    Location
    Dubai, U.A.E.
    Posts
    15
    Quote Originally Posted by matsp View Post
    So, you still need to figure out what sort of AI it is - some forms require a lot of calculations (so Fortran, C or C++ would be good candidates), others are decision based (which at least is easier to write in Prolog or some such), yet others deal with huge lists of items that need to be worked on in some way, and a language that has "lists" as it's basic functionality is a good candidate here - LisP stands for List Programming [of course, almost all AI are a combination of these things - but there's one of these that are the MAJORITY of the work].

    --
    Mats
    As far as my plan is, the AI will be something like an operating system that can operate my computer with only a verbal command from me. Which is why I was thinking that C would be a good candidate as the heart of the Mac OS is a Unix platform written in C code.

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Its true, any Turing complete language can be used for AI, or any other problem for that matter, but as mentioned some will be easier to use for spcific type of AI. So choose your problem, then choose the most appropriate AI algorithm to use, then choose the best language for that algorithm. That is the opimum solution, hoever, since learning a new language entails some overhead, it generally falls down to what is the best language to learn for solving any problem that happens to crop up, in which case C/C++ is IMO the obvious choice, but then im biased.

  10. #10
    Registered User knightjp's Avatar
    Join Date
    Nov 2008
    Location
    Dubai, U.A.E.
    Posts
    15

    Cool

    Quote Originally Posted by abachler View Post
    Its true, any Turing complete language can be used for AI, or any other problem for that matter, but as mentioned some will be easier to use for spcific type of AI. So choose your problem, then choose the most appropriate AI algorithm to use, then choose the best language for that algorithm. That is the opimum solution, hoever, since learning a new language entails some overhead, it generally falls down to what is the best language to learn for solving any problem that happens to crop up, in which case C/C++ is IMO the obvious choice, but then im biased.
    I would tend to agree. I guess I'm looking for a language that I could do anything with; whether it be AI, database or any other project.
    Java is a candidate, but I'm not too keen on it. I tried Applescript, but when compared to C, the executing time is slower. C & Assembly were my obvious choices and after debating between the two I chose C. I guess I'm biased too.... lol
    Last edited by knightjp; 11-25-2008 at 08:40 PM.

  11. #11
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Part of my decision comes from the fact that I grew up with computers that were really really slow so to get anything approximating throughput from them it was necessary to scavenge every possible processor cycle. This is part of the reason I learned assembly (years before i learned C/C++) and later C/C++. Obviously as my projects became larger I needed a high level language like C/C++ but my roots are in assembly and languages that try to abstract the programming environment too far away from the metal just make me think 'what's the point?'. I know a lot of people have problems with memory management, but after doing memory management in assembly on a 6502, memory management in C/C++ seems incredibly simple. For me keeping track of whether an object has been dereferenced into oblivion would put more bugs into my applications that it woudl remove by saving me those rare times when I forget to deallocate the object explicitly in a deconstructor. Ive been doing it so long now that its just second nature. Then again, I am in MENSA, so maybe I just have fewer problems learning these things. There was a time when I was actually anti C++ because at the time it entailed a lot of overhead and ran slower than C.

  12. #12
    Registered User knightjp's Avatar
    Join Date
    Nov 2008
    Location
    Dubai, U.A.E.
    Posts
    15
    You learned Assembly? You must be a master. Do you think that it will be good for AI? Or is it too complex?

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by knightjp View Post
    You learned Assembly? You must be a master. Do you think that it will be good for AI? Or is it too complex?
    Assembler can do anything - but it's hard work, because a simple C statement easily becomes 5-10 lines of assembler code. And if you think that C is not a very "safe" language, assembler is much worse - you REALLY need to keep track of all your types and what goes where yourself.

    I wouldn't say that it's a good language for AI in general.

    Assembler should be used:
    1. When something CAN NOT be done in a higher level language (context switching in the OS for example, where you'd have to store and restore specific registers to make it work)
    2. When it is PROVEN that the compiler generates slow code for a small portion of the whole application, and there is no easy way to make the compiler produce better code.
    3. When the application is so small that it can be written in a few hundred lines of assembler, and memory is critical (e.g. tiny embedded projects).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by knightjp View Post
    As far as my plan is, the AI will be something like an operating system that can operate my computer with only a verbal command from me. Which is why I was thinking that C would be a good candidate as the heart of the Mac OS is a Unix platform written in C code.
    I would recommend C++ if your platform supports it (and if you choose to go C/C++), because it's higher level than C, and higher level always means making it easier for you. As well, it is a somewhat modern language with powerful features and tools - but the best thing is that in case you need to go lower, then C++ is backwards compatible with C and hence you can do those lower parts in C, too. Or you can compile them using a C compiler, if you wish.

    And let's be fair about one thing - the myth that C is faster than C++ just is not true. They have advantages and disadvantages and are thus about equal in speed.

    C and C++ can sometimes also deal with assembly, although it's tricky and requires safety guidelines.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by knightjp View Post
    You learned Assembly? You must be a master. Do you think that it will be good for AI? Or is it too complex?
    as matsp states there are some caveats, but he forgot my favorite -

    4. To make your collegues gape in wonderment.

    and

    5. When you can do in 12 lines of assembly what it will take 1 lines in C/C++, e.g.

    Code:
    __asm pusha
    __asm mov         ecx , 0x00100000
    __asm mov         eax , GPU_Array
    __asm mov         edx , Inputs
    __asm mov         esi , 0x00000010
    loop_start:
    __asm add         eax , esi
    __asm movapd    xmm0 , [edx]
    __asm add         edx , esi
    __asm movapd    [eax] , xmm0 
    __asm loop         loop_start
    __asm popa
    why would you do that you ask? because it lends itself to optimizations that are not possible in C/C++, because it produces faster code, because it obfuscates what you are doing, and because it produces different results than a simple CopyMemory(), specifically it will throw if you try to use unaligned memory which may indicate an error condition on the GPU.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why C Matters
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 136
    Last Post: 01-16-2008, 09:09 AM
  2. chess ai contest
    By Raven Arkadon in forum Contests Board
    Replies: 7
    Last Post: 07-09-2005, 06:38 AM
  3. AI Contest Proposal
    By MadCow257 in forum Contests Board
    Replies: 4
    Last Post: 03-13-2005, 03:27 PM
  4. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 01:20 AM
  5. Game Design Topic #1 - AI Behavior
    By TechWins in forum Game Programming
    Replies: 13
    Last Post: 10-11-2002, 10:35 AM