Logic programming with glob patterns

  • 15 Replies
  • 9415 Views
*

Zero

  • Eve
  • ***********
  • 1287
Logic programming with glob patterns
« on: September 13, 2015, 09:08:29 am »
Hi all,

In the "what language for a thinkbot" series, here is my idea from last night.

If you reverse AIML, you get a cheap logic engine.

Code
Knowledge:
  the sky is blue
  the sky is big

Query:
  the sky is *

Answer:
  blue
  big

It's like saying "the sky is what?"

With multiple constraints:
Code
Knowledge:
the sky is blue
the sky is big
blue is a color

Query:
the sky is {1}
{1] is a color

Answer:
blue

If knowledge is stored in a tree, it can be pretty fast I guess.
It's easy to use and understand anyway, which is important if you believe in crowdsourcing.

*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1302
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Logic programming with glob patterns
« Reply #1 on: September 13, 2015, 03:57:06 pm »
Code
Knowledge:
the sky is blue
the sky is big
blue is a color

Query:
the sky is {1}
{1] is a color

Answer:
blue

And, therefore:

Code
Query:
the sky is {1}
{1] is a color
the sky is a color

Or, with {1}, {2}, {3}:

Code
Query:
THE {1} IS {2}
{2] IS A {3}
THE {1} IS A {3}

Opinion: Reversing a finalized A.I. which has been tightly coupled for years, may not the best way to go for learning purposes, I think. It is more educational to start fresh.


▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
                                                           8PLA.NET
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
« Last Edit: September 13, 2015, 04:34:42 pm by 8pla.net »
My Very Enormous Monster Just Stopped Using Nine

*

Zero

  • Eve
  • ***********
  • 1287
Re: Logic programming with glob patterns
« Reply #2 on: September 13, 2015, 04:13:42 pm »
No, {1} was supposed to be an lvar. I was asking "what can {1} be if the sky is {1} and {1} is a color?" My bad, I wasn't clear.

But it's not a logic engine yet, since we would need facts and rules to run a complete engine. So we could do it old style, like this...
Code
[the Bing family]
John is the father of Miranda
Miranda is the father of Chandler

[generally speaking]
if you can say:
    "man1" is the father of "man2"
    "man2" is the father of "man3"
then you can say:
    "man1" is the grandfather of "man3"
...and then query the engine (here lvars are between double quotes).

Or embed it in functions, like...
Code
=> the Bing family
John is the father of Miranda
Miranda is the father of Chandler

{the grandfather of <name>}
considering: "man1" is the father of "man2"
considering: "man2" is the father of <name>
render: "man1"

[main]
about: the Bing family
print: Grandpa is (the grandfather of Chandler)
...or something.

*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1302
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Logic programming with glob patterns
« Reply #3 on: September 13, 2015, 04:51:39 pm »
You said, "My bad, I wasn't clear."  Oh, I must say, your pseudo code was very clear to me.  It was thought-provoking, so I thought I would try to apply it to a larger area. 

However, I offered no critique of your pseudo code for covering a smaller area!  That, is very important.  Maybe, more important. 

In your pseudo code, the A.I. would know more about what it was talking about, since the number of words it matched is greater.  So, your pseudo code is a valid case.
My Very Enormous Monster Just Stopped Using Nine

*

DemonRaven

  • Trusty Member
  • ********
  • Replicant
  • *
  • 630
  • Disclaimer old brain @ work not liable for content
    • Chatbotfriends
Re: Logic programming with glob patterns
« Reply #4 on: September 14, 2015, 01:32:17 am »
it looks good to me. I am not a expert by any means. I am frustrating myself by learning programming more of it. I know basic html but i am rusty on html 5 and css and do not know java script. So if i want to learn to program with rivescript i need to brush up on that stuff.
So sue me

*

Zero

  • Eve
  • ***********
  • 1287
Re: Logic programming with glob patterns
« Reply #5 on: September 14, 2015, 09:11:25 am »
Thank you. Javascript is rather friendly. Sometimes it will tell you that 2+3 = 23, but beyond that, it's nice!

*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1302
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Logic programming with glob patterns
« Reply #6 on: September 14, 2015, 02:02:45 pm »
My recommendation is to start out with PHP and plain HTML.
My Very Enormous Monster Just Stopped Using Nine

*

Zero

  • Eve
  • ***********
  • 1287
Re: Logic programming with glob patterns
« Reply #7 on: September 14, 2015, 02:10:25 pm »
Yes, or NodeJS!

So, I keep going. The following program...
Code
	=> way to school
right from home is town
up from town is school
up from home is woods
right from woods is school

{possible ways}
consider: "direction1" from home is "a place"
consider: "direction2" from "a place" is school
formulate: we can go "direction1" to "a place" and then "direction2" to school
render: <this>

[main]
print: (possible ways)
... should print:
we can go up to woods and then right to school
we can go right to town and then up to school

Right?

*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1302
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Logic programming with glob patterns
« Reply #8 on: September 14, 2015, 02:46:49 pm »


********************************
*                              *
*                              *
*   Raven,                     *
*                              *
*   If you are going for       *
*   high performance, or you   *
*   are building a robot,      *
*   then the C language, or    *
*   C++ is the best choice.    *
*   C/C++ is more powerful     *
*   than Perl or PHP, though   *
*   it takes a lot to reach    *
*   the limits of web based    *
*   programming.  The limits   *
*   are definitely there,      *
*   though.                    *
*                              *
*   For the web, C and C++     *
*   are not the best choice.   *
*   Perl or PHP are the        *
*   best free choices.         *
*   ASP.NET is the best        *
*   commercial choice. PHP     *
*   is more widely             *
*   supported, and does not    *
*   require a cgi-bin          *
*   directory.  Perl may be    *
*   a little more powerful     *
*   than PHP, but you can do   *
*   alot more with PHP, I      *
*   think.                     *
*                              *
*   PHP works perfectly with   *
*   HTML5 and CSS and          *
*   JavaScript, which you      *
*   can brush up on later.     *
*   JavaScript is the most     *
*   powerful client side       *
*   language. HTML5 relies     *
*   heavily on JavaScript.     *
*   There is supposedly, no    *
*   way to protect             *
*   JavaScript, besides        *
*   obfuscation. If you're     *
*   going open source, or      *
*   don't care about           *
*   protecting JavaScript,     *
*   then that's another        *
*   matter.                    *
*                              *
*   In conclusion, I am        *
*   simply sharing my picks    *
*   for development            *
*   languages.  Someone else   *
*   may have a different       *
*   opinion, and that's just   *
*   fine with me.  For         *
*   example, I find Logic      *
*   programming with glob      *
*   patterns very              *
*   interesting with what      *
*   Zero is researching.       *
*   It's all good, but if      *
*   you are just starting      *
*   out. I would recommend     *
*   PHP and plain HTML, then   *
*   start adding JavaScript,   *
*   then move on to HTML5.     *
*                              *
*                              *
********************************


My Very Enormous Monster Just Stopped Using Nine

*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1302
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Logic programming with glob patterns
« Reply #9 on: September 14, 2015, 02:53:44 pm »
I formatted the post above using PHP, just for fun.

So, I keep going.

Yes, let's keep going.  Thanks for this.

I would suggest (politely) :   North, East, South, West.
My Very Enormous Monster Just Stopped Using Nine

*

Zero

  • Eve
  • ***********
  • 1287
Re: Logic programming with glob patterns
« Reply #10 on: September 14, 2015, 03:23:58 pm »
Yep, why not. It works too!  :)
I used a new command "formulate" because I realized that answers to queries are actually arrays of arrays, say with lvars in columns and possibilities in rows. The "formulate" command makes a single sentence from one row. I never really digged (dug?) into logic programming before.

EDIT:

Code

=> ways to school

east from home is town
north from town is school
north from home is woods
east from woods is school



{possible ways}

consider: "direction1" from home is "a place"
consider: "direction2" from "a place" is school
formulate: go "direction1" to "a place" and then "direction2" to school

render: <this>



[main]

consider: <ways to school>

for each item from: (possible ways)
print: We can <item>.

print: Done.


The "consider" command places things in a variable named <truth>. The "formulate" command works from what is in this <truth> variable. Then we would have a "putaside" command that removes stuff from <truth>, an "if" command that succeeds only if its argument can be found in <truth>, and a "while" command. And one last: the "store truth in" command that would store the current content of <truth> in another variable.

[ ] sections are commands
{ } sections are functions
=> sections are merely variables containing lists of strings

Code blocks end with a blank line. For now.
« Last Edit: September 14, 2015, 04:01:42 pm by Zero »

*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1302
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Logic programming with glob patterns
« Reply #11 on: September 15, 2015, 11:19:14 pm »
   ways to school

   east from home is town
   north from town is school
   north from home is woods
   east from woods is school


Rule:
direction from starting_point is end_point

if starting_point is home and end_point is town then direction is east.
if starting_point is town and end_point is school then direction is north.
if starting_point is home and end_point is woods then direction is north.
if starting_point is woods and end_point is school then direction is east.

Why?
"from" indicates starting point. We can always start from zero whether it
is home, town, woods.  Since we have four directions, we can travel on
the Z axis, positive moving south, negative moving north and X axis,
positive moving east, negative negative moving west.


  N     - 
 W+E   -0+
  S     +


The Y axis can be the bird's eye view, but we don't need it right now.
My Very Enormous Monster Just Stopped Using Nine

*

Zero

  • Eve
  • ***********
  • 1287
Re: Logic programming with glob patterns
« Reply #12 on: September 17, 2015, 09:58:53 am »
Yes, you're right. I feel we need recursion now. So, back to the family example, we could have:

Code

=> the Bing family

Paul is the father of John
John is the father of Miranda
Miranda is the father of Chandler



{ancestors of <name>}

consider: "man1" is the father of <name>    // put in "man1" the father of <name>
formulate: "man1"                           // produce man1's name in <this>

for each item from: <this>                  // if <this> is not empty
with: (ancestors of <item>)                 // append man1's ancestors to <this>

render: <this>                              // return <this>



[main]

consider: (the Bing family)       // load the Bing family in <truth>

print: Ancestors of Chandler:
print: (ancestors of Chandler)    // print the list of ancestors

put aside: (the Bing family)



Next step would be to find our way in a map. Let's make it a little bigger:

Code

  +----------+------------+----------+
  |   town   |   woods    |  SCHOOL  |
  +----------+------------+----------+
  |   HOME   |  mountain  |   beach  |
  +----------+------------+----------+



  => map

  east from home is mountain
  east from mountain is beach
  north from home is town
  north from mountain is woods
  north from beach is school



  => map logic

  east from "west place" is "east place"
  north from "south place" is "north place"



  [build entire map]

  consider: <map logic>

  formulate: west from "east place" is "west place"
  consider: <this>

  formulate: south from "north place" is "south place"
  consider: <this>

  put aside: <map logic>



  [main]

  consider: <map>
  build entire map


Here with [build entire map] we deduce "west" and "south" links from existing "east" and "north" links. Now I'll try to build a way from home to school recursively.

EDIT: added a [main] section in the 2nd example

*

Zero

  • Eve
  • ***********
  • 1287
Re: Logic programming with glob patterns
« Reply #13 on: September 18, 2015, 09:04:01 am »
We split [consider] in [sufficient] and [necessary] because we need to express AND and OR.
[consider] is still here to accept new truths.



Code
  [make parents]

  sufficient: "parent" is the father of "child"
  sufficient: "parent" is the mother of "child"

  formulate: "parent" is the parent of "child"
  consider: <this>

If you're a father OR a mother, then you're a parent.



Code
  [make mom and dad]

  necessary: "dad" is the parent of "child"
  necessary: "dad" is a man

  formulate: "dad" is the father of "child"
  consider: <this>

  necessary: "mom" is the parent of "child"
  necessary: "mom" is a woman

  formulate: "mom" is the mother of "child"
  consider: <this>

If you're a parent AND you're a man, then you're a father.
If you're a parent AND you're a woman, then you're a mother.



[formulate] produces results, and then deletes every logic variable.

*

yotamarker

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1003
  • battle programmer
    • battle programming
Re: Logic programming with glob patterns
« Reply #14 on: March 05, 2016, 10:12:03 am »
I think some words have a special function in the brain :
colors
is
directions
occurance number

notice you used a pattern for those special words then had the program deal with that pattern
but why do you think you used those patterns in the first place.

what do you think ?

 


OpenAI Speech-to-Speech Reasoning Demo
by ivan.moony (AI News )
March 28, 2024, 01:31:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

284 Guests, 0 Users

Most Online Today: 363. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles