sets

package
v0.0.0-...-0505374 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sets implement basic math sets theory, usefull to evaluate an answer. For instance, the two expression A and A ∩ (B U neg(B)) are equal

Note that this package treats sets as opaque, so that simplification using relation such as A = B U C are not supported.

Index

Constants

View Source
const MaxNumberOfLeaves = 16

Variables

This section is empty.

Functions

This section is empty.

Types

type BinNode

type BinNode interface {
	String() string
	// contains filtered or unexported methods
}

BinNode is one node of a binary tree representation of a set expression.

The nil value is invalid and does not appear in a well formed tree.

type BinarySet

type BinarySet struct {
	// Sets stores the LaTeX code of each set,
	// like "A", "B_i" or "B_{i+1}", and is indexed by
	// a Leaf id.
	// A well formed set has no more than [MaxNumberOfLeaves] leaves.
	Sets []string
	Root BinNode
}

func (BinarySet) IsEquivalent

func (s BinarySet) IsEquivalent(other BinNode) bool

IsEquivalent assumes [other] is built with the same leaves, and returns true if the two expressions define the same set. For instance, A n A == A and (A n B) u (A n neg(B)) == A

func (BinarySet) ToList

func (bin BinarySet) ToList() ListSet

type Complement

type Complement struct {
	Right BinNode
}

func (Complement) String

func (c Complement) String() string

type Inter

type Inter struct {
	Left, Right BinNode
}

func (Inter) String

func (i Inter) String() string

type ListNode

type ListNode struct {
	// with length 0 if Op == SLeaf, one if Op == SComplement, > 1 otherwise
	Args []ListNode
	Op   SetOp
	Leaf Set // valid only if Op == SLeaf
}

ListNode is a tree where operator are grouped when possible, used by the student app.

func (ListNode) ToBin

func (ls ListNode) ToBin() BinNode

ToBin converts the given tree to a binary version.

type ListSet

type ListSet struct {
	Leaves []string // indexed by Leaf
	Expr   ListNode
}

ListSet is a tree where operator are grouped when possible, and leaf contents are extracted

type Set

type Set int

Set is an index into the [BinarySet.Leaves] slice.

func (Set) String

func (l Set) String() string

type SetOp

type SetOp uint8
const (
	SLeaf SetOp = iota
	SUnion
	SInter
	SComplement
)

type Union

type Union struct {
	Left, Right BinNode
}

func (Union) String

func (u Union) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL