Represent Accounting Equation Using SWI-Prolog

Would a simple DSL work in your case? For example, one that would allow you to write instead:

microsoft asset = 5000.
microsoft liabilities = 1000.
microsoft equity = 4000.

Entity asset = Entity liabilities + Entity equity.
Entity balance = Entity asset.

Using term-expansion (e.g. term_expansion/2), you could then translate this DSL into a set of Prolog facts and rules.

1 Like

As I have never really done any term expansion or used qusi-quoations, is the use of = in what I am guessing is a fact allowed?

Assuming that asset is defined as an postfix operator, yes. For example:

?- op(1100, xf, asset).
true.

?- read(Fact), write_canonical(Fact).
|: microsoft asset = 5000.
asset(=(microsoft,5000))
Fact =  (microsoft=5000 asset).

You could then define a term-expansion rule that expands these user-defined facts into a suitable set of facts and rules for actual processing. For example:

term_expansion(
    asset(=Entity,Value),
    asset(Entity,Value)
).
1 Like

Ahh! Did not see asset as an operator. Nice trick!

Oops. I meant to write postfix operator. Fixed my reply. When defining DSLs, my advice regarding operators is (1) reuse as much as possible standard operators and (2) when defining your own operators, prefer descriptive words to combination of graphic characters.

I can’t count how many times when I read some math research papers or books that I have to keep cheat sheets of the operator symbols handy to look up what they mean an how to use them. I get it that writing a symbol on the black board is a lot faster and smaller than writing a word, but my brain has a limited capacity.

You can also use nice Unicode symbols. Hard to type and remember, but can look really nice and geeky :slight_smile:

2 Likes

Yes, totally agree. I do this so often that in trying to identify the symbols I have found this nice web page that lets you draw the symbol and it shows you similar Unicode characters.

e.g.

image


Note to others:

Be aware that when using other characters some are seen as variables and some as constants, e.g.

Also as I use SWI-Prolog on Windows, not all of the Unicode characters appear as expected so check that they will appear as needed before using in production code.

My favorite exploit of this is that a snowman will unify with a snowman.

?- =(☃,☃).
true.
1 Like

This is probably exactly what you need, a conformance suite. It has both positive and negative examples. It is not very extensive yet:

https://tinyurl.com/vn58o6l

I can certainly build out simple examples that have one error and would if you are interested in processing the XBRL files to validate the logic.

1 Like

In that case, that IS the format for your domain experts - assuming they’ve seen plenty of that already. Read in using the SGML package, get the parts you want out with SWI-prolog XPATH library.
One thing you might do, if you want to internally work with it in some other form, is to make a quasiquoter.

I refer you to the online docs for how to do that - it’s fairly straightforward.

Jan was thinking of a situation like, your users are musicians - let them write in something that looks like the musical notation they’re used to.

[qtr(bb), half(a), half(a#)]

Some representation like that .
Then compile that to executable prolog yourself.

I am with you here. The storage format is the global standard syntax for business reporting which is XBRL. The question is to how best process the XBRL to make sure the information being conveyed by the XBRL syntax is logical per domain semantics; in this case accounting and financial reporting.

This is a big opportunity that is only in it’s infancy now. There is a boatload of information on XBRL on my blog: http://xbrl.squarespace.com/

I would be very happy to answer any questions.

XBRL is a global standard language for business reports and financial reports. Every public company in the United States is required to submit XBRL-based quarterly and annual financial statements with the U.S. Securities and Exchange Commission. A good way to see some of those documents is via XBRL Cloud’s Edgar Dashboard:

https://edgardashboard.xbrlcloud.com/edgar-dashboard/

The European Single Market Authority (ESMA) has similarly required that every listed company in the European Union submit financial statements in the XBRL format beginning in January 2020.

But that is small potatoes. The BIG OPPORTUNITY is the 25 million private companies in the US and similar number globally. There are additional opportunities in special purpose financial reporting.

Currently, the missing piece of the XBRL puzzle is a “rules engine” that is powerful to process the logic of a financial report so that the XBRL-based financial reports can be created CORRECTLY. Currently, for example, the reports submitted to the SEC have errors.

The opportunity is to provide some sort of “rules engine” or “logic processor” or “expert system” that helps professional accountants create reports correctly so that the quality is high. This document summarizes many aspects of the opportunity:

There are many ways to approach this. One way is partnering with other software vendors that do not have these capabilities. I have many, many good contacts.

1 Like

Let me work with the files in the conformance suite first and learn from them. I think the format is easy enough that I can create the simple examples needed, but would need you to very the are correct from a business perspective. Then later adding some more complex examples where the problems are nested (e.g. the individual items will pass, but as a group they will fail) I would need help.

Also I plan to do all of this with unit test so that it can be reproducible.

What if any are the licenses on the conformance suite? (XBRL-based Digital Financial Reporting Conformance Suite Tests)

I don’t want to repackage the data into a test case and find that I have violated some copyright or something.

One more important piece of information. One of the issues with XBRL is that it does not do a particularly good job of communicating the logical model of a business report or of a financial report. So help solve that problem, the Object Management Group (OMG) is creating a global standard called Standard Business Report Model (SBRM) which is a logical conceptualization of a business report. Basically, what they are doing is formalizing the somewhat informal model that I have been creating for the past 5 years. For more information search my blog for Object Management Group SBRM, (I cannot seem to post a link).

Also, when you think about artificial intelligence and how to actually implement it and what people are saying about “The Fourth Industrial Revolution”; global standard technical syntax’s that provide the “information” and tools like Prolog that help you USE that information make a whole lot of sense. Search my blog for Adapting to Changes Caused by the Fourth Industrial Revolution (I cannot seem to post links to my blog)

Personally, I think Prolog and likely the more safe Datalog (as I understand it) will play a big role in accounting, reporting, auditing, and analysis in next 100 years. Very, very big opportunity.

(To get to my blog search on “XBRL Squarespace”)

Is this it?

Standard Business Report Model

When I think about AI, at the high level I break it down into two sets,

open-world
closed-world

Prolog is great for closed-world, but I shy away from it for open-world.
Neural Networks are great at open-world.

Datalog has better termination properties while its performance is less sensitives to e.g., ordering than standard Prolog due to bottom-up evaluation. Prolog with tabling (SLG resolution) has similar properties while providing a richer language. Performance and scalability of Datalog is probably better in the domains where it shines.

1 Like

I don’t think that there’s anything inherently bottom-up in Datalog other than it allows bottom-up implementation.

Google’s Yedalog is a Datalog whose syntax might be nicer for people who aren’t used to Prolog, and which transparently layers on top of databases, distributed file systems, mapreduce, etc.
https://ai.google/research/pubs/pub43462

I’ve implemented accounting systems (not using Prolog) and can assure you that Prolog (or Datalog) would be a fine way of adding business rules to databases. But I am unaware of non-experimental implementations. (Yedalog, AFAIK, is (a) experimental and (b) not publicly available.)

As an aside: many databases use the accounting profession’s “never erase a journal entry” methodology to reduce lock contention (in effect, allowing “shared nothing” parallelism) – although I’m pretty sure the idea was discovered independently.

Yes, that is the OMG web site for the Standard Business Report Model (SBRM). You might want to consider reading the 2 page summary of what SBRM is and the RDF section 6 which describes what SBRM needs to do.

Yes, XBRL-based reporting makes the closed-world assumption.