Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unique #785

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 57 additions & 16 deletions lib/src/metta/runner/stdlib.metta
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,47 @@
(: empty (-> %Undefined%))
(= (empty) (let a b never-happens))

(@doc unique
(@desc "Function takes non-deterministic input (first argument) and returns only unique entities. E.g. (unique (superpose (a b c d d))) -> [a, b, c, d]")
(@params (
(@param "Non-deterministic set of values")))
(@return "Unique values from input set"))
(: unique (-> Atom Atom))
(= (unique $arg) (let $c (collapse $arg) (let $u (unique-atom $c) (superpose $u))))

(@doc union
(@desc "Function takes two non-deterministic inputs (first and second argument) and returns their union. E.g. (union (superpose (a b b c)) (superpose (b c c d))) -> [a, b, b, c, b, c, c, d]")
(@params (
(@param "Non-deterministic set of values")
(@param "Another non-deterministic set of values")))
(@return "Union of sets"))
(: union (-> Atom Atom Atom))
(= (union $arg1 $arg2)
(let $c1 (collapse $arg1) (let $c2 (collapse $arg2)
(let $u (union-atom $c1 $c2) (superpose $u)))))

(@doc intersection
(@desc "Function takes two non-deterministic inputs (first and second argument) and returns their intersection. E.g. (intersection (superpose (a b c c)) (superpose (b c c c d))) -> [b, c, c]")
(@params (
(@param "Non-deterministic set of values")
(@param "Another non-deterministic set of values")))
(@return "Intersection of sets"))
(: intersection (-> Atom Atom Atom))
(= (intersection $arg1 $arg2)
(let $c1 (collapse $arg1) (let $c2 (collapse $arg2)
(let $u (intersection-atom $c1 $c2) (superpose $u)))))

(@doc subtraction
(@desc "Function takes two non-deterministic inputs (first and second argument) and returns their subtraction. E.g. !(subtraction (superpose (a b b c)) (superpose (b c c d))) -> [a, b]")
(@params (
(@param "Non-deterministic set of values")
(@param "Another non-deterministic set of values")))
(@return "Subtraction of sets"))
(: subtraction (-> Atom Atom Atom))
(= (subtraction $arg1 $arg2)
(let $c1 (collapse $arg1) (let $c2 (collapse $arg2)
(let $u (subtraction-atom $c1 $c2) (superpose $u)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Documentation formatting functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -657,35 +698,35 @@
(@params ())
(@return "Random boolean value"))

(@doc unique
(@desc "Function takes non-deterministic input (first argument) and returns only unique entities. E.g. (unique (superpose (a b c d d))) -> [a, b, c, d]")
(@doc unique-atom
(@desc "Function takes tuple and returns only unique entities. E.g. (unique-atom (a b c d d)) -> (a b c d)")
(@params (
(@param "Non-deterministic set of values")))
(@param "List of values")))
(@return "Unique values from input set"))

(@doc union
(@desc "Function takes two non-deterministic inputs (first and second argument) and returns their union. E.g. (union (superpose (a b b c)) (superpose (b c c d))) -> [a, b, b, c, b, c, c, d]")
(@doc union-atom
(@desc "Function takes two tuples and returns their union. E.g. (union-atom (a b b c) (b c c d)) -> (a b b c b c c d)")
(@params (
(@param "Non-deterministic set of values")
(@param "Another non-deterministic set of values")))
(@param "List of values")
(@param "List of values")))
(@return "Union of sets"))

(@doc intersection
(@desc "Function takes two non-deterministic inputs (first and second argument) and returns their intersection. E.g. (intersection (superpose (a b c c)) (superpose (b c c c d))) -> [b, c, c]")
(@doc intersection-atom
(@desc "Function takes two tuples and returns their intersection. E.g. (intersection-atom (a b c c) (b c c c d)) -> (b c c)")
(@params (
(@param "Non-deterministic set of values")
(@param "Another non-deterministic set of values")))
(@param "List of values")
(@param "List of values")))
(@return "Intersection of sets"))

(@doc subtraction
(@desc "Function takes two non-deterministic inputs (first and second argument) and returns their subtraction. E.g. !(subtraction (superpose (a b b c)) (superpose (b c c d))) -> [a, b]")
(@doc subtraction-atom
(@desc "Function takes two tuples and returns their subtraction. E.g. !(subtraction-atom (a b b c) (b c c d)) -> (a b)")
(@params (
(@param "Non-deterministic set of values")
(@param "Another non-deterministic set of values")))
(@param "List of values")
(@param "List of values")))
(@return "Subtraction of sets"))

(@doc git-module!
(@desc "Provides access to module in a remote git repo, from within MeTTa code. Similar to `register-module!`, this op will bypass the catalog search")
(@params (
(@param "URL to github repo")))
(@return "Unit atom"))
(@return "Unit atom"))
Loading
Loading