Liking cljdoc? Tell your friends :D

sicmutils.expression.analyze

This namespace defines an API for working with 'expression analyzers' and the ICanonicalize protocol.

Expression analyzers find canonical forms of inputs over limited vocabularies of operations. For example, a polynomial analyzer will expose operations like addition, subtraction, multiplication, and exponentiation by positive integers (but not division).

An expression containing only these operations and symbols can then be converted to and from a polynomial canonical form, which in this example would have the effect of grouping like terms; a rational function backend would include the division operation and be capable of cancellation. Canonicalizing an expression with respect to an analyzer is therefore effected by a round-trip to and from the canonical form.

This namespace defines an API for working with 'expression analyzers' and
the [[ICanonicalize]] protocol.

Expression analyzers find canonical forms of inputs over limited vocabularies
of operations. For example, a polynomial analyzer will expose operations like
addition, subtraction, multiplication, and exponentiation by positive
integers (but not division).

An expression containing only these operations and symbols can then be
converted to and from a polynomial canonical form, which in this example would
have the effect of grouping like terms; a rational function backend would
include the division operation and be capable of cancellation. Canonicalizing
an expression with respect to an analyzer is therefore effected by a
round-trip to and from the canonical form.
raw docstring

ICanonicalizeclj/sprotocol

ICanonicalize captures the methods exposed by a SICMUtils analyzer backend.

[[ICanonicalize]] captures the methods exposed by a SICMUtils analyzer backend.

->expressionclj/s

(->expression analyzer b variables)

Convert a canonical form b back to S-expression form.

Each ICanonicalize instance uses variables in different ways. The variables sequence is typically obtained from the continuation invoked by [[expression->]], so these functions are complementary.

Convert a canonical form `b` back to S-expression form.

Each [[ICanonicalize]] instance uses `variables` in different ways. The
`variables` sequence is typically obtained from the continuation invoked
by [[expression->]], so these functions are complementary.

expression->clj/s

(expression-> analyzer x continue)
(expression-> analyzer x continue compare-fn)

Invokes continue with

  • A version of x converted to the canonical form represented by analyzer
  • A (sorted) sequence of variables found in x

compare-fn is used to sort variables. Defaults to clojure.core/compare.

Invokes `continue` with

- A version of `x` converted to the canonical form represented by `analyzer`
- A (sorted) sequence of variables found in `x`

`compare-fn` is used to sort variables. Defaults to `clojure.core/compare`.

known-operation?clj/s

(known-operation? analyzer x)

Returns true if the symbolic operation x is considered fundamental by analyzer, false otherwise.

Returns true if the symbolic operation `x` is considered fundamental by
`analyzer`, false otherwise.

new-variablesclj/s

(new-variables analyzer n)

Returns n new symbolic variables used to represent values outside the domain of computation for analyzer

Returns `n` new symbolic variables used to represent values outside the
domain of computation for `analyzer`
sourceraw docstring

make-analyzerclj/s

(make-analyzer backend symbol-generator)

Make-analyzer takes an analyzer backend (which implements ICanonicalize) and provides the apparatus necessary to prepare expressions for analysis by replacing subexpressions formed from operations unknown to the analyzer with generated symbols, and backsubstituting after analysis is complete.

For example, in the case of polynomial canonical form, we would replace a subexpression like (sin x) with a gensym, before entry, since the sine operation is not available to the polynomial canonicalizer, and restore it afterwards.

Make-analyzer takes an analyzer `backend` (which implements [[ICanonicalize]])
and provides the apparatus necessary to prepare expressions for analysis by
replacing subexpressions formed from operations unknown to the analyzer with
generated symbols, and backsubstituting after analysis is complete.

For example, in the case of polynomial canonical form, we would replace a
subexpression like `(sin x)` with a gensym, before entry, since the sine
operation is not available to the polynomial canonicalizer, and restore it
afterwards.
sourceraw docstring

monotonic-symbol-generatorclj/s

(monotonic-symbol-generator prefix)

Returns a function which generates a sequence of symbols with the given prefix with the property that later symbols will sort after earlier symbols.

This is important for the stability of the simplifier. (If we just used clojure.core/gensym, then a temporary symbol like G__1000 will sort earlier than G__999. This will trigger errors at unpredictable times, whenever clojure.core/gensym returns two symbols that cross an order-of-magnitude boundary.)

Returns a function which generates a sequence of symbols with the given
`prefix` with the property that later symbols will sort after earlier symbols.

This is important for the stability of the simplifier. (If we just used
`clojure.core/gensym`, then a temporary symbol like `G__1000` will sort
earlier than `G__999`. This will trigger errors at unpredictable times,
whenever `clojure.core/gensym` returns two symbols that cross an
order-of-magnitude boundary.)
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close