Relation of filter expressions to boolean logic

109 views
Skip to first unread message

joearms

unread,
Dec 19, 2018, 9:54:59 AM12/19/18
to TiddlyWikiDev
I'm trying to understand filters by comparing them to boolean logic.

Given three tags A B and  C

Then a filter that finds A is "[tag[A]]"

B OR C is "[tag[B]] [tag[C]]"

A AND B is "[tag[A]tag[B]]"

A and (B or C) has to be rewritten as
(A and B) or (A and C) and is 

"[tag[A]tag[B]] [tag[A]tag[C]]"

Which in a strange way reminds me of horn clauses in Prolog where I'd write:

```
filter(a, b) :- ...
filter(a, c) :- ..
```

So really these filter expressions are equivalent to queries in predicate logic.

(which is why they are so powerful :-)

Cheers

/Joe


Jeremy Ruston

unread,
Dec 19, 2018, 5:21:15 PM12/19/18
to TiddlyWikiDev
Hi Joe

Then a filter that finds A is "[tag[A]]"

B OR C is "[tag[B]] [tag[C]]"

A AND B is "[tag[A]tag[B]]"

A and (B or C) has to be rewritten as
(A and B) or (A and C) and is 

"[tag[A]tag[B]] [tag[A]tag[C]]”

You can directly do A and (B or C) as:

[tag[B]] [tab[C]] +[tag[A]]

There are three runs here:

* The first two are processed in the same way: they start with an implicit [all[tiddlers]] to select all “real” tiddlers (ie, non-shadow tiddlers), whether or not they are system tiddelrs. The [tag[x]] filter operator selects those tiddlers that carry the indicated tag. At the end of processing each run, the results of the run are merged into the accumulator, the temporary holding storage for intermediate results.

* The third run starts with a “+” which means that instead of kicking off with all the real tiddlers, it instead uses the accumulator as the input to the run. The [tag[A]] then selects those tiddlers from the accumulator that carry the tag “A”.

The results of the third run replace the accumulator, and become the results of the entire filter.

The other filter prefixes that are available are “-“ and “~”. The action of minus is that the results of the run are removed from the accumulator (the input to the run is still the list of all “real” tiddlers). The action of tilde is to only evaluate the run if the accumulator is empty; the results of the run then become the accumulator.

Which in a strange way reminds me of horn clauses in Prolog where I'd write:

```
filter(a, b) :- ...
filter(a, c) :- ..
```

So really these filter expressions are equivalent to queries in predicate logic.

(which is why they are so powerful :-)

Thank you! It’s slightly embarrassing to have to invent something rather than being able to adopt something tried and trusted, so it’s good to hear that it’s not too terrible.

Best wishes

Jeremy


Cheers

/Joe



--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/9b8edbb1-8657-4502-ba5e-c867651203a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

joearms

unread,
Dec 20, 2018, 4:38:37 AM12/20/18
to TiddlyWikiDev


On Wednesday, 19 December 2018 23:21:15 UTC+1, Jeremy Ruston wrote:
Hi Joe

Then a filter that finds A is "[tag[A]]"

B OR C is "[tag[B]] [tag[C]]"

A AND B is "[tag[A]tag[B]]"

A and (B or C) has to be rewritten as
(A and B) or (A and C) and is 

"[tag[A]tag[B]] [tag[A]tag[C]]”

You can directly do A and (B or C) as:

[tag[B]] [tab[C]] +[tag[A]]

There are three runs here:

* The first two are processed in the same way: they start with an implicit [all[tiddlers]] to select all “real” tiddlers (ie, non-shadow tiddlers), whether or not they are system tiddelrs. The [tag[x]] filter operator selects those tiddlers that carry the indicated tag. At the end of processing each run, the results of the run are merged into the accumulator, the temporary holding storage for intermediate results.

* The third run starts with a “+” which means that instead of kicking off with all the real tiddlers, it instead uses the accumulator as the input to the run. The [tag[A]] then selects those tiddlers from the accumulator that carry the tag “A”.

The results of the third run replace the accumulator, and become the results of the entire filter.

   Great - IMHO the above explanation is far better than the definitive explanation 

 So the algorithm is

    1) create an empty output set (call this accumulator)
    2) A <whitespace> B means
        starting from the set of all tiddlers add those that match A to accumulator
        starting from the set of all tiddlers add those that match B to accumulator
    3) +X means starting from the accumulator
        match all X's and create a NEW accumulator which is passed onto the next step

     So A B +C where A B and C are "runs" means (in pseudo code)

     accumulator = {}    // empty set
     accumulator += matchalltags oftype A from all tiddlers
     accumulator += matchalltags oftype B from all tiddlers
     accumulator1 = matchalltags oftype C from accumulator
     return accumulator1       


The other filter prefixes that are available are “-“ and “~”. The action of minus is that the results of the run are removed from the accumulator (the input to the run is still the list of all “real” tiddlers). The action of tilde is to only evaluate the run if the accumulator is empty; the results of the run then become the accumulator.

Which in a strange way reminds me of horn clauses in Prolog where I'd write:

```
filter(a, b) :- ...
filter(a, c) :- ..
```

So really these filter expressions are equivalent to queries in predicate logic.

(which is why they are so powerful :-)

Thank you! It’s slightly embarrassing to have to invent something rather than being able to adopt something tried and trusted, so it’s good to hear that it’s not too terrible.


You've invented the monad :-) - monads just pass an invisible state through a pipeline of operations
that manipulate the state (you call it an accumulator)

Cheers

/Joe

joearms

unread,
Dec 20, 2018, 5:02:58 AM12/20/18
to TiddlyWikiDev
It also strikes me that rewriting

    A AND (B OR C) 

as

   B C +A

is pretty neat - it eliminates the parentheses OR becomes whitespace and AND becomes +

It's a Reverse Polish Monad Filter (RPMF)

/Joe

@TiddlyTweeter

unread,
Dec 20, 2018, 5:58:31 AM12/20/18
to TiddlyWikiDev
J & J,

"Reverse Polish" I understand.

This thread is interesting for highlighting, I think, how an explanandum can clarify the variety of explanans.

josiah

joearms

unread,
Dec 20, 2018, 6:21:15 AM12/20/18
to TiddlyWikiDev
There is method in my madness :-)

I'm trying to relate stuff I don't know (ie the tiddlywiki) to stuff I do know
(ie regular programming languages)

/Joe

@TiddlyTweeter

unread,
Dec 20, 2018, 6:51:13 AM12/20/18
to TiddlyWikiDev
Joe

FYI I'm not a programmer and don't want to be one :-).

But I found your probing is very illuminating.

Given you are a highly achieved programmer I find it interesting even you need to grapple the TW.

I think there is a kind of "implicit" TW zeitgeist or weltanschauung in TW that is both very happily bracing and quite askance (oblique) to other stuff. Once we get into it I think we tend forget its divergences.

THB I think Jeremy does not fully know himself quite how far he has got and how good it is.

One thing I'm kinda interested in is "comparing Wiki". IMO we are underselling TW. Its a different world.

Just thoughts
Josiah

joearms

unread,
Dec 20, 2018, 7:09:07 AM12/20/18
to TiddlyWikiDev


On Thursday, 20 December 2018 12:51:13 UTC+1, @TiddlyTweeter wrote:
Joe

FYI I'm not a programmer and don't want to be one :-).

It's fun - once you get the hang of if
 

But I found your probing is very illuminating.


Thanks
 
Given you are a highly achieved programmer I find it interesting even you need to grapple the TW.

I grapple with everything - I can't just cut and paste code - I want to dig down and understand
what every line does - so I'm a very slow learner.
 

I think there is a kind of "implicit" TW zeitgeist or weltanschauung in TW that is both very happily bracing and quite askance (oblique) to other stuff. Once we get into it I think we tend forget its divergences.

THB I think Jeremy does not fully know himself quite how far he has got and how good it is.

It's a great achievement - It takes a lot longer to understand what we have created than to do the creation.

You see this all the time - Politicians pass laws all the time, but it takes a long time to understand the consequences of
these laws - same for programming.


 

One thing I'm kinda interested in is "comparing Wiki". IMO we are underselling TW. Its a different world.

Well I'd appreciate your feedback -- I'm just dithering along saying "I think this <in TW speak>" means "XYZ in pseudocode"
but I'm not really sure if this is by accident or design. Does it do something by accident or because
it was designed to do exactly this

Cheers

/Joe

Mohammad Rahmani

unread,
Dec 20, 2018, 9:11:30 AM12/20/18
to TiddlyWikiDev

joearms

unread,
Dec 20, 2018, 12:45:00 PM12/20/18
to TiddlyWikiDev
Brilliant

/Joe
 


-- Mohammad

TonyM

unread,
Dec 21, 2018, 6:15:11 PM12/21/18
to tiddly...@googlegroups.com
Joe,

I empathise with you learning journey, having come to tiddlywiki in a similar way, as an IT Professional with coding in my past. Perhaps this perspective can help with the conceptualisation.

In case it helps, filters and the filter runs are somewhat like command line filters piping selecting etc... but in Tiddlywiki the primary purpose (but not the only one) is the manipulation of tiddlers, and lists of tiddlers so they lean towards handing tiddler titles, of course you can list fields in the current tiddler, or throughout the whole wiki, or generate virtual titles (EG Range operator)

Tiddler titles are in effect the key to a tiddler, and tiddlers are the standard unit of data, "the records in the database". But of course these records also provide the user interface and bootstrap the whole wiki in a file model.

You said "equivalent to queries in predicate logic", I tend to think of it as the previously defined but forgotten 4th Generation programming languages 

In effect we are normally processing sets at a time, even if that set has zero 1, or many members, tags on a tiddler are just a subset as are fields. 
the special design in tiddlywiki is, changes in these lists are automatically reflected in what you see and it does this economically by using trees to identify the effected tiddlers.

TiddlyWikis tag line is "a non-linear personal web notebook", and this explains somewhat its structure and concept, but I now consider "tiddlywiki a platform" on which to build almost any algorithm, and deploy it almost anywhere.

For 3Generation language coders there is a need to in someways forget a little of how we conceptualise programming, because tiddlywiki is handling the relationship and changes in tiddlers across the whole wiki, provides the tools for list / set management and more. Of course if you want to be a developer, rather than a TiddlyWiki Super User, you may need to revert to the regular programming language models, but then you need to learn about the way in which tiddlywiki achieves its magic. See https://tiddlywiki.com/dev/ especialy https://tiddlywiki.com/dev/#TiddlyWiki%20Architecture

Of course if you are across object oriented coding you can in some ways treat tiddlers as objects, or a html developer think of it as website design (A lot of html and css works out of the box in TiddlyWiki, unless it needs javascript), if you have database skills you can build databases using tiddlers or datatiddlers, if you are a user interface designer you can use tiddlywikis logic, tiddlers, html and css. If you are a javascript designer, you could build widgets and filter operators and create plugins that bring in open source javascript solutions to tiddlywiki - one of the best already is codemirror but there are many more in math and visualisation as examples.

If you want to be involved in core development perhaps building a widget and a filter operator would be a good start, I would be happy to provide some ideas if you want a project.

However there is so much more than can be done without going into core development, because this is a platform of almost infinite possibilities.

Welcome to the community, I see by your questions, you are likely to be a productive member.

Regards
Tony

joearms

unread,
Jan 4, 2019, 5:06:17 PM1/4/19
to TiddlyWikiDev


On Saturday, 22 December 2018 00:15:11 UTC+1, TonyM wrote:
Joe,

I empathise with you learning journey, having come to tiddlywiki in a similar way, as an IT Professional with coding in my past. Perhaps this perspective can help with the conceptualisation.

In case it helps, filters and the filter runs are somewhat like command line filters piping selecting etc... but in Tiddlywiki the primary purpose (but not the only one) is the manipulation of tiddlers, and lists of tiddlers so they lean towards handing tiddler titles, of course you can list fields in the current tiddler, or throughout the whole wiki, or generate virtual titles (EG Range operator)

Tiddler titles are in effect the key to a tiddler, and tiddlers are the standard unit of data, "the records in the database". But of course these records also provide the user interface and bootstrap the whole wiki in a file model.

You said "equivalent to queries in predicate logic", I tend to think of it as the previously defined but forgotten 4th Generation programming languages 

In effect we are normally processing sets at a time, even if that set has zero 1, or many members, tags on a tiddler are just a subset as are fields. 
the special design in tiddlywiki is, changes in these lists are automatically reflected in what you see and it does this economically by using trees to identify the effected tiddlers.

TiddlyWikis tag line is "a non-linear personal web notebook", and this explains somewhat its structure and concept, but I now consider "tiddlywiki a platform" on which to build almost any algorithm, and deploy it almost anywhere.

For 3Generation language coders there is a need to in someways forget a little of how we conceptualise programming, because tiddlywiki is handling the relationship and changes in tiddlers across the whole wiki, provides the tools for list / set management and more. Of course if you want to be a developer, rather than a TiddlyWiki Super User, you may need to revert to the regular programming language models, but then you need to learn about the way in which tiddlywiki achieves its magic. See https://tiddlywiki.com/dev/ especialy https://tiddlywiki.com/dev/#TiddlyWiki%20Architecture

Of course if you are across object oriented coding you can in some ways treat tiddlers as objects, or a html developer think of it as website design (A lot of html and css works out of the box in TiddlyWiki, unless it needs javascript), if you have database skills you can build databases using tiddlers or datatiddlers, if you are a user interface designer you can use tiddlywikis logic, tiddlers, html and css. If you are a javascript designer, you could build widgets and filter operators and create plugins that bring in open source javascript solutions to tiddlywiki - one of the best already is codemirror but there are many more in math and visualisation as examples.

If you want to be involved in core development perhaps building a widget and a filter operator would be a good start, I would be happy to provide some ideas if you want a project.

Writing a widget is on my lists of things to do :-) - subject to the condition that it is clearly described and well-documented and contains beautiful code (which makes it tricky)

At the moment I'm staring at the documentation and writing zillions of small test cases to
test my understanding.

In my opinion, the examples are too tough - the macro definitions *start* with parametrised macros 
at which I think "what about macros with zero parameters" the notations $var$ and $(var)$ and
<<var>> are used in ways that are unfamiliar to me - is this eager or lazy evaluation? what is the scope
of variables? what is the visibility of a macro? is it public/private, are their global variables etc.

The way of programming by creating a bundle or tiddlers whose net effect is to do something
is also unfamiliar (rather than just writing one module that does everything)


However there is so much more than can be done without going into core development, because this is a platform of almost infinite possibilities.

It's great
 

Welcome to the community, I see by your questions, you are likely to be a productive member.

Thanks for those kind words :-)

/Joe
Reply all
Reply to author
Forward
0 new messages