I'm a brick-and-mortar engineer with very cursory coding experience (pseudo-code algorithms, formal logic gates in printed circuits, and Matlab/Simulink), studying to be a Civil Servant in a Romance country where the law is extremely informed by what I understand is the Positivist mindset - tries to create a closed logical system where all possibilities are accounted for and judges have as little leeway of interpretation as possible.

A lot of it follows patterns such as

    //as in, "apply article 35 line 3 paragraph b 
    //of section A of book 1 of law 75/2003 of 
    //the National Assembly", for example 



In my line of work, it often happens that a lower-tier, quick-release Executive Regulation conflicts with a parliamentary Law or with the Constitution Itself. This can have dire business consequences and completely wreck a project's timeline, or budget, or sink it altogether. I understand that this is known as "judicial insecurity", and it's tangibly damaging.

It would be nice if lawgivers were kind enough to decree airtight laws that, though one might argue they are more or less just or good, at least are formally consistent with each other, telling citizens and legal persons clearly what we can and cannot do. However, it's often up to lay citizens to notice these discrepancies and take them to court for appeal. Even when the cases are very clear-cut, it can take months or years, and by the time it's done, a whole new set of quick-and-dirty executive regulations may have come out.

I'd like to know if, given the at least attempted "formal algorithm" method of the law, there wouldn't be an automated method of parsing the laws for contradictions, formal inconsistencies, endless loops, or undesirable end-states. I'd likewise appreciate an automated system for parsing out the control flows in the laws and turning them into easily-readable, standardized diagrams and charts.

Now, However, I don't know enough about programming, particularly as applied to linguistics, to figure out what the best approach would be. If y'all got any insights, I'd strongly appreciate them.

The DEFINITIONS part is particularly tricky for me, as we've got, off the top of my head:

  1. Agents
    • Public ones: Courts, Legislative Assemblies, Administrations, Department, Position (distinct to the person of the civil servant in it), "Organ", etc. (it's quite a tangled web of affiliations and dependencies, and liable to change quickly, too).
    • Private citizens, with the attributes thereof that are deemed relevant (nationals/EU citizens/foreign, major/minor, etc.)
    • Private associations: Privately or Publicly owned, For Profit or Non Profit, different types of corporation...
  2. Actions: For example, for a person to be [appointed to an Positon], -Organ A [nominates], -Organ B [introduces in the agenda], -Organ C [votes], -Organ D [vetoes or not], -Organ E [signs the appointment], -Organ F [publishes] in the official bulletin, etc.
  3. Documents: just in the example above, each action or lack thereof is recorded (actively or by default) in a document (Nomination, Minutes, Appointment, the Bulletin, etc.). Then you have stuff like Registries and Records, which are compilations of documents, and need to be distinguished from the Organs named after them that are in charge of running them. You have Contracts, which are a whole Thing themselves. You have your specific Administrative Acts and your General Decrees. And, well, I can't help but think of the myriad types of documents, both formal and not, that are introduced in - discovery, was it? - as Evidence.
  4. Dates and timestamps are very important, as are the specific windows and deadlines to perform this or that action.
  5. Principles: they're very annoying because they're unevenly applied and usually not self explanatory, but they're supposed to inform all legislation and, when they're in the Consitution, they're meant to be very binding indeed. Legality, Rule of Law, State of Law, Non-Arbitrariness, Objectivity, Impartiality, Transparency, Non-Retroactiveness, General Interest, Cooperation, Coordination...
    • It's possible to go to the Doctrine (i.e., the opinions of Respected Legal Scholars) or to Case Law (which tend to rule on ambiguities of this type) to construct something resembling a useful formal definition, but it's usually very difficult to avoid a degree of "fuzziness" and "gradient" in the concept.
    • As such, my impression is that any formal tests that one could devise to make sure the laws apply those principles would fall under the header of operationalization, i.e. answering a difficult question with a similar, much simpler one.
      • The example I was given in Philosophy of Science class at Uni was: "How much do you love your wife?" vs. "How high a voltage are you willing to be shocked with in order to guarantee that she herself does not get shocked?"
      • Likewise, "is this law impartial" could be turned into "in practice, what demographics are disproportionately favored by it and what aren't", although that requires going outside of the formal confines of the law. There's likely a way to formally test if, in theory, the law is impartial, but I can't think of one right now.
      • Similarly, the concept of "General Interest" is quite problematic - a huge collection of subjective interests that seems incredibly hard to even know objectively, let alone turn into a set of quantitative criteria, or legislate for without biases or hidden assumptions, - and yet "the Administration serves the General Interest Objectively and Impartially" is an actual article of Law that is in effect and which you could refer to in court when appealing an administrative regulation or act that you have evidence serves Special Interests, is Subjective, or favors certain parties over others.

I've been circling the problem, reading some law, attempting a chart and a pseudo-code, going to practical cases, reading some theory on the background thereof, learning about different coding languages and practicing simple exercises just to get the hang of them, etc. I'm slowly growing familiar with declarative, imperative, object-oriented, etc languages, as well as Controlled Natural Languages and attempts to make programming easy to parse for people and human language easy to parse for machine. I'm finding out about programs and AIs that are designed to parse language, and about statistical methods to hermeneutics and data analysis.

It's been quite haphazard and unstructured, and I feel like I may be wasting my time blindly touching an elephant's trunk and trying to figure out what sort of snake it is. But I'm afraid to raise my voice, explaining what I'm doing and ask, "am I doing this right" and of either being ignored or being told to ask a more specific and well-researched question. I'd really appreciate some guidance, though.

I guess, for now, I'd be content with tips on how to approach the following problems, in order of priority:

  • automating the representation of laws as control flow charts
  • automating the discovery of
    • undesirable loops and end-states in said flow charts
    • fringe cases that are pedagogically optimal for explaining the nuts and bolts of the law to people learning it
    • ambiguous language: when a word means different things depending on which "semantic field" of law we're in - for example, "convention" can mean very different kinds of agreements in Civil Law, Administrative Law dealing with private entities, Administrative law dealing with different tiers of the Administration, and International Law, just to name a few.
    • formal contradictions between laws of equal and different tiers

That would be a good start - just a formal comprehension and testing of the law.

Other than that, I'm aware that LawTech firms are developing some truly interesting applications on a number of subjects, with particular attention paid to contract drafting and enforcement, and the automation thereof, as well as to the prediction of outcomes in lawsuits based on case analytics. I'm not, however, aware of the theoretical and skillset edifice upon which this kind of work is build - but it interests me a great deal. In fact, I'm finding Law so fascinating and vitally important that I'm actually considering getting a Law degree myself - I understand that STEM-trained folks are actually rather welcome in Law Schools? I'd strongly appreciate any guidance on how to build my knowledge and skills base to begin to be able to grapple with such problems - and, eventually, if I'm any good at it, offer useful billable expertise that clients would purchase, of course.

  • 2
    Your question is way too broad and unrealistic. Consider Worldbuilding SE instead. Jun 7, 2021 at 14:48
  • I’m voting to close this question because asking for guidance developing technical implementations legal software - "I'd strongly appreciate any guidance on how to build my knowledge and skills base to begin to be able to grapple with such problems" is off topic here. Jun 7, 2021 at 15:12
  • 1
    @BlueDogRanch Not necessarily. I'm not here asking for programming tips. but for the tools to approach understanding law from a theoretical perspective.
    –  aarek-eng
    Jun 7, 2021 at 15:24
  • @IñakiViggers Exactly the reaction I was wary of. I'm trying to narrow down questions and avenues of investigation. but I can't know what's "realistic" or "unrealistic" in advance outside of my field of expertise. Worldbuilding is about speculative fiction, while LawTech is quite real and active.
    –  aarek-eng
    Jun 7, 2021 at 15:33
  • 1
    I'm sorry, I tried to read the question but it's way too long. In general, the problem seems to be that while if–then implications can be encoded clearly, the definitions used in law are far too imprecise for automation. The legislator would have to build a clear and unambiguous ontology instead. Often, lawsuits hinge not on facts but on questions of law, e.g. on the definitions of individual words such as “access”, “consent”, or “legitimate”.
    – amon
    Jun 7, 2021 at 16:06

1 Answer 1


You can’t have complete mathematics; you have no chance of a complete legal system

Godel’s incompleteness theorems tell us that mathematics has no complete, consistent and finite set of axioms that can prove every correct statement. If we can’t do it for something as logical as maths, we certainly can’t do it for anything involving things as messy as people.

The solution that has been adopted in most jurisdictions is to give decision makers discretion and allow appeals. That’s pretty hard to turn into an algorithm.

  • I'm aware of Gödel's incompleteness theorem, but it's not relevant here -I wasn't asking about completely automating law into a perfectly logical system so that a robot can do all the work. I was asking about ways of presenting laws and, possibly, legal systems, in a way that highlights and clarifies its requirements and consequences and eases testing it for loopholes, undersirable end states, ambiguities, etc., and then ways of automating as much of that work as possible. To create a "handle" that makes law easier to grasp, wield, study and improve, not about aiming for Platonic perfection.
    –  aarek-eng
    Jun 8, 2021 at 9:32
  • As you say, even Math & Physics cannot be "perfect" or "complete", but we've automated the hell out of them anyway, and that didn't diminish the work and role of scientists and engineers, it just saved on tedious pen-and-paper calculations and onerous destructive testing of prototypes, in favour of virtual simulations more complex than any human brain could imagine. Laws are drafted by assemblies of elected officials that may not be legal experts (or experts in anything), and understood, obeyed by laypeople, who rely on the Law's protection. Shouldn't their work be eased as much as possible?
    –  aarek-eng
    Jun 8, 2021 at 9:44
  • That could do with a little more explanation.
    –  aarek-eng
    Jun 8, 2021 at 10:57

Not the answer you're looking for? Browse other questions tagged .