The concept of One

by Peter Chapman

addition_1_to_5_using_objects_worksheet_01

The band Three Dog Night has the lyrics “One is the loneliest number that you’ll ever do.” as part of one of their songs.  They must have been working on Strong AI at the time when they came up with that song.

Lots of work related to ML and such has been applied to NLP/NLU and largely failed. If we skipped the problem of parsing English for a moment, what would you do with the information if you had a great parser?  What would the backend look like?  How would you represent the concept of the integer number one or addition?

I happen to be enamored with Category Theory at the moment.  In particular, I have been thinking about how to represent the concept of addition in the backend.  In traditional modern object oriented computer programming, there is several ways we might be able to add this functionality to a class.  Lets review some of them.

  • Interfaces: For each object that we want to be able to add, we supply an addition interface.  For instance, if you want to add two persons, the person object would implement an addition interface.  Or better yet, a container such as a List or Array object and a little generics might do the same (such as C# List<Person> People).
  • Implicit and/or Explicit Operators: The person object or better yet, the List or Array provides a way to cast between a Person or array of People and an integer allowing normal addition arithmetic to be performed.
  • Conversion Functions: .NET has a well formed system for doing conversions between objects.  Create a new conversion function that converts between people and integers.  One of the problems is loss of information.  As you convert objects, you need to make sure you don’t loose information in the process.
  • Massive switch statement in the addition operator: In this version, the addition operator has a switch statement that looks at both the left and right side of the addition symbol and tries to coalesce them so they can be added.
  • Generics/Templates: Create a generic class that tries to do most of the work.  Helps implementation, but doesn’t really reduce the amount of code required.

And more exotic ways such as proxies, mixins, traits, compound objects at runtime, automatic code generation, etc.

So, there seems lots of ways to do this, what’s the problem?  Computers can add integers natively through the instruction set of the processor.  So they don’t need to “understand” how to add, they can just “do it”.  But simple math concepts are but the tip of the iceberg of concepts to which there is no native implementation.

Part of the problem is that it all leads to an explosion of object oriented code.  For instance, I would have a Person class, that needs to implement an addition interface and numerous other interfaces that are related to individual concepts.  The Person class would need thousands of interfaces.  And every other type of object: Car, Dog, Bike, etc. would need them too.  In addition, the smarts required to generate it at runtime seems very daunting.

Worse yet it the design by Amazon’s Alexa.  The knowledge of how to do something is in individual skills coded by different developers.  Hence, you can’t even apply some of the techniques above because each skill is an island isolated from every other skill.  Ultimately, if left unfixed, this will be Alexa’s downfall.

I would like to implement addition once in my entire code base and have it apply to any object.  So, this leads to the question on how to structure a code base that would allow this.  In Alexa parlance, I want to write an addition skill and have it work with every other kind of skill. How would you represent the concept of one so it could be used by addition?

This is what I am working on now.  To truly understand the concept of counting and addition and have that concept be applied to any other kind of object.  To have the code in one place and not duplicated everywhere.

I think Category Theory might have part of the answer.  More to come.