Beispiel #1
0
    internal override Zahl f(Zahl x)
    {
        if (!x.integerq() || x.smaller(Zahl.ZERO))
        {
            throw new JasymcaException("Argument to factorial must be a positive integer, is " + x);
        }

        Algebraic r = Zahl.ONE;

        while (Zahl.ONE.smaller(x))
        {
            r = r.mult(x);
            x = ( Zahl )x.sub(Zahl.ONE);
        }

        return(( Zahl )r);
    }
Beispiel #2
0
    internal virtual Algebraic fzexakt(Zahl x)
    {
        if (x.smaller(Zahl.ZERO))
        {
            Algebraic r = fzexakt((Zahl)x.mult(Zahl.MINUS));
            if (r != null)
            {
                return(r.cc());
            }
            return(r);
        }

        if (x.integerq())
        {
            if (x.intval() % 2 == 0)
            {
                return(Zahl.ONE);
            }
            else
            {
                return(Zahl.MINUS);
            }
        }

        Algebraic qs = x.add(new Unexakt(.5));

        if (((Zahl)qs).integerq())
        {
            if (((Zahl)qs).intval() % 2 == 0)
            {
                return(Zahl.IMINUS);
            }
            else
            {
                return(Zahl.IONE);
            }
        }

        qs = x.mult(new Unexakt(4));

        if (((Zahl)qs).integerq())
        {
            Algebraic sq2 = FunctionVariable.create("sqrt", new Unexakt(0.5));
            switch (((Zahl)qs).intval() % 8)
            {
            case 1:
                return(Zahl.ONE.add(Zahl.IONE).div(Zahl.SQRT2));

            case 3:
                return(Zahl.MINUS.add(Zahl.IONE).div(Zahl.SQRT2));

            case 5:
                return(Zahl.MINUS.add(Zahl.IMINUS).div(Zahl.SQRT2));

            case 7:
                return(Zahl.ONE.add(Zahl.IMINUS).div(Zahl.SQRT2));
            }
        }
        qs = x.mult(new Unexakt(6));
        if (((Zahl)qs).integerq())
        {
            switch (((Zahl)qs).intval() % 12)
            {
            case 1:
                return(Zahl.SQRT3.add(Zahl.IONE).div(Zahl.TWO));

            case 2:
                return(Zahl.ONE.add(Zahl.SQRT3.mult(Zahl.IONE)).div(Zahl.TWO));

            case 4:
                return(Zahl.SQRT3.mult(Zahl.IONE).add(Zahl.MINUS).div(Zahl.TWO));

            case 5:
                return(Zahl.IONE.sub(Zahl.SQRT3).div(Zahl.TWO));

            case 7:
                return(Zahl.IMINUS.sub(Zahl.SQRT3).div(Zahl.TWO));

            case 8:
                return(Zahl.SQRT3.mult(Zahl.IMINUS).sub(Zahl.ONE).div(Zahl.TWO));

            case 10:
                return(Zahl.SQRT3.mult(Zahl.IMINUS).add(Zahl.ONE).div(Zahl.TWO));

            case 11:
                return(Zahl.IMINUS.add(Zahl.SQRT3).div(Zahl.TWO));
            }
        }
        return(null);
    }