News for hackers. Stuff that matters.
Re:Tree Calculus by pdw on Tuesday December 10, 2024 @07:15AM (#42376131)
Modern APL dialects have an inverse operator (https://aplwiki.com/wiki/Inverse). For example, in Dyalog APL (https://tryapl.com/):

        ⍝ Convert Fahrenheit to Celsius
        f_to_c ← (÷∘1.8)∘(-∘32)

        f_to_c 68
    20

        (f_to_c ⍣ ¯1) 20
    68
Now I'm an APL noob, I don't know how deeply this is implemented. I suspect it's very adhoc.

More interesting are logic languages such as Prolog. If you stick to the core logical features, you get the inverse of a function for free:

    ?- append([1,2,3], [4,5,6], X).
    X = [1, 2, 3, 4, 5, 6].

    ?- append(X, [4,5,6], [1,2,3,4,5,6]).
    X = [1, 2, 3].

    ?- append(X, Y, [1,2,3,4]).
    X = [], Y = [1, 2, 3, 4] ;
    X = [1], Y = [2, 3, 4] ;
    X = [1, 2], Y = [3, 4] ;
    X = [1, 2, 3], Y = [4] ;
    X = [1, 2, 3, 4], Y = [].

There are no comments on this comment yet.