Difference between revisions of "LogZp1oZm1"

From aemwiki
Jump to: navigation, search
m
m
 
(4 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
; Purpose: Calculates <math>\ln\left(\frac{Z-1}{Z+1}\right)</math>
 
; Purpose: Calculates <math>\ln\left(\frac{Z-1}{Z+1}\right)</math>
  
; Author: James R. Craig
+
; Author: James R. Craig, Ph. Le Grand
  
 
  #include <math.h>
 
  #include <math.h>
 
  #include <complex>
 
  #include <complex>
  typedef complex<double> cmplex;
+
  typedef std::complex<double> cmplex;
 
  const double PI=3.141592653589793238462643; // pi  
 
  const double PI=3.141592653589793238462643; // pi  
 
  /*******************************************************************************
 
  /*******************************************************************************
 
  logZm1oZp1
 
  logZm1oZp1
 
  optimized version of log ((Z-1.0)/(Z+1.0)):  
 
  optimized version of log ((Z-1.0)/(Z+1.0)):  
  1.1% of the cost of a direct call- 2 orders of magnitude speedup!
+
  ~13% of the cost of a direct call- 1 order of magnitude speedup!
 
  Author: James R. Craig
 
  Author: James R. Craig
 +
Modified 2007 12 06 by Ph. Le Grand:
 +
    Added local variables x,y,r2 to reduce number of calls to
 +
    member functions of Z and reduce number of operations
 +
    for minor speed gains.
 +
Modified 2008 01 11 by Ph. Le Grand:
 +
    Reduced some operations for minor speed gains,
 +
    used atan2, for speed and reduction of logic.
 
  -------------------------------------------------------------------------------*/
 
  -------------------------------------------------------------------------------*/
 
  inline cmplex logZm1oZp1(const cmplex &Z)
 
  inline cmplex logZm1oZp1(const cmplex &Z)
  {
+
  {
  double den(Z.real()*Z.real()+Z.imag()*Z.imag()+Z.real()+Z.real()+1.0);
+
  double x(Z.real());
  double add=0.0;
+
double y(Z.imag());
if ((Z.real()*Z.real()+Z.imag()*Z.imag())<1.0){
+
  double r2=x*x+y*y;
add=-PI;
+
if (Z.imag()>0.0){add=PI;}
+
  return cmplex(0.5*log(1.0-4.0*x/(r2+x+x+1.0)),
}
+
        atan2( y+y, r2-1.0 ));   
  return cmplex(0.5*log(1.0-((Z.real()*(den-Z.real()-2)+den-Z.imag()*Z.imag()-1.0)/(0.25*den*den))),
 
        add+atan( (Z.imag()+Z.imag()) /(den-Z.real()-Z.real()-2.0) ));   
 
 
  }
 
  }

Latest revision as of 14:56, 12 January 2008

Language
c++
Purpose
Calculates <math>\ln\left(\frac{Z-1}{Z+1}\right)</math>
Author
James R. Craig, Ph. Le Grand
#include <math.h>
#include <complex>
typedef std::complex<double> cmplex;
const double PI=3.141592653589793238462643; // pi 
/*******************************************************************************
logZm1oZp1
optimized version of log ((Z-1.0)/(Z+1.0)): 
~13% of the cost of a direct call- 1 order of magnitude speedup!
Author: James R. Craig
Modified 2007 12 06 by Ph. Le Grand:
    Added local variables x,y,r2 to reduce number of calls to 
    member functions of Z and reduce number of operations 
    for minor speed gains.
Modified 2008 01 11 by Ph. Le Grand:
    Reduced some operations for minor speed gains,
    used atan2, for speed and reduction of logic.
-------------------------------------------------------------------------------*/
inline cmplex logZm1oZp1(const cmplex &Z)
{ 	
	double x(Z.real());
	double y(Z.imag());	
	double r2=x*x+y*y;								 

	return cmplex(0.5*log(1.0-4.0*x/(r2+x+x+1.0)),
		      atan2( y+y, r2-1.0 ));   
}