• Re: Is this program OOP?

    From Tim Rentsch@21:1/5 to wij on Mon Dec 9 09:35:20 2024
    wij <[email protected]> writes:

    Because I said: C++ is the best language to model general
    problems. So it is.

    Almost all are logical propositions. Except those few keywords,
    such programwon't be recognized as a C++ program, instead of some
    kind of declarative language.

    Zebra puzzle is an interesting programing exercise because it is
    not too easy and also not too difficult.

    ------------
    /* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2023

    Example of solving the zebra puzzle by using propositional logic.
    Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Puzzle

    [...]
    */
    #include <Wy.stdio.h>
    #include <Sc/PropExpr.h>

    using namespace Wy;
    using namespace Sc;

    [...]

    You're asking a question that cannot be answered because much or
    most of the program is in the two include files, which are not
    shown.

    As a general rule, when posting code there should be enough posted
    so that readers can at least compile it. In cases like the program
    asked about here, what is posted should be enough to both compile
    the program and run the generated executable.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to wij on Mon Dec 9 22:15:07 2024
    wij <[email protected]> writes:

    On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote:

    wij <[email protected]> writes:

    Because I said: C++ is the best language to model general
    problems. So it is.

    Almost all are logical propositions. Except those few keywords,
    such programwon't be recognized as a C++ program, instead of some
    kind of declarative language.

    Zebra puzzle is an interesting programing exercise because it is
    not too easy and also not too difficult.

    ------------
    /* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2023 >>>
    Example of solving the zebra puzzle by using propositional logic.
    Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Puzzle

    [...]
    */
    #include <Wy.stdio.h>
    #include <Sc/PropExpr.h>

    using namespace Wy;
    using namespace Sc;

    [...]

    You're asking a question that cannot be answered because much or
    most of the program is in the two include files, which are not
    shown.

    As a general rule, when posting code there should be enough posted
    so that readers can at least compile it. In cases like the program
    asked about here, what is posted should be enough to both compile
    the program and run the generated executable.

    I thought nobody will be interested with the implement, and what
    is shown should be enough for the moment.

    The point is that what was posted is not enough to answer the
    question of the Subject: line.

    The Zebra Puzzle program has two version, a_puzzle_21.cpp (has
    shown) takes too long to complete. a_puzzle_2.cpp (736 lines, too
    long to post, I thought) is the realistic one written in way I
    feel just solving the prolem is enough.

    I wrote a program in prolog to solve this puzzle. The entire
    program is 60 lines long, including 13 blank lines. It finds
    the solution in 0.03 seconds. The program doesn't do anything
    fancy; it pretty much just gives the listed conditions in the form
    of prolog rules, plus 20 lines to establish the structure of the
    information that is being sought.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to wij on Tue Dec 10 17:04:37 2024
    On 10/12/2024 10:23, wij wrote:
    On Mon, 2024-12-09 at 22:15 -0800, Tim Rentsch wrote:
    wij <[email protected]> writes:

    On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote:

    wij <[email protected]> writes:

    Because I said:  C++ is the best language to model general
    problems.  So it is.

    Almost all are logical propositions.  Except those few keywords,
    such programwon't be recognized as a C++ program, instead of some
    kind of declarative language.

    Zebra puzzle is an interesting programing exercise because it is
    not too easy and also not too difficult.

    ------------
    /* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2023 >>>>>
     Example of solving the zebra puzzle by using propositional logic. >>>>>  Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Puzzle

    [...]
    */
    #include <Wy.stdio.h>
    #include <Sc/PropExpr.h>

    using namespace Wy;
    using namespace Sc;

    [...]

    You're asking a question that cannot be answered because much or
    most of the program is in the two include files, which are not
    shown.

    As a general rule, when posting code there should be enough posted
    so that readers can at least compile it.  In cases like the program
    asked about here, what is posted should be enough to both compile
    the program and run the generated executable.

    I thought nobody will be interested with the implement, and what
    is shown should be enough for the moment.

    The point is that what was posted is not enough to answer the
    question of the Subject: line.

    The Zebra Puzzle program has two version, a_puzzle_21.cpp (has
    shown) takes too long to complete.  a_puzzle_2.cpp (736 lines, too
    long to post, I thought) is the realistic one written in way I
    feel just solving the prolem is enough.

    I wrote a program in prolog to solve this puzzle.  The entire
    program is 60 lines long, including 13 blank lines.  It finds
    the solution in 0.03 seconds.  The program doesn't do anything
    fancy;  it pretty much just gives the listed conditions in the form
    of prolog rules, plus 20 lines to establish the structure of the
    information that is being sought.

    Very dubious, show us what you say is true.


    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about them.
    It's at least 35 years since I tried Prolog one afternoon, and that's
    exactly the kind of task I played with (though a bit smaller).

    This is not a big problem in any language. It's 5 characteristics for
    each of 5 houses - that's 3125 possibilities. Make a big array of
    booleans, initialised to true. Run through the array and kill any
    combination that is contrary to one of the facts. It might have been a
    worthy benchmark in 1962 but it should not be challenging to solve with
    modern machines. (Of course it can still inspire interesting solutions
    and ways to express code in different languages.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to All on Tue Dec 10 16:35:39 2024
    On Tue, 10 Dec 2024 17:04:37 +0100
    David Brown <[email protected]> wibbled:
    On 10/12/2024 10:23, wij wrote:
    Very dubious, show us what you say is true.


    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about them.
    It's at least 35 years since I tried Prolog one afternoon, and that's
    exactly the kind of task I played with (though a bit smaller).

    I found Prolog an absolute bugger of a language. Beyond simple clauses it
    never did what I expected it to do. Its the one language I never really
    got. I think it requires a certain mindset or way of thinking.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to [email protected] on Wed Dec 11 08:59:18 2024
    On 10/12/2024 17:35, [email protected] wrote:
    On Tue, 10 Dec 2024 17:04:37 +0100
    David Brown <[email protected]> wibbled:
    On 10/12/2024 10:23, wij wrote:
    Very dubious, show us what you say is true.


    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about them.
    It's at least 35 years since I tried Prolog one afternoon, and that's
    exactly the kind of task I played with (though a bit smaller).

    I found Prolog an absolute bugger of a language. Beyond simple clauses it never did what I expected it to do. Its the one language I never really
    got. I think it requires a certain mindset or way of thinking.


    Having only tried it for a short time as a teenager, it's not fair for
    me to judge it - but it is certainly quite a different kind of language
    from C++!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to All on Wed Dec 11 08:40:24 2024
    On Wed, 11 Dec 2024 08:59:18 +0100
    David Brown <[email protected]> wibbled:
    On 10/12/2024 17:35, [email protected] wrote:
    On Tue, 10 Dec 2024 17:04:37 +0100
    David Brown <[email protected]> wibbled:
    On 10/12/2024 10:23, wij wrote:
    Very dubious, show us what you say is true.


    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about them.
    It's at least 35 years since I tried Prolog one afternoon, and that's
    exactly the kind of task I played with (though a bit smaller).

    I found Prolog an absolute bugger of a language. Beyond simple clauses it
    never did what I expected it to do. Its the one language I never really
    got. I think it requires a certain mindset or way of thinking.


    Having only tried it for a short time as a teenager, it's not fair for
    me to judge it - but it is certainly quite a different kind of language
    from C++!

    We had to use it in the AI module at uni. :/

    I suspect its raison d'etre has rather been shot down these days as AI has moved away from propositional logic to neural networks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to wij on Wed Dec 11 12:42:28 2024
    On 10/12/2024 18:02, wij wrote:
    On Tue, 2024-12-10 at 17:04 +0100, David Brown wrote:
    On 10/12/2024 10:23, wij wrote:
    On Mon, 2024-12-09 at 22:15 -0800, Tim Rentsch wrote:
    wij <[email protected]> writes:

    On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote:

    wij <[email protected]> writes:

    Because I said:  C++ is the best language to model general
    problems.  So it is.

    Almost all are logical propositions.  Except those few keywords, >>>>>>> such programwon't be recognized as a C++ program, instead of some >>>>>>> kind of declarative language.

    Zebra puzzle is an interesting programing exercise because it is >>>>>>> not too easy and also not too difficult.

    ------------
    /* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2023

      Example of solving the zebra puzzle by using propositional logic. >>>>>>>   Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Puzzle

    [...]
    */
    #include <Wy.stdio.h>
    #include <Sc/PropExpr.h>

    using namespace Wy;
    using namespace Sc;

    [...]

    You're asking a question that cannot be answered because much or
    most of the program is in the two include files, which are not
    shown.

    As a general rule, when posting code there should be enough posted >>>>>> so that readers can at least compile it.  In cases like the program >>>>>> asked about here, what is posted should be enough to both compile
    the program and run the generated executable.

    I thought nobody will be interested with the implement, and what
    is shown should be enough for the moment.

    The point is that what was posted is not enough to answer the
    question of the Subject: line.

    The Zebra Puzzle program has two version, a_puzzle_21.cpp (has
    shown) takes too long to complete.  a_puzzle_2.cpp (736 lines, too
    long to post, I thought) is the realistic one written in way I
    feel just solving the prolem is enough.

    I wrote a program in prolog to solve this puzzle.  The entire
    program is 60 lines long, including 13 blank lines.  It finds
    the solution in 0.03 seconds.  The program doesn't do anything
    fancy;  it pretty much just gives the listed conditions in the form
    of prolog rules, plus 20 lines to establish the structure of the
    information that is being sought.

    Very dubious, show us what you say is true.


    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about them.
    It's at least 35 years since I tried Prolog one afternoon, and that's
    exactly the kind of task I played with (though a bit smaller).

    I know a bit of prolog,lisp (in DOS era). Strongly suspicious what Tim says.

    This is not a big problem in any language.  It's 5 characteristics for
    each of 5 houses - that's 3125 possibilities.  Make a big array of
    booleans, initialised to true.  Run through the array and kill any
    combination that is contrary to one of the facts.  It might have been a
    worthy benchmark in 1962 but it should not be challenging to solve with
    modern machines.  (Of course it can still inspire interesting solutions
    and ways to express code in different languages.)

    Not that simple, try it to know (your eye may fool you, just like with libwy).

    a_puzzle_2.cpp (736 lines) was a random try in normal C++ programming
    style. I did not try to optimize it. It took 3m22s.
    a_puzzle_21.cpp has 178 lines, about 40 lines of comments, so 178-40=138 lines.
    So, I have reason to doubt 60 lines of prolog can do the job. And most importantly, the number of 0.03 seconds is too difficult to explain.
    Prolog is not really a declarative language, you need to provide 'algorithm' to 'compute' the answer. So, there is reason why 'prolog' program can run faster.
    But, unless there is some built-in mechanism in modern prolog to solve Zebra-puzzle-like problem, 60 lines of codes is dubious to me
    and even so, 0.03 seconds remains highly dubious.


    I just wrote a short Python program for the task. Yes, it was a little
    more involved than I had suggested (though there was also no need to
    store an array of booleans). I took all possible mixes for the house
    numbers, colours, etc. - that's 15625 sets and filtered out the ones
    that don't match the rules which did not involve neighbour-finding.
    Taking all the combinations there that pick one from each house, and
    there are 9810801 sets. Eliminate sets where you don't have one of each nationality, one of each house colour, etc., then filter through the
    neighbour rules. That gives one answer set.

    It was about 80 lines of Python (43 lines of code), and took 3.6 seconds
    to run (interpreted Python 3.10 - with pypy, it was about 1 second).
    There was no optimisation effort at all, with lots of use of list comprehensions, comparisons of strings, and so on - there's plenty of
    scope for writing it in a faster way.

    Do I believe that a decently written program in a language that is
    dedicated to such tasks could be a hundred times as fast as interpreted
    Python? I think it is not entirely unrealistic. (And I expect that a carefully written C++ program would be too fast to measure on a single
    run - especially if you through in vector instructions.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to [email protected] on Thu Dec 12 09:59:14 2024
    On 11.12.2024 10:40, [email protected] wrote:
    On Wed, 11 Dec 2024 08:59:18 +0100
    David Brown <[email protected]> wibbled:
    On 10/12/2024 17:35, [email protected] wrote:
    On Tue, 10 Dec 2024 17:04:37 +0100
    David Brown <[email protected]> wibbled:
    On 10/12/2024 10:23, wij wrote:
    Very dubious, show us what you say is true.


    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about them.
    It's at least 35 years since I tried Prolog one afternoon, and that's
    exactly the kind of task I played with (though a bit smaller).

    I found Prolog an absolute bugger of a language. Beyond simple clauses it >>> never did what I expected it to do. Its the one language I never really
    got. I think it requires a certain mindset or way of thinking.


    Having only tried it for a short time as a teenager, it's not fair for
    me to judge it - but it is certainly quite a different kind of language >>from C++!

    We had to use it in the AI module at uni. :/

    I suspect its raison d'etre has rather been shot down these days as AI has moved away from propositional logic to neural networks.

    Some propositional logic would be very beneficial for the current
    babble-GPT style AI. This is exactly what they are missing. Alas, this
    would assume they understand a bit what they are babbling about, which
    is not the case.

    As far as I can tell, currently their hope is that by piling more and
    more data and hardware on top of their AI it would accidentally discover
    by itself several important features:

    a) a coherent world model
    b) rules of logic for operating with the model
    c) some way to connect the model to their huge data corpora
    d) some way to check if the model corresponds to reality

    Given that even many people have huge problems with a), b) and d) I
    would not hold my hopes high that all these things would somehow
    randomly emerge.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to wij on Thu Dec 12 08:59:27 2024
    On 12/12/2024 06:26, wij wrote:
    On Wed, 2024-12-11 at 12:42 +0100, David Brown wrote:
    On 10/12/2024 18:02, wij wrote:
    On Tue, 2024-12-10 at 17:04 +0100, David Brown wrote:
    On 10/12/2024 10:23, wij wrote:
    On Mon, 2024-12-09 at 22:15 -0800, Tim Rentsch wrote:
    wij <[email protected]> writes:

    On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote:

    wij <[email protected]> writes:

    Because I said:  C++ is the best language to model general
    problems.  So it is.

    Almost all are logical propositions.  Except those few keywords, >>>>>>>>> such programwon't be recognized as a C++ program, instead of some >>>>>>>>> kind of declarative language.

    Zebra puzzle is an interesting programing exercise because it is >>>>>>>>> not too easy and also not too difficult.

    ------------
    /* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2023

       Example of solving the zebra puzzle by using propositional logic.
       Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Puzzle >>>>>>>>>
    [...]
    */
    #include <Wy.stdio.h>
    #include <Sc/PropExpr.h>

    using namespace Wy;
    using namespace Sc;

    [...]

    You're asking a question that cannot be answered because much or >>>>>>>> most of the program is in the two include files, which are not >>>>>>>> shown.

    As a general rule, when posting code there should be enough posted >>>>>>>> so that readers can at least compile it.  In cases like the program >>>>>>>> asked about here, what is posted should be enough to both compile >>>>>>>> the program and run the generated executable.

    I thought nobody will be interested with the implement, and what >>>>>>> is shown should be enough for the moment.

    The point is that what was posted is not enough to answer the
    question of the Subject: line.

    The Zebra Puzzle program has two version, a_puzzle_21.cpp (has
    shown) takes too long to complete.  a_puzzle_2.cpp (736 lines, too >>>>>>> long to post, I thought) is the realistic one written in way I
    feel just solving the prolem is enough.

    I wrote a program in prolog to solve this puzzle.  The entire
    program is 60 lines long, including 13 blank lines.  It finds
    the solution in 0.03 seconds.  The program doesn't do anything
    fancy;  it pretty much just gives the listed conditions in the form >>>>>> of prolog rules, plus 20 lines to establish the structure of the
    information that is being sought.

    Very dubious, show us what you say is true.


    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about them.
    It's at least 35 years since I tried Prolog one afternoon, and that's
    exactly the kind of task I played with (though a bit smaller).

    I know a bit of prolog,lisp (in DOS era). Strongly suspicious what Tim says.

    This is not a big problem in any language.  It's 5 characteristics for >>>> each of 5 houses - that's 3125 possibilities.  Make a big array of
    booleans, initialised to true.  Run through the array and kill any
    combination that is contrary to one of the facts.  It might have been a >>>> worthy benchmark in 1962 but it should not be challenging to solve with >>>> modern machines.  (Of course it can still inspire interesting solutions >>>> and ways to express code in different languages.)

    Not that simple, try it to know (your eye may fool you, just like with libwy).

    a_puzzle_2.cpp (736 lines) was a random try in normal C++ programming
    style. I did not try to optimize it. It took 3m22s.
    a_puzzle_21.cpp has 178 lines, about 40 lines of comments, so 178-40=138 lines.
    So, I have reason to doubt 60 lines of prolog can do the job. And most
    importantly, the number of 0.03 seconds is too difficult to explain.
    Prolog is not really a declarative language, you need to provide 'algorithm'
    to 'compute' the answer. So, there is reason why 'prolog' program can run faster.
    But, unless there is some built-in mechanism in modern prolog to solve
    Zebra-puzzle-like problem, 60 lines of codes is dubious to me
    and even so, 0.03 seconds remains highly dubious.


    I just wrote a short Python program for the task.  Yes, it was a little
    more involved than I had suggested (though there was also no need to
    store an array of booleans).  I took all possible mixes for the house
    numbers, colours, etc. - that's 15625 sets and filtered out the ones
    that don't match the rules which did not involve neighbour-finding.
    Taking all the combinations there that pick one from each house, and
    there are 9810801 sets.  Eliminate sets where you don't have one of each
    nationality, one of each house colour, etc., then filter through the
    neighbour rules.  That gives one answer set.

    (5^6) = 156255
    (5^6)*(4^6) = 64000000
    (5^6)*(4^6)*(3^6)= 46656000000
    (5^6)*(4^6)*(3^6)*(2^6)= 2985984000000

    6-attr version simply has too many instances, so I changed to 5-attr version

    (5^5)*(4^5) = 3200000
    (5^5)*(4^5)*(3^5) = 777600000
    (5^5)*(4^5)*(3^5)*(2^5)= 24883200000


    There is a difference between "not optimising" and "thoughtlessly brute
    force" !

    Starting out, there are 5 ^ 5 sets for each house - 5 ^ 6 sets in all.
    Apply rules 2, 3, 4, 5, 7, 8, 9, 10, 13 and 14 to filter these - that's
    the rules that don't involve any kind of neighbour relationships. That
    gives you 21 possibilities for house 0, 13 possibilities for house 2,
    and 33 possibilities for the other houses. (Rules 9 and 10 reduce the
    numbers for houses 2 and 0.)

    21 * 33 * 13 * 33 * 33 = 9810801

    That's the search space for considering the "Latin square" requirement
    (only one in each set from each nationality, with each pet, etc.). That
    gets you down to 2016 combinations.

    Then filter through rules 6, 11, 12, 15 about neighbour relationships to
    get one answer set.

    Of course there are many other ways to organise this problem - in
    particular, you can handle the constraints in different orders, or you
    can divide the "build search space then filter out" in different ways (I
    used two levels, as described). Or you can view the search space as a
    tree that you build up and prune as you go along.

    You can even go for the most brute-force method of all - there are 5 ^ 5 combinations for each house, so you have (5 ^ 5) ^ 5 sets for all five
    houses. Check each of these 298023223876953125 sets against all the
    rules, and see which one passes.

    Your approach is a little less bad than that, but only a little.



    If my PC only runs the program like the t.cpp above, it will need 49.8s to complete (below 49.8s is not possible, unless the program model is not (5^5)*(4^5)*(3^5)*(2^5)).

    With the 5-attr version (t_zebra2.cpp):

    -----------------
    []$ g++ t_zebra2.cpp -lwy -O2
    []$ time ./a.out
    (Yellow,Norwegian,Water,Kools,Fox)
    (Blue,Ukrainian,Tea,Chesterfield,Horse)
    (Red,Englishman,Milk,OldGold,Snail) (Ivory,Spaniard,OrangeJuice,LuckyStrike,Dog) (Green,Japanese,Coffee,Parliament,Zebra)
    OK

    real 4m1.683s
    user 4m1.244s
    sys 0m0.001s

    It was about 80 lines of Python (43 lines of code), and took 3.6 seconds
    to run (interpreted Python 3.10 - with pypy, it was about 1 second).
    There was no optimisation effort at all, with lots of use of list
    comprehensions, comparisons of strings, and so on - there's plenty of
    scope for writing it in a faster way.

    I guess, 3.6s is the first solution found.

    There is only one solution. So yes, technically it /is/ the first
    solution found - it is also the /last/ solution found. (Had there been
    more than one solution, they'd all have come out.)


    Do I believe that a decently written program in a language that is
    dedicated to such tasks could be a hundred times as fast as interpreted
    Python?  I think it is not entirely unrealistic.  (And I expect that a
    carefully written C++ program would be too fast to measure on a single
    run - especially if you through in vector instructions.)

    Nothing absolutely bad with interpreted language. If properly supported
    and used, Python should be better than C++ (conditional).


    This example demonstrates that a slow interpreted language with a good algorithm soundly beating a fast compiled language with a bad algorithm.
    (And my algorithm was far from optimal, and the implementation of it
    in Python was also far from optimal.)


    Now I just need to translate my code into C++ :-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to All on Thu Dec 12 08:32:46 2024
    On Wed, 11 Dec 2024 09:41:14 -0800
    Ross Finlayson <[email protected]> wibbled:
    and friends have been running "AI" since for example
    the '80's at least since Moravec said "you know
    we've had human-level AI for a while, ....".

    Either he was refering to humans or he was smoking some VERY expensive weed.

    It's moreso that various un-truths about the actual
    implementations of AI offerings are designed to
    reduce liability with regards to things like
    "well it doesn't really think, and thus be
    responsible for its actions, the dictates".

    They don't think, or at least ChatGPT. It seems very clever at first and there's no doubt its a quantum leap in AI, but the more you use it the more
    you realise how inconsistent it is and the apparent lack of understanding of some basic concepts.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to All on Thu Dec 12 08:37:26 2024
    On Thu, 12 Dec 2024 09:59:14 +0200
    Paavo Helde <[email protected]> wibbled:
    On 11.12.2024 10:40, [email protected] wrote:
    We had to use it in the AI module at uni. :/

    I suspect its raison d'etre has rather been shot down these days as AI has >> moved away from propositional logic to neural networks.

    Some propositional logic would be very beneficial for the current
    babble-GPT style AI. This is exactly what they are missing. Alas, this
    would assume they understand a bit what they are babbling about, which
    is not the case.

    The problem with propositional logic is its completely restricted to what
    its been programmed with. If there was a way for a logic system to slurp the internet the way neural nets do and create its own clean logical deductions it might work but clearly there isn't or someone would have done it by now.

    Given that even many people have huge problems with a), b) and d) I
    would not hold my hopes high that all these things would somehow
    randomly emerge.

    Given that even the programmers don't really understand how these systems
    work at the deep level I don't think anyone can make any predictions about wghat they might do. However the limit of the current designs seems to have been reached beyond tweaks here and there.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to wij on Thu Dec 12 08:00:01 2024
    wij <[email protected]> writes:

    On Tue, 2024-12-10 at 17:04 +0100, David Brown wrote:

    On 10/12/2024 10:23, wij wrote:

    On Mon, 2024-12-09 at 22:15 -0800, Tim Rentsch wrote:

    wij <[email protected]> writes:

    On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote:

    wij <[email protected]> writes:

    Because I said: C++ is the best language to model general
    problems. So it is.

    Almost all are logical propositions. Except those few
    keywords, such programwon't be recognized as a C++ program,
    instead of some kind of declarative language.

    Zebra puzzle is an interesting programing exercise because it
    is not too easy and also not too difficult.

    ------------
    /* Copyright is licensed by GNU LGPL, see file COPYING. by
    I.J.Wang 2023

    Example of solving the zebra puzzle by using propositional logic. >>>>>>> Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Puzzle

    [...]
    */
    #include <Wy.stdio.h>
    #include <Sc/PropExpr.h>

    using namespace Wy;
    using namespace Sc;

    [...]

    You're asking a question that cannot be answered because much
    or most of the program is in the two include files, which are
    not shown.

    As a general rule, when posting code there should be enough
    posted so that readers can at least compile it. In cases like
    the program asked about here, what is posted should be enough
    to both compile the program and run the generated executable.

    I thought nobody will be interested with the implement, and what
    is shown should be enough for the moment.

    The point is that what was posted is not enough to answer the
    question of the Subject: line.

    The Zebra Puzzle program has two version, a_puzzle_21.cpp (has
    shown) takes too long to complete. a_puzzle_2.cpp (736 lines,
    too long to post, I thought) is the realistic one written in way
    I feel just solving the prolem is enough.

    I wrote a program in prolog to solve this puzzle. The entire
    program is 60 lines long, including 13 blank lines. It finds the
    solution in 0.03 seconds. The program doesn't do anything fancy;
    it pretty much just gives the listed conditions in the form of
    prolog rules, plus 20 lines to establish the structure of the
    information that is being sought.

    Very dubious, show us what you say is true.

    Prolog is a language that is ideally suited to such problems.
    Basically, you give the language a bunch of objects and facts and
    relations about those objects, then you ask it questions about
    them. It's at least 35 years since I tried Prolog one afternoon,
    and that's exactly the kind of task I played with (though a bit
    smaller).

    I know a bit of prolog,lisp (in DOS era). Strongly suspicious what
    Tim says.

    This is not a big problem in any language. It's 5 characteristics
    for each of 5 houses - that's 3125 possibilities. Make a big array
    of booleans, initialised to true. Run through the array and kill
    any combination that is contrary to one of the facts. It might
    have been a worthy benchmark in 1962 but it should not be
    challenging to solve with modern machines. (Of course it can still
    inspire interesting solutions and ways to express code in different
    languages.)

    Not that simple, try it to know (your eye may fool you, just like
    with libwy).

    a_puzzle_2.cpp (736 lines) was a random try in normal C++
    programming style. I did not try to optimize it. It took 3m22s. a_puzzle_21.cpp has 178 lines, about 40 lines of comments, so
    178-40=138 lines. So, I have reason to doubt 60 lines of prolog
    can do the job. And most importantly, the number of 0.03 seconds
    is too difficult to explain. Prolog is not really a declarative
    language, you need to provide 'algorithm' to 'compute' the answer.
    So, there is reason why 'prolog' program can run faster. But,
    unless there is some built-in mechanism in modernprolog to solve Zebra-puzzle-like problem, 60 lines of codes is dubious to me and
    even so, 0.03 seconds remains highly dubious.

    I'm wondering what it is you are dubious about. Are you dubious

    (a) that I know how to use the 'wc' program to see how many
    lines there are in a file?

    (b) that I know how to use awk, and pipe the results into wc,
    to see how many blank lines there are in a file?

    (c) that I am capable of writing a prolog program that can be
    accepted and run by the swipl prolog interpreter?

    (d) that I know how to run a prolog program contained in a file,
    and look at the output it produces?

    (e) that I am capable of checking the output against the problem
    specification, to be sure the purported solution satisifies
    the conditions of the problem?

    (f) that I know how to use 'time' in a linux/unix shell, to see
    how long it took to run a program?

    (g) that I know how to interpret the output of 'time', and map
    it onto a time as measured by a regular time-keeping device
    such as a stopwatch?

    Or is that you just think I'm a liar?

    Incidentally I cleaned up the program a bit, and now it is only 50
    lines long, including 13 blank lines. It doesn't run any faster
    than it did before; still taking about 0.03 seconds of user time,
    and about 0.04 seconds real time (that includes the time taken by a
    short shell script wrapper to prettify the output).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to wij on Sun Dec 15 10:45:33 2024
    On 14/12/2024 09:22, wij wrote:
    On Thu, 2024-12-12 at 08:59 +0100, David Brown wrote:

    "21 * 33 * 13 * 33 * 33 = 9810801" is a pretty much *optimized* solution. Depending on the viewpoint (what kind of problem you want to solve), the puzzle solving algorithm can be from O(1) to O(2^N).


    "Optimised" would mean, as I see it, as fast as possible within
    reasonably practical limits. (And of course it would be unreasonable to
    simply pre-calculate the answer.) For a problem like this, there are
    three kinds of optimisations - algorithmic, choice of language or
    compute platform, and optimisation of the implementation itself.

    I have done none of these, so IMHO my solution is far from optimal. All
    I did was split the problem into two parts based on a simple criteria.
    To me, the split was so obvious that I do not see it as something
    special - but perhaps it is one of these things that seems obvious once
    you have thought of it.

    Algorithmic optimisation would involve dividing the problem into more
    parts, probably using a search tree and stack structure of some kind but ensuring that it is all allocated and handled with as little dynamic
    allocation as possible.

    Language and compute platform choice optimisation would certainly result
    in something other than single-threaded Python. It might mean Prolog,
    it might mean C++. Maybe this can be done on a GPU in CUDA - I don't
    know such platforms well. Certainly it would aim to be multi-threaded
    (at least, for a similar style of problem that is large enough to
    justify the overheads). And a key consideration would be cache friendly structures.

    And I didn't bother doing any kind of implementation optimisation at
    all. There is probably scope for increasing speed by a factor of 5 or
    so in straightforward Python, more from the use of numpy. But there's a
    lot more possibility in C++.



    Now I just need to translate my code into C++ :-)

    So far from I know, using C++ to beat those numbers you provided from Python is no trivial task. I estimate the limit is 0.08s (on my PC's speed) if nothing
    significantly changed.


    I don't think it should be hard to do a lot better than the Python code
    from a fairly direct translation of the Python - lists to std::vector<>,
    and so on. Translating into more optimal C++ code would lead to a huge improvement in speed. I would not expect the results to be measurable
    with the "time" command without looping the algorithm many times.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)