Profile image

Equality (== / !=) and Inclusive inequalities (<=, >=) in Funky Trees

66.6k SnoWFLakE0s  4.2 years ago

This post is an addendum to @spefyjerbf's post. Read that first if you haven't yet.

Also, my computer crashed and I am rewriting this, so this may be mildly badly written. Curse QuickTime player. Absolutely dysfunctional software.

So a while ago spefy showcased his method of comparison operators that used boolean logic to produce a method that allows for comparison operators, specifically noninclusive inequalities (<, >). He did mention that equality operators (==, !=) are possible, but not useful because exact values rarely happen in SP. It's true, but I personally found tons of usage applications for equality statements so I'm writing this post.

Using spefy's system for replicating the function of comparative operators in funky trees, we can say that X < A becomes clamp01(A - X) and that X > A becomes clamp01(X - A). However, in order to boolean logic to work correctly all outputs should be 0 or 1. Sometimes spefy's current system doesn't do that, so we'll add one more thing to make it always work - ceil. So, instead of clamp01(X - A), we'll do clamp01(ceil(X - A)). This makes this system work regardless how small the difference is.
This is important, because if you’re using equality statements, it’s very likely you’re working with very precise values.


Inclusive inequalities (<=, >=)

With that out of the way, I'll make this concise as possible. For our purposes, a value of A ± b, where b is a negligibly small number, is equivalent to A. With this in mind, we can say that since if we do X < A + b, then that's equivalent to X <= A and that if we do X > A - b, then that's equivalent to X >= A.

If we want to do X <= A, we apply the logic above to say that X <= A is equivalent to clamp01(ceil(A + b - X)).

By the same token, if we want to do X >= A, we apply the logic above to say that X >= A is equivalent to clamp01(ceil(X - (A - b))).


Here's some tangible usage examples.

If you want to do X <= 5, then do X < 5.01. In this case b = 0.01. This depends on how much precision you want.
In funky trees form, this would mean that X <= 5 is functionally equal to clamp01(ceil(5.01 - X)).

If you want to do X >= 5, then do X > 4.99. In this case b = 0.01. This depends on how much precision you want.
In funky trees form, this would mean that X >= 5 is functionally equal to clamp01(ceil(X - 4.99)).

That concludes inclusive inequalities.


Equalities (==, !=)

We can apply inclusive inequalities to create equality statements. How? Let me show you…

spefy pointed out how and operators (&&) would work in boolean algebra. Simply multiply. What that means is that by multiplying our inequalities, you can reproduce the effects of intervals, or statements like A < X < B. Interestingly, by our logic above with inclusive inequalities, if we do A <= X <= A (note that both sides are the same value) this is logically equivalent to X = A. We already have the code. Let’s write this out.

We want A <= X <= A. We know that this works by multiplying two inclusive inequalities, one the “greater” comparator and the other the “lesser” comparator. Using the same system as above, A <= X <= A is functionally equal to A - b < X < A + b, and convert these to our funky trees method- we get that:

If we want to do X = A, we multiply A <= X and X <= A. That is, clamp01(ceil(A + b - X)) and clamp01(ceil(X - (A - b))), to yield the statement:

clamp01(ceil(A + b - X)) * clamp01(ceil(X - (A - b)))

An usage example:

If you want to do X = 5, then do clamp01(ceil(5.01 - X)) * clamp01(ceil(X - 4.99)).


What spefy didn’t mention is how you can use or operators ( | ). or operators in boolean algebra operate based on addition (+). Using or operators and noninclusive inequalities, we can create not operators. Here’s the conventional format…

If X != A then that means that X > A or X < A. You cannot use the and operator (multiplying) here because a value cannot be something like 3 and 5 at the same time. If it does, that’s quantum mechanics. Anyhow, then we already know that X > A is clamp01(ceil(X - A)) and X < A is clamp01(ceil(A - X)). Simply add the two (or operator). In summary:

If we want to do X != A, we use: clamp01(ceil(X - A)) + clamp01(ceil(A - X)).

The statement only returns 0 when X = A, hence working as X != A. Cool!

An usage example:

If you want to do X != 5, then do clamp01(ceil(X - 5)) + clamp01(ceil(5 - X)).


I hope that made sense. I’ll answer any questions down below. Note, if you want to ask me something, please come with valid questions (so no “I don’t understand” - instead do “I don’t understand X about Y”. Thanks.)

Also, I've created a complied list of Funky Tree resources. Check here:

bit.ly/FunkyResources

  • Log in to leave a comment
  • Profile image
    66.6k SnoWFLakE0s

    @spefyjerbf
    .
    Makes sense. I suppose I can do that.

    4.2 years ago
  • Profile image
    35.3k V

    @Stormfur think of clamp01( x - y ) as a > statement.

    +1 4.2 years ago
  • Profile image
    161k spefyjerbf

    Very nice! I have been thinking of making a technical resources page much like the one that you have made. Perhaps making it into a forum post might be beneficial - some users do not have access to (or understand) google docs.

    +1 4.2 years ago
  • Profile image
    51.0k PyrrhaNikos

    As the person with no idea about funky tree

    I think I lost some brain cells trying to understand this

    +2 4.2 years ago
  • Profile image
    15.7k Stormfur

    You lost me at the title lol

    +1 4.2 years ago