The model for lazy elements is quite different from any of the other
types of
-adics. In addition to storing a finite approximation,
one also stores a method for increasing the precision. The interface
supports two ways to do this:
set_precision_relative
and
set_precision_absolute
.
#sage: R = Zp(5, prec = 10, type = 'lazy', print_mode = 'series', halt = 30) #sage: R #Lazy 5-adic Ring #sage: R.precision_cap() #10 #sage: R.halting_parameter() #30 #sage: K = Qp(5, type = 'lazy') #sage: K.precision_cap() #20 #sage: K.halting_parameter() #40
There are two parameters that are set at the creation of a lazy ring
or field. The first is prec
, which controls the precision to
which elements are initially computed. When computing with lazy
rings, sometimes situations arise where the insolvability of the
halting problem gives us problems. For example,
#sage: a = R(16) #sage: b = a.log().exp() - a #sage: b #O(5^10) #sage: b.valuation() #Traceback (most recent call last): #... #HaltingError: Stopped computing sum: set halting parameter higher if you want computation to continue
Setting the halting parameter controls to what absolute precision one computes in such a situation.
The interesting feature of lazy elements is that one can perform computations with them, discover that the answer does not have the desired precision, and then ask for more precision. For example,
#sage: a = R(6).log() * 15 #sage: b = a.exp() #sage: c = b / R(15).exp() #sage: c #1 + 2*5 + 4*5^2 + 3*5^3 + 2*5^4 + 3*5^5 + 5^6 + 5^10 + O(5^11) #sage: c.set_precision_absolute(15) #sage: c #1 + 2*5 + 4*5^2 + 3*5^3 + 2*5^4 + 3*5^5 + 5^6 + 5^10 + 4*5^11 + 2*5^12 + 4*5^13 + 3*5^14 + O(5^15)
There can be a performance penalty to using lazy
-adics in this
way. When one does computations with them, the computer construct an
expression tree. As you compute, values of these elements are cached,
and the overhead is reasonably low (though obviously higher than for a
fixed modulus element for example). But when you set the precision,
the computer has to reset precision throughout the expression tree for
that element, and thus setting precision can take the same order of
magnitude of time as doing the initial computation. However, lazy
-adics can be quite useful when experimenting.
See About this document... for information on suggesting changes.