# ideas by u/DaVinci103 # MIT License, Copyright (c) 2024 Marvin Borner # (p : q) ⇔ (p / (q + 1)) :import std/Logic . :import std/Combinator . :import std/Pair . :import std/Math N # converts a balanced ternary number to a rational number number→rational [0 : (+0)] ⧗ Number → Rational :test (number→rational (+5)) ((+5.0)) # returns true if two rational numbers are equal eq? &[[&[[N.eq? (N.mul 3 N.++0) (N.mul N.++2 1)]]]] ⧗ Rational → Rational → Boolean …=?… eq? :test (((+1) : (+3)) =? ((+2) : (+7))) (true) :test ((+0.5) =? (+0.5)) (true) :test ((+42.0) =? (+42.0)) (true) :test ((+0.4) =? (+0.5)) (false) # returns true if a rational number is greater than another gt? &[[&[[N.gt? (N.mul 3 N.++0) (N.mul N.++2 1)]]]] ⧗ Rational → Rational → Boolean …>?… gt? # returns true if a rational number is less than another lt? &[[&[[N.lt? (N.mul 3 N.++0) (N.mul N.++2 1)]]]] ⧗ Rational → Rational → Boolean …?‣ positive? # returns true if a real number is negative negative? \lt? (+0.0) ⧗ Rational → Boolean