complex inverse hyperbolic tangent function

Complex::artanh($z) computes and returns the principal branch of artanh($z)


@param mixed $z (Complex, or parsable to Complex)
@retval Complex
19883
public static function artanh($z) {
        if (!($z instanceof Complex)) $z = static::parse($z);

        return static::div(static::log(static::div(static::add(1,$z), static::sub(1,$z))),2);
    }
1281357
public static function IMCONJUGATE($complexNumber)
    {
        $complexNumber    = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);

        $parsedComplex = self::parseComplex($complexNumber);

        if ($parsedComplex['imaginary'] == 0.0) {
            return $parsedComplex['real'];
        } else {
            return self::cleanComplex(
                self::COMPLEX(
                    $parsedComplex['real'],
                    0 - $parsedComplex['imaginary'],
                    $parsedComplex['suffix']
                )
            );
        }
    }
400860
public function inverse($p)
    {
        /*
        $dlon;
        $xx;
        $yy;
        $xys;
        $c1;
        $c2;
        $c3;
        $al;
        $asq;
        $a1;
        $m1;
        $con;
        $th1;
        $d;
        */

        $p->x -= $this->x0;
        $p->y -= $this->y0;

        $con = Common::PI * $this->R;

        $xx = $p->x / $con;
        $yy = $p->y / $con;

        $xys = $xx * $xx + $yy * $yy;

        $c1 = -abs( $yy ) * (1.0 + $xys);
        $c2 = $c1 - 2.0 * $yy * $yy + $xx * $xx;
        $c3 = -2.0 * $c1 + 1.0 + 2.0 * $yy * $yy + $xys * $xys;

        $d = $yy * $yy / $c3 + (2.0 * $c2 * $c2 * $c2 / $c3 / $c3 / $c3 - 9.0 * $c1 * $c2 / $c3 / $c3) / 27.0;

        $a1 = ($c1 - $c2 * $c2 / 3.0 / $c3) / $c3;
        $m1 = 2.0 * sqrt( -$a1 / 3.0 );
        $con = ((3.0 * $d) / $a1) / $m1;

        if (abs($con) > 1.0) {
            if ($con >= 0.0) {
                $con = 1.0;
            } else {
                $con = -1.0;
            }
        }

        $th1 = acos($con) / 3.0;

        if ($p->$y >= 0) {
            $lat = (-$m1 * cos($th1 + Common::PI / 3.0) - $c2 / 3.0 / $c3) * Common::PI;
        } else {
            $lat = -(-m1 * cos($th1 + Common::PI / 3.0) - $c2 / 3.0 / $c3) * Common::PI;
        }

        if (abs($xx) < Common::EPSLN) {
            $lon = $this->$long0;
        }

        $lon = Common::adjust_lon(
            $this->long0 + Common::PI * ($xys - 1.0 + sqrt(1.0 + 2.0 * ($xx * $xx - $yy * $yy) + $xys * $xys)) / 2.0 / $xx
        );

        $p->x = $lon;
        $p->y = $lat;

        return $p;
    }
14490
public function union($a, $b)
	{
		$ar = $this->find($a);
		$br = $this->find($b);

		if ($ar !== $br) {
			$this->parents[$br] = $ar;
		}

		/*
		$c = function($x) {
			return sprintf('<span style="background:#%x">%s</span>', crc32($x) & 0xffffff | 0x808080, $x);
		};

		echo '<br><b>', $c($a), ' == ', $c($b), "</b><br>";
		var_dump($this->parents);
		echo '    ', $c($a), ' … ', ($ar === $this->parents[$ar] ? $c($ar).' is root' : '<b>'.$c($ar).' is NOT root!</b>'), "<br>";
		echo '    ', $c($b), ' … ', ($br === $this->parents[$br] ? $c($br).' is root' : '<b>'.$c($br).' is NOT root!</b>'), "<br>";
		echo '    ', $c($ar), ' =?= ', $c($br), "<br>";
		echo '    ', $c($br), ' --&gt; ', $c($this->parents[$br]), "<br>";
		// */
	}
229635
public function complexSub(ComplexType $a, ComplexType $b)
    {
        $r = $this->rationalSub($a->r(), $b->r());
        $i = $this->rationalSub($a->i(), $b->i());
        return ComplexTypeFactory::create($r, $i);
    }
947236
public static function arsinh($z) {
        if (!($z instanceof Complex)) $z = static::parse($z);

        return static::log(static::add($z, static::sqrt(static::add(1, static::mul($z, $z)))));
    }
271452
function() {

      // acsch(c) = log((1+sqrt(1+c^2))/c)

      var a = this['re'];
      var b = this['im'];

      if (b === 0) {

        return new Complex(
                (a !== 0)
                ? Math.log(a + Math.sqrt(a * a + 1))
                : Infinity, 0);
      }

      var d = a * a + b * b;
      return (d !== 0)
              ? new Complex(
                      a / d,
                      -b / d).asinh()
              : new Complex(
                      (a !== 0) ? a / 0 : 0,
                      (b !== 0) ? -b / 0 : 0).asinh();
    }
827380
public static function IMCOS($complexNumber) {
		$complexNumber	= PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);

		$parsedComplex = self::_parseComplex($complexNumber);

		if ($parsedComplex['imaginary'] == 0.0) {
			return cos($parsedComplex['real']);
		} else {
			return self::IMCONJUGATE(self::COMPLEX(cos($parsedComplex['real']) * cosh($parsedComplex['imaginary']),sin($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']));
		}
	}
589668
function() {

      // acot(c) = i / 2 log((c - i) / (c + i))

      var a = this['re'];
      var b = this['im'];

      if (b === 0) {
        return new Complex(Math.atan2(1, a), 0);
      }

      var d = a * a + b * b;
      return (d !== 0)
              ? new Complex(
                      a / d,
                      -b / d).atan()
              : new Complex(
                      (a !== 0) ? a / 0 : 0,
                      (b !== 0) ? -b / 0 : 0).atan();
    }
952766
protected function compute(Matrix $z) : Matrix
    {
        if (!$this->alpha) {
            throw new RuntimeException('Layer is not initialized.');
        }

        $alphas = $this->alpha->w();

        $computed = [];

        foreach ($z as $i => $row) {
            $alpha = $alphas[$i];

            $activations = [];

            foreach ($row as $value) {
                $activations[] = $value > 0.
                    ? $value
                    : $alpha * $value;
            }

            $computed[] = $activations;
        }

        return Matrix::quick($computed);
    }
428644
public static function arctan($z) {
        if (!($z instanceof Complex)) $z = static::parse($z);

        $I = new Complex(0,1);
        $iz = static::mul($z, $I);
        $w = static::div( static::add(1, $iz), static::sub(1, $iz) );
        $logw = static::log($w);
        return static::div($logw, new Complex(0,2));
    }
1314739
public function parents($hash, $lineal = false) {
		if (($current = $this->dir($hash)) == false) {
			return false;
		}

		$path = $this->decode($hash);
		$tree = array();
		
		while ($path && $path != $this->root) {
			$path = $this->dirnameCE($path);
			$stat = $this->stat($path);
			if (!empty($stat['hidden']) || !$stat['read']) {
				return false;
			}
			
			array_unshift($tree, $stat);
			if (!$lineal) {
				foreach ($this->gettree($path, 0) as $dir) {
					if (!in_array($dir, $tree)) {
						$tree[] = $dir;
					}
				}
			}
		}

		return $tree ? $tree : array($current);
	}
82868
public function sub($a, $b)
    {
        $a = $this->convert($a);
        $b = $this->convert($b);
        switch ($this->arbitrate($a, $b)) {
            case 'int':
                return $this->calcEngine->intSub($a, $b);
            case 'float':
                return $this->calcEngine->floatSub($a, $b);
            case 'whole':
                return $this->calcEngine->wholeSub($a, $b);
            case 'natural':
                return $this->calcEngine->naturalSub($a, $b);
            case 'rational':
                return $this->calcEngine->rationalSub($a, $b);
            case 'complex':
                return $this->calcEngine->complexSub($a, $b);
            case 'complex:numeric':
                return $this->calcEngine->complexSub($a, $b->asComplex());
            case 'numeric:complex':
                return $this->calcEngine->complexSub($a->asComplex(), $b);
        }
    }
413305
public function drawLine($xStart, $yStart, $zStart, $xEnd, $yEnd, $zEnd)
	{
		$this->setCode("(line)");
		$this->setCode("G0 X{$xStart} Y{$yStart} Z{$this->spindleAxisStartPosition}");
		$this->setCode("G1 Z{$zStart}");
		
		// testing tool setup tool metric M8 diameter 4mm
		$this->setCode("T1 M08");
		$this->setCode("G41 D4");
		
		$this->setCode("G1 X{$xStart} Y{$yStart} Z{$zStart}");
		$this->setCode("G1 X{$xEnd} Y{$yEnd} Z{$zEnd}");

		$this->setCode("G0 Z{$this->spindleAxisStartPosition}");
		$this->setCode("G0 X{$xStart} Y{$yStart}");
		$this->setCode("(/line)\n");
		
		return $this;
	}
1300520
protected function differentiate(Matrix $z) : Matrix
    {
        if (!$this->alpha) {
            throw new RuntimeException('Layer has not been initlaized.');
        }

        $alphas = $this->alpha->w();

        $gradient = [];

        foreach ($z as $i => $row) {
            $alpha = $alphas[$i];

            $temp = [];

            foreach ($row as $value) {
                $temp[] = $value > 0. ? 1. : $alpha;
            }

            $gradient[] = $temp;
        }

        return Matrix::quick($gradient);
    }
258439
public function getZ() : ?int 
    {
        if ( ! $this->hasZ()) {
            $this->setZ($this->getDefaultZ());
        }
        return $this->z;
    }
1354886
public static function sqrt($z)
    {
        if (!($z instanceof Complex)) $z = static::parse($z);

        $r = sqrt($z->abs());
        $theta = $z->arg()/2;

        return new Complex($r*cos($theta), $r*sin($theta));
    }