## reb Class REB_Cayley_Switch

```Object
common:Generic
common:Formula
reb:Switch
reb:REB_Cayley_Switch
```

`class Switch:REB_Cayley_Switch`

Ultra Fractal Source
``` class REB_Cayley_Switch(Switch) {
public:
import "common.ulb"

; constructor
func REB_Cayley_Switch(Generic pparent)
Switch.Switch(pparent)
m_power = @p_power
m_mand = @p_mand
m_jul = @p_jul
m_bailout = @p_upperbailout
m_bailout2 = @p_lowerbailout
m_c = @m_c
m_test = @test
endfunc

; initialize the formula
complex func Init(complex pz)
Switch.Init(pz)
m_fz = 0
m_fzp = 0
m_fzp2 = 0
m_zold = 0
m_iterations = 0
if m_mand
m_c = pz
pz = 0
endif
return pz
endfunc

; call for each iterated point
complex func Iterate(complex pz)
Switch.Iterate(pz)
m_fz = pz^3 - m_c*pz - m_c + 1
m_fzp = 3*pz^2 - m_c
m_fzp2 = 6*pz
if @converge == 0                          ; Newton
pz = pz - m_fz/m_fzp
elseif @converge == 1                      ; Householder
pz = pz - m_fz/m_fzp*(1 + m_fz*m_fzp2/(2*m_fzp^2))
elseif @converge == 2                      ; Halley
pz = pz - 2*m_fz*m_fzp/(2*m_fzp^2 - m_fz*m_fzp2)
elseif @converge == 3                      ; Schroder
pz = pz - m_fz*m_fzp/(m_fzp^2 - m_fz*m_fzp2)
elseif @converge == 4                      ; Ho custom
pz = pz - m_fz/m_fzp*(1 + m_fz*m_fzp2/(@custom*m_fzp^2))
elseif @converge == 5                      ; Ha custom
pz = pz - 2*m_fz*m_fzp/(@custom*m_fzp^2 - m_fz*m_fzp2)
elseif @converge == 6                      ; H_S custom
pz = pz - @custom*m_fz*m_fzp/(@custom*m_fzp^2 - m_fz*m_fzp2)
elseif @converge == 7                      ; Mixed 1
if  m_iterations % 2 == 0
pz = pz - m_fz/m_fzp*(1 + m_fz*m_fzp2/(2*m_fzp^2))
else
pz = pz - m_fz/m_fzp
endif
elseif @converge == 8                      ; Mixed 2
if  m_iterations % 2 == 0
pz = pz - 2*m_fz*m_fzp/(2*m_fzp^2 - m_fz*m_fzp2)
else
pz = pz - m_fz/m_fzp
endif
elseif @converge == 9                      ; Mixed 3
if  m_iterations % 2 == 0
pz = pz - m_fz*m_fzp/(m_fzp^2 - m_fz*m_fzp2)
else
pz = pz - m_fz/m_fzp
endif
elseif @converge == 10                      ; Mixed 4
if  m_iterations % 2 == 0
pz = pz - @custom*m_fz*m_fzp/(@custom*m_fzp^2 - m_fz*m_fzp2)
else
pz = pz - m_fz/m_fzp
endif
endif
return pz
endfunc

; Override the default function for bailout
bool func IsBailedOut(complex pz)
return |pz-m_zold| < m_bailout2
endfunc

protected:
complex m_fz
complex m_fzp
complex m_fzp2

default:
title = "Cayley Switch"
int param v_cayleyswitch
caption = "Version (Cayley Switch)"
default = 100
hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
visible = @v_cayleyswitch < 100
endparam
complex param m_c
caption = "Julia Seed"
default = (0,0)
visible = false
endparam
bool param p_mand
caption = "Mandel Type"
default = true
visible = false
endparam
bool param p_jul
caption = "Julia Type"
default = false
visible = false
endparam
param test
caption = "Bailout Test"
default = 0
enum = "mod" "real" "imag" "or" "and" "manh" "manr"
hint = "mod is the standard bailout. The remaining bailout methods are \
from Fractint."
visible = false
endparam
float param p_upperbailout
caption = "Bailout value (Divergent)"
default = 1e10
min = 1.0
visible = false
endparam
float param p_lowerbailout
caption = "Bailout value (Convergent)"
default = 1e-10
endparam
complex param p_power ; Overrides p_power from Formula
caption = "Power"
default = (2,0)
visible = false
endparam
caption = "Convergence Methods"
param converge
caption = "Convergence Method"
default = 0
enum = "Newton" "Householder" "Halley" "Schroder" "Ho Custom" \
"Ha Custom" "H_S Custom" "Mixed1" "Mixed2" "Mixed3" "Mixed4"
endparam
float param custom
caption = "H_S Constant"
default = 1.5
visible = @converge==4 || @converge==5  || @converge==6 || @converge==10
endparam
}
```

Constructor Summary
`REB_Cayley_Switch()`

`REB_Cayley_Switch(Generic pparent)`
constructor

Method Summary
` complex` `Init(complex pz)`
initialize the formula
` boolean` `IsBailedOut(complex pz)`
Override the default function for bailout
` complex` `Iterate(complex pz)`
call for each iterated point

Methods inherited from class reb:Switch
`GetParams, SetParams`

Methods inherited from class common:Formula
`GetLowerBailout, GetPrimaryExponent, GetUpperBailout`

Methods inherited from class common:Generic
`GetParent`

Methods inherited from class Object

Constructor Detail

### REB_Cayley_Switch

`public REB_Cayley_Switch(Generic pparent)`
constructor

### REB_Cayley_Switch

`public REB_Cayley_Switch()`
Method Detail

### Init

`public complex Init(complex pz)`
initialize the formula

Overrides:
`Init` in class `Switch`
Parameters:
`pz` - seed value for the sequence; for a normal fractal formula, this will be #pixel
Returns:
first value in the sequence; this corresponds to #z in a fractal formula

### Iterate

`public complex Iterate(complex pz)`
call for each iterated point

Overrides:
`Iterate` in class `Switch`
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)`
Override the default function for bailout

Overrides:
`IsBailedOut` in class `Switch`
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)