# The Prooftoys Language

The language is a computer-oriented notation for mathematical formulas. It allows variables for functions and predicates as well as individual values, so it is “higher-order”. And it has notation for anonymous functions, see below.

The language has only expressions. The parser and printer both support infix notation and precedence of operators, so for example it fills in parentheses so `2*x + 3*y` means the same as `(2*x) + (3*y)` and not `((2*x) + 3)*y` or even something different.

## Special characters

The characters `"`, `'`, `(`, `)`, `[`, `]`, `{`, `}`, `\`, `#`, ```, `:`, and `.` are special and never part of any variable, constant, or operator name.

## Variables and constants

A letter optionally followed by any number of letters, digits, and underscores is an identifier.

For example `a`, `b`, `x`, `x_1`, `P`, `PI`, `y0`, `sin`, and `log10` are identifiers.

A variable name is a single letter optionally followed by an underscore and one or more digits. The identifiers `T`, `F`, `R`, and `e` however are reserved for names of commonly-used constants.

For example `a`, `b`, `x`, `x_1`, and `P` are variable names, but `PI`, `y0`, `sin`, and `log10` are not.

Only variable names are allowed as the bound variable in a function literal, and substitution can only be applied to variables, not constants.

Any identifier that is not a variable name is a constant name. Also, any sequence of graphic characters other than alphabetics, numerics, underscores, dollar signs, parentheses, braces, brackets, single- and double-quotation marks, backquotes, colons, semicolons, commas and dots is a constant name.

Sequences of characters that are not whitespace, not reserved as shown above, and not letters, digits, or underscores are operator names. All operator names are constant names.

All of `R`, `pi`, `sin`, `log10`, `>=`, and `-->` are constant names.

Only constants can have definitions.

Numeric literals. Prooftoys treats the usual numeric literals as representing real numbers. Currently only integer literals are supported. An expression such as `-2` is always an integer literal, so when subtracting be sure to leave a space between the `-` and a following literal number.

Other literals. The language has string literals beginning and ending with the quote character ("). Within a string literal, occurrences of backslash () followed by any other character are part of the string literal. So `"\""` is a string literal.

Literals of course have predefined values and cannot be defined by users.

## Operators

Names of the boolean operators favor programming language practice over mathematical logic, with &and | for and and or. The infix operators in order of increasing precedence are:

Symbol Display Typical usage
`==` Logical equivalence. Note: currently same as = but lower precedence
`=>` implication
`=, !=` =, ≠ equality and its negation
`|` or
`&` and
`<, <=, >, >=` <, ≤, >, ≥ inequality operators
`+, -` +, - add and subtract
`*, /` ⋅, / multiply and divide

## Functions

Functions with names that are identifiers, both constants and variables, have higher precedence than any of these, so for example

``````f x * g y
``````

is the same as

``````(f x) * (g y)
``````

and both of these have calls a function `f` and a function `g`, each taking one argument.

To call a function `f` with multiple arguments, simply write an additional expression for each argument, like this:

``````f (x + y) z (g w)
``````

This represents a call to `f` with arguments `x + y`, `z`, and `g w` Predicates use the same notation.

Writing `f(x)` means the same as `f x`, but `f (x y)` is a call to a function `f` of one argument, the result of applying function `x` to `y`, not a call to a function `f` of two arguments.

#### Special operators/functions

The logical “not” operator is just a function, so `not a | b` is the same as `(not a) | b`.

Similarly, negative and reciprocal are represented by “neg” and “recip”, which are just functions. So `neg x + y` is the same as `(neg x) + y`.

#### Function expressions

The language has a form of the traditional “set notation” for predicates, as in `{x. x < 10}` (“the set of x such that x is less than ten”). In this example the first `x` is known as the bound variable, and the `x < 10` is the body of the function. The Prooftoys language extends the notation to functions, for example `{x. x*x}` for a function that computes the square of a number. The key difference from set notation is just that the body can have a value that is not boolean.

In Prooftoys the value of `{x. x < 10}` for example is a predicate, like any other. So it is not necessary to write something like `z in {x. x < 10}`. You can just write it like a predicate or function call: `{x. x < 10} x`.
{"ft_lang_label":"__label__en","ft_lang_prob":0.84548026,"math_prob":0.9672001,"size":4478,"snap":"2021-31-2021-39","text_gpt3_token_len":1152,"char_repetition_ratio":0.11935628,"word_repetition_ratio":0.037647057,"special_character_ratio":0.26574364,"punctuation_ratio":0.16481069,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.989758,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-22T05:01:16Z\",\"WARC-Record-ID\":\"<urn:uuid:8d530288-4692-46bf-81d8-6bb93c7b1a95>\",\"Content-Length\":\"13127\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:218a5420-8660-4c56-8feb-d373366577ed>\",\"WARC-Concurrent-To\":\"<urn:uuid:54705a5d-ffed-4bd3-b6c5-a014391f5233>\",\"WARC-IP-Address\":\"157.245.84.7\",\"WARC-Target-URI\":\"https://prooftoys.org/prooftoys-language/\",\"WARC-Payload-Digest\":\"sha1:MX6O7C45H4ZLCAWVORM534OIO25SLU55\",\"WARC-Block-Digest\":\"sha1:ZHTYJLJCGEXCWIPVNERY3UYLL62HA4EY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057329.74_warc_CC-MAIN-20210922041825-20210922071825-00067.warc.gz\"}"}