mmf
Class MMF_SwitchRecursion

Object
  extended by common:Generic
      extended by common:Formula
          extended by common:ConvergentDivergentFormula
              extended by mmf:MMF_SwitchConvergentDivergentFormula
                  extended by mmf:MMF_SwitchRecursion

class 
MMF_SwitchConvergentDivergentFormula:MMF_SwitchRecursion

This formula is an adaption of 'Switch Recursion' from mmfs.ufm which itself was based on the Lucas recursion formula found on Mathworld.

Note that for historical reasons this formula uses its own zold and bailout values instead of those defined in the base class doing so should not be taken as a model for other formulas.


Ultra Fractal Source

Toggle UF Source Code Display

 class MMF_SwitchRecursion(MMF_SwitchConvergentDivergentFormula) {
 ; This formula is an adaption of 'Switch Recursion' from mmfs.ufm
 ; which itself was based on the Lucas recursion formula found on Mathworld.<p>
 ; Note that for historical reasons this formula uses its own
 ; zold and bailout values instead of those defined in the base class
 ; doing so should not be taken as a model for other formulas.<br>
 public:
   import "common.ulb"
 
   ; @param pparent the parent, generally "this" for the parent, or zero
   func MMF_SwitchRecursion(Generic pparent)
     MMF_SwitchConvergentDivergentFormula.MMF_SwitchConvergentDivergentFormula(pparent)
     fTransform0 = new @p_Transform0(this)
     fTransform1 = new @p_Transform1(this)
     fTransformPZ = new @p_TransformPZ(this)
     fTransformP = new @p_TransformP(this)
     fTransformQZ = new @p_TransformQZ(this)
     fTransformQ = new @p_TransformQ(this)
     fTransformX = new @p_TransformX(this)
     fTransformD = new @p_TransformD(this)
   endfunc
 
   complex func Init(complex pz)
 ;    m_Iterations = 0 not used in this formula
     m_BailedOut = false
     fTransform0.Init(pz)
     fTransform1.Init(pz)
     fTransformPZ.Init(pz)
     fTransformP.Init(pz)
     fTransformQZ.Init(pz)
     fTransformQ.Init(pz)
     fTransformX.Init(pz)
     fTransformD.Init(pz)
     if fType
       fConstant = pz
       if @p_addpixel
         fZold = pz = fValue + fConstant
       else
         fZold = pz = fValue
       endif
     else
       fZold = pz
     endif
     if @p_type=="Iterative"
       m_p = m_p0 = fTransform0.Iterate(pz)
       m_p1 = fTransform1.Iterate(pz)
       m_recursecount = 2
     endif
     return pz
   endfunc
 
   complex func Iterate(complex pz)
 ;    m_Iterations = m_Iterations + 1 not used in this formula
     if @p_type=="Normal"
       complex p
       complex p0 = fTransform0.Iterate(pz)
       complex p1 = fTransform1.Iterate(pz)
       int i = 2
       repeat
         p = ((fTransformPZ.Iterate(i)*pz + fTransformP.Iterate(i))*p1 \
              + (fTransformQZ.Iterate(i)*pz + fTransformQ.Iterate(i))*p0) \
             / fTransformD.Iterate(i)
         p0 = p1
         p1 = p
       until (i=i+1)>@p_recurse
       m_p = p1
     else;if @p_type=="Iterative"
       m_p = ((fTransformPZ.Iterate(m_recursecount)*pz \
               + fTransformP.Iterate(m_recursecount))*m_p1 \
              + (fTransformQZ.Iterate(m_recursecount)*pz \
                 + fTransformQ.Iterate(m_recursecount))*m_p0) \
             / fTransformD.Iterate(m_recursecount)
       m_p0 = m_p1
       m_p1 = m_p
       m_recursecount = m_recursecount + 1
     endif
     if @p_fractal=="Pn(z)+c"
       m_p = fTransformX.Iterate(m_p) + fConstant
     elseif @p_fractal=="c*Pn(z)"
       m_p = fConstant*fTransformX.Iterate(m_p)
     elseif @p_fractal=="Pn(z)+zold+c"
       m_p = fTransformX.Iterate(m_p) + fZold + fConstant
     elseif @p_fractal=="c*Pn(z)+zold"
       m_p = fConstant*fTransformX.Iterate(m_p) + fZold
     elseif @p_fractal=="zold*Pn(z)+c"
       m_p = fZold*fTransformX.Iterate(m_p) + fConstant
     else;if @p_fractal=="c*zold*Pn(z)"
       m_p = fConstant*fZold*fTransformX.Iterate(m_p)
     endif
     fZold = pz
     return m_p
   endfunc
 
   bool func IsBailedOut(complex pz)
     if ((@p_BailType=="Divergent" || @p_BailType=="Both" \
          || @p_BailType=="Div.+Abs.Conv.") \
         && |pz|>=@p_Bailout) \
        || ((@p_BailType=="Convergent" || @p_BailType=="Both") \
            && |pz-fZold|<=@p_SmallBail) \
        || ((@p_BailType=="Absolute Convergence" \
             || @p_BailType=="Div.+Abs.Conv.") \
            && |pz-@p_root|<=@p_SmallBail )
       m_BailedOut = true
     endif
     return m_BailedOut
   endfunc
 
   float func GetUpperBailout()
     return @p_Bailout
   endfunc
 
   float func GetLowerBailout()
     return @p_SmallBail
   endfunc
 
   complex func GetPrimaryExponent()
     return @p_recurse
   endfunc
 
 private:
   Transform fTransform0
   Transform fTransform1
   Transform fTransformPZ
   Transform fTransformP
   Transform fTransformQZ
   Transform fTransformQ
   Transform fTransformX
   Transform fTransformD
   complex fZold
   complex m_p
   complex m_p0
   complex m_p1
   int m_recursecount
 
 default:
   title = "Switch Recursion"
   int param v_mmfswitchrecursion
     caption = "Version (MMF Switch Recursion)"
     enum = "1.0"
     default = 0
     hint = "This field is to absolutely ensure backward compatibility, \
             the default will always be set to the latest version, but \
             there may be some cases where an older effect that you like \
             is lost in an update and you could still use it by selecting \
             the older version number."
     visible = false
   endparam
   float param p_upperbailout
     visible = false
   endparam
   float param p_lowerbailout
     visible = false
   endparam
   bool param p_addpixel
     caption = "Offset z start"
     default = false
     hint = "When enabled the z start value (in Mandelbrot mode) is offset \
             by the constant for the current position - normally '#pixel'."
     visible = !@p_manual || @p_mandy
   endparam
   complex param p_power
     visible = false
   endparam
   heading
     caption = "Information"
     text = "This formula is an adaptation of 'Switch Recursion' from \
             mmfs.ufm which itself was based on the Lucas recursion \
             formula found on Mathworld. Tip: You'll often find that \
             the best Mandelbrot start value (critical value) is \
             non-zero when you change the recursion parameters. You \
             can use the switch back from the Julia to the Mandelbrot \
             to help find the critical value - it's usually when the \
             Mandelbrot 'lake' is at its largest, if you stick to real \
             values for the recursion parameters then the critical \
             value should also be real. Note that it's often worth trying \
             values such as -1, -0.5, 0.5 or 1 as the Mandelbrot start \
             value. For those more mathematically inclined see the details \
             of the 'Transpoly' formula in mmf.html for details of several \
             classic polynomial functions that you can create using this \
             formula by setting the recursion transforms and values \
             appropriately."
   endheading
   heading
     caption = "Bailout Options"
     text = "Depending on the transforms you choose your fractal could \
             be either divergent or convergent. You need to choose the \
             correct type to produce a result, a symptom of choosing the \
             wrong type is an image in a single solid colour e.g. black. \
             Sometimes fractals produce both types of 'vergence and for \
             these you can choose 'Both'."
   endheading
   int param p_BailType
     caption = "Bailout Type"
     enum = "Divergent" "Convergent" "Both" "Absolute Convergence" \
            "Div.+Abs.Conv."
     default = 0
     hint = "If you get an empty or nearly empty fractal try switching \
             from 'Divergent' to 'Convergent' or vice-versa or choosing \
             'Both'. Note that in some cases if your fractal is a \
             Mandelbrot you may need to ensure that the zstart value \
             is non-zero."
   endparam
   complex param p_root
     caption = "Convergence Value"
     default = (1,0)
     hint = "This is the value for testing for convergence to. For the \
             'Magnet' formulas the value should be (1,0), if you don't \
             know the value to use it's best to stick to the plain \
             'Convergent' 'Bailout Type'. It's always worth trying (0,0)."
     visible = @p_BailType>2
   endparam
   float param p_Bailout
     caption = "Divergent Bailout"
     default = 128.0
     hint = "In general larger values will require higher iterations."
     visible = @p_BailType==0 || @p_BailType==2 || @p_BailType==4
   endparam
   float param p_SmallBail
     caption = "Convergent Bailout"
     default = 1e-5
     hint = "In general smaller values will require higher iterations."
     visible = @p_BailType>0
   endparam
   heading
     caption = "Fractal Method"
   endheading
   int param p_type
     caption = "Recursion Type"
     enum = "Normal" "Iterative"
     default = 0
     hint = "When you specify 'Normal' a set number of recursions are \
             performed on each iteration, the number of recursions will \
             control the degree (exponent) of the fractal (at least for \
             divergent fractals). When you choose 'Iterative' the \
             recurrence relation is performed as the iterations i.e. for \
             divergent fractals the degree increases with the number of \
             iterations."
   endparam
   int param p_recurse
     caption = "Number of Recursions"
     default = 6
     min = 2
     hint = "The number of recursions to perform on each iteration. The \
             minimum is 2. Using the defaults a count of 2 will produce \
             a degree 2 fractal, 3 will produce a degree 3 fractal and so \
             on."
     visible = @p_type==0
   endparam
   Transform param p_TransformX
     caption = "Transform of Pn(z)"
     default = NullTransform
     hint = "Here you may specify a transform of the recurrence \
             function Pn(z) before it is plugged into the 'Fractal \
             Formula'."
   endparam
   int param p_fractal
     caption = "Fractal Formula"
     enum = "Pn(z)+c" "c*Pn(z)" "Pn(z)+zold+c" "c*Pn(z)+zold" \
            "zold*Pn(z)+c" "c*zold*Pn(z)"
     default = 0
     hint = "Normally the recurrence relation you set using the \
             transforms will produce a polynomial in z, Pn(z). \
             Here you can choose how Pn(z) is used to produce a \
             fractal."
   endparam
   heading
     caption = "Recursion Equations"
     text = "Here you can set the equations used for the recurrence \
             relation by choosing appropriate transforms. \
             The recurrence relation works as follows: Two base \
             equations are used, P0(z) and P1(z) and on each recursion \
             Pn(z) is created as Pn(z) = ((Q(n)*z + R(n))*Pn-1(z) + \
             (S(n)*z + T(n))*Pn-2(z))/D(n) where Q(n), R(n), S(n), T(n) \
             and D(n) are functions of the recurrence level n. You \
             specify P0 as 'Transform 0', P1 as 'Transform 1', Q as \
             'Transform Q', R as 'Transform R', S as 'Transform S', T \
             as 'Transform T' and D as 'Transform D'. The formula is \
             really designed so you should use either the 'Constant Value', \
             'Simple Scale' or 'Linear' transforms from mmf.ulb but \
             interesting results may arise from almost any transform :)"
   endheading
   Transform param p_Transform0
     caption = "Transform 0"
     default = MMF_Scale
     hint = "P0(z)"
   endparam
   Transform param p_Transform1
     caption = "Transform 1"
     default = MMF_Scale
     hint = "P1(z)"
   endparam
   Transform param p_TransformPZ
     caption = "Transform Q"
     default = MMF_Constant
     hint = "Q(n) in (Q(n)*z + R(n))*Pn-1(z) + (S(n)*z + T(n))*Pn-2(z)"
   endparam
   Transform param p_TransformP
     caption = "Transform R"
     default = MMF_Constant
     hint = "R(n) in (Q(n)*z + R(n))*Pn-1(z) + (S(n)*z + T(n))*Pn-2(z)"
   endparam
   Transform param p_TransformQZ
     caption = "Transform S"
     default = MMF_Constant
     hint = "S(n) in (Q(n)*z + R(n))*Pn-1(z) + (S(n)*z + T(n))*Pn-2(z)"
   endparam
   Transform param p_TransformQ
     caption = "Transform T"
     default = MMF_Constant
     hint = "T(n) in (Q(n)*z + R(n))*Pn-1(z) + (S(n)*z + T(n))*Pn-2(z)"
   endparam
   Transform param p_TransformD
     caption = "Transform D"
     default = MMF_Constant
     hint = "The polynomial is divided by this transform of the \
             recurrence level at each stage."
   endparam
 }
 


Constructor Summary
MMF_SwitchRecursion()
           
MMF_SwitchRecursion(Generic pparent)
           
 
Method Summary
 float GetLowerBailout()
          Determine the lower bailout boundary.
 complex GetPrimaryExponent()
          Determine the primary exponent.
 float GetUpperBailout()
          Determine the upper bailout boundary.
 complex Init(complex pz)
          Note that here zold is initialised to initial z
 boolean IsBailedOut(complex pz)
          Test whether the formula has bailed out (i.e.
 complex Iterate(complex pz)
          Produce the next value in the sequence
 
Methods inherited from class mmf:MMF_SwitchConvergentDivergentFormula
SetParams
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

MMF_SwitchRecursion

public MMF_SwitchRecursion(Generic pparent)
Parameters:
pparent - the parent, generally "this" for the parent, or zero

MMF_SwitchRecursion

public MMF_SwitchRecursion()
Method Detail

Init

public complex Init(complex pz)
Description copied from class: MMF_SwitchConvergentDivergentFormula
Note that here zold is initialised to initial z

What it's initialised to is normally irrelevant unless the derived formula uses zold in its main calculations in which case the user should be given the choice of initialising zold to either the location, the initial z value or a fixed constant.

Overrides:
Init in class MMF_SwitchConvergentDivergentFormula
Parameters:
pz - the location (normally #pixel)
Returns:
initial z for iteration

Iterate

public complex Iterate(complex pz)
Description copied from class: ConvergentDivergentFormula
Produce the next value in the sequence

As long as the sequence has not bailed out, this function will be continually called to produce sequence values.

Overrides:
Iterate in class ConvergentDivergentFormula
Parameters:
pz - previous value in the sequence; corresponds to #z in a fractal formula. Note that you should always use this value for computing the next iteration, rather than a saved value, as the calling code may modify the returned value before passing it back to the next Iterate() call.
Returns:
the next value in the sequence

IsBailedOut

public boolean IsBailedOut(complex pz)
Description copied from class: ConvergentDivergentFormula
Test whether the formula has bailed out (i.e. the sequence is complete)

Since this is a divergent fractal, the test is easy: if it's bigger than the bailout, the sequence is done.

Overrides:
IsBailedOut in class ConvergentDivergentFormula
Parameters:
pz - last sequence value to test; this should be the value returned from the previous Iterate() call. Note that it is acceptable to ignore pz and use m_BailedOut, but any code calling IsBailedOut() should pass in the correct pz for Formula classes which do not use m_BailedOut.
Returns:
true if the sequence has bailed out (i.e. should be terminated)

GetUpperBailout

public float GetUpperBailout()
Description copied from class: ConvergentDivergentFormula
Determine the upper bailout boundary.

Overrides:
GetUpperBailout in class ConvergentDivergentFormula
Returns:
the upper bailout parameter

GetLowerBailout

public float GetLowerBailout()
Description copied from class: ConvergentDivergentFormula
Determine the lower bailout boundary.

Overrides:
GetLowerBailout in class ConvergentDivergentFormula
Returns:
the lower bailout parameter

GetPrimaryExponent

public complex GetPrimaryExponent()
Description copied from class: Formula
Determine the primary exponent.

Many fractals can be characterized by an exponent value that is useful to other formulas, so we provide that here. If your formula does not need or use this value, override the p_power parameter and make it hidden.

Overrides:
GetPrimaryExponent in class Formula
Returns:
the primary exponent parameter