Pedro Sobota's GitHub Page

Hello! Welcome to my GitHub Page.

🛸About

💻Software

📰News

📝Blog

Property Provider Console

03/2024


Abstract: This article describes the development of a tool for mapping and relating objects to properties. The user can rank objects based on their properties and examine object sets.

As a starting point, I considered combinations of properties of certain mathematical structures like sets, tuples, lists, and so on. Then, I mapped a complete set of combinations of properties, and in the process, I found out I could now rank them according to the similarity of their set of properties. This complete enumeration also allowed to discover new objects.

I implemented a relation relating objects to properties, and a scoring algorithm ordering arbitrary objects with respect to a particular object which worked as a similarity measure between two objects. It's now possible to identify most similar and dissimilar objects with respect to an object and check for definitional holes, defining new objects for such missing combinations of properties.

Let's present a practical example. Given the following input file:

    Collections, Multiset
    Collections, Tuple
    Collections, Struct
    Collections, ElementNamedTuple
    Collections, Set
    Collections, Track
    Collections, Array
    Collections, String
    Collections, Column
    
    Properties, NaturalOrdering
    Properties, ElementNaming
    Properties, Uniqueness
    Properties, Typing
    Properties, Naming
    
    // Multiset has no properties
    
    Collections.Tuple , Properties.NaturalOrdering
    Collections.Struct, Properties.ElementNaming
    Collections.Set   , Properties.Uniqueness
    Collections.Track , Properties.Typing
    Collections.String, Properties.Naming
    
    Collections.ElementNamedTuple, Properties.ElementNaming
    Collections.ElementNamedTuple, Properties.NaturalOrdering
    Collections.Array            , Properties.NaturalOrdering
    Collections.Array            , Properties.Typing
    Collections.Column           , Properties.Naming
    Collections.Column           , Properties.NaturalOrdering
    Collections.Column           , Properties.Typing
    

The following results would follow:

    PropertyProvider v0.1
    
    PP> load D:\PropertyProviderConsoleSample.txt
    2 classes constructed
    14 class elements added
    2 relations defined
    24 relation elements defined
    
    PP> help
    exit, outfile, classes, relations, [className],
    [className] v [className]
    [className] v [className] (!|!!|?|??) [classElement]
    
    PP> classes
    Collections, Properties
    
    PP> relations
    (Collections, Properties), (Properties, Collections)
    
    PP> Collections
    Collections.Multiset, Collections.Tuple, Collections.Struct, Collections.ElementNamedTuple, Collections.Set, Collections.Track, Collections.Array, Collections.String, Collections.Column
    
    PP> Properties
    Properties.NaturalOrdering, Properties.ElementNaming, Properties.Uniqueness, Properties.Typing, Properties.Naming
    
    PP> Collections v Properties
    > 
    +---------------------------+-----------------+
    | (Collections, Properties) | 1/5             |
    +---------------------------+-----------------+
    | Multiset                  |                 |
    | Tuple                     |                 |
    | Struct                    | ElementNaming   |
    | ElementNamedTuple         | ElementNaming   |
    | Set                       |                 |
    | Track                     |                 |
    | Array                     |                 |
    | String                    |                 |
    | Column                    |                 |
    +---------------------------+-----------------+
                               < >
    
    > help
    b|break, c|clear, pp, pn, pf, pl, p[pageNumber]
    
    > pn
    +---------------------------+-----------------+
    | (Collections, Properties) | 2/5             |
    +---------------------------+-----------------+
    | Multiset                  |                 |
    | Tuple                     |                 |
    | Struct                    |                 |
    | ElementNamedTuple         |                 |
    | Set                       |                 |
    | Track                     |                 |
    | Array                     |                 |
    | String                    | Naming          |
    | Column                    | Naming          |
    +---------------------------+-----------------+
                               < >
    
    PP> Properties v Collections
    > 
    +---------------------------+-------------------+
    | (Properties, Collections) | 1/9               |
    +---------------------------+-------------------+
    | NaturalOrdering           | Array             |
    | ElementNaming             |                   |
    | Uniqueness                |                   |
    | Typing                    | Array             |
    | Naming                    |                   |
    +---------------------------+-------------------+
                               < >
    
    PP> Properties v Collections
    > pn
    +---------------------------+-------------------+
    | (Properties, Collections) | 2/9               |
    +---------------------------+-------------------+
    | NaturalOrdering           | Column            |
    | ElementNaming             |                   |
    | Uniqueness                |                   |
    | Typing                    | Column            |
    | Naming                    | Column            |
    +---------------------------+-------------------+
                               < >
    
    PP> Collections v Properties ! Set
    > s
    +---------------------------+-----------------+
    | (Collections, Properties) | 1/5             |
    +---------------------------+-----------------+
    | (5) Set                   | ElementNaming   |
    | (4) Multiset              | ElementNaming   |
    | (3) Tuple                 | ElementNaming   |
    | (3) Struct                |                 |
    | (3) Track                 | ElementNaming   |
    | (3) String                | ElementNaming   |
    | (2) ElementNamedTuple     |                 |
    | (2) Array                 | ElementNaming   |
    | (1) Column                | ElementNaming   |
    +---------------------------+-----------------+
                               < >
    
    > pn
    +---------------------------+-----------------+
    | (Collections, Properties) | 2/5             |
    +---------------------------+-----------------+
    | (5) Set                   | Naming          |
    | (4) Multiset              | Naming          |
    | (3) Tuple                 | Naming          |
    | (3) Struct                | Naming          |
    | (3) Track                 | Naming          |
    | (3) String                |                 |
    | (2) ElementNamedTuple     | Naming          |
    | (2) Array                 | Naming          |
    | (1) Column                |                 |
    +---------------------------+-----------------+
                               < >
    
    PP> Properties v Collections !! Uniqueness
    > s
    +---------------------------+-------------------+
    | (Properties, Collections) | 1/9               |
    +---------------------------+-------------------+
    | (9) Uniqueness            |                   |
    | (6) ElementNaming         |                   |
    | (6) Naming                |                   |
    | (5) Typing                | Array             |
    | (4) NaturalOrdering       | Array             |
    +---------------------------+-------------------+
                               < >
    
    PP> Properties v Collections ! Uniqueness
    > s
    +---------------------------+-------------------+
    | (Properties, Collections) | 1/9               |
    +---------------------------+-------------------+
    | (9) Uniqueness            | Array             |
    | (6) ElementNaming         | Array             |
    | (6) Naming                | Array             |
    | (5) Typing                |                   |
    | (4) NaturalOrdering       |                   |
    +---------------------------+-------------------+
                               < >
    
    PP> Collections v Properties ? Array
    > s
    +---------------------------+-----------------+
    | (Collections, Properties) | 1/5             |
    +---------------------------+-----------------+
    | (3) Struct                |                 |
    | (3) Set                   | ElementNaming   |
    | (3) String                | ElementNaming   |
    | (2) Multiset              | ElementNaming   |
    | (2) ElementNamedTuple     |                 |
    | (1) Tuple                 | ElementNaming   |
    | (1) Track                 | ElementNaming   |
    | (1) Column                | ElementNaming   |
    | (0) Array                 | ElementNaming   |
    +---------------------------+-----------------+
                               < >
                               
    > save
    %LOCALAPPDATA%\PropertyProvider\PropertyProviderOut.txt
    
    +---------------------------+-----------------+-----------------+-----------------+-----------------+-----------------+
    | (Collections, Properties) | 1/5             | 2/5             | 3/5             | 4/5             | 5/5             |
    +---------------------------+-----------------+-----------------+-----------------+-----------------+-----------------+
    | (3) Struct                |                 | Naming          |                 |                 | Uniqueness      | 
    | (3) Set                   | ElementNaming   | Naming          |                 |                 |                 | 
    | (3) String                | ElementNaming   |                 |                 |                 | Uniqueness      | 
    | (2) Multiset              | ElementNaming   | Naming          |                 |                 | Uniqueness      | 
    | (2) ElementNamedTuple     |                 | Naming          | NaturalOrdering |                 | Uniqueness      | 
    | (1) Tuple                 | ElementNaming   | Naming          | NaturalOrdering |                 | Uniqueness      | 
    | (1) Track                 | ElementNaming   | Naming          |                 | Typing          | Uniqueness      | 
    | (1) Column                | ElementNaming   |                 | NaturalOrdering | Typing          | Uniqueness      | 
    | (0) Array                 | ElementNaming   | Naming          | NaturalOrdering | Typing          | Uniqueness      | 
    +---------------------------+-----------------+-----------------+-----------------+-----------------+-----------------+
    

Observations

  • A project can contain any number of classes and relations. The "Properties" classes is not hardcoded and is just a "default" class name for properties of objects. Any classes of objects could be related
  • Tables are paged to allow a constant width for inspection. Full tables can be printed to files with save
  • Reverse relations are automatically created from any relation
  • The A v B ! C syntax, where A is the "key" class and B is the "value" class, performs similarity scoring (non-unique) in the relation with respect to element C of the key class. The descending similarity score is shown in parenthesis on the key cell
  • Dissimilarity scoring is also available with the ? operator
  • The double operators !! and ?? for scoring shows true or false values (which we call "characteristics"), as opposed to equal or distinct values (for similarity or dissimilarity respectively), for each key class
  • The project abstracts class element names as Symbols, which allows to:
    • Enforce uniqueness of Symbols on a class
    • Implement integer encoding of Symbols, as 1) combination of elements on a Set is expressible as a sum, 2) powers-of-two sums are unique, and 3) classes are Sets. Thus, element combinations (or Objects) are encoded as unique integers in a way such that, from an integer, the combination (or Object) is recoverable.

Implementation

The operations have been implemented in a command line program written in C# 11 and released under the AGPL-3.0.

Computing layered intervals

04/2018


Abstract: This article explains an algorithm for calculating a set of intervals from a set of layered of intervals while accounting for obstructions.

This page describes an algorithm for calculation of a final set of intervals from a set of layered intervals, accounting for obstructions, linearly (i.e., from left to right).









The above images are examples of composed intervals (the lines are the paths taken by the algorithm).

As you can see, the main obstacle in calculating such composed intervals is accounting for obstructions in more important (i.e., higher priority) layers.

This is the simplest method to perform this computation in a linear way I could come up with.

For a tree approach, see [1].

Pseudocode

    from first to last node, ordered by position first and ascending lane second:
    if not closing:
        if not open in any higher lane:
            if final opened:
                close final.
            open final.
        open in this lane.
    if closing:
        closed in this lane.
        if final opened:
            if not open in any higher lane:
                close final.
    if not final opened:
        if at last lane of position, except for the last position:
            if open in any other lane:
                open final.

Implementations

With tests.

References

  1. Interval tree (Wikipedia)

Lattice big-integer multiplication

01/2018


Abstract: This article presents an implementation of the lattice multiplication method, an ancient technique for multiplying large numbers. The implementation, capable of computing 4999! (with 16322 digits) in the order of a minute, uses a cell-walking routine to traverse arbitrary shape lattices in three distinct phases.

As we know, not very large numbers (such as 99) have very large factorials, with this one having 156 decimal places.

The problem with multiplying those numbers is the common problem of overflow with large number computations.

For example, 29! fails to compute with ulongs in C#, producing 11390785281054474240 instead of 8841761993739701954543616000000.

The lattice or gelosia method here implemented is an ancient multiplication method with the idea that numbers can be multiplied digit-by-digit and, as each digit only ranges from 0 to 9, the maximum multiplication performed per step is 9 x 9.

The method is executed by laying out first the digits of the multiplicands across the borders of a table. The multiplied digits are read in diagonal lines and summed, and these summed digits become the result of the multiplication.


I penned a particular implementation of the calculation of the lattice method after inspiration through [1]. (The cell walking routine is also implemented in the above graphic in JavaScript.)

This particular implementation can compute 4999! (which has 16322 digits) in 1m24s. It works by walking cells of arbitrary shape (width x height) lattices (the grids shown above).

The basic procedure can be divided in the following kinds of steps:

1) Basic cell-to-cell walk

2) Line changes

3) Phase changes (including the end of the walk)

There are three phases.

In any phase, the basic cell walk routine is the same: if we are in an odd cell (the "uppermost" triangle in a square), we go to the left square to the even cell. Furthermore, if we are in an even cell (the "lowermost" triangle in the square), we go down one square and switch to the odd cell.

If we reach the lower cells in the first phase, in any shape lattices, or in the second phase in horizontal lattices, a line change occurs. If we reach the leftmost cells in the third phase of any shape lattice or in the second phase of vertical lattices, a line change also occurs.

The first and third phases are common to all shape lattices, and the second phase (only occurring in non-square lattices) is of different line-changing procedure with different orientation lattices.

In any phase, when changing lines, we look for when the phase changes. According to the orientation, the phase transition can jump an additional line, before changing phases, or not.

Pseudocode

    let d1 be the amount of digits in the multiplicator, and 
    d2 be the amount of digits in the multiplicand.

    do:
        multiply the digits at x and y.
        add to the sum.
        orientation undefined.

        if end of line of any phase:
            if carrying digit, add it to sum.
            if one digit sum:
                take the only digit.
            if two digits sum:
                take the second digit and carry the first.
            result position less one.
            reset the sum.
        
        if end of line of phase 1:
            if x is at d1 + 1 - d2 (the "square" position):
                the lattice is horizontal.
            if x is at 1:
                the lattice is vertical.
            if the lattice is both horizontal and vertical:
                the lattice is square.

            if orientation is defined and:
                it's square:
                    phase is 3.
                    jump cell like the new phase, but 
                    x is 1 and odd toggles to true.
                it's horizontal:
                    phase is 2.
                    jump cell like the new phase.
                it's vertical:
                    phase is 2.
                    jump cell normally.
            if not:
                jump cell normally.
        if end of line phase 2 vertical:
            if y is d1 + 1:
                phase is 3.
                jump cell like the new phase.
            if not:
                jump cell normally.
        if end of line phase 2 horizontal:
            if x is 1:
                phase is 3.
            jump cell normally.
        if end of line phase 3:
            if y is 1:
                end of walk.
            if not:
                jump cell normally.
        if no end of line:
            if not odd:
                y is increased 1.
            if odd:
                x is decreased 1.
            toggle odd.

Implementations

With tests.

References

  1. Homework: how to write own multiplication of big numbers?, Stack Overflow