Package: thompyson
thompysonInstallationUsepipto install thethompysonpackage.To import the package, runimportthompysonCurrent FunctionalityRationals and DyadicsThethompysonpackage provides utilities for infinite-precision calculations on dyadic rationals (soon to be upgraded to rationals).Creation and OperationTo create a rational or a dyadic, simply rundyadic=thompyson.Dyadic(7,32)Orrational=thompyson.Rational(3,55)Dyadics support the following operations: negation, absolute value, addition, multiplication, subtraction, equality checking, less than (and less than or equal to), greater than (and greater than or equal to),__repr__, and simplification.
Simplifying aDyadicputs it in its canonical form.  There are two different ways to simplify aDyadic.  Ifdyadicis aDyadic, then the first isdyadic.simplify(): this simplifiesdyadicin-place; the second isdyadic.simplified(): this returns the canonical form ofdyadic, but leaves the variabledyadicunchanged.Dyadics support the following operations withints (each still returns aDyadicorbool-- the same as whichever it returned before): addition, multiplication, subtraction, equality checking,<,>,<=,>=.Dyadics support the following operations withfloats, where each returns afloat: addition, subtraction, multiplication.Dyadics support the following operations withfloats, which each returns abool:==,<,>,<=,>=.Dyadics are a sub-class ofRational.  Therefore,Dyadics inherit all the methods ofRationals.
Currently,Rationals support the following operations (where an operation is listed forDyadicabove,Dyadichas its own implementation of the operation): conversion tofloat, conversion toint, negation, taking the absolute value, inversion, simplification, producing aTeXstring (.to_tex), conversion tostr.
Inversion is carried out in three ways: the unary operation~, which is not in-place, and does not modify theRational; the in-place.invert(); and the non in-place.inverted().
Simplification is the same as forDyadics:.simplify()is in-place;.simplified()is not.  Note that both of these operations will change theRationalto aDyadicif that is possible.These operations do not simplify theDyadicorRationalafter running (except, of course, the.simplifymethods).Unless explicitly specified, these operations are all implemented with the default Python methods, meaning that they can all be calculated by running the in-built functions (likeabs,int,float, etc.) or by the in-built operations (like the unary-,*,+, etc).Related FunctionsThere are two functions offered by thethompysonpackage to aid inDyadiccomputations.  The first isdyadic_is_power_of_two, which takes in aDyadicand checks whether it is a power of two or not: it returnsTrueif it is, andFalseotherwise.  The second isdyadic_gradient, which takes in two pairs ofDyadics, representing two co-ordinates in the cartesian plane, and then calculates the gradient of the line between those two points: this value will be aDyadicif the result is a dyadic rational, and will be aRationalotherwise.  In either case, the result will be simplified.Tree PairsThethompysonpackage provides utilities for computations in the groups F and T.CreationTree pairs are written in depth-first search notation.  The third argument is the 1-indexed permutation of the tree pair; that is, it says which leaf in the range tree corresponds to the first leaf in the domain tree.  Note that we can describe this by one-variable as we are working in F and T.  Elements of F have permutation of1, and if a tree pair has a permutation not equal to1, it is an element of T.tree_pair=thompyson.TreePair("10100","11000",1)This stores a tree pair representing{10100,11000,1 2 3}(in nvTrees-notation) into the variabletree_pair.We can runprint(tree_pair)to get an nvTrees-compatible string, describing the element (in particular, this would return the string{10100,11000,1 2 3}).Right ActionsBy default,thompysonuses right actions.  To change to left actions, runthompyson.use_right_actions(False)ComputationsMultiplication is invoked by*(currently, we use left-actions).  Multiplication does not return a reduced tree pair.Exponentiation is invoked by**, and negative powers work as expected.  Exponentiation does not return a reduced tree pair.Conjugation is invoked by^.  Conjugation does not return a reduced tree pair.Commutation is invoked by|.  Commutation does not return a reduced tree pair.Inversion is invoked by~and does not modify the tree pair in question.  Inversion does not return a reduced tree pair. To invert the tree pairtree_pairin place, calltree_pair.invert().  We can also runtree_pair.inverted(), which returns the inverse oftree_pairwithout modifyingtree_pair.Equality checking is invoked by==.  Checking for equality does not reduce the tree pairs first; so, an unreduced tree pair, and a reduced tree pair representing the same element would not be classed as being equal.To return a reduced tree pair, without modifying said tree pair, we use that unary-.  To reduce a tree pairtree_pairin place, we runtree_pair.reduce().  Similar to the unary-,tree_pair.reduced()returns a reduced representation oftree_pair, but does not modify the variabletree_pair.Related FunctionsWe have already seenuse_right_actions. But,thompysonalso providestree_pair_to_hidden_breaks,tree_pair_to_breaks, andbreaks_to_tree_pair.First,tree_pair_to_hidden_breakstakes in aTreePair, and then outputs a pair of two equal-length lists ofDyadics. The two lists represent the hidden breaks of the givenTreePair: the first list of those of the domain, in standard increasing order, and the second list is those of the range, where the value of the break in theith position of the range breaks corresponds to the leaf mapped onto by theith leaf/break in the domain.Second,tree_pair_to_breakstakes in aTreePair, and then outputs a triple of two equal-length lists ofDyadics and a singleDyadic.  The two lists represent the true breaks of the givenTreePair(that is, pairing the elements of the two lists in order provides the co-ordinates of each of the positions at which the gradient changes -- where the function is non-differentiable). The final value is aDyadicrepresenting the value of theTreePairapplied to the number 0.Third,breaks_to_tree_pairtakes in two lists ofDyadics, corresponding to positions of the breaks in the domain and the range (theith break in the domain break list must be mapped to theith break in the range break list).  This list must contain all the true breaks of the corresponding tree pair, but it may contain any other hidden breaks that the user wishes to include.  The result is the unique (except no breaks maps to all the rotations in T, -- but is unique when the value of the tree pair applied to 0 is specified -- this will be added soon) tree pair described by this set of break points.