Logic programming with glob patterns

  • 15 Replies
  • 4270 Views
*

Zero

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 481
  • Fictional character
    • SYN CON DEV LOG
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: [Select]
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: [Select]
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
  • *********
  • Terminator
  • *
  • 873
    • 8pla.net
Re: Logic programming with glob patterns
« Reply #1 on: September 13, 2015, 03:57:06 pm »
Code: [Select]
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: [Select]
Query:
the sky is {1}
{1] is a color
the sky is a color

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

Code: [Select]
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

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 481
  • Fictional character
    • SYN CON DEV LOG
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: [Select]
[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: [Select]
=> 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
  • *********
  • Terminator
  • *
  • 873
    • 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
  • *
  • 536
    • 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.

*

Zero

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 481
  • Fictional character
    • SYN CON DEV LOG
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
  • *********
  • Terminator
  • *
  • 873
    • 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

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 481
  • Fictional character
    • SYN CON DEV LOG
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: [Select]
=> 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
  • *********
  • Terminator
  • *
  • 873
    • 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
  • *********
  • Terminator
  • *
  • 873
    • 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

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 481
  • Fictional character
    • SYN CON DEV LOG
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: [Select]

=> 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
  • *********
  • Terminator
  • *
  • 873
    • 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

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 481
  • Fictional character
    • SYN CON DEV LOG
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: [Select]

=> 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: [Select]

  +----------+------------+----------+
  |   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

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 481
  • Fictional character
    • SYN CON DEV LOG
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: [Select]
  [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: [Select]
  [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
  • ********
  • Replicant
  • *
  • 596
    • 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 ?

 


Users Online

31 Guests, 0 Users

Most Online Today: 51. Most Online Ever: 208 (August 27, 2008, 09:36:30 am)

Articles