Deutsch   English   Français   Italiano  
<697574f53708b5c8a92d9facf184725795ff0e75.camel@gmail.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wij <wyniijj5@gmail.com>
Newsgroups: comp.lang.c++
Subject: Re: What is OOP?
Date: Mon, 09 Dec 2024 09:27:00 +0800
Organization: A noiseless patient Spider
Lines: 179
Message-ID: <697574f53708b5c8a92d9facf184725795ff0e75.camel@gmail.com>
References: <d8a5a0d563f0b9b78b34711d12d4975a7941f53a.camel@gmail.com>
	 <3a72f45ce7a77c6272e207f009ba09aece96f8df@i2pn2.org>
	 <253c0b3fe3ac8ea661af3347f93529bd0f03f3e2.camel@gmail.com>
	 <vj4mk6$3u8ea$1@dont-email.me>
	 <8adbdfc97097af5e53c0a22689362f1af2ae2b93.camel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Mon, 09 Dec 2024 02:27:01 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d21130fcf26d215eec62e322955e4662";
	logging-data="120123"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX187jEFznyGT51ZrmL4Y77NH"
User-Agent: Evolution 3.50.2 (3.50.2-1.fc39)
Cancel-Lock: sha1:H1igM9zVLewvZyaEZtmihqqzUiE=
In-Reply-To: <8adbdfc97097af5e53c0a22689362f1af2ae2b93.camel@gmail.com>
Bytes: 6635

On Mon, 2024-12-09 at 08:28 +0800, wij wrote:
> On Sun, 2024-12-08 at 17:56 +0000, Isaac Ganoung wrote:
> > On Mon, 02 Dec 2024 08:57:41 +0800, wij wrote:
> >=20
> > > How do you verify correctness just by the program 'logic'?
> >=20
> > You use a functional language like Haskell. You are probably looking fo=
r=20
> > this: https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence
>=20
> I don't know what to look for, maybe this is from another olcott, knowing
> nothing=C2=A0of what he quotes.
> So far, I feel C++ is the best language to model general problems.
>=20
> The following is in response to the example in the provided webpage (if t=
he
> problem is simple or from a selected set, there are generally various kin=
d
> of elegant solutions):
>=20
> ------------------------------------
> #include <Wy.stdio.h>
> #include <Sc/Search.h>
>=20
> using namespace Wy;
> using namespace Sc;
> #include "Sc/TestRule.inc" // This file must be included after the above =
using...
>=20
> const SubstiRule rule_fac0(fac(NatNum_0), NatNum_1); // fac(0) -> 1
> const SubstiRule rule_fac1(fac(UVarN_n), UVarN_n*fac(UVarN_n-NatNum_1)); =
// fac(n) -> n*fac(n-1)
>=20
> RuleSet rule;
>=20
> // Make rule from "Sc/TestRule.inc" and add two rules
> void make_rule() {
> =C2=A0Errno r;
> =C2=A0for(size_t ri=3D0; ri<sizeof(brule)/sizeof(brule[0]); ++ri) {
> =C2=A0=C2=A0 if((r=3Drule.add_rule(brule[ri]))!=3DOk) {
> =C2=A0=C2=A0=C2=A0=C2=A0 WY_THROW(r);
> =C2=A0=C2=A0 }
> =C2=A0}
> =C2=A0if((r=3Drule.add_rule(rule_fac0))!=3DOk) {
> =C2=A0=C2=A0 WY_THROW(r);
> =C2=A0}
> =C2=A0if((r=3Drule.add_rule(rule_fac1))!=3DOk) {
> =C2=A0=C2=A0 WY_THROW(r);
> =C2=A0}
>=20
> =C2=A0// dump the final rule
> =C2=A0cout << "-------- Rules ---------" << WY_ENDL;
> =C2=A0for(size_t i=3D0; i<rule.num_rules(); ++i) {
> =C2=A0=C2=A0 cout << '(' << wrd(i) << ") "
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 << wrd(rule.rule(i).match_patt=
ern()) << " -> "
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 << wrd(rule.rule(i).deduct_pat=
tern()) << WY_ENDL;
> =C2=A0}
> =C2=A0cout << "-----------------" << WY_ENDL;
> };
>=20
> void t0() {
> =C2=A0Errno r;
> =C2=A0make_rule();
> =C2=A0Search sr0(rule);
> =C2=A0const DyExpr ini_expr=3Dfac(NatNum_2);
> =C2=A0const DyExpr des_expr=3DNatNum_2;
>=20
> =C2=A0cout << "Compute: " << wrd(ini_expr) << " -> " << wrd(des_expr) << =
WY_ENDL;
> =C2=A0if((r=3Dsr0.search(ini_expr,des_expr,10,Search::Mode::Shortest))!=
=3DOk) {
> =C2=A0=C2=A0 WY_THROW(r);
> =C2=A0}
> =C2=A0const Array<Step>& garr=3D sr0.gpath();
> =C2=A0if(garr.is_empty()) {
> =C2=A0=C2=A0 cout << "goal is not found" WY_ENDL;
> =C2=A0} else {
> =C2=A0=C2=A0 cout << garr.size() << " steps" WY_ENDL;
> =C2=A0=C2=A0 for(size_t i=3D0; i<garr.size(); ++i) {
> =C2=A0=C2=A0=C2=A0=C2=A0 cout << '(' << garr[i].rule_index() << ") " << w=
rd(garr[i].expr()) << WY_ENDL;
> =C2=A0=C2=A0 }
> =C2=A0}
> };
>=20
> int main()
> try {
> =C2=A0cout << "check " __FILE__ WY_ENDL;
> =C2=A0t0();
> =C2=A0cout << "OK" WY_ENDL;
> =C2=A0return 0;
> }
> catch(const Errno& e) {
> =C2=A0cerr << wrd(e) << WY_ENDL;
> =C2=A0return -1;
> }
> catch(...) {
> =C2=A0cerr << "main caught(...)" WY_ENDL;
> =C2=A0return -1;
> };
> -----------------------
> []$ g++ a_fac.cpp -lwy
> []$ ./a.out=20
>=20
> check a_fac.cpp
> -------- Rules ---------
> (0) (_a+_b) -> (_b+_a)
> (1) (_a+(_b+_c)) -> ((_a+_b)+_c)
> (2) ((_a+_b)+_c) -> (_a+(_b+_c))
> (3) (_a+0) -> _a
> (4) (_a-_b) -> (_a+(-_b))
> (5) (_a+(-_b)) -> (_a-_b)
> (6) (_a-_a) -> 0
> (7) (-(_a+_b)) -> ((-_a)+(-_b))
> (8) ((-_a)+(-_b)) -> (-(_a+_b))
> (9) (-(-_a)) -> _a
> (10) (-0) -> 0
> (11) (_a*_b) -> (_b*_a)
> (12) (_a*(_b*_c)) -> ((_a*_b)*_c)
> (13) ((_a*_b)*_c) -> (_a*(_b*_c))
> (14) (_a*(_b+_c)) -> ((_a*_b)+(_a*_c))
> (15) ((_a*_b)+(_a*_c)) -> (_a*(_b+_c))
> (16) (_a*1) -> _a
> (17) (_a*0) -> 0
> (18) (_a/_b) -> (_a*(1/_b))
> (19) (_a*(1/_b)) -> (_a/_b)
> (20) (_a/_a) -> 1
> (21) (_a/0) -> $Und_D0
> (22) (-(_a*_b)) -> ((-_a)*_b)
> (23) ((-_a)*_b) -> (-(_a*_b))
> (24) (_a*(-_b)) -> ((-_a)*_b)
> (25) ((-_a)*_b) -> (_a*(-_b))
> (26) ((-_a)*(-_b)) -> (_a*_b)
> (27) (-(_a/_b)) -> ((-_a)/_b)
> (28) ((-_a)/_b) -> (-(_a/_b))
> (29) (_a/(-_b)) -> ((-_a)/_b)
> (30) ((-_a)/_b) -> (_a/(-_b))
> (31) ((-_a)/(-_b)) -> (_a/_b)
> (32) (_a^0) -> 1
> (33) (_a^1) -> _a
> (34) (_a^_b) -> (_a*(_a^(_b-1)))
> (35) ((_a*_b)^_c) -> ((_a^_c)*(_b^_c))
> (36) (_a^(_b+_c)) -> ((_a^_b)*(_a^_c))
> (37) (_a^(_b*_c)) -> ((_a^_b)^_c)
> (38) (0^_a) -> $Und_B0
> (39) (_a^(-_b)) -> (1/(_a^_b))
> (40) (2-1) -> 1
> (41) (_a*_a) -> (_a^2)
> (42) (_a+_a) -> (2*_a)
> (43) fac(0) -> 1
> (44) fac(_n) -> (_n*fac((_n-1)))
> -----------------
> Compute: fac(2) -> 2
> 7 steps
> (44) (2*fac((2-1)))
> (40) (2*fac(1))
> (44) (2*(1*fac((1-1))))
> (6) (2*(1*fac(0)))
> (43) (2*(1*1))
> (16) (2*1)
> (16) 2
> OK
>=20
> ----------------
> Common criticism of libwy is the many error check codes.
> But I feel such codes are necessary in real programs, hiding
> it is dishonest.

Have you found that rule [40] is strange? From there, already, stories can =
be
told about math. and logic (and C++, but more abstract).

Note: I did not comment Haskell, sine I know nealy nothing of it and wish t=
o
========== REMAINDER OF ARTICLE TRUNCATED ==========