Skip to content

Commit 3cb008c

Browse files
committed
add more documentation
1 parent c440dcf commit 3cb008c

1 file changed

Lines changed: 306 additions & 3 deletions

File tree

src/lisb/translation/definition.clj

Lines changed: 306 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050

5151
; Missing:
5252
;; Predicates
53-
;; Set Operators
54-
;; Relations
55-
;; Functions
5653
;; Sequences
5754
;; Records
5855
;; Substitutions
@@ -325,10 +322,315 @@
325322
Then, map the expression over all those values and return the set intersection of the results.
326323
See also: union-pe, intersection, intersect-sets, sigma.")
327324

325+
;; ----
326+
327+
(op "cartesian-product" (cartesian-product #{1 2} #{3 4}) [& sets]
328+
"Set operator. Calculates the cartesian product of all given sets.")
329+
330+
(op "cart-or-mult" (cart-or-mult #{1 2} #{3 4}) [& all-sets-or-all-nums]
331+
"DEPRECATED! Do not use this.
332+
This is an internal node which only exists because the parser does not include
333+
type checking information. It does not contain information whether it is
334+
a cartesian product or a multiplication. Please use instead:
335+
*, cartesian-product.")
336+
;; -----
337+
338+
(literal [1 -> 2]
339+
"Tuple literal. Can be chained, for example, as [1 -> 2 -> 3 -> etc].
340+
Must be a vector, must contain a left element, the arrow symbol `->` and a right element.
341+
Does not directly create an intermediate representation but a tuple object instead.
342+
Corresponding IR can be seen when the print is wrapped in
343+
`(binding [lisb.translation.types/*as-ir* true] ...)`.
344+
See also: maplet, |->.")
345+
346+
(op "maplet" (maplet 1 2 3) [& elements]
347+
"Tuple constructor. Creates the (nested) tuple from the passed elements.
348+
See also: Tuple literal, |->")
349+
350+
(op "|->" (|-> 1 2 3) [& elements]
351+
"Tuple constructor. Creates the (nested) tuple from the passed elements.
352+
Same as maplet.
353+
See also: Tuple literal, maplet")
354+
355+
356+
;; --
357+
(op "<->" (<-> #{1 2} #{2 3}) [& sets]
358+
"Returns the set of all relations between the given sets.
359+
See also: relation, <<->, <->>, <<->>")
360+
361+
(op "relation" (relation #{1 2} #{2 3}) [& sets]
362+
"Returns the set of all relations between the given sets.
363+
Same as <->.
364+
See also: <->, total-relation, surjective-relation, total-surjective-relation.")
365+
366+
(op "<<->" (<<-> #{1 2} #{2 3}) [& sets]
367+
"Returns the set of all total relations between the given sets.
368+
See also: total-relation, <->, <->>, <<->>")
369+
370+
(op "total-relation" (total-relation #{1 2} #{2 3}) [& sets]
371+
"Returns the set of all total relations between the given sets.
372+
Same as <<->.
373+
See also: <<->, relation, surjective-relation, total-surjective-relation.")
374+
375+
(op "<->>" (<->> #{1 2} #{2 3}) [& sets]
376+
"Returns the set of all surjective relations between the given sets.
377+
See also: surjective-relation, <->, <<->, <<->>")
378+
379+
(op "surjective-relation" (surjective-relation #{1 2} #{2 3}) [& sets]
380+
"Returns the set of all total relations between the given sets.
381+
Same as <->>.
382+
See also: <->>, relation, total-relation, total-surjective-relation.")
383+
384+
(op "<<->>" (<<->> #{1 2} #{2 3}) [& sets]
385+
"Returns the set of all total and surjective relations between the given sets.
386+
See also: total-surjective-relation, <->, <<->, <->>")
387+
388+
(op "total-surjective-relation" (total-surjective-relation #{1 2} #{2 3}) [& sets]
389+
"Returns the set of all total and surjective relations between the given sets.
390+
Same as <<->>.
391+
See also: <<->>, relation, total-relation, surjective-relation.")
392+
393+
;; ---
394+
395+
(op "dom" (dom #{[1 -> 2], [2 -> 3]}) [relation]
396+
"Returns the domain of a given relation.
397+
Note that the operation returns the left sides of the tuples actually contained
398+
in the relation, not the domain of the type of the relation.
399+
See also: ran")
400+
401+
(op "ran" (ran #{[1 -> 2], [2 -> 3]}) [relation]
402+
"Returns the range of a given relation.
403+
Note that the operation returns the right sides of the tuples actually contained
404+
in the relation, not the domain of the type of the relation.
405+
See also: dom")
406+
407+
;; --
408+
(op "id" (id #{1 2 3}) [set]
409+
"Returns the identity relation over a given set, mapping each element to itself.")
410+
411+
412+
;; --
413+
(op "<|" (<| #{1 2 3} #{[0 -> 1] [1 -> 2]}) [set relation]
414+
"Restricts the domain of a relation to the specified set, i.e., it removes all tuples
415+
whose left-hand side is not contained in the set.
416+
See also: domain-restriction, <||, |>, |>>")
417+
418+
(op "domain-restriction" (domain-restriction #{1 2 3} #{[0 -> 1] [1 -> 2]}) [set relation]
419+
"Restricts the domain of a relation to the specified set, i.e., it removes all tuples
420+
whose left-hand side is not contained in the set.
421+
Same as <|.
422+
See also: <|, domain-subtraction, range-restriction")
423+
424+
(op "<||" (<| #{1 2 3} #{[0 -> 1] [1 -> 2]}) [set relation]
425+
"Subtracts the specified set from the domain of the relation, i.e., it removes all tuples
426+
whose left-hand side is contained in the set.
427+
See also: domain-subtraction, <|, |>, |>>")
428+
429+
(op "domain-subtraction" (domain-subtraction #{1 2 3} #{[0 -> 1] [1 -> 2]}) [set relation]
430+
"Subtracts the specified set from the domain of the relation, i.e., it removes all tuples
431+
whose left-hand side is contained in the set.
432+
Same as <||.
433+
See also: <|, domain-restriction, range-subtraction")
434+
435+
(op "|>" (|> #{[0 -> 1] [1 -> 2]} #{1 2 3}) [relation set]
436+
"Restricts the range of a relation to the specified set, i.e., it removes all tuples
437+
whose right-hand side is not contained in the set.
438+
See also: range-restriction, <|, <||, <<|, |>>")
439+
440+
(op "range-restriction" (range-restriction #{[0 -> 1] [1 -> 2]} #{1 2 3} ) [relation set]
441+
"Restricts the domain of a relation to the specified set, i.e., it removes all tuples
442+
whose left-hand side is not contained in the set.
443+
Same as |>.
444+
See also: |>, domain-restriction, range-subtraction")
445+
446+
(op "|>>" (|>> #{[0 -> 1] [1 -> 2]} #{1 2 3}) [relation set]
447+
"Subtracts the specified set from the range of the relation, i.e., it removes all tuples
448+
whose right-hand side is contained in the set.
449+
See also: range-restriction, <|, <||, <<|, |>>")
450+
451+
(op "range-subtraction" (range-restriction #{[0 -> 1] [1 -> 2]} #{1 2 3} ) [relation set]
452+
"Subtracts the specified set from the range of the relation, i.e., it removes all tuples
453+
whose right-hand side is contained in the set.
454+
Same as |>>.
455+
See also: |>>, domain-subtraction, range-restriction")
456+
457+
;; ---
458+
(op "inverse" (inverse #{[1 -> 2]}) [relation]
459+
"Returns the inverse relation that swaps the left- and right-hand side of all contained tuples.")
460+
461+
(op "image" (image #{[1 -> 2] [2 -> 3] [3 -> 4]} #{1 2}) [relation set]
462+
"Returns the relational image, i.e., the set of all right-hand sides contained in the relation,
463+
whose left-hand side is contained in the passed set.")
464+
465+
(op "<+" (<+ #{[1 -> 2] [1 -> 3] [3 -> 4]} #{[1 -> 1] [2 -> 0]}) [& relations]
466+
"Relational override. Can be seen as a combination of domain subtraction of the domain of relation2
467+
from relation1, followed by a union with relation2.")
468+
469+
(op "override" (override #{[1 -> 2] [1 -> 3] [3 -> 4]} #{[1 -> 1] [2 -> 0]}) [& relations]
470+
"Relational override. Can be seen as a combination of domain subtraction of the domain of relation2
471+
from relation1, followed by a union with relation2.
472+
Same as <+.")
473+
474+
(op "><" (>< #{[3 -> 4] [1 -> 2] [2 -> 3]} #{[4 -> 0] [1 -> 0]}) [& relations]
475+
"Direct product of the relations. If relation1 and relation2 have tuples with the same left-hand side,
476+
the resulting relation will contain a tuple with this value as its left-hand side and
477+
both right-hand sides of relation1 and relation2 as its right-hand side.
478+
Could be written as: {x,y,z | (x,y) : relation1 & (x,z) : relation2}
479+
See also: direct-product.")
480+
481+
(op "direct-product" (direct-product #{[3 -> 4] [1 -> 2] [2 -> 3]} #{[4 -> 0] [1 -> 0]}) [& relations]
482+
"Direct product of the relations. If relation1 and relation2 have tuples with the same left-hand side,
483+
the resulting relation will contain a tuple with this value as its left-hand side and
484+
both right-hand sides of relation1 and relation2 as its right-hand side.
485+
Could be written as: {x,y,z | (x,y) : relation1 & (x,z) : relation2}.
486+
Same as ><.
487+
See also: ><.")
488+
489+
(op "composition" (composition #{[1 -> 2] [3 -> 4]} #{[2 -> 6] [4 -> 4]}) [& relations]
490+
"The composition of two relations. If a right-hand side of relation1 is contained as a left-hand side
491+
in relation2, replace its with the corresponding right-hand side of relation2.
492+
Could be written as: {x,z | exists y . (x,y) : relation1 & (y,z) : relation2}.")
493+
494+
(op "parallel-product" (parallel-product #{[3 -> 4] [1 -> 2]} #{[5 -> 6] [7 -> 8]}) [& relations]
495+
"Parallel product of two relations. Returns a set of nested tuples [lhs1 -> lhs2 -> [rhs1 -> rhs2]].
496+
Could be written as: {((x,v), (y,w)) | (x,y) : relation1 & (v,w) : relation2}.")
497+
498+
;; --
499+
(op "prj1" (prj1 nat-set nat-set) [set-domain set-range]
500+
"Transformation function.
501+
Returns a projection function, properly typed according to the passed sets.
502+
If a tuple is passed to this function, will return the left-hand side.")
503+
504+
(op "prj2" (prj2 nat-set nat-set) [set-domain set-range]
505+
"Transformation function.
506+
Returns a projection function, properly typed according to the passed sets.
507+
If a tuple is passed to this function, will return the right-hand side.")
508+
509+
;; --
510+
(op "closure" (closure #{[1 -> 2] [2 -> 3]}) [relation]
511+
"Transitive and reflexive closure.
512+
Transitive: If [elem1 -> elem2] and [elem2 -> elem3] is contained in the relation, [elem1 -> elem3]
513+
will be contained as well. Same with any element that is further 'reachable' from elem3.
514+
Reflexive: If elem is contained as a left-hand side, [elem -> elem] will be contained in the result.
515+
See also: closure1, iterate.")
516+
517+
(op "closure1" (closure1 #{[1 -> 2] [2 -> 3]}) [relation]
518+
"Transitive closure.
519+
Transitive: If [elem1 -> elem2] and [elem2 -> elem3] is contained in the relation, [elem1 -> elem3]
520+
will be contained as well. Same with any element that is further 'reachable' from elem3.
521+
Will only contain [elem -> elem] if elem is reachable from the same node via a non-empty 'path'.
522+
See also: closure, iterate.")
523+
524+
(op "iterate" (iterate #{[1 -> 2] [2 -> 3]} 2) [relation n]
525+
"Iteration of the relation.
526+
Will contain tuples [elem1 -> elem2] with elem2 'reachable' from elem1 within n steps.
527+
See also: closure, closure1.")
528+
529+
;; --
530+
(op "fnc" (fnc #{[1 -> 2] [1 -> 3]}) [relation]
531+
"Transformation function. Will transform the relation to a function by collecting all right-hand sides
532+
of the same left-hand side as a set and create the corresponding mapping #{[lhs1 -> #{rhs1, rhs2}] etc}.
533+
Inverse function of rel.
534+
See also: rel.")
535+
536+
(op "rel" (rel #{(maplet 1 #{1 2})}) [function]
537+
"Transformation function. Will transform a function of the form elem -> set(elems) by 'splicing'
538+
the set into (multiple) relational mappings [elem -> elem1], [elem -> elem2], etc.
539+
Inverse function of fnc.
540+
See also: fnc.")
541+
542+
;; ---
543+
544+
(op "+->" (+-> #{1 2 3} #{4 5 6}) [set1 set2]
545+
"Set of all partial functions from set1 to set2.
546+
See also: partial-function, -->, +->>, >+>, >+>>.")
547+
548+
(op "partial-function" (partial-function #{1 2 3} #{4 5 6}) [set1 set2]
549+
"Set of all partial functions from set1 to set2.
550+
Same as +->.
551+
See also: +->, total-function, partial-surjection, partial-injection, partial-bijection.")
552+
553+
(op "-->" (--> #{1 2 3} #{4 5 6}) [set1 set2]
554+
"Set of all total functions from set1 to set2.
555+
See also: total-function, +->, -->>, >->, >->>.")
556+
557+
(op "total-function" (total-function #{1 2 3} #{4 5 6}) [set1 set2]
558+
"Set of all total functions from set1 to set2.
559+
Same as -->.
560+
See also: -->, partial-function, total-surjection, total-injection, total-bijection.")
561+
562+
(op "+->>" (+->> #{1 2 3} #{4 5 6}) [set1 set2]
563+
"Set of all partial surjective functions from set1 to set2.
564+
See also: partial-surjection, -->, +->>, >+>, >+>>.")
565+
566+
(op "partial-surjection" (partial-surjection #{1 2 3} #{4 5 6}) [set1 set2]
567+
"Set of all partial surjective functions from set1 to set2.
568+
Same as +->>.
569+
See also: +->>, total-surjection, partial-function, partial-injection, partial-bijection.")
570+
571+
(op "-->>" (-->> #{1 2 3} #{4 5 6}) [set1 set2]
572+
"Set of all total surjective functions from set1 to set2.
573+
See also: total-surjection, -->, +->>, >->, >->>.")
574+
575+
(op "total-surjection" (total-surjection #{1 2 3} #{4 5 6}) [set1 set2]
576+
"Set of all total surjective functions from set1 to set2.
577+
Same as -->>.
578+
See also: +->>, total-function, partial-surjection, total-injection, total-bijection.")
579+
580+
581+
(op ">+>" (>+> #{1 2 3} #{4 5 6}) [set1 set2]
582+
"Set of all partial injective functions from set1 to set2.
583+
See also: partial-injection, >->, +->, +->>, >+>>.")
584+
585+
(op "partial-injection" (partial-injection #{1 2 3} #{4 5 6}) [set1 set2]
586+
"Set of all partial injective functions from set1 to set2.
587+
Same as >+>.
588+
See also: +->>, total-injection, partial-function, partial-surjection, partial-bijection.")
589+
590+
(op ">->" (>-> #{1 2 3} #{4 5 6}) [set1 set2]
591+
"Set of all total injective functions from set1 to set2.
592+
See also: total-injection, -->, +->>, >->, >->>.")
593+
594+
(op "total-injection" (total-surjection #{1 2 3} #{4 5 6}) [set1 set2]
595+
"Set of all total injective functions from set1 to set2.
596+
Same as >->.
597+
See also: >->, total-function, partial-injection, total-surjection, total-bijection.")
598+
599+
600+
(op ">+>>" (>+>> #{1 2 3} #{4 5 6}) [set1 set2]
601+
"Set of all partial bijective functions from set1 to set2.
602+
See also: partial-bijection, >->>, +->, +->>, >+>.")
603+
604+
(op "partial-bijection" (partial-bijection #{1 2 3} #{4 5 6}) [set1 set2]
605+
"Set of all partial bijective functions from set1 to set2.
606+
Same as >+>>.
607+
See also: +->>, total-bijection, partial-function, partial-surjection, partial-injection.")
608+
609+
(op ">->>" (>->> #{1 2 3} #{4 5 6}) [set1 set2]
610+
"Set of all total bijective functions from set1 to set2.
611+
See also: total-bijection, -->, >+>>, >->, -->>.")
612+
613+
(op "total-bijection" (total-bijection #{1 2 3} #{4 5 6}) [set1 set2]
614+
"Set of all total bijective functions from set1 to set2.
615+
Same as >->>.
616+
See also: >->, total-function, partial-bijection, total-surjection, total-injection.")
617+
618+
;; ---
619+
620+
(op "lambda" (lambda [:x] (member? :x #{1 2}) (inc :x)) [ids pred expr]
621+
"Lambda expression. Creates a function mapping all identifer values constrained by the predicate
622+
to the given expression (likely depending on the identifier values).")
623+
624+
(op "fn-call" (fn-call #{[1 -> 2]} 1) [fn & elems]
625+
"Function call. Will apply the function to the specified element.
626+
Has a well-definedness condition. The element must be in the domain of the function.")
627+
628+
328629
])
329630

330631

331632

633+
332634
(defn bpropos [search & {:as opts :keys [short]}]
333635
(let [search (clojure.string/lower-case search)]
334636
(doseq [res (filter (fn [x] (some #(clojure.string/includes?
@@ -342,3 +644,4 @@
342644

343645
(comment (bpropos "add" :short false)
344646
(bpropos "greater"))
647+
(bpropos "NAT")

0 commit comments

Comments
 (0)