Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #121172 > unrolled thread
| Started by | wij <wyniijj5@gmail.com> |
|---|---|
| First post | 2024-12-09 20:08 +0800 |
| Last post | 2024-12-12 08:00 -0800 |
| Articles | 20 on this page of 23 — 6 participants |
Back to article view | Back to comp.lang.c++
Is this program OOP? wij <wyniijj5@gmail.com> - 2024-12-09 20:08 +0800
Re: Is this program OOP? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-12-09 09:35 -0800
Re: Is this program OOP? wij <wyniijj5@gmail.com> - 2024-12-10 06:35 +0800
Re: Is this program OOP? Ross Finlayson <ross.a.finlayson@gmail.com> - 2024-12-09 17:26 -0800
Re: Is this program OOP? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-12-09 22:15 -0800
Re: Is this program OOP? wij <wyniijj5@gmail.com> - 2024-12-10 17:23 +0800
Re: Is this program OOP? David Brown <david.brown@hesbynett.no> - 2024-12-10 17:04 +0100
Re: Is this program OOP? Muttley@DastardlyHQ.org - 2024-12-10 16:35 +0000
Re: Is this program OOP? David Brown <david.brown@hesbynett.no> - 2024-12-11 08:59 +0100
Re: Is this program OOP? Muttley@DastardlyHQ.org - 2024-12-11 08:40 +0000
Re: Is this program OOP? Ross Finlayson <ross.a.finlayson@gmail.com> - 2024-12-11 09:41 -0800
Re: Is this program OOP? Muttley@DastardlyHQ.org - 2024-12-12 08:32 +0000
Re: Is this program OOP? Ross Finlayson <ross.a.finlayson@gmail.com> - 2024-12-12 10:43 -0800
Re: Is this program OOP? Ross Finlayson <ross.a.finlayson@gmail.com> - 2024-12-12 17:28 -0800
Re: Is this program OOP? Paavo Helde <eesnimi@osa.pri.ee> - 2024-12-12 09:59 +0200
Re: Is this program OOP? Muttley@DastardlyHQ.org - 2024-12-12 08:37 +0000
Re: Is this program OOP? wij <wyniijj5@gmail.com> - 2024-12-11 01:02 +0800
Re: Is this program OOP? David Brown <david.brown@hesbynett.no> - 2024-12-11 12:42 +0100
Re: Is this program OOP? wij <wyniijj5@gmail.com> - 2024-12-12 13:26 +0800
Re: Is this program OOP? David Brown <david.brown@hesbynett.no> - 2024-12-12 08:59 +0100
Re: Is this program OOP? wij <wyniijj5@gmail.com> - 2024-12-14 16:22 +0800
Re: Is this program OOP? David Brown <david.brown@hesbynett.no> - 2024-12-15 10:45 +0100
Re: Is this program OOP? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-12-12 08:00 -0800
Page 1 of 2 [1] 2 Next page →
| From | wij <wyniijj5@gmail.com> |
|---|---|
| Date | 2024-12-09 20:08 +0800 |
| Subject | Is this program OOP? |
| Message-ID | <63cd41709a703e4ac6d76427d53fe06d7ee8b8b1.camel@gmail.com> |
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 program won'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
1.There are five houses.
2.The Englishman lives in the red house.
3.The Spaniard owns the dog.
4.Coffee is drunk in the green house.
5.The Ukrainian drinks tea.
6.The green house is immediately to the right of the ivory house.
7.The Old Gold smoker owns snails.
8.Kools are smoked in the yellow house.
9.Milk is drunk in the middle house.
10.The Norwegian lives in the first house.
11.The man who smokes Chesterfields lives in the house next to the man with the fox.
12.Kools are smoked in the house next to the house where the horse is kept.
13.The Lucky Strike smoker drinks orange juice.
14.The Japanese smokes Parliaments.
15.The Norwegian lives next to the blue house.
Note: This program takes lots of time/space, press cntrl-C to exit.
(a_logic_p2.cpp is more practical)
*/
#include <Wy.stdio.h>
#include <Sc/PropExpr.h>
using namespace Wy;
using namespace Sc;
constexpr WeName Red("Red");
constexpr WeName Yellow("Yellow");
constexpr WeName Blue("Blue");
constexpr WeName Ivory("Ivory");
constexpr WeName Green("Green");
constexpr WeName Norweg("Norweg");
constexpr WeName Ukrain("Ukrain");
constexpr WeName English("English");
constexpr WeName Spani("Spani");
constexpr WeName Japan("Japan");
constexpr WeName Water("Water");
constexpr WeName Tea("Tea");
constexpr WeName Milk("Milk");
constexpr WeName Orange("Orange"); // OrangeJuice
constexpr WeName Coffee("Coffee");
constexpr WeName Kools("Kools"); // Kools
constexpr WeName Chest("Chest"); // Chesterfield
constexpr WeName OldGold("OldGold"); // OldGold
constexpr WeName Lucky("Lucky"); // LuckyStrike
constexpr WeName Parl("Parl"); // Parliament
constexpr WeName Fox("Fox");
constexpr WeName Horse("Horse");
constexpr WeName Snail("Snail");
constexpr WeName Dog("Dog");
constexpr WeName Zebra("Zebra");
constexpr WeName No1("No1");
constexpr WeName No2("No2");
constexpr WeName No3("No3");
constexpr WeName No4("No4");
constexpr WeName No5("No5");
PropExpr same_house(WeName m1, WeName m2) {
return propSEL(
propAND(Prop(No1,m1),Prop(No1,m2)),
propAND(Prop(No2,m1),Prop(No2,m2)),
propAND(Prop(No3,m1),Prop(No3,m2)),
propAND(Prop(No4,m1),Prop(No4,m2)),
propAND(Prop(No5,m1),Prop(No5,m2)) );
};
PropExpr next_house(WeName m1, WeName m2) {
return propSEL(
PropExpr(Prop(No1,m1))&&PropExpr(Prop(No2,m2)),
PropExpr(Prop(No2,m1))&&propXOR(Prop(No1,m2),Prop(No3,m2)),
PropExpr(Prop(No3,m1))&&propXOR(Prop(No2,m2),Prop(No4,m2)),
PropExpr(Prop(No4,m1))&&propXOR(Prop(No3,m2),Prop(No5,m2)),
propAND(Prop(No5,m1),(Prop(No4,m2))) );
};
PropExpr map11(WeName n1, WeName n2, WeName n3, WeName n4, WeName n5)
{
return
propSEL(Prop(No1,n1),Prop(No1,n2),Prop(No1,n3),Prop(No1,n4),Prop(No1,n5))&&
propSEL(Prop(No2,n1),Prop(No2,n2),Prop(No2,n3),Prop(No2,n4),Prop(No2,n5))&&
propSEL(Prop(No3,n1),Prop(No3,n2),Prop(No3,n3),Prop(No3,n4),Prop(No3,n5))&&
propSEL(Prop(No4,n1),Prop(No4,n2),Prop(No4,n3),Prop(No4,n4),Prop(No4,n5))&&
propSEL(Prop(No5,n1),Prop(No5,n2),Prop(No5,n3),Prop(No5,n4),Prop(No5,n5))&&
propSEL(Prop(No1,n1),Prop(No2,n1),Prop(No3,n1),Prop(No4,n1),Prop(No5,n1))&&
propSEL(Prop(No1,n2),Prop(No2,n2),Prop(No3,n2),Prop(No4,n2),Prop(No5,n2))&&
propSEL(Prop(No1,n3),Prop(No2,n3),Prop(No3,n3),Prop(No4,n3),Prop(No5,n3))&&
propSEL(Prop(No1,n4),Prop(No2,n4),Prop(No3,n4),Prop(No4,n4),Prop(No5,n4))&&
propSEL(Prop(No1,n5),Prop(No2,n5),Prop(No3,n5),Prop(No4,n5),Prop(No5,n5))
;
};
// 1.There are five houses.
const PropExpr R1= map11(Red,Yellow,Blue,Ivory,Green)&&
map11(Norweg,Ukrain,English,Spani,Japan)&&
map11(Water,Tea,Milk,Coffee,Orange)&&
map11(Kools,Chest,OldGold,Lucky,Parl)&&
map11(Fox,Snail,Horse,Dog,Zebra);
// 2.The Englishman lives in the red house.
const PropExpr R2( same_house(Red,English) );
// 3.The Spaniard owns the dog.
const PropExpr R3( same_house(Spani, Dog) );
// 4.Coffee is drunk in the green house.
const PropExpr R4( same_house(Green,Coffee) );
// 5.The Ukrainian drinks tea.
const PropExpr R5( same_house(Ukrain, Tea) );
// 6.The green house is immediately to the right of the ivory house.
const PropExpr R6= propSEL(
propAND(Prop(No1,Ivory), Prop(No2,Green)),
propAND(Prop(No2,Ivory), Prop(No3,Green)),
propAND(Prop(No3,Ivory), Prop(No4,Green)),
propAND(Prop(No4,Ivory), Prop(No5,Green))
) && propNOR(Prop(No5,Ivory),Prop(No1,Green));
// 7.The Old Gold smoker owns snails.
const PropExpr R7( same_house(OldGold, Snail) );
// 8.Kools are smoked in the yellow house.
const PropExpr R8( same_house(Yellow, Kools) );
// 9.Milk is drunk in the middle house.
const PropExpr R9( Prop(No3,Milk) );
// 10.The Norwegian lives in the first house.
const PropExpr R10( Prop(No1,Norweg) );
// 11.The man who smokes Chesterfields lives in the house next to the man with the fox.
const PropExpr R11( next_house(Chest, Fox) );
// 12.Kools are smoked in the house next to the house where the horse is kept.
const PropExpr R12( next_house(Kools, Horse) );
// 13.The Lucky Strike smoker drinks orange juice.
const PropExpr R13( same_house(Lucky, Orange) );
// 14.The Japanese smokes Parliaments.
const PropExpr R14( same_house(Japan, Parl) );
// 15.The Norwegian lives next to the blue house.
const PropExpr R15( next_house(Norweg, Blue) );
void t0() {
PropExpr tt( R1 && R2 && R3 && R4 && R5 && R6 && R7 && R8 && R9 &&
R10 && R11 && R12 && R13 && R14 && R15
);
//tt.resolve_pstat(Descrip1);
cout << wrd(tt) << WY_ENDL;
};
int main()
try {
cout << "check " __FILE__ WY_ENDL;
t0();
cout << "OK" WY_ENDL;
return 0;
}
catch(const Errno& e) {
cerr << wrd(e) << WY_ENDL;
return -1;
}
catch(...) {
cerr << "main caught(...)" WY_ENDL;
return -1;
};
[toc] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2024-12-09 09:35 -0800 |
| Message-ID | <86plm0iwtj.fsf@linuxsc.com> |
| In reply to | #121172 |
wij <wyniijj5@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj5@gmail.com> |
|---|---|
| Date | 2024-12-10 06:35 +0800 |
| Message-ID | <035b9e2186f9dc6467806e27a76d98525c104e54.camel@gmail.com> |
| In reply to | #121173 |
On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote:
> wij <wyniijj5@gmail.com> 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 include files refer to two separate
libraries. I had just updated libsc to save 'unupdate' explanations.
https://sourceforge.net/projects/cscall/
https://sourceforge.net/projects/symbcomp/
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.
-------------------
[]$ make a_puzzle_p2
[]$ ./a_puzzle_p2
....
(3,Red,Englishman,Milk,OldGold,Snails)
(0,Green,Japanese,Coffee,Parliament,Zebra)
(1,Yellow,Norwegian,-,Kools,Fox)
(0,Ivory,Spaniard,OrangeJuice,LuckyStrike,Dog)
(2,Blue,Ukrainian,Tea,Chesterfield,Horse)
....
Repeatedly dumping the same thing says there is only one answer.
Ans: Japanese owns the Zebra.
Norwegian drinks water (only one possibility left)
---------------------
My whole point is that C++(and other programing languages, but less optimal,IMO)
could be a languge of mathmatics/logic, nearly the base of formal knowledges (so
don't make it too arbitrarily like a commercial product. Anyway, C++ is created
'for fun', a mathmatician's fun).
In short and roughly, inference is a kind of manipulation of model (I did not
predict what anyone's brain can do, human brain can create model)
We already use simulators to predict things, simulation is a kind of inference
based on all the 'pure' theories we presumed must be correct or 'tautologic' (
olcott's word).
[Snippet from README_en]
3. Theory is 'fabricated' after-events, starting entirely from current
theory totally misplaces the goal and the problem.
...
[toc] | [prev] | [next] | [standalone]
| From | Ross Finlayson <ross.a.finlayson@gmail.com> |
|---|---|
| Date | 2024-12-09 17:26 -0800 |
| Message-ID | <wYSdnT38YoYwBcr6nZ2dnZfqnPadnZ2d@giganews.com> |
| In reply to | #121176 |
On 12/09/2024 02:35 PM, wij wrote: > On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: >> wij <wyniijj5@gmail.com> 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 include files refer to two separate > libraries. I had just updated libsc to save 'unupdate' explanations. > https://sourceforge.net/projects/cscall/ > https://sourceforge.net/projects/symbcomp/ > > 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. > > ------------------- > []$ make a_puzzle_p2 > []$ ./a_puzzle_p2 > .... > (3,Red,Englishman,Milk,OldGold,Snails) > (0,Green,Japanese,Coffee,Parliament,Zebra) > (1,Yellow,Norwegian,-,Kools,Fox) > (0,Ivory,Spaniard,OrangeJuice,LuckyStrike,Dog) > (2,Blue,Ukrainian,Tea,Chesterfield,Horse) > .... > > Repeatedly dumping the same thing says there is only one answer. > Ans: Japanese owns the Zebra. > Norwegian drinks water (only one possibility left) > --------------------- > > My whole point is that C++(and other programing languages, but less optimal,IMO) > could be a languge of mathmatics/logic, nearly the base of formal knowledges (so > don't make it too arbitrarily like a commercial product. Anyway, C++ is created > 'for fun', a mathmatician's fun). > In short and roughly, inference is a kind of manipulation of model (I did not > predict what anyone's brain can do, human brain can create model) > We already use simulators to predict things, simulation is a kind of inference > based on all the 'pure' theories we presumed must be correct or 'tautologic' ( > olcott's word). > [Snippet from README_en] > 3. Theory is 'fabricated' after-events, starting entirely from current > theory totally misplaces the goal and the problem. > ... > > (I think usually one might call that "compiled FSM", as with regards to "jump tables" for example, what accumulate property bits, or enums or flags. It's nice to think that PropExpr results a little compile-time solver. In C++ it might be a fun exercise in templates.)
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2024-12-09 22:15 -0800 |
| Message-ID | <86h67chxn8.fsf@linuxsc.com> |
| In reply to | #121176 |
wij <wyniijj5@gmail.com> writes: > On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: > >> wij <wyniijj5@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj5@gmail.com> |
|---|---|
| Date | 2024-12-10 17:23 +0800 |
| Message-ID | <03fcd46b8d44390c78ca1719e2311b528570d276.camel@gmail.com> |
| In reply to | #121179 |
On Mon, 2024-12-09 at 22:15 -0800, Tim Rentsch wrote: > wij <wyniijj5@gmail.com> writes: > > > On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: > > > > > wij <wyniijj5@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2024-12-10 17:04 +0100 |
| Message-ID | <vj9oql$114ip$1@dont-email.me> |
| In reply to | #121180 |
On 10/12/2024 10:23, wij wrote: > On Mon, 2024-12-09 at 22:15 -0800, Tim Rentsch wrote: >> wij <wyniijj5@gmail.com> writes: >> >>> On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: >>> >>>> wij <wyniijj5@gmail.com> 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.)
[toc] | [prev] | [next] | [standalone]
| From | Muttley@DastardlyHQ.org |
|---|---|
| Date | 2024-12-10 16:35 +0000 |
| Message-ID | <vj9qkr$11ob7$1@dont-email.me> |
| In reply to | #121181 |
On Tue, 10 Dec 2024 17:04:37 +0100 David Brown <david.brown@hesbynett.no> 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.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2024-12-11 08:59 +0100 |
| Message-ID | <vjbgom$1eibh$1@dont-email.me> |
| In reply to | #121182 |
On 10/12/2024 17:35, Muttley@DastardlyHQ.org wrote: > On Tue, 10 Dec 2024 17:04:37 +0100 > David Brown <david.brown@hesbynett.no> 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++!
[toc] | [prev] | [next] | [standalone]
| From | Muttley@DastardlyHQ.org |
|---|---|
| Date | 2024-12-11 08:40 +0000 |
| Message-ID | <vjbj5n$1f4nv$1@dont-email.me> |
| In reply to | #121185 |
On Wed, 11 Dec 2024 08:59:18 +0100 David Brown <david.brown@hesbynett.no> wibbled: >On 10/12/2024 17:35, Muttley@DastardlyHQ.org wrote: >> On Tue, 10 Dec 2024 17:04:37 +0100 >> David Brown <david.brown@hesbynett.no> 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.
[toc] | [prev] | [next] | [standalone]
| From | Ross Finlayson <ross.a.finlayson@gmail.com> |
|---|---|
| Date | 2024-12-11 09:41 -0800 |
| Message-ID | <OP6dnfil9o1DU8T6nZ2dnZfqnPidnZ2d@giganews.com> |
| In reply to | #121186 |
On 12/11/2024 12:40 AM, Muttley@DastardlyHQ.org wrote: > On Wed, 11 Dec 2024 08:59:18 +0100 > David Brown <david.brown@hesbynett.no> wibbled: >> On 10/12/2024 17:35, Muttley@DastardlyHQ.org wrote: >>> On Tue, 10 Dec 2024 17:04:37 +0100 >>> David Brown <david.brown@hesbynett.no> 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. > Mechanized inference is at least three things: expert systems statistical inference neural networks and "AI offerings" generally always have each. LISP is what it is and still very much a thing, I'm not so much into s-expressions and so on, and it's recursive sort of declaration is a bit, you know, functional, yet though LISP and Prolog 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, ....". 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". Giant cheap floating-point units, ....
[toc] | [prev] | [next] | [standalone]
| From | Muttley@DastardlyHQ.org |
|---|---|
| Date | 2024-12-12 08:32 +0000 |
| Message-ID | <vje73d$21sgh$1@dont-email.me> |
| In reply to | #121190 |
On Wed, 11 Dec 2024 09:41:14 -0800 Ross Finlayson <ross.a.finlayson@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | Ross Finlayson <ross.a.finlayson@gmail.com> |
|---|---|
| Date | 2024-12-12 10:43 -0800 |
| Message-ID | <DLacnWTDZt5fs8b6nZ2dnZfqn_ednZ2d@giganews.com> |
| In reply to | #121195 |
On 12/12/2024 12:32 AM, Muttley@DastardlyHQ.org wrote: > On Wed, 11 Dec 2024 09:41:14 -0800 > Ross Finlayson <ross.a.finlayson@gmail.com> 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. > I think it's moreso that the hints you give are what it figures to give you, vis-a-vis making sure to command that it gives both the pros and cons, as it were. There were on-line psychiatrists since the '60's, and bots have been fooling simple humans since decades, and furthermore, "agents and actors in an ecosystem including large-language models", are a lot more than dumb, and usual online chat-bots these days can be directed to demomstrate very thorough and correct reasoning. Mostly it's that when you give it mistaken inputs, then it just freely piles upon the wrong ideas, "imagining" as it were, "playing along", or, you know, "GIGO". Mostly the advertising of these systems as not culpable for any their outputs, is just to avoid liability because otherwise they'd have to be as responsible for their actions and statements as any individual, the massive hegemony of "Google" which you'll notice has that just like search, that ChatGPT and Gemini have the same back-end. So, whatever's not in its context it feels free to "imagine", that you need to know how to give it a chance to demonstrate its assumptions instead of just imagining commonly held unstated assumptions, then verify going along that the assumptions, the stipulations, the axioms as they may be, are in the memory, of the sessions. I.e., it's a very fragmented hive-mind, and each session is a blank slate. Assuming that a massive online information-system couldn't emulate most human reasoning, would not necessarily be a rational expectation.
[toc] | [prev] | [next] | [standalone]
| From | Ross Finlayson <ross.a.finlayson@gmail.com> |
|---|---|
| Date | 2024-12-12 17:28 -0800 |
| Message-ID | <foycnd68Idw9EMb6nZ2dnZfqn_qdnZ2d@giganews.com> |
| In reply to | #121200 |
On 12/12/2024 10:43 AM, Ross Finlayson wrote: > On 12/12/2024 12:32 AM, Muttley@DastardlyHQ.org wrote: >> On Wed, 11 Dec 2024 09:41:14 -0800 >> Ross Finlayson <ross.a.finlayson@gmail.com> 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. >> > > I think it's moreso that the hints you give > are what it figures to give you, vis-a-vis > making sure to command that it gives both > the pros and cons, as it were. > > There were on-line psychiatrists since the '60's, > and bots have been fooling simple humans since > decades, and furthermore, "agents and actors in > an ecosystem including large-language models", > are a lot more than dumb, and usual online > chat-bots these days can be directed to demomstrate > very thorough and correct reasoning. > > Mostly it's that when you give it mistaken inputs, > then it just freely piles upon the wrong ideas, > "imagining" as it were, "playing along", or, > you know, "GIGO". > > Mostly the advertising of these systems as not > culpable for any their outputs, is just to avoid > liability because otherwise they'd have to be > as responsible for their actions and statements > as any individual, the massive hegemony of > "Google" which you'll notice has that just like > search, that ChatGPT and Gemini have the same back-end. > > So, whatever's not in its context it feels free > to "imagine", that you need to know how to give > it a chance to demonstrate its assumptions instead > of just imagining commonly held unstated assumptions, > then verify going along that the assumptions, > the stipulations, the axioms as they may be, > are in the memory, of the sessions. > > I.e., it's a very fragmented hive-mind, and each > session is a blank slate. > > > Assuming that a massive online information-system > couldn't emulate most human reasoning, would not > necessarily be a rational expectation. > > It's like the slightly-affected scientist who decided to use operant conditioning to train a pigeon to fly in circles. So, he rings a bell, ties the pigeon to the end of a stick, and swings it around until he observes the loosed pigeon sort of stumbling in a circle after swinging it around. Apparently having established control, then he's baffled when after this, he rings the bell, and the pigeon just flies directly away. After several attempts, he notices that when he rings the bell, the pigeon attacks him and gives him several pecks for his troubles. Taped up and with mercury iodide blotches everywhere, he writes in his notebook, "day 1: training pigeons makes them un-co-operative".
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <eesnimi@osa.pri.ee> |
|---|---|
| Date | 2024-12-12 09:59 +0200 |
| Message-ID | <vje54h$21d5b$1@dont-email.me> |
| In reply to | #121186 |
On 11.12.2024 10:40, Muttley@DastardlyHQ.org wrote: > On Wed, 11 Dec 2024 08:59:18 +0100 > David Brown <david.brown@hesbynett.no> wibbled: >> On 10/12/2024 17:35, Muttley@DastardlyHQ.org wrote: >>> On Tue, 10 Dec 2024 17:04:37 +0100 >>> David Brown <david.brown@hesbynett.no> 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.
[toc] | [prev] | [next] | [standalone]
| From | Muttley@DastardlyHQ.org |
|---|---|
| Date | 2024-12-12 08:37 +0000 |
| Message-ID | <vje7c5$21tr6$1@dont-email.me> |
| In reply to | #121193 |
On Thu, 12 Dec 2024 09:59:14 +0200 Paavo Helde <eesnimi@osa.pri.ee> wibbled: >On 11.12.2024 10:40, Muttley@DastardlyHQ.org 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.
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj5@gmail.com> |
|---|---|
| Date | 2024-12-11 01:02 +0800 |
| Message-ID | <fb4cdf9c1c99986b84c6f598858efe1a9473cd26.camel@gmail.com> |
| In reply to | #121181 |
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 <wyniijj5@gmail.com> writes: > > > > > > > On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: > > > > > > > > > wij <wyniijj5@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2024-12-11 12:42 +0100 |
| Message-ID | <vjbtr5$1h44t$1@dont-email.me> |
| In reply to | #121183 |
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 <wyniijj5@gmail.com> writes: >>>> >>>>> On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: >>>>> >>>>>> wij <wyniijj5@gmail.com> 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.)
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj5@gmail.com> |
|---|---|
| Date | 2024-12-12 13:26 +0800 |
| Message-ID | <64393d96ff8cc12e274038abda13ac54eacadfed.camel@gmail.com> |
| In reply to | #121187 |
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 <wyniijj5@gmail.com> writes:
> > > > >
> > > > > > On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote:
> > > > > >
> > > > > > > wij <wyniijj5@gmail.com> 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
----------- t.cpp (for estimation)
int main()
{
long long a=3;
for(long long i=0; i<1000000000L; ++i) { // loop 10^9
a+=3;
}
return 0;
};
[]$ g++ t.cpp
[]$ time ./a.out
eal 0m2.164s
user 0m2.154s
sys 0m0.005s
-----------------
(3200000/1000000000)*2s = 0.0064s
(777600000/1000000000)*2s = 1.555s
(24883200000/1000000000)*2s= 49.766s
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.
> 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).
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2024-12-12 08:59 +0100 |
| Message-ID | <vje54v$21dji$1@dont-email.me> |
| In reply to | #121192 |
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 <wyniijj5@gmail.com> writes: >>>>>> >>>>>>> On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: >>>>>>> >>>>>>>> wij <wyniijj5@gmail.com> 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++ :-)
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c++
csiph-web