Interface

This interface is used to implement the built-in operators and can be used to implement custom operators.

Warning

This interface is incomplete and will be changed in v0.4.

Methods

These methods are required to be implemented for some functionalities. If a required method is not implemented, a runtime error will display the function and operator that a method must be implemented for. Default implementations of are not provided so as to avoid correctness bugs.

PAndQ.Interface.OperatorType
Operator{O}
Operator{O}()

Return an operator named O.

Operators are uniquely identified by their name. If possible, an operator should be defined as const o = ℴ = Operator{:o}() where symbol(ℴ) == "ℴ".

This method is required to instantiate an operator.

source

Evaluation

PAndQ.Interface.evaluateFunction
evaluate(::Symbol, ps)

Define the semantics of the Operator.

This method is required to normalize a proposition containing the given operator.

Examples

julia> @atomize Interface.evaluate(¬, [¬p])
p

julia> @atomize Interface.evaluate(→, [p, q])
¬p ∨ q
source

Folding

PAndQ.Interface.initial_valueFunction
initial_value(ℴ::Operator)

Specify a neutral value, v, of a binary Operator such that ℴ(v, p) == p.

If there is no such neutral value, return nothing.

This method is required for calling fold over the operator.

See also ==.

Examples

julia> Interface.initial_value(∧)
⊤

julia> Interface.initial_value(∨)
⊥

julia> Interface.initial_value(↑)
source

Printing

PAndQ.Interface.print_expressionFunction
print_expression(io, ::Operator, ps)

Print the node of a syntax tree containing the Operator and its propositions.

If a node in a syntax tree is not the root node, it may be necessary to parenthesize it to avoid ambiguity. This context can be obtained using is_root.

Each proposition should be represented using print_proposition.

This method is required for calling show(::IO, ::MIME"text/plain, p) for a proposition p containing the given operator.

Examples

julia> @atomize Interface.print_expression(stdout, ⊤, [])
⊤

julia> @atomize Interface.print_expression(stdout, ¬, [p])
¬p

julia> @atomize Interface.print_expression(stdout, ∧, [p, q])
p ∧ q
source
PAndQ.Interface.symbolFunction
symbol(ℴ::Operator)

Return the Unicode symbol of the Operator.

If possible, this should be implemented as symbol(::typeof(ℴ)) = "ℴ".

This method is required for calling show(::IO, ::MIME"text/plain", ::typeof(ℴ)).

See also show.

Examples

julia> Interface.symbol(⊤)
:⊤

julia> Interface.symbol(¬)
:¬

julia> Interface.symbol(∧)
:∧
source

Utilities

These functions may be necessary or useful for implementing the operator interface.

Printing

PAndQ.Interface.print_propositionFunction
print_proposition(io, p)

Print the given proposition with the IOContext that :root => false.

Should be called from print_expression.

Examples

julia> @atomize print_proposition(stdout, ¬p)
¬p

julia> @atomize print_proposition(stdout, p ∧ q)
(p ∧ q)
source

Properties

PAndQ.Interface.arityFunction
arity(::Operator)

Return the number of propositions accepted by the Operator.

Examples

julia> Interface.arity(⊤)
0

julia> Interface.arity(¬)
1

julia> Interface.arity(∧)
2
source
PAndQ.Interface.dualFunction
dual(ℴ::Operator)

Return a function such that dual(ℴ)(ps...) == ¬(ℴ(map(¬, ps)...)).

If possible, this method should be implemented to return another Operator.

See also not and ==.

Examples

julia> Interface.dual(and)
∨

julia> Interface.dual(imply)
↚
source

Predicates

PAndQ.Interface.is_associativeFunction
is_associative(ℴ::Operator)

Return a Boolean indicating whether the operator has the associative property such that ℴ(ℴ(p, q), r) == ℴ(p, ℴ(q, r)).

See also ==.

Examples

julia> Interface.is_associative(∧)
true

julia> Interface.is_associative(→)
false
source
PAndQ.Interface.is_commutativeFunction
is_commutative(ℴ::Operator)

Return a Boolean indicating whether operator has the commutative property such that ℴ(p, q) == ℴ(q, p).

See also ==.

Examples

julia> Interface.is_commutative(∧)
true

julia> Interface.is_commutative(→)
false
source