/** * Computes the norm of an element <code>λ</code> of * <code><b>R</b>[τ]</code>, where <code>λ = u + vτ</code> * and <code>u</code> and <code>u</code> are real numbers (elements of * <code><b>R</b></code>). * @param mu The parameter <code>μ</code> of the elliptic curve. * @param u The real part of the element <code>λ</code> of * <code><b>R</b>[τ]</code>. * @param v The <code>τ</code>-adic part of the element * <code>λ</code> of <code><b>R</b>[τ]</code>. * @return The norm of <code>λ</code>. */ public static SimpleBigDecimal Norm(sbyte mu, SimpleBigDecimal u, SimpleBigDecimal v) { SimpleBigDecimal norm; // s1 = u^2 SimpleBigDecimal s1 = u.Multiply(u); // s2 = u * v SimpleBigDecimal s2 = u.Multiply(v); // s3 = 2 * v^2 SimpleBigDecimal s3 = v.Multiply(v).ShiftLeft(1); if (mu == 1) { norm = s1.Add(s2).Add(s3); } else if (mu == -1) { norm = s1.Subtract(s2).Add(s3); } else { throw new ArgumentException("mu must be 1 or -1"); } return(norm); }
/** * Computes the norm of an element <code>λ</code> of * <code><b>R</b>[τ]</code>, where <code>λ = u + vτ</code> * and <code>u</code> and <code>u</code> are real numbers (elements of * <code><b>R</b></code>). * @param mu The parameter <code>μ</code> of the elliptic curve. * @param u The real part of the element <code>λ</code> of * <code><b>R</b>[τ]</code>. * @param v The <code>τ</code>-adic part of the element * <code>λ</code> of <code><b>R</b>[τ]</code>. * @return The norm of <code>λ</code>. */ public static SimpleBigDecimal Norm(sbyte mu, SimpleBigDecimal u, SimpleBigDecimal v) { SimpleBigDecimal norm; // s1 = u^2 SimpleBigDecimal s1 = u.Multiply(u); // s2 = u * v SimpleBigDecimal s2 = u.Multiply(v); // s3 = 2 * v^2 SimpleBigDecimal s3 = v.Multiply(v).ShiftLeft(1); if(mu == 1) { norm = s1.Add(s2).Add(s3); } else if(mu == -1) { norm = s1.Subtract(s2).Add(s3); } else { throw new ArgumentException("mu must be 1 or -1"); } return norm; }