Basics
What is this tool?
Why does this tool exist?
Who made it?
Help using
How do I use it?
What can it do?
What notations can it recognize?
Troubleshooting
The line ... contains unrecognized symbols
The line ... cannot be parsed
[thing] is an Error: type error
[thing] is an Error: DNE error
Page blank and unresponsive
How it works
What technologies does it use?
Written in pure JavaScript? Are you serious?
What exactly is it doing?
What's is this tool?
This tool is an automatic set theory calculator. It understands the
natural language of set theory, interprets it, and performs set-theoretical
calculations.
Why does this tool exist?
The set theory calculator is designed for exploratory student use in a
learning environment, to enhance learning.
Who made it?
Jason Howald, math professor at SUNY Potsdam and computer programmer,
wrote this tool primarily in the summer of 2007, with the intention
to use it in the course Set Theory and Logic.
Help using
How do I use it?
You may wish to go back to the
main page
and view the examples first. In a nutshell, you write expressions, such as
Let x = {1,2,3} and the machine reads it,
interprets its meaning, and learns any variables you define. The computer
reports back all symbols you have defined. For this reason all lines
should define symbols.
What can it do?
The machine knows about
sets (
{{},{1,2,3},{1,2}}),
vectors (
(1,2,7)),
functions (
f(x)),
numbers (
42),
statements (
C subset D),
and
abstracts (
{"apple","orange"}). It can do
all basic set theoretical operations, such as union, intersection, set
difference, power set, cardinality, etc. It does basic arithmetic when
needed, and understands
y+7*x^3. It
understands about functions, their domain and range, evaluation, and
notation for definition by formula:
Let f:A to B
via f(x) = x^2+1.
What notations can it recognize?
- Operators:
- , for comma separated lists, building vectors and sets
- .. as in {1..6} =
{1,2,3,4,5,6}
- implies logical implication. The tool does not do
automated theorem proving -- "implies" can only be calculated when
both sides are known.
- or logical or
- and logical and
- = equality operator, which returns "true" or "false".
This applies to all kinds of objects.
- <, >, <=, and >= Inequality assertions apply only
to numbers, as in 3 >= 2
- in as in x in S
- subset as in A subset
B. This includes the case A=B.
- superset as in A superset
B,
which also includes the case A=B.
- +,-,*,/,^ Numerical arithmetic operators behave
according to normal rules.
- ^ Applied to sets, A^B
refers to the set of all functions from B to A.
- union, intersect, setminus Set operators, as in
Let C = A setminus B
- Build in functions:
- |x| Applied to numbers, this means absolute value.
To vectors, Euclidean norm. Applied to sets, this denotes cardinality.
For example, {x in {1,2,3,{4},{5,6},(7,8),(0,2)} ;
|x|=2} results in {2,{5,6},(0,2)}.
- powerset as in powerset(S).
- Let (variable) as in Let S = {1..100}
- Let (function) as in Let f:A to B
via f(x) = x^2+1. This one is extremly picky about its syntax.
All the pieces "Let",":","to", "via", and "f(x)" have to be just so. The
domain and codomain must be immediately known to the computer.
- Abstracts Use quotations {"apple","orange"}
to introduce abstract objects.
- Set-builder notation, comprehension version:
{x in S; f(x) > 6 and x in V}
This notation must begin "[variable] in
[set]", setting out the initial
collection. It must continue with a condition on x, which presumably will
be true for some x and false for others. The set created is the set of
all x's making the claim true.
- Set-builder notation, replacement version:
{x^2 + 5; x in S}
This notation must end "[variable] in
[set]", setting out a collection of x values. Before the semicolon
we write some action to be performed on each. The set created is the
set of all possible results of this action. We call this replacement because the original elements
x in S have been replaced by their modified versions x^2 + 5.
- forall as in forall x in S |x|>6.
"in [set]" is required, to give the machine half a chance of figuring out
whether the statement is true! Resist the temptation to place a comma
after S.
- exists as in exists A in C (y in
A). Again, "in [set]" is required. Do not use "such that",
"s.t.", or comma after "C".
Troubleshooting
The line ... contains unrecognized symbols
This is a "nonsense symbol error."
Technically speaking, the
tokenizer
failed to recognize something you typed as a set theoretical symbol.
Probably you used the wrong symbols to represent something, such as
[1,2,3,4] instead of
(1,2,3,4),
f[S] instead of
f(s),
& instead of
and.
If you can't find the problem, copy what you typed and email
jason.
The line ... cannot be parsed
This is a "bad grammar" error, or "syntax error". It means that the
parser could not
recognize your entry as a grammatically sensible combination of symbols.
This could be caused by the use of a synonym for the right symbol
instead of the right symbol:
elementof instead of
in,
subsetof instead of
subset,
by instead of
via in a function definition,
there exists instead of
exists, etc.
It could also be caused by poor arithmetic or "optimistic" grammar:
a+-b,
a+b**4, or even
x<y<z (try
(x<y) and (y<z)). Negatives currently
generate this error: Instead of
-3, try
0-3. Sorry.
[thing] is an Error: type error
You tried to act on things in a way that they can't be acted on.
For example, you intersected two numbers, evaluated S(4), where
S is not a function, divided two sets, etc.
[thing] is an Error: DNE
You divided by zero, evaluated a function at an element not in its domain,
took the fifth coordinate of a 3D vector, or some other such disaster.
Page blank and unresponsive
This can be caused by an actual internal program error, uncovered by
some peculiar user input. Obviously, it's supposed to
never happen.
If it does happen,
jason would appreciate knowing
the input that caused it.
How it works
What technologies does it use?
Obviously html and css, since the project is a webpage. But these are
very minimal. The entire codebase is written in Javascript.
Written in pure Javascript? Are you serious?
Lots of people criticize Javascript, and I'm among them:
It's interpreted, quirky, has odd syntax, uses peculiar object inheritance,
and can't do regular expressions very well. I chose it for one reason
only: Availability. Everybody runs a browser, so everybody has a
Javascript interpreter already up and running. In my opinion,
DHMTL/Javascript/AJAX/css programming has become what Java was supposed
to become. Also, writing a smooth interface in javascript is a snap,
and that has its appeal.
What exactly is it doing?
Each line of user code is processed separately in order. There is a "grammar" object which converts the
user input to symbols, then passes it to the parser. The parser
is given (by the grammar) a long list of "rules", such as how
to interpret a symbol combination "[symbol][left paren][anything][rightparen]"
as functional evaluation. These rules encompass the full expressivity of
the language of set theory. The parser begins a long bottom-up search
process to express substrings of the symbol string as resulting from
the applications of various rules. From the parser's perspective, the
grammatical rules are variable, handed to it at runtime. So this search
was the hardest part to code. The result of the search is (supposed to
be) a parse tree for the entire expression, which can then be evaluated.
Evaluation is recursive and defined simultaneously with the grammar.
(Each rule has an evaluation method.) The values of the expressions are
vectors, sets, functions, abstracts, etc., and so of course there is a
whole subpackage to define all those gadgets and specify their behavior.
Finally an interface package takes over and makes the objects display in
a pretty way. Any assertion that "let"s a variable causes an update to
a symbol table, which of course affects the evaluation of future
expressions.